mirror of
https://github.com/flarum/core.git
synced 2025-05-11 01:45:29 +02:00
Clean up, don't use mixin
PhpStorm/WebStorm doesn't like the mixin syntax, and it's clearer to just use Object.assign.
This commit is contained in:
parent
33dd5fff36
commit
e3569d39cc
@ -143,7 +143,7 @@ export default class IndexPage extends Page {
|
|||||||
*/
|
*/
|
||||||
sidebarItems() {
|
sidebarItems() {
|
||||||
const items = new ItemList();
|
const items = new ItemList();
|
||||||
const canStartDiscussion = app.forum.canStartDiscussion() || !app.session.user;
|
const canStartDiscussion = app.forum.attribute('canStartDiscussion') || !app.session.user;
|
||||||
|
|
||||||
items.add('newDiscussion',
|
items.add('newDiscussion',
|
||||||
Button.component({
|
Button.component({
|
||||||
|
@ -34,7 +34,7 @@ export default class Component {
|
|||||||
* @param {Array|Object} children
|
* @param {Array|Object} children
|
||||||
* @public
|
* @public
|
||||||
*/
|
*/
|
||||||
constructor(props = {}, children) {
|
constructor(props = {}, children = null) {
|
||||||
if (children) props.children = children;
|
if (children) props.children = children;
|
||||||
|
|
||||||
this.constructor.initProps(props);
|
this.constructor.initProps(props);
|
||||||
@ -158,6 +158,7 @@ export default class Component {
|
|||||||
*
|
*
|
||||||
* @see https://lhorie.github.io/mithril/mithril.component.html
|
* @see https://lhorie.github.io/mithril/mithril.component.html
|
||||||
* @param {Object} [props] Properties to set on the component
|
* @param {Object} [props] Properties to set on the component
|
||||||
|
* @param children
|
||||||
* @return {Object} The Mithril component object
|
* @return {Object} The Mithril component object
|
||||||
* @property {function} controller
|
* @property {function} controller
|
||||||
* @property {function} view
|
* @property {function} view
|
||||||
@ -165,7 +166,7 @@ export default class Component {
|
|||||||
* @property {Object} props The props that were passed to the component
|
* @property {Object} props The props that were passed to the component
|
||||||
* @public
|
* @public
|
||||||
*/
|
*/
|
||||||
static component(props = {}, children) {
|
static component(props = {}, children = null) {
|
||||||
const componentProps = Object.assign({}, props);
|
const componentProps = Object.assign({}, props);
|
||||||
|
|
||||||
if (children) componentProps.children = children;
|
if (children) componentProps.children = children;
|
||||||
|
@ -10,7 +10,7 @@ export default class Model {
|
|||||||
* @param {Store} store The data store that this model should be persisted to.
|
* @param {Store} store The data store that this model should be persisted to.
|
||||||
* @public
|
* @public
|
||||||
*/
|
*/
|
||||||
constructor(data = {}, store) {
|
constructor(data = {}, store = null) {
|
||||||
/**
|
/**
|
||||||
* The resource object from the API.
|
* The resource object from the API.
|
||||||
*
|
*
|
||||||
|
@ -5,7 +5,9 @@ import ItemList from 'flarum/utils/ItemList';
|
|||||||
import { slug } from 'flarum/utils/string';
|
import { slug } from 'flarum/utils/string';
|
||||||
import Badge from 'flarum/components/Badge';
|
import Badge from 'flarum/components/Badge';
|
||||||
|
|
||||||
export default class Discussion extends mixin(Model, {
|
export default class Discussion extends Model {}
|
||||||
|
|
||||||
|
Object.assign(Discussion.prototype, {
|
||||||
title: Model.attribute('title'),
|
title: Model.attribute('title'),
|
||||||
slug: computed('title', slug),
|
slug: computed('title', slug),
|
||||||
|
|
||||||
@ -35,8 +37,8 @@ export default class Discussion extends mixin(Model, {
|
|||||||
canReply: Model.attribute('canReply'),
|
canReply: Model.attribute('canReply'),
|
||||||
canRename: Model.attribute('canRename'),
|
canRename: Model.attribute('canRename'),
|
||||||
canHide: Model.attribute('canHide'),
|
canHide: Model.attribute('canHide'),
|
||||||
canDelete: Model.attribute('canDelete')
|
canDelete: Model.attribute('canDelete'),
|
||||||
}) {
|
|
||||||
/**
|
/**
|
||||||
* Remove a post from the discussion's posts relationship.
|
* Remove a post from the discussion's posts relationship.
|
||||||
*
|
*
|
||||||
@ -55,7 +57,7 @@ export default class Discussion extends mixin(Model, {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the estimated number of unread posts in this discussion for the current
|
* Get the estimated number of unread posts in this discussion for the current
|
||||||
@ -72,7 +74,7 @@ export default class Discussion extends mixin(Model, {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the Badge components that apply to this discussion.
|
* Get the Badge components that apply to this discussion.
|
||||||
@ -88,7 +90,7 @@ export default class Discussion extends mixin(Model, {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return items;
|
return items;
|
||||||
}
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a list of all of the post IDs in this discussion.
|
* Get a list of all of the post IDs in this discussion.
|
||||||
@ -99,4 +101,6 @@ export default class Discussion extends mixin(Model, {
|
|||||||
postIds() {
|
postIds() {
|
||||||
return this.data.relationships.posts.data.map(link => link.id);
|
return this.data.relationships.posts.data.map(link => link.id);
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
|
|
||||||
|
export default Discussion;
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
import Model from 'flarum/Model';
|
import Model from 'flarum/Model';
|
||||||
import mixin from 'flarum/utils/mixin';
|
import mixin from 'flarum/utils/mixin';
|
||||||
|
|
||||||
export default class Forum extends mixin(Model, {
|
export default class Forum extends Model {
|
||||||
canStartDiscussion: Model.attribute('canStartDiscussion')
|
|
||||||
}) {
|
|
||||||
apiEndpoint() {
|
apiEndpoint() {
|
||||||
return '/forum';
|
return '/forum';
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,14 @@
|
|||||||
import Model from 'flarum/Model';
|
import Model from 'flarum/Model';
|
||||||
import mixin from 'flarum/utils/mixin';
|
import mixin from 'flarum/utils/mixin';
|
||||||
|
|
||||||
class Group extends mixin(Model, {
|
class Group extends Model {}
|
||||||
|
|
||||||
|
Object.assign(Group.prototype, {
|
||||||
nameSingular: Model.attribute('nameSingular'),
|
nameSingular: Model.attribute('nameSingular'),
|
||||||
namePlural: Model.attribute('namePlural'),
|
namePlural: Model.attribute('namePlural'),
|
||||||
color: Model.attribute('color'),
|
color: Model.attribute('color'),
|
||||||
icon: Model.attribute('icon')
|
icon: Model.attribute('icon')
|
||||||
}) {}
|
});
|
||||||
|
|
||||||
Group.ADMINISTRATOR_ID = '1';
|
Group.ADMINISTRATOR_ID = '1';
|
||||||
Group.GUEST_ID = '2';
|
Group.GUEST_ID = '2';
|
||||||
|
@ -2,7 +2,9 @@ import Model from 'flarum/Model';
|
|||||||
import mixin from 'flarum/utils/mixin';
|
import mixin from 'flarum/utils/mixin';
|
||||||
import computed from 'flarum/utils/computed';
|
import computed from 'flarum/utils/computed';
|
||||||
|
|
||||||
export default class Notification extends mixin(Model, {
|
export default class Notification extends Model {}
|
||||||
|
|
||||||
|
Object.assign(Notification.prototype, {
|
||||||
contentType: Model.attribute('contentType'),
|
contentType: Model.attribute('contentType'),
|
||||||
subjectId: Model.attribute('subjectId'),
|
subjectId: Model.attribute('subjectId'),
|
||||||
content: Model.attribute('content'),
|
content: Model.attribute('content'),
|
||||||
@ -15,4 +17,6 @@ export default class Notification extends mixin(Model, {
|
|||||||
user: Model.hasOne('user'),
|
user: Model.hasOne('user'),
|
||||||
sender: Model.hasOne('sender'),
|
sender: Model.hasOne('sender'),
|
||||||
subject: Model.hasOne('subject')
|
subject: Model.hasOne('subject')
|
||||||
}) {}
|
});
|
||||||
|
|
||||||
|
export default Notification;
|
@ -3,7 +3,9 @@ import mixin from 'flarum/utils/mixin';
|
|||||||
import computed from 'flarum/utils/computed';
|
import computed from 'flarum/utils/computed';
|
||||||
import { getPlainContent } from 'flarum/utils/string';
|
import { getPlainContent } from 'flarum/utils/string';
|
||||||
|
|
||||||
export default class Post extends mixin(Model, {
|
export default class Post extends Model {}
|
||||||
|
|
||||||
|
Object.assign(Post.prototype, {
|
||||||
number: Model.attribute('number'),
|
number: Model.attribute('number'),
|
||||||
discussion: Model.hasOne('discussion'),
|
discussion: Model.hasOne('discussion'),
|
||||||
|
|
||||||
@ -24,4 +26,6 @@ export default class Post extends mixin(Model, {
|
|||||||
|
|
||||||
canEdit: Model.attribute('canEdit'),
|
canEdit: Model.attribute('canEdit'),
|
||||||
canDelete: Model.attribute('canDelete')
|
canDelete: Model.attribute('canDelete')
|
||||||
}) {}
|
});
|
||||||
|
|
||||||
|
export default Post;
|
||||||
|
@ -7,7 +7,9 @@ import ItemList from 'flarum/utils/ItemList';
|
|||||||
import computed from 'flarum/utils/computed';
|
import computed from 'flarum/utils/computed';
|
||||||
import GroupBadge from 'flarum/components/GroupBadge';
|
import GroupBadge from 'flarum/components/GroupBadge';
|
||||||
|
|
||||||
export default class User extends mixin(Model, {
|
export default class User extends Model {}
|
||||||
|
|
||||||
|
Object.assign(User.prototype, {
|
||||||
username: Model.attribute('username'),
|
username: Model.attribute('username'),
|
||||||
email: Model.attribute('email'),
|
email: Model.attribute('email'),
|
||||||
isActivated: Model.attribute('isActivated'),
|
isActivated: Model.attribute('isActivated'),
|
||||||
@ -45,8 +47,8 @@ export default class User extends mixin(Model, {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return '#' + stringToColor(username);
|
return '#' + stringToColor(username);
|
||||||
})
|
}),
|
||||||
}) {
|
|
||||||
/**
|
/**
|
||||||
* Check whether or not the user has been seen in the last 5 minutes.
|
* Check whether or not the user has been seen in the last 5 minutes.
|
||||||
*
|
*
|
||||||
@ -55,7 +57,7 @@ export default class User extends mixin(Model, {
|
|||||||
*/
|
*/
|
||||||
isOnline() {
|
isOnline() {
|
||||||
return this.lastSeenTime() > moment().subtract(5, 'minutes').toDate();
|
return this.lastSeenTime() > moment().subtract(5, 'minutes').toDate();
|
||||||
}
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the Badge components that apply to this user.
|
* Get the Badge components that apply to this user.
|
||||||
@ -73,7 +75,7 @@ export default class User extends mixin(Model, {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return items;
|
return items;
|
||||||
}
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculate the dominant color of the user's avatar. The dominant color will
|
* Calculate the dominant color of the user's avatar. The dominant color will
|
||||||
@ -92,7 +94,7 @@ export default class User extends mixin(Model, {
|
|||||||
m.redraw();
|
m.redraw();
|
||||||
};
|
};
|
||||||
image.src = this.avatarUrl();
|
image.src = this.avatarUrl();
|
||||||
}
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the user's preferences.
|
* Update the user's preferences.
|
||||||
@ -107,4 +109,6 @@ export default class User extends mixin(Model, {
|
|||||||
|
|
||||||
return this.save({preferences});
|
return this.save({preferences});
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
|
|
||||||
|
export default User;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user