diff --git a/src/StacBrowser.vue b/src/StacBrowser.vue index 0fc6f851a..90dc71a1f 100644 --- a/src/StacBrowser.vue +++ b/src/StacBrowser.vue @@ -174,7 +174,7 @@ export default { // A better way would be to combine the language code and URL as the index in the browser database // This needs a database refactor though: https://github.com/radiantearth/stac-browser/issues/231 this.$store.commit('resetCatalog', true); - await this.$store.dispatch("load", { url, loadApi: true, show: true }); + await this.$store.dispatch("load", { url, show: true }); } } } diff --git a/src/components/StacHeader.vue b/src/components/StacHeader.vue index 876f8f415..bd4009a8c 100644 --- a/src/components/StacHeader.vue +++ b/src/components/StacHeader.vue @@ -169,7 +169,6 @@ export default { if (this.url) { this.addAction(() => this.$store.dispatch("load", { url: this.url, - loadApi: true, show: true, force: true, noRetry: true diff --git a/src/components/Tree.vue b/src/components/Tree.vue index d51bc4d46..353188e11 100644 --- a/src/components/Tree.vue +++ b/src/components/Tree.vue @@ -219,7 +219,7 @@ export default { if (this.expanded && !this.pagination) { this.loading = true; let url = this.item instanceof STAC ? this.item.getAbsoluteUrl() : this.item.href; - await this.$store.dispatch("load", { url, loadApi: true }); + await this.$store.dispatch("load", { url }); this.loading = false; } } @@ -251,4 +251,4 @@ export default { margin-left: 1.5em; } } - \ No newline at end of file + diff --git a/src/store/index.js b/src/store/index.js index 691ed36ec..e3cc80c51 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -465,10 +465,9 @@ function getStore(config, router) { Vue.delete(state.stateQueryParameters[type], idx); } }, - updateLoading(state, { url, show, loadApi }) { + updateLoading(state, { url, show }) { let data = state.database[url]; Vue.set(data, 'show', show || data.show); - Vue.set(data, 'loadApi', loadApi || data.loadApi); }, loading(state, { url, loading }) { Vue.set(state.database, url, loading); @@ -686,7 +685,7 @@ function getStore(config, router) { break; } let url = Utils.toAbsolute(parentLink.href, stac.getAbsoluteUrl()); - await cx.dispatch('load', { url, loadApi: true }); + await cx.dispatch('load', { url }); let parentStac = cx.getters.getStac(url, true); if (parentStac instanceof Error) { cx.commit('parents', parentStac); @@ -709,102 +708,110 @@ function getStore(config, router) { await cx.dispatch('auth/requestLogin'); }, async load(cx, args) { - let { url, show, loadApi, loadRoot, force, noRetry } = args; + let { url, show, force, noRetry } = args; - let path = cx.getters.toBrowserPath(url); + const path = cx.getters.toBrowserPath(url); url = Utils.toAbsolute(url, cx.state.url); // Make sure we have all authentication details await cx.dispatch("auth/waitForAuth"); - // Load the root catalog data if not available (e.g. after page refresh or external access) - if (!loadRoot && path !== '/' && cx.state.catalogUrl && !cx.getters.getStac(cx.state.catalogUrl)) { - await cx.dispatch("load", { url: cx.state.catalogUrl, loadApi: true, loadRoot: true }); - } - if (force) { cx.commit('clear', url); } - let loading = new Loading(show, loadApi); + let loading = new Loading(show); let data = cx.state.database[url]; if (data instanceof Loading) { - cx.commit('updateLoading', { url, show, loadApi }); + cx.commit('updateLoading', { url, show }); + return; + } + else if (data instanceof STAC && !data.isPotentiallyIncomplete()) { + if (show) { + cx.commit('showPage', { url }); + } return; } - else if (!data || data instanceof Error || (data instanceof STAC && data.isPotentiallyIncomplete())) { - cx.commit('loading', { url, loading }); - try { - let response = await stacRequest(cx, url); - if (!Utils.isObject(response.data)) { - throw new BrowserError(i18n.t('errors.invalidJsonObject')); - } - data = new STAC(response.data, url, path); - cx.commit('loaded', { url, data }); - if (show) { - // If we prefer another language abort redirect to the new language - let localeLink = data.getLocaleLink(cx.state.dataLanguage); - if (localeLink) { - router.replace(cx.getters.toBrowserPath(localeLink.href)); - return; - } + cx.commit('loading', { url, loading }); + try { + const response = await stacRequest(cx, url); + if (!Utils.isObject(response.data)) { + throw new BrowserError(i18n.t('errors.invalidJsonObject')); + } + data = new STAC(response.data, url, path); + cx.commit('loaded', { url, data }); + + if (show) { + // If we prefer another language abort redirect to the new language + let localeLink = data.getLocaleLink(cx.state.dataLanguage); + if (localeLink) { + router.replace(cx.getters.toBrowserPath(localeLink.href)); + return; } + } - if (!cx.getters.root) { - let root = data.getLinkWithRel('root'); - if (root) { - await cx.dispatch('config', { catalogUrl: Utils.toAbsolute(root.href, url) }); - } - } + // Handle conformance classes + let conformanceLink = data.getStacLinkWithRel('conformance'); + if (Array.isArray(data.conformsTo) && data.conformsTo.length > 0) { + cx.commit('setConformanceClasses', data.conformsTo); + } + else if (conformanceLink) { + await cx.dispatch('loadOgcApiConformance', conformanceLink); + } + } catch (error) { + if (!noRetry && cx.state.authConfig && isAuthenticationError(error)) { + await cx.dispatch('tryLogin', { + url, + action: () => cx.dispatch('load', Object.assign({noRetry: true, force: true, show: true}, args)) + }); + return; + } + console.error(error); + cx.commit('errored', { url, error }); + } - let conformanceLink = data.getStacLinkWithRel('conformance'); - if (Array.isArray(data.conformsTo) && data.conformsTo.length > 0) { - cx.commit('setConformanceClasses', data.conformsTo); - } - else if (conformanceLink) { - await cx.dispatch('loadOgcApiConformance', conformanceLink); - } + // Load API Collections + if (data.getApiCollectionsLink()) { + let args = { stac: data, show: loading.show }; + try { + await cx.dispatch('loadNextApiCollections', args); } catch (error) { - if (!noRetry && cx.state.authConfig && isAuthenticationError(error)) { - await cx.dispatch('tryLogin', { - url, - action: () => cx.dispatch('load', Object.assign({noRetry: true, force: true, show: true}, args)) - }); - return; - } - console.error(error); - cx.commit('errored', { url, error }); - } - } - - if (loading.loadApi && data instanceof STAC) { - // Load API Collections - if (data.getApiCollectionsLink()) { - let args = { stac: data, show: loading.show }; - try { - await cx.dispatch('loadNextApiCollections', args); - } catch (error) { - cx.commit('showGlobalError', { - message: i18n.t('errors.loadApiCollectionsFailed'), - error - }); - } + cx.commit('showGlobalError', { + message: i18n.t('errors.loadApiCollectionsFailed'), + error + }); + } + } + // Load API Items + if (data.getApiItemsLink()) { + let args = { stac: data, show: loading.show }; + try { + await cx.dispatch('loadApiItems', args); + } catch (error) { + cx.commit('showGlobalError', { + message: i18n.t('errors.loadApiItemsFailed'), + error + }); } - // Load API Items - if (data.getApiItemsLink()) { - let args = { stac: data, show: loading.show }; - try { - await cx.dispatch('loadApiItems', args); - } catch (error) { - cx.commit('showGlobalError', { - message: i18n.t('errors.loadApiItemsFailed'), - error - }); + } + + // Load the root catalog data if not available (e.g. after page refresh or external access) + if (!cx.getters.root) { + let catalogUrl = cx.state.catalogUrl; + if (!catalogUrl) { + const root = data.getLinkWithRel('root'); + if (root) { + catalogUrl = Utils.toAbsolute(root.href, url); + await cx.dispatch('config', { catalogUrl }); } } + if (catalogUrl) { + await cx.dispatch("load", { url: catalogUrl }); + } } + // All tasks finished, show the page if requested if (loading.show) { cx.commit('showPage', { url }); } diff --git a/src/store/utils.js b/src/store/utils.js index 47a7eda5d..efbf76edc 100644 --- a/src/store/utils.js +++ b/src/store/utils.js @@ -4,9 +4,8 @@ import Utils from "../utils"; export class Loading { - constructor(show = false, loadApi = false) { + constructor(show = false) { this.show = Boolean(show); - this.loadApi = Boolean(loadApi); } } diff --git a/src/views/BrowseMixin.js b/src/views/BrowseMixin.js index f8f17bb43..1dbb5c17b 100644 --- a/src/views/BrowseMixin.js +++ b/src/views/BrowseMixin.js @@ -77,7 +77,7 @@ export default { } let url = this.fromBrowserPath(path || '/'); - this.$store.dispatch("load", { url, show: true, loadApi: true }); + this.$store.dispatch("load", { url, show: true }); } } }, diff --git a/src/views/Search.vue b/src/views/Search.vue index 37bdbed2c..9c186599d 100644 --- a/src/views/Search.vue +++ b/src/views/Search.vue @@ -217,7 +217,7 @@ export default { this.parent = this.root; } if (!this.parent) { - await this.$store.dispatch('load', { url, loadApi: true }); + await this.$store.dispatch('load', { url }); if (!this.root) { await this.$store.dispatch("config", { catalogUrl: url }); }