mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-08 18:06:36 +00:00
Update registry dialog (#10524)
This commit is contained in:
parent
12ef191a0f
commit
3fd0becfd4
@ -1,12 +1,12 @@
|
|||||||
import "@material/mwc-button/mwc-button";
|
import "@material/mwc-button/mwc-button";
|
||||||
import "@material/mwc-list/mwc-list-item";
|
|
||||||
import { mdiDelete } from "@mdi/js";
|
import { mdiDelete } from "@mdi/js";
|
||||||
import { PaperInputElement } from "@polymer/paper-input/paper-input";
|
|
||||||
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
|
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
|
||||||
import { customElement, property, state } from "lit/decorators";
|
import { customElement, property, state } from "lit/decorators";
|
||||||
import "../../../../src/components/ha-circular-progress";
|
|
||||||
import { createCloseHeading } from "../../../../src/components/ha-dialog";
|
import { createCloseHeading } from "../../../../src/components/ha-dialog";
|
||||||
|
import "../../../../src/components/ha-form/ha-form";
|
||||||
|
import { HaFormSchema } from "../../../../src/components/ha-form/types";
|
||||||
import "../../../../src/components/ha-icon-button";
|
import "../../../../src/components/ha-icon-button";
|
||||||
|
import "../../../../src/components/ha-settings-row";
|
||||||
import { extractApiErrorMessage } from "../../../../src/data/hassio/common";
|
import { extractApiErrorMessage } from "../../../../src/data/hassio/common";
|
||||||
import {
|
import {
|
||||||
addHassioDockerRegistry,
|
addHassioDockerRegistry,
|
||||||
@ -19,22 +19,41 @@ import { haStyle, haStyleDialog } from "../../../../src/resources/styles";
|
|||||||
import type { HomeAssistant } from "../../../../src/types";
|
import type { HomeAssistant } from "../../../../src/types";
|
||||||
import { RegistriesDialogParams } from "./show-dialog-registries";
|
import { RegistriesDialogParams } from "./show-dialog-registries";
|
||||||
|
|
||||||
|
const SCHEMA = [
|
||||||
|
{
|
||||||
|
type: "string",
|
||||||
|
name: "registry",
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: "string",
|
||||||
|
name: "username",
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: "string",
|
||||||
|
name: "password",
|
||||||
|
required: true,
|
||||||
|
format: "password",
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
@customElement("dialog-hassio-registries")
|
@customElement("dialog-hassio-registries")
|
||||||
class HassioRegistriesDialog extends LitElement {
|
class HassioRegistriesDialog extends LitElement {
|
||||||
@property({ attribute: false }) public hass!: HomeAssistant;
|
@property({ attribute: false }) public hass!: HomeAssistant;
|
||||||
|
|
||||||
@property({ attribute: false }) public supervisor!: Supervisor;
|
@property({ attribute: false }) public supervisor!: Supervisor;
|
||||||
|
|
||||||
@property({ attribute: false }) private _registries?: {
|
@state() private _registries?: {
|
||||||
registry: string;
|
registry: string;
|
||||||
username: string;
|
username: string;
|
||||||
}[];
|
}[];
|
||||||
|
|
||||||
@state() private _registry?: string;
|
@state() private _input: {
|
||||||
|
registry?: string;
|
||||||
@state() private _username?: string;
|
username?: string;
|
||||||
|
password?: string;
|
||||||
@state() private _password?: string;
|
} = {};
|
||||||
|
|
||||||
@state() private _opened = false;
|
@state() private _opened = false;
|
||||||
|
|
||||||
@ -47,6 +66,7 @@ class HassioRegistriesDialog extends LitElement {
|
|||||||
@closed=${this.closeDialog}
|
@closed=${this.closeDialog}
|
||||||
scrimClickAction
|
scrimClickAction
|
||||||
escapeKeyAction
|
escapeKeyAction
|
||||||
|
hideActions
|
||||||
.heading=${createCloseHeading(
|
.heading=${createCloseHeading(
|
||||||
this.hass,
|
this.hass,
|
||||||
this._addingRegistry
|
this._addingRegistry
|
||||||
@ -54,99 +74,77 @@ class HassioRegistriesDialog extends LitElement {
|
|||||||
: this.supervisor.localize("dialog.registries.title_manage")
|
: this.supervisor.localize("dialog.registries.title_manage")
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<div class="form">
|
${this._addingRegistry
|
||||||
${this._addingRegistry
|
? html`
|
||||||
? html`
|
<ha-form
|
||||||
<paper-input
|
.data=${this._input}
|
||||||
@value-changed=${this._inputChanged}
|
.schema=${SCHEMA}
|
||||||
class="flex-auto"
|
@value-changed=${this._valueChanged}
|
||||||
name="registry"
|
.computeLabel=${this._computeLabel}
|
||||||
.label=${this.supervisor.localize(
|
></ha-form>
|
||||||
"dialog.registries.registry"
|
<div class="action">
|
||||||
)}
|
|
||||||
required
|
|
||||||
auto-validate
|
|
||||||
></paper-input>
|
|
||||||
<paper-input
|
|
||||||
@value-changed=${this._inputChanged}
|
|
||||||
class="flex-auto"
|
|
||||||
name="username"
|
|
||||||
.label=${this.supervisor.localize(
|
|
||||||
"dialog.registries.username"
|
|
||||||
)}
|
|
||||||
required
|
|
||||||
auto-validate
|
|
||||||
></paper-input>
|
|
||||||
<paper-input
|
|
||||||
@value-changed=${this._inputChanged}
|
|
||||||
class="flex-auto"
|
|
||||||
name="password"
|
|
||||||
.label=${this.supervisor.localize(
|
|
||||||
"dialog.registries.password"
|
|
||||||
)}
|
|
||||||
type="password"
|
|
||||||
required
|
|
||||||
auto-validate
|
|
||||||
></paper-input>
|
|
||||||
|
|
||||||
<mwc-button
|
<mwc-button
|
||||||
?disabled=${Boolean(
|
?disabled=${Boolean(
|
||||||
!this._registry || !this._username || !this._password
|
!this._input.registry ||
|
||||||
|
!this._input.username ||
|
||||||
|
!this._input.password
|
||||||
)}
|
)}
|
||||||
@click=${this._addNewRegistry}
|
@click=${this._addNewRegistry}
|
||||||
>
|
>
|
||||||
${this.supervisor.localize("dialog.registries.add_registry")}
|
${this.supervisor.localize("dialog.registries.add_registry")}
|
||||||
</mwc-button>
|
</mwc-button>
|
||||||
`
|
</div>
|
||||||
: html`${this._registries?.length
|
`
|
||||||
? this._registries.map(
|
: html`${this._registries?.length
|
||||||
(entry) => html`
|
? this._registries.map(
|
||||||
<mwc-list-item class="option" hasMeta twoline>
|
(entry) => html`
|
||||||
<span>${entry.registry}</span>
|
<ha-settings-row class="registry">
|
||||||
<span slot="secondary"
|
<span slot="heading"> ${entry.registry} </span>
|
||||||
>${this.supervisor.localize(
|
<span slot="description">
|
||||||
"dialog.registries.username"
|
${this.supervisor.localize(
|
||||||
)}:
|
"dialog.registries.username"
|
||||||
${entry.username}</span
|
)}:
|
||||||
>
|
${entry.username}
|
||||||
<ha-icon-button
|
</span>
|
||||||
.entry=${entry}
|
<ha-icon-button
|
||||||
.label=${this.supervisor.localize(
|
.entry=${entry}
|
||||||
"dialog.registries.remove"
|
.label=${this.supervisor.localize(
|
||||||
)}
|
"dialog.registries.remove"
|
||||||
.path=${mdiDelete}
|
)}
|
||||||
slot="meta"
|
.path=${mdiDelete}
|
||||||
@click=${this._removeRegistry}
|
@click=${this._removeRegistry}
|
||||||
></ha-icon-button>
|
></ha-icon-button>
|
||||||
</mwc-list-item>
|
</ha-settings-row>
|
||||||
`
|
`
|
||||||
)
|
)
|
||||||
: html`
|
: html`
|
||||||
<mwc-list-item>
|
<ha-alert>
|
||||||
<span
|
${this.supervisor.localize(
|
||||||
>${this.supervisor.localize(
|
"dialog.registries.no_registries"
|
||||||
"dialog.registries.no_registries"
|
)}
|
||||||
)}</span
|
</ha-alert>
|
||||||
>
|
`}
|
||||||
</mwc-list-item>
|
<div class="action">
|
||||||
`}
|
|
||||||
<mwc-button @click=${this._addRegistry}>
|
<mwc-button @click=${this._addRegistry}>
|
||||||
${this.supervisor.localize(
|
${this.supervisor.localize(
|
||||||
"dialog.registries.add_new_registry"
|
"dialog.registries.add_new_registry"
|
||||||
)}
|
)}
|
||||||
</mwc-button> `}
|
</mwc-button>
|
||||||
</div>
|
</div> `}
|
||||||
</ha-dialog>
|
</ha-dialog>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _inputChanged(ev: Event) {
|
private _computeLabel = (schema: HaFormSchema) =>
|
||||||
const target = ev.currentTarget as PaperInputElement;
|
this.supervisor.localize(`dialog.registries.${schema.name}`) || schema.name;
|
||||||
this[`_${target.name}`] = target.value;
|
|
||||||
|
private _valueChanged(ev: CustomEvent) {
|
||||||
|
this._input = ev.detail.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async showDialog(dialogParams: RegistriesDialogParams): Promise<void> {
|
public async showDialog(dialogParams: RegistriesDialogParams): Promise<void> {
|
||||||
this._opened = true;
|
this._opened = true;
|
||||||
|
this._input = {};
|
||||||
this.supervisor = dialogParams.supervisor;
|
this.supervisor = dialogParams.supervisor;
|
||||||
await this._loadRegistries();
|
await this._loadRegistries();
|
||||||
await this.updateComplete;
|
await this.updateComplete;
|
||||||
@ -155,6 +153,7 @@ class HassioRegistriesDialog extends LitElement {
|
|||||||
public closeDialog(): void {
|
public closeDialog(): void {
|
||||||
this._addingRegistry = false;
|
this._addingRegistry = false;
|
||||||
this._opened = false;
|
this._opened = false;
|
||||||
|
this._input = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
public focus(): void {
|
public focus(): void {
|
||||||
@ -179,15 +178,16 @@ class HassioRegistriesDialog extends LitElement {
|
|||||||
|
|
||||||
private async _addNewRegistry(): Promise<void> {
|
private async _addNewRegistry(): Promise<void> {
|
||||||
const data = {};
|
const data = {};
|
||||||
data[this._registry!] = {
|
data[this._input.registry!] = {
|
||||||
username: this._username,
|
username: this._input.username,
|
||||||
password: this._password,
|
password: this._input.password,
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await addHassioDockerRegistry(this.hass, data);
|
await addHassioDockerRegistry(this.hass, data);
|
||||||
await this._loadRegistries();
|
await this._loadRegistries();
|
||||||
this._addingRegistry = false;
|
this._addingRegistry = false;
|
||||||
|
this._input = {};
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
showAlertDialog(this, {
|
showAlertDialog(this, {
|
||||||
title: this.supervisor.localize("dialog.registries.failed_to_add"),
|
title: this.supervisor.localize("dialog.registries.failed_to_add"),
|
||||||
@ -215,32 +215,20 @@ class HassioRegistriesDialog extends LitElement {
|
|||||||
haStyle,
|
haStyle,
|
||||||
haStyleDialog,
|
haStyleDialog,
|
||||||
css`
|
css`
|
||||||
ha-dialog.button-left {
|
.registry {
|
||||||
--justify-action-buttons: flex-start;
|
|
||||||
}
|
|
||||||
paper-icon-item {
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
.form {
|
|
||||||
color: var(--primary-text-color);
|
|
||||||
}
|
|
||||||
.option {
|
|
||||||
border: 1px solid var(--divider-color);
|
border: 1px solid var(--divider-color);
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
margin-top: 4px;
|
margin-top: 4px;
|
||||||
}
|
}
|
||||||
mwc-button {
|
.action {
|
||||||
margin-left: 8px;
|
margin-top: 24px;
|
||||||
|
width: 100%;
|
||||||
|
display: flex;
|
||||||
|
justify-content: flex-end;
|
||||||
}
|
}
|
||||||
ha-icon-button {
|
ha-icon-button {
|
||||||
color: var(--error-color);
|
color: var(--error-color);
|
||||||
margin: -10px;
|
margin-right: -10px;
|
||||||
}
|
|
||||||
mwc-list-item {
|
|
||||||
cursor: default;
|
|
||||||
}
|
|
||||||
mwc-list-item span[slot="secondary"] {
|
|
||||||
color: var(--secondary-text-color);
|
|
||||||
}
|
}
|
||||||
`,
|
`,
|
||||||
];
|
];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user