@vcmap/module-selector 2.0.1 → 2.0.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.
@@ -16,7 +16,7 @@
16
16
  <v-col>
17
17
  <VcsTextField
18
18
  id="moduleselector-window-title"
19
- :placeholder="$t('moduleSelector.title')"
19
+ :placeholder="$st('moduleSelector.title')"
20
20
  v-model="localConfig.windowTitle"
21
21
  />
22
22
  </v-col>
@@ -163,7 +163,7 @@
163
163
  heading="moduleSelector.configEditor.heading"
164
164
  :start-open="true"
165
165
  :header-actions="headerActions"
166
- ><!--V-if currentItem group > cards || wenn url oder empty listItems-->
166
+ >
167
167
  <VcsList
168
168
  v-if="currentGroup === undefined"
169
169
  :items="listItemArray"
@@ -177,17 +177,27 @@
177
177
  @item-moved="move"
178
178
  />
179
179
  <v-dialog
180
- v-if="editingItem"
181
- :model-value="true"
180
+ v-model="editingItemDialogVisible"
182
181
  width="400"
183
182
  :persistent="true"
184
183
  >
185
184
  <ModuleEditor
186
185
  :model-value="editingItem"
187
- @close="editingItem = undefined"
186
+ @close="editingItemDialogVisible = false"
188
187
  @submit="updateItem()"
189
188
  />
190
189
  </v-dialog>
190
+ <v-dialog
191
+ v-model="selectCloudItemDialogVisible"
192
+ width="1000"
193
+ :persistent="true"
194
+ >
195
+ <VcsModuleTable
196
+ :model-value="selectCloudItem"
197
+ @close="selectCloudItemDialogVisible = false"
198
+ @submit="updateCloudItem()"
199
+ />
200
+ </v-dialog>
191
201
  </VcsFormSection>
192
202
  </AbstractConfigEditor>
193
203
  </template>
@@ -226,6 +236,7 @@
226
236
  import { Module, ModuleSelectorConfig, ModuleType } from '../index';
227
237
  import getDefaultOptions from '../defaultOptions.js';
228
238
  import WindowPositionSettings from './WindowPositionSettings.vue';
239
+ import CloudModuleSelector from './CloudModuleSelector.vue';
229
240
 
230
241
  interface VcsListItemWithLabel extends VcsListItem {
231
242
  id: string;
@@ -236,6 +247,7 @@
236
247
  cards?: VcsListItemWithLabel[];
237
248
  }
238
249
 
250
+ export const windowIdConfigEditor = 'configEditor_window_id';
239
251
  export default defineComponent({
240
252
  name: 'ModuleSelectorConfigEditor',
241
253
  components: {
@@ -253,6 +265,7 @@
253
265
  VBreadcrumbs,
254
266
  VBreadcrumbsItem,
255
267
  WindowPositionSettings,
268
+ VcsModuleTable: CloudModuleSelector,
256
269
  },
257
270
  props: {
258
271
  getConfig: {
@@ -271,13 +284,27 @@
271
284
  const listItemArray: Ref<VcsListItemWithLabel[]> = ref([]);
272
285
  const currentGroup: Ref<VcsListItemWithLabel | undefined> =
273
286
  ref(undefined);
274
- const editingItem: Ref<
275
- | { id: string; title: string; icon: string; moduleUrl: string }
276
- | undefined
277
- > = ref(undefined);
287
+ const editingItem: Ref<{
288
+ id: string;
289
+ title: string;
290
+ icon: string;
291
+ moduleUrl: string;
292
+ }> = ref({ id: '', title: '', icon: '', moduleUrl: '' });
293
+ const selectCloudItem: Ref<{
294
+ id: string;
295
+ title: string;
296
+ icon: string;
297
+ moduleUrl: string;
298
+ }> = ref({ id: '', title: '', icon: '', moduleUrl: '' });
299
+ const selectCloudItemDialogVisible: Ref<boolean> = ref(false);
300
+ const editingItemDialogVisible: Ref<boolean> = ref(false);
301
+ const groupItemDialogVisible: Ref<boolean> = ref(false);
278
302
  const listItems: Ref<VcsListItemWithLabel[] | undefined> = ref(undefined);
279
303
 
280
- localConfig.value = { ...getDefaultOptions(), ...props.getConfig() };
304
+ localConfig.value = {
305
+ ...getDefaultOptions(),
306
+ ...props.getConfig(),
307
+ } as ModuleSelectorConfig;
281
308
 
282
309
  const basisModule = ref();
283
310
 
@@ -299,75 +326,12 @@
299
326
  });
300
327
  const headerActions = reactive<VcsAction[]>([]);
301
328
 
302
- function removeIdAndActions(
303
- item: VcsListItemWithLabel,
304
- ): Module<ModuleType> {
305
- if (item.type === 'url') {
306
- return {
307
- title: item.title,
308
- type: item.type,
309
- icon: item.icon,
310
- moduleUrl: item.moduleUrl || '',
311
- } as Module<'url'>;
312
- } else {
313
- const updatedCards =
314
- item.cards?.map((card) => {
315
- return {
316
- title: card.title,
317
- icon: card.icon,
318
- moduleUrl: card.moduleUrl,
319
- type: card.type,
320
- };
321
- }) || [];
322
- return {
323
- title: item.title,
324
- type: item.type,
325
- icon: item.icon,
326
- ...(updatedCards.length ? { cards: updatedCards } : {}),
327
- } as Module<'group'>;
328
- }
329
- }
330
-
331
- const headerGroupAction = {
332
- name: 'moduleSelector.configEditor.addGroup',
333
- callback(): void {
334
- const newGroup = {
335
- type: 'group',
336
- name: '',
337
- id: '',
338
- title: 'title',
339
- icon: 'icon',
340
- cards: [],
341
- };
342
-
343
- listItemArray.value?.push(newGroup);
344
- currentGroup.value = newGroup;
345
-
346
- const newIndex = listItemArray.value.indexOf(newGroup);
347
-
348
- newGroup.id = `${newGroup.title}-${newIndex}`;
349
-
350
- headerActions.splice(1, 1);
351
- if (headerActions.length > 0) {
352
- headerActions[0].icon = '$vcsPlus';
353
- headerActions[0].title =
354
- 'moduleSelector.configEditor.TooltipAddModule';
355
- }
356
- },
357
- };
358
-
359
- function removeIdAndActionsFromArray(
360
- items: VcsListItemWithLabel[],
361
- ): Module<ModuleType>[] {
362
- return items.map(removeIdAndActions);
363
- }
364
-
365
329
  function createListItem(
366
330
  moduleInfo: Module<ModuleType>,
367
331
  index: number,
368
332
  ): VcsListItemWithLabel {
369
333
  const listItemObject: VcsListItemWithLabel = {
370
- id: `${moduleInfo.title}-${index}`,
334
+ id: `${moduleInfo.title || 'undefined'}-${index}`,
371
335
  name: moduleInfo.title,
372
336
  title: moduleInfo.title,
373
337
  icon: moduleInfo.icon,
@@ -411,6 +375,7 @@
411
375
  };
412
376
  }
413
377
  }
378
+ editingItemDialogVisible.value = true;
414
379
  },
415
380
  });
416
381
  }
@@ -426,10 +391,10 @@
426
391
  );
427
392
  if (item) {
428
393
  currentGroup.value = item;
429
- headerActions.splice(1, 1);
430
- if (headerActions.length > 0) {
431
- headerActions[0].icon = '$vcsPlus';
432
- headerActions[0].title =
394
+ headerActions.splice(2, 1);
395
+ if (headerActions.length > 1) {
396
+ headerActions[1].icon = '$vcsPlus';
397
+ headerActions[1].title =
433
398
  'moduleSelector.configEditor.TooltipAddModule';
434
399
  }
435
400
  }
@@ -459,6 +424,80 @@
459
424
  return listItemObject;
460
425
  }
461
426
 
427
+ headerActions.push({
428
+ name: 'moduleSelector.configEditor.addFromCloud',
429
+ icon: '$vcsImport',
430
+ callback(): void {
431
+ selectCloudItem.value = {
432
+ id: '',
433
+ title: '',
434
+ icon: '',
435
+ moduleUrl: '',
436
+ };
437
+ selectCloudItemDialogVisible.value = true;
438
+ },
439
+ });
440
+
441
+ function removeIdAndActions(
442
+ item: VcsListItemWithLabel,
443
+ ): Module<ModuleType> {
444
+ if (item.type === 'url') {
445
+ const { actions, id, name, ...configItem } = item;
446
+ return {
447
+ ...configItem,
448
+ moduleUrl: item.moduleUrl || '',
449
+ } as Module<'url'>;
450
+ } else {
451
+ const updatedCards =
452
+ item.cards?.map((card) => {
453
+ const { actions, id, name, ...configItem } = card;
454
+ return {
455
+ ...configItem,
456
+ } as Module<'url'>;
457
+ }) || [];
458
+ const { actions, id, name, ...configItem } = item;
459
+ return {
460
+ ...configItem,
461
+ ...(updatedCards.length ? { cards: updatedCards } : {}),
462
+ } as Module<'group'>;
463
+ }
464
+ }
465
+
466
+ const headerGroupAction = {
467
+ name: 'moduleSelector.configEditor.addGroup',
468
+ callback(): void {
469
+ const newGroup = {
470
+ type: 'group',
471
+ title: '',
472
+ icon: '',
473
+ cards: [],
474
+ };
475
+
476
+ groupItemDialogVisible.value = true;
477
+ const indexItem = listItemArray.value?.push(
478
+ createListItem(
479
+ newGroup as Module<'group'>,
480
+ listItemArray.value.length,
481
+ ),
482
+ );
483
+
484
+ currentGroup.value = listItemArray.value[indexItem - 1];
485
+
486
+ headerActions.splice(2, 1);
487
+ if (headerActions.length > 1) {
488
+ headerActions[1].icon = '$vcsPlus';
489
+ headerActions[1].title =
490
+ 'moduleSelector.configEditor.TooltipAddModule';
491
+ }
492
+ },
493
+ };
494
+
495
+ function removeIdAndActionsFromArray(
496
+ items: VcsListItemWithLabel[],
497
+ ): Module<ModuleType>[] {
498
+ return items.map(removeIdAndActions);
499
+ }
500
+
462
501
  if (localConfig.value?.modules) {
463
502
  listItemArray.value = localConfig.value.modules.map(createListItem);
464
503
  }
@@ -469,10 +508,11 @@
469
508
  callback(): void {
470
509
  editingItem.value = {
471
510
  id: '',
472
- title: 'title',
473
- icon: 'icon',
474
- moduleUrl: 'url',
511
+ title: '',
512
+ icon: '',
513
+ moduleUrl: '',
475
514
  };
515
+ editingItemDialogVisible.value = true;
476
516
  },
477
517
  },
478
518
  headerGroupAction,
@@ -503,35 +543,30 @@
503
543
  (i) => i.id === editingItem.value?.id,
504
544
  );
505
545
  if (item) {
506
- item.title = editingItem.value.title;
507
- item.icon = editingItem.value.icon;
508
- item.moduleUrl = editingItem.value.moduleUrl;
546
+ Object.assign(item, {
547
+ ...editingItem.value,
548
+ });
509
549
  }
510
550
  } else {
511
- listItemArray.value.push({
512
- id: `${editingItem.value.title}-${listItemArray.value.length}`,
513
- title: editingItem.value.title,
514
- name: editingItem.value.title,
515
- icon: editingItem.value.icon,
516
- moduleUrl: editingItem.value.moduleUrl,
517
- type: 'url',
518
- });
519
-
520
- const filteredItems = removeIdAndActionsFromArray(
521
- listItemArray.value,
551
+ listItemArray.value.push(
552
+ createListItem(
553
+ {
554
+ ...editingItem.value,
555
+ type: 'url',
556
+ },
557
+ listItemArray.value.length,
558
+ ),
522
559
  );
523
-
524
- listItemArray.value = filteredItems.map(createListItem);
525
560
  }
526
561
  }
527
562
  } else if (editingItem.value && editingItem.value?.id !== '') {
528
563
  const item = currentGroup.value.cards!.find(
529
- (i) => i.id === editingItem.value!.id,
564
+ (i) => i.id === editingItem.value.id,
530
565
  );
531
566
  if (item) {
532
- item.title = editingItem.value.title;
533
- item.icon = editingItem.value.icon;
534
- item.moduleUrl = editingItem.value.moduleUrl;
567
+ Object.assign(item, {
568
+ ...editingItem.value,
569
+ });
535
570
  }
536
571
 
537
572
  let groupId;
@@ -544,19 +579,61 @@
544
579
  (i) => i.id === groupId,
545
580
  );
546
581
  } else {
547
- currentGroup.value.cards!.push({
548
- id: `${editingItem.value!.title}-${currentGroup.value?.cards?.length}`,
549
- title: editingItem.value!.title,
550
- name: editingItem.value!.title,
551
- icon: editingItem.value!.icon,
552
- moduleUrl: editingItem.value!.moduleUrl,
553
- type: 'url',
554
- });
555
- const filteredItems = removeIdAndActionsFromArray(
556
- listItemArray.value,
582
+ currentGroup.value.cards!.push(
583
+ createListItem(
584
+ {
585
+ ...editingItem.value,
586
+ type: 'url',
587
+ },
588
+ currentGroup.value.cards!.length,
589
+ ),
557
590
  );
558
591
 
559
- listItemArray.value = filteredItems.map(createListItem);
592
+ let groupId;
593
+ if (currentGroup.value?.id || currentGroup.value?.id !== '') {
594
+ groupId = currentGroup.value.id;
595
+ } else {
596
+ groupId = `${currentGroup.value?.title}-${listItemArray.value.length - 1}`;
597
+ }
598
+ currentGroup.value = listItemArray.value?.find(
599
+ (item) => item.id === groupId,
600
+ );
601
+ }
602
+
603
+ editingItem.value = {
604
+ id: '',
605
+ title: '',
606
+ icon: '',
607
+ moduleUrl: '',
608
+ };
609
+ editingItemDialogVisible.value = false;
610
+ };
611
+
612
+ const updateCloudItem = (): void => {
613
+ if (currentGroup.value === undefined) {
614
+ if (selectCloudItem.value) {
615
+ listItemArray.value.push(
616
+ createListItem(
617
+ {
618
+ title: selectCloudItem.value.title,
619
+ icon: selectCloudItem.value.icon,
620
+ moduleUrl: selectCloudItem.value.moduleUrl,
621
+ type: 'url',
622
+ },
623
+ listItemArray.value.length,
624
+ ),
625
+ );
626
+ }
627
+ } else {
628
+ currentGroup.value.cards!.push(
629
+ createListItem(
630
+ {
631
+ ...selectCloudItem.value,
632
+ type: 'url',
633
+ },
634
+ currentGroup.value.cards!.length,
635
+ ),
636
+ );
560
637
 
561
638
  let groupId;
562
639
  if (currentGroup.value?.id || currentGroup.value?.id !== '') {
@@ -569,14 +646,20 @@
569
646
  );
570
647
  }
571
648
 
572
- editingItem.value = undefined;
649
+ selectCloudItem.value = {
650
+ id: '',
651
+ title: '',
652
+ icon: '',
653
+ moduleUrl: '',
654
+ };
655
+ selectCloudItemDialogVisible.value = false;
573
656
  };
574
657
 
575
658
  const returnLevel = (): void => {
576
659
  currentGroup.value = undefined;
577
- if (headerActions.length > 0) {
578
- delete headerActions[0].icon;
579
- delete headerActions[0].title;
660
+ if (headerActions.length > 1) {
661
+ delete headerActions[1].icon;
662
+ delete headerActions[1].title;
580
663
  }
581
664
  headerActions.push(headerGroupAction);
582
665
  };
@@ -603,6 +686,9 @@
603
686
  });
604
687
  return {
605
688
  editingItem,
689
+ selectCloudItem,
690
+ editingItemDialogVisible,
691
+ selectCloudItemDialogVisible,
606
692
  localConfig,
607
693
  listItemArray,
608
694
  breadcrumbItems,
@@ -610,6 +696,7 @@
610
696
  apply,
611
697
  returnLevel,
612
698
  updateItem,
699
+ updateCloudItem,
613
700
  level,
614
701
  listItems: listItems as unknown as unknown[],
615
702
  basisModule,
@@ -0,0 +1,25 @@
1
+ import { authorize, setServerUrl } from '@vcsuite/publisher-sdk';
2
+ import { getLogger } from '@vcsuite/logger';
3
+ import { name } from '../../package.json';
4
+ import { ModuleSelectorConfig } from '../index';
5
+
6
+ // eslint-disable-next-line import/prefer-default-export
7
+ export function setupPublisherSDK(options: ModuleSelectorConfig): void {
8
+ try {
9
+ if (options.serverUrl) {
10
+ const serverUrl = new URL(
11
+ options.serverUrl,
12
+ window.location.href,
13
+ ).toString();
14
+ setServerUrl(serverUrl);
15
+
16
+ const token = options.token || localStorage.getItem('Meteor.loginToken');
17
+ if (token) {
18
+ authorize(token);
19
+ getLogger(name).info('Publisher connection successful');
20
+ }
21
+ }
22
+ } catch (err) {
23
+ getLogger(name).error('Failed to connect to publisher', err);
24
+ }
25
+ }
@@ -11,4 +11,8 @@ export default (): ModuleSelectorConfig => ({
11
11
  },
12
12
  basisModule: undefined,
13
13
  modules: [],
14
+ serverUrl: '',
15
+ projectId: '',
16
+ appId: '',
17
+ token: '',
14
18
  });
package/src/index.ts CHANGED
@@ -33,6 +33,10 @@ export type ModuleSelectorConfig = {
33
33
  windowTitle?: string;
34
34
  isActiveOnStart?: boolean;
35
35
  requireModuleSelection?: boolean;
36
+ serverUrl?: string;
37
+ projectId?: string;
38
+ appId?: string;
39
+ token?: string;
36
40
  position?: WindowPositionOptions;
37
41
  basisModule?: BasisModule;
38
42
  modules?: Array<Module<ModuleType>>;
@@ -205,6 +209,22 @@ export default function plugin(
205
209
  serial.basisModule = this.config.basisModule;
206
210
  }
207
211
 
212
+ if (configInput.serverUrl != null) {
213
+ serial.serverUrl = configInput.serverUrl;
214
+ }
215
+
216
+ if (configInput.projectId != null) {
217
+ serial.projectId = configInput.projectId;
218
+ }
219
+
220
+ if (configInput.appId != null) {
221
+ serial.appId = configInput.appId;
222
+ }
223
+
224
+ if (configInput.token != null) {
225
+ serial.token = configInput.token;
226
+ }
227
+
208
228
  return serial;
209
229
  },
210
230
  i18n: {
@@ -215,6 +235,20 @@ export default function plugin(
215
235
  startButton: 'Anwendung starten',
216
236
  cardBack: 'Zurück',
217
237
  configEditor: {
238
+ moduleCloudPicker: {
239
+ searchName: 'Suche nach Name...',
240
+ continue: 'Weiter',
241
+ back: 'Zurück',
242
+ headers: {
243
+ name: 'Modul Name',
244
+ type: 'Typ',
245
+ description: 'Beschreibung',
246
+ createdAt: 'Erzeugt am',
247
+ updatedAt: 'Aktualisiert am',
248
+ createdBy: 'Erzeugt von',
249
+ updatedBy: 'Aktualisiert von',
250
+ },
251
+ },
218
252
  TooltipAddModule: 'Modul hinzufügen',
219
253
  TooltipEditModule: 'Modul bearbeiten',
220
254
  TooltipEditGroup: 'Modul-Gruppe bearbeiten',
@@ -248,6 +282,20 @@ export default function plugin(
248
282
  startButton: 'Start application',
249
283
  cardBack: 'Back',
250
284
  configEditor: {
285
+ moduleCloudPicker: {
286
+ searchName: 'Search for name...',
287
+ continue: 'Continue',
288
+ back: 'Back',
289
+ headers: {
290
+ name: 'Module name',
291
+ type: 'Type',
292
+ description: 'Description',
293
+ createdAt: 'Created at',
294
+ updatedAt: 'Updated at',
295
+ createdBy: 'Created by',
296
+ updatedBy: 'Created by',
297
+ },
298
+ },
251
299
  TooltipAddModule: 'Add module',
252
300
  TooltipEditModule: 'Edit module',
253
301
  TooltipEditGroup: 'Edit module group',