goblin-desktop 4.2.0 → 4.2.2

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 (144) hide show
  1. package/.editorconfig +9 -9
  2. package/.zou-flow +2 -2
  3. package/LICENSE +21 -21
  4. package/README.md +108 -108
  5. package/builders/builders.js +3 -3
  6. package/builders/wizard.js +462 -462
  7. package/contexts.js +13 -13
  8. package/desktop-manager.js +10 -10
  9. package/desktop-window.js +13 -13
  10. package/desktop.js +13 -13
  11. package/eslint.config.js +65 -65
  12. package/lib/service.js +137 -137
  13. package/package.json +48 -48
  14. package/password-wizard.js +24 -24
  15. package/quest-run-wizard.js +24 -24
  16. package/taskbar.js +13 -13
  17. package/widgets/audio/sfx.js +177 -177
  18. package/widgets/board/view.js +37 -37
  19. package/widgets/board/widget.js +65 -65
  20. package/widgets/contexts/logic-handlers.js +36 -36
  21. package/widgets/contexts/service.js +40 -40
  22. package/widgets/contexts/view.js +21 -21
  23. package/widgets/contexts/widget.js +147 -147
  24. package/widgets/datagrid/datagrid-entity.js +82 -82
  25. package/widgets/datagrid/datagrid-headers.js +274 -274
  26. package/widgets/datagrid/styles.js +13 -13
  27. package/widgets/datagrid/widget.js +192 -192
  28. package/widgets/datagrid-cell/styles.js +52 -52
  29. package/widgets/datagrid-cell/widget.js +41 -41
  30. package/widgets/datagrid-item/styles.js +15 -15
  31. package/widgets/datagrid-item/widget.js +74 -74
  32. package/widgets/default/view.js +160 -160
  33. package/widgets/desktop/compensator.js +9 -9
  34. package/widgets/desktop/logic-handlers.js +243 -243
  35. package/widgets/desktop/reducer.js +35 -35
  36. package/widgets/desktop/service.js +858 -858
  37. package/widgets/desktop/styles.js +28 -28
  38. package/widgets/desktop/widget.js +191 -191
  39. package/widgets/desktop-clock/styles.js +69 -69
  40. package/widgets/desktop-clock/widget.js +387 -387
  41. package/widgets/desktop-clock-clock/styles.js +56 -56
  42. package/widgets/desktop-clock-clock/widget.js +96 -96
  43. package/widgets/desktop-clock-menu/styles.js +129 -129
  44. package/widgets/desktop-clock-menu/widget.js +63 -63
  45. package/widgets/desktop-connection-status/reducer.js +15 -15
  46. package/widgets/desktop-connection-status/styles.js +44 -44
  47. package/widgets/desktop-connection-status/widget.js +134 -134
  48. package/widgets/desktop-content/widget.js +68 -68
  49. package/widgets/desktop-footer/reducer.js +31 -31
  50. package/widgets/desktop-footer/styles.js +36 -36
  51. package/widgets/desktop-footer/widget.js +52 -52
  52. package/widgets/desktop-monitors/styles.js +155 -155
  53. package/widgets/desktop-monitors/widget.js +272 -272
  54. package/widgets/desktop-notebook/styles.js +155 -155
  55. package/widgets/desktop-notebook/widget.js +252 -252
  56. package/widgets/desktop-notifications/styles.js +147 -147
  57. package/widgets/desktop-notifications/widget.js +231 -231
  58. package/widgets/desktop-scale/reducer.js +15 -15
  59. package/widgets/desktop-scale/styles.js +49 -49
  60. package/widgets/desktop-scale/widget.js +173 -172
  61. package/widgets/desktop-state-monitor/styles.js +72 -72
  62. package/widgets/desktop-state-monitor/widget.js +123 -123
  63. package/widgets/desktop-taskbar/widget.js +57 -57
  64. package/widgets/desktop-themes-menu/widget.js +121 -121
  65. package/widgets/desktop-topbar/widget.js +201 -201
  66. package/widgets/desktop-window/service.js +56 -56
  67. package/widgets/desktop-window/styles.js +22 -22
  68. package/widgets/desktop-window/widget.js +70 -70
  69. package/widgets/detail/compensator.js +17 -17
  70. package/widgets/detail/view.js +40 -40
  71. package/widgets/detail/widget.js +119 -119
  72. package/widgets/editor/widget.js +82 -82
  73. package/widgets/entity-alerts/styles.js +77 -77
  74. package/widgets/entity-alerts/widget.js +328 -328
  75. package/widgets/entity-list/styles.js +66 -66
  76. package/widgets/entity-list/view.js +36 -36
  77. package/widgets/entity-list/widget.js +209 -209
  78. package/widgets/entity-list-item/widget.js +68 -68
  79. package/widgets/entity-row/styles.js +105 -105
  80. package/widgets/entity-row/widget.js +524 -524
  81. package/widgets/entity-row-button/styles.js +46 -46
  82. package/widgets/entity-row-button/widget.js +57 -57
  83. package/widgets/entity-view/reducer.js +20 -20
  84. package/widgets/entity-view/styles.js +90 -90
  85. package/widgets/entity-view/widget.js +601 -601
  86. package/widgets/facet-checkbox/styles.js +17 -17
  87. package/widgets/facet-checkbox/widget.js +43 -43
  88. package/widgets/facet-filter/widget.js +94 -94
  89. package/widgets/facet-filter-add/styles.js +30 -30
  90. package/widgets/facet-filter-add/widget.js +105 -105
  91. package/widgets/facet-filter-button/styles.js +74 -74
  92. package/widgets/facet-filter-button/widget.js +214 -214
  93. package/widgets/facet-filter-list-dialog/styles.js +59 -59
  94. package/widgets/facet-filter-list-dialog/widget.js +273 -273
  95. package/widgets/facet-filter-list-dialog-footer/styles.js +22 -22
  96. package/widgets/facet-filter-list-dialog-footer/widget.js +105 -105
  97. package/widgets/facet-filter-range-dialog/styles.js +82 -82
  98. package/widgets/facet-filter-range-dialog/widget.js +399 -399
  99. package/widgets/facet-filter-range-dialog-footer/styles.js +22 -22
  100. package/widgets/facet-filter-range-dialog-footer/widget.js +182 -182
  101. package/widgets/gamepad/widget.js +75 -75
  102. package/widgets/helpers/facet-helpers.js +105 -105
  103. package/widgets/hinter/reducer.js +35 -35
  104. package/widgets/hinter/styles.js +79 -79
  105. package/widgets/hinter/view.js +32 -32
  106. package/widgets/hinter/widget.js +289 -291
  107. package/widgets/junction/styles.js +22 -22
  108. package/widgets/junction/widget.js +50 -50
  109. package/widgets/main-tab-menu/styles.js +17 -17
  110. package/widgets/main-tab-menu/widget.js +130 -130
  111. package/widgets/map/view.js +49 -49
  112. package/widgets/map/widget.js +64 -64
  113. package/widgets/monitor/reducer.js +15 -15
  114. package/widgets/monitor/widget.js +60 -60
  115. package/widgets/navigating-layer/widget.js +25 -25
  116. package/widgets/notifications-button/widget.js +44 -44
  117. package/widgets/password-wizard/service.js +53 -53
  118. package/widgets/password-wizard/ui.js +66 -66
  119. package/widgets/plugin/reducer.js +19 -19
  120. package/widgets/plugin/styles.js +294 -294
  121. package/widgets/plugin/widget.js +622 -622
  122. package/widgets/quest-run-wizard/service.js +49 -49
  123. package/widgets/quest-run-wizard/ui.js +25 -25
  124. package/widgets/search/styles.js +80 -80
  125. package/widgets/search/widget.js +283 -285
  126. package/widgets/simple/view.js +28 -28
  127. package/widgets/status-filters/widget.js +121 -121
  128. package/widgets/tab/styles.js +16 -16
  129. package/widgets/tab/widget.js +89 -89
  130. package/widgets/tab-content/widget.js +35 -35
  131. package/widgets/tabs/widget.js +48 -48
  132. package/widgets/taskbar/service.js +99 -99
  133. package/widgets/taskbar/view.js +27 -27
  134. package/widgets/taskbar/widget.js +167 -167
  135. package/widgets/widget-doc-caller/reducer.js +15 -15
  136. package/widgets/widget-doc-caller/styles.js +20 -20
  137. package/widgets/widget-doc-caller/widget.js +55 -55
  138. package/widgets/wizard/widget.js +298 -298
  139. package/widgets/wizard-buttons/widget.js +111 -111
  140. package/widgets/workitem/styles.js +286 -286
  141. package/widgets/workitem/view.js +62 -62
  142. package/widgets/workitem/widget.js +988 -988
  143. package/widgets/workitem-dialog/widget.js +86 -86
  144. package/widgets/workitem-fields/widget.js +64 -64
@@ -1,622 +1,622 @@
1
- //T:2019-02-27
2
-
3
- import React from 'react';
4
- import scrollIntoViewIfNeeded from 'scroll-into-view-if-needed';
5
- import Widget from 'goblin-laboratory/widgets/widget';
6
- import StateLoader from 'goblin-laboratory/widgets/state-loader/widget.js';
7
- import {Unit} from 'goblin-theme';
8
- const px = Unit.toPx;
9
-
10
- import Workitem from 'goblin-desktop/widgets/workitem/widget';
11
- import Container from 'goblin-gadgets/widgets/container/widget';
12
- import Button from 'goblin-gadgets/widgets/button/widget';
13
- import Label from 'goblin-gadgets/widgets/label/widget';
14
- import Field from 'goblin-gadgets/widgets/field/widget';
15
- import DragCab from 'goblin-gadgets/widgets/drag-cab/widget';
16
- import Combo from 'goblin-gadgets/widgets/combo/widget';
17
-
18
- import importer from 'goblin_importer';
19
- import T from 't';
20
- import stateMapperToProps from 'goblin-laboratory/widgets/state-mapper-to-props/widget';
21
-
22
- const uiImporter = importer('ui');
23
-
24
- /******************************************************************************/
25
-
26
- class Plugin extends Widget {
27
- constructor() {
28
- super(...arguments);
29
-
30
- this._refs = {};
31
- this._scrollEntityId = null;
32
- this.comboButton = null;
33
-
34
- this.state = {
35
- showActionMenu: false,
36
- };
37
-
38
- this.onAction = this.onAction.bind(this);
39
- this.onActionAdd = this.onActionAdd.bind(this);
40
- this.onSwapExtended = this.onSwapExtended.bind(this);
41
- this.onDeleteEntity = this.onDeleteEntity.bind(this);
42
- this.onEditEntity = this.onEditEntity.bind(this);
43
- this.onEntityDragged = this.onEntityDragged.bind(this);
44
- this.doProxy = this.doProxy.bind(this);
45
- this.open = this.open.bind(this);
46
- this.close = this.close.bind(this);
47
- }
48
-
49
- get showActionMenu() {
50
- return this.state.showActionMenu;
51
- }
52
-
53
- set showActionMenu(value) {
54
- this.setState({
55
- showActionMenu: value,
56
- });
57
- }
58
-
59
- _scrollIntoView(duration) {
60
- if (
61
- !this._scrollEntityId ||
62
- !this._refs[this._scrollEntityId] ||
63
- this._scrollEntityId !== this.props.extendedId
64
- ) {
65
- return;
66
- }
67
-
68
- scrollIntoViewIfNeeded(this._refs[this._scrollEntityId], {
69
- duration,
70
- // HACK: we need to fix the transitions in order to remove this offset
71
- offset: {
72
- top: 3,
73
- },
74
- });
75
- }
76
-
77
- componentDidUpdate() {
78
- this._scrollIntoView(150);
79
- }
80
-
81
- onAction(actionName) {
82
- const service = this.props.namespace;
83
- switch (actionName) {
84
- case 'add':
85
- this.doAs(service, actionName);
86
- break;
87
- case 'clear':
88
- this.doAs(service, actionName);
89
- break;
90
- default:
91
- this.doAs(service, 'do-action', {action: actionName});
92
- }
93
- }
94
-
95
- onActionAdd() {
96
- this.onAction('add');
97
- }
98
-
99
- onSwapExtended(entityId) {
100
- this._scrollEntityId = entityId;
101
- this.dispatch({type: 'TOGGLE_EXTENDED', entityId});
102
- }
103
-
104
- onDeleteEntity(entityId) {
105
- const service = this.props.namespace;
106
- this.doAs(service, 'remove', {entityId});
107
- }
108
-
109
- onEditEntity(entityId) {
110
- const service = this.props.namespace;
111
- this.doAs(service, 'edit', {entityId});
112
- }
113
-
114
- onEntityDragged(selectedIds, toId, ownerId, ownerKind) {
115
- const service = this.props.namespace;
116
- if (ownerId === this.props.id) {
117
- this.doAs(service, 'drag', {
118
- fromId: selectedIds[0],
119
- toId: toId,
120
- });
121
- } else {
122
- this.doAs(service, 'remove', {
123
- entityId: selectedIds[0],
124
- });
125
- this.cmd(`${service}.add`, {
126
- id: ownerId,
127
- entityId: selectedIds[0],
128
- });
129
- }
130
- }
131
-
132
- getActionMenuList(numberOfIds) {
133
- const list = [];
134
-
135
- if (this.props.actionMenu) {
136
- for (const item of this.props.actionMenu) {
137
- if (!item.min || item.min <= numberOfIds) {
138
- list.push({
139
- glyph: item.glyph,
140
- text: item.text,
141
- action: () => this.onAction(item.actionName),
142
- });
143
- }
144
- }
145
- }
146
-
147
- if (
148
- numberOfIds > 0 &&
149
- (!this.props.arity || !this.props.arity.startsWith('1'))
150
- ) {
151
- if (list.length > 0) {
152
- list.push({
153
- separator: true,
154
- });
155
- }
156
- list.push({
157
- glyph: 'solid/trash',
158
- text: T('Tout supprimer'),
159
- action: () => this.onAction('clear'),
160
- });
161
- }
162
-
163
- return list;
164
- }
165
-
166
- doProxy(index) {
167
- return (action, args) => {
168
- const workitemId = `${this.props.editorWidget}@${
169
- this.context.desktopId
170
- }@${this.props.entityIds.get(index)}`;
171
- this.doFor(workitemId, action, args);
172
- };
173
- }
174
-
175
- open() {
176
- this.showActionMenu = true;
177
- }
178
-
179
- close() {
180
- this.showActionMenu = false;
181
- }
182
-
183
- /******************************************************************************/
184
-
185
- renderHeaderSearch() {
186
- if (this.props.searchHinter) {
187
- return (
188
- <Field
189
- shape="rounded"
190
- labelGlyph="solid/search"
191
- labelWidth="24px"
192
- fieldWidth="180px"
193
- hintText={T('Ajouter existant')}
194
- tooltip={T(
195
- 'Ajouter un élément existant en le choisissant dans une liste'
196
- )}
197
- kind="hinter"
198
- required={false}
199
- hinter={this.props.searchHinter}
200
- horizontalSpacing="large"
201
- />
202
- );
203
- } else {
204
- return null;
205
- }
206
- }
207
-
208
- renderHeaderActionMenuButton(numberOfIds) {
209
- const list = this.getActionMenuList(numberOfIds);
210
- if (list.length > 0) {
211
- return (
212
- <Button
213
- ref={(x) => (this.comboButton = x)}
214
- glyph="solid/ellipsis-h"
215
- horizontalSpacing="large"
216
- active={this.showActionMenu}
217
- onClick={this.open}
218
- />
219
- );
220
- } else {
221
- return null;
222
- }
223
- }
224
-
225
- renderHeaderActionMenu(numberOfIds) {
226
- if (this.showActionMenu) {
227
- const node = this.comboButton.ref;
228
- const rect = node.getBoundingClientRect();
229
- const top = Unit.add(
230
- px(rect.bottom),
231
- this.context.theme.shapes.flyingBalloonTriangleSize
232
- );
233
-
234
- return (
235
- <Combo
236
- menuType="menu"
237
- left={(rect.left + rect.right) / 2}
238
- top={top}
239
- list={this.getActionMenuList(numberOfIds)}
240
- close={this.close}
241
- />
242
- );
243
- } else {
244
- return null;
245
- }
246
- }
247
-
248
- renderHeaderAdd(numberOfIds) {
249
- const canAdd =
250
- !this.props.disableAdd &&
251
- (!this.props.arity ||
252
- this.props.arity.endsWith('n') ||
253
- (this.props.arity === '0..1' && numberOfIds === 0));
254
-
255
- if (canAdd) {
256
- return (
257
- <Button
258
- glyph="solid/plus"
259
- text={this.props.addText || T('Ajouter')}
260
- tooltip={this.props.addTooltip}
261
- glyphPosition="right"
262
- onClick={this.onActionAdd}
263
- />
264
- );
265
- } else {
266
- return null;
267
- }
268
- }
269
-
270
- renderHeader(numberOfIds) {
271
- const headerClass =
272
- this.props.entityIds.size === 0
273
- ? this.styles.classNames.headerEmpty
274
- : this.styles.classNames.header;
275
-
276
- const title = this.props.pluginTitle
277
- ? this.props.pluginTitle
278
- : this.props.title;
279
-
280
- if (this.props.readonly) {
281
- return (
282
- <div className={headerClass}>
283
- <Label text={title} grow="1" kind="title" />
284
- </div>
285
- );
286
- } else {
287
- return (
288
- <div className={headerClass}>
289
- <Label text={title} grow="1" kind="title" />
290
- {this.renderHeaderSearch()}
291
- {this.renderHeaderActionMenuButton(numberOfIds)}
292
- {this.renderHeaderAdd(numberOfIds)}
293
- {this.renderHeaderActionMenu(numberOfIds)}
294
- </div>
295
- );
296
- }
297
- }
298
-
299
- renderLoading() {
300
- return (
301
- <Container busy={true}>
302
- <Label text={T('chargement...')} />
303
- </Container>
304
- );
305
- }
306
-
307
- renderItem(entityId, extended, index) {
308
- const workitemUI = uiImporter(this.props.editorWidget);
309
- const workitemId = `${this.props.editorWidget}@${
310
- this.context.desktopId
311
- }@${this.props.entityIds.get(index)}`;
312
-
313
- if (!workitemUI.plugin) {
314
- return null;
315
- }
316
-
317
- const itemClass = extended
318
- ? this.props.embedded
319
- ? this.styles.classNames.extendedEmbeddedItem
320
- : this.styles.classNames.extendedItem
321
- : this.props.embedded
322
- ? this.styles.classNames.compactedEmbeddedItem
323
- : this.styles.classNames.compactedItem;
324
-
325
- const key1 = this.props.readonly ? 'readonly' : 'edit';
326
- const key2 = extended ? 'extend' : 'compact';
327
- const mapper =
328
- workitemUI.mappers &&
329
- workitemUI.mappers.plugin &&
330
- workitemUI.mappers.plugin[key1] &&
331
- workitemUI.mappers.plugin[key1][key2];
332
- const UI = stateMapperToProps(
333
- workitemUI.plugin[key1][key2],
334
- mapper,
335
- `backend.${entityId}`
336
- );
337
-
338
- const type = entityId.split('@', 1)[0];
339
-
340
- return (
341
- <div className={itemClass}>
342
- <StateLoader path={workitemId} FallbackComponent={this.renderLoading}>
343
- <Workitem
344
- id={workitemId}
345
- entityId={entityId}
346
- kind="form"
347
- readonly={this.props.readonly}
348
- dragServiceId={this.props.dragServiceId}
349
- >
350
- <StateLoader path={entityId}>
351
- <UI
352
- id={workitemId}
353
- theme={this.context.theme}
354
- entityId={entityId}
355
- pluginProps={this.props.pluginProps}
356
- embeddedLevel={this.props.embeddedLevel}
357
- origin={this.props.origin}
358
- contextId={this.context.contextId}
359
- do={this.doProxy(index)}
360
- entitySchema={this.getSchema(type)}
361
- />
362
- </StateLoader>
363
- </Workitem>
364
- </StateLoader>
365
- </div>
366
- );
367
- }
368
-
369
- renderButtons(entityId, extended, numberOfIds) {
370
- if (extended) {
371
- const buttonsClass = this.props.readonly
372
- ? this.props.embedded
373
- ? this.styles.classNames.extendedEmbeddedReadonlyButtons
374
- : this.styles.classNames.extendedReadonlyButtons
375
- : this.props.embedded
376
- ? this.styles.classNames.extendedEmbeddedButtons
377
- : this.styles.classNames.extendedButtons;
378
-
379
- const canDelete =
380
- !this.props.readonly &&
381
- !this.props.disableDelete &&
382
- (!this.props.arity ||
383
- this.props.arity.startsWith('0') ||
384
- numberOfIds > 1);
385
-
386
- const kind = this.props.readonly ? 'plugin-light' : 'plugin-dark';
387
-
388
- let otherButtons = null;
389
- if (this.props.buttons) {
390
- otherButtons = this.props.buttons(entityId);
391
- }
392
-
393
- return (
394
- <div className={buttonsClass}>
395
- <Button
396
- width="32px"
397
- kind={kind}
398
- glyph="solid/angle-up"
399
- glyphSize="180%"
400
- tooltip={T('Replier')}
401
- active={false}
402
- activeColor={
403
- this.context.theme.palette.recurrenceExtendedBoxBackground
404
- }
405
- onClick={() => this.onSwapExtended(entityId)}
406
- />
407
- <Button
408
- width="32px"
409
- kind={kind}
410
- glyph="solid/pencil"
411
- tooltip={T('Editer')}
412
- onClick={() => this.onEditEntity(entityId)}
413
- />
414
- {otherButtons}
415
- {canDelete ? (
416
- <Button
417
- width="32px"
418
- kind={kind}
419
- glyph="solid/trash"
420
- tooltip={T('Supprimer')}
421
- onClick={() => this.onDeleteEntity(entityId)}
422
- />
423
- ) : null}
424
- </div>
425
- );
426
- } else {
427
- const buttonsClass = this.props.readonly
428
- ? this.props.embedded
429
- ? this.styles.classNames.compactedEmbeddedReadonlyButtons
430
- : this.styles.classNames.compactedReadonlyButtons
431
- : this.props.embedded
432
- ? this.styles.classNames.compactedEmbeddedButtons
433
- : this.styles.classNames.compactedButtons;
434
-
435
- const kind =
436
- this.props.readonly || !this.props.embedded
437
- ? 'plugin-light'
438
- : 'plugin-dark';
439
-
440
- return (
441
- <div className={buttonsClass}>
442
- {this.props.readonly && !this.props.embedded ? (
443
- <Button
444
- width="32px"
445
- kind={kind}
446
- glyph="solid/pencil"
447
- tooltip={T('Editer')}
448
- onClick={() => this.onEditEntity(entityId)}
449
- />
450
- ) : null}
451
- <Button
452
- width="32px"
453
- kind={kind}
454
- glyph="solid/angle-down"
455
- glyphSize="180%"
456
- tooltip={T('Etendre')}
457
- active={false}
458
- activeColor={
459
- this.context.theme.palette.recurrenceExtendedBoxBackground
460
- }
461
- onClick={() => this.onSwapExtended(entityId)}
462
- />
463
- </div>
464
- );
465
- }
466
- }
467
-
468
- renderRowContent(entityId, extended, numberOfIds, index) {
469
- const rowClass = extended
470
- ? this.props.embedded
471
- ? this.styles.classNames.extendedEmbeddedRow
472
- : this.styles.classNames.extendedRow
473
- : numberOfIds > 1 && this.props.horizontalSeparator !== 'compact'
474
- ? this.props.embedded
475
- ? this.styles.classNames.compactedEmbeddedDashedRow
476
- : this.styles.classNames.compactedDashedRow
477
- : this.props.embedded
478
- ? this.styles.classNames.compactedEmbeddedRow
479
- : this.styles.classNames.compactedRow;
480
-
481
- return (
482
- <Container
483
- kind="row-draggable"
484
- busyLook={extended ? null : 'smallest'}
485
- key={index}
486
- ref={(n) => {
487
- if (n) {
488
- // Get the html node ref via instance variable of component
489
- this._refs[entityId] = n.ref;
490
- } else {
491
- delete this._refs[entityId];
492
- }
493
- }}
494
- >
495
- <div className={rowClass}>
496
- {this.renderItem(entityId, extended, index)}
497
- {this.renderButtons(entityId, extended, numberOfIds)}
498
- </div>
499
- </Container>
500
- );
501
- }
502
-
503
- renderRow(entityId, extended, dragEnabled, numberOfIds, index) {
504
- if (dragEnabled) {
505
- return (
506
- <DragCab
507
- key={index}
508
- dragController={this.props.dragType || this.props.id}
509
- dragOwnerId={entityId}
510
- dragMode="handle"
511
- dragHandleWidth={this.context.theme.shapes.containerMargin}
512
- direction="vertical"
513
- color={this.context.theme.palette.dragAndDropHover}
514
- thickness={this.context.theme.shapes.dragAndDropTicketThickness}
515
- overSpacing="0px"
516
- verticalSpacing="0px"
517
- radius="0px"
518
- doClickAction={() => this.onSwapExtended(entityId)}
519
- doDragEnding={this.onEntityDragged}
520
- >
521
- {this.renderRowContent(entityId, extended, numberOfIds, index)}
522
- </DragCab>
523
- );
524
- } else {
525
- return this.renderRowContent(entityId, extended, numberOfIds, index);
526
- }
527
- }
528
-
529
- renderRows(entityIds) {
530
- const dragEnabled =
531
- !this.props.readonly && (entityIds.length > 1 || !!this.props.dragType);
532
-
533
- let index = 0;
534
-
535
- return entityIds.map((entityId) => {
536
- const extended = entityId === this.props.extendedId;
537
- return this.renderRow(
538
- entityId,
539
- extended,
540
- dragEnabled,
541
- entityIds.length,
542
- index++
543
- );
544
- });
545
- }
546
-
547
- renderDefault() {
548
- const entityIds = this.props.entityIds.valueSeq().toArray();
549
- if (entityIds.length === 0 && this.props.readonly && this.props.embedded) {
550
- return null;
551
- }
552
-
553
- let boxClass = null;
554
- if (!this.props.entityIds || this.props.entityIds.size === 0) {
555
- boxClass = this.props.embedded
556
- ? this.styles.classNames.emptyembeddedBox
557
- : this.styles.classNames.emptyBox;
558
- } else {
559
- boxClass = this.props.embedded
560
- ? this.styles.classNames.embeddedBox
561
- : this.styles.classNames.box;
562
- }
563
-
564
- return (
565
- <div className={boxClass}>
566
- {this.renderHeader(entityIds.length)}
567
- <Container
568
- kind="column"
569
- dragController={this.props.dragType || this.props.id}
570
- dragSource={this.props.id}
571
- dragOwnerId={this.props.id}
572
- >
573
- {this.renderRows(entityIds)}
574
- </Container>
575
- </div>
576
- );
577
- }
578
-
579
- render() {
580
- if (!this.props.id || !this.props.entityIds) {
581
- return null;
582
- }
583
-
584
- if (!this.props.editorWidget) {
585
- return null;
586
- }
587
-
588
- return this.renderDefault();
589
- }
590
- }
591
-
592
- /******************************************************************************/
593
-
594
- const select = (root) => (state, id) => (prop) => {
595
- if (!id) {
596
- return null;
597
- }
598
- const target = state.get(`${root}.${id}`);
599
- if (!target) {
600
- return null;
601
- }
602
- return target.get(prop);
603
- };
604
-
605
- const withBackend = select('backend');
606
- const withWidget = select('widgets');
607
-
608
- export default Widget.connect((state, props) => {
609
- const plugin = withBackend(state, props.id);
610
- const entity = withBackend(state, plugin('forEntity'));
611
- const widget = withWidget(state, props.id);
612
- return {
613
- id: props.id,
614
- title: plugin('title'),
615
- editorWidget: plugin('editorWidget'),
616
- arity: plugin('arity'),
617
- mode: plugin('mode'),
618
- entityIds: entity(plugin('entityPath')),
619
- namespace: `${plugin('type')}-plugin`,
620
- extendedId: widget('extendedId'),
621
- };
622
- })(Plugin);
1
+ //T:2019-02-27
2
+
3
+ import React from 'react';
4
+ import scrollIntoViewIfNeeded from 'scroll-into-view-if-needed';
5
+ import Widget from 'goblin-laboratory/widgets/widget';
6
+ import StateLoader from 'goblin-laboratory/widgets/state-loader/widget.js';
7
+ import {Unit} from 'goblin-theme';
8
+ const px = Unit.toPx;
9
+
10
+ import Workitem from 'goblin-desktop/widgets/workitem/widget';
11
+ import Container from 'goblin-gadgets/widgets/container/widget';
12
+ import Button from 'goblin-gadgets/widgets/button/widget';
13
+ import Label from 'goblin-gadgets/widgets/label/widget';
14
+ import Field from 'goblin-gadgets/widgets/field/widget';
15
+ import DragCab from 'goblin-gadgets/widgets/drag-cab/widget';
16
+ import Combo from 'goblin-gadgets/widgets/combo/widget';
17
+
18
+ import importer from 'goblin_importer';
19
+ import T from 't';
20
+ import stateMapperToProps from 'goblin-laboratory/widgets/state-mapper-to-props/widget';
21
+
22
+ const uiImporter = importer('ui');
23
+
24
+ /******************************************************************************/
25
+
26
+ class Plugin extends Widget {
27
+ constructor() {
28
+ super(...arguments);
29
+
30
+ this._refs = {};
31
+ this._scrollEntityId = null;
32
+ this.comboButton = null;
33
+
34
+ this.state = {
35
+ showActionMenu: false,
36
+ };
37
+
38
+ this.onAction = this.onAction.bind(this);
39
+ this.onActionAdd = this.onActionAdd.bind(this);
40
+ this.onSwapExtended = this.onSwapExtended.bind(this);
41
+ this.onDeleteEntity = this.onDeleteEntity.bind(this);
42
+ this.onEditEntity = this.onEditEntity.bind(this);
43
+ this.onEntityDragged = this.onEntityDragged.bind(this);
44
+ this.doProxy = this.doProxy.bind(this);
45
+ this.open = this.open.bind(this);
46
+ this.close = this.close.bind(this);
47
+ }
48
+
49
+ get showActionMenu() {
50
+ return this.state.showActionMenu;
51
+ }
52
+
53
+ set showActionMenu(value) {
54
+ this.setState({
55
+ showActionMenu: value,
56
+ });
57
+ }
58
+
59
+ _scrollIntoView(duration) {
60
+ if (
61
+ !this._scrollEntityId ||
62
+ !this._refs[this._scrollEntityId] ||
63
+ this._scrollEntityId !== this.props.extendedId
64
+ ) {
65
+ return;
66
+ }
67
+
68
+ scrollIntoViewIfNeeded(this._refs[this._scrollEntityId], {
69
+ duration,
70
+ // HACK: we need to fix the transitions in order to remove this offset
71
+ offset: {
72
+ top: 3,
73
+ },
74
+ });
75
+ }
76
+
77
+ componentDidUpdate() {
78
+ this._scrollIntoView(150);
79
+ }
80
+
81
+ onAction(actionName) {
82
+ const service = this.props.namespace;
83
+ switch (actionName) {
84
+ case 'add':
85
+ this.doAs(service, actionName);
86
+ break;
87
+ case 'clear':
88
+ this.doAs(service, actionName);
89
+ break;
90
+ default:
91
+ this.doAs(service, 'do-action', {action: actionName});
92
+ }
93
+ }
94
+
95
+ onActionAdd() {
96
+ this.onAction('add');
97
+ }
98
+
99
+ onSwapExtended(entityId) {
100
+ this._scrollEntityId = entityId;
101
+ this.dispatch({type: 'TOGGLE_EXTENDED', entityId});
102
+ }
103
+
104
+ onDeleteEntity(entityId) {
105
+ const service = this.props.namespace;
106
+ this.doAs(service, 'remove', {entityId});
107
+ }
108
+
109
+ onEditEntity(entityId) {
110
+ const service = this.props.namespace;
111
+ this.doAs(service, 'edit', {entityId});
112
+ }
113
+
114
+ onEntityDragged(selectedIds, toId, ownerId, ownerKind) {
115
+ const service = this.props.namespace;
116
+ if (ownerId === this.props.id) {
117
+ this.doAs(service, 'drag', {
118
+ fromId: selectedIds[0],
119
+ toId: toId,
120
+ });
121
+ } else {
122
+ this.doAs(service, 'remove', {
123
+ entityId: selectedIds[0],
124
+ });
125
+ this.cmd(`${service}.add`, {
126
+ id: ownerId,
127
+ entityId: selectedIds[0],
128
+ });
129
+ }
130
+ }
131
+
132
+ getActionMenuList(numberOfIds) {
133
+ const list = [];
134
+
135
+ if (this.props.actionMenu) {
136
+ for (const item of this.props.actionMenu) {
137
+ if (!item.min || item.min <= numberOfIds) {
138
+ list.push({
139
+ glyph: item.glyph,
140
+ text: item.text,
141
+ action: () => this.onAction(item.actionName),
142
+ });
143
+ }
144
+ }
145
+ }
146
+
147
+ if (
148
+ numberOfIds > 0 &&
149
+ (!this.props.arity || !this.props.arity.startsWith('1'))
150
+ ) {
151
+ if (list.length > 0) {
152
+ list.push({
153
+ separator: true,
154
+ });
155
+ }
156
+ list.push({
157
+ glyph: 'solid/trash',
158
+ text: T('Tout supprimer'),
159
+ action: () => this.onAction('clear'),
160
+ });
161
+ }
162
+
163
+ return list;
164
+ }
165
+
166
+ doProxy(index) {
167
+ return (action, args) => {
168
+ const workitemId = `${this.props.editorWidget}@${
169
+ this.context.desktopId
170
+ }@${this.props.entityIds.get(index)}`;
171
+ this.doFor(workitemId, action, args);
172
+ };
173
+ }
174
+
175
+ open() {
176
+ this.showActionMenu = true;
177
+ }
178
+
179
+ close() {
180
+ this.showActionMenu = false;
181
+ }
182
+
183
+ /******************************************************************************/
184
+
185
+ renderHeaderSearch() {
186
+ if (this.props.searchHinter) {
187
+ return (
188
+ <Field
189
+ shape="rounded"
190
+ labelGlyph="solid/search"
191
+ labelWidth="24px"
192
+ fieldWidth="180px"
193
+ hintText={T('Ajouter existant')}
194
+ tooltip={T(
195
+ 'Ajouter un élément existant en le choisissant dans une liste'
196
+ )}
197
+ kind="hinter"
198
+ required={false}
199
+ hinter={this.props.searchHinter}
200
+ horizontalSpacing="large"
201
+ />
202
+ );
203
+ } else {
204
+ return null;
205
+ }
206
+ }
207
+
208
+ renderHeaderActionMenuButton(numberOfIds) {
209
+ const list = this.getActionMenuList(numberOfIds);
210
+ if (list.length > 0) {
211
+ return (
212
+ <Button
213
+ ref={(x) => (this.comboButton = x)}
214
+ glyph="solid/ellipsis-h"
215
+ horizontalSpacing="large"
216
+ active={this.showActionMenu}
217
+ onClick={this.open}
218
+ />
219
+ );
220
+ } else {
221
+ return null;
222
+ }
223
+ }
224
+
225
+ renderHeaderActionMenu(numberOfIds) {
226
+ if (this.showActionMenu) {
227
+ const node = this.comboButton.ref;
228
+ const rect = node.getBoundingClientRect();
229
+ const top = Unit.add(
230
+ px(rect.bottom),
231
+ this.context.theme.shapes.flyingBalloonTriangleSize
232
+ );
233
+
234
+ return (
235
+ <Combo
236
+ menuType="menu"
237
+ left={(rect.left + rect.right) / 2}
238
+ top={top}
239
+ list={this.getActionMenuList(numberOfIds)}
240
+ close={this.close}
241
+ />
242
+ );
243
+ } else {
244
+ return null;
245
+ }
246
+ }
247
+
248
+ renderHeaderAdd(numberOfIds) {
249
+ const canAdd =
250
+ !this.props.disableAdd &&
251
+ (!this.props.arity ||
252
+ this.props.arity.endsWith('n') ||
253
+ (this.props.arity === '0..1' && numberOfIds === 0));
254
+
255
+ if (canAdd) {
256
+ return (
257
+ <Button
258
+ glyph="solid/plus"
259
+ text={this.props.addText || T('Ajouter')}
260
+ tooltip={this.props.addTooltip}
261
+ glyphPosition="right"
262
+ onClick={this.onActionAdd}
263
+ />
264
+ );
265
+ } else {
266
+ return null;
267
+ }
268
+ }
269
+
270
+ renderHeader(numberOfIds) {
271
+ const headerClass =
272
+ this.props.entityIds.size === 0
273
+ ? this.styles.classNames.headerEmpty
274
+ : this.styles.classNames.header;
275
+
276
+ const title = this.props.pluginTitle
277
+ ? this.props.pluginTitle
278
+ : this.props.title;
279
+
280
+ if (this.props.readonly) {
281
+ return (
282
+ <div className={headerClass}>
283
+ <Label text={title} grow="1" kind="title" />
284
+ </div>
285
+ );
286
+ } else {
287
+ return (
288
+ <div className={headerClass}>
289
+ <Label text={title} grow="1" kind="title" />
290
+ {this.renderHeaderSearch()}
291
+ {this.renderHeaderActionMenuButton(numberOfIds)}
292
+ {this.renderHeaderAdd(numberOfIds)}
293
+ {this.renderHeaderActionMenu(numberOfIds)}
294
+ </div>
295
+ );
296
+ }
297
+ }
298
+
299
+ renderLoading() {
300
+ return (
301
+ <Container busy={true}>
302
+ <Label text={T('chargement...')} />
303
+ </Container>
304
+ );
305
+ }
306
+
307
+ renderItem(entityId, extended, index) {
308
+ const workitemUI = uiImporter(this.props.editorWidget);
309
+ const workitemId = `${this.props.editorWidget}@${
310
+ this.context.desktopId
311
+ }@${this.props.entityIds.get(index)}`;
312
+
313
+ if (!workitemUI.plugin) {
314
+ return null;
315
+ }
316
+
317
+ const itemClass = extended
318
+ ? this.props.embedded
319
+ ? this.styles.classNames.extendedEmbeddedItem
320
+ : this.styles.classNames.extendedItem
321
+ : this.props.embedded
322
+ ? this.styles.classNames.compactedEmbeddedItem
323
+ : this.styles.classNames.compactedItem;
324
+
325
+ const key1 = this.props.readonly ? 'readonly' : 'edit';
326
+ const key2 = extended ? 'extend' : 'compact';
327
+ const mapper =
328
+ workitemUI.mappers &&
329
+ workitemUI.mappers.plugin &&
330
+ workitemUI.mappers.plugin[key1] &&
331
+ workitemUI.mappers.plugin[key1][key2];
332
+ const UI = stateMapperToProps(
333
+ workitemUI.plugin[key1][key2],
334
+ mapper,
335
+ `backend.${entityId}`
336
+ );
337
+
338
+ const type = entityId.split('@', 1)[0];
339
+
340
+ return (
341
+ <div className={itemClass}>
342
+ <StateLoader path={workitemId} FallbackComponent={this.renderLoading}>
343
+ <Workitem
344
+ id={workitemId}
345
+ entityId={entityId}
346
+ kind="form"
347
+ readonly={this.props.readonly}
348
+ dragServiceId={this.props.dragServiceId}
349
+ >
350
+ <StateLoader path={entityId}>
351
+ <UI
352
+ id={workitemId}
353
+ theme={this.context.theme}
354
+ entityId={entityId}
355
+ pluginProps={this.props.pluginProps}
356
+ embeddedLevel={this.props.embeddedLevel}
357
+ origin={this.props.origin}
358
+ contextId={this.context.contextId}
359
+ do={this.doProxy(index)}
360
+ entitySchema={this.getSchema(type)}
361
+ />
362
+ </StateLoader>
363
+ </Workitem>
364
+ </StateLoader>
365
+ </div>
366
+ );
367
+ }
368
+
369
+ renderButtons(entityId, extended, numberOfIds) {
370
+ if (extended) {
371
+ const buttonsClass = this.props.readonly
372
+ ? this.props.embedded
373
+ ? this.styles.classNames.extendedEmbeddedReadonlyButtons
374
+ : this.styles.classNames.extendedReadonlyButtons
375
+ : this.props.embedded
376
+ ? this.styles.classNames.extendedEmbeddedButtons
377
+ : this.styles.classNames.extendedButtons;
378
+
379
+ const canDelete =
380
+ !this.props.readonly &&
381
+ !this.props.disableDelete &&
382
+ (!this.props.arity ||
383
+ this.props.arity.startsWith('0') ||
384
+ numberOfIds > 1);
385
+
386
+ const kind = this.props.readonly ? 'plugin-light' : 'plugin-dark';
387
+
388
+ let otherButtons = null;
389
+ if (this.props.buttons) {
390
+ otherButtons = this.props.buttons(entityId);
391
+ }
392
+
393
+ return (
394
+ <div className={buttonsClass}>
395
+ <Button
396
+ width="32px"
397
+ kind={kind}
398
+ glyph="solid/angle-up"
399
+ glyphSize="180%"
400
+ tooltip={T('Replier')}
401
+ active={false}
402
+ activeColor={
403
+ this.context.theme.palette.recurrenceExtendedBoxBackground
404
+ }
405
+ onClick={() => this.onSwapExtended(entityId)}
406
+ />
407
+ <Button
408
+ width="32px"
409
+ kind={kind}
410
+ glyph="solid/pencil"
411
+ tooltip={T('Editer')}
412
+ onClick={() => this.onEditEntity(entityId)}
413
+ />
414
+ {otherButtons}
415
+ {canDelete ? (
416
+ <Button
417
+ width="32px"
418
+ kind={kind}
419
+ glyph="solid/trash"
420
+ tooltip={T('Supprimer')}
421
+ onClick={() => this.onDeleteEntity(entityId)}
422
+ />
423
+ ) : null}
424
+ </div>
425
+ );
426
+ } else {
427
+ const buttonsClass = this.props.readonly
428
+ ? this.props.embedded
429
+ ? this.styles.classNames.compactedEmbeddedReadonlyButtons
430
+ : this.styles.classNames.compactedReadonlyButtons
431
+ : this.props.embedded
432
+ ? this.styles.classNames.compactedEmbeddedButtons
433
+ : this.styles.classNames.compactedButtons;
434
+
435
+ const kind =
436
+ this.props.readonly || !this.props.embedded
437
+ ? 'plugin-light'
438
+ : 'plugin-dark';
439
+
440
+ return (
441
+ <div className={buttonsClass}>
442
+ {this.props.readonly && !this.props.embedded ? (
443
+ <Button
444
+ width="32px"
445
+ kind={kind}
446
+ glyph="solid/pencil"
447
+ tooltip={T('Editer')}
448
+ onClick={() => this.onEditEntity(entityId)}
449
+ />
450
+ ) : null}
451
+ <Button
452
+ width="32px"
453
+ kind={kind}
454
+ glyph="solid/angle-down"
455
+ glyphSize="180%"
456
+ tooltip={T('Etendre')}
457
+ active={false}
458
+ activeColor={
459
+ this.context.theme.palette.recurrenceExtendedBoxBackground
460
+ }
461
+ onClick={() => this.onSwapExtended(entityId)}
462
+ />
463
+ </div>
464
+ );
465
+ }
466
+ }
467
+
468
+ renderRowContent(entityId, extended, numberOfIds, index) {
469
+ const rowClass = extended
470
+ ? this.props.embedded
471
+ ? this.styles.classNames.extendedEmbeddedRow
472
+ : this.styles.classNames.extendedRow
473
+ : numberOfIds > 1 && this.props.horizontalSeparator !== 'compact'
474
+ ? this.props.embedded
475
+ ? this.styles.classNames.compactedEmbeddedDashedRow
476
+ : this.styles.classNames.compactedDashedRow
477
+ : this.props.embedded
478
+ ? this.styles.classNames.compactedEmbeddedRow
479
+ : this.styles.classNames.compactedRow;
480
+
481
+ return (
482
+ <Container
483
+ kind="row-draggable"
484
+ busyLook={extended ? null : 'smallest'}
485
+ key={index}
486
+ ref={(n) => {
487
+ if (n) {
488
+ // Get the html node ref via instance variable of component
489
+ this._refs[entityId] = n.ref;
490
+ } else {
491
+ delete this._refs[entityId];
492
+ }
493
+ }}
494
+ >
495
+ <div className={rowClass}>
496
+ {this.renderItem(entityId, extended, index)}
497
+ {this.renderButtons(entityId, extended, numberOfIds)}
498
+ </div>
499
+ </Container>
500
+ );
501
+ }
502
+
503
+ renderRow(entityId, extended, dragEnabled, numberOfIds, index) {
504
+ if (dragEnabled) {
505
+ return (
506
+ <DragCab
507
+ key={index}
508
+ dragController={this.props.dragType || this.props.id}
509
+ dragOwnerId={entityId}
510
+ dragMode="handle"
511
+ dragHandleWidth={this.context.theme.shapes.containerMargin}
512
+ direction="vertical"
513
+ color={this.context.theme.palette.dragAndDropHover}
514
+ thickness={this.context.theme.shapes.dragAndDropTicketThickness}
515
+ overSpacing="0px"
516
+ verticalSpacing="0px"
517
+ radius="0px"
518
+ doClickAction={() => this.onSwapExtended(entityId)}
519
+ doDragEnding={this.onEntityDragged}
520
+ >
521
+ {this.renderRowContent(entityId, extended, numberOfIds, index)}
522
+ </DragCab>
523
+ );
524
+ } else {
525
+ return this.renderRowContent(entityId, extended, numberOfIds, index);
526
+ }
527
+ }
528
+
529
+ renderRows(entityIds) {
530
+ const dragEnabled =
531
+ !this.props.readonly && (entityIds.length > 1 || !!this.props.dragType);
532
+
533
+ let index = 0;
534
+
535
+ return entityIds.map((entityId) => {
536
+ const extended = entityId === this.props.extendedId;
537
+ return this.renderRow(
538
+ entityId,
539
+ extended,
540
+ dragEnabled,
541
+ entityIds.length,
542
+ index++
543
+ );
544
+ });
545
+ }
546
+
547
+ renderDefault() {
548
+ const entityIds = this.props.entityIds.valueSeq().toArray();
549
+ if (entityIds.length === 0 && this.props.readonly && this.props.embedded) {
550
+ return null;
551
+ }
552
+
553
+ let boxClass = null;
554
+ if (!this.props.entityIds || this.props.entityIds.size === 0) {
555
+ boxClass = this.props.embedded
556
+ ? this.styles.classNames.emptyembeddedBox
557
+ : this.styles.classNames.emptyBox;
558
+ } else {
559
+ boxClass = this.props.embedded
560
+ ? this.styles.classNames.embeddedBox
561
+ : this.styles.classNames.box;
562
+ }
563
+
564
+ return (
565
+ <div className={boxClass}>
566
+ {this.renderHeader(entityIds.length)}
567
+ <Container
568
+ kind="column"
569
+ dragController={this.props.dragType || this.props.id}
570
+ dragSource={this.props.id}
571
+ dragOwnerId={this.props.id}
572
+ >
573
+ {this.renderRows(entityIds)}
574
+ </Container>
575
+ </div>
576
+ );
577
+ }
578
+
579
+ render() {
580
+ if (!this.props.id || !this.props.entityIds) {
581
+ return null;
582
+ }
583
+
584
+ if (!this.props.editorWidget) {
585
+ return null;
586
+ }
587
+
588
+ return this.renderDefault();
589
+ }
590
+ }
591
+
592
+ /******************************************************************************/
593
+
594
+ const select = (root) => (state, id) => (prop) => {
595
+ if (!id) {
596
+ return null;
597
+ }
598
+ const target = state.get(`${root}.${id}`);
599
+ if (!target) {
600
+ return null;
601
+ }
602
+ return target.get(prop);
603
+ };
604
+
605
+ const withBackend = select('backend');
606
+ const withWidget = select('widgets');
607
+
608
+ export default Widget.connect((state, props) => {
609
+ const plugin = withBackend(state, props.id);
610
+ const entity = withBackend(state, plugin('forEntity'));
611
+ const widget = withWidget(state, props.id);
612
+ return {
613
+ id: props.id,
614
+ title: plugin('title'),
615
+ editorWidget: plugin('editorWidget'),
616
+ arity: plugin('arity'),
617
+ mode: plugin('mode'),
618
+ entityIds: entity(plugin('entityPath')),
619
+ namespace: `${plugin('type')}-plugin`,
620
+ extendedId: widget('extendedId'),
621
+ };
622
+ })(Plugin);