Add activity list to sidebars

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl
2018-09-04 18:06:33 +02:00
parent 18f92f7b54
commit 3319f9c3b3
11 changed files with 299 additions and 35 deletions

View File

@@ -0,0 +1,9 @@
.activitymessage .visualdiff ins {
background-color: rgba(70, 186, 97, 0.2);
text-decoration: none;
}
.activitymessage .visualdiff del {
background-color: rgba(233, 50, 45, 0.2);
text-decoration: none;
}

View File

@@ -48,13 +48,15 @@ import ngsortable from 'ng-sortable';
import md from 'angular-markdown-it'; import md from 'angular-markdown-it';
import nganimate from 'angular-animate'; import nganimate from 'angular-animate';
import 'angular-file-upload'; import 'angular-file-upload';
import ngInfiniteScroll from 'ng-infinite-scroll';
var app = angular.module('Deck', [ var app = angular.module('Deck', [
ngsanitize, ngsanitize,
uirouter, uirouter,
angularuiselect, angularuiselect,
ngsortable, md, nganimate, ngsortable, md, nganimate,
'angularFileUpload' 'angularFileUpload',
ngInfiniteScroll
]); ]);
export default app; export default app;

View File

@@ -0,0 +1,65 @@
/*
* @copyright Copyright (c) 2018 Julius Härtl <jus@bitgrid.net>
*
* @author Julius Härtl <jus@bitgrid.net>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
/* global OC */
class ActivityController {
constructor ($scope, CardService, ActivityService) {
'ngInject';
this.cardservice = CardService;
this.activityservice = ActivityService;
this.$scope = $scope;
this.type = '';
var self = this;
this.$scope.$watch(function() {
return self.element.id;
}, function (params) {
self.activityservice.fetchMoreActivities(self.type, self.element.id);
self.activityservice.fetchNewerActivities(self.type, self.element.id);
}, true);
console.log('constructor');
}
getData(id) {
return this.activityservice.getData(this.type, id);
}
parseMessage(subject, parameters) {
OCA.Activity.RichObjectStringParser._userLocalTemplate = '<avatar ng-attr-contactsmenu ng-attr-tooltip ng-attr-user="{{ id }}" ng-attr-displayname="{{name}}"></avatar>';
return OCA.Activity.RichObjectStringParser.parseMessage(subject, parameters);
}
page() {
this.activityservice.fetchMoreActivities(this.type, this.element.id);
}
}
let activityComponent = {
templateUrl: OC.linkTo('deck', 'templates/part.card.activity.html'),
controller: ActivityController,
bindings: {
type: '@',
element: '='
}
};
export default activityComponent;

View File

@@ -14,9 +14,11 @@ import './app/Run.js';
import ListController from 'controller/ListController.js'; import ListController from 'controller/ListController.js';
import attachmentListComponent from './controller/AttachmentController.js'; import attachmentListComponent from './controller/AttachmentController.js';
import activityComponent from './controller/ActivityController.js';
app.controller('ListController', ListController); app.controller('ListController', ListController);
app.component('attachmentListComponent', attachmentListComponent); app.component('attachmentListComponent', attachmentListComponent);
app.component('activityComponent', activityComponent);
// require all the js files from subdirectories // require all the js files from subdirectories

46
js/package-lock.json generated
View File

@@ -2970,8 +2970,7 @@
"ansi-regex": { "ansi-regex": {
"version": "2.1.1", "version": "2.1.1",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"aproba": { "aproba": {
"version": "1.2.0", "version": "1.2.0",
@@ -2992,14 +2991,12 @@
"balanced-match": { "balanced-match": {
"version": "1.0.0", "version": "1.0.0",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"brace-expansion": { "brace-expansion": {
"version": "1.1.11", "version": "1.1.11",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"balanced-match": "^1.0.0", "balanced-match": "^1.0.0",
"concat-map": "0.0.1" "concat-map": "0.0.1"
@@ -3014,20 +3011,17 @@
"code-point-at": { "code-point-at": {
"version": "1.1.0", "version": "1.1.0",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"concat-map": { "concat-map": {
"version": "0.0.1", "version": "0.0.1",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"console-control-strings": { "console-control-strings": {
"version": "1.1.0", "version": "1.1.0",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"core-util-is": { "core-util-is": {
"version": "1.0.2", "version": "1.0.2",
@@ -3144,8 +3138,7 @@
"inherits": { "inherits": {
"version": "2.0.3", "version": "2.0.3",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"ini": { "ini": {
"version": "1.3.5", "version": "1.3.5",
@@ -3157,7 +3150,6 @@
"version": "1.0.0", "version": "1.0.0",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"number-is-nan": "^1.0.0" "number-is-nan": "^1.0.0"
} }
@@ -3172,7 +3164,6 @@
"version": "3.0.4", "version": "3.0.4",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"brace-expansion": "^1.1.7" "brace-expansion": "^1.1.7"
} }
@@ -3180,14 +3171,12 @@
"minimist": { "minimist": {
"version": "0.0.8", "version": "0.0.8",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"minipass": { "minipass": {
"version": "2.2.4", "version": "2.2.4",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"safe-buffer": "^5.1.1", "safe-buffer": "^5.1.1",
"yallist": "^3.0.0" "yallist": "^3.0.0"
@@ -3206,7 +3195,6 @@
"version": "0.5.1", "version": "0.5.1",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"minimist": "0.0.8" "minimist": "0.0.8"
} }
@@ -3287,8 +3275,7 @@
"number-is-nan": { "number-is-nan": {
"version": "1.0.1", "version": "1.0.1",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"object-assign": { "object-assign": {
"version": "4.1.1", "version": "4.1.1",
@@ -3300,7 +3287,6 @@
"version": "1.4.0", "version": "1.4.0",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"wrappy": "1" "wrappy": "1"
} }
@@ -3386,8 +3372,7 @@
"safe-buffer": { "safe-buffer": {
"version": "5.1.1", "version": "5.1.1",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"safer-buffer": { "safer-buffer": {
"version": "2.1.2", "version": "2.1.2",
@@ -3423,7 +3408,6 @@
"version": "1.0.2", "version": "1.0.2",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"code-point-at": "^1.0.0", "code-point-at": "^1.0.0",
"is-fullwidth-code-point": "^1.0.0", "is-fullwidth-code-point": "^1.0.0",
@@ -3443,7 +3427,6 @@
"version": "3.0.1", "version": "3.0.1",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"ansi-regex": "^2.0.0" "ansi-regex": "^2.0.0"
} }
@@ -3487,14 +3470,12 @@
"wrappy": { "wrappy": {
"version": "1.0.2", "version": "1.0.2",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"yallist": { "yallist": {
"version": "3.0.2", "version": "3.0.2",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
} }
} }
}, },
@@ -4917,6 +4898,11 @@
"integrity": "sha512-vdqTKI9GBIYcAEbFAcpKPErKINfPF5zIuz3/niBfq8WUZjpT2tytLlFVrBgWdOtqI4uaA/Rb6No0hux39XXDuw==", "integrity": "sha512-vdqTKI9GBIYcAEbFAcpKPErKINfPF5zIuz3/niBfq8WUZjpT2tytLlFVrBgWdOtqI4uaA/Rb6No0hux39XXDuw==",
"dev": true "dev": true
}, },
"ng-infinite-scroll": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/ng-infinite-scroll/-/ng-infinite-scroll-1.3.0.tgz",
"integrity": "sha1-wumNj9E0sFJaTSz1jJXZtYN1URI="
},
"ng-sortable": { "ng-sortable": {
"version": "1.3.8", "version": "1.3.8",
"resolved": "https://registry.npmjs.org/ng-sortable/-/ng-sortable-1.3.8.tgz", "resolved": "https://registry.npmjs.org/ng-sortable/-/ng-sortable-1.3.8.tgz",

View File

@@ -17,6 +17,7 @@
"babel-polyfill": "^6.26.0", "babel-polyfill": "^6.26.0",
"markdown-it": "^8.4.2", "markdown-it": "^8.4.2",
"markdown-it-link-target": "^1.0.2", "markdown-it-link-target": "^1.0.2",
"ng-infinite-scroll": "^1.3.0",
"ng-sortable": "^1.3.8", "ng-sortable": "^1.3.8",
"ui-select": "^0.19.8" "ui-select": "^0.19.8"
}, },

View File

@@ -0,0 +1,168 @@
/*
* @copyright Copyright (c) 2018 Julius Härtl <jus@bitgrid.net>
*
* @author Julius Härtl <jus@bitgrid.net>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
import app from '../app/App.js';
const DECK_ACTIVITY_TYPE_BOARD = 'deck_board';
const DECK_ACTIVITY_TYPE_CARD = 'deck_card';
/* global OC oc_requesttoken */
class ActivityService {
constructor ($rootScope, $filter, $http, $q) {
this.running = false;
this.$filter = $filter;
this.$http = $http;
this.$q = $q;
this.data = {};
this.data[DECK_ACTIVITY_TYPE_BOARD] = {};
this.data[DECK_ACTIVITY_TYPE_CARD] = {};
this.since = {
deck_card: {
},
deck_board: {
},
}
}
static getUrl(type, id, since) {
if (type === DECK_ACTIVITY_TYPE_CARD)
return OC.linkToOCS('apps/activity/api/v2/activity', 2) + 'filter?format=json&object_type=deck_card&object_id=' + id + '&limit=5&since=' + since;
if (type === DECK_ACTIVITY_TYPE_BOARD)
return OC.linkToOCS('apps/activity/api/v2/activity', 2) + 'filter?format=json&object_type=deck_board&object_id=' + id + '&limit=5&since=' + since;
}
fetchCardActivities(type, id, since) {
var deferred = this.$q.defer();
this.running = true;
this.checkData(type, id);
var self = this;
this.$http.get(ActivityService.getUrl(type, id, since)).then(function (response) {
var objects = response.data.ocs.data;
for (let index in objects) {
let item = objects[index];
self.addItem(type, id, item);
if (item.activity_id > self.since[type][id].latest) {
self.since[type][id].latest = item.activity_id;
}
}
self.data[type][id].sort(function(a, b) {
return b.activity_id - a.activity_id;
});
self.since[type][id].oldest = response.headers('X-Activity-Last-Given');
self.running = false;
deferred.resolve(objects);
}, function (error) {
if (error.status === 304) {
self.since[type][id].finished = true;
}
self.running = false;
});
return deferred.promise;
}
fetchMoreActivities(type, id) {
this.checkData(type, id);
if (this.running === true) {
return;
}
if (!this.since[type][id].finished) {
return this.fetchCardActivities(type, id, this.since[type][id].oldest);
}
}
checkData(type, id) {
if (!Array.isArray(this.data[type][id])) {
this.data[type][id] = [];
}
if (typeof this.since[type][id] === 'undefined') {
this.since[type][id] = {
latest: 0,
oldestCatchedUp: false,
oldest: '0',
finished: false,
};
}
}
addItem(type, id, item) {
console.log(id);
if (this.data[type][id].findIndex((entry) => { return entry.activity_id === item.activity_id; }) === -1) {
item.timestamp = new Date(item.datetime).getTime();
this.data[type][id].push(item);
}
}
/**
* Fetch newer activities starting from the latest ones that are in cache
*
* @param type
* @param id
*/
fetchNewerActivities(type, id) {
if (this.since[type][id].latest === 0) {
return;
}
let self = this;
this.fetchNewer(type, id).then(function() {
self.fetchNewerActivities(type, id);
});
}
fetchNewer(type, id) {
var deferred = this.$q.defer();
this.running = true;
var self = this;
this.$http.get(ActivityService.getUrl(type, id, this.since[type][id].latest) + '&sort=asc').then(function (response) {
var objects = response.data.ocs.data;
let data = [];
for (let index in objects) {
let item = objects[index];
self.addItem(type, id, item);
}
self.data[type][id].sort(function(a, b) {
return b.activity_id - a.activity_id;
});
self.since[type][id].latest = response.headers('X-Activity-Last-Given');
self.data[type][id] = data.concat(self.data[type][id]);
self.running = false;
deferred.resolve(objects);
}, function (error) {
self.running = false;
});
return deferred.promise;
}
getData(type, id) {
return this.data[type][id];
}
};
app.service('ActivityService', ActivityService);
export default ActivityService;
export {DECK_ACTIVITY_TYPE_BOARD, DECK_ACTIVITY_TYPE_CARD};

View File

@@ -23,6 +23,9 @@
use OCP\Util; use OCP\Util;
Util::addScript('activity', 'richObjectStringParser');
Util::addStyle('activity', 'style');
Util::addStyle('deck', '../js/build/vendor'); Util::addStyle('deck', '../js/build/vendor');
Util::addScript('deck', 'build/vendor'); Util::addScript('deck', 'build/vendor');

View File

@@ -16,6 +16,8 @@
<li class="tabHeader" ng-class="{'selected': (params.tab==1)}" ui-sref="{tab: 1}"><a><?php p($l->t('Tags')); ?></a></li> <li class="tabHeader" ng-class="{'selected': (params.tab==1)}" ui-sref="{tab: 1}"><a><?php p($l->t('Tags')); ?></a></li>
<li class="tabHeader" ng-class="{'selected': (params.tab==2)}" ui-sref="{tab: 2}"><a><?php p($l->t('Deleted Stacks')); ?></a></li> <li class="tabHeader" ng-class="{'selected': (params.tab==2)}" ui-sref="{tab: 2}"><a><?php p($l->t('Deleted Stacks')); ?></a></li>
<li class="tabHeader" ng-class="{'selected': (params.tab==3)}" ui-sref="{tab: 3}"><a><?php p($l->t('Deleted Cards')); ?></a></li> <li class="tabHeader" ng-class="{'selected': (params.tab==3)}" ui-sref="{tab: 3}"><a><?php p($l->t('Deleted Cards')); ?></a></li>
<li class="tabHeader" ng-class="{'selected': (params.tab==4)}" ui-sref="{tab: 4}"><a><?php p($l->t('Activity')); ?></a></li>
</ul> </ul>
<div class="tabsContainer"> <div class="tabsContainer">
<div id="tabBoardShare" class="tab" ng-if="params.tab==0 || !params.tab"> <div id="tabBoardShare" class="tab" ng-if="params.tab==0 || !params.tab">
@@ -147,4 +149,10 @@
</li> </li>
</ul> </ul>
</div> </div>
<div id="board-detail-activity" class="tab" ng-if="params.tab==4">
<activity-component ng-if="boardservice.getCurrent()" type="deck_board" element="boardservice.getCurrent()"></activity-component>
</div>
</div> </div>

View File

@@ -0,0 +1,12 @@
<ul class="activities" infinite-scroll="$ctrl.page()" infinite-scroll-container="'#app-sidebar'">
<li class="activity box" ng-repeat="activity in $ctrl.getData($ctrl.element.id)">
<div class="activity-icon">
<img src="{{activity.icon}}" alt="">
</div>
<div class="activitysubject"
ng-bind-html="$ctrl.parseMessage(activity.subject_rich[0], activity.subject_rich[1])"></div>
<span class="activitytime has-tooltip live-relative-timestamp"
data-timestamp="{{ activity.timestamp }}">{{ activity.timestamp/1000 | relativeDateFilter }}</span>
<div class="activitymessage">{{ activity.activity_id }}</div>
</li>
</ul>

View File

@@ -92,6 +92,8 @@
<ul class="tabHeaders ng-scope"> <ul class="tabHeaders ng-scope">
<li class="tabHeader selected" ng-class="{'selected': (params.tab==0 || !params.tab)}" ui-sref="{tab: 0}"><a><?php p($l->t('Description')); ?></a></li> <li class="tabHeader selected" ng-class="{'selected': (params.tab==0 || !params.tab)}" ui-sref="{tab: 0}"><a><?php p($l->t('Description')); ?></a></li>
<li class="tabHeader" ng-class="{'selected': (params.tab==1)}" ui-sref="{tab: 1}"><a><?php p($l->t('Attachments')); ?></a></li> <li class="tabHeader" ng-class="{'selected': (params.tab==1)}" ui-sref="{tab: 1}"><a><?php p($l->t('Attachments')); ?></a></li>
<li class="tabHeader" ng-class="{'selected': (params.tab==2)}" ui-sref="{tab: 2}"><a><?php p($l->t('Activity')); ?></a></li>
</ul> </ul>
<div class="tabDetails"> <div class="tabDetails">
<span class="save-indicator saved"><?php p($l->t('Saved')); ?></span> <span class="save-indicator saved"><?php p($l->t('Saved')); ?></span>
@@ -128,4 +130,10 @@
ng-if="!description()"><?php p($l->t('Add a card description…')); ?></div> ng-if="!description()"><?php p($l->t('Add a card description…')); ?></div>
</div> </div>
</div> </div>
<div class="section-content card-activity" ng-if="params.tab === 2">
<activity-component type="deck_card" element="cardservice.getCurrent()"></activity-component>
</div>
</div> </div>