@dcrackel/hematournamentui 1.0.712 → 1.0.714
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.prettierignore +7 -7
- package/.storybook/main.js +3 -1
- package/README.md +42 -0
- package/dist/HemaTournamentUI-lib.es.js +6856 -6243
- package/dist/HemaTournamentUI-lib.umd.js +27 -27
- package/dist/hematournamentui-tailwind.css +79 -9
- package/package.json +96 -96
- package/prettier.config.js +16 -16
- package/src/index.js +43 -42
- package/src/main.js +1 -1
- package/src/mocks/getDEBouts-TableOf128.js +37 -37
- package/src/mocks/getDEBouts-TableOf64.js +35 -35
- package/src/stories/Atoms/Input/BaseInput.test.js +97 -97
- package/src/stories/Atoms/Input/BaseInput.vue +149 -149
- package/src/stories/Molecules/Indicators/MissingHemaRatingsId/MissingHemaRatingsId.stories.js +23 -23
- package/src/stories/Molecules/Indicators/MissingHemaRatingsId/MissingHemaRatingsId.vue +35 -35
- package/src/stories/Molecules/Indicators/RegistrationStatus/RegistrationStatus.vue +30 -30
- package/src/stories/Molecules/Menus/HoverActions/HoverActions.test.js +138 -0
- package/src/stories/Molecules/Menus/HoverActions/HoverActions.vue +212 -0
- package/src/stories/Molecules/Modals/BracketDirectorsModal/BracketDirectorsModal.stories.js +49 -0
- package/src/stories/Molecules/Modals/BracketDirectorsModal/BracketDirectorsModal.test.js +129 -0
- package/src/stories/Molecules/Modals/BracketDirectorsModal/BracketDirectorsModal.vue +165 -0
- package/src/stories/Molecules/Modals/DirectorModal/DirectorModal.stories.js +6 -0
- package/src/stories/Molecules/Modals/DirectorModal/DirectorModal.test.js +18 -18
- package/src/stories/Molecules/Modals/DirectorModal/DirectorModal.vue +1 -1
- package/src/stories/Organisms/Cards/BoutCard/BoutCard.vue +5 -1
- package/src/stories/Organisms/Cards/BoutCard/Variants/BoutCardActive/BoutCardActive.vue +19 -10
- package/src/stories/Organisms/Cards/BoutCard/Variants/BoutCardInactive/BoutCardInactive.vue +11 -7
- package/src/stories/Organisms/Cards/BracketDirectorAssignmentCard/BracketDirectorAssignmentCard.stories.js +42 -33
- package/src/stories/Organisms/Cards/BracketDirectorAssignmentCard/BracketDirectorAssignmentCard.test.js +76 -45
- package/src/stories/Organisms/Cards/BracketDirectorAssignmentCard/BracketDirectorAssignmentCard.vue +122 -103
- package/src/stories/Organisms/Cards/Director/DirectorCard.test.js +82 -0
- package/src/stories/Organisms/Cards/Director/DirectorCard.vue +32 -51
- package/src/stories/Organisms/Cards/EditBout/EditBout.test.js +51 -51
- package/src/stories/Organisms/Cards/EventCard/EventCard.test.js +106 -106
- package/src/stories/Organisms/Cards/FencerCard/FencerCard.vue +298 -298
- package/src/stories/Organisms/Cards/TableauBoutCard/TableauBoutCard.stories.js +77 -60
- package/src/stories/Organisms/Cards/TableauBoutCard/TableauBoutCard.test.js +144 -143
- package/src/stories/Organisms/Cards/TableauBoutCard/TableauBoutCard.vue +289 -256
- package/src/stories/Organisms/Cards/TableauFencerCard/TableauFencerCard.stories.js +69 -69
- package/src/stories/Organisms/Cards/TableauFencerCard/TableauFencerCard.vue +80 -80
- package/src/stories/Organisms/Cards/WaitlistFencerCard/WaitlistFencerCard.vue +153 -153
- package/src/stories/Organisms/ComplexInputs/DropDown/DropDownMenu.vue +4 -0
- package/src/stories/Organisms/ComplexInputs/ImageCropper/ImageCropper.stories.js +31 -31
- package/src/stories/Organisms/ComplexInputs/ImageCropper/ImageCropper.test.js +109 -109
- package/src/stories/Organisms/ComplexInputs/ImageCropper/ImageCropper.vue +192 -192
- package/src/stories/Organisms/Containers/Tableau/Tableau.stories.js +1 -0
- package/src/stories/Organisms/Containers/Tableau/Tableau.test.js +247 -204
- package/src/stories/Organisms/Containers/Tableau/Tableau.vue +89 -15
- package/src/stories/Organisms/Containers/Tableau/components/BracketDirectorAssignmentPanel.test.js +51 -29
- package/src/stories/Organisms/Containers/Tableau/components/BracketDirectorAssignmentPanel.vue +63 -46
- package/src/stories/Organisms/Containers/Tableau/components/TableauSvgOverlay.test.js +21 -21
- package/src/stories/Organisms/Containers/Tableau/components/TableauSvgOverlay.vue +39 -39
- package/src/stories/Organisms/Containers/Tableau/layout/TableauLayoutEngine.js +145 -145
- package/src/stories/Organisms/Containers/Tableau/layout/TableauLayoutEngine.test.js +64 -64
- package/src/stories/Organisms/Containers/Tableau/plannedAssignments.js +36 -57
- package/src/stories/Organisms/Containers/Tableau/plannedAssignments.test.js +101 -65
- package/src/stories/Organisms/Containers/TableauColumn/TableauColumn.vue +14 -1
- package/src/stories/Organisms/Wizards/EditEventWizard/BasicEventInfo/BasicEventInfo.stories.js +52 -52
- package/src/stories/Organisms/Wizards/EditEventWizard/BasicEventInfo/BasicEventInfo.vue +10 -3
- package/src/stories/Organisms/Wizards/EditEventWizard/DirectElimination/DirectElimination.vue +226 -226
- package/src/stories/Organisms/Wizards/EditEventWizard/DirectEliminationPromotion/DirectEliminationPromotion.vue +204 -204
- package/src/stories/Organisms/Wizards/EditEventWizard/EditEventWizard.stories.js +137 -137
- package/src/stories/Organisms/Wizards/EditEventWizard/EventCustomization/EventCustomization.vue +172 -172
- package/src/stories/Organisms/Wizards/EditEventWizard/PoolConfiguration/PoolConfiguration.vue +216 -216
- package/src/stories/Organisms/Wizards/EditEventWizard/PriceFields.test.js +79 -79
- package/src/stories/Organisms/Wizards/EditEventWizard/RuleSerialization.test.js +29 -29
- package/src/stories/Organisms/Wizards/EditEventWizard/WeaponSelection.test.js +138 -0
- package/src/stories/Templates/EventManagement/Bracket/Bracket.stories.js +149 -9
- package/src/stories/Templates/EventManagement/Bracket/Bracket.test.js +54 -2
- package/src/stories/Templates/EventManagement/Bracket/Bracket.vue +77 -8
- package/src/stories/Templates/EventManagement/Bracket/BracketDirectorAssignment.test.js +242 -0
- package/src/stories/Templates/EventManagement/Bracket/BracketMobile.test.js +131 -0
- package/src/stories/Templates/EventManagement/Bracket/BracketPlannedSuggestions.js +50 -39
- package/src/stories/Templates/EventManagement/Bracket/BracketStories.test.js +201 -0
- package/src/stories/Templates/EventManagement/Bracket/BracketStoryAssignments.js +93 -0
- package/src/stories/Templates/EventManagement/Bracket/BracketStoryAssignments.test.js +152 -0
- package/src/stories/Templates/EventManagement/Bracket/BracketStoryHarness.js +39 -39
- package/src/stories/Templates/EventManagement/Bracket/BracketStoryHarness.test.js +79 -79
- package/src/stories/Templates/EventManagement/EditEventInfo/EditEventInfo.stories.js +93 -93
- package/src/stories/Templates/EventManagement/EditEventInfo/EditEventInfo.vue +91 -91
- package/src/stories/Templates/EventManagement/PoolLive/PoolLive.test.js +121 -121
- package/src/stories/Templates/Menus/EditEventsTopMenu/EditEventsTopMenu.stories.js +9 -2
- package/src/stories/Templates/Menus/EditEventsTopMenu/EditEventsTopMenu.vue +5 -4
- package/src/stories/Templates/PersonManagement/Admin/Administration/Administration.stories.js +81 -81
- package/src/stories/Templates/PersonManagement/Admin/Administration/Administration.test.js +39 -39
- package/src/stories/Templates/PersonManagement/Admin/Administration/Administration.vue +101 -101
- package/src/stories/Templates/PersonManagement/Admin/FencerAdmin/FencerAdmin.stories.js +71 -71
- package/src/stories/Templates/PersonManagement/Admin/FencerAdmin/FencerAdmin.vue +86 -86
- package/src/stories/Templates/PersonManagement/Admin/MergeAccounts/MergeAccounts.stories.js +86 -86
- package/src/stories/Templates/PersonManagement/Admin/MergeAccounts/MergeAccounts.vue +247 -247
- package/src/stories/Templates/PersonManagement/Basic/BasicEdit.vue +170 -170
- package/src/stories/Templates/PersonManagement/PersonManagement.stories.js +156 -156
- package/src/stories/Templates/PersonManagement/PersonManagement.test.js +329 -329
- package/src/stories/Templates/PersonManagement/PersonManagement.vue +329 -329
- package/src/stories/Templates/PersonManagement/PersonManagementDraft.js +42 -42
- package/src/stories/Templates/TournamentManagement/TournamentManagement.stories.js +84 -84
- package/src/stories/Templates/TournamentManagement/TournamentManagement.test.js +114 -114
- package/src/stories/Templates/TournamentManagement/TournamentManagement.vue +363 -363
- package/src/stories/Templates/TournamentManagement/TournamentPageOne/TournamentPageOne.stories.js +116 -116
- package/src/stories/Templates/TournamentManagement/TournamentPageOne/TournamentPageOne.vue +307 -307
- package/src/stories/Util/Validations/PersonManagementValidations.js +45 -45
- package/src/stories/Util/Validations/PriceValidation.js +6 -6
- package/src/stories/Util/boutDirectorAssignment.js +46 -0
- package/src/stories/Util/bracketDirectors.js +86 -0
- package/src/stories/Util/registrationStatus.js +11 -11
- package/src/stories/Util/tabs.js +19 -47
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
const getBoutId = bout => bout.DEBoutId ?? bout.BoutId;
|
|
2
|
+
const getStatus = bout => String(bout.Status || '').toLowerCase();
|
|
3
|
+
const hasFencer = person => Number(person?.PersonId) > 0 && String(person.DisplayName || '').toUpperCase() !== 'BYE';
|
|
4
|
+
const isScheduledBout = bout => getStatus(bout) === 'scheduled';
|
|
5
|
+
const isFinishedOrActiveBout = bout => ['active', 'completed'].includes(getStatus(bout));
|
|
6
|
+
const isPowerOfTwo = value => value > 0 && Number.isInteger(Math.log2(value));
|
|
7
|
+
const sortBouts = (first, second) => Number(getBoutId(first)) - Number(getBoutId(second));
|
|
8
|
+
|
|
9
|
+
const getPlannedRoundSize = bout => {
|
|
10
|
+
const label = String(bout.RoundLabel || '');
|
|
11
|
+
if (/^Quarterfinals?$/i.test(label)) return 8;
|
|
12
|
+
if (/^Semifinals?$/i.test(label)) return 4;
|
|
13
|
+
const size = Number(label.match(/^Table of (\d+)$/i)?.[1] || 0);
|
|
14
|
+
return size >= 4 ? size : 0;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const groupPlannedRounds = bouts => {
|
|
18
|
+
const rounds = new Map();
|
|
19
|
+
for (const bout of bouts) {
|
|
20
|
+
const size = getPlannedRoundSize(bout);
|
|
21
|
+
if (!size || getBoutId(bout) == null) continue;
|
|
22
|
+
if (!rounds.has(size)) rounds.set(size, []);
|
|
23
|
+
rounds.get(size).push(bout);
|
|
24
|
+
}
|
|
25
|
+
return [...rounds].sort(([first], [second]) => second - first);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const isOpeningBye = (bout, isOpeningRound) => {
|
|
29
|
+
if (getStatus(bout) === 'bye') return true;
|
|
30
|
+
return isOpeningRound && ![bout.Person1, bout.Person2].every(hasFencer);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const createStationQuotas = (boutCount, stationLoads, keepBracketSections) => {
|
|
34
|
+
const stationCount = stationLoads.length;
|
|
35
|
+
const groupSize = Math.floor(boutCount / stationCount);
|
|
36
|
+
const largerGroupCount = boutCount % stationCount;
|
|
37
|
+
const stationOrder = stationLoads.map((load, index) => ({ load, index }));
|
|
38
|
+
if (!keepBracketSections)
|
|
39
|
+
stationOrder.sort((first, second) => first.load - second.load || first.index - second.index);
|
|
40
|
+
const largerGroups = new Set(stationOrder.slice(0, largerGroupCount).map(station => station.index));
|
|
41
|
+
return stationLoads.map((_, index) => groupSize + Number(largerGroups.has(index)));
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const getStationIndex = (boutIndex, quotas) => {
|
|
45
|
+
let groupEnd = 0;
|
|
46
|
+
return quotas.findIndex(quota => {
|
|
47
|
+
groupEnd += quota;
|
|
48
|
+
return boutIndex < groupEnd;
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const createRoundAssignments = ({ bouts, stations, stationLoads, isOpeningRound }) => {
|
|
53
|
+
const roundBouts = [...bouts].sort(sortBouts);
|
|
54
|
+
const keepBracketSections = isPowerOfTwo(stations.length);
|
|
55
|
+
const partitionBouts = keepBracketSections
|
|
56
|
+
? roundBouts
|
|
57
|
+
: roundBouts.filter(bout => !isOpeningBye(bout, isOpeningRound));
|
|
58
|
+
const quotas = createStationQuotas(partitionBouts.length, stationLoads, keepBracketSections);
|
|
59
|
+
const nextStationLoads = [...stationLoads];
|
|
60
|
+
const assignments = partitionBouts.flatMap((bout, index) => {
|
|
61
|
+
if (isOpeningBye(bout, isOpeningRound)) return [];
|
|
62
|
+
const stationIndex = getStationIndex(index, quotas);
|
|
63
|
+
nextStationLoads[stationIndex]++;
|
|
64
|
+
if (!isScheduledBout(bout)) return [];
|
|
65
|
+
return [{ DEBoutId: getBoutId(bout), RingId: stations[stationIndex].RingId }];
|
|
66
|
+
});
|
|
67
|
+
return { assignments, stationLoads: nextStationLoads };
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
// Story parent simulation: coverage includes semifinals; the final stays shared.
|
|
71
|
+
export const distributeStoryAssignments = ({ bouts = [], stations = [], previousAssignments = [] } = {}) => {
|
|
72
|
+
const protectedBoutIds = new Set(bouts.filter(isFinishedOrActiveBout).map(bout => String(getBoutId(bout))));
|
|
73
|
+
const protectedAssignments = previousAssignments.filter(assignment =>
|
|
74
|
+
protectedBoutIds.has(String(assignment.DEBoutId))
|
|
75
|
+
);
|
|
76
|
+
const availableStations = stations.filter(station => station?.RingId != null && station.Director?.PersonId != null);
|
|
77
|
+
if (!availableStations.length) return protectedAssignments.map(assignment => ({ ...assignment }));
|
|
78
|
+
const rounds = groupPlannedRounds(bouts);
|
|
79
|
+
const openingRoundSize = rounds[0]?.[0];
|
|
80
|
+
let stationLoads = availableStations.map(() => 0);
|
|
81
|
+
const assignments = [];
|
|
82
|
+
for (const [size, roundBouts] of rounds) {
|
|
83
|
+
const coverage = createRoundAssignments({
|
|
84
|
+
bouts: roundBouts,
|
|
85
|
+
stations: availableStations,
|
|
86
|
+
stationLoads,
|
|
87
|
+
isOpeningRound: size === openingRoundSize
|
|
88
|
+
});
|
|
89
|
+
assignments.push(...coverage.assignments);
|
|
90
|
+
stationLoads = coverage.stationLoads;
|
|
91
|
+
}
|
|
92
|
+
return [...assignments, ...protectedAssignments.map(assignment => ({ ...assignment }))];
|
|
93
|
+
};
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { activateStoryBout, canStoryDirectorDirectBout } from './BracketStoryHarness.js';
|
|
3
|
+
import { distributeStoryAssignments } from './BracketStoryAssignments.js';
|
|
4
|
+
|
|
5
|
+
const stations = Array.from({ length: 6 }, (_, index) => ({ RingId: index + 1, Director: { PersonId: index + 101 } }));
|
|
6
|
+
const createPerson = PersonId => ({ PersonId, DisplayName: PersonId ? 'Fencer ' + PersonId : 'BYE' });
|
|
7
|
+
const createBracket = () => {
|
|
8
|
+
const bouts = [];
|
|
9
|
+
for (let size = 64; size >= 2; size /= 2) {
|
|
10
|
+
for (let index = 0; index < size / 2; index++) {
|
|
11
|
+
const id = bouts.length + 1;
|
|
12
|
+
bouts.push({
|
|
13
|
+
BoutId: id + 1000,
|
|
14
|
+
DEBoutId: id,
|
|
15
|
+
RoundLabel: size >= 8 ? 'Table of ' + size : { 4: 'Semifinal', 2: 'Final' }[size],
|
|
16
|
+
Status: 'Scheduled',
|
|
17
|
+
Person1: createPerson(size === 64 ? index * 2 + 1 : 0),
|
|
18
|
+
Person2: createPerson(size === 64 ? index * 2 + 2 : 0)
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return bouts;
|
|
23
|
+
};
|
|
24
|
+
const getRingIds = (assignments, bouts) => {
|
|
25
|
+
const ringByBout = new Map(assignments.map(assignment => [assignment.DEBoutId, assignment.RingId]));
|
|
26
|
+
return bouts.map(bout => ringByBout.get(bout.DEBoutId));
|
|
27
|
+
};
|
|
28
|
+
const countAssignments = (assignments, count) =>
|
|
29
|
+
stations
|
|
30
|
+
.slice(0, count)
|
|
31
|
+
.map(station => assignments.filter(assignment => assignment.RingId === station.RingId).length);
|
|
32
|
+
|
|
33
|
+
describe('Bracket story section coverage', () => {
|
|
34
|
+
it.each([2, 4])('keeps exact early bracket sections and includes semifinals with %i directors', count => {
|
|
35
|
+
const bouts = createBracket();
|
|
36
|
+
const original = structuredClone(bouts);
|
|
37
|
+
const assignments = distributeStoryAssignments({ bouts, stations: stations.slice(0, count) });
|
|
38
|
+
expect(assignments).toHaveLength(62);
|
|
39
|
+
for (const size of [64, 32, 16, 8]) {
|
|
40
|
+
const round = bouts.filter(bout => bout.RoundLabel === 'Table of ' + size);
|
|
41
|
+
expect(getRingIds(assignments, round)).toEqual(
|
|
42
|
+
round.map((_, index) => Math.floor(index / (round.length / count)) + 1)
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
expect(bouts).toEqual(original);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it.each([
|
|
49
|
+
[3, [11, 11, 10]],
|
|
50
|
+
[5, [7, 7, 6, 6, 6]],
|
|
51
|
+
[6, [6, 6, 5, 5, 5, 5]]
|
|
52
|
+
])('balances contiguous groups and total workload with %i directors', (count, openingCounts) => {
|
|
53
|
+
const bouts = createBracket();
|
|
54
|
+
const assignments = distributeStoryAssignments({ bouts, stations: stations.slice(0, count) });
|
|
55
|
+
expect(
|
|
56
|
+
countAssignments(
|
|
57
|
+
assignments.filter(assignment => assignment.DEBoutId <= 32),
|
|
58
|
+
count
|
|
59
|
+
)
|
|
60
|
+
).toEqual(openingCounts);
|
|
61
|
+
const totals = countAssignments(assignments, count);
|
|
62
|
+
expect(totals.reduce((sum, total) => sum + total, 0)).toBe(62);
|
|
63
|
+
expect(Math.max(...totals) - Math.min(...totals)).toBeLessThanOrEqual(1);
|
|
64
|
+
for (const size of [64, 32, 16, 8]) {
|
|
65
|
+
const ringIds = getRingIds(
|
|
66
|
+
assignments,
|
|
67
|
+
bouts.filter(bout => bout.RoundLabel === 'Table of ' + size)
|
|
68
|
+
);
|
|
69
|
+
expect(ringIds).toEqual([...ringIds].sort((first, second) => first - second));
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('ignores opening BYEs as work while planning unresolved later bouts', () => {
|
|
74
|
+
const bouts = createBracket();
|
|
75
|
+
for (const index of [0, 7, 18]) bouts[index].Person2 = createPerson(0);
|
|
76
|
+
const assignments = distributeStoryAssignments({ bouts, stations: stations.slice(0, 3) });
|
|
77
|
+
expect(assignments).toHaveLength(59);
|
|
78
|
+
expect(
|
|
79
|
+
countAssignments(
|
|
80
|
+
assignments.filter(assignment => assignment.DEBoutId <= 32),
|
|
81
|
+
3
|
|
82
|
+
)
|
|
83
|
+
).toEqual([10, 10, 9]);
|
|
84
|
+
expect(countAssignments(assignments, 3)).toEqual([20, 20, 19]);
|
|
85
|
+
expect(getRingIds(assignments, [bouts[0], bouts[7], bouts[18]])).toEqual([undefined, undefined, undefined]);
|
|
86
|
+
expect(
|
|
87
|
+
getRingIds(
|
|
88
|
+
assignments,
|
|
89
|
+
bouts.filter(bout => bout.RoundLabel === 'Table of 8')
|
|
90
|
+
)
|
|
91
|
+
).not.toContain(undefined);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it('keeps halves and quarters aligned even when opening BYEs make workloads uneven', () => {
|
|
95
|
+
const bouts = createBracket();
|
|
96
|
+
bouts[0].Person2 = createPerson(0);
|
|
97
|
+
bouts[1].Person2 = createPerson(0);
|
|
98
|
+
const assignments = distributeStoryAssignments({ bouts, stations: stations.slice(0, 2) });
|
|
99
|
+
expect(getRingIds(assignments, [bouts[15], bouts[16]])).toEqual([1, 2]);
|
|
100
|
+
expect(countAssignments(assignments, 2)).toEqual([29, 31]);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it('assigns semifinals while leaving finals, placement, and consolation shared', () => {
|
|
104
|
+
const bouts = createBracket();
|
|
105
|
+
bouts.push(
|
|
106
|
+
...['Third Place', 'Consolation Round 8', 'Grand Final'].map((RoundLabel, index) => ({
|
|
107
|
+
...bouts.at(-1),
|
|
108
|
+
BoutId: 2000 + index,
|
|
109
|
+
DEBoutId: 100 + index,
|
|
110
|
+
RoundLabel
|
|
111
|
+
}))
|
|
112
|
+
);
|
|
113
|
+
const assignments = distributeStoryAssignments({ bouts, stations });
|
|
114
|
+
const shared = bouts.filter(bout => !bout.RoundLabel.startsWith('Table of') && bout.RoundLabel !== 'Semifinal');
|
|
115
|
+
expect(
|
|
116
|
+
getRingIds(
|
|
117
|
+
assignments,
|
|
118
|
+
bouts.filter(bout => bout.RoundLabel === 'Semifinal')
|
|
119
|
+
)
|
|
120
|
+
).not.toContain(undefined);
|
|
121
|
+
expect(getRingIds(assignments, shared)).toEqual(shared.map(() => undefined));
|
|
122
|
+
const final = {
|
|
123
|
+
...bouts.find(bout => bout.RoundLabel === 'Final'),
|
|
124
|
+
Person1: createPerson(1),
|
|
125
|
+
Person2: createPerson(2)
|
|
126
|
+
};
|
|
127
|
+
const freshDirector = { Director: { PersonId: 999, DisplayName: 'Fresh Director' } };
|
|
128
|
+
expect(canStoryDirectorDirectBout(final, 999)).toBe(true);
|
|
129
|
+
expect(activateStoryBout(final, freshDirector)).toMatchObject({
|
|
130
|
+
RefereeId: 999,
|
|
131
|
+
RefName: 'Fresh Director',
|
|
132
|
+
Status: 'Active'
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it('redistributes scheduled coverage after adding a director while preserving active and completed plans', () => {
|
|
137
|
+
const bouts = createBracket();
|
|
138
|
+
const previousAssignments = distributeStoryAssignments({ bouts, stations: stations.slice(0, 2) });
|
|
139
|
+
bouts[14].Status = 'Active';
|
|
140
|
+
bouts[15].Status = 'Completed';
|
|
141
|
+
const assignments = distributeStoryAssignments({ bouts, stations: stations.slice(0, 4), previousAssignments });
|
|
142
|
+
expect(getRingIds(assignments, [bouts[14], bouts[15]])).toEqual([1, 1]);
|
|
143
|
+
expect(getRingIds(assignments, [bouts[8], bouts[16], bouts[24]])).toEqual([2, 3, 4]);
|
|
144
|
+
expect(new Set(assignments.map(assignment => assignment.DEBoutId)).size).toBe(assignments.length);
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it('handles no bouts, no stations, and invalid stations without creating assignments', () => {
|
|
148
|
+
expect(distributeStoryAssignments()).toEqual([]);
|
|
149
|
+
expect(distributeStoryAssignments({ bouts: createBracket(), stations: [null, {}, { RingId: 1 }] })).toEqual([]);
|
|
150
|
+
expect(distributeStoryAssignments({ bouts: [], stations })).toEqual([]);
|
|
151
|
+
});
|
|
152
|
+
});
|
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
const STORY_DIRECTOR = {
|
|
2
|
-
PersonId: -1,
|
|
3
|
-
DisplayName: 'Story Director'
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
const isSameBout = (bout, selectedBout) => String(bout.BoutId) === String(selectedBout.BoutId);
|
|
7
|
-
const isActiveBout = bout => String(bout?.Status || '').toLowerCase() === 'active';
|
|
8
|
-
const hasSameIdentity = (firstId, secondId) => String(firstId ?? '') === String(secondId ?? '');
|
|
9
|
-
|
|
10
|
-
export const cloneStoryBouts = bouts => (bouts || []).map(bout => ({ ...bout }));
|
|
11
|
-
|
|
12
|
-
export const canStoryDirectorDirectBout = (bout, directorId) =>
|
|
13
|
-
!isActiveBout(bout) || hasSameIdentity(bout.RefereeId, directorId);
|
|
14
|
-
|
|
15
|
-
export const getStoryDirectorId = station => station?.Director?.PersonId ?? STORY_DIRECTOR.PersonId;
|
|
16
|
-
|
|
17
|
-
export const activateStoryBout = (bout, station = null) => {
|
|
18
|
-
const director = station?.Director || STORY_DIRECTOR;
|
|
19
|
-
|
|
20
|
-
return {
|
|
21
|
-
...bout,
|
|
22
|
-
Status: 'Active',
|
|
23
|
-
RefereeId: director.PersonId,
|
|
24
|
-
RefName: director.DisplayName,
|
|
25
|
-
RingName: station?.RingName || bout.RingName || 'DE Bracket',
|
|
26
|
-
TimerStatus: bout.TimerStatus || 'stopped',
|
|
27
|
-
TimeLeft: Number(bout.TimeLeft) > 0 ? Number(bout.TimeLeft) : 180
|
|
28
|
-
};
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
export const clearStoryBoutChrome = bout => ({
|
|
32
|
-
...bout,
|
|
33
|
-
RingName: '',
|
|
34
|
-
TimerStatus: 'stopped',
|
|
35
|
-
TimeLeft: 0
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
export const replaceStoryBout = (bouts, selectedBout) =>
|
|
39
|
-
bouts.map(bout => (isSameBout(bout, selectedBout) ? { ...selectedBout } : bout));
|
|
1
|
+
const STORY_DIRECTOR = {
|
|
2
|
+
PersonId: -1,
|
|
3
|
+
DisplayName: 'Story Director'
|
|
4
|
+
};
|
|
5
|
+
|
|
6
|
+
const isSameBout = (bout, selectedBout) => String(bout.BoutId) === String(selectedBout.BoutId);
|
|
7
|
+
const isActiveBout = bout => String(bout?.Status || '').toLowerCase() === 'active';
|
|
8
|
+
const hasSameIdentity = (firstId, secondId) => String(firstId ?? '') === String(secondId ?? '');
|
|
9
|
+
|
|
10
|
+
export const cloneStoryBouts = bouts => (bouts || []).map(bout => ({ ...bout }));
|
|
11
|
+
|
|
12
|
+
export const canStoryDirectorDirectBout = (bout, directorId) =>
|
|
13
|
+
!isActiveBout(bout) || hasSameIdentity(bout.RefereeId, directorId);
|
|
14
|
+
|
|
15
|
+
export const getStoryDirectorId = station => station?.Director?.PersonId ?? STORY_DIRECTOR.PersonId;
|
|
16
|
+
|
|
17
|
+
export const activateStoryBout = (bout, station = null) => {
|
|
18
|
+
const director = station?.Director || STORY_DIRECTOR;
|
|
19
|
+
|
|
20
|
+
return {
|
|
21
|
+
...bout,
|
|
22
|
+
Status: 'Active',
|
|
23
|
+
RefereeId: director.PersonId,
|
|
24
|
+
RefName: director.DisplayName,
|
|
25
|
+
RingName: station?.RingName || bout.RingName || 'DE Bracket',
|
|
26
|
+
TimerStatus: bout.TimerStatus || 'stopped',
|
|
27
|
+
TimeLeft: Number(bout.TimeLeft) > 0 ? Number(bout.TimeLeft) : 180
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export const clearStoryBoutChrome = bout => ({
|
|
32
|
+
...bout,
|
|
33
|
+
RingName: '',
|
|
34
|
+
TimerStatus: 'stopped',
|
|
35
|
+
TimeLeft: 0
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
export const replaceStoryBout = (bouts, selectedBout) =>
|
|
39
|
+
bouts.map(bout => (isSameBout(bout, selectedBout) ? { ...selectedBout } : bout));
|
|
@@ -1,79 +1,79 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import {
|
|
3
|
-
activateStoryBout,
|
|
4
|
-
canStoryDirectorDirectBout,
|
|
5
|
-
clearStoryBoutChrome,
|
|
6
|
-
replaceStoryBout
|
|
7
|
-
} from './BracketStoryHarness';
|
|
8
|
-
|
|
9
|
-
describe('Bracket story parent simulation', () => {
|
|
10
|
-
it('returns an Active parent-owned bout without mutating the selected bout', () => {
|
|
11
|
-
const scheduledBout = { BoutId: 42, Status: 'Scheduled', TimeLeft: 0, Score1: 2, Score2: 1 };
|
|
12
|
-
|
|
13
|
-
const activeBout = activateStoryBout(scheduledBout);
|
|
14
|
-
|
|
15
|
-
expect(activeBout).toMatchObject({
|
|
16
|
-
Status: 'Active',
|
|
17
|
-
RefereeId: -1,
|
|
18
|
-
RefName: 'Story Director',
|
|
19
|
-
RingName: 'DE Bracket',
|
|
20
|
-
TimerStatus: 'stopped',
|
|
21
|
-
TimeLeft: 180,
|
|
22
|
-
Score1: 2,
|
|
23
|
-
Score2: 1
|
|
24
|
-
});
|
|
25
|
-
expect(scheduledBout).toEqual({ BoutId: 42, Status: 'Scheduled', TimeLeft: 0, Score1: 2, Score2: 1 });
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it('replaces only the selected bout in the story-owned collection', () => {
|
|
29
|
-
const bouts = [
|
|
30
|
-
{ BoutId: 41, Status: 'Scheduled' },
|
|
31
|
-
{ BoutId: 42, Status: 'Scheduled' }
|
|
32
|
-
];
|
|
33
|
-
const activeBout = { BoutId: 42, Status: 'Active' };
|
|
34
|
-
|
|
35
|
-
expect(replaceStoryBout(bouts, activeBout)).toEqual([bouts[0], activeBout]);
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it('uses the viewer station when the story simulates pulling a scheduled bout', () => {
|
|
39
|
-
const scheduledBout = { BoutId: 42, Status: 'Scheduled' };
|
|
40
|
-
const station = {
|
|
41
|
-
RingName: 'Ring 1',
|
|
42
|
-
Director: { PersonId: 1001, DisplayName: 'Alex Morgan' }
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
expect(activateStoryBout(scheduledBout, station)).toMatchObject({
|
|
46
|
-
Status: 'Active',
|
|
47
|
-
RefereeId: 1001,
|
|
48
|
-
RefName: 'Alex Morgan',
|
|
49
|
-
RingName: 'Ring 1'
|
|
50
|
-
});
|
|
51
|
-
expect(scheduledBout).toEqual({ BoutId: 42, Status: 'Scheduled' });
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it('allows scheduled bouts to move but protects an Active bout owned by another director', () => {
|
|
55
|
-
expect(canStoryDirectorDirectBout({ Status: 'Scheduled', RefereeId: 2002 }, 1001)).toBe(true);
|
|
56
|
-
expect(canStoryDirectorDirectBout({ Status: 'Active', RefereeId: 2002 }, 1001)).toBe(false);
|
|
57
|
-
expect(canStoryDirectorDirectBout({ Status: 'Active', RefereeId: 1001 }, '1001')).toBe(true);
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it('clears story-only ring and timer fields without resetting status or scores', () => {
|
|
61
|
-
const activeBout = {
|
|
62
|
-
BoutId: 42,
|
|
63
|
-
Status: 'Active',
|
|
64
|
-
Score1: 5,
|
|
65
|
-
Score2: 4,
|
|
66
|
-
RingName: 'Ring 3',
|
|
67
|
-
TimerStatus: 'running',
|
|
68
|
-
TimeLeft: 72
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
expect(clearStoryBoutChrome(activeBout)).toEqual({
|
|
72
|
-
...activeBout,
|
|
73
|
-
RingName: '',
|
|
74
|
-
TimerStatus: 'stopped',
|
|
75
|
-
TimeLeft: 0
|
|
76
|
-
});
|
|
77
|
-
expect(activeBout).toMatchObject({ Status: 'Active', Score1: 5, Score2: 4 });
|
|
78
|
-
});
|
|
79
|
-
});
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import {
|
|
3
|
+
activateStoryBout,
|
|
4
|
+
canStoryDirectorDirectBout,
|
|
5
|
+
clearStoryBoutChrome,
|
|
6
|
+
replaceStoryBout
|
|
7
|
+
} from './BracketStoryHarness';
|
|
8
|
+
|
|
9
|
+
describe('Bracket story parent simulation', () => {
|
|
10
|
+
it('returns an Active parent-owned bout without mutating the selected bout', () => {
|
|
11
|
+
const scheduledBout = { BoutId: 42, Status: 'Scheduled', TimeLeft: 0, Score1: 2, Score2: 1 };
|
|
12
|
+
|
|
13
|
+
const activeBout = activateStoryBout(scheduledBout);
|
|
14
|
+
|
|
15
|
+
expect(activeBout).toMatchObject({
|
|
16
|
+
Status: 'Active',
|
|
17
|
+
RefereeId: -1,
|
|
18
|
+
RefName: 'Story Director',
|
|
19
|
+
RingName: 'DE Bracket',
|
|
20
|
+
TimerStatus: 'stopped',
|
|
21
|
+
TimeLeft: 180,
|
|
22
|
+
Score1: 2,
|
|
23
|
+
Score2: 1
|
|
24
|
+
});
|
|
25
|
+
expect(scheduledBout).toEqual({ BoutId: 42, Status: 'Scheduled', TimeLeft: 0, Score1: 2, Score2: 1 });
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('replaces only the selected bout in the story-owned collection', () => {
|
|
29
|
+
const bouts = [
|
|
30
|
+
{ BoutId: 41, Status: 'Scheduled' },
|
|
31
|
+
{ BoutId: 42, Status: 'Scheduled' }
|
|
32
|
+
];
|
|
33
|
+
const activeBout = { BoutId: 42, Status: 'Active' };
|
|
34
|
+
|
|
35
|
+
expect(replaceStoryBout(bouts, activeBout)).toEqual([bouts[0], activeBout]);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('uses the viewer station when the story simulates pulling a scheduled bout', () => {
|
|
39
|
+
const scheduledBout = { BoutId: 42, Status: 'Scheduled' };
|
|
40
|
+
const station = {
|
|
41
|
+
RingName: 'Ring 1',
|
|
42
|
+
Director: { PersonId: 1001, DisplayName: 'Alex Morgan' }
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
expect(activateStoryBout(scheduledBout, station)).toMatchObject({
|
|
46
|
+
Status: 'Active',
|
|
47
|
+
RefereeId: 1001,
|
|
48
|
+
RefName: 'Alex Morgan',
|
|
49
|
+
RingName: 'Ring 1'
|
|
50
|
+
});
|
|
51
|
+
expect(scheduledBout).toEqual({ BoutId: 42, Status: 'Scheduled' });
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('allows scheduled bouts to move but protects an Active bout owned by another director', () => {
|
|
55
|
+
expect(canStoryDirectorDirectBout({ Status: 'Scheduled', RefereeId: 2002 }, 1001)).toBe(true);
|
|
56
|
+
expect(canStoryDirectorDirectBout({ Status: 'Active', RefereeId: 2002 }, 1001)).toBe(false);
|
|
57
|
+
expect(canStoryDirectorDirectBout({ Status: 'Active', RefereeId: 1001 }, '1001')).toBe(true);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('clears story-only ring and timer fields without resetting status or scores', () => {
|
|
61
|
+
const activeBout = {
|
|
62
|
+
BoutId: 42,
|
|
63
|
+
Status: 'Active',
|
|
64
|
+
Score1: 5,
|
|
65
|
+
Score2: 4,
|
|
66
|
+
RingName: 'Ring 3',
|
|
67
|
+
TimerStatus: 'running',
|
|
68
|
+
TimeLeft: 72
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
expect(clearStoryBoutChrome(activeBout)).toEqual({
|
|
72
|
+
...activeBout,
|
|
73
|
+
RingName: '',
|
|
74
|
+
TimerStatus: 'stopped',
|
|
75
|
+
TimeLeft: 0
|
|
76
|
+
});
|
|
77
|
+
expect(activeBout).toMatchObject({ Status: 'Active', Score1: 5, Score2: 4 });
|
|
78
|
+
});
|
|
79
|
+
});
|
|
@@ -1,93 +1,93 @@
|
|
|
1
|
-
import { ref } from 'vue';
|
|
2
|
-
import editConfig from './EditEventInfo.vue';
|
|
3
|
-
import singleEventMock from '../../../../mocks/singleEventMock.js';
|
|
4
|
-
import eventRules from '../../../../mocks/eventRules.js';
|
|
5
|
-
import getAllWeapons from '../../../../mocks/getAllWeapons.js';
|
|
6
|
-
|
|
7
|
-
export default {
|
|
8
|
-
title: 'Templates/EventManagement/EditEventInfo',
|
|
9
|
-
component: editConfig,
|
|
10
|
-
tags: ['autodocs'],
|
|
11
|
-
args: {
|
|
12
|
-
event: singleEventMock,
|
|
13
|
-
weapons: getAllWeapons,
|
|
14
|
-
rules: eventRules,
|
|
15
|
-
userLevel: 'admin'
|
|
16
|
-
},
|
|
17
|
-
argTypes: {
|
|
18
|
-
editMode: { control: 'boolean' },
|
|
19
|
-
step: { control: { type: 'number', min: 1, max: 5 } },
|
|
20
|
-
saving: { control: 'boolean' },
|
|
21
|
-
saveError: { control: 'text' },
|
|
22
|
-
saveNotice: { control: 'text' },
|
|
23
|
-
event: { control: 'object' },
|
|
24
|
-
weapons: { control: 'object' },
|
|
25
|
-
rules: { control: 'object' },
|
|
26
|
-
userLevel: { control: 'text' }
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
export const Default = {
|
|
31
|
-
args: {
|
|
32
|
-
event: singleEventMock,
|
|
33
|
-
weapons: getAllWeapons,
|
|
34
|
-
rules: eventRules,
|
|
35
|
-
userLevel: 'admin'
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
export const NewEvent = {
|
|
40
|
-
args: {
|
|
41
|
-
event: {
|
|
42
|
-
Absent: 0,
|
|
43
|
-
Date: new Date().toISOString().split('T')[0],
|
|
44
|
-
EventName: '',
|
|
45
|
-
Flights: 1,
|
|
46
|
-
NumberOfPools: 2,
|
|
47
|
-
NumberOfRings: 2,
|
|
48
|
-
PoolSize: 0,
|
|
49
|
-
Present: 0,
|
|
50
|
-
StartTime: '12:00:00',
|
|
51
|
-
Status: 'planning',
|
|
52
|
-
TournamentId: 10
|
|
53
|
-
},
|
|
54
|
-
weapons: getAllWeapons,
|
|
55
|
-
rules: [],
|
|
56
|
-
userLevel: 'admin'
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
export const EditWithStepSaves = {
|
|
61
|
-
args: { ...Default.args, editMode: true, step: 1 },
|
|
62
|
-
render: args => ({
|
|
63
|
-
components: { Editor: editConfig },
|
|
64
|
-
setup() {
|
|
65
|
-
const event = ref(JSON.parse(JSON.stringify(args.event)));
|
|
66
|
-
const step = ref(args.step);
|
|
67
|
-
const saving = ref(false);
|
|
68
|
-
const notice = ref('');
|
|
69
|
-
const saveStep = async request => {
|
|
70
|
-
saving.value = true;
|
|
71
|
-
await new Promise(resolve => setTimeout(resolve, 500));
|
|
72
|
-
event.value = request.event;
|
|
73
|
-
step.value = Math.min(request.step + 1, 5);
|
|
74
|
-
notice.value = 'Changes saved.';
|
|
75
|
-
saving.value = false;
|
|
76
|
-
};
|
|
77
|
-
const clearNotice = dirty => {
|
|
78
|
-
if (dirty) notice.value = '';
|
|
79
|
-
};
|
|
80
|
-
return { args, event, step, saving, notice, saveStep, clearNotice };
|
|
81
|
-
},
|
|
82
|
-
template:
|
|
83
|
-
'<Editor v-bind="args" :rules="args.rules" :weapons="args.weapons" :event="event" :step="step" :saving="saving" :saveNotice="notice" @save:step="saveStep" @navigate:step="step = $event" @update:dirty="clearNotice" />'
|
|
84
|
-
})
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
export const SavingStep = {
|
|
88
|
-
args: { ...Default.args, editMode: true, step: 2, saving: true }
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
export const StepSaveFailed = {
|
|
92
|
-
args: { ...Default.args, editMode: true, step: 2, saveError: 'Changes could not be saved. Please try again.' }
|
|
93
|
-
};
|
|
1
|
+
import { ref } from 'vue';
|
|
2
|
+
import editConfig from './EditEventInfo.vue';
|
|
3
|
+
import singleEventMock from '../../../../mocks/singleEventMock.js';
|
|
4
|
+
import eventRules from '../../../../mocks/eventRules.js';
|
|
5
|
+
import getAllWeapons from '../../../../mocks/getAllWeapons.js';
|
|
6
|
+
|
|
7
|
+
export default {
|
|
8
|
+
title: 'Templates/EventManagement/EditEventInfo',
|
|
9
|
+
component: editConfig,
|
|
10
|
+
tags: ['autodocs'],
|
|
11
|
+
args: {
|
|
12
|
+
event: singleEventMock,
|
|
13
|
+
weapons: getAllWeapons,
|
|
14
|
+
rules: eventRules,
|
|
15
|
+
userLevel: 'admin'
|
|
16
|
+
},
|
|
17
|
+
argTypes: {
|
|
18
|
+
editMode: { control: 'boolean' },
|
|
19
|
+
step: { control: { type: 'number', min: 1, max: 5 } },
|
|
20
|
+
saving: { control: 'boolean' },
|
|
21
|
+
saveError: { control: 'text' },
|
|
22
|
+
saveNotice: { control: 'text' },
|
|
23
|
+
event: { control: 'object' },
|
|
24
|
+
weapons: { control: 'object' },
|
|
25
|
+
rules: { control: 'object' },
|
|
26
|
+
userLevel: { control: 'text' }
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export const Default = {
|
|
31
|
+
args: {
|
|
32
|
+
event: singleEventMock,
|
|
33
|
+
weapons: getAllWeapons,
|
|
34
|
+
rules: eventRules,
|
|
35
|
+
userLevel: 'admin'
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export const NewEvent = {
|
|
40
|
+
args: {
|
|
41
|
+
event: {
|
|
42
|
+
Absent: 0,
|
|
43
|
+
Date: new Date().toISOString().split('T')[0],
|
|
44
|
+
EventName: '',
|
|
45
|
+
Flights: 1,
|
|
46
|
+
NumberOfPools: 2,
|
|
47
|
+
NumberOfRings: 2,
|
|
48
|
+
PoolSize: 0,
|
|
49
|
+
Present: 0,
|
|
50
|
+
StartTime: '12:00:00',
|
|
51
|
+
Status: 'planning',
|
|
52
|
+
TournamentId: 10
|
|
53
|
+
},
|
|
54
|
+
weapons: getAllWeapons,
|
|
55
|
+
rules: [],
|
|
56
|
+
userLevel: 'admin'
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export const EditWithStepSaves = {
|
|
61
|
+
args: { ...Default.args, editMode: true, step: 1 },
|
|
62
|
+
render: args => ({
|
|
63
|
+
components: { Editor: editConfig },
|
|
64
|
+
setup() {
|
|
65
|
+
const event = ref(JSON.parse(JSON.stringify(args.event)));
|
|
66
|
+
const step = ref(args.step);
|
|
67
|
+
const saving = ref(false);
|
|
68
|
+
const notice = ref('');
|
|
69
|
+
const saveStep = async request => {
|
|
70
|
+
saving.value = true;
|
|
71
|
+
await new Promise(resolve => setTimeout(resolve, 500));
|
|
72
|
+
event.value = request.event;
|
|
73
|
+
step.value = Math.min(request.step + 1, 5);
|
|
74
|
+
notice.value = 'Changes saved.';
|
|
75
|
+
saving.value = false;
|
|
76
|
+
};
|
|
77
|
+
const clearNotice = dirty => {
|
|
78
|
+
if (dirty) notice.value = '';
|
|
79
|
+
};
|
|
80
|
+
return { args, event, step, saving, notice, saveStep, clearNotice };
|
|
81
|
+
},
|
|
82
|
+
template:
|
|
83
|
+
'<Editor v-bind="args" :rules="args.rules" :weapons="args.weapons" :event="event" :step="step" :saving="saving" :saveNotice="notice" @save:step="saveStep" @navigate:step="step = $event" @update:dirty="clearNotice" />'
|
|
84
|
+
})
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
export const SavingStep = {
|
|
88
|
+
args: { ...Default.args, editMode: true, step: 2, saving: true }
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
export const StepSaveFailed = {
|
|
92
|
+
args: { ...Default.args, editMode: true, step: 2, saveError: 'Changes could not be saved. Please try again.' }
|
|
93
|
+
};
|