Files

74 lines
2.1 KiB
Vue

<template>
<div>
<div class="page-heading">
<h1>Кейсы</h1>
<button class="button button-primary" type="button" @click="editing = true">
<AppIcon name="plus" :size="16" /> Добавить кейс
</button>
</div>
<div class="panel">
<NuxtLink v-for="task in cases" :key="task.id" :to="'/admin/cases/' + task.id" class="simple-row"
><div class="case-row-label">
<CaseIcon :src="task.icon" />
<div>
<strong>{{ task.name }}</strong>
<p>{{ task.teams.length }} команд · {{ task.users.length }} экспертов</p>
</div>
</div>
<AppIcon name="arrow" :size="18"
/></NuxtLink>
<div v-if="!cases.length" class="table-empty">Кейсов пока нет.</div>
</div>
<FormDialog
v-if="editing"
title="Новый кейс"
:busy="saving"
submit-label="Добавить"
@close="
editing = false
error = ''
"
@save="save"
><label class="field" for="caseName"
><span>Название</span
><input id="caseName" v-model.trim="name" class="text-input" maxlength="255" required /></label
><label class="field" for="caseDescription"
><span>Описание</span
><textarea id="caseDescription" v-model.trim="description" class="text-input" maxlength="10000" rows="3" />
</label>
<CaseIconUpload v-model="icon" :disabled="saving" />
<div v-if="error" class="form-error" role="alert">{{ error }}</div></FormDialog
>
</div>
</template>
<script>
export default {
name: 'AdminCases',
async asyncData({ $axios }) {
return await $axios.$get('/admin/cases')
},
data() {
return { cases: [], editing: false, name: '', description: '', icon: null, saving: false, error: '' }
},
methods: {
async save() {
if (this.saving || !this.name) return
this.saving = true
this.error = ''
try {
const { case: task } = await this.$axios.$post('/admin/cases', {
name: this.name,
description: this.description,
icon: this.icon,
})
await this.$router.push('/admin/cases/' + task.id)
} catch (e) {
this.error = 'Не удалось добавить кейс.'
} finally {
this.saving = false
}
},
},
}
</script>