Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Files activity tab eventdispatcher #364

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions appinfo/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,12 @@
// Cron job for sending emails and pruning the activity list
$c->getServer()->getJobList()->add('OCA\Activity\BackgroundJob\EmailNotification');
$c->getServer()->getJobList()->add('OCA\Activity\BackgroundJob\ExpireActivities');

// Needed for the files sidebar entry
\OC::$server->getEventDispatcher()->addListener('OCA\Files::loadAdditionalScripts', function() {
\OCP\Util::addStyle('activity', 'style');
\OCP\Util::addScript('activity', 'activitymodel');
\OCP\Util::addScript('activity', 'activitycollection');
\OCP\Util::addScript('activity', 'activitytabview');
\OCP\Util::addScript('activity', 'filesplugin');
});
82 changes: 82 additions & 0 deletions js/activitycollection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* Copyright (c) 2015
*
* This file is licensed under the Affero General Public License version 3
* or later.
*
* See the COPYING-README file.
*
*/

(function() {
/**
* @class OCA.Activity.ActivityCollection
* @classdesc
*
* Displays activity information for a given file
*
*/
var ActivityCollection = OC.Backbone.Collection.extend(
/** @lends OCA.Activity.ActivityCollection.prototype */ {

/**
* Id of the file for which to filter activities by
*
* @var int
*/
_objectId: null,

/**
* Type of the object to filter by
*
* @var string
*/
_objectType: null,

model: OCA.Activity.ActivityModel,

initialize: function(options) {
if (options && options.fileId) {
this._fileId = options.fileId;
}
},

/**
* Sets the object id to filter by or null for all.
*
* @param {int} objectId file id or null
*/
setObjectId: function(objectId) {
this._objectId = objectId;
},

/**
* Sets the object type to filter by or null for all.
*
* @param {int} objectType file id or null
*/
setObjectType: function(objectType) {
this._objectType = objectType;
},

url: function() {
var query = {
page: 1,
filter: 'all'
};
var url = OC.generateUrl('apps/activity/activities/fetch');
if (this._objectId) {
query.objectid = this._objectId;
}
if (this._objectType) {
query.objecttype = this._objectType;
}
url += '?' + OC.buildQueryString(query);
return url;
}
});

OCA.Activity = OCA.Activity || {};
OCA.Activity.ActivityCollection = ActivityCollection;
})();

26 changes: 26 additions & 0 deletions js/activitymodel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright (c) 2015
*
* This file is licensed under the Affero General Public License version 3
* or later.
*
* See the COPYING-README file.
*
*/

(function() {
/**
* @class OCA.Activity.ActivityModel
* @classdesc
*
* Displays activity information for a given file
*
*/
var ActivityModel = OC.Backbone.Model.extend(
/** @lends OCA.Activity.ActivityModel.prototype */ {
});

OCA.Activity = OCA.Activity || {};
OCA.Activity.ActivityModel = ActivityModel;
})();

151 changes: 151 additions & 0 deletions js/activitytabview.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
/*
* 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>' +
'{{#if loading}}' +
'<div class="loading" style="height: 50px"></div>' +
'{{end}}' +
'{{else}}' +
'<ul>' +
'{{#each activities}}' +
' <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>' +
'{{else}}' +
' <li class="empty">{{emptyMessage}}</li>' +
'{{/each}}' +
'</ul>' +
'{{/if}}' +
'</div>';

/**
* Format an activity model for display
*
* @param {OCA.Activity.ActivityModel} activity
* @return {Object}
*/
function formatActivity(activity) {
var output = {
subject: activity.get('subjectformatted').markup.trimmed,
formattedDate: activity.get('relativeDateTimestamp'),
formattedDateTooltip: activity.get('readableDateTimestamp'),
message: activity.get('messageformatted').markup.trimmed
};

if (activity.has('typeicon')) {
output.typeIconClass = activity.get('typeicon') + ' svg';
}
if (activity.has('previews')) {
output.previews = _.map(activity.get('previews'), function(data) {
return {
previewClass: data.isMimeTypeIcon ? 'preview-mimetype-icon': '',
source: data.source
};
});
}
return output;
}

/**
* @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',

_loading: false,

/**
* @type {OCA.Activity.ActivityCollection}
*/
_activities: null,

initialize: function() {
this._activities = new OCA.Activity.ActivityCollection();
this._activities.setObjectType('files');
this._activities.on('request', this._onRequest, this);
this._activities.on('update', this._onChange, this);
},

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._activities.setObjectId(this._fileInfo.get('id'));
this._activities.fetch();
} else {
this._activities.reset();
}
},

_onRequest: function() {
this._loading = true;
this.render();
},

_onChange: function() {
this._loading = false;
this.render();
},

/**
* Renders this details view
*/
render: function() {
if (this._fileInfo) {
this.$el.html(this.template({
loading: this._loading,
activities: this._activities.map(formatActivity),
emptyMessage: t('activity', 'No activities')
}));
this.$el.find('.has-tooltip').tooltip({
placement: 'bottom'
});
} else {
// TODO: render placeholder text?
}
}
});

OCA.Activity = OCA.Activity || {};
OCA.Activity.ActivityTabView = ActivityTabView;
})();

22 changes: 22 additions & 0 deletions js/filesplugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright (c) 2015
*
* This file is licensed under the Affero General Public License version 3
* or later.
*
* See the COPYING-README file.
*
*/

(function(OCA) {

var FilesPlugin = {
attach: function(fileList) {
fileList.registerTabView(new OCA.Activity.ActivityTabView());
}
};

OC.Plugins.register('OCA.Files.FileList', FilesPlugin);

})(OCA);

1 change: 1 addition & 0 deletions lib/fileshooksstatic.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,5 @@ public static function fileRestore($params) {
public static function share($params) {
self::getHooks()->share($params);
}

}