2020-09-29 08:59:23 -07:00
|
|
|
<template>
|
2020-11-29 02:03:01 -08:00
|
|
|
<div>
|
2020-09-29 08:59:23 -07:00
|
|
|
<h2>
|
|
|
|
<Icon v="signature"/>
|
|
|
|
<T>names.headerLong</T>
|
|
|
|
</h2>
|
|
|
|
|
|
|
|
<section>
|
|
|
|
<T>names.intro</T>
|
2021-09-25 05:55:53 -07:00
|
|
|
<NamesLinks/>
|
2020-09-29 08:59:23 -07:00
|
|
|
</section>
|
|
|
|
|
|
|
|
<section class="sticky-top">
|
|
|
|
<div class="input-group mb-3 bg-white">
|
2021-01-22 14:54:24 -08:00
|
|
|
<span class="input-group-text">
|
|
|
|
<Icon v="filter"/>
|
|
|
|
</span>
|
2020-09-29 08:59:23 -07:00
|
|
|
<input class="form-control border-primary" v-model="filter" :placeholder="$t('crud.filterLong')" ref="filter"/>
|
2021-01-22 14:54:24 -08:00
|
|
|
<button v-if="filter" class="btn btn-outline-danger" @click="filter = ''; $refs.filter.focus()">
|
|
|
|
<Icon v="times"/>
|
|
|
|
</button>
|
2021-09-25 05:55:53 -07:00
|
|
|
<button class="btn btn-outline-success" @click="$refs.form.$el.scrollIntoView({block: 'center'})">
|
|
|
|
<Icon v="plus-circle"/>
|
|
|
|
<T>nouns.submit.action</T>
|
|
|
|
</button>
|
2020-09-29 08:59:23 -07:00
|
|
|
</div>
|
|
|
|
</section>
|
|
|
|
|
|
|
|
<section>
|
|
|
|
<ul class="list-group small">
|
|
|
|
<template v-if="visibleNames().length">
|
2021-09-25 05:55:53 -07:00
|
|
|
<li v-for="name in visibleNames()" :class="['list-group-item', name.approved ? '' : 'marked']">
|
|
|
|
<Name :name="name">
|
|
|
|
<ul class="list-inline small">
|
|
|
|
<template v-if="$isGranted('names')">
|
|
|
|
<li v-if="name.author" class="list-inline-item small">
|
|
|
|
<nuxt-link :to="`/@${name.author}`" class="btn btn-outline-dark btn-sm">
|
|
|
|
<Icon v="user"/>
|
|
|
|
<span class="btn-label">
|
|
|
|
<T>crud.author</T>:
|
|
|
|
@{{name.author}}
|
|
|
|
</span>
|
|
|
|
</nuxt-link>
|
|
|
|
</li>
|
|
|
|
<li v-if="!name.approved" class="list-inline-item">
|
|
|
|
<button class="btn btn-success btn-sm" @click="approve(name)">
|
|
|
|
<Icon v="check"/>
|
|
|
|
<span class="btn-label"><T>crud.approve</T></span>
|
|
|
|
</button>
|
|
|
|
</li>
|
|
|
|
<li v-else @click="hide(name)" class="list-inline-item">
|
|
|
|
<button class="btn btn-outline-secondary btn-sm">
|
|
|
|
<Icon v="times"/>
|
|
|
|
<span class="btn-label"><T>crud.hide</T></span>
|
|
|
|
</button>
|
|
|
|
</li>
|
|
|
|
<li class="list-inline-item">
|
|
|
|
<button class="btn btn-outline-danger btn-sm" @click="remove(name)">
|
|
|
|
<Icon v="trash"/>
|
|
|
|
<span class="btn-label"><T>crud.remove</T></span>
|
|
|
|
</button>
|
|
|
|
</li>
|
|
|
|
</template>
|
|
|
|
<li class="list-inline-item">
|
|
|
|
<button class="btn btn-outline-primary btn-sm" @click="edit(name)">
|
|
|
|
<Icon v="pen"/>
|
|
|
|
<span class="btn-label">
|
|
|
|
<T v-if="$isGranted('names')">crud.edit</T>
|
|
|
|
<T v-else>nouns.edit</T>
|
|
|
|
</span>
|
|
|
|
</button>
|
2020-09-29 08:59:23 -07:00
|
|
|
</li>
|
|
|
|
</ul>
|
2021-09-25 05:55:53 -07:00
|
|
|
</Name>
|
|
|
|
|
|
|
|
<small v-if="name.base && names[name.base]">
|
|
|
|
<hr/>
|
|
|
|
<p><strong><T>nouns.edited</T>:</strong></p>
|
2021-11-29 10:25:23 -08:00
|
|
|
<Diff switchable>
|
|
|
|
<template v-slot:before><Name :name="names[name.base]"/></template>
|
|
|
|
<template v-slot:after><Name :name="name"/></template>
|
|
|
|
</Diff>
|
2021-09-25 05:55:53 -07:00
|
|
|
</small>
|
2020-09-29 08:59:23 -07:00
|
|
|
</li>
|
|
|
|
</template>
|
|
|
|
<template v-else>
|
|
|
|
<li class="list-group-item text-center">
|
|
|
|
<Icon v="search"/>
|
|
|
|
<T>names.empty</T>
|
|
|
|
</li>
|
|
|
|
</template>
|
|
|
|
</ul>
|
|
|
|
</section>
|
|
|
|
|
2021-09-25 05:55:53 -07:00
|
|
|
<Separator icon="plus"/>
|
|
|
|
|
|
|
|
<section class="px-3">
|
|
|
|
<NameSubmitForm ref="form" style="scroll-padding-top: 2rem;"/>
|
|
|
|
</section>
|
2020-09-29 08:59:23 -07:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2021-09-25 05:55:53 -07:00
|
|
|
import {head, buildDict} from '~/src/helpers';
|
2020-12-17 13:18:18 -08:00
|
|
|
import hash from "../plugins/hash";
|
2021-09-25 05:55:53 -07:00
|
|
|
import {Name} from "../src/classes";
|
2020-09-29 08:59:23 -07:00
|
|
|
|
|
|
|
export default {
|
2020-12-17 13:18:18 -08:00
|
|
|
mixins: [ hash ],
|
2020-09-29 08:59:23 -07:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
filter: '',
|
|
|
|
}
|
|
|
|
},
|
2021-09-25 05:55:53 -07:00
|
|
|
async asyncData({app}) {
|
|
|
|
return {
|
|
|
|
namesRaw: await app.$axios.$get(`/names`),
|
|
|
|
}
|
|
|
|
},
|
2020-09-29 08:59:23 -07:00
|
|
|
mounted() {
|
2020-12-17 13:18:18 -08:00
|
|
|
this.handleHash('', filter => {
|
|
|
|
this.filter = filter;
|
2021-09-25 05:55:53 -07:00
|
|
|
if (filter) {
|
|
|
|
this.$refs.filter.focus();
|
2020-09-29 08:59:23 -07:00
|
|
|
this.$refs.filter.scrollIntoView();
|
2021-09-25 05:55:53 -07:00
|
|
|
setTimeout(_ => {
|
|
|
|
this.$refs.filter.scrollIntoView();
|
|
|
|
}, 1000);
|
|
|
|
}
|
2020-12-17 13:18:18 -08:00
|
|
|
});
|
2020-09-29 08:59:23 -07:00
|
|
|
},
|
2021-09-25 05:55:53 -07:00
|
|
|
computed: {
|
|
|
|
names() {
|
|
|
|
if (this.namesRaw === undefined) {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
return buildDict(function* (that) {
|
|
|
|
const sorted = that.namesRaw.sort((a, b) => {
|
|
|
|
if (a.approved && !b.approved) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (!a.approved && b.approved) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return a.name.toLowerCase().localeCompare(b.name.toLowerCase());
|
|
|
|
});
|
|
|
|
for (let n of sorted) {
|
|
|
|
yield [n.id, new Name(n)];
|
|
|
|
}
|
|
|
|
}, this);
|
|
|
|
},
|
|
|
|
},
|
2020-09-29 08:59:23 -07:00
|
|
|
methods: {
|
|
|
|
visibleNames() {
|
2021-09-25 05:55:53 -07:00
|
|
|
return Object.values(this.names).filter(n => n.matches(this.filter));
|
|
|
|
},
|
|
|
|
edit(name) {
|
|
|
|
this.$refs.form.edit(name);
|
|
|
|
},
|
|
|
|
async approve(name) {
|
|
|
|
await this.$post(`/names/approve/${name.id}`);
|
|
|
|
if (name.base) {
|
|
|
|
delete this.names[name.base];
|
|
|
|
}
|
|
|
|
name.approved = true;
|
|
|
|
name.base = null;
|
|
|
|
this.$forceUpdate();
|
|
|
|
},
|
|
|
|
async hide(name) {
|
|
|
|
await this.$post(`/names/hide/${name.id}`);
|
|
|
|
name.approved = false;
|
|
|
|
this.$forceUpdate();
|
|
|
|
},
|
|
|
|
async remove(name) {
|
|
|
|
await this.$confirm(this.$t('crud.removeConfirm'), 'danger');
|
|
|
|
|
|
|
|
await this.$post(`/names/remove/${name.id}`);
|
|
|
|
delete this.names[name.id];
|
|
|
|
this.$forceUpdate();
|
2020-09-29 08:59:23 -07:00
|
|
|
},
|
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
filter() {
|
2020-12-17 13:18:18 -08:00
|
|
|
this.setHash('', this.filter);
|
2020-09-29 08:59:23 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
head() {
|
|
|
|
return head({
|
|
|
|
title: this.$t('names.headerLong'),
|
|
|
|
description: this.$t('names.description'),
|
|
|
|
});
|
|
|
|
},
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss">
|
2020-11-23 14:14:31 -08:00
|
|
|
@import "assets/variables";
|
2020-09-29 08:59:23 -07:00
|
|
|
|
|
|
|
@include media-breakpoint-up('md') {
|
|
|
|
.w-md-50 {
|
|
|
|
width: 50%;
|
|
|
|
}
|
|
|
|
}
|
2021-09-25 05:55:53 -07:00
|
|
|
|
|
|
|
.list-group-item.marked {
|
|
|
|
border-inline-start: 3px solid $primary;
|
|
|
|
}
|
2020-09-29 08:59:23 -07:00
|
|
|
</style>
|