-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdndndnd.html
141 lines (137 loc) · 4.66 KB
/
dndndnd.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Sortable List with Vue.js</title>
<link rel="stylesheet" href="https://bootswatch.com/4/slate/bootstrap.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootswatch/4/slate/bootstrap.min.css">
<link rel="stylesheet" href="https://bootswatch.com/_assets/css/custom.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.13.0/css/all.min.css">
<!-- Vue.js CDN -->
<script src="https://cdn.jsdelivr.net/npm/vue@2"></script>
<style>
body {
padding-top: 70px;
padding-bottom: 20px;
}
.row{
justify-content: center;
}
hidden{
display: none;
}
.card{
margin-bottom: 5%;
}
.container-fluid{
width: 75%;
}
.orange{ color: orange}
.orangered{ color: orangered}
.green{ color: green}
.blue{ color: skyblue}
.purple{ color: mediumpurple}
.red{ color: red}
.lawngreen{ color: lawngreen}
.gray{ color: gray}
.yellow{ color: yellow}
</style>
</head>
<body>
<div id="app">
<div class="container-fluid">
<div class="row" >
<div
v-for="(item, index) in sortedItems"
:key="index"
class="draggable-item col-md-2"
draggable="true"
@dragstart="dragstart(index)"
@dragover="dragover"
@drop="drop"
@dragend="dragend"
>
<div class="card text-center">
<h5 class="card-header">
<i :class="item.class"></i> {{ item.title }}
</h5>
<div class="card-body">
<p class="card-text">{{ item.value }}</p>
<button @click="increaseValue(index)">Increase</button>
</div>
</div>
</div>
</div>
</div>
</div>
<script>
new Vue({
el: '#app',
data: {
items: [
{ title: 'Здраве', value: '24', class: 'fas fa-heartbeat green' },
{ title: 'Фитнес', value: '17', class: 'fas fa-dumbbell blue' },
{ title: 'Дух', value: '11', class: 'fas fa-yin-yang orange' },
{ title: 'Семейство', value: '4', class: 'fas fa-users orangered' },
{ title: 'Ходене', value: '7', class: 'fas fa-walking orangered' },
{ title: 'Хранене', value: '25', class: 'fas fa-utensils lawngreen' },
{ title: 'Медитация', value: '28', class: 'fas fa-atom purple' },
{ title: 'Връзки', value: '34', class: 'fas fa-heart red' },
{ title: 'Приятели', value: '48', class: 'fas fa-beer orange' },
{ title: 'Бизнес', value: '76', class: 'fas fa-briefcase blue' },
{ title: 'Финанси', value: '11', class: 'fas fa-wallet green' },
{ title: 'Дневник', value: '14', class: 'fas fa-book gray' },
{ title: 'Кариера', value: '7', class: 'fas fa-user-tie blue' },
{ title: 'Филантропия', value: '12', class: 'fas fa-gift red' },
{ title: 'Креативност', value: '44', class: 'fas fa-cogs blue' },
{ title: 'Умения', value: '18', class: 'fas fa-tools red' },
{ title: 'Почивка', value: '28', class: 'fas fa-couch green' },
{ title: 'Лукс', value: '28', class: 'far fa-gem blue' },
{ title: 'Приключения', value: '22', class: 'fas fa-plane-departure purple' },
{ title: 'Религия', value: '11', class: 'fas fa-peace purple' },
{ title: 'Хоби', value: '24', class: 'fas fa-camera yellow' },
{ title: 'Социални', value: '24', class: 'fas fa-people-arrows yellow' }
],
draggedIndex: null,
},
computed: {
sortedItems() {
// Sort the items by the value property (as numbers)
return this.items.slice().sort((a, b) => parseInt(a.value) - parseInt(b.value));
},
},
methods: {
dragstart(index) {
this.draggedIndex = index;
},
dragover(event) {
event.preventDefault();
},
drop(event) {
event.preventDefault();
const targetIndex = this.items.findIndex(item => item.title.trim() === event.target.textContent.trim());
if (this.draggedIndex !== null && targetIndex !== -1) {
this.items.splice(targetIndex, 0, this.items.splice(this.draggedIndex, 1)[0]);
this.draggedIndex = null;
}
},
dragend() {
this.draggedIndex = null;
},
increaseValue(index) {
// Increment the value of the selected item by one
this.items[index].value = (parseInt(this.items[index].value) + 1).toString();
},
},
});
</script>
<style>
.draggable-item {
margin: 5px;
padding: 10px;
cursor: grab;
}
</style>
</body>
</html>