Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(editor/communication): move wizards to wizard library #489

Merged
merged 13 commits into from
Feb 8, 2022
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 33 additions & 25 deletions src/editors/Communication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@ import { translate, get } from 'lit-translate';

import '@material/mwc-fab';

import './communication/subnetwork-editor.js';
import {
newWizardEvent,
newActionEvent,
createElement,
isPublic,
} from '../foundation.js';
import { selectors, styles } from './communication/foundation.js';
import './communication/subnetwork-editor.js';
import { subNetworkWizard } from './communication/subnetwork-editor.js';
import { createSubNetworkWizard } from '../wizards/subnetwork.js';

/** An editor [[`plugin`]] for editing the `Communication` section. */
export default class CommunicationPlugin extends LitElement {
/** The document being edited as provided to plugins by [[`OpenSCD`]]. */
@property()
doc!: XMLDocument;

createCommunication(): void {
private createCommunication(): void {
this.dispatchEvent(
newActionEvent({
new: {
Expand All @@ -30,21 +30,15 @@ export default class CommunicationPlugin extends LitElement {
}

/** Opens a [[`WizardDialog`]] for creating a new `SubNetwork` element. */
openCreateSubNetworkWizard(): void {
if (!this.doc.querySelector(selectors.Communication))
this.createCommunication();
private openCreateSubNetworkWizard(): void {
const parent = this.doc.querySelector(':root > Communication');
if (!parent) this.createCommunication();

this.dispatchEvent(
newWizardEvent(
subNetworkWizard({
parent: this.doc.querySelector('Communication')!,
})
)
);
this.dispatchEvent(newWizardEvent(createSubNetworkWizard(parent!)));
}

render(): TemplateResult {
if (!this.doc?.querySelector(selectors.SubNetwork))
if (!this.doc?.querySelector(':root > Communication >SubNetwork'))
return html`<h1>
<span style="color: var(--base1)"
>${translate('communication.missing')}</span
Expand All @@ -55,29 +49,43 @@ export default class CommunicationPlugin extends LitElement {
@click=${() => this.openCreateSubNetworkWizard()}
></mwc-fab>
</h1>`;

return html`<mwc-fab
extended
icon="add"
label="${get('subnetwork.wizard.title.add')}"
@click=${() => this.openCreateSubNetworkWizard()}
></mwc-fab
>${Array.from(this.doc.querySelectorAll(selectors.SubNetwork) ?? []).map(
subnetwork =>
html`<subnetwork-editor .element=${subnetwork}></subnetwork-editor>`
)}`;
></mwc-fab>
<section>
${Array.from(this.doc.querySelectorAll('SubNetwork') ?? [])
.filter(isPublic)
.map(
subnetwork =>
html`<subnetwork-editor
.element=${subnetwork}
></subnetwork-editor>`
)}
</section> `;
}

static styles = css`
${styles}
:host {
width: 100vw;
}
JakobVogelsang marked this conversation as resolved.
Show resolved Hide resolved

section {
outline: none;
padding: 8px 12px 16px;
}

subnetwork-editor {
margin: 8px 12px 16px;
}

mwc-fab {
position: fixed;
bottom: 32px;
right: 32px;
}

:host {
width: 100vw;
}
`;
}
105 changes: 0 additions & 105 deletions src/editors/communication/foundation.ts

This file was deleted.

Loading