Search in sources :

Example 6 with LayoutDescriptor

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

the class HtmlAreaContentProcessor method processComponent.

private void processComponent(final DescriptorBasedComponent component, final ContentIds.Builder processedIds) {
    if (component.hasDescriptor()) {
        if (component instanceof LayoutComponent) {
            final LayoutDescriptor layoutDescriptor = this.layoutDescriptorService.getByKey(component.getDescriptor());
            if (layoutDescriptor != null) {
                processComponentDescriptor(component, layoutDescriptor, processedIds);
            }
            final LayoutComponent layoutComponent = (LayoutComponent) component;
            if (layoutComponent.hasRegions()) {
                processRegionsData(layoutComponent.getRegions(), processedIds);
            }
        }
        if (component instanceof PartComponent) {
            final PartDescriptor partDescriptor = this.partDescriptorService.getByKey(component.getDescriptor());
            if (partDescriptor != null) {
                processComponentDescriptor(component, partDescriptor, processedIds);
            }
        }
    }
}
Also used : LayoutDescriptor(com.enonic.xp.region.LayoutDescriptor) PartDescriptor(com.enonic.xp.region.PartDescriptor) PartComponent(com.enonic.xp.region.PartComponent) LayoutComponent(com.enonic.xp.region.LayoutComponent)

Example 7 with LayoutDescriptor

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

the class LayoutRendererTest method nullResponseComponentEditMode.

@Test
public void nullResponseComponentEditMode() {
    final LayoutDescriptor layoutDescriptor = LayoutDescriptor.create().displayName("My layout component").config(Form.create().build()).key(DescriptorKey.from("module:myLayoutComponent")).regions(RegionDescriptors.create().add(RegionDescriptor.create().name("left").build()).add(RegionDescriptor.create().name("right").build()).build()).build();
    final ControllerScript controllerScript = new ControllerScript() {

        @Override
        public PortalResponse execute(final PortalRequest portalRequest) {
            return new PortalResponseSerializer(null).serialize();
        }

        @Override
        public void onSocketEvent(final WebSocketEvent event) {
        }
    };
    final LayoutDescriptorService layoutDescriptorService = Mockito.mock(LayoutDescriptorService.class);
    final ControllerScriptFactory controllerScriptFactory = Mockito.mock(ControllerScriptFactory.class);
    renderer = new LayoutRenderer();
    renderer.setLayoutDescriptorService(layoutDescriptorService);
    renderer.setControllerScriptFactory(controllerScriptFactory);
    when(layoutDescriptorService.getByKey(any())).thenReturn(layoutDescriptor);
    when(controllerScriptFactory.fromDir(any())).thenReturn(controllerScript);
    portalRequest.setMode(RenderMode.EDIT);
    layoutComponent = LayoutComponent.create().descriptor("myapp:myLayoutComponent").descriptor(layoutDescriptor.getKey()).build();
    // exercise
    portalResponse = renderer.render(layoutComponent, portalRequest);
    // verify
    String expected = "<div data-portal-component-type=\"layout\"></div>";
    assertEquals(expected, portalResponse.getAsString());
}
Also used : PortalResponseSerializer(com.enonic.xp.portal.impl.controller.PortalResponseSerializer) WebSocketEvent(com.enonic.xp.web.websocket.WebSocketEvent) LayoutDescriptor(com.enonic.xp.region.LayoutDescriptor) ControllerScript(com.enonic.xp.portal.controller.ControllerScript) ControllerScriptFactory(com.enonic.xp.portal.controller.ControllerScriptFactory) LayoutDescriptorService(com.enonic.xp.region.LayoutDescriptorService) PortalRequest(com.enonic.xp.portal.PortalRequest) Test(org.junit.jupiter.api.Test)

Example 8 with LayoutDescriptor

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

the class GetComponentByNameCommand method execute.

public Component execute() {
    final String componentDescriptorName = name.toString();
    final PartDescriptor partDescriptor = getPartDescriptor(componentDescriptorName);
    if (partDescriptor != null && componentExists(partDescriptor.getComponentPath())) {
        return PartComponent.create().descriptor(partDescriptor.getKey()).build();
    }
    final LayoutDescriptor layoutDescriptor = getLayoutDescriptor(componentDescriptorName);
    if (layoutDescriptor != null && componentExists(layoutDescriptor.getComponentPath())) {
        return LayoutComponent.create().descriptor(layoutDescriptor.getKey()).build();
    }
    return null;
}
Also used : LayoutDescriptor(com.enonic.xp.region.LayoutDescriptor) PartDescriptor(com.enonic.xp.region.PartDescriptor)

Example 9 with LayoutDescriptor

use of com.enonic.xp.region.LayoutDescriptor 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)

Example 10 with LayoutDescriptor

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

the class LayoutRendererTest method htmlResponseComponentEditMode.

@Test
public void htmlResponseComponentEditMode() {
    final LayoutDescriptor layoutDescriptor = LayoutDescriptor.create().displayName("My layout component").config(Form.create().build()).key(DescriptorKey.from("module:myLayoutComponent")).regions(RegionDescriptors.create().add(RegionDescriptor.create().name("left").build()).add(RegionDescriptor.create().name("right").build()).build()).build();
    final ControllerScript controllerScript = new ControllerScript() {

        @Override
        public PortalResponse execute(final PortalRequest portalRequest) {
            return PortalResponse.create().body("<div class=\"row\"><div data-portal-region=\"left\" class=\"col-left\"></div><div data-portal-region=\"right\" class=\"col-right\"></div></div>").contentType(MediaType.HTML_UTF_8).status(HttpStatus.OK).build();
        }

        @Override
        public void onSocketEvent(final WebSocketEvent event) {
        }
    };
    final LayoutDescriptorService layoutDescriptorService = Mockito.mock(LayoutDescriptorService.class);
    final ControllerScriptFactory controllerScriptFactory = Mockito.mock(ControllerScriptFactory.class);
    renderer = new LayoutRenderer();
    renderer.setLayoutDescriptorService(layoutDescriptorService);
    renderer.setControllerScriptFactory(controllerScriptFactory);
    when(layoutDescriptorService.getByKey(any())).thenReturn(layoutDescriptor);
    when(controllerScriptFactory.fromDir(any())).thenReturn(controllerScript);
    portalRequest.setMode(RenderMode.EDIT);
    layoutComponent = LayoutComponent.create().descriptor("myapp:myLayoutComponent").descriptor(layoutDescriptor.getKey()).build();
    // exercise
    portalResponse = renderer.render(layoutComponent, portalRequest);
    // verify
    String expected = "<div data-portal-component-type=\"layout\" class=\"row\"><div data-portal-region=\"left\" class=\"col-left\"></div><div data-portal-region=\"right\" class=\"col-right\"></div></div>";
    assertEquals(expected, portalResponse.getAsString());
}
Also used : WebSocketEvent(com.enonic.xp.web.websocket.WebSocketEvent) LayoutDescriptor(com.enonic.xp.region.LayoutDescriptor) ControllerScript(com.enonic.xp.portal.controller.ControllerScript) ControllerScriptFactory(com.enonic.xp.portal.controller.ControllerScriptFactory) LayoutDescriptorService(com.enonic.xp.region.LayoutDescriptorService) PortalRequest(com.enonic.xp.portal.PortalRequest) Test(org.junit.jupiter.api.Test)

Aggregations

LayoutDescriptor (com.enonic.xp.region.LayoutDescriptor)12 PartDescriptor (com.enonic.xp.region.PartDescriptor)5 Test (org.junit.jupiter.api.Test)5 Form (com.enonic.xp.form.Form)4 LayoutComponent (com.enonic.xp.region.LayoutComponent)3 PartComponent (com.enonic.xp.region.PartComponent)3 PropertyTree (com.enonic.xp.data.PropertyTree)2 DescriptorKey (com.enonic.xp.page.DescriptorKey)2 PortalRequest (com.enonic.xp.portal.PortalRequest)2 ControllerScript (com.enonic.xp.portal.controller.ControllerScript)2 ControllerScriptFactory (com.enonic.xp.portal.controller.ControllerScriptFactory)2 LayoutDescriptorService (com.enonic.xp.region.LayoutDescriptorService)2 WebSocketEvent (com.enonic.xp.web.websocket.WebSocketEvent)2 EditableContent (com.enonic.xp.content.EditableContent)1 AbstractDescriptorServiceTest (com.enonic.xp.core.impl.content.page.AbstractDescriptorServiceTest)1 PropertySet (com.enonic.xp.data.PropertySet)1 Page (com.enonic.xp.page.Page)1 PageDescriptor (com.enonic.xp.page.PageDescriptor)1 PortalResponseSerializer (com.enonic.xp.portal.impl.controller.PortalResponseSerializer)1 LayoutRegions (com.enonic.xp.region.LayoutRegions)1