goblin-desktop 2.0.21 → 2.0.24

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