mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: better error handling for theme import
This commit is contained in:
parent
5e3a0846f7
commit
86904e9cd6
@ -1,5 +1,6 @@
|
|||||||
import { default as computed } from 'ember-addons/ember-computed-decorators';
|
import { default as computed } from 'ember-addons/ember-computed-decorators';
|
||||||
import { url } from 'discourse/lib/computed';
|
import { url } from 'discourse/lib/computed';
|
||||||
|
import { popupAjaxError } from 'discourse/lib/ajax-error';
|
||||||
|
|
||||||
export default Ember.Controller.extend({
|
export default Ember.Controller.extend({
|
||||||
|
|
||||||
@ -79,14 +80,18 @@ export default Ember.Controller.extend({
|
|||||||
|
|
||||||
updateToLatest() {
|
updateToLatest() {
|
||||||
this.set("updatingRemote", true);
|
this.set("updatingRemote", true);
|
||||||
this.get("model").updateToLatest().finally(()=>{
|
this.get("model").updateToLatest()
|
||||||
|
.catch(popupAjaxError)
|
||||||
|
.finally(()=>{
|
||||||
this.set("updatingRemote", false);
|
this.set("updatingRemote", false);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
checkForThemeUpdates() {
|
checkForThemeUpdates() {
|
||||||
this.set("updatingRemote", true);
|
this.set("updatingRemote", true);
|
||||||
this.get("model").checkForUpdates().finally(()=>{
|
this.get("model").checkForUpdates()
|
||||||
|
.catch(popupAjaxError)
|
||||||
|
.finally(()=>{
|
||||||
this.set("updatingRemote", false);
|
this.set("updatingRemote", false);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -65,7 +65,7 @@
|
|||||||
<p>
|
<p>
|
||||||
{{#if model.remote_theme}}
|
{{#if model.remote_theme}}
|
||||||
{{#if model.remote_theme.commits_behind}}
|
{{#if model.remote_theme.commits_behind}}
|
||||||
{{#d-button action="updateToLatest" icon="download"}}{{i18n "admin.customize.theme.update_to_latest"}}{{/d-button}}
|
{{#d-button action="updateToLatest" icon="download" class='btn-primary'}}{{i18n "admin.customize.theme.update_to_latest"}}{{/d-button}}
|
||||||
{{else}}
|
{{else}}
|
||||||
{{#d-button action="checkForThemeUpdates" icon="refresh"}}{{i18n "admin.customize.theme.check_for_updates"}}{{/d-button}}
|
{{#d-button action="checkForThemeUpdates" icon="refresh"}}{{i18n "admin.customize.theme.check_for_updates"}}{{/d-button}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
@ -101,25 +101,32 @@ class Admin::ThemesController < Admin::AdminController
|
|||||||
|
|
||||||
set_fields
|
set_fields
|
||||||
|
|
||||||
|
save_remote = false
|
||||||
if params[:theme][:remote_check]
|
if params[:theme][:remote_check]
|
||||||
@theme.remote_theme.update_remote_version
|
@theme.remote_theme.update_remote_version
|
||||||
@theme.remote_theme.save!
|
save_remote = true
|
||||||
end
|
end
|
||||||
|
|
||||||
if params[:theme][:remote_update]
|
if params[:theme][:remote_update]
|
||||||
@theme.remote_theme.update_from_remote
|
@theme.remote_theme.update_from_remote
|
||||||
@theme.remote_theme.save!
|
save_remote = true
|
||||||
end
|
end
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
if @theme.save
|
if @theme.save
|
||||||
|
|
||||||
|
@theme.remote_theme.save! if save_remote
|
||||||
|
|
||||||
update_default_theme
|
update_default_theme
|
||||||
|
|
||||||
log_theme_change(original_json, @theme)
|
log_theme_change(original_json, @theme)
|
||||||
format.json { render json: @theme, status: :created}
|
format.json { render json: @theme, status: :created}
|
||||||
else
|
else
|
||||||
format.json { render json: @theme.errors, status: :unprocessable_entity }
|
format.json {
|
||||||
|
|
||||||
|
error = @theme.errors[:color_scheme] ? I18n.t("themes.bad_color_scheme") : I18n.t("themes.other_error")
|
||||||
|
render json: {errors: [ error ]}, status: :unprocessable_entity
|
||||||
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -82,7 +82,7 @@ class RemoteTheme < ActiveRecord::Base
|
|||||||
return unless hex
|
return unless hex
|
||||||
|
|
||||||
override = hex.downcase
|
override = hex.downcase
|
||||||
if override !~ /[0-9a-f]{6}/
|
if override !~ /^[0-9a-f]{6}$/
|
||||||
override = nil
|
override = nil
|
||||||
end
|
end
|
||||||
override
|
override
|
||||||
|
@ -55,6 +55,9 @@ en:
|
|||||||
anonymous: "Anonymous"
|
anonymous: "Anonymous"
|
||||||
remove_posts_deleted_by_author: "Deleted by author"
|
remove_posts_deleted_by_author: "Deleted by author"
|
||||||
|
|
||||||
|
themes:
|
||||||
|
bad_color_scheme: "Can not update theme, invalid color scheme"
|
||||||
|
other_error: "Something went wrong updating theme"
|
||||||
emails:
|
emails:
|
||||||
incoming:
|
incoming:
|
||||||
default_subject: "This topic needs a title"
|
default_subject: "This topic needs a title"
|
||||||
|
Loading…
Reference in New Issue
Block a user