FEATURE: Export customizations as JSON files

This commit is contained in:
riking 2015-05-16 18:15:42 -07:00
parent 7ab8827c7e
commit 1e53c179a3
6 changed files with 40 additions and 1 deletions

View File

@ -84,7 +84,11 @@ Discourse.SiteCustomization = Discourse.Model.extend({
destroy: function() {
if (!this.id) return;
return Discourse.ajax("/admin/site_customizations/" + this.id, { type: 'DELETE' });
}
},
download_url: function() {
return Discourse.getURL('/admin/site_customizations/' + this.id);
}.property('id')
});
var SiteCustomizations = Ember.ArrayProxy.extend({

View File

@ -14,6 +14,7 @@
<div {{bind-attr class=":current-style view.maximized:maximized"}}>
<div class='wrapper'>
{{text-field class="style-name" value=selectedItem.name}}
<a class="btn export" download target="_blank" href={{selectedItem.download_url}}>{{fa-icon "download"}} {{i18n 'admin.export_json.button_text'}}</a>
<div class='admin-controls'>
<ul class="nav nav-pills">

View File

@ -545,6 +545,9 @@ section.details {
.preview-link {
margin-left: 15px;
}
.export {
float: right;
}
padding-left: 10px;
width: 70%;
.style-name {

View File

@ -2,6 +2,8 @@ class Admin::SiteCustomizationsController < Admin::AdminController
before_filter :enable_customization
skip_before_filter :check_xhr, only: [:show]
def index
@site_customizations = SiteCustomization.order(:name)
@ -48,6 +50,26 @@ class Admin::SiteCustomizationsController < Admin::AdminController
end
end
def show
@site_customization = SiteCustomization.find(params[:id])
respond_to do |format|
format.json do
check_xhr
render json: SiteCustomizationSerializer.new(@site_customization)
end
format.any(:html, :text) do
raise RenderEmpty.new if request.xhr?
response.headers['Content-Disposition'] = "attachment; filename=#{@site_customization.name.parameterize}.dcstyle.json"
response.sending_file = true
render json: SiteCustomizationSerializer.new(@site_customization)
end
end
end
private
def site_customization_params

View File

@ -0,0 +1,7 @@
class SiteCustomizationSerializer < ApplicationSerializer
attributes :name, :enabled, :created_at, :updated_at,
:stylesheet, :header, :footer, :top,
:mobile_stylesheet, :mobile_header, :mobile_footer, :mobile_top,
:head_tag, :body_tag
end

View File

@ -1863,6 +1863,8 @@ en:
screened_email: "Export full screened email list in CSV format."
screened_ip: "Export full screened IP list in CSV format."
screened_url: "Export full screened URL list in CSV format."
export_json:
button_text: "Export"
invite:
button_text: "Send Invites"