2020-10-31 04:29:34 -07:00
|
|
|
<template>
|
|
|
|
<Loading :value="nounsRaw">
|
2020-12-30 15:03:30 -08:00
|
|
|
<section v-if="$isGranted('nouns')" class="px-3">
|
2020-10-31 04:29:34 -07:00
|
|
|
<div class="alert alert-info">
|
|
|
|
<strong>{{ nounsCountApproved() }}</strong> <T>nouns.approved</T>,
|
|
|
|
<strong>{{ nounsCountPending() }}</strong> <T>nouns.pending</T>.
|
|
|
|
</div>
|
|
|
|
</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-10-31 04:29:34 -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-07-29 12:42:11 -07:00
|
|
|
<button class="btn btn-outline-success" @click="$refs.form.$el.scrollIntoView({block: 'center'})">
|
2021-01-22 14:54:24 -08:00
|
|
|
<Icon v="plus-circle"/>
|
|
|
|
<T>nouns.submit.action</T>
|
|
|
|
</button>
|
2020-10-31 04:29:34 -07:00
|
|
|
</div>
|
|
|
|
</section>
|
|
|
|
|
2021-07-24 10:18:39 -07:00
|
|
|
<Table :data="visibleNouns()" :columns="3" :marked="(el) => !el.approved" fixed ref="dictionarytable">
|
2020-10-31 04:29:34 -07:00
|
|
|
<template v-slot:header>
|
|
|
|
<th class="text-nowrap">
|
|
|
|
<Icon v="mars"/>
|
|
|
|
<T>nouns.masculine</T>
|
|
|
|
</th>
|
|
|
|
<th class="text-nowrap">
|
|
|
|
<Icon v="venus"/>
|
|
|
|
<T>nouns.feminine</T>
|
|
|
|
</th>
|
|
|
|
<th class="text-nowrap">
|
|
|
|
<Icon v="neuter"/>
|
|
|
|
<T>nouns.neuter</T>
|
|
|
|
</th>
|
2020-12-03 06:01:26 -08:00
|
|
|
<th></th>
|
2020-10-31 04:29:34 -07:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<template v-slot:row="s"><template v-if="s">
|
|
|
|
<td>
|
2021-11-29 10:25:23 -08:00
|
|
|
<Noun :noun="s.el" gender="masc"/>
|
2020-10-31 04:29:34 -07:00
|
|
|
|
|
|
|
<small v-if="s.el.base && nouns[s.el.base]">
|
|
|
|
<p><strong><T>nouns.edited</T>:</strong></p>
|
2021-11-29 10:25:23 -08:00
|
|
|
<Diff switchable>
|
|
|
|
<template v-slot:before><Noun :noun="nouns[s.el.base]" gender="masc"/></template>
|
|
|
|
<template v-slot:after><Noun :noun="s.el" gender="masc"/></template>
|
|
|
|
</Diff>
|
2020-10-31 04:29:34 -07:00
|
|
|
</small>
|
|
|
|
</td>
|
|
|
|
<td>
|
2021-11-29 10:25:23 -08:00
|
|
|
<Noun :noun="s.el" gender="fem"/>
|
2020-10-31 04:29:34 -07:00
|
|
|
|
|
|
|
<small v-if="s.el.base && nouns[s.el.base]">
|
|
|
|
<p><strong><T>nouns.edited</T>:</strong></p>
|
2021-11-29 10:25:23 -08:00
|
|
|
<Diff switchable>
|
|
|
|
<template v-slot:before><Noun :noun="nouns[s.el.base]" gender="fem"/></template>
|
|
|
|
<template v-slot:after><Noun :noun="s.el" gender="fem"/></template>
|
|
|
|
</Diff>
|
2020-10-31 04:29:34 -07:00
|
|
|
</small>
|
|
|
|
</td>
|
|
|
|
<td>
|
2021-11-29 10:25:23 -08:00
|
|
|
<Noun :noun="s.el" gender="neutr"/>
|
2020-10-31 04:29:34 -07:00
|
|
|
|
|
|
|
<small v-if="s.el.base && nouns[s.el.base]">
|
|
|
|
<p><strong><T>nouns.edited</T>:</strong></p>
|
2021-11-29 10:25:23 -08:00
|
|
|
<Diff switchable>
|
|
|
|
<template v-slot:before><Noun :noun="nouns[s.el.base]" gender="neutr"/></template>
|
|
|
|
<template v-slot:after><Noun :noun="s.el" gender="neutr"/></template>
|
|
|
|
</Diff>
|
2020-10-31 04:29:34 -07:00
|
|
|
</small>
|
2021-04-11 07:35:11 -07:00
|
|
|
|
|
|
|
<div v-if="s.el.sourcesData.length" class="div-three-columns">
|
|
|
|
<p><strong><T>sources.referenced</T>:</strong></p>
|
|
|
|
<ul class="list-unstyled">
|
|
|
|
<li v-for="source in s.el.sourcesData">
|
|
|
|
<Source :source="source"/>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
2020-10-31 04:29:34 -07:00
|
|
|
</td>
|
2020-12-03 06:01:26 -08:00
|
|
|
<td>
|
|
|
|
<ul class="list-unstyled list-btn-concise">
|
2021-07-24 12:55:33 -07:00
|
|
|
<template v-if="$isGranted('nouns')">
|
|
|
|
<li v-if="s.el.author" class="small">
|
|
|
|
<nuxt-link :to="`/@${s.el.author}`" class="btn btn-concise btn-outline-dark btn-sm m-1">
|
|
|
|
<Icon v="user"/>
|
|
|
|
<span class="btn-label">
|
2020-12-03 06:01:26 -08:00
|
|
|
<T>crud.author</T>:
|
|
|
|
@{{s.el.author}}
|
|
|
|
</span>
|
2021-07-24 12:55:33 -07:00
|
|
|
</nuxt-link>
|
|
|
|
</li>
|
2020-12-03 06:01:26 -08:00
|
|
|
<li v-if="!s.el.approved">
|
|
|
|
<button class="btn btn-concise btn-success btn-sm m-1" @click="approve(s.el)">
|
|
|
|
<Icon v="check"/>
|
|
|
|
<span class="btn-label"><T>crud.approve</T></span>
|
|
|
|
</button>
|
|
|
|
</li>
|
|
|
|
<li v-else @click="hide(s.el)">
|
|
|
|
<button class="btn btn-concise btn-outline-secondary btn-sm m-1">
|
|
|
|
<Icon v="times"/>
|
|
|
|
<span class="btn-label"><T>crud.hide</T></span>
|
|
|
|
</button>
|
|
|
|
</li>
|
|
|
|
<li>
|
|
|
|
<button class="btn btn-concise btn-outline-danger btn-sm m-1" @click="remove(s.el)">
|
|
|
|
<Icon v="trash"/>
|
|
|
|
<span class="btn-label"><T>crud.remove</T></span>
|
|
|
|
</button>
|
|
|
|
</li>
|
|
|
|
</template>
|
2020-10-31 04:29:34 -07:00
|
|
|
<li>
|
2020-12-03 06:01:26 -08:00
|
|
|
<button class="btn btn-concise btn-outline-primary btn-sm m-1" @click="edit(s.el)">
|
2020-10-31 04:29:34 -07:00
|
|
|
<Icon v="pen"/>
|
2020-12-03 06:01:26 -08:00
|
|
|
<span class="btn-label">
|
2020-12-30 15:03:30 -08:00
|
|
|
<T v-if="$isGranted('nouns')">crud.edit</T>
|
2020-12-03 06:01:26 -08:00
|
|
|
<T v-else>nouns.edit</T>
|
|
|
|
</span>
|
2020-10-31 04:29:34 -07:00
|
|
|
</button>
|
|
|
|
</li>
|
2021-08-28 14:44:30 -07:00
|
|
|
<li>
|
|
|
|
<a :href="`/api/nouns/${s.el.id}.png`" target="_blank" rel="noopener"
|
|
|
|
class="btn btn-concise btn-outline-primary btn-sm m-1"
|
|
|
|
>
|
|
|
|
<Icon v="image"/>
|
|
|
|
<span class="btn-label">
|
|
|
|
<T>nouns.image</T>
|
|
|
|
</span>
|
|
|
|
</a>
|
|
|
|
</li>
|
2020-10-31 04:29:34 -07:00
|
|
|
</ul>
|
|
|
|
</td>
|
|
|
|
</template></template>
|
|
|
|
|
|
|
|
<template v-slot:empty>
|
|
|
|
<Icon v="search"/>
|
|
|
|
<T>nouns.empty</T>
|
|
|
|
</template>
|
|
|
|
</Table>
|
|
|
|
|
2020-10-31 05:10:25 -07:00
|
|
|
<template v-if="config.nouns.submit">
|
|
|
|
<Separator icon="plus"/>
|
2020-10-31 04:29:34 -07:00
|
|
|
|
2020-10-31 05:10:25 -07:00
|
|
|
<div class="px-3">
|
2021-07-29 12:42:11 -07:00
|
|
|
<NounSubmitForm ref="form" style="scroll-padding-top: 2rem;"/>
|
2020-10-31 05:10:25 -07:00
|
|
|
</div>
|
|
|
|
</template>
|
2020-10-31 04:29:34 -07:00
|
|
|
</Loading>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import { Noun } from "~/src/classes";
|
|
|
|
import { buildDict } from "../src/helpers";
|
2020-12-17 13:18:18 -08:00
|
|
|
import hash from "../plugins/hash";
|
2020-10-31 04:29:34 -07:00
|
|
|
|
|
|
|
export default {
|
|
|
|
props: {
|
|
|
|
load: {type: Boolean}
|
|
|
|
},
|
2020-12-17 13:18:18 -08:00
|
|
|
mixins: [ hash ],
|
2020-10-31 04:29:34 -07:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
filter: '',
|
|
|
|
nounsRaw: undefined,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
if (this.load) {
|
|
|
|
this.loadNouns();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
async loadNouns() {
|
|
|
|
if (this.nounsRaw !== undefined) {
|
|
|
|
return;
|
|
|
|
}
|
2020-11-10 14:41:56 -08:00
|
|
|
this.nounsRaw = await this.$axios.$get(`/nouns`);
|
2020-10-31 04:29:34 -07:00
|
|
|
},
|
|
|
|
async setFilter(filter) {
|
|
|
|
this.filter = filter;
|
|
|
|
await this.loadNouns();
|
2021-07-10 03:32:53 -07:00
|
|
|
if (filter) {
|
|
|
|
this.focus();
|
|
|
|
}
|
2020-10-31 04:29:34 -07:00
|
|
|
},
|
|
|
|
focus() {
|
|
|
|
this.$el.focus();
|
|
|
|
this.$el.scrollIntoView();
|
|
|
|
setTimeout(_ => {
|
|
|
|
this.$el.scrollIntoView();
|
|
|
|
}, 1000);
|
|
|
|
},
|
|
|
|
edit(noun) {
|
|
|
|
this.$refs.form.edit(noun);
|
|
|
|
},
|
|
|
|
async approve(noun) {
|
2021-06-09 09:06:32 -07:00
|
|
|
await this.$post(`/nouns/approve/${noun.id}`);
|
2020-10-31 04:29:34 -07:00
|
|
|
if (noun.base) {
|
|
|
|
delete this.nouns[noun.base];
|
|
|
|
}
|
|
|
|
noun.approved = true;
|
|
|
|
noun.base = null;
|
|
|
|
this.$forceUpdate();
|
|
|
|
},
|
|
|
|
async hide(noun) {
|
2021-06-09 09:06:32 -07:00
|
|
|
await this.$post(`/nouns/hide/${noun.id}`);
|
2020-10-31 04:29:34 -07:00
|
|
|
noun.approved = false;
|
|
|
|
this.$forceUpdate();
|
|
|
|
},
|
|
|
|
async remove(noun) {
|
2020-12-05 11:37:10 -08:00
|
|
|
await this.$confirm(this.$t('crud.removeConfirm'), 'danger');
|
|
|
|
|
2021-06-09 09:06:32 -07:00
|
|
|
await this.$post(`/nouns/remove/${noun.id}`);
|
2020-10-31 04:29:34 -07:00
|
|
|
delete this.nouns[noun.id];
|
|
|
|
this.$forceUpdate();
|
|
|
|
},
|
|
|
|
|
|
|
|
// those must be methods, not computed, because when modified, they don't get updated in the view for some reason
|
|
|
|
visibleNouns() {
|
|
|
|
return Object.values(this.nouns).filter(n => n.matches(this.filter));
|
|
|
|
},
|
|
|
|
nounsCountApproved() {
|
|
|
|
return Object.values(this.nouns).filter(n => n.approved).length;
|
|
|
|
},
|
|
|
|
nounsCountPending() {
|
|
|
|
return Object.values(this.nouns).filter(n => !n.approved).length;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
nouns() {
|
|
|
|
if (this.nounsRaw === undefined) {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
return buildDict(function* (that) {
|
|
|
|
const sorted = that.nounsRaw.sort((a, b) => {
|
|
|
|
if (a.approved && !b.approved) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (!a.approved && b.approved) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return a.masc.toLowerCase().localeCompare(b.masc.toLowerCase());
|
|
|
|
});
|
|
|
|
for (let w of sorted) {
|
|
|
|
yield [w.id, new Noun(w)];
|
|
|
|
}
|
|
|
|
}, this);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
filter() {
|
2020-12-17 13:18:18 -08:00
|
|
|
this.setHash(this.config.nouns.hashNamespace || '', this.filter);
|
|
|
|
if (this.$refs.dictionarytable) {
|
|
|
|
this.$refs.dictionarytable.reset();
|
|
|
|
this.$refs.dictionarytable.focus();
|
2020-10-31 04:29:34 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss">
|
2020-11-11 13:53:55 -08:00
|
|
|
@import "assets/variables";
|
2020-10-31 04:29:34 -07:00
|
|
|
|
|
|
|
tr {
|
|
|
|
.hover-show {
|
|
|
|
opacity: 0;
|
|
|
|
}
|
|
|
|
&:hover .hover-show {
|
|
|
|
opacity: 1;
|
|
|
|
}
|
|
|
|
}
|
2020-12-03 06:01:26 -08:00
|
|
|
|
|
|
|
.btn-concise {
|
|
|
|
white-space: nowrap;
|
|
|
|
}
|
|
|
|
@include media-breakpoint-up('md', $grid-breakpoints) {
|
|
|
|
.list-btn-concise {
|
|
|
|
min-width: 3rem;
|
|
|
|
|
|
|
|
li {
|
|
|
|
height: 2.5rem;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.btn-concise {
|
|
|
|
position: absolute;
|
|
|
|
|
|
|
|
.btn-label {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
|
|
|
|
&:hover .btn-label {
|
|
|
|
display: inline;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-01-05 11:11:41 -08:00
|
|
|
|
|
|
|
.div-three-columns {
|
|
|
|
width: 300%;
|
2021-04-11 07:35:11 -07:00
|
|
|
position: relative;
|
|
|
|
left: -200%;
|
2021-01-05 11:11:41 -08:00
|
|
|
}
|
2020-10-31 04:29:34 -07:00
|
|
|
</style>
|