Skip to content

Commit d84f6f9

Browse files
committed
helper: move virtal method to helper
1 parent 31e48c5 commit d84f6f9

File tree

3 files changed

+4
-17
lines changed

3 files changed

+4
-17
lines changed

app/model/topic.js

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ module.exports = app => {
44
const mongoose = app.mongoose;
55
const Schema = mongoose.Schema;
66
const ObjectId = Schema.ObjectId;
7-
const config = app.config;
87

98
const TopicSchema = new Schema({
109
title: { type: String },
@@ -29,17 +28,5 @@ module.exports = app => {
2928
TopicSchema.index({ top: -1, last_reply_at: -1 });
3029
TopicSchema.index({ author_id: 1, create_at: -1 });
3130

32-
TopicSchema.virtual('tabName').get(function() {
33-
const tab = this.tab;
34-
const pair = config.tabs.find(function(_pair) {
35-
return _pair[0] === tab;
36-
});
37-
38-
if (pair) {
39-
return pair[1];
40-
}
41-
return '';
42-
});
43-
4431
return mongoose.model('Topic', TopicSchema);
4532
};

app/view/topic/_top_good.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
<span class='put_top'>置顶</span>
33
<% } else if (topic.good) { %>
44
<span class='put_good'>精华</span>
5-
<% } else if (typeof tab !== 'undefined' && tab === 'all' && topic.tabName) { %>
6-
<span class="topiclist-tab"><%= topic.tabName %></span>
5+
<% } else if (typeof tab !== 'undefined' && tab === 'all' && helper.tabName(topic.tab)) { %>
6+
<span class="topiclist-tab"><%= helper.tabName(topic.tab) %></span>
77
<% } %>

app/view/topic/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,13 @@
6262
<span>
6363
<%= topic.visit_count %> 次浏览
6464
</span>
65-
<% if (topic.create_at != topic.update_at) { %>
65+
<% if (topic.create_at.toString() !== topic.update_at.toString()) { %>
6666
<span>
6767
最后一次编辑是 <%= helper.ago(topic.update_at) %>
6868
</span>
6969
<% } %>
7070
<% if (topic.tab) { %>
71-
<span> 来自 <%= topic.tabName %></span>
71+
<span> 来自 <%= helper.tabName(topic.tab) %></span>
7272
<%}%>
7373

7474
<% if (current_user) { %>

0 commit comments

Comments
 (0)