mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-28 11:46:42 +00:00
Add re-import blueprint (#18807)
* Add re-import blueprint * Add disabled color to icon
This commit is contained in:
parent
5c47d8652d
commit
93158bb3af
@ -1,6 +1,5 @@
|
|||||||
import "@material/mwc-list/mwc-list-item";
|
|
||||||
import { mdiDotsVertical } from "@mdi/js";
|
|
||||||
import "@lrnwebcomponents/simple-tooltip/simple-tooltip";
|
import "@lrnwebcomponents/simple-tooltip/simple-tooltip";
|
||||||
|
import { mdiDotsVertical } from "@mdi/js";
|
||||||
import { css, html, LitElement, TemplateResult } from "lit";
|
import { css, html, LitElement, TemplateResult } from "lit";
|
||||||
import { customElement, property } from "lit/decorators";
|
import { customElement, property } from "lit/decorators";
|
||||||
import { classMap } from "lit/directives/class-map";
|
import { classMap } from "lit/directives/class-map";
|
||||||
@ -8,6 +7,7 @@ import { haStyle } from "../resources/styles";
|
|||||||
import { HomeAssistant } from "../types";
|
import { HomeAssistant } from "../types";
|
||||||
import "./ha-button-menu";
|
import "./ha-button-menu";
|
||||||
import "./ha-icon-button";
|
import "./ha-icon-button";
|
||||||
|
import "./ha-list-item";
|
||||||
import "./ha-svg-icon";
|
import "./ha-svg-icon";
|
||||||
|
|
||||||
export interface IconOverflowMenuItem {
|
export interface IconOverflowMenuItem {
|
||||||
@ -49,7 +49,7 @@ export class HaIconOverflowMenu extends LitElement {
|
|||||||
${this.items.map((item) =>
|
${this.items.map((item) =>
|
||||||
item.divider
|
item.divider
|
||||||
? html`<li divider role="separator"></li>`
|
? html`<li divider role="separator"></li>`
|
||||||
: html`<mwc-list-item
|
: html`<ha-list-item
|
||||||
graphic="icon"
|
graphic="icon"
|
||||||
?disabled=${item.disabled}
|
?disabled=${item.disabled}
|
||||||
@click=${item.action}
|
@click=${item.action}
|
||||||
@ -62,7 +62,7 @@ export class HaIconOverflowMenu extends LitElement {
|
|||||||
></ha-svg-icon>
|
></ha-svg-icon>
|
||||||
</div>
|
</div>
|
||||||
${item.label}
|
${item.label}
|
||||||
</mwc-list-item> `
|
</ha-list-item> `
|
||||||
)}
|
)}
|
||||||
</ha-button-menu>`
|
</ha-button-menu>`
|
||||||
: html`
|
: html`
|
||||||
@ -126,6 +126,9 @@ export class HaIconOverflowMenu extends LitElement {
|
|||||||
border-right: 1px solid var(--divider-color);
|
border-right: 1px solid var(--divider-color);
|
||||||
width: 1px;
|
width: 1px;
|
||||||
}
|
}
|
||||||
|
ha-list-item[disabled] ha-svg-icon {
|
||||||
|
color: var(--disabled-text-color);
|
||||||
|
}
|
||||||
`,
|
`,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -26,15 +26,19 @@ import {
|
|||||||
RowClickedEvent,
|
RowClickedEvent,
|
||||||
} from "../../../components/data-table/ha-data-table";
|
} from "../../../components/data-table/ha-data-table";
|
||||||
import "../../../components/entity/ha-entity-toggle";
|
import "../../../components/entity/ha-entity-toggle";
|
||||||
|
import "../../../components/ha-button";
|
||||||
import "../../../components/ha-fab";
|
import "../../../components/ha-fab";
|
||||||
import "../../../components/ha-icon-button";
|
import "../../../components/ha-icon-button";
|
||||||
import "../../../components/ha-icon-overflow-menu";
|
import "../../../components/ha-icon-overflow-menu";
|
||||||
import "../../../components/ha-svg-icon";
|
import "../../../components/ha-svg-icon";
|
||||||
import { showAutomationEditor } from "../../../data/automation";
|
import { showAutomationEditor } from "../../../data/automation";
|
||||||
import {
|
import {
|
||||||
|
BlueprintImportResult,
|
||||||
BlueprintMetaData,
|
BlueprintMetaData,
|
||||||
Blueprints,
|
Blueprints,
|
||||||
deleteBlueprint,
|
deleteBlueprint,
|
||||||
|
importBlueprint,
|
||||||
|
saveBlueprint,
|
||||||
} from "../../../data/blueprint";
|
} from "../../../data/blueprint";
|
||||||
import { showScriptEditor } from "../../../data/script";
|
import { showScriptEditor } from "../../../data/script";
|
||||||
import { findRelated } from "../../../data/search";
|
import { findRelated } from "../../../data/search";
|
||||||
@ -46,6 +50,7 @@ import "../../../layouts/hass-tabs-subpage-data-table";
|
|||||||
import { haStyle } from "../../../resources/styles";
|
import { haStyle } from "../../../resources/styles";
|
||||||
import { HomeAssistant, Route } from "../../../types";
|
import { HomeAssistant, Route } from "../../../types";
|
||||||
import { documentationUrl } from "../../../util/documentation-url";
|
import { documentationUrl } from "../../../util/documentation-url";
|
||||||
|
import { showToast } from "../../../util/toast";
|
||||||
import { configSections } from "../ha-panel-config";
|
import { configSections } from "../ha-panel-config";
|
||||||
import { showAddBlueprintDialog } from "./show-dialog-import-blueprint";
|
import { showAddBlueprintDialog } from "./show-dialog-import-blueprint";
|
||||||
|
|
||||||
@ -199,6 +204,16 @@ class HaBlueprintOverview extends LitElement {
|
|||||||
),
|
),
|
||||||
action: () => this._share(blueprint),
|
action: () => this._share(blueprint),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: mdiDownload,
|
||||||
|
disabled: !blueprint.source_url,
|
||||||
|
label: this.hass.localize(
|
||||||
|
blueprint.source_url
|
||||||
|
? "ui.panel.config.blueprint.overview.re_import_blueprint"
|
||||||
|
: "ui.panel.config.blueprint.overview.re_import_blueprint_no_url"
|
||||||
|
),
|
||||||
|
action: () => this._reImport(blueprint),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
divider: true,
|
divider: true,
|
||||||
},
|
},
|
||||||
@ -256,10 +271,10 @@ class HaBlueprintOverview extends LitElement {
|
|||||||
target="_blank"
|
target="_blank"
|
||||||
rel="noreferrer noopener"
|
rel="noreferrer noopener"
|
||||||
>
|
>
|
||||||
<mwc-button
|
<ha-button
|
||||||
>${this.hass.localize(
|
>${this.hass.localize(
|
||||||
"ui.panel.config.blueprint.overview.discover_more"
|
"ui.panel.config.blueprint.overview.discover_more"
|
||||||
)}</mwc-button
|
)}</ha-button
|
||||||
>
|
>
|
||||||
</a>
|
</a>
|
||||||
</div>`}
|
</div>`}
|
||||||
@ -359,6 +374,67 @@ class HaBlueprintOverview extends LitElement {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private _reImport = async (blueprint: BlueprintMetaDataPath) => {
|
||||||
|
const result = await showConfirmationDialog(this, {
|
||||||
|
title: this.hass.localize(
|
||||||
|
"ui.panel.config.blueprint.overview.re_import_confirm_title"
|
||||||
|
),
|
||||||
|
text: html`
|
||||||
|
${this.hass.localize(
|
||||||
|
"ui.panel.config.blueprint.overview.re_import_confirm_text"
|
||||||
|
)}
|
||||||
|
`,
|
||||||
|
confirmText: this.hass.localize(
|
||||||
|
"ui.panel.config.blueprint.overview.re_import_confirm_action"
|
||||||
|
),
|
||||||
|
warning: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!result) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let importResult: BlueprintImportResult;
|
||||||
|
try {
|
||||||
|
importResult = await importBlueprint(this.hass, blueprint.source_url!);
|
||||||
|
} catch (err) {
|
||||||
|
showToast(this, {
|
||||||
|
message: this.hass.localize(
|
||||||
|
"ui.panel.config.blueprint.overview.re_import_error_source_not_found"
|
||||||
|
),
|
||||||
|
});
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
await saveBlueprint(
|
||||||
|
this.hass,
|
||||||
|
blueprint.domain,
|
||||||
|
blueprint.path,
|
||||||
|
importResult!.raw_data,
|
||||||
|
blueprint.source_url,
|
||||||
|
true
|
||||||
|
);
|
||||||
|
} catch (err: any) {
|
||||||
|
showToast(this, {
|
||||||
|
message: this.hass.localize(
|
||||||
|
"ui.panel.config.blueprint.overview.re_import_error_save",
|
||||||
|
{ error: err.message }
|
||||||
|
),
|
||||||
|
});
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
|
||||||
|
fireEvent(this, "reload-blueprints");
|
||||||
|
|
||||||
|
showToast(this, {
|
||||||
|
message: this.hass.localize(
|
||||||
|
"ui.panel.config.blueprint.overview.re_import_success",
|
||||||
|
{ name: importResult!.blueprint.metadata.name }
|
||||||
|
),
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
private _delete = async (blueprint: BlueprintMetaDataPath) => {
|
private _delete = async (blueprint: BlueprintMetaDataPath) => {
|
||||||
const related = await findRelated(
|
const related = await findRelated(
|
||||||
this.hass,
|
this.hass,
|
||||||
|
@ -2963,6 +2963,14 @@
|
|||||||
"delete_blueprint": "Delete blueprint",
|
"delete_blueprint": "Delete blueprint",
|
||||||
"share_blueprint": "Share blueprint",
|
"share_blueprint": "Share blueprint",
|
||||||
"share_blueprint_no_url": "Unable to share blueprint: no source url",
|
"share_blueprint_no_url": "Unable to share blueprint: no source url",
|
||||||
|
"re_import_blueprint": "Re-import blueprint",
|
||||||
|
"re_import_blueprint_no_url": "Unable to re-import blueprint: no source url",
|
||||||
|
"re_import_confirm_title": "Re-import blueprint",
|
||||||
|
"re_import_confirm_text": "[%key:ui::panel::config::blueprint::add::override_description%]",
|
||||||
|
"re_import_confirm_action": "Re-import",
|
||||||
|
"re_import_error_source_not_found": "Unable to re-import the blueprint: source not found.",
|
||||||
|
"re_import_error_save": "Unable to re-import the blueprint: {error}.",
|
||||||
|
"re_import_success": "{name} has been successfully re-imported.",
|
||||||
"discover_more": "Discover more blueprints"
|
"discover_more": "Discover more blueprints"
|
||||||
},
|
},
|
||||||
"add": {
|
"add": {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user