This repository has been archived by the owner on Oct 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CardChecklistWrap.vue
332 lines (310 loc) · 6.76 KB
/
CardChecklistWrap.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
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
<template>
<div>
<awesome icon="check-square" class="far fa-check-square"></awesome>
<span v-if="!isTitle">
<a href="" class="checklist-body-card-text" @click.prevent="editTitle">
{{ title }}
<awesome icon="edit" class="fas fa-edit"></awesome>
</a>
<button
class="checklist-title-delete-btn"
type="button"
@click="deleteChecklist"
>
Delete
</button>
</span>
<span v-else>
<input
v-model="inputTitle"
v-focus
type="text"
class="form-control checkbox-input-title"
maxlength="44"
@blur="onSubmitTitle"
@keypress.enter="onKeyupEnter"
/>
<button class="checkbox-input-btn" type="button" @click="onSubmitTitle">
Save
</button>
<a href="" class="checkbox-input-cancel" @click.prevent="isTitle = false">
×
</a>
</span>
<KProgress
:percent="percent"
class="progress"
:line-height="7"
:status="status"
/>
<CardChecklistWrapItem v-for="item in items" :key="item.id" v-bind="item" />
<button
v-if="!isItem"
class="checkbox-add-btn"
type="button"
@click="isAddItem"
>
Add an item
</button>
<span v-else>
<input
ref="addItem"
v-model="inputItem"
v-focus
type="text"
:class="`form-control checkbox-input-title checkbox-item-input`"
placeholder="Add an Item"
maxlength="399"
@blur="onSubmitItem"
@keypress.enter="onKeyupEnter"
/>
<button
class="checkbox-input-btn checkbox-item-save"
type="button"
@click="onSubmitItem"
>
Save
</button>
<a href="" class="checkbox-input-cancel checkbox-item-cancel">
×
</a>
</span>
</div>
</template>
<script>
import CardChecklistWrapItem from '@/components/card/cardModal/mainModal/checklists/CardChecklistWrapItem.vue';
import { updateChecklistAPI, deleteChecklistAPI } from '@/api/checklist';
import { createChecklistItemAPI } from '@/api/checklistItem';
export default {
components: {
CardChecklistWrapItem,
},
props: {
cardId: {
type: Number,
default: 0,
require: true,
},
id: {
type: Number,
default: 0,
require: true,
},
items: {
type: Array,
default: () => [],
require: false,
validator: prop =>
prop.every(
e =>
typeof e === 'string' ||
typeof e === 'number' ||
typeof e === 'object',
),
},
title: {
type: String,
require: true,
default: '',
},
readChecklist: {
type: Function,
require: true,
default: () => {},
},
},
data() {
return {
isTitle: false,
isItem: false,
inputTitle: '',
inputItem: '',
percent: 0,
status: 'error',
};
},
watch: {
items() {
this.onProgress();
},
},
mounted() {
this.onProgress();
},
methods: {
editTitle() {
this.isTitle = true;
this.inputTitle = this.title;
},
async deleteChecklist() {
try {
await deleteChecklistAPI({
checklistId: this.id,
cardId: this.cardId,
});
this.readChecklist(this.cardId);
} catch (error) {
console.log(error);
alert('체크리스트를 삭제하지 못했습니다.');
}
},
async updateChecklist() {
try {
await updateChecklistAPI(this.id, { title: this.inputTitle });
this.readChecklist(this.cardId);
} catch (error) {
console.log(error);
alert('체크리스트를 업데이트 하지 못했습니다.');
}
},
async createChecklistItem() {
try {
await createChecklistItemAPI({
checklistId: this.id,
item: this.inputItem,
});
this.readChecklist(this.cardId);
} catch (error) {
console.log(error);
alert('체크리스트 아이템을 생성하지 못했습니다.');
}
},
onSubmitTitle({ relatedTarget }) {
this.isTitle = false;
if (relatedTarget) {
if (relatedTarget.className === 'checkbox-input-cancel') {
return;
}
}
if (this.inputTitle.trim() === this.title) {
return;
}
this.updateChecklist();
},
isAddItem() {
this.isItem = true;
this.$refs.addItem.focus();
},
onSubmitItem({ relatedTarget }) {
this.isItem = false;
if (relatedTarget) {
if (
relatedTarget.className ===
'checkbox-input-cancel checkbox-item-cancel'
) {
return;
}
}
if (this.inputItem === '') {
return;
}
this.createChecklistItem();
this.inputItem = '';
this.isAddItem();
},
onProgress() {
let count = 0;
if (this.items.length === 0) {
return;
}
this.items.forEach(element => {
if (element.isChecked === 'Y') {
count += 1;
}
});
let changeStatus = (count / this.items.length) * 100;
this.percent = Math.round(changeStatus, -1);
changeStatus === 100
? (this.status = 'success')
: (this.status = 'error');
},
onKeyupEnter(event) {
event.target.blur();
},
},
};
</script>
<style lang="scss">
.fa-check-square {
color: #4f5d76;
}
.checkbox-input-title {
display: inline;
width: 93%;
margin-left: 13px;
&:hover {
filter: brightness(90%);
}
&.checkbox-item-input {
margin-left: 33px;
}
}
.checklist-title-delete-btn {
position: absolute;
display: inline-block;
right: 10px;
width: 66px;
height: 30px;
top: -6px;
color: black;
background: rgba(9, 30, 66, 0.04);
&:hover {
background-color: rgba(9, 30, 66, 0.1);
}
}
.progress {
margin: 15px -8px 15px 34px;
}
.checkbox-input-btn {
display: inline;
position: relative;
width: 60px;
height: 30px;
margin: 0 0 15px 31px;
&:hover {
filter: brightness(90%);
}
&.checkbox-item-save {
margin-left: 34px;
}
}
.checkbox-input-cancel {
color: black;
display: inline;
margin-left: 20px;
cursor: pointer;
&:hover {
font-weight: 900;
}
}
.checklist-body-card-text {
position: relative;
top: -2.5px;
left: 11px;
font-size: 16px !important;
color: #212732;
cursor: pointer;
&:hover {
color: rgba(9, 30, 66, 0.6);
.fa-edit {
display: inline-block;
font-size: 10px !important;
}
}
.fa-edit {
display: none;
}
}
.checkbox-add-btn {
position: relative;
height: 30px;
color: black;
background: rgba(9, 30, 66, 0.04);
left: 35px;
top: 5px;
margin-bottom: 10px;
&:hover {
background-color: rgba(9, 30, 66, 0.1);
}
}
</style>