2014-12-20 14:26:46 +08:00
|
|
|
import Ember from 'ember';
|
|
|
|
import DS from 'ember-data';
|
|
|
|
|
|
|
|
var Discussion = DS.Model.extend({
|
|
|
|
|
|
|
|
title: DS.attr('string'),
|
|
|
|
|
|
|
|
slug: function() {
|
|
|
|
return this.get('title').toLowerCase().replace(/[^a-z0-9]/gi, '-').replace(/-+/g, '-');
|
|
|
|
}.property('title'),
|
|
|
|
|
|
|
|
canReply: DS.attr('boolean'),
|
|
|
|
canEdit: DS.attr('boolean'),
|
|
|
|
canDelete: DS.attr('boolean'),
|
|
|
|
|
|
|
|
startTime: DS.attr('date'),
|
|
|
|
startUser: DS.belongsTo('user'),
|
|
|
|
startPost: DS.belongsTo('post'),
|
|
|
|
|
|
|
|
lastTime: DS.attr('date'),
|
|
|
|
lastUser: DS.belongsTo('user'),
|
|
|
|
lastPost: DS.belongsTo('post'),
|
|
|
|
lastPostNumber: DS.attr('number'),
|
|
|
|
|
|
|
|
relevantPosts: DS.hasMany('post'),
|
|
|
|
|
2015-01-16 14:40:54 +08:00
|
|
|
commentsCount: DS.attr('number'),
|
2014-12-20 14:26:46 +08:00
|
|
|
repliesCount: function() {
|
2015-01-16 14:40:54 +08:00
|
|
|
return Math.max(0, this.get('commentsCount') - 1);
|
|
|
|
}.property('commentsCount'),
|
2014-12-20 14:26:46 +08:00
|
|
|
|
|
|
|
posts: DS.attr('string'),
|
|
|
|
postIds: function() {
|
|
|
|
return this.get('posts').split(',');
|
|
|
|
}.property('posts'),
|
|
|
|
|
2015-01-07 14:52:34 +08:00
|
|
|
readTime: DS.attr('date'),
|
2014-12-20 14:26:46 +08:00
|
|
|
readNumber: DS.attr('number'),
|
|
|
|
unreadCount: function() {
|
|
|
|
return this.get('lastPostNumber') - this.get('readNumber');
|
|
|
|
}.property('lastPostNumber', 'readNumber'),
|
2015-01-07 14:52:34 +08:00
|
|
|
isUnread: Ember.computed.bool('unreadCount')
|
2014-12-20 14:26:46 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
export default Discussion;
|