Search in sources :

Example 6 with PartComponent

use of com.enonic.xp.region.PartComponent in project xp by enonic.

the class HtmlAreaContentProcessorTest method component_config_data.

@Test
public void component_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 PartDescriptor partDescriptor = PartDescriptor.create().key(DescriptorKey.from("app:part")).config(form).build();
    Mockito.when(partDescriptorService.getByKey(partDescriptor.getKey())).thenReturn(partDescriptor);
    final PartComponent partComponent = PartComponent.create().descriptor("myapp:part").descriptor(partDescriptor.getKey()).config(data).build();
    final PageDescriptor pageDescriptor = PageDescriptor.create().regions(RegionDescriptors.create().add(RegionDescriptor.create().name("region").build()).build()).key(DescriptorKey.from("app:page")).config(Form.create().build()).build();
    Mockito.when(pageDescriptorService.getByKey(pageDescriptor.getKey())).thenReturn(pageDescriptor);
    final Page page = Page.create().config(new PropertyTree()).descriptor(pageDescriptor.getKey()).regions(PageRegions.create().add(Region.create().name("region").add(partComponent).build()).build()).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) PartDescriptor(com.enonic.xp.region.PartDescriptor) PropertyTree(com.enonic.xp.data.PropertyTree) EditableContent(com.enonic.xp.content.EditableContent) Page(com.enonic.xp.page.Page) PartComponent(com.enonic.xp.region.PartComponent) Test(org.junit.jupiter.api.Test)

Example 7 with PartComponent

use of com.enonic.xp.region.PartComponent in project xp by enonic.

the class PortalUrlServiceImpl_componentUrlTest method addComponent.

private void addComponent() {
    final PartComponent component = PartComponent.create().descriptor("myapp:mycomp").build();
    final Region region = Region.create().name("main").add(component).build();
    this.portalRequest.setComponent(component);
}
Also used : Region(com.enonic.xp.region.Region) PartComponent(com.enonic.xp.region.PartComponent)

Example 8 with PartComponent

use of com.enonic.xp.region.PartComponent in project xp by enonic.

the class PartComponentDataSerializer method fromData.

@Override
public PartComponent fromData(final PropertySet data) {
    final PartComponent.Builder component = PartComponent.create();
    final PropertySet specialBlockSet = data.getSet(PartComponentType.INSTANCE.toString());
    if (specialBlockSet != null && specialBlockSet.isNotNull(DESCRIPTOR)) {
        final DescriptorKey descriptorKey = DescriptorKey.from(specialBlockSet.getString(DESCRIPTOR));
        component.descriptor(descriptorKey);
        component.config(getConfigFromData(specialBlockSet, descriptorKey));
    }
    return component.build();
}
Also used : PropertySet(com.enonic.xp.data.PropertySet) DescriptorKey(com.enonic.xp.page.DescriptorKey) PartComponent(com.enonic.xp.region.PartComponent)

Example 9 with PartComponent

use of com.enonic.xp.region.PartComponent in project xp by enonic.

the class PageRegionsConfigProcessorTest method processPage.

private PatternIndexConfigDocument processPage(final Page page, final ListIterator<Form> partForms, final ListIterator<Form> layoutForms) {
    final RegionDescriptors.Builder regionDescriptorsBuilder = RegionDescriptors.create();
    page.getRegions().forEach(region -> {
        region.getComponents().forEach(component -> {
            if (PartComponentType.INSTANCE == component.getType()) {
                if (partForms != null && partForms.hasNext()) {
                    final PartComponent partComponent = (PartComponent) component;
                    Mockito.when(partDescriptorService.getByKey(partComponent.getDescriptor())).thenReturn(PartDescriptor.create().key(partComponent.getDescriptor()).config(partForms.next()).build());
                }
            } else if (LayoutComponentType.INSTANCE == component.getType()) {
                if (layoutForms != null && layoutForms.hasNext()) {
                    final LayoutComponent layoutComponent = (LayoutComponent) component;
                    Mockito.when(layoutDescriptorService.getByKey(layoutComponent.getDescriptor())).thenReturn(LayoutDescriptor.create().key(layoutComponent.getDescriptor()).config(layoutForms.next()).regions(RegionDescriptors.create().build()).build());
                    if (layoutComponent.hasRegions()) {
                        processLayoutRegions(layoutComponent.getRegions(), partForms);
                    }
                }
            }
        });
        regionDescriptorsBuilder.add(RegionDescriptor.create().name(region.getName()).build());
    });
    final PageRegionsConfigProcessor configProcessor = new PageRegionsConfigProcessor(page, partDescriptorService, layoutDescriptorService);
    return configProcessor.processDocument(PatternIndexConfigDocument.create()).build();
}
Also used : RegionDescriptors(com.enonic.xp.region.RegionDescriptors) PartComponent(com.enonic.xp.region.PartComponent) LayoutComponent(com.enonic.xp.region.LayoutComponent)

Example 10 with PartComponent

use of com.enonic.xp.region.PartComponent in project xp by enonic.

the class HtmlAreaContentProcessorTest method inner_component_data.

@Test
public void inner_component_data() throws IOException {
    final PropertyTree data1 = new PropertyTree();
    data1.addProperty("htmlData", ValueFactory.newString("<img data-src=\"image://image-id1\"/>"));
    final PropertyTree data2 = new PropertyTree();
    data2.addProperty("htmlData", ValueFactory.newString("<img data-src=\"image://image-id2\"/>"));
    final Form form = Form.create().addFormItem(Input.create().name("htmlData").label("htmlData").inputType(InputTypeName.HTML_AREA).build()).build();
    final PartDescriptor partDescriptor = PartDescriptor.create().key(DescriptorKey.from("app:part")).config(form).build();
    Mockito.when(partDescriptorService.getByKey(partDescriptor.getKey())).thenReturn(partDescriptor);
    final PartComponent partComponent = PartComponent.create().descriptor("myapp:partest").descriptor(partDescriptor.getKey()).config(data2).build();
    final LayoutDescriptor layoutDescriptor = LayoutDescriptor.create().key(DescriptorKey.from("app:layout")).config(form).regions(RegionDescriptors.create().add(RegionDescriptor.create().name("part").build()).build()).build();
    Mockito.when(layoutDescriptorService.getByKey(layoutDescriptor.getKey())).thenReturn(layoutDescriptor);
    final LayoutComponent layoutComponent = LayoutComponent.create().descriptor("myapp:layout").descriptor(layoutDescriptor.getKey()).regions(LayoutRegions.create().add(Region.create().name("part").add(partComponent).build()).build()).config(data1).build();
    final PageDescriptor pageDescriptor = PageDescriptor.create().regions(RegionDescriptors.create().add(RegionDescriptor.create().name("region").build()).build()).key(DescriptorKey.from("app:page")).config(Form.create().build()).build();
    Mockito.when(pageDescriptorService.getByKey(pageDescriptor.getKey())).thenReturn(pageDescriptor);
    final Page page = Page.create().config(new PropertyTree()).descriptor(pageDescriptor.getKey()).regions(PageRegions.create().add(Region.create().name("region").add(layoutComponent).build()).build()).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(2, editableContent.processedReferences.build().getSize());
    assertTrue(editableContent.processedReferences.build().contains(ContentId.from("image-id1")));
    assertTrue(editableContent.processedReferences.build().contains(ContentId.from("image-id2")));
}
Also used : PageDescriptor(com.enonic.xp.page.PageDescriptor) LayoutDescriptor(com.enonic.xp.region.LayoutDescriptor) Form(com.enonic.xp.form.Form) PartDescriptor(com.enonic.xp.region.PartDescriptor) PropertyTree(com.enonic.xp.data.PropertyTree) EditableContent(com.enonic.xp.content.EditableContent) Page(com.enonic.xp.page.Page) PartComponent(com.enonic.xp.region.PartComponent) LayoutComponent(com.enonic.xp.region.LayoutComponent) Test(org.junit.jupiter.api.Test)

Aggregations

PartComponent (com.enonic.xp.region.PartComponent)11 PropertyTree (com.enonic.xp.data.PropertyTree)5 LayoutComponent (com.enonic.xp.region.LayoutComponent)5 PartDescriptor (com.enonic.xp.region.PartDescriptor)4 Test (org.junit.jupiter.api.Test)4 Form (com.enonic.xp.form.Form)3 Page (com.enonic.xp.page.Page)3 LayoutDescriptor (com.enonic.xp.region.LayoutDescriptor)3 EditableContent (com.enonic.xp.content.EditableContent)2 AbstractDescriptorServiceTest (com.enonic.xp.core.impl.content.page.AbstractDescriptorServiceTest)2 PageDescriptor (com.enonic.xp.page.PageDescriptor)2 Component (com.enonic.xp.region.Component)2 Region (com.enonic.xp.region.Region)2 PropertySet (com.enonic.xp.data.PropertySet)1 DescriptorKey (com.enonic.xp.page.DescriptorKey)1 PageRegions (com.enonic.xp.page.PageRegions)1 RegionDescriptors (com.enonic.xp.region.RegionDescriptors)1