Task
Implement two filters:
- Whenever Context CarDriver is opened, only female drivers should be displayed.
- Context CarReservation: Via an Action, the displayed datasets can be reduced so that only future reservations are shown.
Here you can find a generic description of how to create and configure filters.
This training course does not cover FilterExtensionSets, as there is already an extensive example in the generic part of the documentation, see FilterExtensionSet.
Solution
Only female drivers
To show only female drivers, after the Context CarDriver has been opened, we will use CarDriver_entity's initFilterProcess. As preparation, we need to create a gender-related EntityField for CarDriver_entity, as the original GENDER field is an EntityField in Person_entity and therefore cannot be used in a filter of CarDriver_entity.
Create a new EntityField for CarDriver_entity and name it, e.g., DRIVERGENDER. Give it a suitable title, e.g. "Gender of Driver". Then, open the corresponding RecordFieldMapping db > DRIVERGENDER.value and select PERSON.GENDER in its property recordfield. Furthermore, set property isFilterable to true.
Now you can enter the following code in CarDriver_entity's property initFilterProcess:
import { neon, neonFilter, result, vars } from "@aditosoftware/jdito-types";
import { KeywordUtils } from "@aditosoftware/keyword/KeywordUtils_lib";
import { $SalutationKeywords } from "@aditosoftware/salutation/SalutationKeywords_registry";
if (vars.get("$sys.presentationmode") === neon.CONTEXT_PRESENTATIONMODE_FILTER)
{
const genderKey = $SalutationKeywords.personGender$female();
const cond = neonFilter.createFilterCondition()
.field("DRIVERGENDER")
.contentType(neonFilter.CONTENT_TYPE_TEXT)
.searchOperator(neonFilter.SEARCH_OPERATOR_EQUAL)
.key(genderKey)
.value(
KeywordUtils.getViewValue(
$SalutationKeywords.personGender(),
genderKey
)
);
const filter = neonFilter.createFilterGroup()
.mergeOperator(neonFilter.MERGE_OPERATOR_AND)
.addFilterCondition(cond);
result.string(filter.toJson());
}
CarDriver_entity.initFilterProcess.js
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, datetime } from "@aditosoftware/jdito-types";
let cond = neonFilter.createFilterCondition()
.field("STARTDATE")
.contentType(neonFilter.CONTENT_TYPE_DATE)
.searchOperator(neonFilter.SEARCH_OPERATOR_GREATER)
.key(datetime.today())
.value(datetime.today());
let filter = neonFilter.createFilterGroup()
.mergeOperator(neonFilter.MERGE_OPERATOR_AND)
.addFilterCondition(cond);
neon.setFilter("#ENTITY", filter);
CarReservation_entity.CarHandlingActionGroup.showOnlyFutureReservations.onActionProcess.js