diff --git a/app/assets/javascripts/admin/addon/controllers/modals/admin-install-theme.js b/app/assets/javascripts/admin/addon/controllers/modals/admin-install-theme.js index 79f47dfc696..bc6258228da 100644 --- a/app/assets/javascripts/admin/addon/controllers/modals/admin-install-theme.js +++ b/app/assets/javascripts/admin/addon/controllers/modals/admin-install-theme.js @@ -125,6 +125,19 @@ export default Controller.extend(ModalFunctionality, { return privateChecked && checkPrivate && publicKey; }, + onClose() { + this.set("duplicateRemoteThemeWarning", null); + }, + + themeHasSameUrl(theme, url) { + const themeUrl = theme.remote_theme && theme.remote_theme.remote_url; + return ( + themeUrl && + url && + url.replace(/\.git$/, "") === themeUrl.replace(/\.git$/, "") + ); + }, + actions: { uploadLocaleFile() { this.set("localFile", $("#file-input")[0].files[0]); @@ -167,6 +180,17 @@ export default Controller.extend(ModalFunctionality, { } if (this.remote || this.popular) { + const duplicate = this.themesController.model.content.find((theme) => + this.themeHasSameUrl(theme, this.uploadUrl) + ); + if (duplicate && !this.duplicateRemoteThemeWarning) { + const warning = I18n.t( + "admin.customize.theme.duplicate_remote_theme", + { name: duplicate.name } + ); + this.set("duplicateRemoteThemeWarning", warning); + return; + } options.data = { remote: this.uploadUrl, branch: this.branch, diff --git a/app/assets/javascripts/admin/addon/templates/modal/admin-install-theme.hbs b/app/assets/javascripts/admin/addon/templates/modal/admin-install-theme.hbs index 053ce042a8c..bbe8e4a83a2 100644 --- a/app/assets/javascripts/admin/addon/templates/modal/admin-install-theme.hbs +++ b/app/assets/javascripts/admin/addon/templates/modal/admin-install-theme.hbs @@ -103,6 +103,11 @@ {{#unless popular}} diff --git a/app/assets/stylesheets/common/admin/customize-install-theme.scss b/app/assets/stylesheets/common/admin/customize-install-theme.scss index 70e65ae6562..141365c6e6d 100644 --- a/app/assets/stylesheets/common/admin/customize-install-theme.scss +++ b/app/assets/stylesheets/common/admin/customize-install-theme.scss @@ -126,3 +126,7 @@ } } } + +.install-theme-warning { + margin-bottom: 10px; +} diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 74ecc13e69a..80180a7aa97 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -4088,6 +4088,7 @@ en: install_upload: "From your device" install_git_repo: "From a git repository" install_create: "Create new" + duplicate_remote_theme: "The theme component “%{name}” is already installed, are you sure you want to install another copy?" about_theme: "About" license: "License" version: "Version:"