1 | import { createApp } from "vue";
|
---|
2 | import { createStore } from "vuex"
|
---|
3 | import App from "./App.vue";
|
---|
4 | import ToggleButton from "./components/ToggleButton.vue"
|
---|
5 |
|
---|
6 | export class TranscriptionViewModel {
|
---|
7 | /**
|
---|
8 | * Initialises a new instance of the {@link TranscriptionViewModel} class.
|
---|
9 | *
|
---|
10 | * @param {TranscriptionModel} transcription
|
---|
11 | * @param {File} file The file from which the transcription was generated.
|
---|
12 | */
|
---|
13 | constructor(transcription, file) {
|
---|
14 | /** @type {String} The UUID of this transcription. */
|
---|
15 | this.id = file.name + file.size + file.type; // Should be a fairly reliable indicator of uniqueness.
|
---|
16 |
|
---|
17 | /** @type {String} The transcription. */
|
---|
18 | this.transcription = transcription.transcription;
|
---|
19 |
|
---|
20 | /** @type {String} The name of the file from which the transcription was generated. */
|
---|
21 | this.fileName = transcription.file_name;
|
---|
22 |
|
---|
23 | /** @type {TranscriptionMetadata[]} The transcription metadata. */
|
---|
24 | this.metadata = transcription.metadata;
|
---|
25 |
|
---|
26 | /** @type {File} The file from which the transcription was generated. */
|
---|
27 | this.file = file;
|
---|
28 | }
|
---|
29 | }
|
---|
30 |
|
---|
31 | export class PlaybackState {
|
---|
32 | /**
|
---|
33 | * Initialises a new instance of the {@link PlaybackState} class.
|
---|
34 | * @param {String} id The ID of the transcription for which audio is being played.
|
---|
35 | * @param {Boolean} isPlaying A value indicating if audio is currently being played.
|
---|
36 | * @param {Number} currentTime The current time in the audio playback.
|
---|
37 | * @param {Number} length The length of the audio track.
|
---|
38 | */
|
---|
39 | constructor(id = "", isPlaying = false, currentTime = 0, length = 0) {
|
---|
40 | /** @type {String} The ID of the transcription for which audio is currently being played. */
|
---|
41 | this.id = id;
|
---|
42 |
|
---|
43 | /** @type {Boolean} Gets a value indicating if audio is currently being played back. */
|
---|
44 | this.isPlaying = isPlaying;
|
---|
45 |
|
---|
46 | /** @type {Number} Gets the current time in the playback. */
|
---|
47 | this.currentTime = currentTime;
|
---|
48 |
|
---|
49 | /** @type {Number} Gets the length of the current audio track. */
|
---|
50 | this.length = length;
|
---|
51 | }
|
---|
52 | }
|
---|
53 |
|
---|
54 | export class TranscriptionExistsError extends Error {
|
---|
55 | constructor(message = "", ...args) {
|
---|
56 | super(message, ...args);
|
---|
57 | }
|
---|
58 | }
|
---|
59 |
|
---|
60 | const store = createStore({
|
---|
61 | state() {
|
---|
62 | return {
|
---|
63 | /** @type {Map<String, String>} */
|
---|
64 | translations: new Map(),
|
---|
65 | /** @type {Map<String, TranscriptionViewModel>} */
|
---|
66 | rawTranscriptions: new Map(),
|
---|
67 | playbackState: new PlaybackState()
|
---|
68 | }
|
---|
69 | },
|
---|
70 | mutations: {
|
---|
71 | /**
|
---|
72 | * Adds a new transcription to the store.
|
---|
73 | * @param {*} state The state of the store.
|
---|
74 | * @param {TranscriptionViewModel} transcription The transcription's view model object.
|
---|
75 | */
|
---|
76 | transcriptionAdd(state, transcription) {
|
---|
77 | if (state.rawTranscriptions.has(transcription.id)) {
|
---|
78 | throw new Error("Transcription already exists");
|
---|
79 | }
|
---|
80 | state.rawTranscriptions.set(transcription.id, transcription);
|
---|
81 | },
|
---|
82 |
|
---|
83 | /**
|
---|
84 | * Removes a transcription from the store.
|
---|
85 | * @param {*} state The state of the store.
|
---|
86 | * @param {String} id The UUID of the transcription.
|
---|
87 | */
|
---|
88 | transcriptionRemove(state, id) {
|
---|
89 | state.rawTranscriptions.delete(id);
|
---|
90 | },
|
---|
91 |
|
---|
92 | /**
|
---|
93 | * Sets the current playback state.
|
---|
94 | * @param {*} state The state of the store.
|
---|
95 | * @param {PlaybackState} playbackState The new playback state.
|
---|
96 | */
|
---|
97 | setPlaybackState(state, playbackState) {
|
---|
98 | state.playbackState = playbackState;
|
---|
99 | },
|
---|
100 | setCurrentlyPlaying(state, isPlaying) {
|
---|
101 | state.playbackState.isPlaying = isPlaying;
|
---|
102 | },
|
---|
103 | setCurrentPlaybackTime(state, time) {
|
---|
104 | state.playbackState.currentTime = time;
|
---|
105 | },
|
---|
106 | setCurrentlyPlayingId(state, id) {
|
---|
107 | state.playbackState.id = id;
|
---|
108 | },
|
---|
109 | setTranslations(state, translations) {
|
---|
110 | state.translations = translations;
|
---|
111 | }
|
---|
112 | }
|
---|
113 | });
|
---|
114 |
|
---|
115 | createApp(App)
|
---|
116 | .use(store)
|
---|
117 | .component("ToggleButton", ToggleButton)
|
---|
118 | .mount("#app");
|
---|
119 |
|
---|
120 | /* === Get interface translations === */
|
---|
121 |
|
---|
122 | /** @type {Map<String, String>} */
|
---|
123 | const translations = new Map();
|
---|
124 |
|
---|
125 | /* We might be running under Greenstone, so pull the tranlsations from there if so */
|
---|
126 | /* eslint-disable no-undef */
|
---|
127 | if (typeof gs !== "undefined" && gs.text && gs.text.atea) {
|
---|
128 | for (const key in gs.text.atea) {
|
---|
129 | translations.set(key, gs.text.atea[key]);
|
---|
130 | }
|
---|
131 |
|
---|
132 | store.commit("setTranslations", translations)
|
---|
133 | }
|
---|
134 | /* eslint-enable no-undef */
|
---|
135 | else {
|
---|
136 | fetch("resources/interface_atea.properties")
|
---|
137 | .then(async response => {
|
---|
138 | const responseText = await response.text();
|
---|
139 | const responseTranslations = responseText.split("\n");
|
---|
140 |
|
---|
141 | for (const translation of responseTranslations) {
|
---|
142 | const components = translation.split("=");
|
---|
143 |
|
---|
144 | if (components[0] === "") {
|
---|
145 | continue;
|
---|
146 | }
|
---|
147 |
|
---|
148 | const namespaceEndIndex = components[0].lastIndexOf(".");
|
---|
149 | translations.set(components[0].slice(namespaceEndIndex + 1), components[1]);
|
---|
150 | }
|
---|
151 |
|
---|
152 | store.commit("setTranslations", translations)
|
---|
153 | });
|
---|
154 | }
|
---|