@sankhyalabs/sankhyablocks 1.3.31-beta.10 → 1.3.31-beta.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/dist/cjs/SnkMessageBuilder-13239761.js +188 -0
  2. package/dist/cjs/loader.cjs.js +1 -1
  3. package/dist/cjs/sankhyablocks.cjs.js +1 -1
  4. package/dist/cjs/snk-application.cjs.entry.js +3 -1
  5. package/dist/cjs/snk-crud.cjs.entry.js +1 -1
  6. package/dist/cjs/snk-data-unit.cjs.entry.js +107 -48
  7. package/dist/cjs/snk-form_2.cjs.entry.js +18 -11
  8. package/dist/cjs/snk-taskbar.cjs.entry.js +39 -20
  9. package/dist/cjs/{taskbar-elements-7f99f0c9.js → taskbar-elements-73d524e5.js} +1 -1
  10. package/dist/collection/components/snk-application/snk-application.js +30 -1
  11. package/dist/collection/components/snk-crud/snk-crud.js +6 -18
  12. package/dist/collection/components/snk-data-unit/snk-data-unit.js +107 -71
  13. package/dist/collection/components/snk-form/snk-form.js +18 -28
  14. package/dist/collection/components/snk-taskbar/elements/taskbar-elements.js +1 -1
  15. package/dist/collection/components/snk-taskbar/snk-taskbar.js +38 -19
  16. package/dist/collection/lib/http/data-fetcher/DataFetcher.js +1 -1
  17. package/dist/collection/lib/message/SnkMessageBuilder.js +119 -0
  18. package/dist/collection/lib/message/resources/snk-data-unit.msg.js +22 -0
  19. package/dist/collection/lib/message/resources/snk-form.msg.js +10 -0
  20. package/dist/collection/lib/message/resources/snk-taskbar.msg.js +16 -0
  21. package/dist/components/SnkMessageBuilder.js +166 -0
  22. package/dist/components/snk-application2.js +4 -1
  23. package/dist/components/snk-crud.js +1 -2
  24. package/dist/components/snk-data-unit.js +107 -49
  25. package/dist/components/snk-form2.js +17 -11
  26. package/dist/components/snk-taskbar2.js +39 -20
  27. package/dist/esm/SnkMessageBuilder-3835f9d8.js +166 -0
  28. package/dist/esm/loader.js +1 -1
  29. package/dist/esm/sankhyablocks.js +1 -1
  30. package/dist/esm/snk-application.entry.js +3 -1
  31. package/dist/esm/snk-crud.entry.js +1 -1
  32. package/dist/esm/snk-data-unit.entry.js +107 -48
  33. package/dist/esm/snk-form_2.entry.js +18 -11
  34. package/dist/esm/snk-taskbar.entry.js +39 -20
  35. package/dist/esm/{taskbar-elements-e0b8a285.js → taskbar-elements-6d01a640.js} +1 -1
  36. package/dist/sankhyablocks/{p-c3d20542.entry.js → p-5e1b7e51.entry.js} +1 -1
  37. package/dist/sankhyablocks/p-72bccbb6.js +1 -0
  38. package/dist/sankhyablocks/p-8c74d163.entry.js +1 -0
  39. package/dist/sankhyablocks/p-bab507ad.entry.js +1 -0
  40. package/dist/sankhyablocks/p-dd10a5e3.js +1 -0
  41. package/dist/sankhyablocks/p-e942c604.entry.js +69 -0
  42. package/dist/sankhyablocks/p-f4d0394b.entry.js +1 -0
  43. package/dist/sankhyablocks/sankhyablocks.esm.js +1 -1
  44. package/dist/types/components/snk-application/snk-application.d.ts +8 -2
  45. package/dist/types/components/snk-taskbar/snk-taskbar.d.ts +8 -0
  46. package/dist/types/components.d.ts +9 -18
  47. package/dist/types/lib/message/SnkMessageBuilder.d.ts +42 -0
  48. package/dist/types/lib/message/resources/snk-data-unit.msg.d.ts +2 -0
  49. package/dist/types/lib/message/resources/snk-form.msg.d.ts +2 -0
  50. package/dist/types/lib/message/resources/snk-taskbar.msg.d.ts +2 -0
  51. package/package.json +1 -1
  52. package/dist/sankhyablocks/p-18fe0469.entry.js +0 -69
  53. package/dist/sankhyablocks/p-5b5afdbe.entry.js +0 -1
  54. package/dist/sankhyablocks/p-7fe9e5c2.entry.js +0 -1
  55. package/dist/sankhyablocks/p-8650ae26.entry.js +0 -1
  56. package/dist/sankhyablocks/p-a5439706.js +0 -1
@@ -1,4 +1,4 @@
1
- import { Component, h, Method, Event } from "@stencil/core";
1
+ import { Component, h, Method, Event, Prop } from "@stencil/core";
2
2
  import { DataType, ErrorTracking } from "@sankhyalabs/core";
3
3
  import { DependencyType } from "@sankhyalabs/core";
4
4
  import DataUnitFetcher from "../../lib/http/data-fetcher/fetchers/dataunit-fetcher";
@@ -15,6 +15,12 @@ import AuthFetcher, { AutorizationType } from "../../lib/http/data-fetcher/fetch
15
15
  import MGEAuthorization from '../../lib/auth/mgeauthorization.module';
16
16
  import { SnkErrorHandler } from "./errorhandler/snk-error-handler";
17
17
  import { agGridLicense } from '../../lib/licenses/sankhyalicense.module';
18
+ import { SnkMessageBuilder } from "../../lib/message/SnkMessageBuilder";
19
+ /**
20
+ * É possível customizar as mensagens dos blocos de construção através de um pequeno modulo na estrutura da aplicação:
21
+ * - Criar um arquivo no seguinte caminho: /messages/appmessages.msg.js.
22
+ * Para conhecer os detalhes do módulo, vide os arquivos neste projeto "/src/lib/message/resources/*.msg.ts"
23
+ */
18
24
  export class SnkApplication {
19
25
  constructor() {
20
26
  this._authPromises = [];
@@ -441,6 +447,7 @@ export class SnkApplication {
441
447
  }
442
448
  componentWillLoad() {
443
449
  this._errorHandler = new SnkErrorHandler(this);
450
+ this.messagesBuilder = new SnkMessageBuilder();
444
451
  ApplicationContext.setContextValue("__EZUI__UPLOAD__ADD__URL__", `${UrlUtils.getUrlBase()}/mge/upload/file`);
445
452
  ApplicationContext.setContextValue("__EZUI__SEARCH__OPTION__LOADER__", (searchArgument, fieldName, dataUnit) => {
446
453
  return this.executeSearch(searchArgument, fieldName, dataUnit);
@@ -474,6 +481,28 @@ export class SnkApplication {
474
481
  static get styleUrls() { return {
475
482
  "$": ["snk-application.css"]
476
483
  }; }
484
+ static get properties() { return {
485
+ "messagesBuilder": {
486
+ "type": "unknown",
487
+ "mutable": true,
488
+ "complexType": {
489
+ "original": "SnkMessageBuilder",
490
+ "resolved": "SnkMessageBuilder",
491
+ "references": {
492
+ "SnkMessageBuilder": {
493
+ "location": "import",
494
+ "path": "../../lib/message/SnkMessageBuilder"
495
+ }
496
+ }
497
+ },
498
+ "required": false,
499
+ "optional": false,
500
+ "docs": {
501
+ "tags": [],
502
+ "text": "messagesBuilder \u00E9 um utilit\u00E1rio respons\u00E1vel por flexibilizar e padronizar\no uso de mensagens nos blocos de constru\u00E7\u00E3o."
503
+ }
504
+ }
505
+ }; }
477
506
  static get events() { return [{
478
507
  "method": "applicationLoaded",
479
508
  "name": "applicationLoaded",
@@ -1,6 +1,11 @@
1
1
  import { Component, h, Prop, Element, State } from '@stencil/core';
2
2
  const GRID_MODE = 0;
3
3
  const FORM_MODE = 1;
4
+ /**
5
+ * É possível customizar as mensagens dos blocos de construção através de um pequeno modulo na estrutura da aplicação:
6
+ * - Criar um arquivo no seguinte caminho: /messages/appmessages.msg.js.
7
+ * Para conhecer os detalhes do módulo, vide os arquivos neste projeto "/src/lib/message/resources/*.msg.ts"
8
+ */
4
9
  export class SnkCrud {
5
10
  async gridToForm(keepFormMode = false) {
6
11
  this._backToGrid = !keepFormMode && await this._viewStack.getSelectedIndex() === GRID_MODE;
@@ -50,7 +55,7 @@ export class SnkCrud {
50
55
  h("snk-grid", { configName: this.configName, onGridDoubleClick: () => this.gridToForm(true), onActionClick: evt => this.executeAction(evt.detail), actionsList: this.actionsList },
51
56
  h("slot", null))),
52
57
  h("stack-item", null,
53
- h("snk-form", { formTitle: this.formTitle, configName: this.configName, actionsList: this.actionsList, onExit: () => this._viewStack.show(GRID_MODE), recordsValidator: this.recordsValidator, onActionClick: evt => this.executeAction(evt.detail) }))));
58
+ h("snk-form", { configName: this.configName, actionsList: this.actionsList, onExit: () => this._viewStack.show(GRID_MODE), recordsValidator: this.recordsValidator, onActionClick: evt => this.executeAction(evt.detail) }))));
54
59
  }
55
60
  static get is() { return "snk-crud"; }
56
61
  static get encapsulation() { return "scoped"; }
@@ -78,23 +83,6 @@ export class SnkCrud {
78
83
  "attribute": "config-name",
79
84
  "reflect": false
80
85
  },
81
- "formTitle": {
82
- "type": "string",
83
- "mutable": false,
84
- "complexType": {
85
- "original": "string",
86
- "resolved": "string",
87
- "references": {}
88
- },
89
- "required": false,
90
- "optional": false,
91
- "docs": {
92
- "tags": [],
93
- "text": ""
94
- },
95
- "attribute": "form-title",
96
- "reflect": false
97
- },
98
86
  "actionsList": {
99
87
  "type": "unknown",
100
88
  "mutable": false,
@@ -1,6 +1,7 @@
1
1
  import { Component, Host, h, Event, Element, Prop, Watch, Method } from '@stencil/core';
2
2
  import { Action, ApplicationContext } from '@sankhyalabs/core';
3
3
  import { ApplicationUtils } from '@sankhyalabs/ezui/dist/collection/utils';
4
+ import { OperationMap } from '../../lib/message/SnkMessageBuilder';
4
5
  export class SnkDataUnit {
5
6
  constructor() {
6
7
  this._onDataUnitResolve = [];
@@ -13,19 +14,6 @@ export class SnkDataUnit {
13
14
  */
14
15
  this.autoLoad = true;
15
16
  this._dataUnitObserver = (action) => {
16
- let msg;
17
- if (!this.isTransitionAction(action.type)) {
18
- msg = this.getActionInfo(action.type);
19
- }
20
- if (msg) {
21
- ApplicationUtils.info(msg);
22
- }
23
- if (action.type === Action.RECORDS_ADDED || action.type === Action.RECORDS_COPIED) {
24
- this.insertionMode.emit();
25
- }
26
- if (action.type === Action.EDITION_CANCELED) {
27
- this.cancelEdition.emit();
28
- }
29
17
  const duState = {
30
18
  insertionMode: false,
31
19
  hasNext: this.dataUnit.hasNext(),
@@ -42,6 +30,29 @@ export class SnkDataUnit {
42
30
  }
43
31
  });
44
32
  this.dataState = duState;
33
+ if (action.type === Action.DATA_SAVED) {
34
+ const msg = this.getMessage("snkDataUnit.saveInfo", action.payload.records[0]);
35
+ if (msg != undefined) {
36
+ this.showSuccessMessage(msg);
37
+ }
38
+ }
39
+ if (action.type === Action.RECORDS_ADDED || action.type === Action.RECORDS_COPIED) {
40
+ this.insertionMode.emit();
41
+ }
42
+ if (action.type === Action.EDITION_CANCELED) {
43
+ this.cancelEdition.emit();
44
+ const cancelFinishMsg = this.getMessage("snkDataUnit.cancelInfo");
45
+ if (cancelFinishMsg != undefined) {
46
+ this.showSuccessMessage(cancelFinishMsg);
47
+ }
48
+ }
49
+ if (action.type === Action.RECORDS_REMOVED) {
50
+ const removeFinishMsg = this.getMessage("snkDataUnit.removeInfo", action.payload.cachedRecords[0]);
51
+ if (removeFinishMsg != undefined) {
52
+ this.showSuccessMessage(removeFinishMsg);
53
+ }
54
+ }
55
+ this._application.messagesBuilder.currentOperation = this.getMessageOperation();
45
56
  };
46
57
  }
47
58
  observePageSize() {
@@ -89,6 +100,32 @@ export class SnkDataUnit {
89
100
  async interceptAction(action) {
90
101
  return new Promise(resolve => {
91
102
  switch (action.type) {
103
+ case Action.RECORDS_ADDED:
104
+ if (this.isAllowed("INSERT")) {
105
+ resolve(action);
106
+ }
107
+ else {
108
+ ApplicationUtils.info(this.getMessage("snkDataUnit.forbiddenInsert"));
109
+ }
110
+ break;
111
+ case Action.RECORDS_COPIED:
112
+ if (this.isAllowed("CLONE")) {
113
+ resolve(action);
114
+ }
115
+ else {
116
+ ApplicationUtils.info(this.getMessage("snkDataUnit.forbiddenClone"));
117
+ }
118
+ break;
119
+ case Action.DATA_CHANGED:
120
+ case Action.CHANGING_DATA:
121
+ if (this.isAllowed("UPDATE")) {
122
+ resolve(action);
123
+ }
124
+ else {
125
+ this.dataUnit.cancelEdition();
126
+ ApplicationUtils.info(this.getMessage("snkDataUnit.forbiddenUpdate"));
127
+ }
128
+ break;
92
129
  case Action.SAVING_DATA:
93
130
  if (this.beforeSave) {
94
131
  const continueAction = this.beforeSave(this.dataUnit);
@@ -113,52 +150,82 @@ export class SnkDataUnit {
113
150
  break;
114
151
  case Action.EDITION_CANCELED:
115
152
  if (this.dataState.hasDirtyRecords) {
116
- ApplicationUtils.confirm(this.i18n("components.warning"), this.i18n("components.confirmCancelEdition"))
117
- .then((result) => resolve(result ? action : undefined));
153
+ const cancelConfirmation = this.getMessage("snkDataUnit.cancelConfirmation");
154
+ if (cancelConfirmation == undefined) {
155
+ resolve(action);
156
+ }
157
+ else {
158
+ const cancelConfirmationTitle = this.getMessage("snkDataUnit.cancelConfirmationTitle");
159
+ ApplicationUtils.confirm(cancelConfirmationTitle, cancelConfirmation)
160
+ .then((result) => resolve(result ? action : undefined));
161
+ }
118
162
  }
119
163
  else {
120
164
  resolve(action);
121
165
  }
122
166
  break;
123
167
  case Action.REMOVING_RECORDS:
124
- let msg = undefined;
125
- if (this.messageBuilder) {
126
- msg = this.messageBuilder(action.type, this.dataState, this.dataUnit);
168
+ if (this.isAllowed("REMOVE")) {
169
+ const removeConfirmation = this.getMessage("snkDataUnit.removeConfirmation");
170
+ if (removeConfirmation == undefined) {
171
+ resolve(action);
172
+ }
173
+ else {
174
+ const removeConfirmationTitle = this.getMessage("snkDataUnit.removeConfirmationTitle");
175
+ ApplicationUtils.confirm(removeConfirmationTitle, removeConfirmation, "delete", true, { btnConfirmDanger: true })
176
+ .then((result) => resolve(result ? action : undefined));
177
+ }
178
+ }
179
+ else {
180
+ ApplicationUtils.info(this.getMessage("snkDataUnit.forbiddenRemove"));
127
181
  }
128
- ApplicationUtils.confirm(this.i18n("components.delete"), msg || this.i18n("components.confirmRemoveRecord"), "delete", true, { btnConfirmDanger: true })
129
- .then((result) => resolve(result ? action : undefined));
130
182
  break;
131
183
  default:
132
184
  resolve(action);
133
185
  }
134
186
  });
135
187
  }
136
- isTransitionAction(action) {
137
- switch (action) {
138
- case Action.LOADING_METADATA:
139
- case Action.LOADING_DATA:
140
- case Action.SAVING_DATA:
141
- case Action.REMOVING_RECORDS:
142
- case Action.CHANGING_DATA:
143
- return true;
144
- default:
145
- return false;
188
+ showSuccessMessage(message) {
189
+ ApplicationUtils.info(message, { iconName: "check" });
190
+ }
191
+ isAllowed(flag) {
192
+ return this._permissions ? this._permissions.isSup || this._permissions[flag] : false;
193
+ }
194
+ /**
195
+ * Conforme mecanismo de mensagens, é possível customizar as mensagens dos blocos de construção
196
+ * através de um pequeno modulo na estrutura da aplicação:
197
+ * - Criar um arquivo no seguinte caminho: /messages/appmessages.msg.js.
198
+ * Para conhecer os detalhes do módulo, vide o arquivo neste projeto "/src/lib/message/resources/snk-data-unit.msg.ts"
199
+ */
200
+ getMessage(key, params = undefined) {
201
+ if (!params) {
202
+ params = this.getMessageParams();
146
203
  }
204
+ return this._application.messagesBuilder.getMessage(key, params);
147
205
  }
148
- getActionInfo(action) {
149
- if (this.messageBuilder) {
150
- return this.messageBuilder(action, this.dataState, this.dataUnit);
206
+ getMessageParams() {
207
+ //TODO: Atualmente ainda não usamos o recurso de multiseleção do dataunit, mas no futuro
208
+ //precisaremos criar um mecanismo para oferecer todos os registros selecionados para a
209
+ //mensagem
210
+ return this.dataState.selectedRecords ? this.dataState.selectedRecords[0] : undefined;
211
+ }
212
+ getMessageOperation() {
213
+ if (this.dataState.copyMode) {
214
+ return OperationMap.CLONE;
215
+ }
216
+ if (this.dataState.insertionMode) {
217
+ return OperationMap.INSERT;
151
218
  }
152
- if (action === Action.EDITION_CANCELED) {
153
- return this.i18n("components.editionCanceled");
219
+ if (this.dataState.isDirty) {
220
+ return OperationMap.UPDATE;
154
221
  }
222
+ return OperationMap.CLEAN;
155
223
  }
156
224
  async loadDataUnit() {
157
225
  if (!this.dataUnit) {
158
- const app = ApplicationContext.getContextValue("__SNK__APPLICATION__");
159
- if (app && this.entityName) {
226
+ if (this._application && this.entityName) {
160
227
  const cacheName = this.dataUnitName ? this.dataUnitName : this.entityName;
161
- this.dataUnit = await app.getDataUnit(this.entityName, cacheName);
228
+ this.dataUnit = await this._application.getDataUnit(this.entityName, cacheName);
162
229
  this.dataUnit.pageSize = this.pageSize;
163
230
  this.dataUnit.unsubscribe(this._dataUnitObserver);
164
231
  this.dataUnit.addInterceptor(this);
@@ -173,20 +240,12 @@ export class SnkDataUnit {
173
240
  }
174
241
  }
175
242
  }
176
- i18n(key) {
177
- const pt_br = {
178
- "components.warning": "Aviso",
179
- "components.delete": "Excluir",
180
- "components.confirmRemoveRecord": "Deseja realmente excluir o registro atual?",
181
- "components.confirmCancelEdition": "As alterações realizadas serão descartadas<br/><br/><b>Você realmente gostaria de sair?</b>",
182
- "components.editionCanceled": "Todas as alterações foram descartadas.",
183
- };
184
- return pt_br[key];
185
- }
186
243
  //---------------------------------------------
187
244
  // Lifecycle web component
188
245
  //---------------------------------------------
189
246
  componentWillLoad() {
247
+ this._application = ApplicationContext.getContextValue("__SNK__APPLICATION__");
248
+ this._application.getAllAccess().then(access => this._permissions = access);
190
249
  this.loadDataUnit();
191
250
  }
192
251
  render() {
@@ -292,29 +351,6 @@ export class SnkDataUnit {
292
351
  "text": "Uma vez instanciado, pode-se obter o dataUnit por esta propriedade"
293
352
  }
294
353
  },
295
- "messageBuilder": {
296
- "type": "unknown",
297
- "mutable": false,
298
- "complexType": {
299
- "original": "(messageKey: string, dataState: DataState, dataUnit: DataUnit) => string",
300
- "resolved": "(messageKey: string, dataState: DataState, dataUnit: DataUnit) => string",
301
- "references": {
302
- "DataState": {
303
- "location": "local"
304
- },
305
- "DataUnit": {
306
- "location": "import",
307
- "path": "@sankhyalabs/core"
308
- }
309
- }
310
- },
311
- "required": false,
312
- "optional": false,
313
- "docs": {
314
- "tags": [],
315
- "text": "Abstra\u00E7\u00E3o para obter-se mensagens de acordo com o estado dos dados."
316
- }
317
- },
318
354
  "beforeSave": {
319
355
  "type": "unknown",
320
356
  "mutable": false,
@@ -43,22 +43,29 @@ export class SnkForm {
43
43
  });
44
44
  }
45
45
  }
46
- i18n(key) {
47
- const pt_br = {
48
- "components.back": "Voltar"
49
- };
50
- return pt_br[key];
46
+ /**
47
+ * Conforme mecanismo de mensagens, é possível customizar as mensagens dos blocos de construção
48
+ * através de um pequeno modulo na estrutura da aplicação:
49
+ * - Criar um arquivo no seguinte caminho: /messages/appmessages.msg.js.
50
+ * Para conhecer os detalhes do módulo, vide o arquivo neste projeto "/src/lib/message/resources/snk-form.msg.ts"
51
+ */
52
+ getMessage(key) {
53
+ return this._application.messagesBuilder.getMessage(key, this.getMessageParams());
54
+ }
55
+ getMessageParams() {
56
+ var _a;
57
+ return ((_a = this._dataState) === null || _a === void 0 ? void 0 : _a.selectedRecords) ? this._dataState.selectedRecords[0] : undefined;
51
58
  }
52
59
  componentWillLoad() {
53
- const snkApplication = ApplicationContext.getContextValue("__SNK__APPLICATION__");
54
- if (snkApplication) {
55
- snkApplication.loadFormConfig(this.configName).then(cfg => {
60
+ this._application = ApplicationContext.getContextValue("__SNK__APPLICATION__");
61
+ if (this._application) {
62
+ this._application.loadFormConfig(this.configName).then(cfg => {
56
63
  this._configLoaded = true;
57
64
  this._editionFormConfig = cfg;
58
65
  this.loadInsertionConfig();
59
66
  });
60
67
  //Forçamos a carga dos acessos pra aproveitar a request inicial.
61
- snkApplication.getAllAccess();
68
+ this._application.getAllAccess();
62
69
  }
63
70
  let parent = this._element.parentElement;
64
71
  while (parent) {
@@ -90,8 +97,8 @@ export class SnkForm {
90
97
  return (h("section", { class: "snk-form" },
91
98
  h("div", { class: "snk-form__header snk-form__header--fixed ez-row" },
92
99
  h("div", { class: "ez-col ez-col--sd-6 ez-col--tb-6", key: "formHeader" },
93
- h("ez-button", { title: this.i18n("components.back"), mode: "icon", iconName: "arrow_back", class: "ez-padding-right--medium", size: "small", onClick: () => this.exitForm() }),
94
- h("h1", { class: "ez-title ez-title--primary ez-title--xlarge ez-align--middle" }, this.formTitle)),
100
+ h("ez-button", { title: this.getMessage("snkForm.goBackTitle"), mode: "icon", iconName: "arrow_back", class: "ez-padding-right--medium", size: "small", onClick: () => this.exitForm() }),
101
+ h("h1", { class: "ez-title ez-title--primary ez-title--xlarge ez-align--middle" }, this.getMessage("snkForm.title"))),
95
102
  h("div", { class: "ez-col ez-col--sd-6 ez-col--tb-6 ez-align--right" },
96
103
  h("snk-taskbar", { key: "formTaskbar", buttons: this._dataState.isDirty ? "CANCEL,SAVE" : "PREVIOUS,NEXT,DIVIDER,CLONE,REMOVE,MORE_OPTIONS,DIVIDER,GRID_MODE,INSERT", primaryButton: this._dataState.isDirty ? "SAVE" : "INSERT", disabledButtons: this.getDisabledButtons(), actionsList: this.actionsList, dataUnit: this._dataUnit }))),
97
104
  h("section", null,
@@ -108,23 +115,6 @@ export class SnkForm {
108
115
  "$": ["snk-form.css"]
109
116
  }; }
110
117
  static get properties() { return {
111
- "formTitle": {
112
- "type": "string",
113
- "mutable": false,
114
- "complexType": {
115
- "original": "string",
116
- "resolved": "string",
117
- "references": {}
118
- },
119
- "required": false,
120
- "optional": false,
121
- "docs": {
122
- "tags": [],
123
- "text": "Texto que aparece de forma descritiva no cabe\u00E7alho do form"
124
- },
125
- "attribute": "form-title",
126
- "reflect": false
127
- },
128
118
  "configName": {
129
119
  "type": "string",
130
120
  "mutable": false,
@@ -41,7 +41,7 @@ export const buildElem = (element, className, getTitle, action, isEnabled, actio
41
41
  case TaskbarElement.INSERT:
42
42
  return iconTextButton("plus", element, className, getTitle, action, isEnabled);
43
43
  case TaskbarElement.CANCEL:
44
- return h("ez-button", { label: getTitle(element), size: "small", enabled: isEnabled(element), onClick: () => action(element) });
44
+ return h("ez-button", { title: getTitle(element), label: getTitle(element), size: "small", enabled: isEnabled(element), onClick: () => action(element) });
45
45
  case TaskbarElement.SAVE:
46
46
  return iconTextButton("save", element, className, getTitle, action, isEnabled);
47
47
  case TaskbarElement.GRID_MODE:
@@ -24,23 +24,42 @@ export class SnkTaskbar {
24
24
  }
25
25
  return true;
26
26
  }
27
+ /**
28
+ * Conforme mecanismo de mensagens, é possível customizar as mensagens dos blocos de construção
29
+ * através de um pequeno modulo na estrutura da aplicação:
30
+ * - Criar um arquivo no seguinte caminho: /messages/appmessages.msg.js.
31
+ * Para conhecer os detalhes do módulo, vide o arquivo neste projeto "/src/lib/message/resources/snk-taskbar.msg.ts"
32
+ */
27
33
  getTitle(element) {
28
- const pt_br = {
29
- [TaskbarElement.UPDATE]: "Editar",
30
- [TaskbarElement.PREVIOUS]: "Anterior",
31
- [TaskbarElement.NEXT]: "Próximo",
32
- [TaskbarElement.REFRESH]: "Atualizar",
33
- [TaskbarElement.CLONE]: "Duplicar",
34
- [TaskbarElement.REMOVE]: "Excluir",
35
- [TaskbarElement.MORE_OPTIONS]: "Mais Opções",
36
- [TaskbarElement.INSERT]: "Cadastrar",
37
- [TaskbarElement.CANCEL]: "Cancelar",
38
- [TaskbarElement.SAVE]: "Salvar",
39
- [TaskbarElement.GRID_MODE]: "Modo Grade",
40
- [TaskbarElement.CONFIG_GRID]: "Configuração da grade",
41
- [TaskbarElement.FORM_MODE]: "Modo Formulário"
42
- };
43
- return pt_br[element] ? pt_br[element] : "";
34
+ switch (element) {
35
+ case TaskbarElement.UPDATE:
36
+ return this._application.messagesBuilder.getMessage("snkTaskbar.titleUpdate", {});
37
+ case TaskbarElement.PREVIOUS:
38
+ return this._application.messagesBuilder.getMessage("snkTaskbar.titlePrevious", {});
39
+ case TaskbarElement.NEXT:
40
+ return this._application.messagesBuilder.getMessage("snkTaskbar.titleNext", {});
41
+ case TaskbarElement.REFRESH:
42
+ return this._application.messagesBuilder.getMessage("snkTaskbar.titleRefresh", {});
43
+ case TaskbarElement.CLONE:
44
+ return this._application.messagesBuilder.getMessage("snkTaskbar.titleClone", {});
45
+ case TaskbarElement.REMOVE:
46
+ return this._application.messagesBuilder.getMessage("snkTaskbar.titleRemove", {});
47
+ case TaskbarElement.MORE_OPTIONS:
48
+ return this._application.messagesBuilder.getMessage("snkTaskbar.titleMoreOptions", {});
49
+ case TaskbarElement.INSERT:
50
+ return this._application.messagesBuilder.getMessage("snkTaskbar.titleInsert", {});
51
+ case TaskbarElement.CANCEL:
52
+ return this._application.messagesBuilder.getMessage("snkTaskbar.titleCancel", {});
53
+ case TaskbarElement.SAVE:
54
+ return this._application.messagesBuilder.getMessage("snkTaskbar.titleSave", {});
55
+ case TaskbarElement.GRID_MODE:
56
+ return this._application.messagesBuilder.getMessage("snkTaskbar.titleGridMode", {});
57
+ case TaskbarElement.CONFIG_GRID:
58
+ return this._application.messagesBuilder.getMessage("snkTaskbar.titleConfigGrid", {});
59
+ case TaskbarElement.FORM_MODE:
60
+ return this._application.messagesBuilder.getMessage("snkTaskbar.titleFormMode", {});
61
+ }
62
+ return "";
44
63
  }
45
64
  elementClick(elem) {
46
65
  if (this.dataUnit) {
@@ -87,9 +106,9 @@ export class SnkTaskbar {
87
106
  }
88
107
  // Lifecycle
89
108
  componentWillLoad() {
90
- const snkApplication = ApplicationContext.getContextValue("__SNK__APPLICATION__");
91
- if (snkApplication) {
92
- snkApplication.getAllAccess().then(access => this._permissions = access);
109
+ this._application = ApplicationContext.getContextValue("__SNK__APPLICATION__");
110
+ if (this._application) {
111
+ this._application.getAllAccess().then(access => this._permissions = access);
93
112
  }
94
113
  else {
95
114
  this._permissions = {};
@@ -4,7 +4,7 @@ import UrlUtils from "../../../lib/utils/urlutils";
4
4
  import { StringUtils } from '@sankhyalabs/core';
5
5
  export class DataFetcher {
6
6
  constructor() {
7
- this.GRAPHQL_PATH = window['applicationenv'] === "sankhyaom" ? "/mge/graphql" : "";
7
+ this.GRAPHQL_PATH = "/mge/graphql";
8
8
  this.watingRequestsById = new Map();
9
9
  }
10
10
  static get() {
@@ -0,0 +1,119 @@
1
+ import snkDataUnitMessages from "./resources/snk-data-unit.msg.js";
2
+ import snkFormMessages from "./resources/snk-form.msg.js";
3
+ import snkTaskbarMessages from "./resources/snk-taskbar.msg.js";
4
+ export class SnkMessageBuilder {
5
+ constructor() {
6
+ this._defaults = {
7
+ snkDataUnit: snkDataUnitMessages,
8
+ snkForm: snkFormMessages,
9
+ snkTaskbar: snkTaskbarMessages
10
+ };
11
+ this._currentOperation = OperationMap.CLEAN;
12
+ this.loadAppMessages().then((msgs) => {
13
+ this._appMessages = msgs;
14
+ }, error => {
15
+ console.info('O arquivo de mensagens personalizadas não foi encontrado no caminho /messages/appmessages.js', error);
16
+ });
17
+ }
18
+ /**
19
+ * Existem mensagens sensíveis a operação. Por exemplo, a mensagem
20
+ * de inclusão pode ser diferente da mensagem de alteração do mesmo
21
+ * recurso. Para isso "currentOperation" pode variar de acordo com
22
+ * OperationMap.
23
+ */
24
+ set currentOperation(op) {
25
+ this._currentOperation = op;
26
+ }
27
+ /**
28
+ * Método usado para se obter mensagens, respeitando o padrão do sistema
29
+ * ou as mensagens específicas de cada tela
30
+ *
31
+ * @param key Chave usada para obter mensagens. Deve-se usar o separador "."
32
+ * alcançar diversos níveis.
33
+ * @param params Quando a mensagem possui o padrão {{NOME}} as ocorrências
34
+ * serão substituidas pelo respectivo valor do param.
35
+ * @returns A mensagem formatada.
36
+ */
37
+ getMessage(key, params) {
38
+ if (key == undefined) {
39
+ return undefined;
40
+ }
41
+ var parts = key.split(".");
42
+ let msg = this.resolveMessage(parts, this._appMessages);
43
+ if (msg == undefined) {
44
+ msg = this.resolveMessage(parts, this._defaults);
45
+ }
46
+ if (this.customMessageBuilder) {
47
+ const result = this.customMessageBuilder(key, msg, params);
48
+ msg = result.message;
49
+ params = result.params;
50
+ }
51
+ return this.postProcess(msg, params);
52
+ }
53
+ resolveMessage(keys, object) {
54
+ if (object == undefined) {
55
+ return undefined;
56
+ }
57
+ const key = keys[0];
58
+ const result = object[key];
59
+ if (result) {
60
+ if (this.isOperationSensitive(result)) {
61
+ return result[this._currentOperation];
62
+ }
63
+ else {
64
+ const isLeaf = keys.length === 1 ||
65
+ result == undefined ||
66
+ typeof result === "string";
67
+ return isLeaf ? result : this.resolveMessage(keys.slice(1), result);
68
+ }
69
+ }
70
+ }
71
+ isOperationSensitive(value) {
72
+ return value[OperationMap.CLONE] != undefined ||
73
+ value[OperationMap.INSERT] != undefined ||
74
+ value[OperationMap.UPDATE] != undefined ||
75
+ value[OperationMap.CLEAN] != undefined;
76
+ }
77
+ postProcess(message, params) {
78
+ if (message) {
79
+ const propPattern = /(.*?)\{\{(.+?)\}\}/g;
80
+ let processed = "";
81
+ let tail = message;
82
+ let result;
83
+ while ((result = propPattern.exec(message)) !== null) {
84
+ const [match, head, attribute] = result;
85
+ const tailIndex = result.index + match.length;
86
+ tail = tailIndex < message.length ? message.substring(tailIndex) : "";
87
+ let replacement = params ? params[attribute] : undefined;
88
+ if (replacement == undefined) {
89
+ replacement = "";
90
+ }
91
+ processed += head + replacement;
92
+ }
93
+ return processed + tail;
94
+ }
95
+ else {
96
+ return message;
97
+ }
98
+ }
99
+ loadAppMessages() {
100
+ return new Promise((accept, reject) => {
101
+ const messagesUrl = window['applicationenv'] !== "dev" ? `/${window["MGE_MODULE_NAME"]}/labsApps/${window["APPLICATION_NAME"]}/messages/appmessages.js`
102
+ : '/messages/appmessages.js';
103
+ import(/* webpackIgnore: true */ messagesUrl)
104
+ .then(module => {
105
+ accept(module.default);
106
+ })
107
+ .catch(reason => {
108
+ reject(reason);
109
+ });
110
+ });
111
+ }
112
+ }
113
+ export var OperationMap;
114
+ (function (OperationMap) {
115
+ OperationMap["CLONE"] = "clone";
116
+ OperationMap["INSERT"] = "insert";
117
+ OperationMap["UPDATE"] = "update";
118
+ OperationMap["CLEAN"] = "clean";
119
+ })(OperationMap || (OperationMap = {}));
@@ -0,0 +1,22 @@
1
+ const snkDataUnitMessages = {
2
+ saveInfo: {
3
+ clone: "Duplicação realizada!",
4
+ insert: "Inclusão realizada!",
5
+ update: "Aleração realizada!"
6
+ },
7
+ cancelInfo: {
8
+ clone: "Duplicação descartada!",
9
+ insert: "A inclusão descartada!",
10
+ update: "A edição foi descartada!"
11
+ },
12
+ removeInfo: "Registro removido com sucesso!",
13
+ cancelConfirmationTitle: "Aviso",
14
+ cancelConfirmation: "As alterações realizadas serão descartadas<br/><br/><b>Você realmente gostaria de cancelar?",
15
+ removeConfirmationTitle: "Excluir",
16
+ removeConfirmation: "Deseja realmente excluir o registro atual?",
17
+ forbiddenUpdate: "Não é possível fazer alterações. Verifique as permissões de acesso.",
18
+ forbiddenInsert: "Não é possível incluir. Verifique as permissões de acesso.",
19
+ forbiddenClone: "Não é possível duplicar. Verifique as permissões de acesso.",
20
+ forbiddenRemove: "Não é possível remover. Verifique as permissões de acesso."
21
+ };
22
+ export default snkDataUnitMessages;