mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FEATURE: Show diff of local changes before updating remote theme (#7443)
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
import RestModel from "discourse/models/rest";
|
||||
import { default as computed } from "ember-addons/ember-computed-decorators";
|
||||
import { popupAjaxError } from "discourse/lib/ajax-error";
|
||||
import { ajax } from "discourse/lib/ajax";
|
||||
import { escapeExpression } from "discourse/lib/utilities";
|
||||
import highlightSyntax from "discourse/lib/highlight-syntax";
|
||||
|
||||
const THEME_UPLOAD_VAR = 2;
|
||||
|
||||
@@ -277,9 +280,36 @@ const Theme = RestModel.extend({
|
||||
},
|
||||
|
||||
updateToLatest() {
|
||||
return this.save({ remote_update: true }).then(() =>
|
||||
this.set("changed", false)
|
||||
);
|
||||
return ajax(`/admin/themes/${this.id}/diff_local_changes`).then(json => {
|
||||
if (json && json.error) {
|
||||
bootbox.alert(
|
||||
I18n.t("generic_error_with_reason", {
|
||||
error: json.error
|
||||
})
|
||||
);
|
||||
} else if (json && json.diff) {
|
||||
bootbox.confirm(
|
||||
I18n.t("admin.customize.theme.update_confirm") +
|
||||
`<pre><code class="diff">${escapeExpression(
|
||||
json.diff
|
||||
)}</code></pre>`,
|
||||
I18n.t("cancel"),
|
||||
I18n.t("admin.customize.theme.update_confirm_yes"),
|
||||
result => {
|
||||
if (result) {
|
||||
return this.save({ remote_update: true }).then(() =>
|
||||
this.set("changed", false)
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
highlightSyntax();
|
||||
} else {
|
||||
return this.save({ remote_update: true }).then(() =>
|
||||
this.set("changed", false)
|
||||
);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
changed: false,
|
||||
|
||||
@@ -265,6 +265,15 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pre {
|
||||
background-color: blend-primary-secondary(5%);
|
||||
max-height: 300px;
|
||||
padding: 0.5em;
|
||||
code {
|
||||
max-height: none;
|
||||
}
|
||||
}
|
||||
}
|
||||
.password-confirmation {
|
||||
display: none;
|
||||
|
||||
@@ -250,6 +250,15 @@ class Admin::ThemesController < Admin::AdminController
|
||||
exporter.cleanup!
|
||||
end
|
||||
|
||||
def diff_local_changes
|
||||
theme = Theme.find_by(id: params[:id])
|
||||
raise Discourse::InvalidParameters.new(:id) unless theme
|
||||
changes = theme.remote_theme&.diff_local_changes
|
||||
respond_to do |format|
|
||||
format.json { render json: changes || {} }
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def update_default_theme
|
||||
|
||||
@@ -170,6 +170,21 @@ class RemoteTheme < ActiveRecord::Base
|
||||
end
|
||||
end
|
||||
|
||||
def diff_local_changes
|
||||
return unless is_git?
|
||||
importer = ThemeStore::GitImporter.new(remote_url, private_key: private_key, branch: branch)
|
||||
begin
|
||||
importer.import!
|
||||
rescue RemoteTheme::ImportError => err
|
||||
{ error: err.message }
|
||||
else
|
||||
changes = importer.diff_local_changes(self.id)
|
||||
return nil if changes.blank?
|
||||
|
||||
{ diff: changes }
|
||||
end
|
||||
end
|
||||
|
||||
def normalize_override(hex)
|
||||
return unless hex
|
||||
|
||||
|
||||
Reference in New Issue
Block a user