Skip to content

Commit 8912179

Browse files
committed
card dashboard
Signed-off-by: Jakob Röhrl <jakob.roehrl@web.de>
1 parent f94b0b1 commit 8912179

9 files changed

Lines changed: 248 additions & 1 deletion

File tree

appinfo/routes.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,11 @@
6565
['name' => 'card#removeLabel', 'url' => '/cards/{cardId}/label/{labelId}', 'verb' => 'DELETE'],
6666
['name' => 'card#assignUser', 'url' => '/cards/{cardId}/assign', 'verb' => 'POST'],
6767
['name' => 'card#unassignUser', 'url' => '/cards/{cardId}/unassign', 'verb' => 'PUT'],
68+
69+
// dashboard
70+
['name' => 'card#findAllWithDue', 'url' => '/cards/findAllWithDue/{userId}', 'verb' => 'GET'],
6871

72+
// attachments
6973
['name' => 'attachment#getAll', 'url' => '/cards/{cardId}/attachments', 'verb' => 'GET'],
7074
['name' => 'attachment#create', 'url' => '/cards/{cardId}/attachment', 'verb' => 'POST'],
7175
['name' => 'attachment#display', 'url' => '/cards/{cardId}/attachment/{attachmentId}', 'verb' => 'GET'],

lib/Controller/CardController.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
use OCA\Deck\Service\AssignmentService;
2727
use OCA\Deck\Service\CardService;
28+
use OCA\Deck\Service\DashboardService;
2829
use OCP\IRequest;
2930
use OCP\AppFramework\Controller;
3031

@@ -33,10 +34,11 @@ class CardController extends Controller {
3334
private $cardService;
3435
private $assignmentService;
3536

36-
public function __construct($appName, IRequest $request, CardService $cardService, AssignmentService $assignmentService, $userId) {
37+
public function __construct($appName, IRequest $request, CardService $cardService, DashboardService $dashboardService, AssignmentService $assignmentService, $userId) {
3738
parent::__construct($appName, $request);
3839
$this->userId = $userId;
3940
$this->cardService = $cardService;
41+
$this->dashboardService = $dashboardService;
4042
$this->assignmentService = $assignmentService;
4143
}
4244

@@ -165,4 +167,12 @@ public function assignUser($cardId, $userId, $type = 0) {
165167
public function unassignUser($cardId, $userId, $type = 0) {
166168
return $this->assignmentService->unassignUser($cardId, $userId, $type);
167169
}
170+
171+
/**
172+
* @NoAdminRequired
173+
* @return array
174+
*/
175+
public function findAllWithDue($userId) {
176+
return $this->dashboardService->findAllWithDue($userId);
177+
}
168178
}

lib/Db/CardMapper.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,13 @@ public function findAllByStack($stackId, $limit = null, $offset = null) {
141141
return $this->findEntities($sql, [$stackId], $limit, $offset);
142142
}
143143

144+
public function findAllWithDue($boardId) {
145+
$sql = 'SELECT c.* FROM `*PREFIX*deck_cards` c
146+
INNER JOIN `*PREFIX*deck_stacks` s ON s.id = c.stack_id
147+
WHERE `s`.`board_id` = ? AND duedate IS NOT NULL';
148+
return $this->findEntities($sql, [$userId]);
149+
}
150+
144151
public function findOverdue() {
145152
$sql = 'SELECT id,title,duedate,notified from `*PREFIX*deck_cards` WHERE duedate < NOW() AND NOT archived AND deleted_at = 0';
146153
return $this->findEntities($sql);

lib/Service/CardService.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,4 +564,16 @@ public function removeLabel($cardId, $labelId) {
564564
'\OCA\Deck\Card::onUpdate', new FTSEvent(null, ['id' => $cardId, 'card' => $card])
565565
);
566566
}
567+
568+
/**
569+
*
570+
* @return array
571+
* @throws \OCA\Deck\NoPermissionException
572+
* @throws BadRequestException
573+
*/
574+
public function findAllWithDue($userId) {
575+
$cards = $this->cardMapper->findAllWithDue($userId);
576+
577+
return $cards;
578+
}
567579
}

lib/Service/DashboardService.php

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
<?php
2+
/**
3+
* @copyright Copyright (c) 2016 Julius Härtl <jus@bitgrid.net>
4+
*
5+
* @author Julius Härtl <jus@bitgrid.net>
6+
* @author Maxence Lange <maxence@artificial-owl.com>
7+
*
8+
* @license GNU AGPL version 3 or any later version
9+
*
10+
* This program is free software: you can redistribute it and/or modify
11+
* it under the terms of the GNU Affero General Public License as
12+
* published by the Free Software Foundation, either version 3 of the
13+
* License, or (at your option) any later version.
14+
*
15+
* This program is distributed in the hope that it will be useful,
16+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
* GNU Affero General Public License for more details.
19+
*
20+
* You should have received a copy of the GNU Affero General Public License
21+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
22+
*
23+
*/
24+
25+
namespace OCA\Deck\Service;
26+
27+
use OCA\Deck\Activity\ActivityManager;
28+
use OCA\Deck\Activity\ChangeSet;
29+
use OCA\Deck\Db\Acl;
30+
use OCA\Deck\Db\AclMapper;
31+
use OCA\Deck\Db\AssignedUsersMapper;
32+
use OCA\Deck\Db\ChangeHelper;
33+
use OCA\Deck\Db\IPermissionMapper;
34+
use OCA\Deck\Db\Label;
35+
use OCA\Deck\Db\Stack;
36+
use OCA\Deck\Db\StackMapper;
37+
use OCA\Deck\NoPermissionException;
38+
use OCA\Deck\Notification\NotificationHelper;
39+
use OCP\AppFramework\Db\DoesNotExistException;
40+
use OCP\IGroupManager;
41+
use OCP\IL10N;
42+
use OCA\Deck\Db\Board;
43+
use OCA\Deck\Db\BoardMapper;
44+
use OCA\Deck\Db\LabelMapper;
45+
use OCP\IUserManager;
46+
use OCA\Deck\BadRequestException;
47+
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
48+
use Symfony\Component\EventDispatcher\GenericEvent;
49+
50+
class BoardService {
51+
private $boardMapper;
52+
private $stackMapper;
53+
private $labelMapper;
54+
private $aclMapper;
55+
private $l10n;
56+
private $permissionService;
57+
private $notificationHelper;
58+
private $assignedUsersMapper;
59+
private $userManager;
60+
private $groupManager;
61+
private $userId;
62+
private $activityManager;
63+
/** @var EventDispatcherInterface */
64+
private $eventDispatcher;
65+
private $changeHelper;
66+
67+
public function __construct(
68+
BoardMapper $boardMapper,
69+
StackMapper $stackMapper,
70+
IL10N $l10n,
71+
LabelMapper $labelMapper,
72+
AclMapper $aclMapper,
73+
PermissionService $permissionService,
74+
NotificationHelper $notificationHelper,
75+
AssignedUsersMapper $assignedUsersMapper,
76+
IUserManager $userManager,
77+
IGroupManager $groupManager,
78+
ActivityManager $activityManager,
79+
EventDispatcherInterface $eventDispatcher,
80+
ChangeHelper $changeHelper,
81+
$userId
82+
) {
83+
$this->boardMapper = $boardMapper;
84+
$this->stackMapper = $stackMapper;
85+
$this->labelMapper = $labelMapper;
86+
$this->aclMapper = $aclMapper;
87+
$this->l10n = $l10n;
88+
$this->permissionService = $permissionService;
89+
$this->notificationHelper = $notificationHelper;
90+
$this->assignedUsersMapper = $assignedUsersMapper;
91+
$this->userManager = $userManager;
92+
$this->groupManager = $groupManager;
93+
$this->activityManager = $activityManager;
94+
$this->eventDispatcher = $eventDispatcher;
95+
$this->changeHelper = $changeHelper;
96+
$this->userId = $userId;
97+
}
98+
99+
/**
100+
* Set a different user than the current one, e.g. when no user is available in occ
101+
*
102+
* @param string $userId
103+
*/
104+
public function setUserId(string $userId): void {
105+
$this->userId = $userId;
106+
}
107+
108+
/**
109+
* @return array
110+
*/
111+
private function findAllBoardsFromUser($userId) {
112+
$userBoards = $this->boardMapper->findAllByUser($userId);
113+
$groupBoards = $this->boardMapper->findAllByGroups($userId);
114+
$circleBoards = $this->boardMapper->findAllByCircles($userId);
115+
return array_merge($userBoards, $groupBoards, $circleBoards);
116+
}
117+
118+
/**
119+
* @return array
120+
*/
121+
public function findAllWithDue($userId) {
122+
$userInfo = $this->getBoardPrerequisites();
123+
$userBoards = findAllBoardsFromUser($userId);
124+
$allDueCards = [];
125+
foreach ($userBoards as $userBoard) {
126+
$allDueCards = findAllWithDue($userBoard);
127+
}
128+
return $allDueCards;
129+
}
130+
131+
/**
132+
* @return array
133+
*/
134+
private function getBoardPrerequisites() {
135+
$groups = $this->groupManager->getUserGroupIds(
136+
$this->userManager->get($this->userId)
137+
);
138+
return [
139+
'user' => $this->userId,
140+
'groups' => $groups
141+
];
142+
}
143+
144+
145+
}

src/components/navigation/AppNavigation.vue

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@
2323
<template>
2424
<div id="app-navigation" :class="{'icon-loading': loading}">
2525
<ul id="deck-navigation">
26+
<AppNavigationBoardCategory
27+
id="deck-navigation-dashboard"
28+
:text="t('deck', 'Card Dashboard')"
29+
:boards="dashboards"
30+
:open-on-add-boards="true"
31+
icon="icon-screen" />
2632
<AppNavigationBoardCategory
2733
id="deck-navigation-all"
2834
:text="t('deck', 'All boards')"
@@ -110,6 +116,7 @@ export default {
110116
'noneArchivedBoards',
111117
'archivedBoards',
112118
'sharedBoards',
119+
'dashboards',
113120
]),
114121
isAdmin() {
115122
// eslint-disable-next-line

src/services/CardApi.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,4 +195,14 @@ export class CardApi {
195195
})
196196
}
197197

198+
findAllWithDue(data) {
199+
return axios.get(this.url(`/cards/findAllWithDue`))
200+
.then(
201+
(response) => Promise.resolve(response.data),
202+
(err) => Promise.reject(err)
203+
)
204+
.catch((err) => Promise.reject(err)
205+
)
206+
}
207+
198208
}

src/store/dashboard.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* @copyright Copyright (c) 2020 Jakob Röhrl <jakob.roehrl@web.de>
3+
*
4+
* @author Jakob Röhrl <jakob.roehrl@web.de>
5+
*
6+
* @license GNU AGPL version 3 or any later version
7+
*
8+
* This program is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU Affero General Public License as
10+
* published by the Free Software Foundation, either version 3 of the
11+
* License, or (at your option) any later version.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU Affero General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU Affero General Public License
19+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
20+
*
21+
*/
22+
23+
import Vue from 'vue'
24+
import Vuex from 'vuex'
25+
import { CardApi } from '../services/CardApi'
26+
Vue.use(Vuex)
27+
28+
const apiClient = new CardApi()
29+
export default new Vuex.Store({
30+
state: {
31+
withDue: [],
32+
},
33+
getters: {
34+
dashboards: state => {
35+
return state.withDue
36+
},
37+
},
38+
mutations: {
39+
setDashboards(state, withDue) {
40+
state.withDue = withDue
41+
},
42+
43+
},
44+
actions: {
45+
async loadDashboards({ commit }) {
46+
const withDue = await apiClient.findAllWithDue()
47+
commit('setDashboards', withDue)
48+
},
49+
},
50+
})

src/store/main.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import card from './card'
3232
import comment from './comment'
3333
import trashbin from './trashbin'
3434
import attachment from './attachment'
35+
import dashboard from './dashboard'
3536
import debounce from 'lodash/debounce'
3637
Vue.use(Vuex)
3738

@@ -51,6 +52,7 @@ export default new Vuex.Store({
5152
comment,
5253
trashbin,
5354
attachment,
55+
dashboard,
5456
},
5557
strict: debug,
5658
state: {

0 commit comments

Comments
 (0)