Skip to content

Commit

Permalink
feat(wizards): add function type create wizards (openscd#768)
Browse files Browse the repository at this point in the history
* feat(wizards/function): add edit wizard (openscd#762)

* feat(wizards/function): add edit wizard

* test(editors/substation/function-editor): make linter happy

* refactor(wizards/function): review comments

* feat(wizards/subfunction): add edit wizard (openscd#763)

* feat(wizards/eqfunction): add edit wizard (openscd#764)

* feat(wizards/eqfunction): add edit wizard

* refactor(wizards/eqfunction): review comments

* feat(wizards/eqsubfunction): add edit wizard (openscd#765)

* feat(wizards/eqsubfunction): add edit wizard

* refactor(wizards/eqsubfunction): review comments
  • Loading branch information
JakobVogelsang authored May 23, 2022
1 parent ce9dea1 commit 6e9c928
Show file tree
Hide file tree
Showing 26 changed files with 1,237 additions and 35 deletions.
15 changes: 15 additions & 0 deletions src/editors/substation/eq-function-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ export class EqFunctionEditor extends LitElement {
@query('mwc-menu') addMenu!: Menu;
@query('mwc-icon-button[icon="playlist_add"]') addButton!: IconButton;

private openEditWizard(): void {
const wizard = wizards['EqFunction'].edit(this.element);
if (wizard) this.dispatchEvent(newWizardEvent(wizard));
}

remove(): void {
if (this.element.parentElement)
this.dispatchEvent(
Expand Down Expand Up @@ -116,6 +121,11 @@ export class EqFunctionEditor extends LitElement {
icon="functions"
secondary
highlighted
><abbr slot="action" title="${translate('edit')}">
<mwc-icon-button
icon="edit"
@click=${() => this.openEditWizard()}
></mwc-icon-button> </abbr
><abbr slot="action" title="${translate('remove')}">
<mwc-icon-button
icon="delete"
Expand Down Expand Up @@ -144,6 +154,11 @@ export class EqFunctionEditor extends LitElement {
}

static styles = css`
abbr {
text-decoration: none;
border-bottom: none;
}
.container.lnode {
display: grid;
grid-gap: 12px;
Expand Down
15 changes: 15 additions & 0 deletions src/editors/substation/eq-sub-function-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ export class EqSubFunctionEditor extends LitElement {
@query('mwc-menu') addMenu!: Menu;
@query('mwc-icon-button[icon="playlist_add"]') addButton!: IconButton;

private openEditWizard(): void {
const wizard = wizards['EqSubFunction'].edit(this.element);
if (wizard) this.dispatchEvent(newWizardEvent(wizard));
}

remove(): void {
if (this.element.parentElement)
this.dispatchEvent(
Expand Down Expand Up @@ -111,6 +116,11 @@ export class EqSubFunctionEditor extends LitElement {

render(): TemplateResult {
return html`<action-pane label="${this.header}" icon="functions" secondary
><abbr slot="action" title="${translate('edit')}">
<mwc-icon-button
icon="edit"
@click=${() => this.openEditWizard()}
></mwc-icon-button> </abbr
><abbr slot="action" title="${translate('remove')}">
<mwc-icon-button
icon="delete"
Expand Down Expand Up @@ -139,6 +149,11 @@ export class EqSubFunctionEditor extends LitElement {
}

static styles = css`
abbr {
text-decoration: none;
border-bottom: none;
}
.container.lnode {
display: grid;
grid-gap: 12px;
Expand Down
15 changes: 15 additions & 0 deletions src/editors/substation/function-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ export class FunctionEditor extends LitElement {
@query('mwc-menu') addMenu!: Menu;
@query('mwc-icon-button[icon="playlist_add"]') addButton!: IconButton;

private openEditWizard(): void {
const wizard = wizards['Function'].edit(this.element);
if (wizard) this.dispatchEvent(newWizardEvent(wizard));
}

remove(): void {
if (this.element.parentElement)
this.dispatchEvent(
Expand Down Expand Up @@ -109,6 +114,11 @@ export class FunctionEditor extends LitElement {
icon="functions"
secondary
highlighted
><abbr slot="action" title="${translate('edit')}">
<mwc-icon-button
icon="edit"
@click=${() => this.openEditWizard()}
></mwc-icon-button> </abbr
><abbr slot="action" title="${translate('remove')}">
<mwc-icon-button
icon="delete"
Expand Down Expand Up @@ -137,6 +147,11 @@ export class FunctionEditor extends LitElement {
}

static styles = css`
abbr {
text-decoration: none;
border-bottom: none;
}
.container.lnode {
display: grid;
grid-gap: 12px;
Expand Down
15 changes: 15 additions & 0 deletions src/editors/substation/sub-function-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ export class SubFunctionEditor extends LitElement {
@query('mwc-menu') addMenu!: Menu;
@query('mwc-icon-button[icon="playlist_add"]') addButton!: IconButton;

private openEditWizard(): void {
const wizard = wizards['SubFunction'].edit(this.element);
if (wizard) this.dispatchEvent(newWizardEvent(wizard));
}

remove(): void {
if (this.element.parentElement)
this.dispatchEvent(
Expand Down Expand Up @@ -109,6 +114,11 @@ export class SubFunctionEditor extends LitElement {

render(): TemplateResult {
return html`<action-pane label="${this.header}" icon="functions" secondary
><abbr slot="action" title="${translate('edit')}">
<mwc-icon-button
icon="edit"
@click=${() => this.openEditWizard()}
></mwc-icon-button> </abbr
><abbr slot="action" title="${translate('remove')}">
<mwc-icon-button
icon="delete"
Expand Down Expand Up @@ -137,6 +147,11 @@ export class SubFunctionEditor extends LitElement {
}

static styles = css`
abbr {
text-decoration: none;
border-bottom: none;
}
.container.lnode {
display: grid;
grid-gap: 12px;
Expand Down
58 changes: 58 additions & 0 deletions src/wizards/eqfunction.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,72 @@
import { get } from 'lit-translate';

import {
cloneElement,
createElement,
getChildElementsByTagName,
getValue,
SimpleAction,
Wizard,
WizardActor,
WizardInputElement,
} from '../foundation.js';
import { contentFunctionWizard } from './function.js';

function updateEqFunctionAction(element: Element): WizardActor {
return (inputs: WizardInputElement[]): SimpleAction[] => {
const functionAttrs: Record<string, string | null> = {};
const functionKeys = ['name', 'desc', 'type'];
functionKeys.forEach(key => {
functionAttrs[key] = getValue(inputs.find(i => i.label === key)!);
});

if (
functionKeys.some(key => functionAttrs[key] !== element.getAttribute(key))
) {
const newElement = cloneElement(element, functionAttrs);
return [
{
old: { element },
new: { element: newElement },
},
];
}

return [];
};
}

export function editEqFunctionWizard(element: Element): Wizard {
const name = element.getAttribute('name');
const desc = element.getAttribute('desc');
const type = element.getAttribute('type');
const reservedNames: string[] = getChildElementsByTagName(
element.parentElement!,
'EqFunction'
)
.filter(sibling => sibling !== element)
.map(sibling => sibling.getAttribute('name')!);

return [
{
title: get('wizard.title.edit', { tagName: 'EqFunction' }),
primary: {
icon: 'save',
label: get('save'),
action: updateEqFunctionAction(element),
},
content: [
...contentFunctionWizard({
name,
desc,
type,
reservedNames,
}),
],
},
];
}

function createEqFunctionAction(parent: Element): WizardActor {
return (inputs: WizardInputElement[]) => {
const eqFunctionAttrs: Record<string, string | null> = {};
Expand Down
58 changes: 58 additions & 0 deletions src/wizards/eqsubfunction.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,72 @@
import { get } from 'lit-translate';

import {
cloneElement,
createElement,
getChildElementsByTagName,
getValue,
SimpleAction,
Wizard,
WizardActor,
WizardInputElement,
} from '../foundation.js';
import { contentFunctionWizard } from './function.js';

function updateEqSubFunctionAction(element: Element): WizardActor {
return (inputs: WizardInputElement[]): SimpleAction[] => {
const functionAttrs: Record<string, string | null> = {};
const functionKeys = ['name', 'desc', 'type'];
functionKeys.forEach(key => {
functionAttrs[key] = getValue(inputs.find(i => i.label === key)!);
});

if (
functionKeys.some(key => functionAttrs[key] !== element.getAttribute(key))
) {
const newElement = cloneElement(element, functionAttrs);
return [
{
old: { element },
new: { element: newElement },
},
];
}

return [];
};
}

export function editEqSubFunctionWizard(element: Element): Wizard {
const name = element.getAttribute('name');
const desc = element.getAttribute('desc');
const type = element.getAttribute('type');
const reservedNames: string[] = getChildElementsByTagName(
element.parentElement!,
'EqSubFunction'
)
.filter(sibling => sibling !== element)
.map(sibling => sibling.getAttribute('name')!);

return [
{
title: get('wizard.title.edit', { tagName: 'EqSubFunction' }),
primary: {
icon: 'save',
label: get('save'),
action: updateEqSubFunctionAction(element),
},
content: [
...contentFunctionWizard({
name,
desc,
type,
reservedNames,
}),
],
},
];
}

function createEqSubFunctionAction(parent: Element): WizardActor {
return (inputs: WizardInputElement[]) => {
const eqSubFunctionAttrs: Record<string, string | null> = {};
Expand Down
58 changes: 58 additions & 0 deletions src/wizards/function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ import { html, TemplateResult } from 'lit-element';
import { get, translate } from 'lit-translate';

import {
cloneElement,
createElement,
getChildElementsByTagName,
getValue,
SimpleAction,
Wizard,
WizardActor,
WizardInputElement,
Expand Down Expand Up @@ -44,6 +47,61 @@ export function contentFunctionWizard(
];
}

function updateFunctionAction(element: Element): WizardActor {
return (inputs: WizardInputElement[]): SimpleAction[] => {
const functionAttrs: Record<string, string | null> = {};
const functionKeys = ['name', 'desc', 'type'];
functionKeys.forEach(key => {
functionAttrs[key] = getValue(inputs.find(i => i.label === key)!);
});

if (
functionKeys.some(key => functionAttrs[key] !== element.getAttribute(key))
) {
const newElement = cloneElement(element, functionAttrs);
return [
{
old: { element },
new: { element: newElement },
},
];
}

return [];
};
}

export function editFunctionWizard(element: Element): Wizard {
const name = element.getAttribute('name');
const desc = element.getAttribute('desc');
const type = element.getAttribute('type');
const reservedNames: string[] = getChildElementsByTagName(
element.parentElement!,
'Function'
)
.filter(sibling => sibling !== element)
.map(sibling => sibling.getAttribute('name')!);

return [
{
title: get('wizard.title.edit', { tagName: 'Function' }),
primary: {
icon: 'save',
label: get('save'),
action: updateFunctionAction(element),
},
content: [
...contentFunctionWizard({
name,
desc,
type,
reservedNames,
}),
],
},
];
}

function createFunctionAction(parent: Element): WizardActor {
return (inputs: WizardInputElement[]) => {
const functionAttrs: Record<string, string | null> = {};
Expand Down
Loading

0 comments on commit 6e9c928

Please sign in to comment.