-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathactivitytabview.js
229 lines (199 loc) · 6.01 KB
/
activitytabview.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
/*
* Copyright (c) 2015
*
* This file is licensed under the Affero General Public License version 3
* or later.
*
* See the COPYING-README file.
*
*/
(function() {
var TEMPLATE =
'<div class="activity-section">' +
'<div class="loading hidden" style="height: 50px"></div>' +
'<ul class="activities hidden">' +
' <li class="empty">{{emptyMessage}}</li>' +
'</ul>' +
'<input type="button" class="showMore" value="{{moreLabel}}"' +
'</div>';
var ACTIVITY_TEMPLATE =
' <li class="activity box">' +
' <div class="activity-icon {{typeIconClass}}"></div>' +
' <div class="activitysubject">{{{subject}}}</div>' +
' <span class="activitytime has-tooltip" title="{{formattedDateTooltip}}">{{formattedDate}}</span>' +
' <div class="activitymessage">{{{message}}}</div>' +
' {{#if previews}}' +
' <div class="previews">' +
' {{#each previews}}' +
' <img class="preview {{previewClass}}" src="{{source}}" alt="" />' +
' {{/each}}' +
' </div>' +
' {{/if}}' +
' </li>';
/**
* @class OCA.Activity.ActivityTabView
* @classdesc
*
* Displays activity information for a given file
*
*/
var ActivityTabView = OCA.Files.DetailTabView.extend(/** @lends OCA.Activity.ActivityTabView.prototype */ {
id: 'activityTabView',
className: 'activityTabView tab',
events: {
'click .showMore': '_onClickShowMore'
},
_loading: false,
_plugins: [],
initialize: function() {
this.collection = new OCA.Activity.ActivityCollection();
this.collection.setObjectType('files');
this.collection.on('request', this._onRequest, this);
this.collection.on('sync', this._onEndRequest, this);
this.collection.on('error', this._onError, this);
this.collection.on('add', this._onAddModel, this);
this._plugins = OC.Plugins.getPlugins('OCA.Activity.RenderingPlugins');
_.each(this._plugins, function(plugin) {
if (_.isFunction(plugin.initialize)) {
plugin.initialize();
}
});
},
template: function(data) {
if (!this._template) {
this._template = Handlebars.compile(TEMPLATE);
}
return this._template(data);
},
get$: function() {
return this.$el;
},
getLabel: function() {
return t('activity', 'Activities');
},
setFileInfo: function(fileInfo) {
this._fileInfo = fileInfo;
if (this._fileInfo) {
this.collection.setObjectId(this._fileInfo.get('id'));
this.collection.reset();
this.collection.fetch();
_.each(this._plugins, function(plugin) {
if (_.isFunction(plugin.setFileInfo)) {
plugin.setFileInfo('files', fileInfo.get('id'));
}
});
} else {
this.collection.reset();
_.each(this._plugins, function(plugin) {
if (_.isFunction(plugin.resetFileInfo)) {
plugin.resetFileInfo();
}
});
}
},
_onError: function() {
OC.Notification.showTemporary(t('activity', 'Error loading activities'));
},
_onRequest: function() {
if (this.collection.lastGivenId === 0) {
this.render();
}
this.$el.find('.showMore').addClass('hidden');
},
_onEndRequest: function() {
this.$container.removeClass('hidden');
this.$el.find('.loading').addClass('hidden');
if (this.collection.length) {
this.$container.find('li.empty').addClass('hidden');
}
if (this.collection.hasMore) {
this.$el.find('.showMore').removeClass('hidden');
}
},
_onClickShowMore: function() {
this.collection.fetch({
reset: false
});
},
/**
* Format an activity model for display
*
* @param {OCA.Activity.ActivityModel} activity
* @return {Object}
*/
_formatItem: function(activity) {
var displayFullPath = activity.get('type') === 'file_moved';
var output = {
subject: OCA.Activity.Formatter.parseMessage(activity.get('subject_prepared'), false, displayFullPath),
formattedDate: activity.getRelativeDate(),
formattedDateTooltip: activity.getFullDate(),
message: OCA.Activity.Formatter.parseMessage(activity.get('message_prepared'), false)
};
if (activity.has('typeicon')) {
output.typeIconClass = activity.get('typeicon') + ' svg';
}
/**
* Disable previews in the rightside bar,
* it's always the same image anyway.
if (activity.has('previews')) {
output.previews = _.map(activity.get('previews'), function(data) {
return {
previewClass: data.isMimeTypeIcon ? 'preview-mimetype-icon': '',
source: data.source
};
});
}
*/
return output;
},
activityTemplate: function(params) {
if (!this._activityTemplate) {
this._activityTemplate = Handlebars.compile(ACTIVITY_TEMPLATE);
}
return this._activityTemplate(params);
},
_onAddModel: function(model, collection, options) {
var $el = $(this.activityTemplate(this._formatItem(model)));
_.each(this._plugins, function(plugin) {
if (_.isFunction(plugin.prepareModelForDisplay)) {
plugin.prepareModelForDisplay(model, $el, 'ActivityTabView');
}
});
if (!_.isUndefined(options.at) && collection.length > 1) {
this.$container.find('li').eq(options.at).before($el);
} else {
this.$container.append($el);
}
this._postRenderItem($el);
},
_postRenderItem: function($el) {
$el.find('.avatar').each(function() {
var element = $(this);
if (typeof element.avatar === 'function') {
if (element.data('user-display-name')) {
element.avatar(element.data('user'), 28, undefined, false, undefined, element.data('user-display-name'));
} else if (element.data('user')) {
element.avatar(element.data('user'), 28);
}
}
});
$el.find('.has-tooltip').tooltip({
placement: 'bottom'
});
},
/**
* Renders this details view
*/
render: function() {
if (this._fileInfo) {
this.$el.html(this.template({
emptyMessage: t('activity', 'No activities'),
moreLabel: t('activity', 'Load more activities')
}));
this.$container = this.$el.find('ul.activities');
}
}
});
OCA.Activity = OCA.Activity || {};
OCA.Activity.ActivityTabView = ActivityTabView;
})();