Skip to content

Commit 54f01d4

Browse files
committed
dumili: Fix handling of long issuecodes in text editor
1 parent bd74850 commit 54f01d4

File tree

1 file changed

+66
-19
lines changed

1 file changed

+66
-19
lines changed

apps/dumili/src/components/TextEditor.vue

Lines changed: 66 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,14 @@
99
}}</b-alert
1010
>
1111
<template v-if="rows">
12-
<b-form-checkbox v-model="showEntryLetters" class="m-2">{{
13-
$t("Afficher des lettres au lieu des numéros de pages")
14-
}}</b-form-checkbox>
12+
<b-form-checkbox
13+
v-model="showEntryLetters"
14+
:disabled="hasEntrycodesLongerThanFirstColumnMaxWidth"
15+
class="m-2"
16+
>{{
17+
$t("Afficher des lettres au lieu des numéros de pages")
18+
}}</b-form-checkbox
19+
>
1520
<b-form-checkbox v-model="showHorizontalScroll" class="m-2">{{
1621
$t("Afficher la barre de défilement horizontale")
1722
}}</b-form-checkbox>
@@ -60,17 +65,6 @@ const isCopied = ref(false);
6065
6166
const columnWidths = [12, 14, 3, 2, 1, 4, 4, 4, 4, 4];
6267
63-
const text = computed(() =>
64-
[Object.values(issueRow.value)]
65-
.concat((rows.value || []).map(Object.values))
66-
.map((row) =>
67-
row
68-
.map((text, idx) => String(text || "").padEnd(columnWidths[idx] || 0))
69-
.join(" "),
70-
)
71-
.join("\n"),
72-
);
73-
7468
const copyToClipboard = () => {
7569
navigator.clipboard.writeText(text.value);
7670
isCopied.value = true;
@@ -112,6 +106,40 @@ const issuecode = computed(
112106
`${issue.value!.publicationcode.split("/")[1]} ${issue.value!.issuenumber}`,
113107
);
114108
109+
const entrycodesWithPageNumbers = computed(() =>
110+
indexation.value!.entries.map(
111+
(entry, idx) =>
112+
`${issuecode.value}${
113+
idx === 0
114+
? String.fromCharCode(97 + idx)
115+
: `p${String(entry.position).padStart(3, "0")}`
116+
}`,
117+
),
118+
);
119+
120+
const entrycodesWithLetters = computed(() =>
121+
indexation.value!.entries.map(
122+
(_entry, idx) => `${issuecode.value}${String.fromCharCode(97 + idx)}`,
123+
),
124+
);
125+
126+
const hasEntrycodesLongerThanFirstColumnMaxWidth = computed(() =>
127+
entrycodesWithPageNumbers.value.some(
128+
(entrycode) => entrycode.length > columnWidths[0],
129+
),
130+
);
131+
132+
watch(
133+
hasEntrycodesLongerThanFirstColumnMaxWidth,
134+
(value) => {
135+
if (value) {
136+
debugger;
137+
showEntryLetters.value = true;
138+
}
139+
},
140+
{ immediate: true },
141+
);
142+
115143
const issueRow = computed(() => ({
116144
issuecode: issuecode.value,
117145
details: [
@@ -137,10 +165,14 @@ const rows = computed(() =>
137165
({ storycode }) => storycode === entry.acceptedStory?.storycode,
138166
);
139167
return {
140-
entrycode: `${issuecode.value}${(idx === 0 || showEntryLetters.value
141-
? String.fromCharCode(97 + idx)
142-
: `p${String(entry.position)}`
143-
).padStart(3, "0")}`,
168+
entrycode:
169+
idx === 0 ||
170+
(showEntryLetters.value &&
171+
!hasEntrycodesLongerThanFirstColumnMaxWidth.value)
172+
? entrycodesWithLetters.value[idx]
173+
: hasEntrycodesLongerThanFirstColumnMaxWidth.value
174+
? "->"
175+
: entrycodesWithPageNumbers.value[idx],
144176
storycode: entry.acceptedStory?.storycode || "",
145177
pg: String(getEntryPages(indexation.value!, entry.id).length),
146178
la:
@@ -157,11 +189,26 @@ const rows = computed(() =>
157189
]),
158190
) as { plot: string; writer: string; artist: string; ink: string }),
159191
hero: "", //story!.printedhero,
160-
title: entry.title,
192+
title: `${entry.title || ""}${
193+
hasEntrycodesLongerThanFirstColumnMaxWidth.value && idx > 0
194+
? `[entrycode:${entrycodesWithPageNumbers.value[idx]}]`
195+
: ""
196+
}`,
161197
};
162198
}),
163199
);
164200
201+
const text = computed(() =>
202+
[Object.values(issueRow.value)]
203+
.concat((rows.value || []).map(Object.values))
204+
.map((row) =>
205+
row
206+
.map((text, idx) => String(text || "").padEnd(columnWidths[idx] || 0))
207+
.join(" "),
208+
)
209+
.join("\n"),
210+
);
211+
165212
watch(
166213
acceptedStories,
167214
async (value) => {

0 commit comments

Comments
 (0)