Skip to content

Commit

Permalink
Remove quick view when logging out/disconnecting #277
Browse files Browse the repository at this point in the history
  • Loading branch information
m-mohr committed Oct 10, 2022
1 parent 65a9496 commit 88ab5f1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/components/ServicePanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import EventBusMixin from './EventBusMixin.vue';
import WorkPanelMixin from './WorkPanelMixin';
import Utils from '../utils';
import { Service } from '@openeo/js-client';
import { mapMutations } from 'vuex';
export default {
name: 'ServicePanel',
Expand Down Expand Up @@ -57,7 +58,8 @@ export default {
filterable: false,
sort: false
}
}
},
createdQuickViews: {}
};
},
computed: {
Expand Down Expand Up @@ -91,8 +93,22 @@ export default {
},
mounted() {
this.listen('replaceProcess', this.replaceProcess);
this.beforeLogoutListener({key: this.$options.name, listener: this.onExit});
},
beforeDestroy() {
this.beforeLogoutListener({key: this.$options.name});
},
methods: {
...mapMutations(['beforeLogoutListener']),
async onExit() {
let promises = [];
for(let id in this.createdQuickViews) {
let service = this.createdQuickViews[id];
promises.push(this.deleteService(service, true));
}
await Promise.all(promises);
this.createdQuickViews = {};
},
isMapServiceSupported(type) {
return Utils.isMapServiceSupported(type);
},
Expand Down Expand Up @@ -237,6 +253,7 @@ export default {
};
let service = await this.createService(this.process, settings, true);
if (service) {
this.createdQuickViews[service.id] = service;
this.viewService(service, () => this.deleteService(service, true));
}
} catch(error) {
Expand Down Expand Up @@ -287,6 +304,7 @@ export default {
try {
await this.delete({data: service});
this.emit('removeWebService', service.id);
delete this.createdQuickViews[service.id];
} catch(error) {
if (quiet) {
console.error(error);
Expand Down
15 changes: 15 additions & 0 deletions src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const getDefaultState = () => {
isAuthenticated: false,
userInfo: {},
connectionError: null,
beforeLogoutListener: {},
authProviders: [],
fileFormats: {},
serviceTypes: {},
Expand Down Expand Up @@ -293,7 +294,13 @@ export default new Vuex.Store({
return cx.getters.processes.get(id, namespace);
},

async beforeLogout(cx) {
await Promise.all(Object.values(cx.state.beforeLogoutListener).map(listener => listener()));
},

async logout(cx, disconnect = false) {
await cx.dispatch('beforeLogout');

if (disconnect) {
// Remove listeners, we don't need them anymore if we connect anyway
cx.state.connection.off('authProviderChanged');
Expand Down Expand Up @@ -404,6 +411,14 @@ export default new Vuex.Store({
},
endActiveRequest(state) {
state.activeRequests -= 1;
},
beforeLogoutListener(state, {key, listener}) {
if (typeof listener === 'function') {
state.beforeLogoutListener[key] = listener;
}
else {
Vue.delete(state.beforeLogoutListener, key);
}
}
}
});

0 comments on commit 88ab5f1

Please sign in to comment.