Added figure size conversions to actor revisions.

This commit is contained in:
DebaucheryLibrarian 2024-10-23 02:58:05 +02:00
parent 192aeeaafd
commit 39a7cf2ec0
3 changed files with 183 additions and 42 deletions

View File

@ -176,12 +176,12 @@
>{{ rev.base.title }}</span>
<span class="rev-summary">
<span class="summary-deltas ellipsis">{{ rev.deltas.map((delta) => delta.key).join(', ') }}</span>
<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">
@ -615,9 +615,9 @@ async function banEditor(revision) {
}
.summary-comment {
padding-right: .5rem;
border-right: solid 1px var(--glass-weak-20);
margin-right: .5rem;
padding-left: .5rem;
border-left: solid 1px var(--glass-weak-20);
margin-left: .5rem;
}
.summary-deltas {

View File

@ -138,7 +138,7 @@
v-for="option in item.options"
:key="`${item.key}-option-${option}`"
:value="typeof option?.value === 'undefined' ? option : option.value"
>{{ option?.label || option || 'unknown' }}</option>
>{{ option?.label || option }}</option>
</select>
<div
@ -196,14 +196,17 @@
<span class="value-label">Units</span>
<select
v-model="figureSystem"
v-model="figureUnits"
class="input"
:disabled="!editing.has(item.key)"
>
<option value="us">USA</option>
<option value="uk">UK</option>
<option value="eu">Europe/Asia</option>
<option value="jp">Japan</option>
<option value="aus">Australia</option>
<option value="au">Australia</option>
<option value="it">Italy</option>
<option value="fr">France</option>
</select>
</div>
@ -211,13 +214,23 @@
<div class="value-section">
<span class="value-label">Bust</span>
<input
<select
v-model="edits[item.key].bust"
type="number"
class="input"
class="select input"
placeholder="Bust"
:disabled="!editing.has(item.key)"
>
<option
:key="`${item.key}-bust-unknown`"
:value="null"
/>
<option
v-for="bust in bustSizes[figureUnits]"
:key="`${item.key}-bust-${bust}`"
:value="Array.isArray(bust) ? bust[0] : bust"
>{{ Array.isArray(bust) ? bust.join('/') : bust }}</option>
</select>
</div>
<div class="value-section">
@ -232,13 +245,13 @@
<option
:key="`${item.key}-cup-unknown`"
:value="null"
>Unknown</option>
/>
<option
v-for="cup in cupSizes"
v-for="cup in cupSizes[figureUnits]"
:key="`${item.key}-cup-${cup}`"
:value="cup"
>{{ cup }}</option>
:value="Array.isArray(cup) ? cup[0] : cup"
>{{ Array.isArray(cup) ? cup.join('/') : cup }}</option>
</select>
</div>
</span>
@ -246,25 +259,33 @@
<div class="value-section">
<span class="value-label">Waist</span>
<input
v-model="edits[item.key].waist"
type="number"
class="input"
placeholder="Waist"
:disabled="!editing.has(item.key)"
>
<span>
<input
v-model="edits[item.key].waist"
type="number"
class="input"
:disabled="!editing.has(item.key)"
>
<template v-if="['us', 'uk'].includes(figureUnits)">&nbsp;inch</template>
<template v-else>&nbsp;cm</template>
</span>
</div>
<div class="value-section">
<span class="value-label">Hip</span>
<input
v-model="edits[item.key].hip"
type="number"
class="input"
placeholder="Hip"
:disabled="!editing.has(item.key)"
>
<span>
<input
v-model="edits[item.key].hip"
type="number"
class="input"
:disabled="!editing.has(item.key)"
>
<template v-if="['us', 'uk'].includes(figureUnits)">&nbsp;inch</template>
<template v-else>&nbsp;cm</template>
</span>
</div>
</div>
@ -280,7 +301,7 @@
class="input"
:disabled="!editing.has(item.key)"
>
<option :value="null">Unknown</option>
<option :value="null" />
<option :value="true">Yes</option>
<option :value="false">No</option>
</select>
@ -314,7 +335,7 @@
class="input"
:disabled="!editing.has(item.key)"
>
<option :value="null">Unknown</option>
<option :value="null" />
<option value="saline">Saline</option>
<option value="silicone">Silicone</option>
<option value="gummy">Gummy</option>
@ -333,7 +354,7 @@
class="input"
:disabled="!editing.has(item.key)"
>
<option :value="null">Unknown</option>
<option :value="null" />
<option value="over">Over muscle</option>
<option value="under">Under muscle</option>
</select>
@ -367,7 +388,7 @@
class="input"
:disabled="!editing.has(item.key)"
>
<option :value="null">Unknown</option>
<option :value="null" />
<option :value="true">Yes</option>
<option :value="false">No</option>
</select>
@ -401,7 +422,7 @@
class="input"
:disabled="!editing.has(item.key)"
>
<option :value="null">Unknown</option>
<option :value="null" />
<option value="bbl">BBL (fat transfer)</option>
<option value="lift">Direct lift</option>
<option value="filler">Filler (Sculptra)</option>
@ -419,7 +440,7 @@
<span class="value-label">Units</span>
<select
v-model="penisSystem"
v-model="penisUnits"
class="input"
:disabled="!editing.has(item.key)"
>
@ -462,7 +483,7 @@
class="input"
:disabled="!editing.has(item.key)"
>
<option :value="null">Unknown</option>
<option :value="null" />
<option :value="true">Yes</option>
<option :value="false">No</option>
</select>
@ -478,7 +499,7 @@
class="select input"
:disabled="!editing.has(item.key)"
>
<option :value="null">Unknown</option>
<option :value="null" />
<option :value="true">Yes</option>
<option :value="false">No</option>
</select>
@ -574,6 +595,7 @@ const topCountries = [
const sortedCountries = countries.toSorted((countryA, countryB) => topCountries.indexOf(countryB.alpha2) - topCountries.indexOf(countryA.alpha2));
/*
const cupSizes = [
'A', 'AA',
'B',
@ -591,6 +613,30 @@ const cupSizes = [
'O',
'P',
];
*/
const cupSizes = {
us: ['AA', 'A', 'B', 'C', 'D', ['DD', 'E'], ['DDD', 'F'], 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P'], // United States
uk: ['AA', 'A', 'B', 'C', 'D', 'DD', 'E', 'F', 'FF', 'G', 'GG', 'H', 'HH', 'J', 'JJ', 'K', 'KK'], // United Kingdom
eu: ['AA', 'A', 'B', 'C', 'D', 'E', 'F', 'G', ' H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P'], // Europe
jp: ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q'], // Japan
};
cupSizes.fr = cupSizes.eu; // France
cupSizes.it = cupSizes.uk; // Italy
cupSizes.au = cupSizes.uk; // Australia
// bra band sizes
const bustSizes = {
us: [28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56],
eu: [60, 65, 70, 75, 80, 85, 90, 95, 100, 105, 110, 115, 120, 125, 130],
fr: [75, 80, 85, 90, 95, 100, 105, 110, 115, 120, 125, 130, 135, 140, 145],
it: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13],
au: [6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34],
};
bustSizes.uk = bustSizes.us;
bustSizes.jp = bustSizes.eu;
const fields = computed(() => [
{
@ -767,8 +813,8 @@ const comment = ref(null);
const apply = ref(user.role !== 'user');
const submitted = ref(false);
const figureSystem = ref('us');
const penisSystem = ref('imperial');
const figureUnits = ref('us');
const penisUnits = ref('imperial');
function toggleField(item) {
if (editing.value.has(item.key)) {
@ -809,6 +855,8 @@ async function submit() {
return [[key, edits.value[key]]];
})),
figureUnits: figureUnits.value,
penisUnits: penisUnits.value,
comment: comment.value,
apply: apply.value,
}, {
@ -873,6 +921,8 @@ async function submit() {
.row .input {
height: 2.5rem;
flex-shrink: 0;
min-width: 7rem;
}
.select {

View File

@ -4,6 +4,7 @@ import { unit } from 'mathjs';
import { MerkleJson } from 'merkle-json';
import moment from 'moment';
import omit from 'object.omit';
import convert from 'convert';
import initLogger from './logger.js';
import { knexOwner as knex, knexManticore } from './knex.js';
@ -662,7 +663,77 @@ export async function reviewActorRevision(revisionId, isApproved, { feedback },
}
}
export async function createActorRevision(actorId, { edits, comment, apply }, reqUser) {
const cupConversions = {
us: ['AA', 'A', 'B', 'C', 'D', ['DD', 'E'], ['DDD', 'F'], 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P'], // United States
uk: ['AA', 'A', 'B', 'C', 'D', 'DD', 'E', 'F', 'FF', 'G', 'GG', 'H', 'HH', 'J', 'JJ', 'K', 'KK'], // United Kingdom
eu: ['AA', 'A', 'B', 'C', 'D', 'E', 'F', 'G', ' H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P'], // Europe
jp: ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q'], // Japan
};
cupConversions.fr = cupConversions.eu; // France
cupConversions.it = cupConversions.uk; // Italy
cupConversions.au = cupConversions.uk; // Australia
// bra band sizes
const bustConversions = {
us: [28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56],
eu: [60, 65, 70, 75, 80, 85, 90, 95, 100, 105, 110, 115, 120, 125, 130],
fr: [75, 80, 85, 90, 95, 100, 105, 110, 115, 120, 125, 130, 135, 140, 145],
it: [0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13],
au: [6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34],
};
bustConversions.uk = bustConversions.us;
bustConversions.jp = bustConversions.eu;
const conversions = {
cup: cupConversions,
bust: bustConversions,
};
// to US
function convertFigure(domain = 'cup', rawValue, units) {
if (!rawValue) {
return null;
}
const value = typeof rawValue === 'string'
? rawValue.toUpperCase()
: Number(rawValue);
if (!units || !cupConversions[units] || units === 'us') {
return value;
}
if (!conversions[domain]) {
if (['us', 'uk'].includes(units)) {
return value; // should already be in inches
}
return Math.round(convert(value, 'cm').to('inches'));
}
if (Number.isNaN(value)) {
return value;
}
const valueIndex = conversions[domain][units].findIndex((chartValue) => (Array.isArray(chartValue) // US uses both DD and E, and DDD and F
? chartValue.includes(value)
: value === chartValue));
const usValue = Array.isArray(conversions[domain].us[valueIndex])
? conversions[domain].us[valueIndex][0]
: conversions[domain].us[valueIndex];
return usValue;
}
export async function createActorRevision(actorId, {
edits,
comment,
apply,
...options
}, reqUser) {
const [
[actor],
openRevisions,
@ -732,9 +803,29 @@ export async function createActorRevision(actorId, { edits, comment, apply }, re
return { key, value: Array.from(valueSet) };
}
return { key, value: value || null };
if (['cup', 'bust', 'waist', 'hip'].includes(key)) {
const convertedValue = convertFigure(key, value, options.figureUnits);
const conversionComment = convertedValue === value
? null
: `${key} converted from ${value} ${options.figureUnits?.toUpperCase() || 'US'} to ${convertedValue} US`;
return {
key,
value: convertedValue,
comment: conversionComment,
};
}
return {
key,
value: value || null,
};
}).filter(Boolean);
const deltaComments = deltas.map((delta) => delta.comment);
const curatedComment = [comment, ...deltaComments].filter(Boolean).join(' | ');
if (deltas.length === 0) {
throw new HttpError('No effective changes provided', 400);
}
@ -749,7 +840,7 @@ export async function createActorRevision(actorId, { edits, comment, apply }, re
base: baseActor,
deltas,
}),
comment,
comment: curatedComment,
})
.returning('id');