Skip to content

Commit

Permalink
Move updates (#10626)
Browse files Browse the repository at this point in the history
  • Loading branch information
ludeeus committed Nov 17, 2021
1 parent 481da19 commit e9f0967
Show file tree
Hide file tree
Showing 25 changed files with 829 additions and 626 deletions.
26 changes: 25 additions & 1 deletion gallery/src/demos/demo-ha-alert.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import "../../../src/components/ha-logo-svg";
import { html, css, LitElement, TemplateResult } from "lit";
import { customElement } from "lit/decorators";
import "../../../src/components/ha-alert";
Expand All @@ -10,6 +11,8 @@ const alerts: {
dismissable?: boolean;
action?: string;
rtl?: boolean;
iconSlot?: TemplateResult;
actionSlot?: TemplateResult;
}[] = [
{
title: "Test info alert",
Expand Down Expand Up @@ -81,6 +84,18 @@ const alerts: {
type: "warning",
action: "save",
},
{
title: "Slotted icon",
description: "Alert with slotted icon",
type: "warning",
iconSlot: html`<ha-logo-svg slot="icon"></ha-logo-svg>`,
},
{
title: "Slotted action",
description: "Alert with slotted action",
type: "info",
actionSlot: html`<mwc-button slot="action" label="action"></mwc-button>`,
},
{
description: "Dismissable information (RTL)",
type: "info",
Expand Down Expand Up @@ -117,7 +132,7 @@ export class DemoHaAlert extends LitElement {
.actionText=${alert.action || ""}
.rtl=${alert.rtl || false}
>
${alert.description}
${alert.iconSlot} ${alert.description} ${alert.actionSlot}
</ha-alert>
`
)}
Expand Down Expand Up @@ -145,6 +160,15 @@ export class DemoHaAlert extends LitElement {
span {
margin-right: 16px;
}
ha-logo-svg {
width: 28px;
height: 28px;
padding-right: 8px;
place-self: center;
}
mwc-button {
--mdc-theme-primary: var(--primary-text-color);
}
`;
}
}
Expand Down
135 changes: 29 additions & 106 deletions hassio/src/addon-view/info/hassio-addon-info.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import "@material/mwc-button";
import {
mdiArrowUpBoldCircle,
mdiCheckCircle,
mdiChip,
mdiCircle,
Expand Down Expand Up @@ -49,7 +48,6 @@ import {
startHassioAddon,
stopHassioAddon,
uninstallHassioAddon,
updateHassioAddon,
validateHassioAddonOption,
} from "../../../../src/data/hassio/addon";
import {
Expand All @@ -69,9 +67,8 @@ import { bytesToString } from "../../../../src/util/bytes-to-string";
import "../../components/hassio-card-content";
import "../../components/supervisor-metric";
import { showHassioMarkdownDialog } from "../../dialogs/markdown/show-dialog-hassio-markdown";
import { showDialogSupervisorUpdate } from "../../dialogs/update/show-dialog-update";
import { hassioStyle } from "../../resources/hassio-style";
import { addonArchIsSupported } from "../../util/addon";
import { addonArchIsSupported, extractChangelog } from "../../util/addon";

const STAGE_ICON = {
stable: mdiCheckCircle,
Expand Down Expand Up @@ -128,69 +125,23 @@ class HassioAddonInfo extends LitElement {
return html`
${this.addon.update_available
? html`
<ha-card
.header="${this.supervisor.localize(
"common.update_available",
"count",
1
)}🎉"
<ha-alert
.title=${this.supervisor.localize("common.update_available", {
count: 1,
})}
>
<div class="card-content">
<hassio-card-content
.hass=${this.hass}
.title=${this.supervisor.localize(
"addon.dashboard.new_update_available",
"name",
this.addon.name,
"version",
this.addon.version_latest
)}
.description=${this.supervisor.localize(
"common.running_version",
"version",
this.addon.version
)}
icon=${mdiArrowUpBoldCircle}
iconClass="update"
></hassio-card-content>
${!this.addon.available && addonStoreInfo
? !addonArchIsSupported(
this.supervisor.info.supported_arch,
this.addon.arch
)
? html`
<ha-alert alert-type="warning">
${this.supervisor.localize(
"addon.dashboard.not_available_arch"
)}
</ha-alert>
`
: html`
<ha-alert alert-type="warning">
${this.supervisor.localize(
"addon.dashboard.not_available_arch",
"core_version_installed",
this.supervisor.core.version,
"core_version_needed",
addonStoreInfo.homeassistant
)}
</ha-alert>
`
: ""}
</div>
<div class="card-actions">
${this.addon.changelog
? html`
<mwc-button @click=${this._openChangelog}>
${this.supervisor.localize("addon.dashboard.changelog")}
</mwc-button>
`
: html`<span></span>`}
<mwc-button @click=${this._updateClicked}>
${this.supervisor.localize("common.update")}
${this.supervisor.localize(
"addon.dashboard.new_update_available",
{ name: this.addon.name, version: this.addon.version_latest }
)}
<a
href="/hassio/update-available/${this.addon.slug}"
slot="action"
>
<mwc-button .label=${this.supervisor.localize("common.review")}>
</mwc-button>
</div>
</ha-card>
</a>
</ha-alert>
`
: ""}
${!this.addon.protected
Expand Down Expand Up @@ -899,22 +850,14 @@ class HassioAddonInfo extends LitElement {

private async _openChangelog(): Promise<void> {
try {
let content = await fetchHassioAddonChangelog(this.hass, this.addon.slug);
if (
content.includes(`# ${this.addon.version}`) &&
content.includes(`# ${this.addon.version_latest}`)
) {
const newcontent = content.split(`# ${this.addon.version}`)[0];
if (newcontent.includes(`# ${this.addon.version_latest}`)) {
// Only change the content if the new version still exist
// if the changelog does not have the newests version on top
// this will not be true, and we don't modify the content
content = newcontent;
}
}
const content = await fetchHassioAddonChangelog(
this.hass,
this.addon.slug
);

showHassioMarkdownDialog(this, {
title: this.supervisor.localize("addon.dashboard.changelog"),
content,
content: extractChangelog(this.addon, content),
});
} catch (err: any) {
showAlertDialog(this, {
Expand Down Expand Up @@ -989,33 +932,6 @@ class HassioAddonInfo extends LitElement {
button.progress = false;
}

private async _updateClicked(): Promise<void> {
showDialogSupervisorUpdate(this, {
supervisor: this.supervisor,
name: this.addon.name,
version: this.addon.version_latest,
backupParams: {
name: `addon_${this.addon.slug}_${this.addon.version}`,
addons: [this.addon.slug],
homeassistant: false,
},
updateHandler: async () => this._updateAddon(),
});
}

private async _updateAddon(): Promise<void> {
await updateHassioAddon(this.hass, this.addon.slug);
fireEvent(this, "supervisor-collection-refresh", {
collection: "addon",
});
const eventdata = {
success: true,
response: undefined,
path: "update",
};
fireEvent(this, "hass-api-called", eventdata);
}

private async _startClicked(ev: CustomEvent): Promise<void> {
const button = ev.currentTarget as any;
button.progress = true;
Expand Down Expand Up @@ -1244,6 +1160,13 @@ class HassioAddonInfo extends LitElement {
align-self: end;
}
ha-alert mwc-button {
--mdc-theme-primary: var(--primary-text-color);
}
a {
text-decoration: none;
}
@media (max-width: 720px) {
ha-chip {
line-height: 36px;
Expand Down
2 changes: 1 addition & 1 deletion hassio/src/backups/hassio-backups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export class HassioBackups extends LitElement {
}
return html`
<hass-tabs-subpage-data-table
.tabs=${supervisorTabs}
.tabs=${supervisorTabs(this.hass)}
.hass=${this.hass}
.localizeFunc=${this.supervisor.localize}
.searchLabel=${this.supervisor.localize("search")}
Expand Down
4 changes: 3 additions & 1 deletion hassio/src/dashboard/hassio-addons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ class HassioAddons extends LitElement {
protected render(): TemplateResult {
return html`
<div class="content">
<h1>${this.supervisor.localize("dashboard.addons")}</h1>
${!atLeastVersion(this.hass.config.version, 2021, 12)
? html` <h1>${this.supervisor.localize("dashboard.addons")}</h1> `
: ""}
<div class="card-group">
${!this.supervisor.supervisor.addons?.length
? html`
Expand Down
15 changes: 10 additions & 5 deletions hassio/src/dashboard/hassio-dashboard.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { mdiStorePlus } from "@mdi/js";
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
import { customElement, property } from "lit/decorators";
import { atLeastVersion } from "../../../src/common/config/version";
import "../../../src/components/ha-fab";
import { Supervisor } from "../../../src/data/supervisor/supervisor";
import "../../../src/layouts/hass-tabs-subpage";
Expand All @@ -27,7 +28,7 @@ class HassioDashboard extends LitElement {
.localizeFunc=${this.supervisor.localize}
.narrow=${this.narrow}
.route=${this.route}
.tabs=${supervisorTabs}
.tabs=${supervisorTabs(this.hass)}
main-page
supervisor
hasFab
Expand All @@ -36,10 +37,14 @@ class HassioDashboard extends LitElement {
${this.supervisor.localize("panel.dashboard")}
</span>
<div class="content">
<hassio-update
.hass=${this.hass}
.supervisor=${this.supervisor}
></hassio-update>
${!atLeastVersion(this.hass.config.version, 2021, 12)
? html`
<hassio-update
.hass=${this.hass}
.supervisor=${this.supervisor}
></hassio-update>
`
: ""}
<hassio-addons
.hass=${this.hass}
.supervisor=${this.supervisor}
Expand Down

0 comments on commit e9f0967

Please sign in to comment.