From 58a57df33daa4a332a6b0cc079227c65b5407433 Mon Sep 17 00:00:00 2001 From: bat Date: Sun, 30 Apr 2023 09:07:31 +0000 Subject: [PATCH] save connections and apply inverse connections --- connection-edit.js | 5 ----- connections.js | 52 ++++++++++++++++++++++++++++++++++++++++++++-- page-settings.js | 6 ++++-- 3 files changed, 54 insertions(+), 9 deletions(-) diff --git a/connection-edit.js b/connection-edit.js index 2a38b4a..2fa5b05 100644 --- a/connection-edit.js +++ b/connection-edit.js @@ -72,10 +72,6 @@ export class ConnectionEdit extends HTMLElement { this.shadowRoot.append(style) } - display() { - - } - get data() { return { networkAccess: this.netSelect.value, @@ -85,7 +81,6 @@ export class ConnectionEdit extends HTMLElement { set data(value) { this.netText.innerText = JSON.stringify(value) this.netSelect.value = value.networkAccess ?? 'local' - this.display() } set error(error) { diff --git a/connections.js b/connections.js index 7b24a20..f1f0e98 100644 --- a/connections.js +++ b/connections.js @@ -1,12 +1,24 @@ export class Connections extends HTMLElement { + icons = { + del: ` + + + + ` + } + textEn = { add: 'Add connection', cancel: 'Cancel', + read: 'read', + readWrite: 'read and write', } textEs = { add: 'Añadir conexión', cancel: 'Cancelar', + read: 'leer', + readWrite: 'leer y escribir', } constructor() { @@ -38,6 +50,27 @@ export class Connections extends HTMLElement { m-dialog::part(footer) { padding-top: 15px; } + button.icon { + border: none; + background: inherit; + color: #555; + } + button.icon svg { + width: 12px; + height: 12px; + } + .connection { + display: flex; + flex-direction: row; + gap: 8px; + align-items: center; + } + .access { + font-size: 80%; + background: #ccc; + border-radius: 3px; + padding: 5px; + } ` this.shadowRoot.append(style) } @@ -81,10 +114,25 @@ export class Connections extends HTMLElement { } display() { - const entries = Object.entries(this.data) + const entries = Object.entries(this.data).filter( + ([k, v]) => v !== undefined + ) const content = entries.map(([path, access]) => { const el = document.createElement('div') - el.innerText = `${path}: ${access}` + el.classList.add('connection') + const pathEl = document.createElement('span') + pathEl.innerText = path + el.append(pathEl) + const accessEl = document.createElement('span') + accessEl.innerText = this.text[access] + accessEl.classList.add('access') + const delBtn = document.createElement('button') + delBtn.classList.add('delete', 'icon') + delBtn.innerHTML = this.icons.del + delBtn.addEventListener('click', () => { + this.data = {...this.data, [path]: undefined} + }) + el.append(accessEl, delBtn) return el }) this.content.replaceChildren(...content) diff --git a/page-settings.js b/page-settings.js index d494920..50c074c 100644 --- a/page-settings.js +++ b/page-settings.js @@ -75,8 +75,10 @@ export class PageSettings extends HTMLElement { get data() { return { ...this.network.data, - outbound: this.outbound.data, - inbound: this.inbound.data, + connections: { + outbound: this.outbound.data, + inbound: this.inbound.data, + }, } }