Search in sources :

Example 1 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 2 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 3 with LayoutDescriptor

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

the class XmlLayoutDescriptorParserTest method assertResult.

private void assertResult() throws Exception {
    final LayoutDescriptor result = this.builder.build();
    assertEquals("myapplication:mylayout", result.getKey().toString());
    assertEquals("mylayout", result.getName());
    assertEquals("My Layout", result.getDisplayName());
    assertEquals("key.display-name", result.getDisplayNameI18nKey());
    assertEquals("My Layout 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 : LayoutDescriptor(com.enonic.xp.region.LayoutDescriptor) Form(com.enonic.xp.form.Form) RegionDescriptors(com.enonic.xp.region.RegionDescriptors)

Example 4 with LayoutDescriptor

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

the class ApplicationInfoServiceImplTest method mockLayoutDescriptors.

private void mockLayoutDescriptors(final ApplicationKey applicationKey) {
    final LayoutDescriptor layoutDescriptor1 = LayoutDescriptor.create().displayName("Fancy layout").config(Form.create().build()).regions(RegionDescriptors.create().add(RegionDescriptor.create().name("left").build()).add(RegionDescriptor.create().name("right").build()).build()).key(DescriptorKey.from("application:fancy-layout")).build();
    final LayoutDescriptor layoutDescriptor2 = LayoutDescriptor.create().displayName("Putty layout").config(Form.create().build()).regions(RegionDescriptors.create().add(RegionDescriptor.create().name("top").build()).add(RegionDescriptor.create().name("bottom").build()).build()).key(DescriptorKey.from("application:putty-layout")).build();
    Mockito.when(layoutDescriptorService.getByApplication(applicationKey)).thenReturn(LayoutDescriptors.from(layoutDescriptor1, layoutDescriptor2));
}
Also used : LayoutDescriptor(com.enonic.xp.region.LayoutDescriptor)

Example 5 with LayoutDescriptor

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

the class PageDefaultValuesProcessor method applyComponentDefaultValues.

private void applyComponentDefaultValues(final DescriptorBasedComponent cmp) {
    if (cmp.getDescriptor() == null) {
        return;
    }
    final Form cmpForm;
    if (cmp instanceof PartComponent) {
        final PartDescriptor partDescriptor = partDescriptorService.getByKey(cmp.getDescriptor());
        cmpForm = partDescriptor.getConfig();
    } else {
        final LayoutDescriptor layoutDescriptor = layoutDescriptorService.getByKey(cmp.getDescriptor());
        cmpForm = layoutDescriptor.getConfig();
    }
    if (cmpForm != null) {
        final PropertyTree cmpData = cmp.getConfig();
        formDefaultValuesProcessor.setDefaultValues(cmpForm, cmpData);
    }
}
Also used : LayoutDescriptor(com.enonic.xp.region.LayoutDescriptor) Form(com.enonic.xp.form.Form) PartDescriptor(com.enonic.xp.region.PartDescriptor) PropertyTree(com.enonic.xp.data.PropertyTree) PartComponent(com.enonic.xp.region.PartComponent)

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