diff --git a/layout-service/src/main/java/io/meeds/layout/entity/PageTemplateEntity.java b/layout-service/src/main/java/io/meeds/layout/entity/PageTemplateEntity.java index 1a04dd9e7..450eb7bb0 100644 --- a/layout-service/src/main/java/io/meeds/layout/entity/PageTemplateEntity.java +++ b/layout-service/src/main/java/io/meeds/layout/entity/PageTemplateEntity.java @@ -40,9 +40,15 @@ public class PageTemplateEntity { @SequenceGenerator(name = "SEQ_PAGE_TEMPLATE_ID", sequenceName = "SEQ_PAGE_TEMPLATE_ID", allocationSize = 1) @GeneratedValue(strategy = GenerationType.AUTO, generator = "SEQ_PAGE_TEMPLATE_ID") @Column(name = "ID") - protected Long id; + protected Long id; + + @Column(name = "DISABLED") + private boolean disabled; + + @Column(name = "CATEGORY") + private String category; @Column(name = "CONTENT") - private String content; + private String content; } diff --git a/layout-service/src/main/java/io/meeds/layout/model/PageTemplate.java b/layout-service/src/main/java/io/meeds/layout/model/PageTemplate.java index 21a14b2b9..dc2fe3c13 100644 --- a/layout-service/src/main/java/io/meeds/layout/model/PageTemplate.java +++ b/layout-service/src/main/java/io/meeds/layout/model/PageTemplate.java @@ -27,19 +27,25 @@ @AllArgsConstructor public class PageTemplate { - private long id; + private long id; - private String content; + private boolean disabled; - private String name; + private String category; - private String description; + private String content; - private long illustrationId; + private String name; - public PageTemplate(long id, String content) { + private String description; + + private long illustrationId; + + public PageTemplate(long id, boolean disabled, String category, String content) { this.id = id; this.content = content; + this.disabled = disabled; + this.category = category; } } diff --git a/layout-service/src/main/java/io/meeds/layout/model/PageTemplateDescriptor.java b/layout-service/src/main/java/io/meeds/layout/model/PageTemplateDescriptor.java index aae40baca..5ce03c077 100644 --- a/layout-service/src/main/java/io/meeds/layout/model/PageTemplateDescriptor.java +++ b/layout-service/src/main/java/io/meeds/layout/model/PageTemplateDescriptor.java @@ -37,6 +37,8 @@ public class PageTemplateDescriptor { private Map descriptions; + private String category; + private String illustrationPath; private String layoutPath; diff --git a/layout-service/src/main/java/io/meeds/layout/service/PageLayoutService.java b/layout-service/src/main/java/io/meeds/layout/service/PageLayoutService.java index 2093fc652..feaeaf34b 100644 --- a/layout-service/src/main/java/io/meeds/layout/service/PageLayoutService.java +++ b/layout-service/src/main/java/io/meeds/layout/service/PageLayoutService.java @@ -291,6 +291,9 @@ private Page createPageInstance(String siteType, if (pageTemplate == null) { throw new ObjectNotFoundException("pageTemplate not found"); } + if (pageTemplate.isDisabled()) { + throw new IllegalArgumentException("pageTemplate with designated Id is disabled"); + } page = userPortalConfigService.createPageTemplate(EMPTY_PAGE_TEMPLATE, siteType, siteName); diff --git a/layout-service/src/main/java/io/meeds/layout/service/PageTemplateImportService.java b/layout-service/src/main/java/io/meeds/layout/service/PageTemplateImportService.java index 76dfeae1e..14569be5f 100644 --- a/layout-service/src/main/java/io/meeds/layout/service/PageTemplateImportService.java +++ b/layout-service/src/main/java/io/meeds/layout/service/PageTemplateImportService.java @@ -237,6 +237,7 @@ protected PageTemplate createPageTemplate(PageTemplateDescriptor d, long oldTemp pageTemplate = new PageTemplate(); isNew = true; } + pageTemplate.setCategory(d.getCategory()); try (InputStream is = configurationManager.getInputStream(d.getLayoutPath())) { String xml = IOUtil.getStreamContentAsString(is); Container layout = fromXML(xml); diff --git a/layout-service/src/main/java/io/meeds/layout/storage/PageTemplateStorage.java b/layout-service/src/main/java/io/meeds/layout/storage/PageTemplateStorage.java index 7328a9518..4f80a7906 100644 --- a/layout-service/src/main/java/io/meeds/layout/storage/PageTemplateStorage.java +++ b/layout-service/src/main/java/io/meeds/layout/storage/PageTemplateStorage.java @@ -37,28 +37,48 @@ public class PageTemplateStorage { public List getPageTemplates() { List entities = pageTemplateDAO.findAll(); - return entities.stream().map(entity -> new PageTemplate(entity.getId(), entity.getContent())).toList(); + return entities.stream() + .map(e -> new PageTemplate(e.getId(), + e.isDisabled(), + e.getCategory(), + e.getContent())) + .toList(); } public PageTemplate getPageTemplate(long id) { return pageTemplateDAO.findById(id) - .map(e -> new PageTemplate(e.getId(), e.getContent())) + .map(e -> new PageTemplate(e.getId(), + e.isDisabled(), + e.getCategory(), + e.getContent())) .orElse(null); } public PageTemplate createPageTemplate(PageTemplate pageTemplate) { - PageTemplateEntity entity = new PageTemplateEntity(null, pageTemplate.getContent()); + PageTemplateEntity entity = new PageTemplateEntity(null, + pageTemplate.isDisabled(), + pageTemplate.getCategory(), + pageTemplate.getContent()); entity = pageTemplateDAO.save(entity); - return new PageTemplate(entity.getId(), entity.getContent()); + return new PageTemplate(entity.getId(), + entity.isDisabled(), + entity.getCategory(), + entity.getContent()); } public PageTemplate updatePageTemplate(PageTemplate pageTemplate) throws ObjectNotFoundException { if (!pageTemplateDAO.existsById(pageTemplate.getId())) { throw new ObjectNotFoundException("Page template doesn't exist"); } - PageTemplateEntity entity = new PageTemplateEntity(pageTemplate.getId(), pageTemplate.getContent()); + PageTemplateEntity entity = new PageTemplateEntity(pageTemplate.getId(), + pageTemplate.isDisabled(), + pageTemplate.getCategory(), + pageTemplate.getContent()); entity = pageTemplateDAO.save(entity); - return new PageTemplate(entity.getId(), entity.getContent()); + return new PageTemplate(entity.getId(), + entity.isDisabled(), + entity.getCategory(), + entity.getContent()); } public void deletePageTemplate(long templateId) throws ObjectNotFoundException { diff --git a/layout-service/src/main/resources/changelog/layout-rdbms.db.changelog-1.0.0.xml b/layout-service/src/main/resources/changelog/layout-rdbms.db.changelog-1.0.0.xml index 3137dd2a8..927ef9a56 100644 --- a/layout-service/src/main/resources/changelog/layout-rdbms.db.changelog-1.0.0.xml +++ b/layout-service/src/main/resources/changelog/layout-rdbms.db.changelog-1.0.0.xml @@ -46,4 +46,37 @@ + + + + + + + + + + + + + + + ALTER TABLE LAYOUT_PAGE_TEMPLATES MODIFY COLUMN CONTENT LONGTEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + + + + + + ALTER TABLE LAYOUT_PAGE_TEMPLATES MODIFY COLUMN CATEGORY VARCHAR(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + + + \ No newline at end of file diff --git a/layout-service/src/test/java/io/meeds/layout/service/PageTemplateServiceTest.java b/layout-service/src/test/java/io/meeds/layout/service/PageTemplateServiceTest.java index ea7ecc8c6..ad52b090e 100644 --- a/layout-service/src/test/java/io/meeds/layout/service/PageTemplateServiceTest.java +++ b/layout-service/src/test/java/io/meeds/layout/service/PageTemplateServiceTest.java @@ -55,12 +55,14 @@ import io.meeds.social.translation.service.TranslationService; @SpringBootTest(classes = { - PageTemplateService.class, + PageTemplateService.class, }) @ExtendWith(MockitoExtension.class) public class PageTemplateServiceTest { - private static final String LAYOUT_CONTENT = "...layout..."; + private static final String LAYOUT_CONTENT = "...layout..."; + + private static final String LAYOUT_CATEGORY = "CATEGORY"; @MockBean private LayoutAclService layoutAclService; @@ -89,13 +91,13 @@ public class PageTemplateServiceTest { @Autowired private PageTemplateService pageTemplateService; - private String testuser = "testuser"; + private String testuser = "testuser"; @Test public void getPageTemplates() { when(pageTemplate.getId()).thenReturn(2l); when(pageTemplate.getContent()).thenReturn(LAYOUT_CONTENT); - + when(pageTemplateStorage.getPageTemplates()).thenReturn(Collections.singletonList(pageTemplate)); List pageTemplates = pageTemplateService.getPageTemplates(); assertNotNull(pageTemplates); @@ -109,7 +111,7 @@ public void getPageTemplates() { @Test public void getPageTemplatesWithExpand() throws ObjectNotFoundException { - PageTemplate template = new PageTemplate(2l, LAYOUT_CONTENT); + PageTemplate template = new PageTemplate(2l, false, LAYOUT_CATEGORY, LAYOUT_CONTENT); when(localeConfigService.getDefaultLocaleConfig()).thenReturn(defaultLocaleConfig); when(defaultLocaleConfig.getLocale()).thenReturn(Locale.ENGLISH); @@ -166,7 +168,8 @@ public void getPageTemplatesWithExpand() throws ObjectNotFoundException { assertEquals(1, pageTemplates.size()); assertEquals(enDesc, pageTemplates.get(0).getDescription()); - when(attachmentService.getAttachmentFileIds(PageTemplateAttachmentPlugin.OBJECT_TYPE, "2")).thenReturn(Collections.singletonList("32")); + when(attachmentService.getAttachmentFileIds(PageTemplateAttachmentPlugin.OBJECT_TYPE, + "2")).thenReturn(Collections.singletonList("32")); pageTemplates = pageTemplateService.getPageTemplates(Locale.GERMAN, true); assertNotNull(pageTemplates); assertEquals(1, pageTemplates.size()); @@ -196,7 +199,7 @@ public void createPageTemplate() throws IllegalAccessException { @Test public void deletePageTemplate() throws ObjectNotFoundException, IllegalAccessException { assertThrows(IllegalAccessException.class, () -> pageTemplateService.deletePageTemplate(2l, testuser)); - + when(layoutAclService.isAdministrator(testuser)).thenReturn(true); pageTemplateService.deletePageTemplate(2l, testuser); verify(attachmentService, times(1)).deleteAttachments(PageTemplateAttachmentPlugin.OBJECT_TYPE, "2"); diff --git a/layout-webapp/src/main/resources/locale/portlet/LayoutEditor_en.properties b/layout-webapp/src/main/resources/locale/portlet/LayoutEditor_en.properties index ededd1635..dff10c3dd 100644 --- a/layout-webapp/src/main/resources/locale/portlet/LayoutEditor_en.properties +++ b/layout-webapp/src/main/resources/locale/portlet/LayoutEditor_en.properties @@ -116,4 +116,5 @@ pageTemplates.add=Add pageTemplates.filter.placeholder=Filter by name, description pageTemplates.label.name=Name pageTemplates.label.description=Description +pageTemplates.label.category=Category pageTemplate.label.preview=Preview of {0} template diff --git a/layout-webapp/src/main/webapp/vue-app/common-layout-components/components/site-navigation/SiteNavigationPageElement.vue b/layout-webapp/src/main/webapp/vue-app/common-layout-components/components/site-navigation/SiteNavigationPageElement.vue index 873b51d67..5ea6b07f1 100644 --- a/layout-webapp/src/main/webapp/vue-app/common-layout-components/components/site-navigation/SiteNavigationPageElement.vue +++ b/layout-webapp/src/main/webapp/vue-app/common-layout-components/components/site-navigation/SiteNavigationPageElement.vue @@ -56,7 +56,7 @@ export default { getPageTemplates() { if (!this.$root.pageTemplates) { return this.$pageTemplateService.getPageTemplates() - .then(pageTemplates => this.$root.pageTemplates = pageTemplates || []); + .then(pageTemplates => this.$root.pageTemplates = pageTemplates && pageTemplates.filter(t => !t.disabled) || []); } }, }, diff --git a/layout-webapp/src/main/webapp/vue-app/page-templates-management/components/list/PageTemplateItem.vue b/layout-webapp/src/main/webapp/vue-app/page-templates-management/components/list/PageTemplateItem.vue index ced1f241e..c35aab3c3 100644 --- a/layout-webapp/src/main/webapp/vue-app/page-templates-management/components/list/PageTemplateItem.vue +++ b/layout-webapp/src/main/webapp/vue-app/page-templates-management/components/list/PageTemplateItem.vue @@ -11,9 +11,9 @@ + + {{ category }} + \ No newline at end of file diff --git a/layout-webapp/src/main/webapp/vue-app/page-templates-management/components/list/PageTemplates.vue b/layout-webapp/src/main/webapp/vue-app/page-templates-management/components/list/PageTemplates.vue index e40f79aac..fb1e8432a 100644 --- a/layout-webapp/src/main/webapp/vue-app/page-templates-management/components/list/PageTemplates.vue +++ b/layout-webapp/src/main/webapp/vue-app/page-templates-management/components/list/PageTemplates.vue @@ -54,6 +54,14 @@ export default { class: 'page-template-description-header', width: '70%' }, + { + text: this.$t('pageTemplates.label.category'), + value: 'category', + align: 'left', + sortable: false, + class: 'page-template-category-header', + width: '120px' + }, ]; }, filteredPageTemplates() {