Skip to content

Commit c28ae9c

Browse files
authored
Merge pull request #451 from fschmenger/multiple_module_instances
Support multiple instances of a module.
2 parents 5c471e4 + 6b3d293 commit c28ae9c

File tree

18 files changed

+180
-82
lines changed

18 files changed

+180
-82
lines changed

app-starter/WguAppTemplate.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,8 @@ export default {
186186
const moduleOpts = appConfig.modules[key];
187187
if (moduleOpts.win === target) {
188188
moduleWins.push({
189-
type: key + '-win',
189+
type: (moduleOpts.moduleType ?? key) + '-win',
190+
moduleName: key,
190191
...moduleOpts
191192
});
192193
}

app-starter/components/AppHeader.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,9 @@ export default {
9999
const moduleOpts = appConfig.modules[key];
100100
if (moduleOpts.target === target) {
101101
buttons.push({
102-
type: moduleOpts.win ? 'wgu-toggle-btn' : key + '-btn',
102+
type: moduleOpts.win
103+
? 'wgu-toggle-btn'
104+
: (moduleOpts.moduleType ?? key) + '-btn',
103105
moduleName: key,
104106
...moduleOpts
105107
});

app-starter/components/SampleModule.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
-->
88
<wgu-module-card
99
v-bind="$attrs"
10-
moduleName="sample-module"
1110
class="sample-module"
1211
:icon="icon"
1312
>

docs/module-configuration.md

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,68 @@ JSON configuration objects for Wegue modules.
44

55
## General
66

7-
The `modules` object contains sub-objects, whereas the key is the identifier for the module and the value is the dedicated module configuration. For example:
7+
The `modules` object contains sub-objects, where the key is the identifier for the module instance and the value is the dedicated module configuration. For example:
88

99
```json
10-
"wgu-layerlist": {
11-
"target": "menu",
12-
"win": "floating",
13-
"draggable": false
14-
}
10+
"wgu-layerlist": {
11+
"target": "menu",
12+
"win": "floating",
13+
"draggable": false
14+
}
1515
```
1616

17+
### Module identifier and module type
18+
In general, the identifier specifies the type of module to be added.
19+
In the example above, Wegue will look for a Vue component matching the module type `wgu-layerlist` and automatically append the `-win` suffix when resolving the component name. Internally, this results in the component `wgu-layerlist-win`, which must be registered in the application, for example:
20+
21+
```js
22+
import LayerListWin from '@/components/layerlist/LayerListWin.vue';
23+
24+
components: {
25+
'wgu-layerlist-win': LayerListWin
26+
}
27+
```
28+
This approach allows simple module definitions where the identifier directly maps to a single module instance.
29+
30+
### Multiple instances of the same module type
31+
To allow multiple instances of the same module type, the module identifier can be chosen arbitrarily. In this case, the actual module type must be specified explicitly using the `moduleType` property.
32+
Example:
33+
```json
34+
"wgu-layerlist1": {
35+
"moduleType": "wgu-layerlist",
36+
"target": "menu",
37+
"win": "floating",
38+
"draggable": false
39+
},
40+
"wgu-layerlist2": {
41+
"moduleType": "wgu-layerlist",
42+
"target": "menu",
43+
"win": "floating",
44+
"draggable": false
45+
}
46+
```
47+
In this configuration:
48+
* `wgu-layerlist1` and `wgu-layerlist2` are instance identifiers.
49+
* Both instances reference the same module type via `"moduleType": "wgu-layerlist"`
50+
* Wegue will create two independent instances of the `wgu-layerlist` module.
51+
* Each instance has its own configuration, state, and window (if applicable)
52+
If `moduleType` is omitted, Wegue assumes that the module identifier itself represents the module type.
53+
54+
55+
#### Note / Limitation:
56+
While Wegue supports configuring multiple instances of the same module type, stock Wegue components are not guaranteed to be designed for multi-instantiation. Some built-in modules may rely on shared state, global identifiers, or singleton assumptions and may behave incorrectly or unpredictably when instantiated multiple times.
57+
58+
Multi-instantiation is therefore primarily intended for custom modules or stock modules that are explicitly designed and validated for this usage. When using multiple instances of a stock module, this behavior should be considered experimental unless otherwise documented.
59+
60+
### Common module properties
61+
1762
The following properties can be applied to all module types:
1863

1964
| Property | Meaning | Example |
2065
|--------------------|:---------:|---------|
2166
| **target** | Where should the button to enable/disable the module be rendered. Valid options are `menu` or `toolbar` | `"target": "menu"` |
2267
| **win** | Value to mark if the module has a window as sub component and where to show the module UI elements. Valid options are `floating` and `sidebar`. If the value is omitted, then the module is not associated with a window. | `"win": "floating"` |
68+
| moduleType | Optional module type. Required only if different from the module identifier (e.g. for multi-instantiation). | `"moduleType": "wgu-layerlist"`
2369
| icon | Provide a customized icon for the module. | `"icon": "md:info"` |
2470
| minimizable | Indicates whether the module window can be minimized. Only applies if a module window is present as indicated by the `win` parameter. | `"minimizable": true` |
2571
| closable | Indicates whether the module window can be closed by a "X" icon in the window's header bar. Only applies if a module window is present as indicated by the `win` parameter. | `"closable": false` |

src/components/attributeTable/AttributeTableWin.vue

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<template>
22
<wgu-module-card v-bind="$attrs"
3-
:moduleName="moduleName"
43
class="wgu-attributetable-win"
54
:icon="icon"
65
>
@@ -56,7 +55,6 @@ export default {
5655
},
5756
data () {
5857
return {
59-
moduleName: 'wgu-attributetable',
6058
selLayerLid: null
6159
}
6260
},

src/components/helpwin/HelpWin.vue

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<template>
22
<wgu-module-card v-bind="$attrs"
3-
:moduleName="moduleName"
43
class="wgu-helpwin"
54
:icon="icon"
65
:width="width">
@@ -36,11 +35,6 @@ export default {
3635
props: {
3736
icon: { type: String, required: false, default: 'md:help' },
3837
width: { type: Number, required: false, default: 300 }
39-
},
40-
data () {
41-
return {
42-
moduleName: 'wgu-helpwin'
43-
}
4438
}
4539
};
4640
</script>

src/components/infoclick/InfoClickWin.vue

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<template>
22
<wgu-module-card v-bind="$attrs"
3-
:moduleName="moduleName"
43
class="wgu-infoclick-win"
54
:icon="icon"
65
v-on:visibility-change="show">
@@ -105,7 +104,6 @@ export default {
105104
},
106105
data: function () {
107106
return {
108-
moduleName: 'wgu-infoclick',
109107
attributeData: null,
110108
coordsData: null,
111109
featureIdx: 0,

src/components/layerlist/LayerListWin.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<template>
22
<wgu-module-card v-bind="$attrs"
3-
moduleName="wgu-layerlist"
43
class="wgu-layerlist"
54
:icon="icon"
65
>

src/components/maprecorder/MapRecorderWin.vue

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<template>
22
<wgu-module-card v-bind="$attrs"
3-
:moduleName="moduleName"
43
class="wgu-maprecorder-win"
54
:icon="icon"
65
width=350>
@@ -156,7 +155,6 @@ export default {
156155
const mimeTypes = this.getSupportedMimeTypes();
157156
158157
return {
159-
moduleName: 'wgu-maprecorder',
160158
/**
161159
* Custom canvas element for drawing the OpenLayers map.
162160
*/

src/components/measuretool/MeasureWin.vue

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<template>
22
<wgu-module-card v-bind="$attrs"
3-
:moduleName="moduleName"
43
class="wgu-measurewin"
54
:icon="icon"
65
v-on:visibility-change="show">
@@ -48,7 +47,6 @@ export default {
4847
},
4948
data () {
5049
return {
51-
moduleName: 'wgu-measuretool',
5250
measureGeom: null,
5351
measureType: 'distance'
5452
}

0 commit comments

Comments
 (0)