-
Notifications
You must be signed in to change notification settings - Fork 85
/
script.js
64 lines (59 loc) · 1.81 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { mapState, mapGetters, mapMutations, mapActions } from 'vuex';
import RawFileReader from 'paraview-glance/src/components/core/RawFileReader';
import { Actions, Getters, Mutations } from 'paraview-glance/src/store/types';
// ----------------------------------------------------------------------------
export default {
name: 'FileLoader',
components: {
RawFileReader,
},
computed: Object.assign(
mapState({
stage: (state) => state.files.stage,
files: (state) => state.files.files,
loadingNames: (state) =>
[].concat(state.files.urls, state.files.files).map((o) => o.name),
preloadCanContinue(state) {
const { files, rawInfos } = state.files;
for (let i = 0; i < files.length; i++) {
const file = files[i];
if (
this.isRawFile(file) &&
(!(i in rawInfos) || rawInfos[i].effectiveSize !== file.size)
) {
return false;
}
}
return true;
},
}),
mapGetters({
totalProgress: Getters.FILE_TOTAL_PROGRESS,
preloadCanLoad: Getters.FILE_RAW_FILES_LOADABLE,
indeterminateProgress: Getters.FILE_INDETERMINATE_PROGRESS,
})
),
methods: Object.assign(
mapMutations({
setFileRawInfo: (commit, fileIndex, rawInfo) =>
commit(Mutations.FILE_SET_RAW_INFO, { fileIndex, rawInfo }),
cancel: Mutations.FILE_IDLE,
closeAndTryToLoad(commit) {
const allFilesErrored = this.files.reduce(
(flag, { error }) => flag && error,
true
);
if (!allFilesErrored) {
commit(Mutations.SHOW_APP);
}
commit(Mutations.FILE_IDLE);
},
}),
mapActions({
openFiles: Actions.OPEN_FILES,
}),
{
isRawFile: (f) => f.name.toLowerCase().endsWith('.raw'),
}
),
};