DEV: Modernize upgrade controller, fix banner styling

This commit is contained in:
Jarek Radosz 2023-01-16 11:18:34 +01:00
parent 4abbd27626
commit 1334cdef41
4 changed files with 36 additions and 34 deletions

View File

@ -1,27 +1,27 @@
import Controller from "@ember/controller";
import { computed } from "@ember/object";
import { tracked } from "@glimmer/tracking";
import { action } from "@ember/object";
export default Controller.extend({
showBanner: computed("banner", "bannerDismissed", "banner.[]", function () {
if (this.get("bannerDismissed")) {
export default class Upgrade extends Controller {
@tracked banner = [];
@tracked bannerDismissed = false;
get showBanner() {
if (this.bannerDismissed) {
return false;
}
const banner = this.get("banner");
return banner && banner.length > 0;
}),
return this.banner?.length > 0;
}
appendBannerHtml(html) {
const banner = this.get("banner") || [];
if (banner.indexOf(html) === -1) {
banner.pushObject(html);
if (!this.banner.includes(html)) {
this.banner = [...this.banner, html];
}
this.set("banner", banner);
},
}
actions: {
dismiss() {
this.set("bannerDismissed", true);
},
},
});
@action
dismiss() {
this.bannerDismissed = true;
}
}

View File

@ -36,9 +36,12 @@ export default Route.extend({
repo.get("id") === "discourse" &&
repo.get("branch") === "origin/main"
) {
upgradeController.appendBannerHtml(
"<b>WARNING:</b> Your Discourse is tracking the 'main' branch which may be unstable, <a href='https://meta.discourse.org/t/change-tracking-branch-for-your-discourse-instance/17014'>we recommend tracking the 'tests-passed' branch</a>."
);
upgradeController.appendBannerHtml(`
<b>WARNING:</b>
Your Discourse is tracking the 'main' branch which may be unstable,
<a href='https://meta.discourse.org/t/change-tracking-branch-for-your-discourse-instance/17014'>
we recommend tracking the 'tests-passed' branch</a>.
`);
}
});

View File

@ -17,15 +17,20 @@
</div>
<div class="docker-manager">
{{#if showBanner}}
{{#if this.showBanner}}
<div id="banner">
<div id="banner-content">
<div class="close" {{action "dismiss"}}>
<i class="fa fa-times" title="Dismiss this banner."></i>
<div class="floated-buttons">
<DButton
@icon="times"
@action={{this.dismiss}}
@class="btn btn-flat close"
@title="banner.close"
/>
</div>
{{#each banner as |row|}}
<p>{{{row}}}</p>
{{#each this.banner as |row|}}
<p>{{html-safe row}}</p>
{{/each}}
</div>
</div>

View File

@ -84,15 +84,9 @@
#banner {
margin: 1rem 0;
padding: 10px;
border-radius: 5px;
background: scale-color($tertiary, $lightness: 90%);
box-shadow: 0 1px 2px scale-color($tertiary, $lightness: 70%);
max-width: 1140px;
.close {
font-size: 20px !important;
margin-top: -10px !important;
p:first-of-type {
margin-top: 0;
}
}