From 06ceaf6aa5f99da7a5db6ff3933b4779c62f8547 Mon Sep 17 00:00:00 2001 From: Matthias Mohr Date: Fri, 13 Nov 2020 10:43:30 +0100 Subject: [PATCH 1/4] Support API Collections https://github.com/radiantearth/stac-browser/issues/48 --- src/components/Catalog.vue | 116 ++++++++++++++++++++++++++++++++++--- src/main.js | 8 ++- src/migrate.js | 2 +- 3 files changed, 117 insertions(+), 9 deletions(-) diff --git a/src/components/Catalog.vue b/src/components/Catalog.vue index 21f9f540f..0ee51d0c8 100644 --- a/src/components/Catalog.vue +++ b/src/components/Catalog.vue @@ -49,6 +49,37 @@
+ + + + + + + x.rel === "data"); + if (externalCollections === undefined) { + return []; + } + + try { + const rsp = await fetch(externalCollections.href); + if (!rsp.ok) { + console.warn(await rsp.text()); + return []; + } + + const data = await rsp.json(); + if (!data || !Array.isArray(data.collections)) { + console.warn(await rsp.text()); + return []; + } + + return data.collections + .map(collection => { + // strip /collection from the target path + let p = this.path.replace(/^\/collection/, ""); + if (!p.endsWith("/")) { + p += "/"; + } + + // Try to get the location of the collection + let href = externalCollections.href + '/collections/' + collection.id; + if (Array.isArray(collection.links)) { + let selfLink = collection.links.find(l => l.rel == 'self'); + if (selfLink && selfLink.href) { + href = selfLink.href; + } + } + + const slug = this.slugify(this.resolve(href, this.url)); + const to = [p, slug].join(""); + + return Object.assign(collection, { + path: href, + to, + title: collection.title || collection.id || href, + url: this.resolve(href, this.url) + }); + }); + } catch (err) { + console.warn(err); + + return []; + } + } + }, externalItems: { default: [], lazy: true, async get() { const externalItemsLink = this.links.find(x => x.rel === "items"); - if (externalItemsLink == null) { + if (externalItemsLink === undefined) { return []; } @@ -337,16 +437,17 @@ export default { catalog() { return this.entity; }, + collectionCount() { + return this.collections.length; + }, childCount() { - return this.links.filter(x => x.rel === "child").length; + return this.children.length; }, children() { - return this.links - .filter(x => x.rel === "child") + return this.links.filter(x => x.rel === "child") .map(child => { // strip /collection from the target path let p = this.path.replace(/^\/collection/, ""); - if (!p.endsWith("/")) { p += "/"; } @@ -606,6 +707,7 @@ export default { }, visibleTabs() { return [ + this.collectionCount > 0 && "collections", this.childCount > 0 && "catalogs", (this.hasExternalItems || this.itemCount > 0) && "items", this.bands.length > 0 && "bands", diff --git a/src/main.js b/src/main.js index 7081d39d8..8d8bca549 100644 --- a/src/main.js +++ b/src/main.js @@ -99,7 +99,13 @@ const main = async () => { }; const catalogValidator = async (data) => { - if (data.license != null || data.extent != null) { + if (Array.isArray(data.collections) && Array.isArray(data.links)) { + // TODO: Validate the Collections API (/collections) + // Skip Collections API validation for now + return null; + } + + if (data.license || data.extent) { // contains Collection properties return collectionValidator(data); } diff --git a/src/migrate.js b/src/migrate.js index efb669ee3..6da1909b2 100644 --- a/src/migrate.js +++ b/src/migrate.js @@ -1,6 +1,6 @@ /* Methods that transform STAC object JSON from older versions to allow for a more consistent usage in other parts of the codebase */ -import { STAC_VERISON } from './config'; +import { STAC_VERSION } from './config'; export const transformCatalog = (entity) => { if(!entity) { return entity; } From 8e7059858fa7076ffca61184886364d0f6d5e9ac Mon Sep 17 00:00:00 2001 From: Matthias Mohr Date: Fri, 13 Nov 2020 14:31:54 +0100 Subject: [PATCH 2/4] clean-up --- src/components/Catalog.vue | 4 +++- src/main.js | 6 ------ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/components/Catalog.vue b/src/components/Catalog.vue index 0ee51d0c8..6ed5850ed 100644 --- a/src/components/Catalog.vue +++ b/src/components/Catalog.vue @@ -444,10 +444,12 @@ export default { return this.children.length; }, children() { - return this.links.filter(x => x.rel === "child") + return this.links + .filter(x => x.rel === "child") .map(child => { // strip /collection from the target path let p = this.path.replace(/^\/collection/, ""); + if (!p.endsWith("/")) { p += "/"; } diff --git a/src/main.js b/src/main.js index 8d8bca549..9c9d52b70 100644 --- a/src/main.js +++ b/src/main.js @@ -99,12 +99,6 @@ const main = async () => { }; const catalogValidator = async (data) => { - if (Array.isArray(data.collections) && Array.isArray(data.links)) { - // TODO: Validate the Collections API (/collections) - // Skip Collections API validation for now - return null; - } - if (data.license || data.extent) { // contains Collection properties return collectionValidator(data); From 0b7c24bea6fccf52a99f4cd82c9cab54120428b1 Mon Sep 17 00:00:00 2001 From: Matthias Mohr Date: Fri, 13 Nov 2020 15:02:12 +0100 Subject: [PATCH 3/4] Fix providers header showing up always #58 --- src/components/MetadataSidebar.vue | 2 +- src/components/common.js | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/components/MetadataSidebar.vue b/src/components/MetadataSidebar.vue index 966f897ad..dd55feb87 100644 --- a/src/components/MetadataSidebar.vue +++ b/src/components/MetadataSidebar.vue @@ -47,7 +47,7 @@ -