Skip to content

Commit

Permalink
Implement app mode for services
Browse files Browse the repository at this point in the history
  • Loading branch information
m-mohr committed Jul 31, 2024
1 parent d9fe7f3 commit 731c336
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 18 deletions.
1 change: 1 addition & 0 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export default {

// List of supported web service sharing services
supportedWebServiceSharingServices: [
'ShareEditor',
'CopyUrl',
'TwitterShare'
],
Expand Down
4 changes: 3 additions & 1 deletion src/Page.vue
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,12 @@ export default {
});
this.setCollectionPreview(Utils.param('preview-collection'));
let resultUrl = Utils.param('result');
const resultUrl = Utils.param('result');
const resultType = Utils.param('result-type') || 'job';
if (resultUrl) {
this.setAppMode({
resultUrl,
resultType,
...Utils.paramsForPrefix('app')
});
}
Expand Down
25 changes: 20 additions & 5 deletions src/components/Viewer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,7 @@ export default {
this.listen('addToMapChooser', this.addToMapChooser);
if (this.appMode) {
this.showJobResults(this.appMode.data, null, this.appMode.title);
if (typeof this.appMode.expires === 'string') {
const expires = Formatters.formatTimestamp(this.appMode.expires);
Utils.info(this, `The shared data is available until ${expires}`);
}
this.showAppMode();
}
},
data() {
Expand All @@ -78,6 +74,25 @@ export default {
methods: {
...Utils.mapActions(['describeCollection']),
...Utils.mapMutations('editor', ['setViewerOptions', 'setModelDnD']),
showAppMode() {
if (this.appMode.resultType === 'service') {
console.log(this.appMode);
const service = new Service(this.connection, 'app');
service.title = this.appMode.title;
service.url = this.appMode.resultUrl;
service.type = this.appMode.service;
service.enabled = true;
console.log(service);
this.showWebService(service);
}
else {
this.showJobResults(this.appMode.data, null, this.appMode.title);
if (typeof this.appMode.expires === 'string') {
const expires = Formatters.formatTimestamp(this.appMode.expires);
Utils.info(this, `The shared data is available until ${expires}`);
}
}
},
isCollectionPreview(data) {
return (data instanceof Service && Utils.isObject(data.attributes) && data.attributes.preview === true);
},
Expand Down
12 changes: 9 additions & 3 deletions src/components/share/CopyUrl.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<ShareInterface v-if="canCopy"
id="share-copy" icon="fa-file-code" title="STAC metadata" :description="description" :action="copy"
actionDefaultIcon="fa-clipboard" actionSuccessIcon="fa-clipboard-check" @stateChanged="state => this.state = state">
id="share-copy" icon="fa-file-code" :title="name" :description="description" :action="copy"
actionDefaultIcon="fa-clipboard" actionSuccessIcon="fa-clipboard-check" @stateChanged="updateState">
</ShareInterface>
</template>

Expand All @@ -24,6 +24,9 @@ export default {
};
},
computed: {
name() {
return this.type === 'service' ? 'Web Service' : 'STAC metadata';
},
description() {
if (this.state === 'error') {
return 'Copying to clipboard failed';
Expand All @@ -32,11 +35,14 @@ export default {
return 'Copied to clipboard';
}
else {
return 'Copy the public URL of the STAC metadata to your clipboard';
return `Copy the public URL of the ${this.name} to your clipboard`;
}
}
},
methods: {
updateState(state) {
this.state = state;
},
copy() {
return this.$clipboard(this.url);
}
Expand Down
4 changes: 4 additions & 0 deletions src/components/share/ShareEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ export default {
editorUrl() {
const url = new URL(window.location.href);
const query = new URLSearchParams(url.search);
query.set('result-type', this.type);
query.set('result', this.url); // Pass canonical link, implies discover = 1
if (this.type === 'service') {
query.set('app~service', this.context.type);
}
url.search = query;
return url.toString();
}
Expand Down
2 changes: 1 addition & 1 deletion src/events.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Sends the current custom process and inserts it into the currently active editor
Shows a list in a modal.

### showWebEditorInfo()
Showa information about the web editor in a modal.
Shows information about the web editor in a modal.

### showCollection(id)
Shows collection information in a modal.
Expand Down
16 changes: 9 additions & 7 deletions src/store/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,16 @@ export default {
return;
}

try {
let response = await axios(cx.state.appMode.resultUrl);
if (Utils.isObject(response.data)) {
cx.commit('setAppModeData', response.data);
if (cx.state.appMode.resultType !== 'service') {
try {
let response = await axios(cx.state.appMode.resultUrl);
if (Utils.isObject(response.data)) {
cx.commit('setAppModeData', response.data);
}
} catch (error) {
console.error(error);
throw new Error("Sorry, the shared data is not available anymore!");
}
} catch (error) {
console.error(error);
throw new Error("Sorry, the shared data is not available anymore!");
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ export default new Vuex.Store({
}
}

// Request batch job result for app mode
// Request results for app mode
if (!refresh) {
try {
await cx.dispatch('editor/loadForAppMode');
Expand Down

0 comments on commit 731c336

Please sign in to comment.