Algorithm.vue
6.36 KB
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
<template>
<q-layout>
<q-page-container>
<q-page class="row panels justify-around">
<q-card flat bordered class="col-5 column items-between items-center card-table">
<h1>Algoritmos</h1>
<q-table
class="table-algorithms"
:data="algorithmTable.data"
:columns="algorithmTable.columns"
row-key="name"
>
<template v-slot:body-cell-id="props">
<q-td key="id" class="row justify-center" :props="props">
<div class="row table-btn justify-around">
<q-btn @click="addAlgorithmModal(props.row.id)" class="remove-btn" icon="add" color="orange"/>
<q-btn @click="editAlgorithmModal(props.row.id)" class="remove-btn" icon="edit" color="orange"/>
<q-btn @click="removeAlgorithm(props.row.id)" class="remove-btn" icon="remove" color="orange"/>
</div>
</q-td>
</template>
</q-table>
</q-card>
<q-card flat bordered class="col-5 column items-between items-center card-info">
<h1>Dados do Algoritmo</h1>
<div class="buttons-info column justify-between">
<q-btn icon="local_offer" color="orange" label="Tags" no-caps/>
</div>
</q-card>
<q-dialog v-model="editModal" persistent>
<q-card class="algorithm-edit column items-center justify-between">
<h1>Editar Algoritmo</h1>
<div>
<q-input v-model="newAlgorithm.name" label="Nome da Tag"/>
<q-select v-model="newAlgorithm.typeRecommendation" :options="typeRecommendations" label="Tipo de Recomendação"/>
</div>
<q-card-actions>
<q-btn flat label="Cancelar" color="orange" v-close-popup/>
<q-btn flat @click="editAlgorithmData" label="Confirmar" color="orange" v-close-popup/>
</q-card-actions>
</q-card>
</q-dialog>
<q-dialog v-model="addModal" persistent>
<q-card class="algorithm-edit column items-center justify-between">
<h1>Adicionar Algoritmo</h1>
<div>
<q-input v-model="newAlgorithm.name" label="Nome da Algoritmo"/>
<q-select v-model="newAlgorithm.typeRecommendation" :options="typeRecommendations" label="Tipo de Recomendação"/>
</div>
<q-card-actions>
<q-btn flat label="Cancelar" color="orange" v-close-popup/>
<q-btn flat @click="addAlgorithm" label="Confirmar" color="orange" v-close-popup/>
</q-card-actions>
</q-card>
</q-dialog>
</q-page>
</q-page-container>
</q-layout>
</template>
<script>
import BaseService from 'src/services/BaseService'
export default {
name: 'Algorithm',
data () {
return {
addModal: false,
algorithmService: new BaseService('algorithms'),
newAlgorithm: {
name: '',
typeRecommendation: ''
},
editModal: false,
typeRecommendations: [
'HYBRID',
'CONTENT',
'COLLABORATIVE'
],
algorithmTable: {
data: [],
columns: [
{
name: 'name',
label: 'Nome',
field: 'name',
align: 'center',
sortable: true
},
{
name: 'type',
label: 'Tipo',
field: 'typeRecommendation',
align: 'center',
sortable: true
},
{
name: 'id',
label: 'Operações',
field: 'id',
align: 'center',
sortable: true
}
]
}
}
},
methods: {
async getAlgorithms () {
const resp = await this.algorithmService.get()
return resp._embedded && resp._embedded.algorithms ? resp._embedded.algorithms : []
},
async editAlgorithmModal (id) {
this.newAlgorithm = await this.algorithmService.get(`${id}`)
this.editModal = true
},
async addAlgorithmModal (id) {
this.newAlgorithm = await this.algorithmService.get(`${id}`)
this.addModal = true
},
async editAlgorithmData () {
try {
await this.algorithmService.put(`/${this.newAlgorithm.id}`, this.newAlgorithm)
this.$q.notify({
message: 'Algoritmo removido com sucesso!',
color: 'green',
position: 'bottom-right'
})
} catch (e) {
this.$q.notify({
message: 'Houve um problema ao remover o Algoritmo',
color: 'red',
position: 'bottom-right'
})
}
this.algorithmTable.data = await this.getAlgorithms()
},
async removeAlgorithm (id) {
try {
await this.algorithmService.delete(`/${id}`)
this.$q.notify({
message: 'Algoritmo removido com sucesso!',
color: 'green',
position: 'bottom-right'
})
} catch (e) {
this.$q.notify({
message: 'Houve um problema ao remover o Algoritmo',
color: 'red',
position: 'bottom-right'
})
}
this.algorithmTable.data = await this.getAlgorithms()
},
async addAlgorithm () {
try {
await this.algorithmService.post('', this.newAlgorithm)
this.$q.notify({
message: 'Algoritmo adicionado com sucesso!',
color: 'green',
position: 'bottom-right'
})
} catch (e) {
this.$q.notify({
message: 'Houve um problema ao adicionar o Algoritmo',
color: 'red',
position: 'bottom-right'
})
}
this.algorithmTable.data = await this.getAlgorithms()
}
},
async mounted () {
this.algorithmTable.data = await this.getAlgorithms()
}
}
</script>
<style lang="scss" scoped>
h1 {
font-size: 1.2em;
font-weight: 500;
color: $gunmetal;
text-align: center;
margin: 0;
padding: 0;
line-height: 3rem;
}
.algorithm-edit {
width: 350px;
height: 250px;
}
.table-algorithms {
width: 85%;
}
.remove-btn {
display: flex;
width: 35px;
height: 35px;
font-size: 0.8em;
border-radius: 40px;
}
.table-btn {
width: 80%;
}
.q-card {
border-radius: 20px;
}
.buttons-info {
margin-top: 15px;
width: 80%;
}
.card-table {
height: 550px;
}
.card-info {
height: 150px;
}
</style>