mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 23:58:31 -05:00
Fix deprecations with site text, upgrade to ES6 / store
This commit is contained in:
parent
bd631e343a
commit
7fffd483f8
23 changed files with 96 additions and 107 deletions
|
@ -1,20 +1,16 @@
|
|||
export default Ember.ObjectController.extend({
|
||||
saving: false,
|
||||
export default Ember.Controller.extend({
|
||||
saved: false,
|
||||
|
||||
saveDisabled: function() {
|
||||
if (this.get('saving')) { return true; }
|
||||
if ((!this.get('allow_blank')) && Ember.isEmpty(this.get('value'))) { return true; }
|
||||
if (this.get('model.isSaving')) { return true; }
|
||||
if ((!this.get('allow_blank')) && Ember.isEmpty(this.get('model.value'))) { return true; }
|
||||
return false;
|
||||
}.property('saving', 'value'),
|
||||
}.property('model.iSaving', 'model.value'),
|
||||
|
||||
actions: {
|
||||
saveChanges: function() {
|
||||
var self = this;
|
||||
self.setProperties({saving: true, saved: false});
|
||||
self.get('model').save().then(function () {
|
||||
self.setProperties({saving: false, saved: true});
|
||||
});
|
||||
saveChanges() {
|
||||
const model = this.get('model');
|
||||
model.save(model.getProperties('value')).then(() => this.set('saved', true));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
import RestModel from 'discourse/models/rest';
|
||||
export default RestModel.extend();
|
8
app/assets/javascripts/admin/models/site-text.js.es6
Normal file
8
app/assets/javascripts/admin/models/site-text.js.es6
Normal file
|
@ -0,0 +1,8 @@
|
|||
import RestModel from 'discourse/models/rest';
|
||||
|
||||
export default RestModel.extend({
|
||||
markdown: Em.computed.equal('format', 'markdown'),
|
||||
plainText: Em.computed.equal('format', 'plain'),
|
||||
html: Em.computed.equal('format', 'html'),
|
||||
css: Em.computed.equal('format', 'css'),
|
||||
});
|
|
@ -1,21 +0,0 @@
|
|||
Discourse.SiteText = Discourse.Model.extend({
|
||||
markdown: Em.computed.equal('format', 'markdown'),
|
||||
plainText: Em.computed.equal('format', 'plain'),
|
||||
html: Em.computed.equal('format', 'html'),
|
||||
css: Em.computed.equal('format', 'css'),
|
||||
|
||||
save: function() {
|
||||
return Discourse.ajax("/admin/customize/site_text/" + this.get('text_type'), {
|
||||
type: 'PUT',
|
||||
data: {value: this.get('value')}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
Discourse.SiteText.reopenClass({
|
||||
find: function(type) {
|
||||
return Discourse.ajax("/admin/customize/site_text/" + type).then(function (data) {
|
||||
return Discourse.SiteText.create(data.site_text);
|
||||
});
|
||||
}
|
||||
});
|
|
@ -1,11 +0,0 @@
|
|||
Discourse.SiteTextType = Discourse.Model.extend();
|
||||
|
||||
Discourse.SiteTextType.reopenClass({
|
||||
findAll: function() {
|
||||
return Discourse.ajax("/admin/customize/site_text_types").then(function(data) {
|
||||
return data.map(function(ct) {
|
||||
return Discourse.SiteTextType.create(ct);
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
|
@ -21,7 +21,7 @@ export default {
|
|||
this.route('show', {path: '/:site_customization_id/:section'});
|
||||
});
|
||||
|
||||
this.resource('adminSiteText', { path: '/site_text' }, function() {
|
||||
this.resource('adminSiteText', { path: '/site_texts' }, function() {
|
||||
this.route('edit', {path: '/:text_type'});
|
||||
});
|
||||
this.resource('adminUserFields', { path: '/user_fields' });
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
export default Discourse.Route.extend({
|
||||
model: function(params) {
|
||||
return Discourse.SiteText.find(params.text_type);
|
||||
model(params) {
|
||||
return this.store.find('site-text', params.text_type);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
export default Discourse.Route.extend({
|
||||
model: function() {
|
||||
return Discourse.SiteTextType.findAll();
|
||||
model() {
|
||||
return this.store.findAll('site-text-type');
|
||||
}
|
||||
});
|
||||
|
|
26
app/assets/javascripts/admin/templates/site-text-edit.hbs
Normal file
26
app/assets/javascripts/admin/templates/site-text-edit.hbs
Normal file
|
@ -0,0 +1,26 @@
|
|||
<h3>{{model.title}}</h3>
|
||||
<p class='description'>{{model.description}}</p>
|
||||
|
||||
{{#if model.markdown}}
|
||||
{{pagedown-editor value=model.value}}
|
||||
{{/if}}
|
||||
{{#if model.plainText}}
|
||||
{{textarea value=model.value class="plain"}}
|
||||
{{/if}}
|
||||
{{#if model.html}}
|
||||
{{ace-editor content=model.value mode="html"}}
|
||||
{{/if}}
|
||||
{{#if model.css}}
|
||||
{{ace-editor content=model.value mode="css"}}
|
||||
{{/if}}
|
||||
|
||||
<div class='controls'>
|
||||
<button class='btn' {{action "saveChanges"}} disabled={{saveDisabled}}>
|
||||
{{#if model.isSaving}}
|
||||
{{i18n 'saving'}}
|
||||
{{else}}
|
||||
{{i18n 'save'}}
|
||||
{{/if}}
|
||||
</button>
|
||||
{{#if saved}}{{i18n 'saved'}}{{/if}}
|
||||
</div>
|
|
@ -1,26 +0,0 @@
|
|||
<h3>{{title}}</h3>
|
||||
<p class='description'>{{description}}</p>
|
||||
|
||||
{{#if markdown}}
|
||||
{{pagedown-editor value=value}}
|
||||
{{/if}}
|
||||
{{#if plainText}}
|
||||
{{textarea value=value class="plain"}}
|
||||
{{/if}}
|
||||
{{#if html}}
|
||||
{{ace-editor content=value mode="html"}}
|
||||
{{/if}}
|
||||
{{#if css}}
|
||||
{{ace-editor content=value mode="css"}}
|
||||
{{/if}}
|
||||
|
||||
<div class='controls'>
|
||||
<button class='btn' {{action "saveChanges"}} {{bind-attr disabled="saveDisabled"}}>
|
||||
{{#if saving}}
|
||||
{{i18n 'saving'}}
|
||||
{{else}}
|
||||
{{i18n 'save'}}
|
||||
{{/if}}
|
||||
</button>
|
||||
{{#if saved}}{{i18n 'saved'}}{{/if}}
|
||||
</div>
|
|
@ -0,0 +1,7 @@
|
|||
import RestAdapter from 'discourse/adapters/rest';
|
||||
|
||||
export default RestAdapter.extend({
|
||||
basePath() {
|
||||
return "/admin/customize/";
|
||||
}
|
||||
});
|
|
@ -0,0 +1,2 @@
|
|||
import CustomizationBase from 'discourse/adapters/customization-base';
|
||||
export default CustomizationBase;
|
|
@ -0,0 +1,2 @@
|
|||
import CustomizationBase from 'discourse/adapters/customization-base';
|
||||
export default CustomizationBase;
|
|
@ -1,7 +1,2 @@
|
|||
import RestAdapter from 'discourse/adapters/rest';
|
||||
|
||||
export default RestAdapter.extend({
|
||||
basePath() {
|
||||
return "/admin/customize/";
|
||||
}
|
||||
});
|
||||
import CustomizationBase from 'discourse/adapters/customization-base';
|
||||
export default CustomizationBase;
|
||||
|
|
|
@ -74,7 +74,7 @@ const ApplicationRoute = Discourse.Route.extend(OpenComposer, {
|
|||
}
|
||||
exceptionController.setProperties({ lastTransition: transition, thrown: err });
|
||||
|
||||
this.transitionTo('exception');
|
||||
this.intermediateTransitionTo('exception');
|
||||
},
|
||||
|
||||
showLogin: unlessReadOnly('handleShowLogin'),
|
||||
|
|
|
@ -1,21 +0,0 @@
|
|||
class Admin::SiteTextController < Admin::AdminController
|
||||
|
||||
def show
|
||||
site_text = SiteText.find_or_new(params[:id].to_s)
|
||||
render_serialized(site_text, SiteTextSerializer)
|
||||
end
|
||||
|
||||
def update
|
||||
site_text = SiteText.find_or_new(params[:id].to_s)
|
||||
|
||||
# Updating to nothing is the same as removing it
|
||||
if params[:value].present?
|
||||
site_text.value = params[:value]
|
||||
site_text.save!
|
||||
else
|
||||
site_text.destroy
|
||||
end
|
||||
|
||||
render nothing: true
|
||||
end
|
||||
end
|
|
@ -1,7 +1,7 @@
|
|||
class Admin::SiteTextTypesController < Admin::AdminController
|
||||
|
||||
def index
|
||||
render_serialized(SiteText.text_types, SiteTextTypeSerializer)
|
||||
render_serialized(SiteText.text_types, SiteTextTypeSerializer, root: 'site_text_types')
|
||||
end
|
||||
|
||||
end
|
||||
|
|
21
app/controllers/admin/site_texts_controller.rb
Normal file
21
app/controllers/admin/site_texts_controller.rb
Normal file
|
@ -0,0 +1,21 @@
|
|||
class Admin::SiteTextsController < Admin::AdminController
|
||||
|
||||
def show
|
||||
site_text = SiteText.find_or_new(params[:id].to_s)
|
||||
render_serialized(site_text, SiteTextSerializer, root: 'site_text')
|
||||
end
|
||||
|
||||
def update
|
||||
site_text = SiteText.find_or_new(params[:id].to_s)
|
||||
|
||||
# Updating to nothing is the same as removing it
|
||||
if params[:site_text][:value].present?
|
||||
site_text.value = params[:site_text][:value]
|
||||
site_text.save!
|
||||
else
|
||||
site_text.destroy
|
||||
end
|
||||
|
||||
render_serialized(site_text, SiteTextSerializer, root: 'site_text')
|
||||
end
|
||||
end
|
|
@ -1,12 +1,17 @@
|
|||
class SiteTextSerializer < ApplicationSerializer
|
||||
|
||||
attributes :text_type,
|
||||
attributes :id,
|
||||
:text_type,
|
||||
:title,
|
||||
:description,
|
||||
:value,
|
||||
:format,
|
||||
:allow_blank?
|
||||
|
||||
def id
|
||||
text_type
|
||||
end
|
||||
|
||||
def title
|
||||
object.site_text_type.title
|
||||
end
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
class SiteTextTypeSerializer < ApplicationSerializer
|
||||
|
||||
attributes :text_type, :title
|
||||
attributes :id, :text_type, :title
|
||||
|
||||
def id
|
||||
text_type
|
||||
end
|
||||
|
||||
def text_type
|
||||
object.text_type
|
||||
|
|
|
@ -142,7 +142,7 @@ Discourse::Application.routes.draw do
|
|||
post "flags/defer/:id" => "flags#defer"
|
||||
resources :site_customizations, constraints: AdminConstraint.new
|
||||
scope "/customize" do
|
||||
resources :site_text, constraints: AdminConstraint.new
|
||||
resources :site_texts, constraints: AdminConstraint.new
|
||||
resources :site_text_types, constraints: AdminConstraint.new
|
||||
resources :user_fields, constraints: AdminConstraint.new
|
||||
resources :emojis, constraints: AdminConstraint.new
|
||||
|
|
Loading…
Reference in a new issue