Skip to content

Commit

Permalink
Merge pull request #457 from DavidBerger98/support-file-series-in-res…
Browse files Browse the repository at this point in the history
…tore-app-state

feat(store): Support loading file series in restoreAppState
  • Loading branch information
floryst authored Oct 21, 2022
2 parents a386b3c + 4b12d4c commit 7d6f01b
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/store/fileLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function getSupportedExtensions() {

// ----------------------------------------------------------------------------

function getExtension(filename) {
export function getExtension(filename) {
const i = filename.lastIndexOf('.');
if (i > -1) {
return filename.substr(i + 1).toLowerCase();
Expand Down
73 changes: 48 additions & 25 deletions src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import viewHelper from 'paraview-glance/src/components/core/VtkView/helper';
import ReaderFactory from 'paraview-glance/src/io/ReaderFactory';
import postProcessDataset from 'paraview-glance/src/io/postProcessing';
import Config from 'paraview-glance/src/config';
import files from 'paraview-glance/src/store/fileLoader';
import files, { getExtension } from 'paraview-glance/src/store/fileLoader';
import views from 'paraview-glance/src/store/views';
import widgets from 'paraview-glance/src/store/widgets';
import animations from 'paraview-glance/src/store/animations';
Expand All @@ -28,6 +28,10 @@ function typeOf(o) {
return {}.toString.call(o).slice(8, -1).toLowerCase();
}

function extractFilenameFromUrl(url) {
return url.split('/').pop()?.split('?').shift();
}

// quick object merge using Vue.set
/* eslint-disable no-param-reassign */
function merge(dst, src) {
Expand Down Expand Up @@ -247,17 +251,35 @@ function createStore(injected) {
};
}

return ReaderFactory.downloadDataset(name, url, {
...options,
progressCallback(progress) {
const percentage = progress.lengthComputable
? progress.loaded / progress.total
: Infinity;
commit('files/setProgress', { id: name, percentage });
},
})
.then((file) => ReaderFactory.loadFiles([file]))
.then((readers) => readers[0])
let loadDataset;

if (ds.seriesUrls) {
const extension = getExtension(ds.name);
const promises = ds.seriesUrls.map((u) =>
ReaderFactory.downloadDataset(
extractFilenameFromUrl(u),
u,
options
)
);
loadDataset = Promise.all(promises).then((fileSeries) =>
ReaderFactory.loadFileSeries(fileSeries, extension, name)
);
} else {
loadDataset = ReaderFactory.downloadDataset(name, url, {
...options,
progressCallback(progress) {
const percentage = progress.lengthComputable
? progress.loaded / progress.total
: Infinity;
commit('files/setProgress', { id: name, percentage });
},
})
.then((file) => ReaderFactory.loadFiles([file]))
.then((readers) => readers[0]);
}

return loadDataset
.then(({ dataset, reader }) => {
let outDS = null;
if (reader && reader.getOutputData) {
Expand All @@ -269,20 +291,21 @@ function createStore(injected) {
return null;
}

if (outDS) {
if (ds.serializedType === 'girder') {
outDS = postProcessDataset(outDS, ds.meta);
restoreProxyKeys.set(outDS, {
girderProvenance: ds.provenance,
girderItem: ds.item,
meta: ds.meta,
});
} else {
outDS.set(ds, true); // Attach remote data origin
}
return outDS;
if (!outDS) {
throw new Error('Invalid dataset');
}

if (ds.serializedType === 'girder') {
outDS = postProcessDataset(outDS, ds.meta);
restoreProxyKeys.set(outDS, {
girderProvenance: ds.provenance,
girderItem: ds.item,
meta: ds.meta,
});
} else {
outDS.set(ds, true); // Attach remote data origin
}
throw new Error('Invalid dataset');
return outDS;
})
.catch((e) => {
// more meaningful error
Expand Down

0 comments on commit 7d6f01b

Please sign in to comment.