FIX: better error handling for theme import

This commit is contained in:
Sam 2017-04-17 16:55:53 -04:00
parent 5e3a0846f7
commit 86904e9cd6
5 changed files with 26 additions and 11 deletions

View File

@ -1,5 +1,6 @@
import { default as computed } from 'ember-addons/ember-computed-decorators';
import { url } from 'discourse/lib/computed';
import { popupAjaxError } from 'discourse/lib/ajax-error';
export default Ember.Controller.extend({
@ -79,14 +80,18 @@ export default Ember.Controller.extend({
updateToLatest() {
this.set("updatingRemote", true);
this.get("model").updateToLatest().finally(()=>{
this.get("model").updateToLatest()
.catch(popupAjaxError)
.finally(()=>{
this.set("updatingRemote", false);
});
},
checkForThemeUpdates() {
this.set("updatingRemote", true);
this.get("model").checkForUpdates().finally(()=>{
this.get("model").checkForUpdates()
.catch(popupAjaxError)
.finally(()=>{
this.set("updatingRemote", false);
});
},

View File

@ -65,7 +65,7 @@
<p>
{{#if model.remote_theme}}
{{#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}}
{{#d-button action="checkForThemeUpdates" icon="refresh"}}{{i18n "admin.customize.theme.check_for_updates"}}{{/d-button}}
{{/if}}

View File

@ -101,25 +101,32 @@ class Admin::ThemesController < Admin::AdminController
set_fields
save_remote = false
if params[:theme][:remote_check]
@theme.remote_theme.update_remote_version
@theme.remote_theme.save!
save_remote = true
end
if params[:theme][:remote_update]
@theme.remote_theme.update_from_remote
@theme.remote_theme.save!
save_remote = true
end
respond_to do |format|
if @theme.save
@theme.remote_theme.save! if save_remote
update_default_theme
log_theme_change(original_json, @theme)
format.json { render json: @theme, status: :created}
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

View File

@ -82,7 +82,7 @@ class RemoteTheme < ActiveRecord::Base
return unless hex
override = hex.downcase
if override !~ /[0-9a-f]{6}/
if override !~ /^[0-9a-f]{6}$/
override = nil
end
override

View File

@ -55,6 +55,9 @@ en:
anonymous: "Anonymous"
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:
incoming:
default_subject: "This topic needs a title"