mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-15 03:12:54 +03:00
5abeadf80d
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
34 lines
1.1 KiB
JavaScript
34 lines
1.1 KiB
JavaScript
export default {
|
|
name: 'currentUser',
|
|
after: 'store',
|
|
|
|
initialize: function (container, application) {
|
|
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 });
|
|
|
|
// Inject into the routes and controllers as the user property.
|
|
container.injection('route', 'user', 'user:current');
|
|
container.injection('controller', 'user', 'user:current');
|
|
|
|
application.advanceReadiness();
|
|
});
|
|
}
|
|
}; |