From 9f9749d12377de9550c5853051e84e1064cb34df Mon Sep 17 00:00:00 2001 From: David Arvelo Date: Fri, 27 Jun 2014 23:50:31 -0400 Subject: [PATCH] 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 --- ghost/admin/controllers/posts.js | 23 +++++++++++++++++++---- ghost/admin/mixins/validation-engine.js | 3 +++ ghost/admin/utils/ajax.js | 2 +- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/ghost/admin/controllers/posts.js b/ghost/admin/controllers/posts.js index 9387ab0155..83c0b264de 100644 --- a/ghost/admin/controllers/posts.js +++ b/ghost/admin/controllers/posts.js @@ -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) { diff --git a/ghost/admin/mixins/validation-engine.js b/ghost/admin/mixins/validation-engine.js index e1fbad7c78..534754801d 100644 --- a/ghost/admin/mixins/validation-engine.js +++ b/ghost/admin/mixins/validation-engine.js @@ -54,6 +54,9 @@ var ValidationEngine = Ember.Mixin.create({ if (Ember.isArray(errors)) { // get validation error messages message = errors.mapBy('message').join('
'); + } 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); diff --git a/ghost/admin/utils/ajax.js b/ghost/admin/utils/ajax.js index 12ebc8f2b2..b67e181603 100644 --- a/ghost/admin/utils/ajax.js +++ b/ghost/admin/utils/ajax.js @@ -26,7 +26,7 @@ var getRequestErrorMessage = function (request) { message = request.responseJSON.errors.map(function (errorItem) { return errorItem.message; - }).join('; '); + }).join('
'); } else { message = request.responseJSON.error || 'Unknown Error'; }