Skip to content

Commit 88ba11e

Browse files
authored
Merge pull request #379 from com-pas/fix/377-add-wizard-plugin-for-substation-designer
fix: 377 add wizard plugin for substation designer
2 parents cfe40e4 + c5570a1 commit 88ba11e

File tree

8 files changed

+97
-33
lines changed

8 files changed

+97
-33
lines changed

.gitmodules

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,7 @@
2626
path = packages/external-plugins/scl-bay-template
2727
url = https://github.com/com-pas/scl-bay-template
2828
branch = deploy
29+
[submodule "packages/external-plugins/scl-wizarding"]
30+
path = packages/external-plugins/scl-wizarding
31+
url = https://github.com/openenergytools/scl-wizarding
32+
branch = deploy

packages/compas-open-scd/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
"release:major": "standard-version --release-as major",
7171
"build:test": "npm run test && npm run build && cp .nojekyll build/",
7272
"build": "npm run doc && npm run build:only && cp .nojekyll build/",
73-
"build:only": "snowpack build && workbox generateSW workbox-config.cjs",
73+
"build:only": "npx rimraf node_modules/.cache/snowpack/build/[email protected] && snowpack build && workbox generateSW workbox-config.cjs",
7474
"__comment:start": "snowpack dev fails if the lit package is cached. I don't know why, but we have to delete it before starting",
7575
"start": "npx rimraf node_modules/.cache/snowpack/build/[email protected] && snowpack dev"
7676
},

packages/compas-open-scd/public/js/plugins.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,15 @@ export const officialPlugins = [
339339
requireDoc: true,
340340
position: 'middle',
341341
},
342+
{
343+
name: 'Wizarding',
344+
src: '/external-plugins/scl-wizarding/scl-wizarding.js',
345+
icon: 'edit',
346+
activeByDefault: true,
347+
kind: 'menu',
348+
requireDoc: true,
349+
position: 'middle',
350+
},
342351
{
343352
name: 'Show SCL History',
344353
src: '/plugins/src/menu/SclHistory.js',

packages/compas-open-scd/src/addons/CompasLayout.ts

Lines changed: 63 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ import { OscdPluginManager } from '@openscd/open-scd/src/addons/plugin-manager/p
4444
import '@openscd/open-scd/src/addons/plugin-manager/plugin-manager';
4545
import { OscdCustomPluginDialog } from '@openscd/open-scd/src/addons/plugin-manager/custom-plugin-dialog';
4646
import '@openscd/open-scd/src/addons/plugin-manager/custom-plugin-dialog';
47-
import { nothing } from 'lit';
47+
import { pluginTag } from '../plugin-tag.js';
4848

4949
// TODO: What happens with this?
5050
export function compasOpenMenuEvent(): CustomEvent<void> {
@@ -77,6 +77,7 @@ export class CompasLayout extends LitElement {
7777
@state() shouldValidate = false;
7878

7979
@query('#menu') menuUI!: Drawer;
80+
@query('#menuContent') menuContent!: List;
8081
@query('#pluginManager') pluginUI!: OscdPluginManager;
8182
@query('#pluginList') pluginList!: List;
8283
@query('#pluginAdd') pluginDownloadUI!: OscdCustomPluginDialog;
@@ -89,8 +90,8 @@ export class CompasLayout extends LitElement {
8990
@oscd-run-menu=${this.handleRunMenuByEvent}
9091
>
9192
<slot></slot>
92-
${this.renderHeader()} ${this.renderAside()} ${this.renderContent()}
93-
${this.renderLanding()} ${this.renderPlugging()}
93+
${this.renderHeader()} ${this.renderAside()} ${this.renderMenuContent()}
94+
${this.renderContent()} ${this.renderLanding()} ${this.renderPlugging()}
9495
</div>
9596
`;
9697
}
@@ -99,6 +100,11 @@ export class CompasLayout extends LitElement {
99100
return html` ${this.renderPluginUI()} ${this.renderDownloadUI()} `;
100101
}
101102

103+
private getMenuContent(src: string) {
104+
const tag = pluginTag(src);
105+
return this.menuContent.querySelector(tag);
106+
}
107+
102108
/** Renders the "Add Custom Plug-in" UI*/
103109
protected renderDownloadUI(): TemplateResult {
104110
return html`
@@ -271,8 +277,17 @@ export class CompasLayout extends LitElement {
271277
this.menuUI
272278
.querySelector('mwc-list')!
273279
.items.filter(item => item.className === 'validator')
274-
.map(item =>
275-
(<Validator>(<unknown>item.nextElementSibling)).validate()
280+
.map(item => {
281+
const src = item.dataset.src ?? '';
282+
283+
const menuContentElement = this.getMenuContent(src);
284+
285+
if (!menuContentElement) {
286+
return;
287+
}
288+
289+
return (menuContentElement as unknown as Validator).validate()
290+
}
276291
)
277292
).then();
278293
this.dispatchEvent(newPendingStateEvent(this.validated));
@@ -293,16 +308,14 @@ export class CompasLayout extends LitElement {
293308
return {
294309
icon: plugin.icon || pluginIcons['menu'],
295310
name: plugin.name,
311+
src: plugin.src,
296312
action: ae => {
297-
this.dispatchEvent(
298-
newPendingStateEvent(
299-
(<MenuPlugin>(
300-
(<unknown>(
301-
(<List>ae.target).items[ae.detail.index].nextElementSibling
302-
))
303-
)).run()
304-
)
305-
);
313+
const menuContentElement = this.getMenuContent(plugin.src);
314+
if (!menuContentElement) {
315+
return;
316+
}
317+
318+
this.dispatchEvent(newPendingStateEvent((menuContentElement as unknown as MenuPlugin).run()))
306319
},
307320
disabled: (): boolean => plugin.requireDoc! && this.doc === null,
308321
content: () => {
@@ -319,18 +332,16 @@ export class CompasLayout extends LitElement {
319332
return {
320333
icon: plugin.icon || pluginIcons['validator'],
321334
name: plugin.name,
335+
src: plugin.src,
322336
action: ae => {
323337
this.dispatchEvent(newEmptyIssuesEvent(plugin.src));
324338

325-
this.dispatchEvent(
326-
newPendingStateEvent(
327-
(<Validator>(
328-
(<unknown>(
329-
(<List>ae.target).items[ae.detail.index].nextElementSibling
330-
))
331-
)).validate()
332-
)
333-
);
339+
const menuContentElement = this.getMenuContent(plugin.src);
340+
if (!menuContentElement) {
341+
return;
342+
}
343+
344+
this.dispatchEvent(newPendingStateEvent((menuContentElement as unknown as Validator).validate()))
334345
},
335346
disabled: (): boolean => this.doc === null,
336347
content: plugin.content ?? (() => html``),
@@ -347,21 +358,30 @@ export class CompasLayout extends LitElement {
347358
const hasActionItem = me !== 'divider' && me.actionItem;
348359

349360
if (isDivider(me)) { return html`<li divider padded role="separator"></li>`; }
350-
if (hasActionItem){ return html``; }
361+
if (hasActionItem){
362+
return html``;
363+
}
364+
365+
/*
366+
if (me.kind === 'validator') {
367+
console.log('rendering validator with data')
368+
console.log(me)
369+
}
370+
*/
351371
return html`
352372
<mwc-list-item
353373
class="${me.kind}"
354374
iconid="${me.icon}"
355375
graphic="icon"
356376
data-name="${me.name}"
377+
data-src="${me.src ?? ''}"
357378
.disabled=${me.disabled?.() || !me.action}
358379
><mwc-icon slot="graphic">${me.icon}</mwc-icon>
359380
<span>${get(me.name)}</span>
360381
${me.hint
361382
? html`<span slot="secondary"><tt>${me.hint}</tt></span>`
362383
: ''}
363384
</mwc-list-item>
364-
${me.content ? me.content() : nothing}
365385
`;
366386
}
367387

@@ -406,6 +426,18 @@ export class CompasLayout extends LitElement {
406426
</mwc-top-app-bar-fixed>`;
407427
}
408428

429+
protected renderMenuContent(): TemplateResult {
430+
return html`
431+
<div id="menuContent">
432+
${
433+
this.menu
434+
.filter(p => (p as MenuItem).content)
435+
.map(p => (p as MenuItem).content())
436+
}
437+
</div>
438+
`;
439+
}
440+
409441
/**
410442
* Renders a drawer toolbar featuring the scl filename, enabled menu plugins,
411443
* settings, help, scl history and plug-ins management
@@ -505,14 +537,16 @@ export class CompasLayout extends LitElement {
505537
}
506538

507539
private handleRunMenuByEvent(e: CustomEvent<{name: string}>): void {
508-
509540
// TODO: this is a workaround, fix it
510541
this.menuUI.open = true;
511542
const menuEntry = this.menuUI.querySelector(`[data-name="${e.detail.name}"]`) as HTMLElement
512-
const menuElement = menuEntry.nextElementSibling
513-
if(!menuElement){ return; } // TODO: log error
514543

515-
(menuElement as unknown as MenuPlugin).run()
544+
const menuContentElement = this.getMenuContent(menuEntry.dataset.src ?? '');
545+
if (!menuContentElement) {
546+
return;
547+
}
548+
549+
(menuContentElement as unknown as MenuPlugin).run()
516550
}
517551

518552
/**

packages/compas-open-scd/src/menu/CompasOpen.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ export default class CompasOpenMenuPlugin extends LitElement {
2828
this.compasOpenElement.selectedType = undefined;
2929
await this.compasOpenElement.requestUpdate();
3030

31-
// TODO: Fix for dialog, the menu has to be open to see the dialog
32-
this.dispatchEvent(compasOpenMenuEvent());
33-
3431
this.dialog.show();
3532
}
3633

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
export function pluginTag(uri: string): string {
2+
let h1 = 0xdeadbeef,
3+
h2 = 0x41c6ce57;
4+
for (let i = 0, ch; i < uri.length; i++) {
5+
ch = uri.charCodeAt(i);
6+
h1 = Math.imul(h1 ^ ch, 2654435761);
7+
h2 = Math.imul(h2 ^ ch, 1597334677);
8+
}
9+
h1 =
10+
Math.imul(h1 ^ (h1 >>> 16), 2246822507) ^
11+
Math.imul(h2 ^ (h2 >>> 13), 3266489909);
12+
h2 =
13+
Math.imul(h2 ^ (h2 >>> 16), 2246822507) ^
14+
Math.imul(h1 ^ (h1 >>> 13), 3266489909);
15+
return 'oscd-plugin' +
16+
((h2 >>> 0).toString(16).padStart(8, '0') +
17+
(h1 >>> 0).toString(16).padStart(8, '0'))
18+
}
Submodule scl-wizarding added at 58d0d7d

packages/openscd/src/open-scd.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,7 @@ declare global {
493493
export interface MenuItem {
494494
icon: string;
495495
name: string;
496+
src?: string;
496497
hint?: string;
497498
actionItem?: boolean;
498499
action?: (event: CustomEvent<ActionDetail>) => void;

0 commit comments

Comments
 (0)