Added compact revision overview, formatting duration. Preventing rejected revisions from being reviewed again.

This commit is contained in:
DebaucheryLibrarian 2024-10-08 21:30:55 +02:00
parent 9e87c47b24
commit 067d414cd9
8 changed files with 323 additions and 136 deletions

View File

@ -1,7 +1,7 @@
<template> <template>
<div class="page"> <div class="page">
<div <div
v-if="interactive" v-if="context === 'admin'"
class="revs-header" class="revs-header"
> >
<Checkbox <Checkbox
@ -11,13 +11,20 @@
/> />
</div> </div>
<ul class="revs nolist"> <ul
class="revs nolist"
:class="{ [`revs-${context}`]: true }"
>
<li <li
v-for="rev in curatedRevisions" v-for="rev in curatedRevisions"
:key="`rev-${rev.id}`" :key="`rev-${rev.id}`"
class="rev" class="rev"
:class="{ reviewed: reviewedRevisions.has(rev.id) }" :class="{
reviewed: reviewedRevisions.has(rev.id),
expanded: context === 'admin' || expanded.has(rev.id)
}"
> >
<template v-if="context === 'admin' || expanded.has(rev.id)">
<div class="rev-header"> <div class="rev-header">
<a <a
:href="`/scene/${rev.sceneId}`" :href="`/scene/${rev.sceneId}`"
@ -47,7 +54,7 @@
<div class="rev-actions noshrink"> <div class="rev-actions noshrink">
<span <span
v-if="rev.review" v-if="rev.review && context === 'admin'"
class="approved" class="approved"
:class="{ rejected: !rev.review.isApproved }" :class="{ rejected: !rev.review.isApproved }"
>{{ rev.review.isApproved ? 'Approved' : 'Rejected' }} by&nbsp;<a >{{ rev.review.isApproved ? 'Approved' : 'Rejected' }} by&nbsp;<a
@ -56,7 +63,7 @@
class="nolink" class="nolink"
>{{ rev.review.username }}</a>&nbsp;{{ format(rev.review.reviewedAt, 'yyyy-MM-dd hh:mm') }}</span> >{{ rev.review.username }}</a>&nbsp;{{ format(rev.review.reviewedAt, 'yyyy-MM-dd hh:mm') }}</span>
<template v-else-if="interactive"> <template v-else-if="context === 'admin'">
<Icon <Icon
v-tooltip="`Ban user from submitting revisions`" v-tooltip="`Ban user from submitting revisions`"
icon="user-block" icon="user-block"
@ -76,15 +83,14 @@
placeholder="Feedback" placeholder="Feedback"
class="input" class="input"
> >
</template>
<Icon <Icon
v-if="(!rev.review || !rev.review.isApproved) && interactive"
v-tooltip="`Approve and apply revision`" v-tooltip="`Approve and apply revision`"
icon="checkmark" icon="checkmark"
class="review-approve" class="review-approve"
@click="reviewRevision(rev, true)" @click="reviewRevision(rev, true)"
/> />
</template>
</div> </div>
</div> </div>
@ -142,6 +148,54 @@
> >
{{ rev.comment }} {{ rev.comment }}
</div> </div>
</template>
<div
v-else
class="rev-compact"
@click="expanded.add(rev.id)"
>
<span class="rev-scene nolink noshrink"><template v-if="context !== 'scene'">{{ rev.sceneId }}</template>@{{ rev.hash.slice(0, 6) }}</span>
<span
v-if="context !== 'scene'"
class="rev-title nolink ellipsis"
>{{ rev.base.title }}</span>
<span class="rev-summary">
<span
v-if="rev.comment"
class="summary-comment ellipsis"
>{{ rev.comment }}</span>
<span class="summary-deltas ellipsis">{{ rev.deltas.map((delta) => delta.key).join(', ') }}</span>
</span>
<div class="rev-details noshrink">
<a
v-if="rev.user && context !== 'user'"
:href="`/user/${rev.user.username}`"
target="_blank"
class="rev-username nolink ellipsis"
@click.stop
>{{ rev.user.username }}</a>
<a
v-if="rev.user && context !== 'user'"
v-tooltip="rev.user.username"
:href="`/user/${rev.user.username}`"
target="_blank"
class="rev-avatar nolink ellipsis"
@click.stop
><Icon icon="user3-long" /></a>
<time
:datetime="rev.createdAt"
class="rev-created"
>{{ format(rev.createdAt, 'yyyy-MM-dd hh:mm') }}</time>
</div>
</div>
</li> </li>
</ul> </ul>
</div> </div>
@ -154,11 +208,12 @@ import { format } from 'date-fns';
import Checkbox from '#/components/form/checkbox.vue'; import Checkbox from '#/components/form/checkbox.vue';
import { get, post } from '#/src/api.js'; import { get, post } from '#/src/api.js';
import { formatDuration } from '#/utils/format.js';
defineProps({ defineProps({
interactive: { context: {
type: Boolean, type: String,
default: false, default: 'admin',
}, },
}); });
@ -176,6 +231,7 @@ const moviesById = computed(() => Object.fromEntries(movies.value.map((movie) =>
const feedbacks = ref({}); const feedbacks = ref({});
const showReviewed = ref(false); const showReviewed = ref(false);
const reviewedRevisions = ref(new Set()); const reviewedRevisions = ref(new Set());
const expanded = ref(new Set());
const mappedKeys = { const mappedKeys = {
actors: actorsById, actors: actorsById,
@ -189,6 +245,10 @@ const dateKeys = [
'createdAt', 'createdAt',
]; ];
const curatedKeys = {
duration: (duration) => formatDuration(duration),
};
const curatedRevisions = computed(() => revisions.value.map((revision) => { const curatedRevisions = computed(() => revisions.value.map((revision) => {
const curatedBase = Object.fromEntries(Object.entries(revision.base).map(([key, value]) => { const curatedBase = Object.fromEntries(Object.entries(revision.base).map(([key, value]) => {
if (Array.isArray(value) && mappedKeys[key]) { if (Array.isArray(value) && mappedKeys[key]) {
@ -203,6 +263,10 @@ const curatedRevisions = computed(() => revisions.value.map((revision) => {
return [key, new Date(value)]; return [key, new Date(value)];
} }
if (curatedKeys[key]) {
return [key, curatedKeys[key](value)];
}
return [key, value]; return [key, value];
})); }));
@ -225,6 +289,13 @@ const curatedRevisions = computed(() => revisions.value.map((revision) => {
}; };
} }
if (curatedKeys[delta.key]) {
return {
...delta,
value: curatedKeys[delta.key](delta.value),
};
}
return delta; return delta;
}); });
@ -267,8 +338,6 @@ async function reviewRevision(revision, isApproved) {
} }
async function banEditor(revision) { async function banEditor(revision) {
console.log('ban!', revision);
await post('/bans', { await post('/bans', {
userId: revision.user.id, userId: revision.user.id,
banIp: true, banIp: true,
@ -302,15 +371,19 @@ async function banEditor(revision) {
} }
.rev { .rev {
min-width: 1200px;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
background: var(--background); background: var(--background);
border-radius: .25rem; border-radius: .25rem;
margin-bottom: .5rem;
box-shadow: 0 0 3px var(--shadow-weak-30); box-shadow: 0 0 3px var(--shadow-weak-30);
margin-bottom: .25rem;
font-size: .9rem; font-size: .9rem;
&.expanded {
min-width: 1200px;
margin-bottom: .5rem;
}
&.reviewed { &.reviewed {
pointer-events: none; pointer-events: none;
opacity: .5; opacity: .5;
@ -322,8 +395,6 @@ async function banEditor(revision) {
} }
.rev-link { .rev-link {
color: var(--glass-strong-10);
&:hover { &:hover {
color: var(--primary); color: var(--primary);
text-decoration: underline; text-decoration: underline;
@ -343,10 +414,11 @@ async function banEditor(revision) {
box-sizing: border-box; box-sizing: border-box;
padding: .5rem .5rem; padding: .5rem .5rem;
align-items: center; align-items: center;
color: var(--glass-strong-10);
} }
.rev-title { .rev-title {
color: inherit;
padding: .5rem 0; padding: .5rem 0;
} }
@ -360,7 +432,10 @@ async function banEditor(revision) {
} }
.rev-username { .rev-username {
display: flex;
align-items: center;
font-weight: bold; font-weight: bold;
height: 100%;
} }
.rev-actions { .rev-actions {
@ -485,4 +560,74 @@ async function banEditor(revision) {
padding: .5rem .5rem; padding: .5rem .5rem;
border-top: solid 1px var(--glass-weak-30); border-top: solid 1px var(--glass-weak-30);
} }
.rev-compact {
display: flex;
align-items: stretch;
cursor: pointer;
.rev-title {
width: 15rem;
margin-right: 2rem;
}
.rev-details {
flex-grow: 0;
}
.rev-avatar {
display: none;
.icon {
fill: var(--glass);
}
}
}
.revs-scene .rev-compact .rev-scene {
width: 6rem;
}
.rev-summary {
display: flex;
align-items: center;
flex-grow: 1;
overflow: hidden;
}
.summary-comment {
padding-right: .5rem;
border-right: solid 1px var(--glass-weak-20);
margin-right: .5rem;
}
.summary-deltas {
font-style: italic;
}
@media(--compact) {
.rev-compact .rev-details {
gap: .5rem;
}
.rev-compact .rev-username {
display: none;
}
.rev-compact .rev-avatar {
display: block;
}
}
@media(--small) {
.rev-compact .summary-comment {
padding: 0;
border: none;
margin: 0;
& + .summary-deltas {
display: none;
}
}
}
</style> </style>

View File

@ -1,7 +1,7 @@
<template> <template>
<Admin class="page"> <Admin class="page">
<Revisions <Revisions
:interactive="true" context="admin"
/> />
</Admin> </Admin>
</template> </template>

View File

@ -227,6 +227,14 @@
<template v-if="qualities[scene.qualities[0]]">{{ qualities[scene.qualities[0]] }} ({{ scene.qualities[0] }}p)</template> <template v-if="qualities[scene.qualities[0]]">{{ qualities[scene.qualities[0]] }} ({{ scene.qualities[0] }}p)</template>
<template v-else>{{ scene.qualities[0] }}p</template> <template v-else>{{ scene.qualities[0] }}p</template>
</div> </div>
<div
v-if="scene.photoCount"
class="detail"
>
<h3 class="heading">Photos</h3>
{{ scene.photoCount }}
</div>
</div> </div>
<div <div
@ -321,11 +329,11 @@
</div> </div>
<div <div
v-if="user && user.role !== 'user'"
class="scene-actions section" class="scene-actions section"
> >
<a <a
:href="`/scene/edit/${scene.id}`" v-if="user && user.role !== 'user'"
:href="`/scene/edit/${scene.id}/${scene.slug}`"
target="_blank" target="_blank"
class="link" class="link"
>Edit scene</a> >Edit scene</a>

View File

@ -3,14 +3,21 @@
<div class="revs-header"> <div class="revs-header">
<h2 class="heading">Revisions for "{{ scene.title }}"</h2> <h2 class="heading">Revisions for "{{ scene.title }}"</h2>
<div class="revs-actions">
<a
:href="`/scene/edit/${scene.id}/${scene.slug}`"
class="link"
>Edit scene</a>
<a <a
:href="`/scene/${scene.id}/${scene.slug}`" :href="`/scene/${scene.id}/${scene.slug}`"
target="_blank" target="_blank"
class="link" class="link"
>Go to scene</a> >Go to scene</a>
</div> </div>
</div>
<Revisions /> <Revisions context="scene" />
</div> </div>
</template> </template>
@ -33,5 +40,23 @@ const scene = pageContext.pageProps.scene;
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
align-items: center; align-items: center;
.heading {
line-height: 1.5;
}
}
.revs-actions {
display: flex;
gap: 2rem;
flex-shrink: 0;
}
@media(--compact) {
.revs-header {
display: flex;
flex-direction: column;
margin-bottom: 1rem;
}
} }
</style> </style>

View File

@ -58,7 +58,7 @@
class="profile-section revisions" class="profile-section revisions"
> >
<h3 class="section-header heading">Revisions</h3> <h3 class="section-header heading">Revisions</h3>
<Revisions /> <Revisions context="user" />
</div> </div>
</div> </div>
</template> </template>

View File

@ -114,6 +114,7 @@ function curateScene(rawScene, assets) {
priority: tag.priority, priority: tag.priority,
})), })),
qualities: rawScene.qualities?.sort((qualityA, qualityB) => qualityB - qualityA) || [], qualities: rawScene.qualities?.sort((qualityA, qualityB) => qualityB - qualityA) || [],
photoCount: rawScene.photo_count,
movies: assets.movies.map((movie) => ({ movies: assets.movies.map((movie) => ({
id: movie.id, id: movie.id,
slug: movie.slug, slug: movie.slug,
@ -814,9 +815,9 @@ export async function reviewSceneRevision(revisionId, isApproved, { feedback },
throw new HttpError('You must either approve or reject the revision', 400); throw new HttpError('You must either approve or reject the revision', 400);
} }
await knexOwner('scenes_revisions') const updated = await knexOwner('scenes_revisions')
.where('id', revisionId) .where('id', revisionId)
.whereRaw('approved is not true') // don't rerun approved and applied revision, must be forked into new revision instead .whereNull('approved') // don't rerun reviewed revision, must be forked into new revision instead
.whereNull('applied_at') .whereNull('applied_at')
.update({ .update({
approved: isApproved, approved: isApproved,
@ -825,6 +826,10 @@ export async function reviewSceneRevision(revisionId, isApproved, { feedback },
feedback, feedback,
}); });
if (updated === 0) {
throw new HttpError('This revision was already reviewed', 409);
}
if (isApproved) { if (isApproved) {
await applySceneRevision([revisionId]); await applySceneRevision([revisionId]);
} }

2
static

@ -1 +1 @@
Subproject commit cb3f99c5dcc35c9d492658a228709f9e1af29398 Subproject commit 0f7fc7c9f4ba7454bb92482eaffd93b345ea9834

View File

@ -1,6 +1,10 @@
import { format } from 'date-fns'; import { format } from 'date-fns';
export function formatDuration(duration, forceHours) { export function formatDuration(duration, forceHours) {
if (typeof duration !== 'number') {
return duration;
}
const hours = Math.floor(duration / 3600); const hours = Math.floor(duration / 3600);
const minutes = Math.floor((duration % 3600) / 60); const minutes = Math.floor((duration % 3600) / 60);
const seconds = Math.floor(duration % 60); const seconds = Math.floor(duration % 60);