Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ref #2699 - Introduce ember data dependency - Add loadInitializers and refactor most initializers into one combined - Add Post ember data model - Refactor generateSlug to use title of post and ghostPaths - Refactor post controller to not reference model.property everywhere - Use RESTAdapter for posts, users and tags - Setup author and tag relations in Post model - Fix broken API calls by adding CSRF header - Add initiaizer for csrf value - Use actual User model for current user initializer - Add action for setting featured post, test with actual api call - Fix the sending of UUID's up to the server - Refactor current-user to use ember-data store - If a user is preloaded in the application, use pushPayload to put it in the store - Do a lookup on the store to get an actual User model for injection - Fix posts/post controllerName in route/new.js - Alter signup process to push user into ember data store
- Loading branch information
Showing
25 changed files
with
258 additions
and
207 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import ghostPaths from 'ghost/utils/ghost-paths'; | ||
|
||
// export default DS.FixtureAdapter.extend({}); | ||
|
||
export default DS.RESTAdapter.extend({ | ||
host: window.location.origin, | ||
namespace: ghostPaths().apiRoot.slice(1), | ||
headers: { | ||
'X-CSRF-Token': $('meta[name="csrf-param"]').attr('content') | ||
}, | ||
|
||
buildURL: function (type, id) { | ||
// Ensure trailing slashes | ||
var url = this._super(type, id); | ||
|
||
if (url.slice(-1) !== '/') { | ||
url += '/'; | ||
} | ||
|
||
return url; | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export default { | ||
name: 'csrf-token', | ||
|
||
initialize: function (container) { | ||
container.register('csrf:token', $('meta[name="csrf-param"]').attr('content'), { instantiate: false }); | ||
|
||
container.injection('route', 'csrf', 'csrf:token'); | ||
container.injection('model', 'csrf', 'csrf:token'); | ||
container.injection('controller', 'csrf', 'csrf:token'); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,34 @@ | ||
import User from 'ghost/models/user'; | ||
|
||
export default { | ||
name: 'currentUser', | ||
after: 'store', | ||
|
||
initialize: function (container, application) { | ||
var user = User.create(application.get('user') || {}); | ||
var store = container.lookup('store:main'), | ||
preloadedUser = application.get('user'); | ||
|
||
// If we don't have a user, don't do the injection | ||
if (!preloadedUser) { | ||
return; | ||
} | ||
|
||
// Push the preloaded user into the data store | ||
store.pushPayload({ | ||
users: [preloadedUser] | ||
}); | ||
|
||
// Signal to wait until the user is loaded before continuing. | ||
application.deferReadiness(); | ||
|
||
// Find the user (which should be fast since we just preloaded it in the store) | ||
store.find('user', preloadedUser.id).then(function (user) { | ||
// Register the value for injection | ||
container.register('user:current', user, { instantiate: false }); | ||
|
||
container.register('user:current', user, { instantiate: false }); | ||
// Inject into the routes and controllers as the user property. | ||
container.injection('route', 'user', 'user:current'); | ||
container.injection('controller', 'user', 'user:current'); | ||
|
||
container.injection('route', 'user', 'user:current'); | ||
container.injection('controller', 'user', 'user:current'); | ||
application.advanceReadiness(); | ||
}); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,13 @@ | ||
import Notifications from 'ghost/utils/notifications'; | ||
|
||
var registerNotifications = { | ||
name: 'registerNotifications', | ||
export default { | ||
name: 'injectNotifications', | ||
|
||
initialize: function (container, application) { | ||
application.register('notifications:main', Notifications); | ||
} | ||
}; | ||
|
||
var injectNotifications = { | ||
name: 'injectNotifications', | ||
|
||
initialize: function (container, application) { | ||
application.inject('controller', 'notifications', 'notifications:main'); | ||
application.inject('component', 'notifications', 'notifications:main'); | ||
application.inject('route', 'notifications', 'notifications:main'); | ||
} | ||
}; | ||
|
||
export {registerNotifications, injectNotifications}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,45 @@ | ||
import BaseModel from 'ghost/models/base'; | ||
|
||
var PostModel = BaseModel.extend({ | ||
url: BaseModel.apiRoot + '/posts/', | ||
var Post = DS.Model.extend({ | ||
uuid: DS.attr('string'), | ||
title: DS.attr('string'), | ||
slug: DS.attr('string'), | ||
markdown: DS.attr('string'), | ||
html: DS.attr('string'), | ||
image: DS.attr('string'), | ||
featured: DS.attr('boolean'), | ||
page: DS.attr('boolean'), | ||
status: DS.attr('string'), | ||
language: DS.attr('string'), | ||
meta_title: DS.attr('string'), | ||
meta_description: DS.attr('string'), | ||
author: DS.belongsTo('user', { async: true }), | ||
created_at: DS.attr('date'), | ||
created_by: DS.belongsTo('user', { async: true }), | ||
updated_at: DS.attr('date'), | ||
updated_by: DS.belongsTo('user', { async: true }), | ||
published_at: DS.attr('date'), | ||
published_by: DS.belongsTo('user', { async: true }), | ||
tags: DS.hasMany('tag', { async: true }), | ||
|
||
generateSlug: function () { | ||
// @TODO Make this request use this.get('title') once we're an actual user | ||
var url = this.get('url') + 'slug/' + encodeURIComponent('test title') + '/'; | ||
return ic.ajax.request(url, { | ||
type: 'GET' | ||
}); | ||
}, | ||
|
||
save: function (properties) { | ||
var url = this.url, | ||
self = this, | ||
type, | ||
validationErrors = this.validate(); | ||
|
||
if (validationErrors.length) { | ||
return Ember.RSVP.Promise(function (resolve, reject) { | ||
return reject(validationErrors); | ||
}); | ||
} | ||
|
||
//If specific properties are being saved, | ||
//this is an edit. Otherwise, it's an add. | ||
if (properties && properties.length > 0) { | ||
type = 'PUT'; | ||
url += this.get('id'); | ||
} else { | ||
type = 'POST'; | ||
properties = Ember.keys(this); | ||
} | ||
var title = this.get('title'), | ||
url = this.get('ghostPaths').apiUrl('posts', 'slug', encodeURIComponent(title)); | ||
|
||
return ic.ajax.request(url, { | ||
type: type, | ||
data: this.getProperties(properties) | ||
}).then(function (model) { | ||
return self.setProperties(model); | ||
}); | ||
type: 'GET' | ||
}); | ||
}, | ||
validate: function () { | ||
|
||
validationErrors: function () { | ||
var validationErrors = []; | ||
|
||
if (!(this.get('title') && this.get('title').length)) { | ||
if (!this.get('title.length')) { | ||
validationErrors.push({ | ||
message: "You must specify a title for the post." | ||
}); | ||
} | ||
|
||
return validationErrors; | ||
} | ||
}.property('title') | ||
}); | ||
|
||
export default PostModel; | ||
export default Post; |
Oops, something went wrong.