mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 22:05:48 +08:00
ES6 module migrations
This commit is contained in:
parent
22ffcba8e6
commit
a83a19f6ce
|
@ -1,6 +1,7 @@
|
|||
import Presence from 'discourse/mixins/presence';
|
||||
import { outputExportResult } from 'discourse/lib/export-result';
|
||||
|
||||
export default Ember.ArrayController.extend(Discourse.Presence, {
|
||||
export default Ember.ArrayController.extend(Presence, {
|
||||
loading: false,
|
||||
|
||||
actions: {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import Presence from 'discourse/mixins/presence';
|
||||
import { outputExportResult } from 'discourse/lib/export-result';
|
||||
|
||||
export default Ember.ArrayController.extend(Discourse.Presence, {
|
||||
export default Ember.ArrayController.extend(Presence, {
|
||||
loading: false,
|
||||
itemController: 'admin-log-screened-ip-address',
|
||||
filter: null,
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import Presence from 'discourse/mixins/presence';
|
||||
import { outputExportResult } from 'discourse/lib/export-result';
|
||||
|
||||
export default Ember.ArrayController.extend(Discourse.Presence, {
|
||||
export default Ember.ArrayController.extend(Presence, {
|
||||
loading: false,
|
||||
|
||||
show() {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import Presence from 'discourse/mixins/presence';
|
||||
import { outputExportResult } from 'discourse/lib/export-result';
|
||||
|
||||
export default Ember.ArrayController.extend(Discourse.Presence, {
|
||||
export default Ember.ArrayController.extend(Presence, {
|
||||
loading: false,
|
||||
filters: null,
|
||||
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
export default Ember.ArrayController.extend(Discourse.Presence, {
|
||||
import Presence from 'discourse/mixins/presence';
|
||||
|
||||
export default Ember.ArrayController.extend(Presence, {
|
||||
filter: null,
|
||||
onlyOverridden: false,
|
||||
filtered: Ember.computed.notEmpty('filter'),
|
||||
|
|
|
@ -1 +1,3 @@
|
|||
export default Ember.Controller.extend(Discourse.Presence);
|
||||
import Presence from 'discourse/mixins/presence';
|
||||
|
||||
export default Ember.Controller.extend(Presence);
|
||||
|
|
|
@ -1 +1,3 @@
|
|||
export default Ember.ObjectController.extend(Discourse.Presence);
|
||||
import Presence from 'discourse/mixins/presence';
|
||||
|
||||
export default Ember.ObjectController.extend(Presence);
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
import Presence from 'discourse/mixins/presence';
|
||||
import searchForTerm from 'discourse/lib/search-for-term';
|
||||
|
||||
var _dontSearch = false;
|
||||
|
||||
export default Em.Controller.extend(Discourse.Presence, {
|
||||
export default Em.Controller.extend(Presence, {
|
||||
|
||||
contextType: function(key, value){
|
||||
if(arguments.length > 1) {
|
||||
|
|
|
@ -1,36 +0,0 @@
|
|||
/**
|
||||
This mixin provides `blank` and `present` to determine whether properties are
|
||||
there, accounting for more cases than just null and undefined.
|
||||
|
||||
@class Discourse.Presence
|
||||
@extends Ember.Mixin
|
||||
@namespace Discourse
|
||||
@module Discourse
|
||||
**/
|
||||
Discourse.Presence = Em.Mixin.create({
|
||||
|
||||
/**
|
||||
Returns whether a property is blank. It considers empty arrays, string, objects, undefined and null
|
||||
to be blank, otherwise true.
|
||||
|
||||
@method blank
|
||||
@param {String} name the name of the property we want to check
|
||||
@return {Boolean}
|
||||
*/
|
||||
blank: function(name) {
|
||||
return Ember.isEmpty(this[name] || this.get(name));
|
||||
},
|
||||
|
||||
/**
|
||||
Returns whether a property is present. A present property is the opposite of a `blank` one.
|
||||
|
||||
@method present
|
||||
@param {String} name the name of the property we want to check
|
||||
@return {Boolean}
|
||||
*/
|
||||
present: function(name) {
|
||||
return !this.blank(name);
|
||||
}
|
||||
});
|
||||
|
||||
|
20
app/assets/javascripts/discourse/mixins/presence.js.es6
Normal file
20
app/assets/javascripts/discourse/mixins/presence.js.es6
Normal file
|
@ -0,0 +1,20 @@
|
|||
/**
|
||||
This mixin provides `blank` and `present` to determine whether properties are
|
||||
there, accounting for more cases than just null and undefined.
|
||||
**/
|
||||
export default Ember.Mixin.create({
|
||||
|
||||
/**
|
||||
Returns whether a property is blank. It considers empty arrays, string, objects, undefined and null
|
||||
to be blank, otherwise true.
|
||||
*/
|
||||
blank(name) {
|
||||
return Ember.isEmpty(this[name] || this.get(name));
|
||||
},
|
||||
|
||||
// Returns whether a property is present. A present property is the opposite of a `blank` one.
|
||||
present(name) {
|
||||
return !this.blank(name);
|
||||
}
|
||||
|
||||
});
|
|
@ -1,6 +1,8 @@
|
|||
Discourse.Model = Ember.Object.extend(Discourse.Presence);
|
||||
import Presence from 'discourse/mixins/presence';
|
||||
|
||||
Discourse.Model.reopenClass({
|
||||
const Model = Ember.Object.extend(Presence);
|
||||
|
||||
Model.reopenClass({
|
||||
extractByKey: function(collection, klass) {
|
||||
var retval = {};
|
||||
if (Ember.isEmpty(collection)) { return retval; }
|
||||
|
@ -11,3 +13,5 @@ Discourse.Model.reopenClass({
|
|||
return retval;
|
||||
}
|
||||
});
|
||||
|
||||
export default Model;
|
|
@ -1,4 +1,6 @@
|
|||
const Post = Discourse.Model.extend({
|
||||
import RestModel from 'discourse/models/rest';
|
||||
|
||||
const Post = RestModel.extend({
|
||||
|
||||
init() {
|
||||
this.set('replyHistory', []);
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
export default Ember.Object.extend({
|
||||
import Presence from 'discourse/mixins/presence';
|
||||
|
||||
export default Ember.Object.extend(Presence, {
|
||||
update(attrs) {
|
||||
const self = this,
|
||||
type = this.get('__type');
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
export default Ember.ContainerView.extend(Discourse.Presence, {
|
||||
import Presence from 'discourse/mixins/presence';
|
||||
|
||||
export default Ember.ContainerView.extend(Presence, {
|
||||
|
||||
attachViewWithArgs(viewArgs, viewClass) {
|
||||
if (!viewClass) { viewClass = Ember.View.extend(); }
|
||||
|
|
12
app/assets/javascripts/discourse/views/grouped.js.es6
Normal file
12
app/assets/javascripts/discourse/views/grouped.js.es6
Normal file
|
@ -0,0 +1,12 @@
|
|||
import Presence from 'discourse/mixins/presence';
|
||||
|
||||
export default Ember.View.extend(Presence, {
|
||||
_groupInit: function() {
|
||||
this.set('context', this.get('content'));
|
||||
|
||||
const templateData = this.get('templateData');
|
||||
if (templateData) {
|
||||
this.set('templateData.insideGroup', true);
|
||||
}
|
||||
}.on('init')
|
||||
});
|
|
@ -1,52 +0,0 @@
|
|||
/**
|
||||
A base view that gives us common functionality, for example `present` and `blank`
|
||||
|
||||
@class View
|
||||
@extends Ember.View
|
||||
@uses Discourse.Presence
|
||||
@namespace Discourse
|
||||
@module Discourse
|
||||
**/
|
||||
Discourse.View = Ember.View.extend(Discourse.Presence, {});
|
||||
|
||||
Discourse.GroupedView = Ember.View.extend(Discourse.Presence, {
|
||||
init: function() {
|
||||
this._super();
|
||||
this.set('context', this.get('content'));
|
||||
|
||||
var templateData = this.get('templateData');
|
||||
if (templateData) {
|
||||
this.set('templateData.insideGroup', true);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Discourse.View.reopenClass({
|
||||
|
||||
/**
|
||||
Register a view helper for ease of use
|
||||
|
||||
@method registerHelper
|
||||
@param {String} helperName the name of the helper
|
||||
@param {Ember.View} helperClass the view that will be inserted by the helper
|
||||
**/
|
||||
registerHelper: function(helperName, helperClass) {
|
||||
Ember.Handlebars.registerHelper(helperName, function(options) {
|
||||
var hash = options.hash,
|
||||
types = options.hashTypes;
|
||||
|
||||
Discourse.Utilities.normalizeHash(hash, types);
|
||||
return Ember.Handlebars.helpers.view.call(this, helperClass, options);
|
||||
});
|
||||
},
|
||||
|
||||
renderIfChanged: function() {
|
||||
Em.warn("`rerenderIfChanged` is deprecated. Use the `StringBuffer` mixin with `rerenderTriggers` instead.");
|
||||
var args = Array.prototype.slice.call(arguments, 0);
|
||||
args.unshift(function () {
|
||||
Ember.run.once(this, 'rerender');
|
||||
});
|
||||
return Ember.observer.apply(this, args);
|
||||
}
|
||||
|
||||
});
|
17
app/assets/javascripts/discourse/views/view.js.es6
Normal file
17
app/assets/javascripts/discourse/views/view.js.es6
Normal file
|
@ -0,0 +1,17 @@
|
|||
import Presence from 'discourse/mixins/presence';
|
||||
|
||||
const View = Ember.View.extend(Presence, {});
|
||||
|
||||
View.reopenClass({
|
||||
registerHelper(helperName, helperClass) {
|
||||
Ember.Handlebars.registerHelper(helperName, function(options) {
|
||||
var hash = options.hash,
|
||||
types = options.hashTypes;
|
||||
|
||||
Discourse.Utilities.normalizeHash(hash, types);
|
||||
return Ember.Handlebars.helpers.view.call(this, helperClass, options);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
export default View;
|
|
@ -24,6 +24,7 @@
|
|||
//= require ./discourse/lib/avatar-template
|
||||
//= require ./discourse/lib/safari-hacks
|
||||
//= require_tree ./discourse/adapters
|
||||
//= require ./discourse/models/rest
|
||||
//= require ./discourse/models/model
|
||||
//= require ./discourse/models/post
|
||||
//= require ./discourse/models/user_action
|
||||
|
@ -36,6 +37,7 @@
|
|||
//= require ./discourse/controllers/object
|
||||
//= require ./discourse/controllers/navigation/default
|
||||
//= require ./discourse/views/view
|
||||
//= require ./discourse/views/grouped
|
||||
//= require ./discourse/views/container
|
||||
//= require ./discourse/views/modal-body
|
||||
//= require ./discourse/views/flag
|
||||
|
|
|
@ -107,6 +107,7 @@ module Tilt
|
|||
# HAX
|
||||
result = "Controller" if result == "ControllerController"
|
||||
result = "Route" if result == "DiscourseRoute"
|
||||
result = "View" if result == "ViewView"
|
||||
result.gsub!(/Mixin$/, '')
|
||||
result.gsub!(/Model$/, '')
|
||||
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
moduleFor("controller:admin-email-index");
|
||||
|
||||
test("mixes in Discourse.Presence", function() {
|
||||
ok(Discourse.Presence.detect(this.subject()));
|
||||
});
|
|
@ -1,5 +0,0 @@
|
|||
moduleFor("controller:admin-email-preview-digest");
|
||||
|
||||
test("mixes in Discourse.Presence", function() {
|
||||
ok(Discourse.Presence.detect(this.subject()));
|
||||
});
|
|
@ -1,7 +1,8 @@
|
|||
import DiscourseController from 'discourse/controllers/controller';
|
||||
import Presence from 'discourse/mixins/presence';
|
||||
|
||||
module("DiscourseController");
|
||||
|
||||
test("includes mixins", function() {
|
||||
ok(Discourse.Presence.detect(DiscourseController.create()), "Discourse.Presence");
|
||||
ok(Presence.detect(DiscourseController.create()), "has Presence");
|
||||
});
|
||||
|
|
|
@ -131,7 +131,7 @@ export default function() {
|
|||
return response(200, { basic_topic: {id: request.params.id,
|
||||
title: data.title,
|
||||
fancy_title: data.title,
|
||||
slug: request.params.slug } })
|
||||
slug: request.params.slug } });
|
||||
});
|
||||
|
||||
this.post('/posts', function(request) {
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
module("Discourse.Presence");
|
||||
import Presence from 'discourse/mixins/presence';
|
||||
|
||||
var testObj = Em.Object.createWithMixins(Discourse.Presence, {
|
||||
module("mixin:presence");
|
||||
|
||||
var testObj = Em.Object.createWithMixins(Presence, {
|
||||
emptyString: "",
|
||||
nonEmptyString: "Evil Trout",
|
||||
emptyArray: [],
|
||||
|
|
|
@ -1,14 +1,17 @@
|
|||
import Presence from 'discourse/mixins/presence';
|
||||
import Model from 'discourse/models/model';
|
||||
|
||||
module("Discourse.Model");
|
||||
|
||||
test("mixes in Discourse.Presence", function() {
|
||||
ok(Discourse.Presence.detect(Discourse.Model.create()));
|
||||
test("mixes in Presence", function() {
|
||||
ok(Presence.detect(Model.create()));
|
||||
});
|
||||
|
||||
test("extractByKey: converts a list of hashes into a hash of instances of specified class, indexed by their ids", function() {
|
||||
var firstObject = {id: "id_1", foo: "foo_1"};
|
||||
var secondObject = {id: "id_2", foo: "foo_2"};
|
||||
|
||||
var actual = Discourse.Model.extractByKey([firstObject, secondObject], Ember.Object);
|
||||
var actual = Model.extractByKey([firstObject, secondObject], Ember.Object);
|
||||
var expected = {
|
||||
id_1: Ember.Object.create(firstObject),
|
||||
id_2: Ember.Object.create(secondObject)
|
||||
|
@ -18,6 +21,6 @@ test("extractByKey: converts a list of hashes into a hash of instances of specif
|
|||
});
|
||||
|
||||
test("extractByKey: returns an empty hash if there isn't anything to convert", function() {
|
||||
deepEqual(Discourse.Model.extractByKey(), {}, "when called without parameters");
|
||||
deepEqual(Discourse.Model.extractByKey([]), {}, "when called with an empty array");
|
||||
deepEqual(Model.extractByKey(), {}, "when called without parameters");
|
||||
deepEqual(Model.extractByKey([]), {}, "when called with an empty array");
|
||||
});
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import Presence from 'discourse/mixins/presence';
|
||||
|
||||
var SomeViewClass = Ember.View.extend();
|
||||
|
||||
function containerHasOnlyOneChild(containerView, klass) {
|
||||
|
@ -17,9 +19,9 @@ function childHasProperty(containerView, name) {
|
|||
|
||||
moduleFor("view:container");
|
||||
|
||||
test("mixes in Discourse.Presence", function() {
|
||||
test("mixes in Presence", function() {
|
||||
var containerView = this.subject();
|
||||
ok(Discourse.Presence.detect(containerView));
|
||||
ok(Presence.detect(containerView));
|
||||
});
|
||||
|
||||
test("attachViewWithArgs: creates a view of a given class with given properties and appends it to the container", function() {
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import Presence from 'discourse/mixins/presence';
|
||||
|
||||
var oldHelpers;
|
||||
|
||||
module("Discourse.View", {
|
||||
|
@ -10,8 +12,8 @@ module("Discourse.View", {
|
|||
}
|
||||
});
|
||||
|
||||
test("mixes in Discourse.Presence", function() {
|
||||
ok(Discourse.Presence.detect(Discourse.View.create()));
|
||||
test("mixes in Presence", function() {
|
||||
ok(Presence.detect(Discourse.View.create()));
|
||||
});
|
||||
|
||||
test("registerHelper: enables embedding a child view in a parent view via dedicated, named helper instead of generic 'view' helper", function() {
|
||||
|
|
Loading…
Reference in New Issue
Block a user