Search in sources :

Example 6 with PageDescriptor

use of com.enonic.xp.page.PageDescriptor in project xp by enonic.

the class HtmlAreaContentProcessorTest method page_config_data.

@Test
public void page_config_data() throws IOException {
    final PropertyTree data = new PropertyTree();
    data.addProperty("htmlData", ValueFactory.newString("<img data-src=\"image://image-id\"/>"));
    final Form form = Form.create().addFormItem(Input.create().name("htmlData").label("htmlData").inputType(InputTypeName.HTML_AREA).build()).build();
    final PageDescriptor pageDescriptor = PageDescriptor.create().config(form).regions(RegionDescriptors.create().build()).key(DescriptorKey.from("aaa:bbb")).build();
    Mockito.when(pageDescriptorService.getByKey(Mockito.isA(DescriptorKey.class))).thenReturn(pageDescriptor);
    final Page page = Page.create().config(data).descriptor(pageDescriptor.getKey()).build();
    final EditableContent editableContent = new EditableContent(Media.create().name("myContentName").type(contentTypeName).page(page).parentPath(ContentPath.ROOT).data(new PropertyTree()).build());
    result.getEditor().edit(editableContent);
    assertEquals(1, editableContent.processedReferences.build().getSize());
    assertTrue(editableContent.processedReferences.build().contains(ContentId.from("image-id")));
}
Also used : PageDescriptor(com.enonic.xp.page.PageDescriptor) Form(com.enonic.xp.form.Form) PropertyTree(com.enonic.xp.data.PropertyTree) EditableContent(com.enonic.xp.content.EditableContent) DescriptorKey(com.enonic.xp.page.DescriptorKey) Page(com.enonic.xp.page.Page) Test(org.junit.jupiter.api.Test)

Example 7 with PageDescriptor

use of com.enonic.xp.page.PageDescriptor in project xp by enonic.

the class XmlPageDescriptorParserTest method assertResult.

private void assertResult() throws Exception {
    final PageDescriptor result = this.builder.build();
    assertEquals("myapplication:mypage", result.getKey().toString());
    assertEquals("mypage", result.getName());
    assertEquals("Landing page", result.getDisplayName());
    assertEquals("key.display-name", result.getDisplayNameI18nKey());
    assertEquals("My Page Description", result.getDescription());
    assertEquals("key.description", result.getDescriptionI18nKey());
    final Form config = result.getConfig();
    assertNotNull(config);
    assertEquals(InputTypeName.DOUBLE, config.getFormItem("pause").toInput().getInputType());
    assertEquals("Pause parameter", config.getFormItem("pause").toInput().getLabel());
    assertEquals("key1.label", config.getFormItem("pause").toInput().getLabelI18nKey());
    assertEquals("key1.help-text", config.getFormItem("pause").toInput().getHelpTextI18nKey());
    assertNotNull(config.getFormItem("myFormItemSet").toFormItemSet());
    assertEquals("My form item set", config.getFormItem("myFormItemSet").toFormItemSet().getLabel());
    assertEquals(InputTypeName.TEXT_LINE, config.getFormItem("myFormItemSet.fieldSetItem").toInput().getInputType());
    assertEquals("Field set Item", config.getFormItem("myFormItemSet.fieldSetItem").toInput().getLabel());
    assertEquals("key2.label", config.getFormItem("myFormItemSet.fieldSetItem").toInput().getLabelI18nKey());
    assertEquals("key2.help-text", config.getFormItem("myFormItemSet.fieldSetItem").toInput().getHelpTextI18nKey());
    final RegionDescriptors regions = result.getRegions();
    assertNotNull(regions);
    assertEquals(3, regions.numberOfRegions());
    assertNotNull(regions.getRegionDescriptor("header"));
}
Also used : PageDescriptor(com.enonic.xp.page.PageDescriptor) Form(com.enonic.xp.form.Form) RegionDescriptors(com.enonic.xp.region.RegionDescriptors)

Example 8 with PageDescriptor

use of com.enonic.xp.page.PageDescriptor in project xp by enonic.

the class ApplicationInfoServiceImplTest method mockPageDescriptors.

private void mockPageDescriptors(final ApplicationKey applicationKey) {
    final PageDescriptor pageDescriptor1 = PageDescriptor.create().displayName("Landing page").config(Form.create().build()).regions(RegionDescriptors.create().build()).key(DescriptorKey.from("module:landing-page")).build();
    final PageDescriptor pageDescriptor2 = PageDescriptor.create().displayName("Log out").config(Form.create().build()).regions(RegionDescriptors.create().build()).key(DescriptorKey.from("module:logout-page")).build();
    final PageDescriptors pageDescriptors = PageDescriptors.from(pageDescriptor1, pageDescriptor2);
    Mockito.when(pageDescriptorService.getByApplication(applicationKey)).thenReturn(pageDescriptors);
}
Also used : PageDescriptor(com.enonic.xp.page.PageDescriptor) PageDescriptors(com.enonic.xp.page.PageDescriptors)

Example 9 with PageDescriptor

use of com.enonic.xp.page.PageDescriptor in project xp by enonic.

the class PageDescriptorServiceImpl method getByKey.

@Override
public PageDescriptor getByKey(final DescriptorKey key) {
    final ResourceProcessor<DescriptorKey, PageDescriptor> processor = newProcessor(key);
    final PageDescriptor descriptor = this.resourceService.processResource(processor);
    if (descriptor == null) {
        return createDefaultDescriptor(key);
    }
    return PageDescriptor.copyOf(descriptor).config(this.mixinService.inlineFormItems(descriptor.getConfig())).build();
}
Also used : PageDescriptor(com.enonic.xp.page.PageDescriptor) DescriptorKey(com.enonic.xp.page.DescriptorKey)

Example 10 with PageDescriptor

use of com.enonic.xp.page.PageDescriptor in project xp by enonic.

the class PageDefaultValuesProcessor method applyPageDefaultValues.

private void applyPageDefaultValues(final Page editedPage) {
    final PropertyTree pageData = editedPage.getConfig();
    if (editedPage.getDescriptor() == null) {
        return;
    }
    final PageDescriptor pageForm = pageDescriptorService.getByKey(editedPage.getDescriptor());
    if (pageForm == null || pageForm.getConfig() == null) {
        return;
    }
    formDefaultValuesProcessor.setDefaultValues(pageForm.getConfig(), pageData);
}
Also used : PageDescriptor(com.enonic.xp.page.PageDescriptor) PropertyTree(com.enonic.xp.data.PropertyTree)

Aggregations

PageDescriptor (com.enonic.xp.page.PageDescriptor)15 Page (com.enonic.xp.page.Page)6 PropertyTree (com.enonic.xp.data.PropertyTree)5 Test (org.junit.jupiter.api.Test)5 EditableContent (com.enonic.xp.content.EditableContent)4 Form (com.enonic.xp.form.Form)4 DescriptorKey (com.enonic.xp.page.DescriptorKey)4 PartComponent (com.enonic.xp.region.PartComponent)2 PartDescriptor (com.enonic.xp.region.PartDescriptor)2 RegionDescriptors (com.enonic.xp.region.RegionDescriptors)2 ApplicationKey (com.enonic.xp.app.ApplicationKey)1 Content (com.enonic.xp.content.Content)1 ContentId (com.enonic.xp.content.ContentId)1 Property (com.enonic.xp.data.Property)1 PageDescriptors (com.enonic.xp.page.PageDescriptors)1 PageRegions (com.enonic.xp.page.PageRegions)1 PortalResponse (com.enonic.xp.portal.PortalResponse)1 RenderMode (com.enonic.xp.portal.RenderMode)1 ControllerScript (com.enonic.xp.portal.controller.ControllerScript)1 LayoutComponent (com.enonic.xp.region.LayoutComponent)1