Some cleanup on the filtering
Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
@@ -136,7 +136,6 @@ return [
|
||||
['name' => 'comments_api#delete', 'url' => '/api/v1.0/cards/{cardId}/comments/{commentId}', 'verb' => 'DELETE'],
|
||||
|
||||
// dashboard
|
||||
['name' => 'overview_api#findAllWithDue', 'url' => '/api/v1.0/overview/due', 'verb' => 'GET'],
|
||||
['name' => 'overview_api#findAssignedCards', 'url' => '/api/v1.0/overview/assigned', 'verb' => 'GET'],
|
||||
['name' => 'overview_api#upcomingCards', 'url' => '/api/v1.0/overview/upcoming', 'verb' => 'GET'],
|
||||
]
|
||||
];
|
||||
|
||||
@@ -48,14 +48,7 @@ class OverviewApiController extends OCSController {
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
*/
|
||||
public function findAllWithDue(): DataResponse {
|
||||
return new DataResponse($this->dashboardService->findAllWithDue($this->userId));
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
*/
|
||||
public function findAssignedCards(): DataResponse {
|
||||
return new DataResponse($this->dashboardService->findAssignedCards($this->userId));
|
||||
public function upcomingCards(): DataResponse {
|
||||
return new DataResponse($this->dashboardService->findUpcomingCards($this->userId));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,13 +107,13 @@ class OverviewService {
|
||||
return $allDueCards;
|
||||
}
|
||||
|
||||
public function findAssignedCards(string $userId): array {
|
||||
public function findUpcomingCards(string $userId): array {
|
||||
$userBoards = $this->findAllBoardsFromUser($userId);
|
||||
$findCards = [];
|
||||
foreach ($userBoards as $userBoard) {
|
||||
$service = $this;
|
||||
|
||||
if (count($userBoard->getAcl()) == 0) {
|
||||
if (count($userBoard->getAcl()) === 0) {
|
||||
// get cards with due date
|
||||
$findCards[] = array_map(static function ($card) use ($service, $userBoard, $userId) {
|
||||
$service->enrich($card, $userId);
|
||||
@@ -130,13 +130,11 @@ class OverviewService {
|
||||
return $cardData;
|
||||
}, $this->cardMapper->findAssignedCards($userBoard->getId(), $userId));
|
||||
}
|
||||
|
||||
}
|
||||
return $findCards;
|
||||
}
|
||||
|
||||
// FIXME: This is duplicate code with the board service
|
||||
|
||||
private function findAllBoardsFromUser(string $userId): array {
|
||||
$userInfo = $this->getBoardPrerequisites($userId);
|
||||
$userBoards = $this->boardMapper->findAllByUser($userInfo['user'], null, null);
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
<AppNavigationItem
|
||||
:title="t('deck', 'Upcoming cards')"
|
||||
icon="icon-desktop"
|
||||
to="/overview/assigned" />
|
||||
to="/" />
|
||||
<AppNavigationBoardCategory
|
||||
id="deck-navigation-all"
|
||||
to="/board"
|
||||
|
||||
@@ -85,12 +85,10 @@ import CardItem from '../cards/CardItem'
|
||||
import { mapGetters } from 'vuex'
|
||||
import moment from '@nextcloud/moment'
|
||||
|
||||
const FILTER_DUE = 'due'
|
||||
const FILTER_ASSIGNED = 'assigned'
|
||||
const FILTER_UPCOMING = 'upcoming'
|
||||
|
||||
const SUPPORTED_FILTERS = [
|
||||
FILTER_ASSIGNED,
|
||||
FILTER_DUE,
|
||||
FILTER_UPCOMING,
|
||||
]
|
||||
|
||||
export default {
|
||||
@@ -102,7 +100,7 @@ export default {
|
||||
props: {
|
||||
filter: {
|
||||
type: String,
|
||||
default: FILTER_ASSIGNED,
|
||||
default: FILTER_UPCOMING,
|
||||
},
|
||||
},
|
||||
data() {
|
||||
@@ -116,25 +114,21 @@ export default {
|
||||
},
|
||||
filterDisplayName() {
|
||||
switch (this.filter) {
|
||||
case FILTER_ASSIGNED:
|
||||
case FILTER_UPCOMING:
|
||||
return t('deck', 'Upcoming cards')
|
||||
default:
|
||||
return ''
|
||||
}
|
||||
},
|
||||
...mapGetters([
|
||||
'withDueDashboard',
|
||||
'assignedCardsDashboard',
|
||||
]),
|
||||
cardsByDueDate() {
|
||||
switch (this.filter) {
|
||||
case FILTER_ASSIGNED:
|
||||
case FILTER_UPCOMING:
|
||||
return this.groupByDue(this.assignedCardsDashboard)
|
||||
case FILTER_DUE:
|
||||
return this.groupByDue(this.withDueDashboard)
|
||||
default:
|
||||
return null
|
||||
}
|
||||
return null
|
||||
},
|
||||
},
|
||||
watch: {
|
||||
@@ -149,12 +143,8 @@ export default {
|
||||
async getData() {
|
||||
this.loading = true
|
||||
try {
|
||||
if (this.filter === 'due') {
|
||||
await this.$store.dispatch('loadDueDashboard')
|
||||
}
|
||||
|
||||
if (this.filter === 'assigned') {
|
||||
await this.$store.dispatch('loadAssignDashboard')
|
||||
if (this.filter === FILTER_UPCOMING) {
|
||||
await this.$store.dispatch('loadUpcoming')
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
@@ -172,7 +162,6 @@ export default {
|
||||
later: [],
|
||||
}
|
||||
dataset.forEach(card => {
|
||||
|
||||
if (card.duedate === null) {
|
||||
all.nodue.push(card)
|
||||
} else {
|
||||
@@ -195,10 +184,13 @@ export default {
|
||||
all.later.push(card)
|
||||
}
|
||||
}
|
||||
|
||||
})
|
||||
Object.keys(all).forEach((list) => {
|
||||
all[list] = all[list].sort((a, b) => {
|
||||
return (new Date(a.duedate)).getTime() - (new Date(b.duedate)).getTime()
|
||||
})
|
||||
})
|
||||
return all
|
||||
|
||||
},
|
||||
},
|
||||
|
||||
|
||||
@@ -29,20 +29,8 @@ export class OverviewApi {
|
||||
return generateOcsUrl(`apps/deck/api/v1.0`) + url
|
||||
}
|
||||
|
||||
findAllWithDue(data) {
|
||||
return axios.get(this.url(`overview/due`), {
|
||||
headers: { 'OCS-APIRequest': 'true' },
|
||||
})
|
||||
.then(
|
||||
(response) => Promise.resolve(response.data.ocs.data),
|
||||
(err) => Promise.reject(err)
|
||||
)
|
||||
.catch((err) => Promise.reject(err)
|
||||
)
|
||||
}
|
||||
|
||||
findMyAssignedCards(data) {
|
||||
return axios.get(this.url(`overview/assigned`), {
|
||||
get(filter) {
|
||||
return axios.get(this.url(`overview/${filter}`), {
|
||||
headers: { 'OCS-APIRequest': 'true' },
|
||||
})
|
||||
.then(
|
||||
|
||||
@@ -28,39 +28,22 @@ Vue.use(Vuex)
|
||||
const apiClient = new OverviewApi()
|
||||
export default {
|
||||
state: {
|
||||
withDue: [],
|
||||
assignedCards: [],
|
||||
},
|
||||
getters: {
|
||||
withDueDashboard: state => {
|
||||
return state.withDue
|
||||
},
|
||||
assignedCardsDashboard: state => {
|
||||
return state.assignedCards
|
||||
},
|
||||
},
|
||||
mutations: {
|
||||
setWithDueDashboard(state, withDue) {
|
||||
state.withDue = withDue
|
||||
},
|
||||
setAssignedCards(state, assignedCards) {
|
||||
state.assignedCards = assignedCards
|
||||
},
|
||||
},
|
||||
actions: {
|
||||
async loadDueDashboard({ commit }) {
|
||||
async loadUpcoming({ commit }) {
|
||||
commit('setCurrentBoard', null)
|
||||
const cardsWithDueDate = await apiClient.findAllWithDue()
|
||||
const withDueFlat = cardsWithDueDate.flat()
|
||||
for (const i in withDueFlat) {
|
||||
commit('addCard', withDueFlat[i])
|
||||
}
|
||||
commit('setWithDueDashboard', withDueFlat)
|
||||
},
|
||||
|
||||
async loadAssignDashboard({ commit }) {
|
||||
commit('setCurrentBoard', null)
|
||||
const assignedCards = await apiClient.findMyAssignedCards()
|
||||
const assignedCards = await apiClient.get('upcoming')
|
||||
const assignedCardsFlat = assignedCards.flat()
|
||||
for (const i in assignedCardsFlat) {
|
||||
commit('addCard', assignedCardsFlat[i])
|
||||
|
||||
@@ -100,7 +100,7 @@ export default {
|
||||
},
|
||||
beforeMount() {
|
||||
this.loading = true
|
||||
this.$store.dispatch('loadAssignDashboard').then(() => {
|
||||
this.$store.dispatch('loadUpcoming').then(() => {
|
||||
this.loading = false
|
||||
})
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user