-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathied-container.ts
112 lines (99 loc) · 3.18 KB
/
ied-container.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import {
css,
customElement,
html,
property,
TemplateResult,
} from 'lit-element';
import { nothing } from 'lit-html';
import { get } from 'lit-translate';
import '@openscd/open-scd/src/action-pane.js';
import './access-point-container.js';
import { wizards } from '../../wizards/wizard-library.js';
import { Container } from './foundation.js';
import {
getDescriptionAttribute,
getNameAttribute,
newWizardEvent,
} from '@openscd/open-scd/src/foundation.js';
import { newActionEvent } from '@openscd/core/foundation/deprecated/editor.js';
import { removeIEDWizard } from '../../wizards/ied.js';
import { editServicesWizard } from '../../wizards/services.js';
/** [[`IED`]] plugin subeditor for editing `IED` element. */
@customElement('ied-container')
export class IedContainer extends Container {
@property()
selectedLNClasses: string[] = [];
private openEditWizard(): void {
const wizard = wizards['IED'].edit(this.element);
if (wizard) this.dispatchEvent(newWizardEvent(wizard));
}
private renderServicesIcon(): TemplateResult {
const services: Element | null = this.element.querySelector('Services');
if (!services) {
return html``;
}
return html` <abbr slot="action" title="${get('iededitor.settings')}">
<mwc-icon-button
icon="settings"
@click=${() => this.openSettingsWizard(services)}
></mwc-icon-button>
</abbr>`;
}
private openSettingsWizard(services: Element): void {
const wizard = editServicesWizard(services);
if (wizard) this.dispatchEvent(newWizardEvent(wizard));
}
private removeIED(): void {
const wizard = removeIEDWizard(this.element);
if (wizard) {
this.dispatchEvent(newWizardEvent(() => wizard));
} else {
// If no Wizard is needed, just remove the element.
this.dispatchEvent(
newActionEvent({
old: { parent: this.element.parentElement!, element: this.element },
})
);
}
}
private header(): TemplateResult {
const name = getNameAttribute(this.element);
const desc = getDescriptionAttribute(this.element);
return html`${name}${desc ? html` — ${desc}` : nothing}`;
}
render(): TemplateResult {
return html` <action-pane .label="${this.header()}">
<mwc-icon slot="icon">developer_board</mwc-icon>
<abbr slot="action" title="${get('remove')}">
<mwc-icon-button
icon="delete"
@click=${() => this.removeIED()}
></mwc-icon-button>
</abbr>
<abbr slot="action" title="${get('edit')}">
<mwc-icon-button
icon="edit"
@click=${() => this.openEditWizard()}
></mwc-icon-button>
</abbr>
${this.renderServicesIcon()}
${Array.from(this.element.querySelectorAll(':scope > AccessPoint')).map(
ap => html`<access-point-container
.editCount=${this.editCount}
.doc=${this.doc}
.element=${ap}
.nsdoc=${this.nsdoc}
.selectedLNClasses=${this.selectedLNClasses}
.ancestors=${[this.element]}
></access-point-container>`
)}
</action-pane>`;
}
static styles = css`
abbr {
text-decoration: none;
border-bottom: none;
}
`;
}