From 111bd4f7f5d5abd9809e7446f5d5dc9229c49fcf Mon Sep 17 00:00:00 2001 From: Jonathan Cobb Date: Thu, 9 Jul 2020 22:45:48 -0400 Subject: [PATCH] WIP. adding upgrade jar features --- src/_services/system.service.js | 10 ++++++- src/_store/system.module.js | 22 ++++++++++++-- src/account/NetworkPage.vue | 4 +-- src/account/profile/ProfilePage.vue | 45 +++++++++++++++++++++++++++-- 4 files changed, 74 insertions(+), 7 deletions(-) diff --git a/src/_services/system.service.js b/src/_services/system.service.js index c36039f..62f6df2 100644 --- a/src/_services/system.service.js +++ b/src/_services/system.service.js @@ -17,7 +17,8 @@ export const systemService = { loadTimezones, detectTimezone, detectLocale, - getAppLinks + getAppLinks, + upgradeJar }; function loadIsActivated () { @@ -116,3 +117,10 @@ function getAppLinks (locale) { .then(util.handleBasicResponse) .then(links => { return links; }); } + +function upgradeJar() { + const requestOptions =util.postWithAuth(); + return fetch(`${config.apiUrl}/me/upgrade`, requestOptions) + .then(util.handleBasicResponse) + .then(configs => { return configs; }); +} diff --git a/src/_store/system.module.js b/src/_store/system.module.js index b8e12f9..874607b 100644 --- a/src/_store/system.module.js +++ b/src/_store/system.module.js @@ -23,11 +23,13 @@ const state = { requireSendMetrics: null, awaitingRestore: false, support: {}, - securityLevels: null + securityLevels: null, + jarVersion: null, + jarUpgradeAvailable: null }, entityConfigs: {}, searchResults: [], - status: { activating: false, searching: false, creatingEntity: false, modelSetupInProgress: false }, + status: { activating: false, searching: false, creatingEntity: false, modelSetupInProgress: false, upgrading: false }, activated: null, error: null, messages: { @@ -155,6 +157,13 @@ const actions = { links => commit('getAppLinksSuccess', links), error => commit('getAppLinksFailure', error) ) + }, + upgradeJar({ commit }) { + commit('upgradeJarRequest'); + systemService.upgradeJar(locale).then( + configs => commit('upgradeJarSuccess', configs), + error => commit('upgradeJarFailure', error) + ) } }; @@ -411,6 +420,15 @@ const mutations = { }, getAppLinksFailure(state, error) { state.error = error; + }, + + upgradeJarRequest(state) {}, + upgradeJarSuccess(state, configs) { + state.configs = configs; + state.status = Object.assign(state.status, {upgrading: true}); + }, + upgradeJarFailure(state, error) { + state.error = error; } }; diff --git a/src/account/NetworkPage.vue b/src/account/NetworkPage.vue index 3a03e2b..e0b2e66 100644 --- a/src/account/NetworkPage.vue +++ b/src/account/NetworkPage.vue @@ -13,7 +13,7 @@ -
+
@@ -349,7 +349,7 @@ if (net.uuid === 'Not Found') this.$router.replace({path: '/bubbles'}); this.networkUuid = net.uuid; - if (net.state !== 'starting' && net.state !== 'restoring') { + if (net.state !== 'created' && net.state !== 'starting' && net.state !== 'restoring') { this.clearRefresherInterval(this.refresher); } if (net.state !== 'stopping') this.clearRefresherInterval(this.stopRefresher); diff --git a/src/account/profile/ProfilePage.vue b/src/account/profile/ProfilePage.vue index 617f2d2..7796b35 100644 --- a/src/account/profile/ProfilePage.vue +++ b/src/account/profile/ProfilePage.vue @@ -20,6 +20,17 @@
+
+
+

{{messages.message_jar_upgrade_available}}

+

{{messages.message_jar_upgrade_version}} {{configs.jarUpgradeAvailable.version}}

+

{{messages.message_jar_current_version}} {{configs.jarVersion}}

+ + +

{{messages.message_jar_upgrading}}

+
+
+
{{ errors.first('user') }}
@@ -131,15 +142,18 @@ newUser: null, submitted: false, subject: Object.assign({}, BLANK_SUBJECT), - loadingImgSrc: loadingImgSrc + loadingImgSrc: loadingImgSrc, + upgrading: false, + upgradeRefresher: null }; }, computed: { ...mapState('users', ['user']), - ...mapState('system', ['messages', 'configs']) + ...mapState('system', ['messages', 'configs', 'status']) }, created () { this.me = this.$route.path === '/me' || this.$route.path.startsWith('/me/'); + this.loadSystemConfigs(); if (this.me) { this.linkPrefix = '/me'; if (this.currentUser === null) { @@ -186,6 +200,7 @@ next(); }, methods: { + ...mapActions('system', ['loadSystemConfigs', 'upgradeJar']), ...mapActions('users', ['createUser', 'updateUser', 'updateSelf', 'getUserById']), ...mapGetters('users', ['loading']), handleSubmit (e) { @@ -214,6 +229,10 @@ console.log('invalid!'); } }); + }, + doUpgradeJar () { + this.upgrading = true; + this.upgradeJar(); } }, watch: { @@ -233,6 +252,28 @@ this.subject = u; } } + }, + configs (c) { + if (c) { + console.log('watch.configs received: '+JSON.stringify(c)); + if (this.upgradeRefresher !== null) { + // does the new server version match our version? + if (c.jarVersion && c.jarUpgradeAvailable && c.jarUpgradeAvailable.version && c.jarVersion === c.jarUpgradeAvailable.version) { + window.clearInterval(this.upgradeRefresher); + } + } + } + }, + status (s) { + if (s) { + console.log('watch.status received: '+JSON.stringify(s)); + if (s.upgrading && this.upgradeRefresher === null) { + const vue = this; + this.upgradeRefresher = window.setInterval(() => { + vue.loadSystemConfigs(); + }, 5000); + } + } } } };