From 2bea70a54781852bd42732faf4945fb38dadc585 Mon Sep 17 00:00:00 2001 From: Vinoth Kannan Date: Thu, 2 May 2024 09:41:06 +0530 Subject: [PATCH 1/5] UX: improve UI of software update page & display more info. This PR will refresh the software update page so that self-hosters can more easily understand the plugins they have installed and which plugins need updates, and so that they are able to quickly and easily update them (or update everything). --- .../components/docker-manager/repo-status.hbs | 106 ++++++++++-------- .../javascripts/discourse/models/repo.js | 56 ++++++++- .../discourse/templates/update-index.hbs | 42 ++++--- .../docker_manager/admin_controller.rb | 3 + assets/stylesheets/common/docker-manager.scss | 67 ++++++++++- config/locales/client.en.yml | 8 +- 6 files changed, 213 insertions(+), 69 deletions(-) diff --git a/admin/assets/javascripts/discourse/components/docker-manager/repo-status.hbs b/admin/assets/javascripts/discourse/components/docker-manager/repo-status.hbs index 3d9288d4..091e9fdd 100644 --- a/admin/assets/javascripts/discourse/components/docker-manager/repo-status.hbs +++ b/admin/assets/javascripts/discourse/components/docker-manager/repo-status.hbs @@ -1,62 +1,80 @@ - + - {{#if this.officialRepoBadge}} - {{d-icon - this.officialRepoBadge - translatedTitle=this.officialRepoBadgeTitle - class="check-circle" - }} +
+ {{#if @repo.linkUrl}} + + {{@repo.nameTitleized}} + + {{else}} + {{@repo.nameTitleized}} + {{/if}} +
+ {{#if @repo.author}} +
+ {{@repo.author}} +
+ {{/if}} + {{#if @repo.plugin}} +
+ {{@repo.plugin.about}} + {{#if @repo.linkUrl}} + + {{i18n "admin.plugins.learn_more"}} + + {{/if}} +
+ {{/if}} + {{#if @repo.hasNewVersion}} +
+ {{i18n "admin.docker.new_version_available"}} +
{{/if}} - {{@repo.name}} {{@repo.prettyVersion}} + {{format-date @repo.latest.date leaveAgo="true"}} + + + {{#if @repo.checkingStatus}} {{i18n "admin.docker.checking"}} {{else if @repo.upToDate}} {{i18n "admin.docker.up_to_date"}} {{else}} -
-

{{i18n "admin.docker.new_version_available"}}

- - - - -
+ {{/if}} - \ No newline at end of file + diff --git a/admin/assets/javascripts/discourse/models/repo.js b/admin/assets/javascripts/discourse/models/repo.js index c23d9bf3..b5123d27 100644 --- a/admin/assets/javascripts/discourse/models/repo.js +++ b/admin/assets/javascripts/discourse/models/repo.js @@ -1,6 +1,9 @@ -import { tracked } from "@glimmer/tracking"; +import { cached, tracked } from "@glimmer/tracking"; +import { capitalize } from "@ember/string"; import { TrackedObject } from "@ember-compat/tracked-built-ins"; import { ajax } from "discourse/lib/ajax"; +import I18n from "discourse-i18n"; +import AdminPlugin from "admin/models/admin-plugin"; let loaded = []; export let needsImageUpgrade = false; @@ -74,6 +77,7 @@ export default class Repo { @tracked checking = false; @tracked lastCheckedAt = null; @tracked latest = new TrackedObject({}); + @tracked plugin = null; // model attributes @tracked name = null; @@ -94,8 +98,12 @@ export default class Repo { } } + if (attributes.plugin) { + this.plugin = AdminPlugin.create(attributes.plugin); + } + for (const [key, value] of Object.entries(attributes)) { - if (key === "latest") { + if (["latest", "plugin"].includes(key)) { continue; } @@ -103,6 +111,46 @@ export default class Repo { } } + @cached + get nameTitleized() { + if (this.plugin) { + return this.plugin.nameTitleized; + } + + let name = this.name + .split(/[-_]/) + .map((word) => { + return capitalize(word); + }) + .join(" "); + + // Cuts down on repetition. + const discoursePrefix = "Discourse "; + if (name.startsWith(discoursePrefix)) { + name = name.slice(discoursePrefix.length); + } + + return name; + } + + get linkUrl() { + if (this.plugin) { + return this.plugin.linkUrl; + } + + return this.url; + } + + get author() { + if (this.plugin) { + return this.plugin.author; + } else if (this.name === "docker_manager") { + return I18n.t("admin.plugins.author", { author: "Discourse" }); + } + + return null; + } + get checkingStatus() { return this.unloaded || this.checking; } @@ -111,6 +159,10 @@ export default class Repo { return !this.upgrading && this.version === this.latest?.version; } + get hasNewVersion() { + return !this.checkingStatus && !this.upToDate; + } + get prettyVersion() { return this.pretty_version || this.version?.substring(0, 8); } diff --git a/admin/assets/javascripts/discourse/templates/update-index.hbs b/admin/assets/javascripts/discourse/templates/update-index.hbs index 3b0595ab..612086fa 100644 --- a/admin/assets/javascripts/discourse/templates/update-index.hbs +++ b/admin/assets/javascripts/discourse/templates/update-index.hbs @@ -1,4 +1,21 @@ -

{{i18n "admin.docker.update_title"}}

+
+

{{i18n "admin.docker.update_title"}}

+ {{#unless this.outdated}} + + {{/unless}} +
{{#if this.outdated}}

{{i18n "admin.docker.outdated_image_header"}}

@@ -18,25 +35,14 @@

{{else}} - - +
- - - + + + + + {{#each this.model as |repo|}} diff --git a/app/controllers/docker_manager/admin_controller.rb b/app/controllers/docker_manager/admin_controller.rb index fa4397d1..0dcea311 100644 --- a/app/controllers/docker_manager/admin_controller.rb +++ b/app/controllers/docker_manager/admin_controller.rb @@ -21,6 +21,9 @@ def repos official: Plugin::Metadata::OFFICIAL_PLUGINS.include?(r.name), } + plugin = Discourse.visible_plugins.find { |p| p.path == "#{r.path}/plugin.rb" } + result[:plugin] = AdminPluginSerializer.new(plugin, scope: guardian, root: false) if plugin.present? + result[:fork] = true if result[:official] && !r.url.starts_with?("https://github.com/discourse/") diff --git a/assets/stylesheets/common/docker-manager.scss b/assets/stylesheets/common/docker-manager.scss index bb32c40f..55c281f8 100644 --- a/assets/stylesheets/common/docker-manager.scss +++ b/assets/stylesheets/common/docker-manager.scss @@ -92,10 +92,6 @@ } } - #upgrade-all { - float: right; - } - #banner { margin: 1rem 0; @@ -147,4 +143,67 @@ } } } + + .repo__name { + font-weight: bold; + } + + .repo__author { + font-size: var(--font-down-2); + padding: 0 0 .25em 0; + } + + .repo__new-version { + font-size: var(--font-down-1); + font-weight: bold; + padding: .25em 0 0 0; + } + + .repo__about { + padding: .25em 0 .25em 0; + + a { + color: var(--primary-700); + text-decoration: underline; + } + } + + ul.repo__latest-version { + list-style: none; + margin: 0; + } + + tr.repo { + td { + padding: 1em 0; + } + + &.new-version { + background-color: var(--tertiary-very-low); + + td:first-child { + border-left: solid 3px var(--tertiary); + } + } + + td.repo__status { + text-align: right; + padding-right: 0.5em; + } + } + + .updates-heading { + display: flex; + justify-content: space-between; + margin: 2em 0; + + h3 { + line-height: 40px; + margin-bottom: 0; + } + } + + .admin-repos th:last-child { + text-align: center; + } } diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 64845906..b057366b 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -36,8 +36,14 @@ en: update_repo: "Update %{name}" update_successful: "Update completed successfully!" update_tab: "Update Discourse" - update_title: "Update Discourse" + update_title: "Updates" updating: "Updating…" + repo: + name: "Name" + commit_hash: "Commit Hash" + last_updated: "Last Updated" + latest_version: "Latest Version" + status: "Status" logs: staff_actions: From dfb3f8f56178afd42877ddca9439cfd01117d516 Mon Sep 17 00:00:00 2001 From: Vinoth Kannan Date: Thu, 2 May 2024 09:46:20 +0530 Subject: [PATCH 2/5] fix the linting isues --- app/controllers/docker_manager/admin_controller.rb | 6 +++++- assets/stylesheets/common/docker-manager.scss | 6 +++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/controllers/docker_manager/admin_controller.rb b/app/controllers/docker_manager/admin_controller.rb index 0dcea311..06d1597c 100644 --- a/app/controllers/docker_manager/admin_controller.rb +++ b/app/controllers/docker_manager/admin_controller.rb @@ -22,7 +22,11 @@ def repos } plugin = Discourse.visible_plugins.find { |p| p.path == "#{r.path}/plugin.rb" } - result[:plugin] = AdminPluginSerializer.new(plugin, scope: guardian, root: false) if plugin.present? + result[:plugin] = AdminPluginSerializer.new( + plugin, + scope: guardian, + root: false, + ) if plugin.present? result[:fork] = true if result[:official] && !r.url.starts_with?("https://github.com/discourse/") diff --git a/assets/stylesheets/common/docker-manager.scss b/assets/stylesheets/common/docker-manager.scss index 55c281f8..259ddc05 100644 --- a/assets/stylesheets/common/docker-manager.scss +++ b/assets/stylesheets/common/docker-manager.scss @@ -150,17 +150,17 @@ .repo__author { font-size: var(--font-down-2); - padding: 0 0 .25em 0; + padding: 0 0 0.25em 0; } .repo__new-version { font-size: var(--font-down-1); font-weight: bold; - padding: .25em 0 0 0; + padding: 0.25em 0 0 0; } .repo__about { - padding: .25em 0 .25em 0; + padding: 0.25em 0 0.25em 0; a { color: var(--primary-700); From 5baf590b8a2f6de9f78ee1b3c4b7bb73dec0cb23 Mon Sep 17 00:00:00 2001 From: Vinoth Kannan Date: Thu, 2 May 2024 09:51:27 +0530 Subject: [PATCH 3/5] make the prettier happy --- .../components/docker-manager/repo-status.hbs | 14 +++----------- admin/assets/javascripts/discourse/models/repo.js | 10 +++++----- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/admin/assets/javascripts/discourse/components/docker-manager/repo-status.hbs b/admin/assets/javascripts/discourse/components/docker-manager/repo-status.hbs index 091e9fdd..32847b78 100644 --- a/admin/assets/javascripts/discourse/components/docker-manager/repo-status.hbs +++ b/admin/assets/javascripts/discourse/components/docker-manager/repo-status.hbs @@ -2,11 +2,7 @@ - + \ No newline at end of file diff --git a/admin/assets/javascripts/discourse/models/repo.js b/admin/assets/javascripts/discourse/models/repo.js index b5123d27..c3c540e1 100644 --- a/admin/assets/javascripts/discourse/models/repo.js +++ b/admin/assets/javascripts/discourse/models/repo.js @@ -118,11 +118,11 @@ export default class Repo { } let name = this.name - .split(/[-_]/) - .map((word) => { - return capitalize(word); - }) - .join(" "); + .split(/[-_]/) + .map((word) => { + return capitalize(word); + }) + .join(" "); // Cuts down on repetition. const discoursePrefix = "Discourse "; From 8750082a12216cf4972831ba34746fb45ccae5d0 Mon Sep 17 00:00:00 2001 From: Vinoth Kannan Date: Wed, 26 Jun 2024 14:20:52 +0530 Subject: [PATCH 4/5] DEV: add system tests to check the existance of core & plugin repos --- .../docker_manager/admin_controller.rb | 2 +- spec/system/admin_update_spec.rb | 29 +++++++++++++++++++ .../system/page_objects/pages/admin_update.rb | 20 +++++++++++++ 3 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 spec/system/admin_update_spec.rb create mode 100644 spec/system/page_objects/pages/admin_update.rb diff --git a/app/controllers/docker_manager/admin_controller.rb b/app/controllers/docker_manager/admin_controller.rb index 06d1597c..f8a6eae1 100644 --- a/app/controllers/docker_manager/admin_controller.rb +++ b/app/controllers/docker_manager/admin_controller.rb @@ -45,7 +45,7 @@ def repos response = { repos: repos } - if !Rails.env.development? + if !Rails.env.development? && !Rails.env.test? version = begin File.read("/VERSION") diff --git a/spec/system/admin_update_spec.rb b/spec/system/admin_update_spec.rb new file mode 100644 index 00000000..575c07de --- /dev/null +++ b/spec/system/admin_update_spec.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +RSpec.describe "Admin update", type: :system do + fab!(:admin) + let(:au_page) { PageObjects::Pages::AdminUpdate.new } + + before do + sign_in(admin) + au_page.visit + end + + it "shows the update page" do + expect(au_page).to be_displayed + end + + it "shows the core repo" do + expect(au_page).to have_repo( + name: "Discourse", + url: "https://github.com/discourse/discourse.git", + ) + end + + it "shows the docker_manager plugin repo" do + expect(au_page).to have_repo( + name: "Docker Manager", + url: "https://github.com/discourse/docker_manager.git", + ) + end +end diff --git a/spec/system/page_objects/pages/admin_update.rb b/spec/system/page_objects/pages/admin_update.rb new file mode 100644 index 00000000..b63ce725 --- /dev/null +++ b/spec/system/page_objects/pages/admin_update.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +module PageObjects + module Pages + class AdminUpdate < PageObjects::Pages::Base + def visit + page.visit("/admin/update") + self + end + + def displayed? + has_css?("h3", text: "Updates") + end + + def has_repo?(repo) + has_css?("tr.repo .repo__name a[href='#{repo[:url]}']", text: repo[:name]) + end + end + end +end From b05864cc81f8f57748a992883d45f3dbf1c3ffb6 Mon Sep 17 00:00:00 2001 From: Vinoth Kannan Date: Fri, 28 Jun 2024 02:47:31 +0530 Subject: [PATCH 5/5] UX: link repo SHA versions to the commit URLs --- .../components/docker-manager/repo-status.hbs | 20 ++++++++++++------- .../discourse/helpers/commit-url.js | 19 ++++++++++++++++++ assets/stylesheets/common/docker-manager.scss | 2 +- 3 files changed, 33 insertions(+), 8 deletions(-) create mode 100644 admin/assets/javascripts/discourse/helpers/commit-url.js diff --git a/admin/assets/javascripts/discourse/components/docker-manager/repo-status.hbs b/admin/assets/javascripts/discourse/components/docker-manager/repo-status.hbs index 32847b78..424abb25 100644 --- a/admin/assets/javascripts/discourse/components/docker-manager/repo-status.hbs +++ b/admin/assets/javascripts/discourse/components/docker-manager/repo-status.hbs @@ -32,18 +32,24 @@ - \ No newline at end of file + diff --git a/admin/assets/javascripts/discourse/helpers/commit-url.js b/admin/assets/javascripts/discourse/helpers/commit-url.js new file mode 100644 index 00000000..c561e6b1 --- /dev/null +++ b/admin/assets/javascripts/discourse/helpers/commit-url.js @@ -0,0 +1,19 @@ +import { helper as buildHelper } from "@ember/component/helper"; +import { htmlSafe } from "@ember/template"; + +export default buildHelper(function (params) { + const [_class, version, prettyVersion, url] = params; + + if (!prettyVersion) { + return ""; + } + + if (!url) { + return prettyVersion; + } + + const _url = url.substr(0, url.search(/(\.git)?$/)); + const description = `${prettyVersion}`; + + return new htmlSafe(description); +}); diff --git a/assets/stylesheets/common/docker-manager.scss b/assets/stylesheets/common/docker-manager.scss index 259ddc05..e5dccdf5 100644 --- a/assets/stylesheets/common/docker-manager.scss +++ b/assets/stylesheets/common/docker-manager.scss @@ -73,7 +73,7 @@ } } - span.commit-hash { + .commit-hash { color: #959595; }
{{i18n "admin.docker.repository"}}{{i18n "admin.docker.status"}}{{i18n "admin.docker.repo.name"}}{{i18n "admin.docker.repo.commit_hash"}}{{i18n "admin.docker.repo.last_updated"}}{{i18n "admin.docker.repo.latest_version"}}{{i18n "admin.docker.repo.status"}}
{{#if @repo.linkUrl}} - + {{@repo.nameTitleized}} {{else}} @@ -22,11 +18,7 @@
{{@repo.plugin.about}} {{#if @repo.linkUrl}} - + {{i18n "admin.plugins.learn_more"}} {{/if}} @@ -77,4 +69,4 @@ /> {{/if}}
- - {{@repo.prettyVersion}} - + {{commit-url + "current" + @repo.version + @repo.prettyVersion + @repo.url + }} {{format-date @repo.latest.date leaveAgo="true"}}
  • - - {{@repo.prettyLatestVersion}} - + {{commit-url + "new" + @repo.latest.version + @repo.prettyLatestVersion + @repo.url + }}
  • {{new-commits @@ -69,4 +75,4 @@ /> {{/if}}