Allow to use card item without being available in global card store

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl
2020-07-11 11:10:47 +02:00
parent 3a4bbac6d4
commit 348fc669be
12 changed files with 160 additions and 52 deletions

View File

@@ -66,10 +66,6 @@ return [
['name' => 'card#assignUser', 'url' => '/cards/{cardId}/assign', 'verb' => 'POST'],
['name' => 'card#unassignUser', 'url' => '/cards/{cardId}/unassign', 'verb' => 'PUT'],
// dashboard
['name' => 'card#findAllWithDue', 'url' => '/dashboard/due', 'verb' => 'GET'],
['name' => 'card#findMyAssignedCards', 'url' => '/dashboard/assigned', 'verb' => 'GET'],
// attachments
['name' => 'attachment#getAll', 'url' => '/cards/{cardId}/attachments', 'verb' => 'GET'],
['name' => 'attachment#create', 'url' => '/cards/{cardId}/attachment', 'verb' => 'POST'],
@@ -138,5 +134,9 @@ return [
['name' => 'comments_api#create', 'url' => '/api/v1.0/cards/{cardId}/comments', 'verb' => 'POST'],
['name' => 'comments_api#update', 'url' => '/api/v1.0/cards/{cardId}/comments/{commentId}', 'verb' => 'PUT'],
['name' => 'comments_api#delete', 'url' => '/api/v1.0/cards/{cardId}/comments/{commentId}', 'verb' => 'DELETE'],
// dashboard
['name' => 'dashboard_api#findAllWithDue', 'url' => '/api/v1.0/dashboard/dashboard/due', 'verb' => 'GET'],
['name' => 'dashboard_api#findAssignedCards', 'url' => '/api/v1.0/dashboard/assigned', 'verb' => 'GET'],
]
];
];

View File

@@ -167,20 +167,4 @@ class CardController extends Controller {
public function unassignUser($cardId, $userId, $type = 0) {
return $this->assignmentService->unassignUser($cardId, $userId, $type);
}
/**
* @NoAdminRequired
* @return array
*/
public function findAllWithDue($userId) {
return $this->dashboardService->findAllWithDue($userId);
}
/**
* @NoAdminRequired
* @return array
*/
public function findMyAssignedCards($userId) {
return $this->dashboardService->findMyAssignedCards($userId);
}
}

View File

@@ -0,0 +1,56 @@
<?php
/**
* @copyright Copyright (c) 2020 Jakob Röhrl <jakob.roehrl@web.de>
*
* @author Jakob Röhrl <jakob.roehrl@web.de>
*
* @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/>.
*
*/
namespace OCA\Deck\Controller;
use OCA\Deck\Service\DashboardService;
use OCP\IRequest;
use OCP\AppFramework\Controller;
class DashboardApiController extends OCSController {
private $userId;
private $cardService;
public function __construct($appName, IRequest $request, DashboardService $dashboardService, $userId) {
parent::__construct($appName, $request);
$this->userId = $userId;
$this->dashboardService = $dashboardService;
}
/**
* @NoAdminRequired
* @return array
*/
public function findAllWithDue($userId) {
return $this->dashboardService->findAllWithDue($userId);
}
/**
* @NoAdminRequired
* @return array
*/
public function findAssignedCards($userId) {
return $this->dashboardService->findAssignedCards($userId);
}
}

View File

@@ -149,7 +149,7 @@ class CardMapper extends DeckMapper implements IPermissionMapper {
return $this->findEntities($sql, [$boardId]);
}
public function findMyAssignedCards($boardId, $username) {
public function findAssignedCards($boardId, $username) {
$sql = 'SELECT c.* FROM `*PREFIX*deck_cards` c
INNER JOIN `*PREFIX*deck_stacks` s ON s.id = c.stack_id
INNER JOIN `*PREFIX*deck_boards` b ON b.id = s.board_id

View File

@@ -583,8 +583,8 @@ class CardService {
* @throws \OCA\Deck\NoPermissionException
* @throws BadRequestException
*/
public function findMyAssignedCards($userId) {
$cards = $this->cardMapper->findMyAssignedCards($userId);
public function findAssignedCards($userId) {
$cards = $this->cardMapper->findAssignedCards($userId);
return $cards;
}

View File

@@ -144,7 +144,7 @@ class DashboardService {
/**
* @return array
*/
public function findMyAssignedCards($userId) {
public function findAssignedCards($userId) {
$userInfo = $this->getBoardPrerequisites();
$userBoards = $this->findAllBoardsFromUser($userInfo);
$allAssignedCards = [];
@@ -155,7 +155,7 @@ class DashboardService {
$cardData = $card->jsonSerialize();
$cardData['boardId'] = $userBoard->getId();
return $cardData;
}, $this->cardMapper->findMyAssignedCards($userBoard->getId(), $this->userId));
}, $this->cardMapper->findAssignedCards($userBoard->getId(), $this->userId));
}
return $allAssignedCards;
}

View File

@@ -85,7 +85,6 @@ export default {
created() {
this.$store.dispatch('loadBoards')
this.$store.dispatch('loadSharees')
this.$store.dispatch('loadDashboards')
},
}

View File

@@ -21,7 +21,7 @@
-->
<template>
<div class="badges">
<div v-if="card" class="badges">
<div v-if="card.commentsUnread > 0" class="icon icon-comment" />
<div v-if="card.description && checkListCount > 0" class="card-tasks icon icon-checkmark">
@@ -34,7 +34,7 @@
<AvatarList :users="card.assignedUsers" />
<CardMenu :id="id" />
<CardMenu :id="card.id" />
</div>
</template>
<script>
@@ -45,8 +45,8 @@ export default {
name: 'CardBadges',
components: { AvatarList, CardMenu },
props: {
id: {
type: Number,
card: {
type: Object,
default: null,
},
},
@@ -57,9 +57,6 @@ export default {
checkListCheckedCount() {
return (this.card.description.match(/^\s*([*+-]|(\d\.))\s+\[\s*x\s*\](.*)$/gim) || []).length
},
card() {
return this.$store.getters.cardById(this.id)
},
},
}
</script>

View File

@@ -25,7 +25,7 @@
-->
<template>
<AttachmentDragAndDrop :card-id="id" class="drop-upload--card">
<AttachmentDragAndDrop v-if="card" :card-id="card.id" class="drop-upload--card">
<div :class="{'compact': compactMode, 'current-card': currentCard, 'has-labels': card.labels && card.labels.length > 0, 'is-editing': editing}"
tag="div"
class="card"
@@ -67,7 +67,7 @@
</li>
</transition-group>
<div v-show="!compactMode" class="card-controls compact-item" @click="openCard">
<CardBadges :id="id" />
<CardBadges :card="card" />
</div>
</div>
</AttachmentDragAndDrop>
@@ -95,6 +95,10 @@ export default {
type: Number,
default: null,
},
item: {
type: Object,
default: null,
},
},
data() {
return {
@@ -113,10 +117,10 @@ export default {
'isArchived',
]),
card() {
return this.$store.getters.cardById(this.id)
return this.item ? this.item : this.$store.getters.cardById(this.id)
},
currentCard() {
return this.$route.params.cardId === this.id
return this.card && this.$route && this.$route.params.cardId === this.card.id
},
relativeDate() {
const diff = moment(this.$root.time).diff(this.card.duedate, 'seconds')
@@ -144,7 +148,8 @@ export default {
},
methods: {
openCard() {
this.$router.push({ name: 'card', params: { cardId: this.id } }).catch(() => {})
const boardId = this.item ? this.item.boardId : this.$route.params.id
this.$router.push({ name: 'card', params: { id: boardId, cardId: this.card.id } }).catch(() => {})
},
startEditing(card) {
this.copiedCard = Object.assign({}, card)

View File

@@ -28,24 +28,29 @@
<div class="dashboard-column">
<h2>overdue</h2>
<div v-for="card in withDueDashboardGroup.overdue" :key="card.id">
<!-- <CardItem :id="card.id" /> -->
{{ card.title }}
<CardItem :item="card" />
</div>
</div>
<div class="dashboard-column">
<h2>today</h2>
{{ withDueDashboardGroup.today }}
<div v-for="card in withDueDashboardGroup.today" :key="card.id">
<CardItem :item="card" />
</div>
</div>
<div class="dashboard-column">
<h2>tomorrow</h2>
{{ withDueDashboardGroup.tomorrow }}
<div v-for="card in withDueDashboardGroup.tomorrow" :key="card.id">
<CardItem :item="card" />
</div>
</div>
<div class="dashboard-column">
<h2>this week</h2>
{{ withDueDashboardGroup.thisWeek }}
<div v-for="card in withDueDashboardGroup.thisWeek" :key="card.id">
<CardItem :item="card" />
</div>
</div>
</div>
@@ -53,26 +58,31 @@
<div class="dashboard-column">
<h2>overdue</h2>
<div v-for="card in assignedCardsDashboardGroup.overdue" :key="card.id">
{{ card.title }}
<CardItem :item="card" />
</div>
</div>
<div class="dashboard-column">
<h2>today</h2>
{{ assignedCardsDashboardGroup.today }}
<div v-for="card in assignedCardsDashboardGroup.today" :key="card.id">
<CardItem :item="card" />
</div>
</div>
<div class="dashboard-column">
<h2>tomorrow</h2>
{{ assignedCardsDashboardGroup.tomorrow }}
<div v-for="card in assignedCardsDashboardGroup.tomorrow" :key="card.id">
<CardItem :item="card" />
</div>
</div>
<div class="dashboard-column">
<h2>this week</h2>
{{ assignedCardsDashboardGroup.thisWeek }}
<div v-for="card in assignedCardsDashboardGroup.thisWeek" :key="card.id">
<CardItem :item="card" />
</div>
</div>
</div>
</div>
</template>
@@ -81,6 +91,7 @@
import Controls from '../Controls'
import CardItem from '../cards/CardItem'
import { mapGetters } from 'vuex'
import moment from '@nextcloud/moment'
export default {
name: 'Dashboards',
@@ -106,6 +117,9 @@ export default {
return this.groupByDue(this.assignedCardsDashboard)
},
},
created() {
this.$store.dispatch('loadDashboards')
},
methods: {
groupByDue(dataset) {
const all = {

View File

@@ -0,0 +1,53 @@
/*
* @copyright Copyright (c) 2020 Jakob Röhrl <jakob.roehrl@web.de>
*
* @author Jakob Röhrl <jakob.roehrl@web.de>
*
* @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 axios from '@nextcloud/axios'
import { generateOcsUrl, generateRemoteUrl } from '@nextcloud/router'
export class DashboardApi {
url(url) {
url = `/apps/deck${url}`
return generateOcsUrl(url)
}
findAllWithDue(data) {
return axios.get(this.url(`/api/v1.0/dashboard/dashboard/due`))
.then(
(response) => Promise.resolve(response.data),
(err) => Promise.reject(err)
)
.catch((err) => Promise.reject(err)
)
}
findMyAssignedCards(data) {
return axios.get(this.url(`/ocs/v2.php/apps/deck/api/v1.0/dashboard/assigned`))
.then(
(response) => Promise.resolve(response.data),
(err) => Promise.reject(err)
)
.catch((err) => Promise.reject(err)
)
}
}

View File

@@ -22,10 +22,10 @@
import Vue from 'vue'
import Vuex from 'vuex'
import { CardApi } from '../services/CardApi'
import { DashboardApi } from '../services/DashboardApi'
Vue.use(Vuex)
const apiClient = new CardApi()
const apiClient = new DashboardApi()
export default {
state: {
withDue: [],
@@ -57,7 +57,7 @@ export default {
const assignedCards = await apiClient.findMyAssignedCards()
const assignedCardsFlat = assignedCards.flat()
commit('setAssignedCards', assignedCardsFlat)
},
},
}