From d65df84cc3251d43a3e57f48c19fff7393e84f6d Mon Sep 17 00:00:00 2001 From: Tobias Klika Date: Thu, 20 Aug 2020 01:35:08 +0200 Subject: [PATCH] start module output --- zero.Core/Api/RevisionsApi.cs | 10 ++- zero.Core/Api/Token.cs | 8 +- zero.Core/Entities/ListResult.cs | 4 + zero.Debug/Renderers/module.headline.js | 34 ++++++++ .../richtext.module.js => module.richtext.js} | 0 zero.Debug/Renderers/module.textwithimage.js | 34 ++++++++ .../Renderers/modules/headline.module.js | 51 ------------ zero.Debug/Renderers/page.content.js | 8 +- zero.Debug/TestData/Pages/ContentPage.cs | 3 + zero.Web.UI/App/components/forms/property.vue | 5 +- zero.Web.UI/App/components/loading.vue | 24 ++++-- .../App/components/modules/edit-module.vue | 67 ++++++++++----- .../App/components/modules/modules-select.vue | 49 ++++++----- .../App/components/modules/modules.vue | 81 +++++++++++++++++-- zero.Web.UI/App/navigation.vue | 2 +- zero.Web.UI/App/resources/modules.js | 7 +- zero.Web.UI/App/resources/pages.js | 4 +- zero.Web.UI/Sass/Canvas/_navigation.scss | 8 +- zero.Web.UI/Sass/Modules/Buttons/_button.scss | 2 + zero.Web/Controllers/BackofficeController.cs | 2 +- zero.Web/Controllers/ModulesController.cs | 15 ++++ zero.Web/Controllers/PagesController.cs | 2 +- 22 files changed, 289 insertions(+), 131 deletions(-) create mode 100644 zero.Debug/Renderers/module.headline.js rename zero.Debug/Renderers/{modules/richtext.module.js => module.richtext.js} (100%) create mode 100644 zero.Debug/Renderers/module.textwithimage.js delete mode 100644 zero.Debug/Renderers/modules/headline.module.js diff --git a/zero.Core/Api/RevisionsApi.cs b/zero.Core/Api/RevisionsApi.cs index f0672fcb..4e47db22 100644 --- a/zero.Core/Api/RevisionsApi.cs +++ b/zero.Core/Api/RevisionsApi.cs @@ -28,11 +28,15 @@ namespace zero.Core.Api /// /// Get revision list for an entity /// - public async Task> GetPaged(string id, int pageNumber = 1, int pageSize = 30, bool includeContent = false) where T : IZeroEntity + public async Task> GetPaged(string id, int pageNumber = 1, int pageSize = 10, bool includeContent = false) where T : IZeroEntity { using IAsyncDocumentSession session = Raven.OpenAsyncSession(); List items = await session.Advanced.Revisions.GetForAsync(id, pageNumber - 1, pageSize); + + List continuedItems = await session.Advanced.Revisions.GetForAsync(id, pageNumber, 1); + bool hasMore = continuedItems.Count > 0; + List revisions = new List(); string[] userIds = items.Select(x => x.LastModifiedById).Distinct().ToArray(); @@ -62,7 +66,7 @@ namespace zero.Core.Api revisions.Add(revision); } - return new ListResult(revisions, revisions.Count, pageNumber, pageSize); + return new ListResult(revisions, hasMore ? revisions.Count + 1 : revisions.Count, pageNumber, pageSize); } } @@ -72,6 +76,6 @@ namespace zero.Core.Api /// /// Get revision list (without content JSON) for an entity /// - Task> GetPaged(string id, int pageNumber = 1, int pageSize = 30, bool includeContent = false) where T : IZeroEntity; + Task> GetPaged(string id, int pageNumber = 1, int pageSize = 10, bool includeContent = false) where T : IZeroEntity; } } diff --git a/zero.Core/Api/Token.cs b/zero.Core/Api/Token.cs index 174fb6a3..b06e699b 100644 --- a/zero.Core/Api/Token.cs +++ b/zero.Core/Api/Token.cs @@ -26,7 +26,7 @@ namespace zero.Core.Api /// - public bool Verify(IZeroEntity entity, string token) + public bool Verify(IZeroIdEntity entity, string token) { return Verify(entity?.Id, token); } @@ -53,7 +53,7 @@ namespace zero.Core.Api /// - public string Get(IZeroEntity entity) + public string Get(IZeroIdEntity entity) { return Get(entity?.Id); } @@ -90,7 +90,7 @@ namespace zero.Core.Api /// /// Verifies if the change token is valid for the entity /// - bool Verify(IZeroEntity entity, string token); + bool Verify(IZeroIdEntity entity, string token); /// /// Verifies if the change token is valid for the entity @@ -100,7 +100,7 @@ namespace zero.Core.Api /// /// Get a new change token for the entity /// - string Get(IZeroEntity entity); + string Get(IZeroIdEntity entity); /// /// Get a new change token for the entity diff --git a/zero.Core/Entities/ListResult.cs b/zero.Core/Entities/ListResult.cs index 981553a5..cc28b359 100644 --- a/zero.Core/Entities/ListResult.cs +++ b/zero.Core/Entities/ListResult.cs @@ -23,6 +23,8 @@ namespace zero.Core.Entities { TotalPages = 1; } + + HasMore = TotalPages > Page; } public ListResult(IList items, long totalItems, long pageNumber, long pageSize) : this(totalItems, pageNumber, pageSize) @@ -46,6 +48,8 @@ namespace zero.Core.Entities public long TotalItems { get; private set; } + public bool HasMore { get; private set; } + public IList Items { get; set; } public List Statistics { get; set; } = new List(); diff --git a/zero.Debug/Renderers/module.headline.js b/zero.Debug/Renderers/module.headline.js new file mode 100644 index 00000000..15d2a6ae --- /dev/null +++ b/zero.Debug/Renderers/module.headline.js @@ -0,0 +1,34 @@ +export default { + alias: 'module.headline', + + // define layouts users can switch between + layouts: [ + { + label: 'Default', + preview: '/images/rte-layout1.png' + }, + { + label: 'Big', + preview: '/images/rte-layout2.png' + }, + ], + + // define a preview which is rendered in the overview + preview: { + template: '
' + }, + + fields: [ + { + field: 'headline', + display: 'text', + label: 'Headline', + required: true + }, + { + field: 'subline', + display: 'text', + label: 'Subline' + }, + ] +}; \ No newline at end of file diff --git a/zero.Debug/Renderers/modules/richtext.module.js b/zero.Debug/Renderers/module.richtext.js similarity index 100% rename from zero.Debug/Renderers/modules/richtext.module.js rename to zero.Debug/Renderers/module.richtext.js diff --git a/zero.Debug/Renderers/module.textwithimage.js b/zero.Debug/Renderers/module.textwithimage.js new file mode 100644 index 00000000..dd263824 --- /dev/null +++ b/zero.Debug/Renderers/module.textwithimage.js @@ -0,0 +1,34 @@ +export default { + alias: 'module.textWithImage', + + // define a preview which is rendered in the overview + preview: { + template: '
' + }, + + fields: [ + { + field: 'headline', + display: 'text', + label: 'Headline', + required: true + }, + { + field: 'text', + display: 'rte', + label: 'Text', + description: 'Enter a long-form text', + required: true + }, + { + field: 'isLeftAligned', + display: 'toggle', + label: 'Is left aligned' + }, + { + field: 'imageId', + display: 'media', + label: 'Image' + } + ] +}; \ No newline at end of file diff --git a/zero.Debug/Renderers/modules/headline.module.js b/zero.Debug/Renderers/modules/headline.module.js deleted file mode 100644 index f30ffb5a..00000000 --- a/zero.Debug/Renderers/modules/headline.module.js +++ /dev/null @@ -1,51 +0,0 @@ -import MetaFields from '../meta.partial'; - -export default { - alias: 'module.headline', - - // define layouts users can switch between - layouts: [ - { - label: 'Default', - preview: '/images/rte-layout1.png' - }, - { - label: 'Big', - preview: '/images/rte-layout2.png' - }, - ], - - // define a preview which is rendered in the overview - preview: { - template: '
' - }, - - tabs: [ - { - name: 'general', - label: '@ui.tab_content', - class: 'is-blank' - }, - { - name: 'meta', - label: 'Meta' - } - ], - - fields: [ - //{ - // field: 'name', - // display: 'text', - // label: '@ui.name', - // required: true - //}, - { - field: 'name', - display: 'modules', - label: '@ui.name', - required: true, - hideLabel: true, - class: 'ui-modules' - } - ].concat(MetaFields) -}; \ No newline at end of file diff --git a/zero.Debug/Renderers/page.content.js b/zero.Debug/Renderers/page.content.js index 295b27bc..cca2ddd5 100644 --- a/zero.Debug/Renderers/page.content.js +++ b/zero.Debug/Renderers/page.content.js @@ -16,14 +16,8 @@ export default { ], fields: [ - //{ - // field: 'name', - // display: 'text', - // label: '@ui.name', - // required: true - //}, { - field: 'name', + field: 'modules', display: 'modules', label: '@ui.name', required: true, diff --git a/zero.Debug/TestData/Pages/ContentPage.cs b/zero.Debug/TestData/Pages/ContentPage.cs index a333ef53..e714db18 100644 --- a/zero.Debug/TestData/Pages/ContentPage.cs +++ b/zero.Debug/TestData/Pages/ContentPage.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using zero.Core.Entities; namespace zero.TestData @@ -10,5 +11,7 @@ namespace zero.TestData public OptionsPagePartial Options { get; set; } = new OptionsPagePartial(); public string Text { get; set; } + + public List Modules { get; set; } = new List(); } } diff --git a/zero.Web.UI/App/components/forms/property.vue b/zero.Web.UI/App/components/forms/property.vue index 516f7af1..f3bc91ee 100644 --- a/zero.Web.UI/App/components/forms/property.vue +++ b/zero.Web.UI/App/components/forms/property.vue @@ -50,8 +50,9 @@ .ui-split + .ui-property, .ui-property + .ui-property { - padding-top: 30px; - margin-top: 30px; + margin-top: 50px; + //padding-top: 30px; + //margin-top: 30px; //border-top: 1px solid var(--color-line); } diff --git a/zero.Web.UI/App/components/loading.vue b/zero.Web.UI/App/components/loading.vue index ab4d2ed8..a0e6a99c 100644 --- a/zero.Web.UI/App/components/loading.vue +++ b/zero.Web.UI/App/components/loading.vue @@ -1,11 +1,18 @@  @@ -16,12 +23,17 @@ width: 28px; height: 28px; border-radius: 40px; - border: 2px solid var(--color-bg-mid); + border: 2px solid var(--color-bg-bright-two); border-left-color: var(--color-fg); - opacity: 1; will-change: transform; - animation: loadingRotation .8s linear infinite; - transition: opacity .25s ease; + animation: loadingRotation 0.8s linear infinite; + + &.is-big + { + width: 36px; + height: 36px; + border-width: 2px; + } } @keyframes loadingRotation diff --git a/zero.Web.UI/App/components/modules/edit-module.vue b/zero.Web.UI/App/components/modules/edit-module.vue index ba00aa46..04e76217 100644 --- a/zero.Web.UI/App/components/modules/edit-module.vue +++ b/zero.Web.UI/App/components/modules/edit-module.vue @@ -1,46 +1,66 @@  @@ -45,7 +101,7 @@ margin-top: var(--padding); } - .ui-modules-start + .ui-modules-start, .ui-module-item { margin: 0; padding: var(--padding); @@ -56,6 +112,17 @@ justify-content: center; } + .ui-module-item + { + display: block; + } + + .ui-module-item + .ui-module-item, + .ui-module-item + .ui-modules-start + { + margin-top: 3px; + } + .ui-modules-start-button { color: var(--color-fg); diff --git a/zero.Web.UI/App/navigation.vue b/zero.Web.UI/App/navigation.vue index 7ba0a8ef..37b40427 100644 --- a/zero.Web.UI/App/navigation.vue +++ b/zero.Web.UI/App/navigation.vue @@ -38,7 +38,7 @@ diff --git a/zero.Web.UI/App/resources/modules.js b/zero.Web.UI/App/resources/modules.js index d234e222..b324772e 100644 --- a/zero.Web.UI/App/resources/modules.js +++ b/zero.Web.UI/App/resources/modules.js @@ -12,5 +12,10 @@ export default { getModuleType(alias) { return Axios.get(base + 'getModuleType', { params: { alias } }).then(res => Promise.resolve(res.data)); - } + }, + + getEmpty(alias) + { + return Axios.get(base + 'getEmpty', { params: { alias } }).then(res => Promise.resolve(res.data)); + }, }; \ No newline at end of file diff --git a/zero.Web.UI/App/resources/pages.js b/zero.Web.UI/App/resources/pages.js index 36bd6510..9e60488d 100644 --- a/zero.Web.UI/App/resources/pages.js +++ b/zero.Web.UI/App/resources/pages.js @@ -24,9 +24,9 @@ export default { return Axios.get(base + 'getEmpty', { params: { type, parent } }).then(res => Promise.resolve(res.data)); }, - getRevisions(id) + getRevisions(id, page) { - return Axios.get(base + 'getRevisions', { params: { id } }).then(res => Promise.resolve(res.data)); + return Axios.get(base + 'getRevisions', { params: { id, page } }).then(res => Promise.resolve(res.data)); }, getAll(query) diff --git a/zero.Web.UI/Sass/Canvas/_navigation.scss b/zero.Web.UI/Sass/Canvas/_navigation.scss index 39a21f2b..9b2473c5 100644 --- a/zero.Web.UI/Sass/Canvas/_navigation.scss +++ b/zero.Web.UI/Sass/Canvas/_navigation.scss @@ -164,14 +164,14 @@ a.app-nav-child .-image { - height: 36px; - width: 36px; + height: 32px; + width: 32px; border-radius: 18px; position: relative; top: -1px; background: var(--color-bg-bright-two); text-align: center; - line-height: 37px; + line-height: 33px; font-size: 16px; } @@ -182,7 +182,7 @@ a.app-nav-child strong { - font-weight: 700; + font-weight: 400; color: var(--color-fg); } } diff --git a/zero.Web.UI/Sass/Modules/Buttons/_button.scss b/zero.Web.UI/Sass/Modules/Buttons/_button.scss index d6d9686b..86c02fa3 100644 --- a/zero.Web.UI/Sass/Modules/Buttons/_button.scss +++ b/zero.Web.UI/Sass/Modules/Buttons/_button.scss @@ -41,6 +41,8 @@ button::-moz-focus-inner padding: 0 20px; height: 42px; border-radius: var(--radius); + //border-bottom-left-radius: 15px; + //border-top-right-radius: 15px; font-size: var(--font-size); font-weight: 700; margin: 0; diff --git a/zero.Web/Controllers/BackofficeController.cs b/zero.Web/Controllers/BackofficeController.cs index 0a22a723..e64970ea 100644 --- a/zero.Web/Controllers/BackofficeController.cs +++ b/zero.Web/Controllers/BackofficeController.cs @@ -57,7 +57,7 @@ namespace zero.Web.Controllers /// /// Creates an edit model with appropriate options and permissions /// - public JsonResult Edit(T data, bool typed = true, Action transform = null) where T : IZeroEntity + public JsonResult Edit(T data, bool typed = true, Action transform = null) where T : IZeroIdEntity { Type type = typeof(T); bool canBeShared = AppAwareShareableType.IsAssignableFrom(type); diff --git a/zero.Web/Controllers/ModulesController.cs b/zero.Web/Controllers/ModulesController.cs index c131e7e4..0867097c 100644 --- a/zero.Web/Controllers/ModulesController.cs +++ b/zero.Web/Controllers/ModulesController.cs @@ -1,5 +1,8 @@ using Microsoft.AspNetCore.Mvc; +using System; using zero.Core.Api; +using zero.Core.Entities; +using zero.Core.Utils; namespace zero.Web.Controllers { @@ -16,5 +19,17 @@ namespace zero.Web.Controllers public IActionResult GetModuleTypes() => Json(Api.GetModuleTypes()); public IActionResult GetModuleType([FromQuery] string alias) => Json(Api.GetModuleType(alias)); + + public IActionResult GetEmpty(string alias) + { + ModuleType moduleType = Api.GetModuleType(alias); + IModule module = Activator.CreateInstance(moduleType.ContentType) as IModule; + + module.ModuleTypeAlias = moduleType.Alias; + module.Id = IdGenerator.Create(8); + module.IsActive = true; + + return Edit(module); + } } } diff --git a/zero.Web/Controllers/PagesController.cs b/zero.Web/Controllers/PagesController.cs index 1e716bba..0e755557 100644 --- a/zero.Web/Controllers/PagesController.cs +++ b/zero.Web/Controllers/PagesController.cs @@ -30,7 +30,7 @@ namespace zero.Web.Controllers ParentId = parent }); - public async Task GetRevisions([FromQuery] string id) => Json(await RevisionsApi.GetPaged(id)); + public async Task GetRevisions([FromQuery] string id, [FromQuery] int page = 1) => Json(await RevisionsApi.GetPaged(id, page)); public async Task Save([FromBody] T model) => Json(await Api.Save(model));