Skip to content

Commit afd5396

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

12 files changed

Lines changed: 332 additions & 2 deletions

File tree

appinfo/routes.php

Lines changed: 6 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' => '/dashboard/due', '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'],
@@ -110,6 +114,8 @@
110114
['name' => 'card_api#reorder', 'url' => '/api/v1.0/boards/{boardId}/stacks/{stackId}/cards/{cardId}/reorder', 'verb' => 'PUT'],
111115
['name' => 'card_api#delete', 'url' => '/api/v1.0/boards/{boardId}/stacks/{stackId}/cards/{cardId}', 'verb' => 'DELETE'],
112116

117+
['name' => 'card_api#findAllWithDue', 'url' => '/api/v1.0/dashboard/due', 'verb' => 'GET'],
118+
113119
['name' => 'label_api#get', 'url' => '/api/v1.0/boards/{boardId}/labels/{labelId}', 'verb' => 'GET'],
114120
['name' => 'label_api#create', 'url' => '/api/v1.0/boards/{boardId}/labels', 'verb' => 'POST'],
115121
['name' => 'label_api#update', 'url' => '/api/v1.0/boards/{boardId}/labels/{labelId}', 'verb' => 'PUT'],

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 AND NOT archived AND c.deleted_at = 0';
148+
return $this->findEntities($sql, [$boardId]);
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: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
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\CardMapper;
35+
use OCA\Deck\Db\Label;
36+
use OCA\Deck\Db\Stack;
37+
use OCA\Deck\Db\StackMapper;
38+
use OCA\Deck\NoPermissionException;
39+
use OCA\Deck\Notification\NotificationHelper;
40+
use OCP\AppFramework\Db\DoesNotExistException;
41+
use OCP\IGroupManager;
42+
use OCP\IL10N;
43+
use OCA\Deck\Db\Board;
44+
use OCA\Deck\Db\BoardMapper;
45+
use OCA\Deck\Db\LabelMapper;
46+
use OCP\IUserManager;
47+
use OCA\Deck\BadRequestException;
48+
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
49+
use Symfony\Component\EventDispatcher\GenericEvent;
50+
51+
class DashboardService {
52+
private $boardMapper;
53+
private $stackMapper;
54+
private $labelMapper;
55+
private $aclMapper;
56+
private $cardMapper;
57+
private $l10n;
58+
private $permissionService;
59+
private $notificationHelper;
60+
private $assignedUsersMapper;
61+
private $userManager;
62+
private $groupManager;
63+
private $userId;
64+
private $activityManager;
65+
/** @var EventDispatcherInterface */
66+
private $eventDispatcher;
67+
private $changeHelper;
68+
69+
public function __construct(
70+
BoardMapper $boardMapper,
71+
StackMapper $stackMapper,
72+
IL10N $l10n,
73+
LabelMapper $labelMapper,
74+
AclMapper $aclMapper,
75+
CardMapper $cardMapper,
76+
PermissionService $permissionService,
77+
NotificationHelper $notificationHelper,
78+
AssignedUsersMapper $assignedUsersMapper,
79+
IUserManager $userManager,
80+
IGroupManager $groupManager,
81+
ActivityManager $activityManager,
82+
EventDispatcherInterface $eventDispatcher,
83+
ChangeHelper $changeHelper,
84+
$userId
85+
) {
86+
$this->boardMapper = $boardMapper;
87+
$this->stackMapper = $stackMapper;
88+
$this->labelMapper = $labelMapper;
89+
$this->aclMapper = $aclMapper;
90+
$this->cardMapper = $cardMapper;
91+
$this->l10n = $l10n;
92+
$this->permissionService = $permissionService;
93+
$this->notificationHelper = $notificationHelper;
94+
$this->assignedUsersMapper = $assignedUsersMapper;
95+
$this->userManager = $userManager;
96+
$this->groupManager = $groupManager;
97+
$this->activityManager = $activityManager;
98+
$this->eventDispatcher = $eventDispatcher;
99+
$this->changeHelper = $changeHelper;
100+
$this->userId = $userId;
101+
}
102+
103+
/**
104+
* Set a different user than the current one, e.g. when no user is available in occ
105+
*
106+
* @param string $userId
107+
*/
108+
public function setUserId(string $userId): void {
109+
$this->userId = $userId;
110+
}
111+
112+
113+
/**
114+
* @return array
115+
*/
116+
public function findAllWithDue($userId) {
117+
$userInfo = $this->getBoardPrerequisites();
118+
$userBoards = $this->findAllBoardsFromUser($userInfo);
119+
$allDueCards = [];
120+
foreach ($userBoards as $userBoard) {
121+
$allDueCards[] = $this->cardMapper->findAllWithDue($userBoard->getId());
122+
}
123+
return $allDueCards;
124+
}
125+
126+
/**
127+
* @return array
128+
*/
129+
private function findAllBoardsFromUser($userInfo, $since = -1) {
130+
$userBoards = $this->boardMapper->findAllByUser($userInfo['user'], null, null, $since);
131+
$groupBoards = $this->boardMapper->findAllByGroups($userInfo['user'], $userInfo['groups'],null, null, $since);
132+
$circleBoards = $this->boardMapper->findAllByCircles($userInfo['user'], null, null, $since);
133+
return array_merge($userBoards, $groupBoards, $circleBoards);
134+
}
135+
136+
/**
137+
* @return array
138+
*/
139+
private function getBoardPrerequisites() {
140+
$groups = $this->groupManager->getUserGroupIds(
141+
$this->userManager->get($this->userId)
142+
);
143+
return [
144+
'user' => $this->userId,
145+
'groups' => $groups
146+
];
147+
}
148+
149+
150+
}

src/App.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ export default {
8585
created: function() {
8686
this.$store.dispatch('loadBoards')
8787
this.$store.dispatch('loadSharees')
88+
this.$store.dispatch('loadDashboards')
8889
},
8990
}
9091
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<!--
2+
- @copyright Copyright (c) 2018 Julius Härtl <jus@bitgrid.net>
3+
-
4+
- @author Julius Härtl <jus@bitgrid.net>
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+
<template>
24+
<div>
25+
<Controls />
26+
<h1>dashboards</h1>
27+
</div>
28+
</template>
29+
30+
<script>
31+
32+
import Controls from '../Controls'
33+
34+
export default {
35+
name: 'Dashboards',
36+
components: {
37+
Controls,
38+
},
39+
props: {
40+
filter: {
41+
type: String,
42+
default: '',
43+
},
44+
},
45+
46+
}
47+
</script>

src/components/navigation/AppNavigation.vue

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,17 @@
2323
<template>
2424
<div id="app-navigation" :class="{'icon-loading': loading}">
2525
<ul id="deck-navigation">
26+
<AppNavigationItem
27+
:title="t('deck', 'Your cards2')"
28+
icon="icon-screen"
29+
to="dashboards" />
30+
31+
<!-- <AppNavigationBoardCategory
32+
id="deck-navigation-dashboard"
33+
:text="t('deck', 'Your cards')"
34+
:boards="dashboards"
35+
:open-on-add-boards="true"
36+
icon="icon-screen" /> -->
2637
<AppNavigationBoardCategory
2738
id="deck-navigation-all"
2839
:text="t('deck', 'All boards')"
@@ -72,9 +83,9 @@ import axios from '@nextcloud/axios'
7283
import { mapGetters } from 'vuex'
7384
import ClickOutside from 'vue-click-outside'
7485
import { Multiselect } from '@nextcloud/vue'
75-
7686
import AppNavigationAddBoard from './AppNavigationAddBoard'
7787
import AppNavigationBoardCategory from './AppNavigationBoardCategory'
88+
import AppNavigationItem from '@nextcloud/vue/dist/Components/AppNavigationItem'
7889
import { loadState } from '@nextcloud/initial-state'
7990
import { generateUrl, generateOcsUrl } from '@nextcloud/router'
8091
@@ -86,6 +97,7 @@ export default {
8697
AppNavigationAddBoard,
8798
AppNavigationBoardCategory,
8899
Multiselect,
100+
AppNavigationItem,
89101
},
90102
directives: {
91103
ClickOutside,
@@ -103,13 +115,23 @@ export default {
103115
groupLimit: [],
104116
groupLimitDisabled: true,
105117
canCreate: canCreateState,
118+
dashboards: [{
119+
id: 1,
120+
title: 'due',
121+
color: '999999',
122+
acl: [],
123+
permissions: {
124+
PERMISSION_MANAGE: false,
125+
},
126+
}],
106127
}
107128
},
108129
computed: {
109130
...mapGetters([
110131
'noneArchivedBoards',
111132
'archivedBoards',
112133
'sharedBoards',
134+
// 'dashboards',
113135
]),
114136
isAdmin() {
115137
// eslint-disable-next-line

src/router.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import Board from './components/board/Board'
2929
import Sidebar from './components/Sidebar'
3030
import BoardSidebar from './components/board/BoardSidebar'
3131
import CardSidebar from './components/card/CardSidebar'
32+
import Dashboards from './components/dashboards/Dashboards'
3233

3334
Vue.use(Router)
3435

@@ -119,6 +120,18 @@ export default new Router({
119120
},
120121
},
121122
},
123+
{
124+
path: '/dashboard/:filter',
125+
name: 'dashboards',
126+
component: Dashboards,
127+
props: {
128+
default: (route) => {
129+
return {
130+
filter: route.params.filter,
131+
}
132+
},
133+
},
134+
},
122135
],
123136
},
124137
],

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(`/dashboard/due`))
200+
.then(
201+
(response) => Promise.resolve(response.data),
202+
(err) => Promise.reject(err)
203+
)
204+
.catch((err) => Promise.reject(err)
205+
)
206+
}
207+
198208
}

0 commit comments

Comments
 (0)