From 39a7cf2ec01152114b9e647dbba6c077dc149f94 Mon Sep 17 00:00:00 2001 From: DebaucheryLibrarian Date: Wed, 23 Oct 2024 02:58:05 +0200 Subject: [PATCH] Added figure size conversions to actor revisions. --- components/edit/revisions.vue | 10 +-- pages/actors/@actorId/edit/+Page.vue | 118 +++++++++++++++++++-------- src/actors.js | 97 +++++++++++++++++++++- 3 files changed, 183 insertions(+), 42 deletions(-) diff --git a/components/edit/revisions.vue b/components/edit/revisions.vue index 58eb113..5dfd1e8 100644 --- a/components/edit/revisions.vue +++ b/components/edit/revisions.vue @@ -176,12 +176,12 @@ >{{ rev.base.title }} + {{ rev.deltas.map((delta) => delta.key).join(', ') }} + {{ rev.comment }} - - {{ rev.deltas.map((delta) => delta.key).join(', ') }}
@@ -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 { diff --git a/pages/actors/@actorId/edit/+Page.vue b/pages/actors/@actorId/edit/+Page.vue index 7ee7c8b..bd48351 100644 --- a/pages/actors/@actorId/edit/+Page.vue +++ b/pages/actors/@actorId/edit/+Page.vue @@ -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?.label || option }}
Units
@@ -211,13 +214,23 @@
Bust - + +
@@ -232,13 +245,13 @@ + /> + :value="Array.isArray(cup) ? cup[0] : cup" + >{{ Array.isArray(cup) ? cup.join('/') : cup }}
@@ -246,25 +259,33 @@
Waist - + + + + + +
Hip - + + + + + +
@@ -280,7 +301,7 @@ class="input" :disabled="!editing.has(item.key)" > - + @@ -314,7 +335,7 @@ class="input" :disabled="!editing.has(item.key)" > - + @@ -333,7 +354,7 @@ class="input" :disabled="!editing.has(item.key)" > - + @@ -367,7 +388,7 @@ class="input" :disabled="!editing.has(item.key)" > - + @@ -401,7 +422,7 @@ class="input" :disabled="!editing.has(item.key)" > - + @@ -419,7 +440,7 @@ Units @@ -478,7 +499,7 @@ class="select input" :disabled="!editing.has(item.key)" > - + @@ -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 { diff --git a/src/actors.js b/src/actors.js index 0c02287..394f596 100644 --- a/src/actors.js +++ b/src/actors.js @@ -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');