mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-24 23:48:13 -05:00
New posts pass PostsController sorting function at the top
- PostsController orderBy function sorts posts with isNew to the top, otherwise their undefined dates fail to compare - also catch when `updated_at` is undefined, happens when model is being written with results from the server - catch objects of type Error in validation engine, helps catching client errors - join server errors with BR tag in ajax util - add `emberBuild` task to `grunt test-functional` - add a test helper, `thenTransitionAndWaitForScreenLoad`, to test transitioning to major parts of the app - add a test that transitions from Content to the Editor, and back to Content
This commit is contained in:
parent
47eb354a7b
commit
9f9749d123
3 changed files with 23 additions and 5 deletions
|
@ -15,7 +15,6 @@ var PostsController = Ember.ArrayController.extend({
|
|||
// published_at: DESC
|
||||
// updated_at: DESC
|
||||
orderBy: function (item1, item2) {
|
||||
|
||||
function publishedAtCompare() {
|
||||
var published1 = item1.get('published_at'),
|
||||
published2 = item2.get('published_at');
|
||||
|
@ -35,9 +34,25 @@ var PostsController = Ember.ArrayController.extend({
|
|||
return Ember.compare(item1.get('published_at').valueOf(), item2.get('published_at').valueOf());
|
||||
}
|
||||
|
||||
var statusResult = Ember.compare(item1.get('status'), item2.get('status')),
|
||||
updatedAtResult = Ember.compare(item1.get('updated_at').valueOf(), item2.get('updated_at').valueOf()),
|
||||
publishedAtResult = publishedAtCompare();
|
||||
var updated1 = item1.get('updated_at'),
|
||||
updated2 = item2.get('updated_at'),
|
||||
statusResult,
|
||||
updatedAtResult,
|
||||
publishedAtResult;
|
||||
|
||||
// when `updated_at` is undefined, the model is still
|
||||
// being written to with the results from the server
|
||||
if (item1.get('isNew') || !updated1) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (item2.get('isNew') || !updated2) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
statusResult = Ember.compare(item1.get('status'), item2.get('status'));
|
||||
updatedAtResult = Ember.compare(updated1.valueOf(), updated2.valueOf());
|
||||
publishedAtResult = publishedAtCompare();
|
||||
|
||||
if (statusResult === 0) {
|
||||
if (publishedAtResult === 0) {
|
||||
|
|
|
@ -54,6 +54,9 @@ var ValidationEngine = Ember.Mixin.create({
|
|||
if (Ember.isArray(errors)) {
|
||||
// get validation error messages
|
||||
message = errors.mapBy('message').join('<br />');
|
||||
} else if (errors instanceof Error) {
|
||||
// we got some kind of error in Ember
|
||||
message += ': ' + errors.message;
|
||||
} else if (typeof errors === 'object') {
|
||||
// Get messages from server response
|
||||
message += ': ' + getRequestErrorMessage(errors);
|
||||
|
|
|
@ -26,7 +26,7 @@ var getRequestErrorMessage = function (request) {
|
|||
|
||||
message = request.responseJSON.errors.map(function (errorItem) {
|
||||
return errorItem.message;
|
||||
}).join('; ');
|
||||
}).join('<br />');
|
||||
} else {
|
||||
message = request.responseJSON.error || 'Unknown Error';
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue