Files
CyberGarden-Grade/hackathon-grading-system-front/pages/admin/marks.vue
T

318 lines
10 KiB
Vue

<template>
<div>
<div class="page-heading">
<h1>Результаты</h1>
<button class="button" type="button" :disabled="refreshing" @click="refresh">
{{ refreshing ? 'Обновляем…' : 'Обновить' }}
</button>
</div>
<div class="toolbar">
<div class="tabs report-tabs" role="group" aria-label="Отчёт">
<button
v-for="item in tabs"
:key="item.id"
class="tab"
:class="{ active: tab === item.id }"
:aria-pressed="String(tab === item.id)"
type="button"
@click="tab = item.id"
>
{{ item.name }}
</button>
</div>
<select v-model="selectedCase" class="filter-select" aria-label="Кейс">
<option value="">Все кейсы</option>
<option v-for="(name, id) in cases" :key="id" :value="id">{{ name }}</option>
</select>
</div>
<div v-if="error" class="form-error" role="alert">{{ error }}</div>
<template v-if="tab === 'ranking'"
><section v-for="(ranking, id) in filteredPositions" :key="id" class="panel report-section">
<div class="panel-header">
<h2>{{ cases[id] }}</h2>
</div>
<div class="table-scroll">
<table class="data-table">
<thead>
<tr>
<SortHeader
v-for="column in rankingColumns"
:key="column.key"
:active="sorting.key === column.key"
:direction="sorting.direction"
@sort="sortBy(column.key)"
>{{ column.name }}</SortHeader
>
</tr>
</thead>
<tbody>
<tr v-for="[teamId, place] in sortedRanking(ranking)" :key="teamId">
<td style="width: 80px">{{ place }}</td>
<td>{{ teams[teamId] }}</td>
</tr>
</tbody>
</table>
</div>
</section>
<div v-if="!Object.keys(filteredPositions).length" class="panel table-empty">Оценок пока нет.</div></template
>
<template v-else-if="tab === 'details'">
<section v-for="task in filteredDetails" :key="task.id" class="panel report-section">
<div class="panel-header">
<h2>{{ task.name }}</h2>
</div>
<div class="table-scroll">
<table class="data-table all-marks-table">
<thead>
<tr>
<SortHeader
v-for="column in detailColumns"
:key="column.key"
:active="sorting.key === column.key"
:direction="sorting.direction"
@sort="sortBy(column.key)"
>{{ column.name }}</SortHeader
>
</tr>
</thead>
<tbody>
<tr v-for="row in sortedDetails(task.rows)" :key="row.teamId + row.userId">
<td>{{ row.team }}</td>
<td>{{ row.expert }}<span v-if="row.role === 'technical'" class="badge">Технический эксперт</span></td>
<td v-for="(_, type) in criteria" :key="type">
{{ row.marks[type] === null ? '—' : row.marks[type] }}
</td>
<td>{{ row.total === null ? '—' : row.total }}</td>
</tr>
<tr v-if="!task.rows.length">
<td :colspan="Object.keys(criteria).length + 3" class="table-empty">
Нет назначенных экспертов или команд.
</td>
</tr>
</tbody>
</table>
</div>
</section>
<div v-if="!filteredDetails.length" class="panel table-empty">Кейсов пока нет.</div>
</template>
<section v-else class="panel">
<div class="table-scroll">
<table class="data-table">
<thead>
<tr>
<SortHeader
v-for="column in reportColumns"
:key="column.key"
:active="sorting.key === column.key"
:direction="sorting.direction"
@sort="sortBy(column.key)"
>{{ column.name }}</SortHeader
>
</tr>
</thead>
<template v-if="tab === 'zero'">
<tbody v-for="group in zeroGroups" :key="group.id">
<tr v-for="(row, index) in group.rows" :key="index">
<td v-if="index === 0" :rowspan="group.rows.length">{{ group.user }}</td>
<td>{{ row.task }}</td>
<td class="assignment-cell">{{ row.teams[0] }}</td>
<td class="assignment-cell">{{ row.criterion }}</td>
<td>0</td>
</tr>
</tbody>
</template>
<tbody v-if="tab !== 'zero' || !reportRows.length">
<tr v-for="(row, index) in reportRows" :key="index">
<td>{{ row.user }}</td>
<td>{{ row.task }}</td>
<td class="assignment-cell">{{ row.teams.join(', ') }}</td>
<td v-if="tab === 'zero'">{{ row.criterion }}</td>
<td v-if="tab === 'zero'">0</td>
</tr>
<tr v-if="!reportRows.length">
<td :colspan="reportColumns.length" class="table-empty">
{{ tab === 'missing' ? 'Все оценки заполнены.' : 'Нулевых оценок нет.' }}
</td>
</tr>
</tbody>
</table>
</div>
</section>
</div>
</template>
<script>
export default {
name: 'Results',
async asyncData({ $axios }) {
const [missing, ranking, detail] = await Promise.all([
$axios.$get('/admin/marks'),
$axios.$get('/admin/positions'),
$axios.$get('/admin/marks/details'),
])
return { ...missing, ...ranking, ...detail }
},
data() {
return {
noMarks: {},
zeroMarks: {},
positions: {},
details: [],
criteria: {},
cases: {},
teams: {},
selectedCase: '',
tab: 'ranking',
sorts: {
ranking: { key: 'place', direction: 'asc' },
details: { key: '', direction: 'asc' },
missing: { key: '', direction: 'asc' },
zero: { key: '', direction: 'asc' },
},
rankingColumns: [
{ key: 'place', name: 'Место' },
{ key: 'team', name: 'Команда' },
],
missingColumns: [
{ key: 'user', name: 'Эксперт' },
{ key: 'task', name: 'Кейс' },
{ key: 'teams', name: 'Команды' },
],
refreshing: false,
error: '',
tabs: [
{ id: 'ranking', name: 'Рейтинг' },
{ id: 'details', name: 'Все оценки' },
{ id: 'missing', name: 'Без оценок' },
{ id: 'zero', name: 'Нулевые оценки' },
],
}
},
computed: {
zeroGroups() {
if (this.tab !== 'zero') return []
const groups = new Map()
for (const row of this.reportRows) {
if (!groups.has(row.userId)) groups.set(row.userId, { id: row.userId, user: row.user, rows: [] })
groups.get(row.userId).rows.push(row)
}
const direction = this.sorting.key === 'user' && this.sorting.direction === 'desc' ? -1 : 1
return [...groups.values()].sort(
(a, b) => direction * a.user.localeCompare(b.user, 'ru', { sensitivity: 'base', numeric: true })
)
},
reportColumns() {
if (this.tab !== 'zero') return this.missingColumns
return [
{ key: 'user', name: 'Эксперт' },
{ key: 'task', name: 'Кейс' },
{ key: 'teams', name: 'Команда' },
{ key: 'criterion', name: 'Критерий' },
{ key: 'value', name: 'Оценка' },
]
},
sorting() {
return this.sorts[this.tab]
},
detailColumns() {
return [
{ key: 'team', name: 'Команда' },
{ key: 'expert', name: 'Эксперт' },
...Object.entries(this.criteria).map(([type, name]) => ({
key: 'mark:' + type,
name: name + ([20, 30].includes(+type) ? ' (тех.)' : ''),
})),
{ key: 'total', name: 'Сумма' },
]
},
filteredDetails() {
return this.details.filter(task => !this.selectedCase || task.id === this.selectedCase)
},
filteredPositions() {
return this.selectedCase
? this.positions[this.selectedCase]
? { [this.selectedCase]: this.positions[this.selectedCase] }
: {}
: this.positions
},
reportRows() {
if (this.tab === 'zero') {
const rows = this.filteredDetails.flatMap(task =>
task.rows.flatMap(row => {
const types = Object.entries(row.marks)
.filter(([, value]) => value === 0)
.map(([type]) => type)
return types.length
? [
{
userId: row.userId,
user: row.expert + (row.role === 'technical' ? ' (тех.)' : ''),
task: task.name,
teams: [row.team],
criterion: types
.map(type => this.criteria[type] + ([20, 30].includes(+type) ? ' (тех.)' : ''))
.join(', '),
value: 0,
},
]
: []
})
)
return this.sortRows(rows, (row, key) => (key === 'teams' ? row.teams[0] : row[key]))
}
const data = this.noMarks
const rows = Object.entries(data).flatMap(([user, tasks]) =>
Object.entries(tasks)
.filter(([name]) => !this.selectedCase || name === this.cases[this.selectedCase])
.map(([task, teams]) => ({ user, task, teams }))
)
return this.sortRows(rows, (row, key) => (key === 'teams' ? row.teams.join(', ') : row[key]))
},
},
methods: {
sortBy(key) {
this.$set(this.sorts, this.tab, {
key,
direction: this.sorting.key === key && this.sorting.direction === 'asc' ? 'desc' : 'asc',
})
},
sortRows(rows, value) {
const { key, direction } = this.sorting
if (!key) return rows
return [...rows].sort((a, b) => {
const left = value(a, key)
const right = value(b, key)
if (left == null) return right == null ? 0 : 1
if (right == null) return -1
const result =
typeof left === 'number' && typeof right === 'number'
? left - right
: String(left).localeCompare(String(right), 'ru', { numeric: true, sensitivity: 'base' })
return direction === 'asc' ? result : -result
})
},
sortedDetails(rows) {
return this.sortRows(rows, (row, key) => (key.startsWith('mark:') ? row.marks[key.slice(5)] : row[key]))
},
sortedRanking(ranking) {
return this.sortRows(Object.entries(ranking), (row, key) => (key === 'place' ? row[1] : this.teams[row[0]]))
},
async refresh() {
this.refreshing = true
this.error = ''
try {
const [missing, ranking, detail] = await Promise.all([
this.$axios.$get('/admin/marks'),
this.$axios.$get('/admin/positions'),
this.$axios.$get('/admin/marks/details'),
])
Object.assign(this, missing, ranking, detail)
} catch (e) {
this.error = 'Не удалось обновить результаты.'
} finally {
this.refreshing = false
}
},
},
}
</script>