|
| 1 | +import { |
| 2 | + css, |
| 3 | + customElement, |
| 4 | + html, |
| 5 | + LitElement, |
| 6 | + property, |
| 7 | + state, |
| 8 | + TemplateResult, |
| 9 | +} from 'lit-element'; |
| 10 | + |
| 11 | +import '../../action-pane.js'; |
| 12 | +import '../../action-icon.js'; |
| 13 | + |
| 14 | +import { |
| 15 | + selectors, |
| 16 | + SIEMENS_SITIPE_IED_REF, |
| 17 | + SIEMENS_SITIPE_BAY_TEMPLATE, |
| 18 | +} from './foundation.js'; |
| 19 | + |
| 20 | +/** [[`Sitipe`]] plugin subeditor for editing `Sitipe` configuration. */ |
| 21 | +@customElement('sitipe-substation') |
| 22 | +export class SitipeSubstation extends LitElement { |
| 23 | + /** The document being edited as provided to editor by [[`Sitipe`]]. */ |
| 24 | + @property({ attribute: false }) |
| 25 | + doc!: XMLDocument; |
| 26 | + /** The edited `Element`, a common property of all Sitipe subeditors. */ |
| 27 | + @property({ attribute: false }) |
| 28 | + element!: Element; |
| 29 | + |
| 30 | + @state() |
| 31 | + get substationHeader(): string { |
| 32 | + const name = this.element.getAttribute('name') ?? ''; |
| 33 | + const desc = this.element.getAttribute('desc'); |
| 34 | + |
| 35 | + return `${name} ${desc ? `- ${desc}` : ''}`; |
| 36 | + } |
| 37 | + |
| 38 | + @state() |
| 39 | + get voltage(): string | null { |
| 40 | + const V = this.element.querySelector(selectors.VoltageLevel + ' > Voltage'); |
| 41 | + if (V === null) return null; |
| 42 | + const v = V.textContent ?? ''; |
| 43 | + const m = V.getAttribute('multiplier'); |
| 44 | + const u = m === null ? 'V' : ' ' + m + 'V'; |
| 45 | + return v ? v + u : null; |
| 46 | + } |
| 47 | + |
| 48 | + @state() |
| 49 | + voltageLevelHeader(voltageLevel: Element): string { |
| 50 | + const name = voltageLevel.getAttribute('name') ?? ''; |
| 51 | + const desc = voltageLevel.getAttribute('desc'); |
| 52 | + |
| 53 | + return `${name} ${desc ? `- ${desc}` : ''} |
| 54 | + ${this.voltage === null ? '' : `(${this.voltage})`}`; |
| 55 | + } |
| 56 | + |
| 57 | + @state() |
| 58 | + bayHeader(bay: Element): string { |
| 59 | + const name = bay.getAttribute('name') ?? ''; |
| 60 | + const desc = bay.getAttribute('desc'); |
| 61 | + |
| 62 | + return `${name} ${desc ? `(${desc})` : ''}`; |
| 63 | + } |
| 64 | + |
| 65 | + private renderIEDs(bay: Element): TemplateResult { |
| 66 | + const template: string = |
| 67 | + bay.querySelector(`Private[type="${SIEMENS_SITIPE_BAY_TEMPLATE}"]`) |
| 68 | + ?.textContent ?? ''; |
| 69 | + |
| 70 | + return html` |
| 71 | + <div> |
| 72 | + ${Array.from( |
| 73 | + bay.querySelectorAll( |
| 74 | + `Private[type="${SIEMENS_SITIPE_IED_REF}"]` ?? [] |
| 75 | + ) |
| 76 | + ).map( |
| 77 | + iedTemplate => |
| 78 | + html`<action-icon |
| 79 | + .label=${iedTemplate.textContent |
| 80 | + ? `${iedTemplate.textContent} (${template})` |
| 81 | + : ''} |
| 82 | + icon="developer_board" |
| 83 | + ></action-icon>` |
| 84 | + )} |
| 85 | + </div> |
| 86 | + `; |
| 87 | + } |
| 88 | + |
| 89 | + private renderBay(bay: Element): TemplateResult { |
| 90 | + return html`<action-pane label="${this.bayHeader(bay)}" |
| 91 | + >${this.renderIEDs(bay)}</action-pane |
| 92 | + >`; |
| 93 | + } |
| 94 | + |
| 95 | + private renderVoltageLevel(voltageLevel: Element): TemplateResult { |
| 96 | + return html`<action-pane label="${this.voltageLevelHeader(voltageLevel)}"> |
| 97 | + <div class="bayContainer"> |
| 98 | + ${Array.from(voltageLevel.querySelectorAll(selectors.Bay) ?? []).map( |
| 99 | + this.renderBay.bind(this) |
| 100 | + )} |
| 101 | + </div> |
| 102 | + </action-pane>`; |
| 103 | + } |
| 104 | + |
| 105 | + render(): TemplateResult { |
| 106 | + return html`<action-pane label="${this.substationHeader}"> |
| 107 | + ${Array.from( |
| 108 | + this.element.querySelectorAll(selectors.VoltageLevel) ?? [] |
| 109 | + ).map(this.renderVoltageLevel.bind(this))} |
| 110 | + </action-pane>`; |
| 111 | + } |
| 112 | + |
| 113 | + static styles = css` |
| 114 | + .bayContainer { |
| 115 | + display: grid; |
| 116 | + grid-gap: 12px; |
| 117 | + box-sizing: border-box; |
| 118 | + grid-template-columns: repeat(auto-fit, minmax(316px, auto)); |
| 119 | + } |
| 120 | +
|
| 121 | + @media (max-width: 387px) { |
| 122 | + .bayContainer { |
| 123 | + grid-template-columns: repeat(auto-fit, minmax(196px, auto)); |
| 124 | + } |
| 125 | + } |
| 126 | + `; |
| 127 | +} |
0 commit comments