|
115 | 115 | </el-dialog>
|
116 | 116 | </template>
|
117 | 117 | <script>
|
118 |
| - import _ from 'lodash' |
119 |
| - import draggable from 'vuedraggable' |
120 |
| - import { NextAPI } from '../services/NextAPI' |
121 |
| - import matriculaUtils from '../utils/Matricula' |
122 |
| - import { convertDisciplina } from '../utils/convertUfabcDisciplina' |
123 |
| - import { findSeasonKey, findIdeais } from '../utils/season' |
| 118 | +import _ from 'lodash'; |
| 119 | +import draggable from 'vuedraggable'; |
| 120 | +import { NextAPI } from '../services/NextAPI'; |
| 121 | +import matriculaUtils from '../utils/Matricula'; |
| 122 | +import { convertDisciplina } from '../utils/convertUfabcDisciplina'; |
| 123 | +import { findSeasonKey, findIdeais } from '../utils/season'; |
124 | 124 |
|
125 |
| - const nextApi = NextAPI(); |
| 125 | +const nextApi = NextAPI(); |
126 | 126 |
|
127 |
| - export default { |
128 |
| - name: 'Modal', |
129 |
| - props: ['value'], |
130 |
| - components: { |
131 |
| - draggable, |
132 |
| - }, |
133 |
| - data() { |
134 |
| - return { |
135 |
| - loading: false, |
136 |
| - disciplina: {}, |
137 |
| -
|
138 |
| - headers: [], |
| 127 | +export default { |
| 128 | + name: 'Modal', |
| 129 | + props: ['value'], |
| 130 | + components: { |
| 131 | + draggable, |
| 132 | + }, |
| 133 | + data() { |
| 134 | + return { |
| 135 | + loading: false, |
| 136 | + disciplina: {}, |
139 | 137 |
|
140 |
| - kicksData: [], |
141 |
| - } |
142 |
| - }, |
| 138 | + headers: [], |
143 | 139 |
|
144 |
| - created() { |
145 |
| - this.fetch() |
146 |
| - }, |
| 140 | + kicksData: [], |
| 141 | + }; |
| 142 | + }, |
147 | 143 |
|
148 |
| - watch: { |
149 |
| - 'value.dialog'(v) { |
150 |
| - this.restore() |
151 |
| - }, |
| 144 | + created() { |
| 145 | + this.fetch(); |
| 146 | + }, |
152 | 147 |
|
153 |
| - 'value.corte_id'(val){ |
154 |
| - this.disciplina = _.find(todasDisciplinas, { id: parseInt(val) }) |
155 |
| - this.headers = this.defaultHeaders |
156 |
| - this.fetch() |
157 |
| - }, |
| 148 | + watch: { |
| 149 | + 'value.dialog'(v) { |
| 150 | + this.restore(); |
158 | 151 | },
|
159 | 152 |
|
160 |
| - computed: { |
161 |
| - transformed() { |
162 |
| - return this.kicksData.map(d => { |
163 |
| - return _.assign(_.clone(d), { |
164 |
| - reserva: d.reserva ? 'Sim' : 'Não', |
165 |
| - ik: d.ik.toFixed(3) |
166 |
| - }) |
167 |
| - }) |
168 |
| - }, |
| 153 | + 'value.corte_id'(val) { |
| 154 | + this.disciplina = _.find(todasDisciplinas, { id: parseInt(val) }); |
| 155 | + this.headers = this.defaultHeaders; |
| 156 | + this.fetch(); |
| 157 | + }, |
| 158 | + }, |
169 | 159 |
|
170 |
| - defaultHeaders() { |
171 |
| - let isIdeal = findIdeais().includes(this.disciplina.codigo) |
| 160 | + computed: { |
| 161 | + transformed() { |
| 162 | + return this.kicksData.map((d) => { |
| 163 | + return _.assign(_.clone(d), { |
| 164 | + reserva: d.reserva ? 'Sim' : 'Não', |
| 165 | + ik: d.ik.toFixed(3), |
| 166 | + }); |
| 167 | + }); |
| 168 | + }, |
172 | 169 |
|
173 |
| - const base = [ |
174 |
| - { text: 'Reserva', sortable: false, value: 'reserva' }, |
175 |
| - { text: 'Turno', value: 'turno', sortable: false }, |
176 |
| - { text: 'Ik', value: 'ik', sortable: false }, |
177 |
| - ] |
| 170 | + defaultHeaders() { |
| 171 | + let isIdeal = findIdeais().includes(this.disciplina.codigo); |
178 | 172 |
|
179 |
| - const season = findSeasonKey() |
| 173 | + const base = [ |
| 174 | + { text: 'Reserva', sortable: false, value: 'reserva' }, |
| 175 | + { text: 'Turno', value: 'turno', sortable: false }, |
| 176 | + { text: 'Ik', value: 'ik', sortable: false }, |
| 177 | + ]; |
180 | 178 |
|
181 |
| - if(isIdeal && (season != '2020:3' || season != '2021:1' || season != '2021:2')) { |
182 |
| - base.push({ text: 'CR', value: 'cr', sortable: false }) |
183 |
| - base.push({ text: 'CP', value: 'cp', sortable: false }) |
184 |
| - } else { |
185 |
| - base.push({ text: 'CP', value: 'cp', sortable: false }) |
186 |
| - base.push({ text: 'CR', value: 'cr', sortable: false }) |
187 |
| - } |
| 179 | + const season = findSeasonKey(); |
188 | 180 |
|
189 |
| - return base |
190 |
| - }, |
| 181 | + if ( |
| 182 | + isIdeal && |
| 183 | + (season != '2020:3' || season != '2021:1' || season != '2021:2') |
| 184 | + ) { |
| 185 | + base.push({ text: 'CR', value: 'cr', sortable: false }); |
| 186 | + base.push({ text: 'CP', value: 'cp', sortable: false }); |
| 187 | + } else { |
| 188 | + base.push({ text: 'CP', value: 'cp', sortable: false }); |
| 189 | + base.push({ text: 'CR', value: 'cr', sortable: false }); |
| 190 | + } |
191 | 191 |
|
192 |
| - getRequests() { |
193 |
| - return _.reduce(matriculas, (a, c) => c.includes(this.disciplina.id.toString()) ? a + 1 : a, 0) |
194 |
| - }, |
| 192 | + return base; |
| 193 | + }, |
195 | 194 |
|
196 |
| - computeKicksForecast() { |
197 |
| - return (this.kicksData.length * this.disciplina.vagas) / this.getRequests |
198 |
| - }, |
| 195 | + getRequests() { |
| 196 | + return _.reduce( |
| 197 | + matriculas, |
| 198 | + (a, c) => (c.includes(this.disciplina.id.toString()) ? a + 1 : a), |
| 199 | + 0, |
| 200 | + ); |
| 201 | + }, |
199 | 202 |
|
200 |
| - parsedDisciplina() { |
201 |
| - return convertDisciplina(this.disciplina) |
202 |
| - } |
| 203 | + computeKicksForecast() { |
| 204 | + return (this.kicksData.length * this.disciplina.vagas) / this.getRequests; |
| 205 | + }, |
203 | 206 |
|
| 207 | + parsedDisciplina() { |
| 208 | + return convertDisciplina(this.disciplina); |
204 | 209 | },
|
| 210 | + }, |
205 | 211 |
|
206 |
| - methods: { |
207 |
| - fetch() { |
208 |
| - let corteId = _.get(this.value, 'corte_id', '') |
209 |
| - if(!corteId) return |
210 |
| - const aluno_id = matriculaUtils.getAlunoId() |
| 212 | + methods: { |
| 213 | + fetch() { |
| 214 | + let corteId = _.get(this.value, 'corte_id', ''); |
| 215 | + if (!corteId) return; |
| 216 | + const aluno_id = matriculaUtils.getAlunoId(); |
211 | 217 |
|
212 |
| - this.loading = true |
| 218 | + this.loading = true; |
213 | 219 |
|
214 |
| - nextApi.get(`/disciplinas/${corteId}/kicks?aluno_id=${aluno_id}`).then((res) => { |
215 |
| - this.kicksData = res |
216 |
| - this.resort() |
217 |
| - this.loading = false |
218 |
| - }).catch((e) => { |
219 |
| - this.loading = false |
| 220 | + nextApi |
| 221 | + .get(`/disciplinas/${corteId}/kicks?aluno_id=${aluno_id}`) |
| 222 | + .then((res) => { |
| 223 | + this.kicksData = res; |
| 224 | + this.resort(); |
| 225 | + this.loading = false; |
| 226 | + }) |
| 227 | + .catch((e) => { |
| 228 | + this.loading = false; |
220 | 229 |
|
221 |
| - if(e && e.name == 'Forbidden') { |
| 230 | + if (e && e.name == 'Forbidden') { |
222 | 231 | // Show dialog with error
|
223 | 232 | this.$notify({
|
224 |
| - message: 'Não temos as diciplinas que você cursou, acesse o Portal do Aluno' |
225 |
| - }) |
| 233 | + message: |
| 234 | + 'Não temos as diciplinas que você cursou, acesse o Portal do Aluno', |
| 235 | + }); |
226 | 236 | }
|
227 |
| - }) |
228 |
| - }, |
| 237 | + }); |
| 238 | + }, |
229 | 239 |
|
230 |
| - resort(e) { |
231 |
| - const sortOrder = _.map(this.headers, 'value') |
232 |
| - const sortRef = Array(sortOrder.length || 0).fill('desc') |
| 240 | + resort(e) { |
| 241 | + const sortOrder = _.map(this.headers, 'value'); |
| 242 | + const sortRef = Array(sortOrder.length || 0).fill('desc'); |
233 | 243 |
|
234 |
| - const turnoIndex = sortOrder.indexOf('turno') |
235 |
| - if(turnoIndex != -1) { |
236 |
| - sortRef[turnoIndex] = (this.parsedDisciplina.turno == 'diurno') ? 'asc' : 'desc' |
237 |
| - } |
| 244 | + const turnoIndex = sortOrder.indexOf('turno'); |
| 245 | + if (turnoIndex != -1) { |
| 246 | + sortRef[turnoIndex] = |
| 247 | + this.parsedDisciplina.turno == 'diurno' ? 'asc' : 'desc'; |
| 248 | + } |
238 | 249 |
|
239 |
| - this.kicksData = _.orderBy(this.kicksData, sortOrder, sortRef) |
240 |
| - }, |
| 250 | + this.kicksData = _.orderBy(this.kicksData, sortOrder, sortRef); |
| 251 | + }, |
241 | 252 |
|
242 |
| - removedFilter(value) { |
243 |
| - this.headers = _.filter(this.headers, o => o.value != value) |
244 |
| - this.resort() |
245 |
| - }, |
| 253 | + removedFilter(value) { |
| 254 | + this.headers = _.filter(this.headers, (o) => o.value != value); |
| 255 | + this.resort(); |
| 256 | + }, |
246 | 257 |
|
247 |
| - restore() { |
248 |
| - this.headers = this.defaultHeaders |
249 |
| - this.resort() |
250 |
| - }, |
| 258 | + restore() { |
| 259 | + this.headers = this.defaultHeaders; |
| 260 | + this.resort(); |
| 261 | + }, |
251 | 262 |
|
252 |
| - closeDialog(){ |
253 |
| - this.value.dialog = false |
254 |
| - }, |
| 263 | + closeDialog() { |
| 264 | + this.value.dialog = false; |
| 265 | + }, |
255 | 266 |
|
256 |
| - // kickStatus(rowIndex) { |
257 |
| - // console.log("rowIndex", rowIndex) |
258 |
| - // console.log("this.computeKicksForecast", this.computeKicksForecast) |
259 |
| - // if(rowIndex <= this.computeKicksForecast) { |
260 |
| - // return 'not-kicked' |
261 |
| - // }else if(rowIndex >= this.disciplina.vagas){ |
262 |
| - // return 'kicked' |
263 |
| - // }else { |
264 |
| - // return 'probably-kicked' |
265 |
| - // } |
266 |
| - // }, |
| 267 | + // kickStatus(rowIndex) { |
| 268 | + // console.log("rowIndex", rowIndex) |
| 269 | + // console.log("this.computeKicksForecast", this.computeKicksForecast) |
| 270 | + // if(rowIndex <= this.computeKicksForecast) { |
| 271 | + // return 'not-kicked' |
| 272 | + // }else if(rowIndex >= this.disciplina.vagas){ |
| 273 | + // return 'kicked' |
| 274 | + // }else { |
| 275 | + // return 'probably-kicked' |
| 276 | + // } |
| 277 | + // }, |
267 | 278 |
|
268 |
| - tableRowClassName({row, rowIndex}) { |
269 |
| - if (row.aluno_id == matriculaUtils.getAlunoId()) { |
270 |
| - return 'aluno-row' |
271 |
| - } else if(rowIndex <= this.computeKicksForecast) { |
272 |
| - return 'not-kicked-row' |
273 |
| - }else if(rowIndex >= this.disciplina.vagas){ |
274 |
| - return 'kicked-row' |
275 |
| - }else { |
276 |
| - return 'probably-kicked-row' |
277 |
| - } |
| 279 | + tableRowClassName({ row, rowIndex }) { |
| 280 | + if (row.aluno_id == matriculaUtils.getAlunoId()) { |
| 281 | + return 'aluno-row'; |
| 282 | + } else if (rowIndex <= this.computeKicksForecast) { |
| 283 | + return 'not-kicked-row'; |
| 284 | + } else if (rowIndex >= this.disciplina.vagas) { |
| 285 | + return 'kicked-row'; |
| 286 | + } else { |
| 287 | + return 'probably-kicked-row'; |
278 | 288 | }
|
279 | 289 | },
|
280 |
| - } |
| 290 | + }, |
| 291 | +}; |
281 | 292 | </script>
|
282 | 293 | <style scoped>
|
283 | 294 | .information {
|
|
0 commit comments