Skip to main content

Task

Implement two filters:

  1. Whenever Context CarDriver is opened, only female drivers should be displayed.
  2. Context CarReservation: Via an Action, the displayed datasets can be reduced so that only future reservations are shown.
tip

Here you can find a generic description of how to create and configure filters.

note

This training course does not cover FilterExtensionSets, as there is already an extensive example in the generic part of the documentation, see here.

Solution

Only female drivers

To show only female drivers, when the Context CarDriver is opened, we will use CarDriver_entity's initFilterProcess:

import { neon, neonFilter, result, translate, vars } from "@aditosoftware/jdito-types";
import { $KeywordRegistry } from "KeywordRegistry_basic";
import { KeywordUtils } from "KeywordUtils_lib";

if (vars.get("$sys.presentationmode") === neon.CONTEXT_PRESENTATIONMODE_FILTER)
{
let cond = neonFilter.createFilterCondition()
.field("GENDER")
.contentType(vars.get("$property.GENDER.contentType"))
.searchOperator(neonFilter.SEARCH_OPERATOR_EQUAL)
.key($KeywordRegistry.personGender$female())
.value(KeywordUtils.getViewValue($KeywordRegistry.personGender(), $KeywordRegistry.personGender$female()));

let filter = neonFilter.createFilterGroup()
.mergeOperator(neonFilter.MERGE_OPERATOR_AND)
.addFilterCondition(cond);

result.string(filter.toJson());
}

CarDriver_entity.initFilterProcess.js

note

You can show all CarDrivers in the client again, if you reset the filter in the filter component of the client via "Condition -> reset" > "Apply filter".

Only future reservations

For the sake of simplicity, we re-use CarResrevation_entity's ActionGroup "CarHandlingActionGroup". Via the context menu of this ActionGroup, create a new Action, name it "showOnlyFutureReservations" and title it "Show only future reservations".

The onActionProcess should include a logic like this:

import { neon, neonFilter, result, translate, vars } from "@aditosoftware/jdito-types";
import { $KeywordRegistry } from "KeywordRegistry_basic";
import { KeywordUtils } from "KeywordUtils_lib";
let cond = neonFilter.createFilterCondition()
.field("STARTDATE")
.contentType(vars.get("$property.GENDER.contentType"))
.searchOperator(neonFilter.SEARCH_OPERATOR_EQUAL)
.key($KeywordRegistry.personGender$female())
.value(KeywordUtils.getViewValue($KeywordRegistry.personGender(), $KeywordRegistry.personGender$female()));

let filter = neonFilter.createFilterGroup()
.mergeOperator(neonFilter.MERGE_OPERATOR_AND)
.addFilterCondition(cond);

result.string(filter.toJson());

CarReservation_entity.CarHandlingActionGroup.showOnlyFutureReservations.onActionProcess.js