forked from nextcloud/deck
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BoardSelector.vue
114 lines (103 loc) · 2.28 KB
/
BoardSelector.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<!--
- SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
- SPDX-License-Identifier: AGPL-3.0-or-later
-->
<template>
<NcModal @close="close">
<div id="modal-inner" :class="{ 'icon-loading': loading }">
<h1>{{ t('deck', 'Select the board to link to a project') }}</h1>
<input v-model="filter" type="text" :placeholder="t('deck', 'Search by board title')">
<ul v-if="!loading">
<li v-for="board in availableBoards"
:key="board.id"
:class="{'selected': (selectedBoard === board.id) }"
@click="selectedBoard=board.id">
<span :style="{ 'backgroundColor': '#' + board.color }" class="board-bullet" />
<span>{{ board.title }}</span>
</li>
</ul>
<button v-if="!loading" class="primary" @click="select">
{{ t('deck', 'Select board') }}
</button>
</div>
</NcModal>
</template>
<script>
import { NcModal } from '@nextcloud/vue'
import axios from '@nextcloud/axios'
import { generateUrl } from '@nextcloud/router'
export default {
name: 'BoardSelector',
components: {
NcModal,
},
data() {
return {
filter: '',
boards: [],
selectedBoard: null,
loading: true,
currentBoard: null,
}
},
computed: {
availableBoards() {
return this.boards.filter((board) => (
'' + board.id !== '' + this.currentBoard
&& board.title.match(this.filter)
))
},
},
beforeMount() {
this.fetchBoards()
const hash = window.location.hash.match(/\/boards\/([0-9]+)/)
this.currentBoard = hash.length > 0 ? hash[1] : null
},
methods: {
fetchBoards() {
axios.get(generateUrl('/apps/deck/boards')).then((response) => {
this.boards = response.data
this.loading = false
})
},
close() {
this.$root.$emit('close')
},
select() {
this.$root.$emit('select', this.selectedBoard)
},
},
}
</script>
<style scoped>
#modal-inner {
width: 90vw;
max-width: 400px;
padding: 20px;
}
ul {
min-height: 100px;
}
li {
padding: 6px;
border: 1px solid transparent;
}
li:hover, li:focus {
background-color: var(--color-background-dark);
}
li.selected {
border: 1px solid var(--color-primary-element);
}
.board-bullet {
display: inline-block;
width: 12px;
height: 12px;
border: none;
border-radius: 50%;
cursor: pointer;
}
li > span,
.avatar {
vertical-align: middle;
}
</style>