1
0
Fork 0
mirror of https://github.com/TryGhost/Ghost-Admin.git synced 2023-12-14 02:33:04 +01:00

Change Ember function.property() to Ember.computed

Closes #3417
This commit is contained in:
Matt Enlow 2014-07-29 19:57:19 -06:00
parent ba326f0a56
commit b05f6618aa
16 changed files with 75 additions and 73 deletions

View file

@ -31,7 +31,7 @@ var ModalDialog = Ember.Component.extend({
}
},
klass: function () {
klass: Ember.computed('type', 'style', 'animation', function () {
var classNames = [];
classNames.push(this.get('type') ? 'modal-' + this.get('type') : 'modal');
@ -45,15 +45,15 @@ var ModalDialog = Ember.Component.extend({
classNames.push(this.get('animation'));
return classNames.join(' ');
}.property('type', 'style', 'animation'),
acceptButtonClass: function () {
}),
acceptButtonClass: Ember.computed('confirm.accept.buttonClass', function () {
return this.get('confirm.accept.buttonClass') ? this.get('confirm.accept.buttonClass') : 'btn btn-green';
}.property('confirm.accept.buttonClass'),
}),
rejectButtonClass: function () {
rejectButtonClass: Ember.computed('confirm.reject.buttonClass', function () {
return this.get('confirm.reject.buttonClass') ? this.get('confirm.reject.buttonClass') : 'btn btn-red';
}.property('confirm.reject.buttonClass')
})
});
export default ModalDialog;

View file

@ -1,7 +1,7 @@
var NotificationComponent = Ember.Component.extend({
classNames: ['js-bb-notification'],
typeClass: function () {
typeClass: Ember.computed(function () {
var classes = '',
message = this.get('message'),
type,
@ -24,7 +24,7 @@ var NotificationComponent = Ember.Component.extend({
}
return classes;
}.property(),
}),
didInsertElement: function () {
var self = this;

View file

@ -1,15 +1,15 @@
var ErrorController = Ember.Controller.extend({
code: function () {
code: Ember.computed('content.status', function () {
return this.get('content.status') > 200 ? this.get('content.status') : 500;
}.property('content.status'),
message: function () {
}),
message: Ember.computed('content.statusText', function () {
if (this.get('code') === 404) {
return 'No Ghost Found';
}
return this.get('content.statusText') !== 'error' ? this.get('content.statusText') : 'Internal Server Error';
}.property('content.statusText'),
}),
stack: false
});
export default ErrorController;
export default ErrorController;

View file

@ -46,7 +46,7 @@ var PostSettingsMenuController = Ember.ObjectController.extend({
model.rollback();
});
}.observes('selectedAuthor'),
authors: function () {
authors: Ember.computed(function () {
//Loaded asynchronously, so must use promise proxies.
var deferred = {};
@ -61,20 +61,20 @@ var PostSettingsMenuController = Ember.ObjectController.extend({
return Ember.ArrayProxy
.extend(Ember.PromiseProxyMixin)
.create(deferred);
}.property(),
}),
//Changes in the PSM are too minor to warrant NProgress firing
saveOptions: {disableNProgress: true},
/**
* The placeholder is the published date of the post,
* or the current date if the pubdate has not been set.
*/
publishedAtPlaceholder: function () {
publishedAtPlaceholder: Ember.computed('publishedAtValue', function () {
var pubDate = this.get('published_at');
if (pubDate) {
return formatDate(pubDate);
}
return formatDate(moment());
}.property('publishedAtValue'),
}),
publishedAtValue: boundOneWay('published_at', formatDate),
slugValue: boundOneWay('slug'),
@ -99,7 +99,7 @@ var PostSettingsMenuController = Ember.ObjectController.extend({
Ember.run.debounce(this, 'generateSlugPlaceholder', 700);
}
},
slugPlaceholder: function (key, value) {
slugPlaceholder: Ember.computed(function (key, value) {
var slug = this.get('slug');
//If the post has a slug, that's its placeholder.
@ -114,7 +114,7 @@ var PostSettingsMenuController = Ember.ObjectController.extend({
}
//The title will stand in until the actual slug has been generated
return this.get('titleScratch');
}.property(),
}),
showErrors: function (errors) {
errors = Ember.isArray(errors) ? errors : [errors];

View file

@ -147,14 +147,14 @@ var PostTagsInputController = Ember.Controller.extend({
},
selectedSuggestion: function () {
selectedSuggestion: Ember.computed('suggestions.@each.selected', function () {
var suggestions = this.get('suggestions');
if (suggestions && suggestions.get('length')) {
return suggestions.filterBy('selected').get('firstObject');
} else {
return null;
}
}.property('suggestions.@each.selected'),
}),
updateSuggestionsList: function () {

View file

@ -28,13 +28,13 @@ var SettingsAppController = Ember.ObjectController.extend({
}
}.observes('appState').on('init'),
activeClass: function () {
activeClass: Ember.computed('appState', function () {
return this.appState === AppStates.active ? true : false;
}.property('appState'),
}),
inactiveClass: function () {
inactiveClass: Ember.computed('appState', function () {
return this.appState === AppStates.inactive ? true : false;
}.property('appState'),
}),
actions: {
toggleApp: function (app) {

View file

@ -1,5 +1,5 @@
var SettingsGeneralController = Ember.ObjectController.extend({
isDatedPermalinks: function (key, value) {
isDatedPermalinks: Ember.computed('permalinks', function (key, value) {
// setter
if (arguments.length > 1) {
this.set('permalinks', value ? '/:year/:month/:day/:slug/' : '/:slug/');
@ -9,9 +9,9 @@ var SettingsGeneralController = Ember.ObjectController.extend({
var slugForm = this.get('permalinks');
return slugForm !== '/:slug/';
}.property('permalinks'),
}),
themes: function () {
themes: Ember.computed(function () {
return this.get('availableThemes').reduce(function (themes, t) {
var theme = {};
@ -24,7 +24,7 @@ var SettingsGeneralController = Ember.ObjectController.extend({
return themes;
}, []);
}.property().readOnly(),
}).readOnly(),
actions: {
save: function () {

View file

@ -10,45 +10,45 @@ var SettingsUserController = Ember.ObjectController.extend({
lastPromise: null,
coverDefault: function () {
coverDefault: Ember.computed('ghostPaths', function () {
return this.get('ghostPaths.url').asset('/shared/img/user-cover.png');
}.property('ghostPaths'),
}),
userDefault: function () {
userDefault: Ember.computed('ghostPaths', function () {
return this.get('ghostPaths.url').asset('/shared/img/user-image.png');
}.property('ghostPaths'),
}),
cover: function () {
cover: Ember.computed('user.cover', 'coverDefault', function () {
var cover = this.get('user.cover');
if (Ember.isBlank(cover)) {
cover = this.get('coverDefault');
}
return cover;
}.property('user.cover', 'coverDefault'),
}),
coverTitle: function () {
coverTitle: Ember.computed('user.name', function () {
return this.get('user.name') + '\'s Cover Image';
}.property('user.name'),
}),
image: function () {
image: Ember.computed('imageUrl', function () {
return 'background-image: url(' + this.get('imageUrl') + ')';
}.property('imageUrl'),
}),
imageUrl: function () {
imageUrl: Ember.computed('user.image', function () {
return this.get('user.image') || this.get('userDefault');
}.property('user.image'),
}),
last_login: function () {
last_login: Ember.computed('user.last_login', function () {
var lastLogin = this.get('user.last_login');
return lastLogin ? lastLogin.fromNow() : '';
}.property('user.last_login'),
}),
created_at: function () {
created_at: Ember.computed('user.created_at', function () {
var createdAt = this.get('user.created_at');
return createdAt ? createdAt.fromNow() : '';
}.property('user.created_at'),
}),
//Lazy load the slug generator for slugPlaceholder
slugGenerator: Ember.computed(function () {

View file

@ -16,9 +16,9 @@ var AuthenticationInitializer = {
authorizer: 'simple-auth-authorizer:oauth2-bearer'
};
SimpleAuth.Session.reopen({
user: function () {
user: Ember.computed(function () {
return container.lookup('store:main').find('user', 'me');
}.property()
})
});
SimpleAuth.Authenticators.OAuth2.reopen({
serverTokenEndpoint: Ghost.apiRoot + '/authentication/token',

View file

@ -38,9 +38,9 @@ var EditorControllerMixin = Ember.Mixin.create(MarkerManager, {
// whether the number of tags has changed for `isDirty`.
previousTagNames: null,
tagNames: function () {
tagNames: Ember.computed('tags.[]', function () {
return this.get('tags').mapBy('name');
}.property('tags.[]'),
}),
// compares previousTagNames to tagNames
tagNamesEqual: function () {

View file

@ -71,7 +71,7 @@ var User = DS.Model.extend(NProgressSaveMixin, SelectiveSaveMixin, ValidationEng
});
},
passwordValidationErrors: function () {
passwordValidationErrors: Ember.computed('password', 'newPassword', 'ne2Password', function () {
var validationErrors = [];
if (!validator.equals(this.get('newPassword'), this.get('ne2Password'))) {
@ -83,16 +83,17 @@ var User = DS.Model.extend(NProgressSaveMixin, SelectiveSaveMixin, ValidationEng
}
return validationErrors;
}.property('password', 'newPassword', 'ne2Password'),
}),
isPasswordValid: Ember.computed.empty('passwordValidationErrors.[]'),
active: function () {
active: Ember.computed('status', function () {
return _.contains(['active', 'warn-1', 'warn-2', 'warn-3', 'warn-4', 'locked'], this.get('status'));
}.property('status'),
invited: function () {
}),
invited: Ember.computed('status', function () {
return _.contains(['invited', 'invited-pending'], this.get('status'));
}.property('status'),
pending: Ember.computed.equal('status', 'invited-pending').property('status')
}),
pending: Ember.computed.equal('status', 'invited-pending')
});
export default User;

View file

@ -12,9 +12,9 @@ var BoundOneWay = function (upstream, transform) {
//default to the identity function
transform = function (value) { return value; };
}
return function (key, value) {
return Ember.computed(upstream, function (key, value) {
return arguments.length > 1 ? value : transform(this.get(upstream));
}.property(upstream);
});
};
export default BoundOneWay;

View file

@ -4,21 +4,21 @@ var EditorSaveButtonView = Ember.View.extend({
classNames: ['splitbtn js-publish-splitbutton'],
//Tracks whether we're going to change the state of the post on save
isDangerous: function () {
isDangerous: Ember.computed('controller.isPublished', 'controller.willPublish', function () {
return this.get('controller.isPublished') !== this.get('controller.willPublish');
}.property('controller.isPublished', 'controller.willPublish'),
}),
'save-text': function () {
'save-text': Ember.computed('controller.willPublish', function () {
return this.get('controller.willPublish') ? this.get('publish-text') : this.get('draft-text');
}.property('controller.willPublish'),
}),
'publish-text': function () {
'publish-text': Ember.computed('controller.isPublished', function () {
return this.get('controller.isPublished') ? 'Update Post' : 'Publish Now';
}.property('controller.isPublished'),
}),
'draft-text': function () {
'draft-text': Ember.computed('controller.isPublished', function () {
return this.get('controller.isPublished') ? 'Unpublish' : 'Save Draft';
}.property('controller.isPublished')
})
});
export default EditorSaveButtonView;

View file

@ -1,9 +1,9 @@
var ItemView = Ember.View.extend({
classNameBindings: ['active'],
active: function () {
active: Ember.computed('childViews.firstObject.active', function () {
return this.get('childViews.firstObject.active');
}.property('childViews.firstObject.active')
})
});
export default ItemView;

View file

@ -3,10 +3,11 @@ import {formatDate} from 'ghost/utils/date-formatting';
var PostSettingsMenuView = Ember.View.extend({
templateName: 'post-settings-menu',
//@TODO Changeout the binding for a simple computedOneWay?
publishedAtBinding: Ember.Binding.oneWay('controller.publishedAt'),
datePlaceholder: function () {
datePlaceholder: Ember.computed('controller.publishedAt', function () {
return formatDate(moment());
}.property('controller.publishedAt')
})
});
export default PostSettingsMenuView;

View file

@ -26,7 +26,7 @@ var PostTagsInputView = Ember.View.extend({
this.get('controller').send('reset');
},
overlayStyles: function () {
overlayStyles: Ember.computed('hasFocus', 'controller.suggestions.length', function () {
var styles = [],
leftPos;
@ -40,7 +40,7 @@ var PostTagsInputView = Ember.View.extend({
}
return styles.join(';');
}.property('hasFocus', 'controller.suggestions.length'),
}),
tagInputView: Ember.TextField.extend({