Welcome to mirror list, hosted at ThFree Co, Russian Federation.

CardSelector.vue « src - github.com/nextcloud/deck.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5a255aac6db92c2f540081a883b91111695d673e (plain)
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<!--
  - @copyright Copyright (c) 2019 Julius Härtl <jus@bitgrid.net>
  -
  - @author Julius Härtl <jus@bitgrid.net>
  -
  - @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/>.
  -
  -->

<template>
	<NcModal class="card-selector" @close="close">
		<div id="modal-inner" :class="{ 'icon-loading': loading }">
			<h3>{{ title }}</h3>
			<NcMultiselect v-model="selectedBoard"
				:placeholder="t('deck', 'Select a board')"
				:options="boards"
				:disabled="loading"
				label="title"
				@select="fetchCardsFromBoard">
				<template slot="singleLabel" slot-scope="props">
					<span>
						<span :style="{ 'backgroundColor': '#' + props.option.color }" class="board-bullet" />
						<span>{{ props.option.title }}</span>
					</span>
				</template>
				<template slot="option" slot-scope="props">
					<span>
						<span :style="{ 'backgroundColor': '#' + props.option.color }" class="board-bullet" />
						<span>{{ props.option.title }}</span>
					</span>
				</template>
			</NcMultiselect>

			<NcMultiselect v-model="selectedCard"
				:placeholder="t('deck', 'Select a card')"
				:options="cardsFromBoard"
				:disabled="loading || selectedBoard === ''"
				label="title" />

			<button :disabled="!isBoardAndStackChoosen" class="primary" @click="select">
				{{ action }}
			</button>
			<button @click="close">
				{{ t('deck', 'Cancel') }}
			</button>
		</div>
	</NcModal>
</template>

<script>
import { generateUrl } from '@nextcloud/router'
import { NcModal, NcMultiselect } from '@nextcloud/vue'
import axios from '@nextcloud/axios'

export default {
	name: 'CardSelector',
	components: {
		NcModal,
		NcMultiselect,
	},
	props: {
		title: {
			type: String,
			default: t('deck', 'Select the card to link to a project'),
		},
		action: {
			type: String,
			default: t('deck', 'Link to card'),
		},
	},
	data() {
		return {
			boards: [],
			selectedBoard: '',
			cardsFromBoard: [],
			selectedCard: '',
			loading: true,
		}
	},
	computed: {
		isBoardAndStackChoosen() {
			return !(this.selectedBoard === '' || this.selectedCard === '')
		},
	},
	beforeMount() {
		this.fetchBoards()
	},
	methods: {
		fetchBoards() {
			axios.get(generateUrl('/apps/deck/boards')).then((response) => {
				this.boards = response.data
				this.loading = false
			})
		},
		async fetchCardsFromBoard(board) {
			try {
				this.cardsFromBoard = []
				const url = generateUrl('/apps/deck/stacks/' + board.id)
				const response = await axios.get(url)
				response.data.forEach(stack => {
					this.cardsFromBoard.push(...stack.cards)
				})
			} catch (err) {
				return err
			}

		},
		close() {
			this.$root.$emit('close')
		},
		select() {
			this.$root.$emit('select', this.selectedCard.id)

		},
	},

}
</script>

<style scoped>
	#modal-inner {
		width: 90vw;
		max-width: 400px;
		padding: 20px;
		height: 200px;
	}

	.multiselect {
		width: 100%;
		margin-bottom: 10px;
	}

	ul {
		min-height: 100px;
	}

	li {
		padding: 6px;
		border: 1px solid transparent;
	}

	li:hover, li:focus {
		background-color: var(--color-background-dark);
	}

	.board-bullet {
		display: inline-block;
		width: 12px;
		height: 12px;
		border: none;
		border-radius: 50%;
		cursor: pointer;
	}

	button {
		float: right;
	}

	.card-selector::v-deep .modal-container {
		overflow: visible !important;
	}
</style>