Search in sources :

Example 1 with ComponentOption

use of com.qcadoo.view.internal.ComponentOption in project qcadoo by qcadoo.

the class GridComponentPatternTest method shouldHaveDefaultValues.

@Test
public void shouldHaveDefaultValues() throws Exception {
    // given
    DataDefinition dataDefinition = mock(DataDefinition.class);
    InternalViewDefinition viewDefinition = mock(InternalViewDefinition.class);
    given(viewDefinition.getDataDefinition()).willReturn(dataDefinition);
    ComponentDefinition componentDefinition = getComponentDefinition(QcadooViewConstants.L_GRID, viewDefinition);
    componentDefinition.setTranslationService(translationService);
    componentDefinition.setApplicationContext(applicationContext);
    GridComponentPattern pattern = new GridComponentPattern(componentDefinition);
    pattern.addOption(new ComponentOption("order", ImmutableMap.of("column", "name", "direction", "asc")));
    // when
    pattern.initialize();
    // then
    JSONObject options = getJsOptions(pattern);
    assertFalse(options.has("correspondingView"));
    assertFalse(options.has("correspondingComponent"));
    assertFalse(options.has("belongsToFieldName"));
    assertTrue(options.getBoolean("paginable"));
    assertFalse(options.getBoolean("lookup"));
    assertFalse(options.getBoolean("creatable"));
    assertFalse(options.getBoolean("deletable"));
    assertFalse(options.getBoolean("prioritizable"));
    assertFalse(options.getBoolean("fullscreen"));
    assertEquals(300, options.getInt("width"));
    assertEquals(300, options.getInt("height"));
    assertEquals(0, options.getJSONArray("orderableColumns").length());
    assertEquals(0, options.getJSONArray("searchableColumns").length());
    assertEquals(0, options.getJSONArray("columns").length());
}
Also used : GridComponentPattern(com.qcadoo.view.internal.components.grid.GridComponentPattern) JSONObject(org.json.JSONObject) InternalViewDefinition(com.qcadoo.view.internal.api.InternalViewDefinition) ComponentOption(com.qcadoo.view.internal.ComponentOption) DataDefinition(com.qcadoo.model.api.DataDefinition) ComponentDefinition(com.qcadoo.view.internal.ComponentDefinition) AbstractPatternTest(com.qcadoo.view.internal.patterns.AbstractPatternTest) Test(org.junit.Test)

Example 2 with ComponentOption

use of com.qcadoo.view.internal.ComponentOption in project qcadoo by qcadoo.

the class GridComponentPatternTest method shouldParsePredefinedFilters.

@Test
public void shouldParsePredefinedFilters() throws Exception {
    // given
    DataDefinition dataDefinition = mock(DataDefinition.class);
    InternalViewDefinition viewDefinition = mock(InternalViewDefinition.class);
    SecurityRolesService securityRolesService = mock(SecurityRolesService.class);
    given(viewDefinition.getDataDefinition()).willReturn(dataDefinition);
    ComponentDefinition componentDefinition = getComponentDefinition(QcadooViewConstants.L_GRID, viewDefinition);
    componentDefinition.setTranslationService(translationService);
    componentDefinition.setApplicationContext(applicationContext);
    GridComponentPattern pattern = new GridComponentPattern(componentDefinition);
    pattern.addOption(new ComponentOption("order", ImmutableMap.of("column", "name", "direction", "asc")));
    ViewDefinitionParser parser = new ViewDefinitionParserImpl();
    setField(parser, "securityRolesService", securityRolesService);
    DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    Document doc = builder.newDocument();
    Node componentNode = doc.createElement("root");
    Node predefinedFiltersNode = doc.createElement("predefinedFilters");
    componentNode.appendChild(predefinedFiltersNode);
    Element predefinedFilter1 = doc.createElement("predefinedFilter");
    predefinedFilter1.setAttribute("name", "filter1");
    predefinedFiltersNode.appendChild(predefinedFilter1);
    Element predefinedFilter2 = doc.createElement("predefinedFilter");
    predefinedFilter2.setAttribute("name", "filter2");
    predefinedFiltersNode.appendChild(predefinedFilter2);
    Element orderNode = doc.createElement("filterOrder");
    orderNode.setAttribute("column", "testCol");
    orderNode.setAttribute("direction", "desc");
    predefinedFilter2.appendChild(orderNode);
    Element filterNode1 = doc.createElement("filterRestriction");
    filterNode1.setAttribute("column", "testCol1");
    filterNode1.setAttribute("value", "testVal1");
    predefinedFilter2.appendChild(filterNode1);
    Element filterNode2 = doc.createElement("filterRestriction");
    filterNode2.setAttribute("column", "testCol2");
    filterNode2.setAttribute("value", "testVal2");
    predefinedFilter2.appendChild(filterNode2);
    pattern.initialize();
    // when
    pattern.parse(componentNode, parser);
    // then
    JSONObject options = getJsOptions(pattern);
    JSONArray filtersArray = options.getJSONArray("predefinedFilters");
    assertNotNull(filtersArray);
    assertEquals(2, filtersArray.length());
    assertEquals("filter1", filtersArray.getJSONObject(0).get("label"));
    assertEquals("name", filtersArray.getJSONObject(0).get("orderColumn"));
    assertEquals("asc", filtersArray.getJSONObject(0).get("orderDirection"));
    assertEquals(0, filtersArray.getJSONObject(0).getJSONObject("filter").length());
    assertEquals("filter2", filtersArray.getJSONObject(1).get("label"));
    assertEquals("testCol", filtersArray.getJSONObject(1).get("orderColumn"));
    assertEquals("desc", filtersArray.getJSONObject(1).get("orderDirection"));
    assertEquals(2, filtersArray.getJSONObject(1).getJSONObject("filter").length());
    assertEquals("testVal1", filtersArray.getJSONObject(1).getJSONObject("filter").getString("testCol1"));
    assertEquals("testVal2", filtersArray.getJSONObject(1).getJSONObject("filter").getString("testCol2"));
}
Also used : InternalViewDefinition(com.qcadoo.view.internal.api.InternalViewDefinition) ComponentOption(com.qcadoo.view.internal.ComponentOption) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) JSONArray(org.json.JSONArray) Document(org.w3c.dom.Document) DataDefinition(com.qcadoo.model.api.DataDefinition) ViewDefinitionParserImpl(com.qcadoo.view.internal.xml.ViewDefinitionParserImpl) GridComponentPattern(com.qcadoo.view.internal.components.grid.GridComponentPattern) JSONObject(org.json.JSONObject) DocumentBuilder(javax.xml.parsers.DocumentBuilder) SecurityRolesService(com.qcadoo.security.api.SecurityRolesService) ViewDefinitionParser(com.qcadoo.view.internal.xml.ViewDefinitionParser) ComponentDefinition(com.qcadoo.view.internal.ComponentDefinition) AbstractPatternTest(com.qcadoo.view.internal.patterns.AbstractPatternTest) Test(org.junit.Test)

Example 3 with ComponentOption

use of com.qcadoo.view.internal.ComponentOption in project qcadoo by qcadoo.

the class GridComponentPatternTest method shouldNotFilterOutColumnsVisibleForTenant.

@Test
public void shouldNotFilterOutColumnsVisibleForTenant() throws Exception {
    // given
    PluginStateResolver pluginStateResolver = mock(PluginStateResolver.class);
    PluginUtilsService pluginUtil = new PluginUtilsService(pluginStateResolver);
    pluginUtil.init();
    given(pluginStateResolver.isEnabled("disabledPlugin")).willReturn(true);
    InternalViewDefinitionState viewDefinitionState = mock(InternalViewDefinitionState.class);
    DataDefinition dataDefinition = mock(DataDefinition.class);
    InternalViewDefinition viewDefinition = mock(InternalViewDefinition.class);
    given(viewDefinition.getDataDefinition()).willReturn(dataDefinition);
    ComponentDefinition componentDefinition = getComponentDefinition(QcadooViewConstants.L_GRID, viewDefinition);
    componentDefinition.setTranslationService(translationService);
    componentDefinition.setApplicationContext(applicationContext);
    componentDefinition.setDataDefinition(dataDefinition);
    GridComponentPattern pattern = new GridComponentPattern(componentDefinition);
    FieldDefinition nameFieldDefinition = mock(FieldDefinition.class);
    given(nameFieldDefinition.getType()).willReturn(new EnumType(translationService, "", true, "v1", "v2"));
    given(dataDefinition.getField("name")).willReturn(nameFieldDefinition);
    pattern.addOption(new ComponentOption("column", ImmutableMap.of("name", "name", "fields", "name", "hidden", "true")));
    pattern.addOption(new ComponentOption("order", ImmutableMap.of("column", "name", "direction", "asc")));
    ViewGridColumnModuleColumnModel columnModel = new ViewGridColumnModuleColumnModel("invisible", "name");
    columnModel.setWidth(100);
    pattern.addColumn("disabledPlugin", columnModel);
    pattern.initialize();
    // when
    ComponentState state = pattern.createComponentState(viewDefinitionState);
    // then
    assertTrue(state instanceof GridComponent);
    @SuppressWarnings("unchecked") Map<String, GridComponentColumn> patternColumns = (Map<String, GridComponentColumn>) getField(pattern, "columns");
    @SuppressWarnings("unchecked") Map<String, GridComponentColumn> stateColumns = (Map<String, GridComponentColumn>) getField(state, "columns");
    assertEquals(2, patternColumns.size());
    assertEquals(2, stateColumns.size());
    assertTrue(patternColumns.keySet().contains("name"));
    assertNotNull(patternColumns.get("name"));
    assertTrue(patternColumns.keySet().contains("invisible"));
    assertNotNull(patternColumns.get("invisible"));
    assertTrue(stateColumns.keySet().contains("name"));
    assertNotNull(stateColumns.get("name"));
    assertTrue(stateColumns.keySet().contains("invisible"));
    assertNotNull(stateColumns.get("invisible"));
}
Also used : PluginUtilsService(com.qcadoo.plugin.internal.PluginUtilsService) ViewGridColumnModuleColumnModel(com.qcadoo.view.internal.module.gridColumn.ViewGridColumnModuleColumnModel) InternalViewDefinitionState(com.qcadoo.view.internal.api.InternalViewDefinitionState) InternalViewDefinition(com.qcadoo.view.internal.api.InternalViewDefinition) ComponentOption(com.qcadoo.view.internal.ComponentOption) GridComponent(com.qcadoo.view.api.components.GridComponent) FieldDefinition(com.qcadoo.model.api.FieldDefinition) GridComponentColumn(com.qcadoo.view.internal.components.grid.GridComponentColumn) DataDefinition(com.qcadoo.model.api.DataDefinition) GridComponentPattern(com.qcadoo.view.internal.components.grid.GridComponentPattern) PluginStateResolver(com.qcadoo.plugin.api.PluginStateResolver) EnumType(com.qcadoo.model.internal.types.EnumType) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ComponentDefinition(com.qcadoo.view.internal.ComponentDefinition) ComponentState(com.qcadoo.view.api.ComponentState) AbstractPatternTest(com.qcadoo.view.internal.patterns.AbstractPatternTest) Test(org.junit.Test)

Example 4 with ComponentOption

use of com.qcadoo.view.internal.ComponentOption in project qcadoo by qcadoo.

the class ViewDefinitionParserImpl method parseOption.

@Override
public ComponentOption parseOption(final Node optionNode) {
    Map<String, String> attributes = new HashMap<String, String>();
    NamedNodeMap attributesNodes = optionNode.getAttributes();
    for (int i = 0; i < attributesNodes.getLength(); i++) {
        attributes.put(attributesNodes.item(i).getNodeName(), attributesNodes.item(i).getNodeValue());
    }
    String type = getStringAttribute(optionNode, "type");
    if (type == null) {
        type = getStringAttribute(optionNode, "xsi:type");
    }
    return new ComponentOption(type, attributes);
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) HashMap(java.util.HashMap) ComponentOption(com.qcadoo.view.internal.ComponentOption)

Example 5 with ComponentOption

use of com.qcadoo.view.internal.ComponentOption in project qcadoo by qcadoo.

the class GridComponentPattern method parseOptions.

private void parseOptions() {
    for (ComponentOption option : getOptions()) {
        if ("correspondingView".equals(option.getType())) {
            correspondingView = option.getValue();
        } else if ("correspondingComponent".equals(option.getType())) {
            correspondingComponent = option.getValue();
        } else if ("correspondingLookup".equals(option.getType())) {
            correspondingLookup = option.getValue();
        } else if ("correspondingViewInModal".equals(option.getType())) {
            correspondingViewInModal = Boolean.parseBoolean(option.getValue());
        } else if ("paginable".equals(option.getType())) {
            paginable = Boolean.parseBoolean(option.getValue());
        } else if ("creatable".equals(option.getType())) {
            creatable = Boolean.parseBoolean(option.getValue());
        } else if ("prioritizable".equals(option.getType())) {
            prioritizable = Boolean.parseBoolean(option.getValue());
        } else if ("onlyActive".equals(option.getType())) {
            onlyActive = Boolean.parseBoolean(option.getValue());
        } else if ("multiselect".equals(option.getType())) {
            multiselect = Boolean.parseBoolean(option.getValue());
        } else if ("hasPredefinedFilters".equals(option.getType())) {
            hasPredefinedFilters = Boolean.parseBoolean(option.getValue());
        } else if ("defaultPredefinedFilterName".equals(option.getType())) {
            defaultPredefinedFilterName = option.getValue();
        } else if ("filtersDefaultVisible".equals(option.getType())) {
            filtersDefaultVisible = Boolean.parseBoolean(option.getValue());
        } else if ("deletable".equals(option.getType())) {
            deletable = Boolean.parseBoolean(option.getValue());
        } else if ("selectableWhenDisabled".equals(option.getType())) {
            selectableWhenDisabled = Boolean.parseBoolean(option.getValue());
        } else if ("deletableAuthorizationRole".equals(option.getType())) {
            deletableAuthorizationRole = option.getValue();
        } else if ("linkAuthorizationRole".equals(option.getType())) {
            linkAuthorizationRole = option.getValue();
        } else if ("height".equals(option.getType())) {
            height = Integer.parseInt(option.getValue());
        } else if ("width".equals(option.getType())) {
            width = Integer.parseInt(option.getValue());
        } else if ("fullscreen".equals(option.getType())) {
            width = 0;
            height = 0;
        } else if ("lookup".equals(option.getType())) {
            lookup = Boolean.parseBoolean(option.getValue());
        } else if ("searchable".equals(option.getType())) {
            searchableColumns.addAll(parseColumns(option.getValue()));
        } else if ("multiSearch".equals(option.getType())) {
            multiSearchColumns.addAll(parseColumns(option.getValue()));
        } else if ("orderable".equals(option.getType())) {
            orderableColumns.addAll(parseColumns(option.getValue()));
        } else if ("order".equals(option.getType())) {
            defaultOrderColumn = option.getAttributeValue(L_COLUMN);
            defaultOrderDirection = option.getAttributeValue("direction");
            if (Objects.isNull(defaultOrderDirection)) {
                defaultOrderDirection = "asc";
            }
            if (Objects.nonNull(predefinedFilters)) {
                for (PredefinedFilter predefinedFilter : predefinedFilters.values()) {
                    if (Objects.isNull(predefinedFilter.getOrderColumn())) {
                        predefinedFilter.setOrderColumn(defaultOrderColumn);
                        predefinedFilter.setOrderDirection(defaultOrderDirection);
                    }
                }
            }
        } else if (L_COLUMN.equals(option.getType())) {
            parseColumnOption(option);
        } else if ("defaultVisibleColumns".equals(option.getType())) {
            defaultVisibleColumns.addAll(parseColumns(option.getValue()));
        } else if ("weakRelation".equals(option.getType())) {
            weakRelation = Boolean.parseBoolean(option.getValue());
        } else if ("fixedHeight".equals(option.getType())) {
            fixedHeight = Boolean.parseBoolean(option.getValue());
        } else if ("shrinkToFit".equals(option.getType())) {
            shrinkToFit = Boolean.parseBoolean(option.getValue());
        } else if ("autoRefresh".equals(option.getType())) {
            autoRefresh = Boolean.parseBoolean(option.getValue());
        } else if ("footerRow".equals(option.getType())) {
            footerRow = Boolean.parseBoolean(option.getValue());
        } else if ("columnsToSummary".equals(option.getType())) {
            columnsToSummary = option.getValue();
        } else if ("columnsToSummaryTime".equals(option.getType())) {
            columnsToSummaryTime = option.getValue();
        } else if ("suppressSelectEvent".equals(option.getType())) {
            suppressSelectEvent = Boolean.parseBoolean(option.getValue());
        }
    }
    if (Objects.isNull(defaultOrderColumn)) {
        throwIllegalStateException("grid must contain 'order' option");
    }
}
Also used : ComponentOption(com.qcadoo.view.internal.ComponentOption)

Aggregations

ComponentOption (com.qcadoo.view.internal.ComponentOption)11 DataDefinition (com.qcadoo.model.api.DataDefinition)8 ComponentDefinition (com.qcadoo.view.internal.ComponentDefinition)8 InternalViewDefinition (com.qcadoo.view.internal.api.InternalViewDefinition)8 GridComponentPattern (com.qcadoo.view.internal.components.grid.GridComponentPattern)8 AbstractPatternTest (com.qcadoo.view.internal.patterns.AbstractPatternTest)8 Test (org.junit.Test)8 FieldDefinition (com.qcadoo.model.api.FieldDefinition)5 JSONObject (org.json.JSONObject)5 EnumType (com.qcadoo.model.internal.types.EnumType)3 ComponentState (com.qcadoo.view.api.ComponentState)3 GridComponent (com.qcadoo.view.api.components.GridComponent)3 InternalViewDefinitionState (com.qcadoo.view.internal.api.InternalViewDefinitionState)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 BelongsToType (com.qcadoo.model.api.types.BelongsToType)2 HasManyType (com.qcadoo.model.api.types.HasManyType)2 PluginStateResolver (com.qcadoo.plugin.api.PluginStateResolver)2 PluginUtilsService (com.qcadoo.plugin.internal.PluginUtilsService)2 TextInputComponentPattern (com.qcadoo.view.internal.components.TextInputComponentPattern)2 GridComponentColumn (com.qcadoo.view.internal.components.grid.GridComponentColumn)2