Skip to content

Commit

Permalink
Implement empty numbering style
Browse files Browse the repository at this point in the history
  • Loading branch information
carlobeltrame committed Mar 22, 2024
1 parent be0dae9 commit b2e967c
Show file tree
Hide file tree
Showing 13 changed files with 100 additions and 19 deletions.
5 changes: 4 additions & 1 deletion api/src/Entity/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ class Category extends BaseEntity implements BelongsToCampInterface, CopyFromPro
* Specifies whether the schedule entries of the activities in this category should be numbered
* using arabic numbers, roman numerals or letters.
*/
#[Assert\Choice(choices: ['a', 'A', 'i', 'I', '1'])]
#[Assert\Choice(choices: ['a', 'A', 'i', 'I', '1', '-'])]
#[ApiProperty(example: '1')]
#[Groups(['read', 'write'])]
#[ORM\Column(type: 'string', length: 1, nullable: false)]
Expand Down Expand Up @@ -235,6 +235,9 @@ public function getStyledNumber(int $num): string {
case 'I':
return strtoupper($this->getRomanNum($num));

case '-':
return '';

default:
return strval($num);
}
Expand Down
4 changes: 4 additions & 0 deletions api/src/Entity/ScheduleEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,10 @@ public function getScheduleEntryNumber(): int {
#[ApiProperty(example: '1.b')]
#[Groups(['read'])]
public function getNumber(): string {
if ('-' === $this->getNumberingStyle()) {
return '';
}

$dayNumber = $this->getDayNumber();
$scheduleEntryNumber = $this->getScheduleEntryNumber();

Expand Down
11 changes: 11 additions & 0 deletions api/tests/Entity/ScheduleEntryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,17 @@ public function testGetNumberInDifferentNumberingStyle() {
$this->assertEquals('2.1', $this->scheduleEntry3->getNumber());
}

public function testGetEmptyValueWhenNumberingStyleIsNone() {
$category = new Category();
$category->numberingStyle = '-';
$activity = new Activity();
$activity->category = $category;
$this->scheduleEntry2->activity = $activity;
$this->assertEquals('1.1', $this->scheduleEntry1->getNumber());
$this->assertEquals('', $this->scheduleEntry2->getNumber());
$this->assertEquals('', $this->scheduleEntry3->getNumber());
}

public function testGetNumberOrdersSamePeriodOffsetByLeft() {
$this->scheduleEntry1->startOffset = $this->scheduleEntry2->startOffset;
$this->scheduleEntry1->left = 0.5;
Expand Down
6 changes: 4 additions & 2 deletions common/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@
"A": "A, B, C - grosse Buchstaben",
"I": "I, II, III - grosse römische Zahlen",
"a": "a, b, c - kleine Buchstaben",
"i": "i, ii, iii - kleine römische Zahlen"
"i": "i, ii, iii - kleine römische Zahlen",
"-": "keine Nummerierung"
}
},
"contentType": {
Expand Down Expand Up @@ -210,7 +211,8 @@
},
"hourLong": "LT",
"hourShort": "H:mm"
}
},
"shortScheduleEntryDescription": "{title} (Tag {dayNumber})"
},
"print": {
"cover": {
Expand Down
6 changes: 4 additions & 2 deletions common/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@
"A": "A, B, C - uppercase letters",
"I": "I, II, III - uppercase roman numerals",
"a": "a, b, c - lowercase letters",
"i": "i, ii, iii - lowercase roman numerals"
"i": "i, ii, iii - lowercase roman numerals",
"-": "no numbering"
}
},
"contentType": {
Expand Down Expand Up @@ -217,7 +218,8 @@
},
"hourLong": "LT",
"hourShort": "H:mm"
}
},
"shortScheduleEntryDescription": "{title} (day {dayNumber})"
},
"print": {
"cover": {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/campAdmin/DialogCategoryForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export default {
},
computed: {
numberingStyles() {
return ['1', 'a', 'A', 'i', 'I'].map((i) => ({
return ['1', 'a', 'A', 'i', 'I', '-'].map((i) => ({
value: i,
text: this.$tc('entity.category.numberingStyles.' + i),
}))
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/category/CategoryProperties.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export default {
},
computed: {
numberingStyles() {
return ['1', 'a', 'A', 'i', 'I'].map((i) => ({
return ['1', 'a', 'A', 'i', 'I', '-'].map((i) => ({
value: i,
text: this.$tc('entity.category.numberingStyles.' + i),
}))
Expand Down
11 changes: 9 additions & 2 deletions frontend/src/components/material/ScheduleEntryLinks.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<CategoryChip dense :category="activity.category()" />&thinsp;{{
$vuetify.breakpoint.smAndUp
? `${activity.title}: ${items[0].number}`
: items[0].number
: shortDescription(items[0])
}}
</router-link>
<span v-else class="d-inline-flex flex-sm-wrap gap-1 align-center py-sm-1">
Expand All @@ -28,7 +28,9 @@
:to="scheduleEntryRoute(scheduleEntry)"
small
>{{
index < items.length - 1 ? `${scheduleEntry.number},` : scheduleEntry.number
index < items.length - 1
? `${shortDescription(scheduleEntry)},`
: shortDescription(scheduleEntry)
}}</router-link
>
</span>
Expand All @@ -38,6 +40,7 @@
<script>
import { scheduleEntryRoute } from '@/router.js'
import CategoryChip from '@/components/generic/CategoryChip.vue'
import shortScheduleEntryDescription from './shortScheduleEntryDescription.js'
export default {
name: 'ScheduleEntryLinks',
Expand Down Expand Up @@ -65,6 +68,10 @@ export default {
},
methods: {
scheduleEntryRoute,
shortDescription(scheduleEntry) {
if (this.loading) return ''
return shortScheduleEntryDescription(scheduleEntry, this.$tc.bind(this))
},
},
}
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import shortScheduleEntryDescription from '../shortScheduleEntryDescription.js'

describe('shortScheduleEntryDescription', () => {
it.each([
[{ _meta: { loading: true } }, ''],
[null, ''],
[undefined, ''],
[
{
_meta: { loading: false },
number: '1.2',
activity: () => ({
title: 'foo',
}),
dayNumber: '3',
},
'1.2',
],
[
{
_meta: { loading: false },
number: '',
activity: () => ({
title: 'foo',
}),
dayNumber: '3',
},
'["global.shortScheduleEntryDescription",1,{"title":"foo","dayNumber":"3"}]',
],
])('maps %p to %p', (input, expected) => {
const tc = (...args) => JSON.stringify(args)
expect(shortScheduleEntryDescription(input, tc)).toEqual(expected)
})
})
11 changes: 11 additions & 0 deletions frontend/src/components/material/shortScheduleEntryDescription.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export default function shortScheduleEntryDescription(scheduleEntry, tc) {
if (!scheduleEntry || scheduleEntry._meta.loading) return ''
return (
scheduleEntry?.number ||
// For numbering style "none", display the activity title and day number instead
tc('global.shortScheduleEntryDescription', 1, {
title: scheduleEntry.activity().title,
dayNumber: scheduleEntry.dayNumber,
})
)
}
2 changes: 1 addition & 1 deletion frontend/src/components/print/config/ActivityConfig.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export default {
this.camp.periods().items.forEach((p) => {
const periodScheduleEntries = p.scheduleEntries().items.map((se) => ({
value: { activity: se.activity()._meta.self, scheduleEntry: se._meta.self },
text: '(' + se.number + ') ' + se.activity().title,
text: (se.number ? '(' + se.number + ') ' : '') + se.activity().title,
}))
scheduleEntries = [...scheduleEntries, ...periodScheduleEntries]
})
Expand Down
11 changes: 9 additions & 2 deletions frontend/src/components/story/StoryDay.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,15 @@
<div v-for="chapter in storyChapters" :key="chapter._meta.self">
<h4 class="mt-3 mt-sm-5">
<span class="d-inline-flex align-center">
<span class="tabular-nums">{{ scheduleEntry.number }}</span>
<CategoryChip :schedule-entry="scheduleEntry" class="mx-1" dense />
<span v-if="scheduleEntry.number" class="tabular-nums">{{
scheduleEntry.number
}}</span>
<CategoryChip
:schedule-entry="scheduleEntry"
class="mr-1"
:class="{ 'ml-1': scheduleEntry.number }"
dense
/>
</span>
<router-link
:to="{
Expand Down
14 changes: 7 additions & 7 deletions pdf/src/campPrint/scheduleEntry/ScheduleEntry.vue
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ export default {
return this.scheduleEntry.activity()
},
bookmarkTitle() {
return (
this.activity.category().short +
' ' +
this.scheduleEntry.number +
' ' +
this.activity.title
)
return [
this.activity.category().short,
this.scheduleEntry.number,
this.activity.title,
]
.filter((entry) => entry)
.join(' ')
},
start() {
return this.$date.utc(this.scheduleEntry.start)
Expand Down

0 comments on commit b2e967c

Please sign in to comment.