Include complete API and frontend sources for unified deployment
This commit is contained in:
1 parent
627b0ae60e
commit
d8fcae32b0
93 files changed
+53270
-3
No files matched your search
@@ -0,0 +1,369 @@
|
||||
<template>
|
||||
<div>
|
||||
<NuxtLink to="/admin" class="back-link"><AppIcon name="back" :size="15" /> Кейсы</NuxtLink>
|
||||
<div class="page-heading">
|
||||
<div class="case-title">
|
||||
<CaseIcon :src="task.icon" />
|
||||
<h1>{{ task.name }}</h1>
|
||||
</div>
|
||||
<button class="button" type="button" @click="editCase">Изменить</button>
|
||||
</div>
|
||||
<p v-if="task.description" class="plain-description">{{ task.description }}</p>
|
||||
<div class="section-heading">
|
||||
<h2>Команды</h2>
|
||||
<button class="button button-primary" type="button" @click="editTeam()">
|
||||
<AppIcon name="plus" :size="16" /> Добавить команду
|
||||
</button>
|
||||
</div>
|
||||
<div v-if="scoreError" class="form-error" role="alert">{{ scoreError }}</div>
|
||||
<div class="panel">
|
||||
<div class="table-scroll">
|
||||
<table class="data-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<SortHeader
|
||||
v-for="column in teamColumns"
|
||||
:key="column.key"
|
||||
:active="teamSortKey === column.key"
|
||||
:direction="teamSortDirection"
|
||||
@sort="sortTeamsBy(column.key)"
|
||||
>{{ column.name }}</SortHeader
|
||||
>
|
||||
<th scope="col"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="team in sortedTeams" :key="team.id">
|
||||
<td>
|
||||
<strong>{{ team.name }}</strong>
|
||||
<p v-if="team.description" class="table-description">{{ team.description }}</p>
|
||||
<p
|
||||
v-if="team.TeamInCase && team.TeamInCase.technicalComment"
|
||||
class="table-description technical-comment-text"
|
||||
>
|
||||
Комментарий тех. эксперта: {{ team.TeamInCase.technicalComment }}
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<input
|
||||
class="score-input"
|
||||
type="number"
|
||||
min="0"
|
||||
max="5"
|
||||
step="1"
|
||||
:value="implementation[team.id]"
|
||||
:aria-label="'Качество реализации — ' + team.name"
|
||||
:disabled="savingScores"
|
||||
@input="setScore(implementation, team.id, $event)"
|
||||
/>
|
||||
</td>
|
||||
<td>
|
||||
<input
|
||||
class="score-input"
|
||||
type="number"
|
||||
min="0"
|
||||
max="5"
|
||||
step="1"
|
||||
:value="work[team.id]"
|
||||
:aria-label="'Работа на хакатоне — ' + team.name"
|
||||
:disabled="savingScores"
|
||||
@input="setScore(work, team.id, $event)"
|
||||
/>
|
||||
</td>
|
||||
<td>
|
||||
<button
|
||||
class="button button-sm"
|
||||
type="button"
|
||||
:aria-label="'Изменить команду ' + team.name"
|
||||
@click="editTeam(team)"
|
||||
>
|
||||
Изменить
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
<tr v-if="!task.teams.length">
|
||||
<td colspan="4" class="table-empty">Команд пока нет.</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="task.teams.length" class="save-row">
|
||||
<span class="muted">{{
|
||||
task.users.length ? 'Оценки тех. экспертов · 0–5' : 'Сначала назначьте экспертов в разделе «Эксперты».'
|
||||
}}</span
|
||||
><button
|
||||
class="button button-primary"
|
||||
type="button"
|
||||
:disabled="savingScores || !task.users.length"
|
||||
@click="saveScores"
|
||||
>
|
||||
{{ savingScores ? 'Сохраняем…' : 'Сохранить оценки' }}
|
||||
</button>
|
||||
</div>
|
||||
<div class="section-heading" style="margin-top: 32px">
|
||||
<h2>Эксперты</h2>
|
||||
<div ref="assignmentPicker" class="assignment-picker" @keydown.esc.prevent.stop="closeAssignments">
|
||||
<button
|
||||
ref="assignmentButton"
|
||||
type="button"
|
||||
class="button button-sm"
|
||||
:aria-expanded="String(assignmentOpen)"
|
||||
aria-controls="case-expert-picker"
|
||||
:disabled="savingAssignments"
|
||||
@click="toggleAssignments"
|
||||
>
|
||||
Назначить
|
||||
</button>
|
||||
<div v-if="assignmentOpen" id="case-expert-picker" class="assignment-dropdown">
|
||||
<input
|
||||
v-model="expertSearch"
|
||||
class="text-input"
|
||||
type="search"
|
||||
aria-label="Найти эксперта"
|
||||
placeholder="Найти эксперта"
|
||||
/>
|
||||
<p v-if="loadingAssignments" class="muted">Загрузка…</p>
|
||||
<div v-else class="assignment-options">
|
||||
<label v-for="user in filteredAssignmentUsers" :key="user.id" class="checkbox-row">
|
||||
<input
|
||||
type="checkbox"
|
||||
:checked="isAssigned(user)"
|
||||
:disabled="savingAssignments"
|
||||
@change="setAssignment(user, $event)"
|
||||
/>
|
||||
<span
|
||||
>{{ [user.lastName, user.firstName, user.middleName].filter(Boolean).join(' ')
|
||||
}}{{ user.role === 'technical' ? ' · Технический эксперт' : '' }}</span
|
||||
>
|
||||
</label>
|
||||
<p v-if="!filteredAssignmentUsers.length" class="muted">Эксперты не найдены.</p>
|
||||
</div>
|
||||
<div v-if="assignmentError" class="form-error" role="alert">{{ assignmentError }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="panel">
|
||||
<div v-for="user in task.users" :key="user.id" class="simple-row">
|
||||
<span>{{ [user.lastName, user.firstName, user.middleName].filter(Boolean).join(' ') }}</span>
|
||||
<span v-if="user.role === 'technical'" class="badge">Технический эксперт</span>
|
||||
</div>
|
||||
<div v-if="!task.users.length" class="table-empty">Эксперты не назначены.</div>
|
||||
</div>
|
||||
<FormDialog
|
||||
v-if="editor"
|
||||
:title="editor === 'case' ? 'Изменить кейс' : teamId ? 'Изменить команду' : 'Новая команда'"
|
||||
:busy="saving"
|
||||
@close="editor = null"
|
||||
@save="save"
|
||||
><label class="field" for="entityName"
|
||||
><span>Название</span
|
||||
><input id="entityName" v-model.trim="name" class="text-input" maxlength="255" required /></label
|
||||
><label class="field" for="entityDescription"
|
||||
><span>Описание</span
|
||||
><textarea id="entityDescription" v-model.trim="description" class="text-input" maxlength="10000" rows="3" />
|
||||
</label>
|
||||
<CaseIconUpload v-if="editor === 'case'" v-model="icon" :disabled="saving" />
|
||||
<div v-if="error" class="form-error" role="alert">{{ error }}</div></FormDialog
|
||||
>
|
||||
<div v-if="message" class="toast" role="status">{{ message }}</div>
|
||||
</div>
|
||||
</template>
|
||||
<script>
|
||||
export default {
|
||||
name: 'CaseDetails',
|
||||
async asyncData({ $axios, params, error }) {
|
||||
const [{ cases }, { marks }] = await Promise.all([$axios.$get('/admin/cases'), $axios.$get('/admin')])
|
||||
const task = cases.find(c => c.id === params.id)
|
||||
if (!task) {
|
||||
error({ statusCode: 404, message: 'Кейс не найден' })
|
||||
return {}
|
||||
}
|
||||
return { task, implementation: marks.implementation, work: marks.work }
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
task: { name: '', teams: [], users: [] },
|
||||
implementation: {},
|
||||
work: {},
|
||||
editor: null,
|
||||
teamId: null,
|
||||
name: '',
|
||||
description: '',
|
||||
icon: null,
|
||||
saving: false,
|
||||
error: '',
|
||||
savingScores: false,
|
||||
scoreError: '',
|
||||
message: '',
|
||||
timer: null,
|
||||
assignmentOpen: false,
|
||||
assignmentUsers: [],
|
||||
expertSearch: '',
|
||||
loadingAssignments: false,
|
||||
savingAssignments: false,
|
||||
assignmentError: '',
|
||||
teamSortKey: 'name',
|
||||
teamSortDirection: 'asc',
|
||||
teamColumns: [
|
||||
{ key: 'name', name: 'Команда' },
|
||||
{ key: 'implementation', name: 'Качество реализации (тех.)' },
|
||||
{ key: 'work', name: 'Работа на хакатоне (тех.)' },
|
||||
],
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
sortedTeams() {
|
||||
const direction = this.teamSortDirection === 'asc' ? 1 : -1
|
||||
return [...this.task.teams].sort((a, b) => {
|
||||
const nameOrder = a.name.localeCompare(b.name, 'ru', { numeric: true, sensitivity: 'base' })
|
||||
if (this.teamSortKey === 'name') return direction * nameOrder
|
||||
const left = this[this.teamSortKey][a.id]
|
||||
const right = this[this.teamSortKey][b.id]
|
||||
const leftMissing = left === null || left === undefined || left === ''
|
||||
const rightMissing = right === null || right === undefined || right === ''
|
||||
if (leftMissing || rightMissing) return leftMissing === rightMissing ? nameOrder : leftMissing ? 1 : -1
|
||||
return direction * (Number(left) - Number(right)) || nameOrder
|
||||
})
|
||||
},
|
||||
filteredAssignmentUsers() {
|
||||
const search = this.expertSearch.trim().toLowerCase()
|
||||
return this.assignmentUsers.filter(user =>
|
||||
[user.lastName, user.firstName, user.middleName].filter(Boolean).join(' ').toLowerCase().includes(search)
|
||||
)
|
||||
},
|
||||
},
|
||||
mounted() {
|
||||
document.addEventListener('click', this.assignmentOutsideClick)
|
||||
},
|
||||
beforeDestroy() {
|
||||
clearTimeout(this.timer)
|
||||
document.removeEventListener('click', this.assignmentOutsideClick)
|
||||
},
|
||||
methods: {
|
||||
sortTeamsBy(key) {
|
||||
this.teamSortDirection = this.teamSortKey === key && this.teamSortDirection === 'asc' ? 'desc' : 'asc'
|
||||
this.teamSortKey = key
|
||||
},
|
||||
isAssigned(user) {
|
||||
return user.cases.some(task => task.id === this.task.id)
|
||||
},
|
||||
closeAssignments() {
|
||||
if (this.savingAssignments) return
|
||||
this.assignmentOpen = false
|
||||
this.$refs.assignmentButton?.focus()
|
||||
},
|
||||
assignmentOutsideClick(event) {
|
||||
if (!this.savingAssignments && !this.$refs.assignmentPicker?.contains(event.target)) this.assignmentOpen = false
|
||||
},
|
||||
async toggleAssignments() {
|
||||
this.assignmentOpen = !this.assignmentOpen
|
||||
if (!this.assignmentOpen) return
|
||||
this.expertSearch = ''
|
||||
this.assignmentError = ''
|
||||
this.loadingAssignments = true
|
||||
try {
|
||||
const { users } = await this.$axios.$get('/admin/users')
|
||||
this.assignmentUsers = users.filter(user => !user.deletedAt)
|
||||
} catch (e) {
|
||||
this.assignmentUsers = []
|
||||
this.assignmentError = 'Не удалось загрузить экспертов.'
|
||||
} finally {
|
||||
this.loadingAssignments = false
|
||||
}
|
||||
},
|
||||
async setAssignment(user, event) {
|
||||
if (this.savingAssignments) return
|
||||
const checked = event.target.checked
|
||||
const caseIds = user.cases.filter(task => task.id !== this.task.id).map(task => task.id)
|
||||
if (checked) caseIds.push(this.task.id)
|
||||
this.savingAssignments = true
|
||||
this.assignmentError = ''
|
||||
try {
|
||||
await this.$axios.$put('/admin/users/' + user.id + '/cases', { caseIds })
|
||||
user.cases = user.cases.filter(task => task.id !== this.task.id)
|
||||
this.task.users = this.task.users.filter(expert => expert.id !== user.id)
|
||||
if (checked) {
|
||||
user.cases.push({ id: this.task.id, name: this.task.name })
|
||||
const { id, firstName, lastName, middleName, login, role } = user
|
||||
this.task.users.push({ id, firstName, lastName, middleName, login, role })
|
||||
}
|
||||
} catch (e) {
|
||||
event.target.checked = this.isAssigned(user)
|
||||
this.assignmentError = e.response?.data?.message || 'Не удалось сохранить назначение. Попробуйте ещё раз.'
|
||||
} finally {
|
||||
this.savingAssignments = false
|
||||
}
|
||||
},
|
||||
async reload() {
|
||||
const { cases } = await this.$axios.$get('/admin/cases')
|
||||
this.task = cases.find(c => c.id === this.$route.params.id)
|
||||
},
|
||||
editCase() {
|
||||
this.editor = 'case'
|
||||
this.name = this.task.name
|
||||
this.description = this.task.description
|
||||
this.icon = this.task.icon || null
|
||||
this.error = ''
|
||||
},
|
||||
editTeam(team) {
|
||||
this.editor = 'team'
|
||||
this.teamId = team?.id || null
|
||||
this.name = team?.name || ''
|
||||
this.description = team?.description || ''
|
||||
this.error = ''
|
||||
},
|
||||
async save() {
|
||||
if (this.saving || !this.name) return
|
||||
this.saving = true
|
||||
this.error = ''
|
||||
try {
|
||||
const body = { name: this.name, description: this.description || '' }
|
||||
const base = '/admin/cases/' + this.task.id
|
||||
if (this.editor === 'case') await this.$axios.$put(base, { ...body, icon: this.icon })
|
||||
else if (this.teamId) await this.$axios.$put(base + '/teams/' + this.teamId, body)
|
||||
else await this.$axios.$post(base + '/teams', body)
|
||||
await this.reload()
|
||||
this.editor = null
|
||||
} catch (e) {
|
||||
this.error = 'Не удалось сохранить изменения.'
|
||||
} finally {
|
||||
this.saving = false
|
||||
}
|
||||
},
|
||||
setScore(target, id, event) {
|
||||
const value =
|
||||
event.target.value === '' ? '' : Math.min(5, Math.max(0, Math.round(Number(event.target.value) || 0)))
|
||||
this.$set(target, id, value)
|
||||
event.target.value = value
|
||||
},
|
||||
async saveScores() {
|
||||
if (this.savingScores) return
|
||||
this.scoreError = ''
|
||||
const values = this.task.teams.map(team => ({
|
||||
id: team.id,
|
||||
implementation: this.implementation[team.id],
|
||||
work: this.work[team.id],
|
||||
}))
|
||||
const filled = value => value !== '' && value !== undefined && value !== null
|
||||
if (values.some(m => filled(m.implementation) !== filled(m.work))) {
|
||||
this.scoreError = 'Заполните оба критерия для команды.'
|
||||
return
|
||||
}
|
||||
this.savingScores = true
|
||||
try {
|
||||
await this.$axios.$post('/admin', { marks: values.filter(m => filled(m.implementation) && filled(m.work)) })
|
||||
this.message = 'Оценки сохранены'
|
||||
clearTimeout(this.timer)
|
||||
this.timer = setTimeout(() => {
|
||||
this.message = ''
|
||||
}, 3500)
|
||||
} catch (e) {
|
||||
this.scoreError = 'Не удалось сохранить оценки.'
|
||||
} finally {
|
||||
this.savingScores = false
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
</script>
|
||||
Reference in new issue
Block a user