diff --git a/src/presentation/components/App.vue b/src/presentation/components/App.vue index b8a87bcd..f659018a 100644 --- a/src/presentation/components/App.vue +++ b/src/presentation/components/App.vue @@ -7,11 +7,12 @@ + + + diff --git a/src/presentation/components/DevToolkit/DumpNames.ts b/src/presentation/components/DevToolkit/DumpNames.ts new file mode 100644 index 00000000..750e95b1 --- /dev/null +++ b/src/presentation/components/DevToolkit/DumpNames.ts @@ -0,0 +1,35 @@ +import { IApplication } from '@/domain/IApplication'; +import { ApplicationFactory } from '@/application/ApplicationFactory'; + +export async function dumpNames(): Promise { + const application = await ApplicationFactory.Current.getApp(); + const names = collectNames(application); + const output = names.join('\n'); + return output; +} + +function collectNames(application: IApplication): string[] { + const { collections } = application; + + const allNames = [ + ...collections.flatMap((collection) => collection.getAllCategories().map((c) => c.name)), + ...collections.flatMap((collection) => collection.getAllScripts().map((c) => c.name)), + ]; + + const uniqueNames = [...new Set(allNames)]; + + return shuffle(uniqueNames); +} + +/* + Shuffle an array of strings, returning a new array with elements in random order. + Uses the Fisher-Yates (or Durstenfeld) algorithm. +*/ +function shuffle(array: readonly string[]): string[] { + const shuffledArray = [...array]; + for (let i = array.length - 1; i > 0; i--) { + const j = Math.floor(Math.random() * (i + 1)); + [shuffledArray[i], shuffledArray[j]] = [shuffledArray[j], shuffledArray[i]]; + } + return shuffledArray; +} diff --git a/src/presentation/components/TheHeader.vue b/src/presentation/components/TheHeader.vue index 07f863e0..7b9eaf77 100644 --- a/src/presentation/components/TheHeader.vue +++ b/src/presentation/components/TheHeader.vue @@ -22,6 +22,7 @@ export default defineComponent({ }; }, }); +