Search in sources :

Example 76 with FilterValueHolder

use of com.qcadoo.view.api.components.lookup.FilterValueHolder in project mes by qcadoo.

the class ResourceDetailsHooks method setStorageLocationLookupFilterValue.

private void setStorageLocationLookupFilterValue(final ViewDefinitionState view, final Entity resource) {
    LookupComponent storageLocationLookup = (LookupComponent) view.getComponentByReference(ResourceFields.STORAGE_LOCATION);
    FilterValueHolder filter = storageLocationLookup.getFilterValue();
    Entity product = resource.getBelongsToField(ResourceFields.PRODUCT);
    Entity warehouse = resource.getBelongsToField(ResourceFields.LOCATION);
    if (Objects.nonNull(product)) {
        filter.put(ResourceFields.PRODUCT, product.getId());
    }
    if (Objects.nonNull(warehouse)) {
        filter.put(ResourceFields.LOCATION, warehouse.getId());
    }
    storageLocationLookup.setFilterValue(filter);
}
Also used : FilterValueHolder(com.qcadoo.view.api.components.lookup.FilterValueHolder) Entity(com.qcadoo.model.api.Entity) LookupComponent(com.qcadoo.view.api.components.LookupComponent)

Example 77 with FilterValueHolder

use of com.qcadoo.view.api.components.lookup.FilterValueHolder in project mes by qcadoo.

the class PalletResourcesTransferHelperHooks method setStorageLocationFilters.

@Override
protected void setStorageLocationFilters(final ViewDefinitionState view) {
    AwesomeDynamicListComponent adl = (AwesomeDynamicListComponent) view.getComponentByReference(L_PALLET_STORAGE_STATE_DTOS);
    for (FormComponent form : adl.getFormComponents()) {
        LookupComponent newPalletNumber = (LookupComponent) form.findFieldComponentByName("newPalletNumber");
        FilterValueHolder filter = newPalletNumber.getFilterValue();
        Entity persistedEntity = form.getPersistedEntityWithIncludedFormValues();
        filter.put(LOCATION_NUMBER, persistedEntity.getStringField(LOCATION_NUMBER));
        filter.put(PALLET_NUMBER, persistedEntity.getStringField(PALLET_NUMBER));
        newPalletNumber.setFilterValue(filter);
    }
}
Also used : FilterValueHolder(com.qcadoo.view.api.components.lookup.FilterValueHolder) FormComponent(com.qcadoo.view.api.components.FormComponent) Entity(com.qcadoo.model.api.Entity) LookupComponent(com.qcadoo.view.api.components.LookupComponent) AwesomeDynamicListComponent(com.qcadoo.view.api.components.AwesomeDynamicListComponent)

Example 78 with FilterValueHolder

use of com.qcadoo.view.api.components.lookup.FilterValueHolder in project mes by qcadoo.

the class PositionAddMultiHooks method onBeforeRender.

public final void onBeforeRender(final ViewDefinitionState view) throws JSONException {
    FormComponent form = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
    Entity helper = form.getPersistedEntityWithIncludedFormValues();
    JSONObject context = view.getJsonContext();
    if (context != null) {
        Long warehouseId = context.getLong("window.mainTab.helper.gridLayout.warehouseId");
        Long documentId = context.getLong("window.mainTab.helper.gridLayout.documentId");
        helper.setField("documentId", documentId);
        helper.setField("warehouseId", warehouseId);
        GridComponent grid = (GridComponent) view.getComponentByReference("resourceGrid");
        FilterValueHolder filter = grid.getFilterValue();
        filter.put(L_LOCATION_FROM, warehouseId);
        grid.setFilterValue(filter);
        form.setEntity(helper);
    }
}
Also used : FilterValueHolder(com.qcadoo.view.api.components.lookup.FilterValueHolder) FormComponent(com.qcadoo.view.api.components.FormComponent) Entity(com.qcadoo.model.api.Entity) JSONObject(org.json.JSONObject) GridComponent(com.qcadoo.view.api.components.GridComponent)

Example 79 with FilterValueHolder

use of com.qcadoo.view.api.components.lookup.FilterValueHolder in project mes by qcadoo.

the class DocumentDetailsHooks method fillAddressLookupCriteriaModifier.

public void fillAddressLookupCriteriaModifier(final ViewDefinitionState view) {
    LookupComponent companyLookup = (LookupComponent) view.getComponentByReference(DocumentFields.COMPANY);
    LookupComponent addressLookup = (LookupComponent) view.getComponentByReference(DocumentFields.ADDRESS);
    Entity company = companyLookup.getEntity();
    FilterValueHolder filterValueHolder = addressLookup.getFilterValue();
    if (company == null) {
        filterValueHolder.remove(AddressCriteriaModifiers.L_COMPANY_ID);
        addressLookup.setFieldValue(null);
    } else {
        Long companyId = company.getId();
        if (filterValueHolder.has(AddressCriteriaModifiers.L_COMPANY_ID)) {
            Long oldCompanyId = filterValueHolder.getLong(AddressCriteriaModifiers.L_COMPANY_ID);
            if (!companyId.equals(oldCompanyId)) {
                addressLookup.setFieldValue(null);
            }
        }
        filterValueHolder.put(AddressCriteriaModifiers.L_COMPANY_ID, companyId);
    }
    addressLookup.setFilterValue(filterValueHolder);
    addressLookup.requestComponentUpdateState();
}
Also used : FilterValueHolder(com.qcadoo.view.api.components.lookup.FilterValueHolder) Entity(com.qcadoo.model.api.Entity) LookupComponent(com.qcadoo.view.api.components.LookupComponent)

Example 80 with FilterValueHolder

use of com.qcadoo.view.api.components.lookup.FilterValueHolder in project mes by qcadoo.

the class DocumentPositionsCriteriaModifier method restrictToUserLocations.

public void restrictToUserLocations(final SearchCriteriaBuilder scb, final FilterValueHolder filterValue) {
    Long currentUserId = securityService.getCurrentUserId();
    if (Objects.nonNull(currentUserId)) {
        EntityList userLocations = userDataDefinition().get(currentUserId).getHasManyField(UserFieldsMF.USER_LOCATIONS);
        if (!userLocations.isEmpty()) {
            Set<Integer> locationIds = userLocations.stream().map(ul -> ul.getBelongsToField(UserLocationFields.LOCATION)).mapToInt(e -> e.getId().intValue()).boxed().collect(Collectors.toSet());
            scb.add(SearchRestrictions.or(SearchRestrictions.in(LOCATION_TO_ID, locationIds), SearchRestrictions.in(LOCATION_FROM_ID, locationIds)));
        }
    }
}
Also used : DataDefinitionService(com.qcadoo.model.api.DataDefinitionService) SearchRestrictions(com.qcadoo.model.api.search.SearchRestrictions) QcadooSecurityConstants(com.qcadoo.security.constants.QcadooSecurityConstants) Set(java.util.Set) Autowired(org.springframework.beans.factory.annotation.Autowired) Collectors(java.util.stream.Collectors) DataDefinition(com.qcadoo.model.api.DataDefinition) EntityList(com.qcadoo.model.api.EntityList) Objects(java.util.Objects) FilterValueHolder(com.qcadoo.view.api.components.lookup.FilterValueHolder) UserFieldsMF(com.qcadoo.mes.materialFlow.constants.UserFieldsMF) UserLocationFields(com.qcadoo.mes.materialFlow.constants.UserLocationFields) Service(org.springframework.stereotype.Service) SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder) SecurityService(com.qcadoo.security.api.SecurityService) EntityList(com.qcadoo.model.api.EntityList)

Aggregations

FilterValueHolder (com.qcadoo.view.api.components.lookup.FilterValueHolder)119 LookupComponent (com.qcadoo.view.api.components.LookupComponent)69 Entity (com.qcadoo.model.api.Entity)64 FormComponent (com.qcadoo.view.api.components.FormComponent)45 GridComponent (com.qcadoo.view.api.components.GridComponent)26 FieldComponent (com.qcadoo.view.api.components.FieldComponent)13 Collectors (java.util.stream.Collectors)11 Autowired (org.springframework.beans.factory.annotation.Autowired)11 Service (org.springframework.stereotype.Service)11 DataDefinitionService (com.qcadoo.model.api.DataDefinitionService)10 SearchCriteriaBuilder (com.qcadoo.model.api.search.SearchCriteriaBuilder)10 SearchRestrictions (com.qcadoo.model.api.search.SearchRestrictions)10 Objects (java.util.Objects)10 DataDefinition (com.qcadoo.model.api.DataDefinition)9 JSONObject (org.json.JSONObject)9 UserFieldsMF (com.qcadoo.mes.materialFlow.constants.UserFieldsMF)8 UserLocationFields (com.qcadoo.mes.materialFlow.constants.UserLocationFields)8 EntityList (com.qcadoo.model.api.EntityList)8 SecurityService (com.qcadoo.security.api.SecurityService)8 QcadooSecurityConstants (com.qcadoo.security.constants.QcadooSecurityConstants)8