mirror of
https://github.com/flarum/framework.git
synced 2025-05-22 14:49:57 +08:00
Replace Ember app with Mithril app
This commit is contained in:
14
js/lib/models/activity.js
Normal file
14
js/lib/models/activity.js
Normal file
@ -0,0 +1,14 @@
|
||||
import Model from 'flarum/model';
|
||||
|
||||
class Activity extends Model {}
|
||||
|
||||
Activity.prototype.id = Model.prop('id');
|
||||
Activity.prototype.contentType = Model.prop('contentType');
|
||||
Activity.prototype.content = Model.prop('content');
|
||||
Activity.prototype.time = Model.prop('time', Model.date);
|
||||
|
||||
Activity.prototype.user = Model.one('user');
|
||||
Activity.prototype.sender = Model.one('sender');
|
||||
Activity.prototype.post = Model.one('post');
|
||||
|
||||
export default Activity;
|
45
js/lib/models/discussion.js
Normal file
45
js/lib/models/discussion.js
Normal file
@ -0,0 +1,45 @@
|
||||
import Model from 'flarum/model';
|
||||
import computed from 'flarum/utils/computed';
|
||||
import ItemList from 'flarum/utils/item-list';
|
||||
|
||||
class Discussion extends Model {}
|
||||
|
||||
Discussion.prototype.id = Model.prop('id');
|
||||
Discussion.prototype.title = Model.prop('title');
|
||||
Discussion.prototype.slug = computed('title', title => title.toLowerCase().replace(/[^a-z0-9]/gi, '-').replace(/-+/g, '-').replace(/-$|^-/g, ''));
|
||||
|
||||
Discussion.prototype.startTime = Model.prop('startTime', Model.date);
|
||||
Discussion.prototype.startUser = Model.one('startUser');
|
||||
Discussion.prototype.startPost = Model.one('startPost');
|
||||
|
||||
Discussion.prototype.lastTime = Model.prop('lastTime', Model.date);
|
||||
Discussion.prototype.lastUser = Model.one('lastUser');
|
||||
Discussion.prototype.lastPost = Model.one('lastPost');
|
||||
Discussion.prototype.lastPostNumber = Model.prop('lastPostNumber');
|
||||
|
||||
Discussion.prototype.canReply = Model.prop('canReply');
|
||||
Discussion.prototype.canEdit = Model.prop('canEdit');
|
||||
Discussion.prototype.canDelete = Model.prop('canDelete');
|
||||
|
||||
Discussion.prototype.commentsCount = Model.prop('commentsCount');
|
||||
Discussion.prototype.repliesCount = computed('commentsCount', commentsCount => commentsCount - 1);
|
||||
|
||||
Discussion.prototype.posts = Model.many('posts');
|
||||
Discussion.prototype.relevantPosts = Model.many('relevantPosts');
|
||||
Discussion.prototype.addedPosts = Model.many('addedPosts');
|
||||
|
||||
Discussion.prototype.readTime = Model.prop('readTime', Model.date);
|
||||
Discussion.prototype.readNumber = Model.prop('readNumber');
|
||||
|
||||
Discussion.prototype.unreadCount = function() {
|
||||
var user = app.session.user();
|
||||
if (user && user.readTime() < this.lastTime()) {
|
||||
return Math.max(0, this.lastPostNumber() - (this.readNumber() || 0))
|
||||
}
|
||||
return 0
|
||||
};
|
||||
Discussion.prototype.isUnread = computed('unreadCount', unreadCount => !!unreadCount);
|
||||
|
||||
Discussion.prototype.badges = () => new ItemList();
|
||||
|
||||
export default Discussion;
|
8
js/lib/models/group.js
Normal file
8
js/lib/models/group.js
Normal file
@ -0,0 +1,8 @@
|
||||
import Model from 'flarum/model';
|
||||
|
||||
class Group extends Model {}
|
||||
|
||||
Group.prototype.id = Model.prop('id');
|
||||
Group.prototype.name = Model.prop('name');
|
||||
|
||||
export default Group;
|
19
js/lib/models/notification.js
Normal file
19
js/lib/models/notification.js
Normal file
@ -0,0 +1,19 @@
|
||||
import Model from 'flarum/model';
|
||||
import computed from 'flarum/utils/computed';
|
||||
|
||||
class Notification extends Model {}
|
||||
|
||||
Notification.prototype.id = Model.prop('id');
|
||||
Notification.prototype.contentType = Model.prop('contentType');
|
||||
Notification.prototype.subjectId = Model.prop('subjectId');
|
||||
Notification.prototype.content = Model.prop('content');
|
||||
Notification.prototype.time = Model.prop('time', Model.date);
|
||||
Notification.prototype.isRead = Model.prop('isRead');
|
||||
Notification.prototype.unreadCount = Model.prop('unreadCount');
|
||||
Notification.prototype.additionalUnreadCount = computed('unreadCount', unreadCount => Math.max(0, unreadCount - 1));
|
||||
|
||||
Notification.prototype.user = Model.one('user');
|
||||
Notification.prototype.sender = Model.one('sender');
|
||||
Notification.prototype.subject = Model.one('subject');
|
||||
|
||||
export default Notification;
|
27
js/lib/models/post.js
Normal file
27
js/lib/models/post.js
Normal file
@ -0,0 +1,27 @@
|
||||
import Model from 'flarum/model';
|
||||
import computed from 'flarum/utils/computed';
|
||||
|
||||
class Post extends Model {}
|
||||
|
||||
Post.prototype.id = Model.prop('id');
|
||||
Post.prototype.number = Model.prop('number');
|
||||
Post.prototype.discussion = Model.one('discussion');
|
||||
|
||||
Post.prototype.time = Model.prop('time');
|
||||
Post.prototype.user = Model.one('user');
|
||||
Post.prototype.contentType = Model.prop('contentType');
|
||||
Post.prototype.content = Model.prop('content');
|
||||
Post.prototype.contentHtml = Model.prop('contentHtml');
|
||||
|
||||
Post.prototype.editTime = Model.prop('editTime', Model.date);
|
||||
Post.prototype.editUser = Model.one('editUser');
|
||||
Post.prototype.isEdited = computed('editTime', editTime => !!editTime);
|
||||
|
||||
Post.prototype.hideTime = Model.prop('hideTime', Model.date);
|
||||
Post.prototype.hideUser = Model.one('hideUser');
|
||||
Post.prototype.isHidden = computed('hideTime', hideTime => !!hideTime);
|
||||
|
||||
Post.prototype.canEdit = Model.prop('canEdit');
|
||||
Post.prototype.canDelete = Model.prop('canDelete');
|
||||
|
||||
export default Post;
|
53
js/lib/models/user.js
Normal file
53
js/lib/models/user.js
Normal file
@ -0,0 +1,53 @@
|
||||
import Model from 'flarum/model'
|
||||
import stringToColor from 'flarum/utils/string-to-color';
|
||||
import ItemList from 'flarum/utils/item-list';
|
||||
import computed from 'flarum/utils/computed';
|
||||
|
||||
class User extends Model {}
|
||||
|
||||
User.prototype.id = Model.prop('id');
|
||||
User.prototype.username = Model.prop('username');
|
||||
User.prototype.email = Model.prop('email');
|
||||
User.prototype.isConfirmed = Model.prop('isConfirmed');
|
||||
User.prototype.password = Model.prop('password');
|
||||
User.prototype.avatarUrl = Model.prop('avatarUrl');
|
||||
User.prototype.bio = Model.prop('bio');
|
||||
User.prototype.bioHtml = Model.prop('bioHtml');
|
||||
User.prototype.preferences = Model.prop('preferences');
|
||||
|
||||
User.prototype.groups = Model.many('groups');
|
||||
|
||||
User.prototype.joinTime = Model.prop('joinTime', Model.date);
|
||||
User.prototype.lastSeenTime = Model.prop('lastSeenTime', Model.date);
|
||||
User.prototype.online = function() { return this.lastSeenTime() > moment().subtract(5, 'minutes').toDate(); };
|
||||
User.prototype.readTime = Model.prop('readTime', Model.date);
|
||||
User.prototype.unreadNotificationsCount = Model.prop('unreadNotificationsCount');
|
||||
|
||||
User.prototype.discussionsCount = Model.prop('discussionsCount');
|
||||
User.prototype.commentsCount = Model.prop('commentsCount');
|
||||
;
|
||||
User.prototype.canEdit = Model.prop('canEdit');
|
||||
User.prototype.canDelete = Model.prop('canDelete');
|
||||
|
||||
User.prototype.color = computed('username', 'avatarUrl', 'avatarColor', function(username, avatarUrl, avatarColor) {
|
||||
if (avatarColor) {
|
||||
return 'rgb('+avatarColor[0]+', '+avatarColor[1]+', '+avatarColor[2]+')';
|
||||
} else if (avatarUrl) {
|
||||
var image = new Image();
|
||||
var user = this;
|
||||
image.onload = function() {
|
||||
var colorThief = new ColorThief();
|
||||
user.avatarColor = colorThief.getColor(this);
|
||||
user.freshness = new Date();
|
||||
m.redraw();
|
||||
};
|
||||
image.src = avatarUrl;
|
||||
return '';
|
||||
} else {
|
||||
return '#'+stringToColor(username);
|
||||
}
|
||||
});
|
||||
|
||||
User.prototype.badges = () => new ItemList();
|
||||
|
||||
export default User;
|
Reference in New Issue
Block a user