mirror of
https://github.com/flarum/core.git
synced 2025-07-22 17:21:27 +02:00
Initial refactor of client actions, data preloading, SEO
An initial stab at flarum/core#126. Still WIP. Preliminary implementation of flarum/core#128 and flarum/core#13.
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
export default function(app) {
|
||||
if (app.preload.data) {
|
||||
app.store.pushPayload({data: app.preload.data});
|
||||
}
|
||||
app.store.pushPayload({data: app.preload.data});
|
||||
app.forum = app.store.getById('forums', 1);
|
||||
|
||||
if (app.preload.session) {
|
||||
app.session.token(app.preload.session.token);
|
||||
app.session.user(app.store.getById('users', app.preload.session.userId));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@@ -1,4 +1,5 @@
|
||||
import Store from 'flarum/store';
|
||||
import Forum from 'flarum/models/forum';
|
||||
import User from 'flarum/models/user';
|
||||
import Discussion from 'flarum/models/discussion';
|
||||
import Post from 'flarum/models/post';
|
||||
@@ -9,10 +10,13 @@ import Notification from 'flarum/models/notification';
|
||||
export default function(app) {
|
||||
app.store = new Store();
|
||||
|
||||
app.store.models['users'] = User;
|
||||
app.store.models['discussions'] = Discussion;
|
||||
app.store.models['posts'] = Post;
|
||||
app.store.models['groups'] = Group;
|
||||
app.store.models['activity'] = Activity;
|
||||
app.store.models['notifications'] = Notification;
|
||||
};
|
||||
app.store.models = {
|
||||
forums: Forum,
|
||||
users: User,
|
||||
discussions: Discussion,
|
||||
posts: Post,
|
||||
groups: Group,
|
||||
activity: Activity,
|
||||
notifications: Notification
|
||||
};
|
||||
}
|
||||
|
@@ -10,6 +10,10 @@ export default class Model {
|
||||
return this.data().id;
|
||||
}
|
||||
|
||||
attribute(attribute) {
|
||||
return this.data().attributes[attribute];
|
||||
}
|
||||
|
||||
pushData(newData) {
|
||||
var data = this.data();
|
||||
|
||||
@@ -90,7 +94,7 @@ export default class Model {
|
||||
|
||||
return app.request({
|
||||
method: this.exists ? 'PATCH' : 'POST',
|
||||
url: app.config['api_url']+'/'+this.data().type+(this.exists ? '/'+this.data().id : ''),
|
||||
url: app.forum.attribute('apiUrl')+'/'+this.data().type+(this.exists ? '/'+this.data().id : ''),
|
||||
data: {data},
|
||||
background: true,
|
||||
config: app.session.authorize.bind(app.session)
|
||||
@@ -108,7 +112,7 @@ export default class Model {
|
||||
|
||||
return app.request({
|
||||
method: 'DELETE',
|
||||
url: app.config['api_url']+'/'+this.data().type+'/'+this.data().id,
|
||||
url: app.forum.attribute('apiUrl')+'/'+this.data().type+'/'+this.data().id,
|
||||
background: true,
|
||||
config: app.session.authorize.bind(app.session)
|
||||
}).then(() => this.exists = false);
|
||||
|
5
framework/core/js/lib/models/forum.js
Normal file
5
framework/core/js/lib/models/forum.js
Normal file
@@ -0,0 +1,5 @@
|
||||
import Model from 'flarum/model';
|
||||
|
||||
class Forum extends Model {}
|
||||
|
||||
export default Forum;
|
@@ -13,7 +13,7 @@ export default class Session extends mixin(class {}, evented) {
|
||||
var self = this;
|
||||
m.request({
|
||||
method: 'POST',
|
||||
url: app.config['base_url']+'/login',
|
||||
url: app.forum.attribute('baseUrl')+'/login',
|
||||
data: {identification, password},
|
||||
background: true
|
||||
}).then(function(response) {
|
||||
@@ -32,7 +32,7 @@ export default class Session extends mixin(class {}, evented) {
|
||||
}
|
||||
|
||||
logout() {
|
||||
window.location = app.config['base_url']+'/logout';
|
||||
window.location = app.forum.attribute('baseUrl')+'/logout?token='+this.token();
|
||||
}
|
||||
|
||||
authorize(xhr) {
|
||||
|
@@ -38,7 +38,7 @@ export default class Store {
|
||||
}
|
||||
return app.request({
|
||||
method: 'GET',
|
||||
url: app.config['api_url']+'/'+endpoint,
|
||||
url: app.forum.attribute('apiUrl')+'/'+endpoint,
|
||||
data: params,
|
||||
background: true,
|
||||
config: app.session.authorize.bind(app.session)
|
||||
|
@@ -15,8 +15,17 @@ class App {
|
||||
this.initializers.toArray().forEach((initializer) => initializer(this));
|
||||
}
|
||||
|
||||
preloadedDocument() {
|
||||
if (app.preload.document) {
|
||||
const results = app.store.pushPayload(app.preload.document);
|
||||
app.preload.document = null;
|
||||
|
||||
return results;
|
||||
}
|
||||
}
|
||||
|
||||
setTitle(title) {
|
||||
document.title = (title ? title+' - ' : '')+this.config['forum_title'];
|
||||
document.title = (title ? title+' - ' : '')+this.forum.attribute('title');
|
||||
}
|
||||
|
||||
request(options) {
|
||||
|
Reference in New Issue
Block a user