Skip to content

Commit

Permalink
Add new creatorField property
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiasstein committed May 25, 2021
1 parent 08591da commit dc185cf
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/main/js/apps/sample/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"bundles": {
"dn_editingusernameprocessor": {
"Config": {
"creatorField": "",
"usernameField": "kommentar",
"usernameAttributes": [
"givenname",
Expand Down
10 changes: 6 additions & 4 deletions src/main/js/bundles/dn_editingusernameprocessor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Simply add the bundle "dn_editingusernameprocessor" to your app.
"dn_editingusernameprocessor": {
"Config": {
"usernameField": "description",
"creatorField": "",
"usernameAttributes": [
"givenname",
"sn"
Expand All @@ -20,7 +21,8 @@ Simply add the bundle "dn_editingusernameprocessor" to your app.
}
```

| Property | Type | Possible Values | Default | Description |
|--------------------------------|--------------------|------------------------------------|--------------------------------------|-----------------------------------------------------|
| usernameField | String | | ```""``` | Define the username field. |
| usernameAttributes | Array | | ```["givenname", "sn"]``` | Configure the attributes that make up the username. |
| Property | Type | Possible Values | Default | Description |
|--------------------------------|--------------------|------------------------------------|--------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| usernameField | String | | ```""``` | Define the username field. |
| creatorField | String | | ```""``` | Define the creator field to save the user name to another attribute if a new features gets created. If this property has the value ```""``` the user name will be written to the username field in case of create and update workflow. |
| usernameAttributes | Array | | ```["givenname", "sn"]``` | Configure the attributes that make up the username. |
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,36 @@ import async from "apprt-core/async";

export default class UsernameInterceptor {

#watcher = null;

interceptConfig(config) {
}

interceptEditor(editorWidget) {
const featureFormViewModel = editorWidget.viewModel.featureFormViewModel;
featureFormViewModel.watch("feature", (feature) => {
this.#watcher?.remove();
const viewModel = editorWidget.viewModel;
const featureFormViewModel = viewModel.featureFormViewModel;
const properties = this._properties;
this.#watcher = featureFormViewModel.watch("feature", (feature) => {
const workFlowType = viewModel.activeWorkflow.type;
const username = this.getUserName();
if (!feature || !username) {
return;
}
async(() => {
featureFormViewModel.setValue(this._properties.usernameField, username);
if (properties.creatorField && properties.creatorField !== "") {
switch (workFlowType) {
case "create":
featureFormViewModel.setValue(properties.creatorField, username);
break;
case "update":
featureFormViewModel.setValue(properties.usernameField, username);
break;
}
} else {
featureFormViewModel.setValue(properties.usernameField, username);
}

//feature.setAttribute(this._properties.usernameField, username);
//featureFormViewModel.submit();
//featureFormViewModel.emit("value-change");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"provides": "editing.EditorInterceptor",
"properties": {
"usernameField": "",
"creatorField": "",
"usernameAttributes": [
"givenname",
"sn"
Expand Down

0 comments on commit dc185cf

Please sign in to comment.