| 307 | }, |
| 308 | |
| 309 | GetInfo ({ commit }, switchDomain) { |
| 310 | return new Promise((resolve, reject) => { |
| 311 | const cachedApis = switchDomain ? {} : vueProps.$localStorage.get(APIS, {}) |
| 312 | const cachedZones = vueProps.$localStorage.get(ZONES, []) |
| 313 | const cachedTimezoneOffset = vueProps.$localStorage.get(TIMEZONE_OFFSET, 0.0) |
| 314 | const cachedUseBrowserTimezone = vueProps.$localStorage.get(USE_BROWSER_TIMEZONE, false) |
| 315 | const cachedCustomColumns = vueProps.$localStorage.get(CUSTOM_COLUMNS, {}) |
| 316 | const domainStore = vueProps.$localStorage.get(DOMAIN_STORE, {}) |
| 317 | const cachedShowSecurityGroups = vueProps.$localStorage.get(SHOW_SECURTIY_GROUPS, false) |
| 318 | const darkMode = vueProps.$localStorage.get(DARK_MODE, false) |
| 319 | const msId = vueProps.$localStorage.get(MS_ID, false) |
| 320 | const latestVersion = vueProps.$localStorage.get(LATEST_CS_VERSION, { version: '', fetchedTs: 0 }) |
| 321 | const hasAuth = Object.keys(cachedApis).length > 0 |
| 322 | |
| 323 | commit('SET_DOMAIN_STORE', domainStore) |
| 324 | commit('SET_DARK_MODE', darkMode) |
| 325 | commit('SET_LATEST_VERSION', latestVersion) |
| 326 | if (hasAuth) { |
| 327 | console.log('Login detected, using cached APIs') |
| 328 | commit('SET_ZONES', cachedZones) |
| 329 | commit('SET_SHOW_SECURITY_GROUPS', cachedShowSecurityGroups) |
| 330 | commit('SET_APIS', cachedApis) |
| 331 | commit('SET_TIMEZONE_OFFSET', cachedTimezoneOffset) |
| 332 | commit('SET_USE_BROWSER_TIMEZONE', cachedUseBrowserTimezone) |
| 333 | commit('SET_CUSTOM_COLUMNS', cachedCustomColumns) |
| 334 | commit('SET_MS_ID', msId) |
| 335 | |
| 336 | // Ensuring we get the user info so that store.getters.user is never empty when the page is freshly loaded |
| 337 | getAPI('listUsers', { id: Cookies.get('userid'), listall: true }).then(response => { |
| 338 | const result = response.listusersresponse.user[0] |
| 339 | commit('SET_INFO', result) |
| 340 | commit('SET_NAME', result.firstname + ' ' + result.lastname) |
| 341 | resolve(cachedApis) |
| 342 | }).catch(error => { |
| 343 | reject(error) |
| 344 | }) |
| 345 | } else if (store.getters.loginFlag) { |
| 346 | const hide = message.loading(i18n.global.t('message.discovering.feature'), 0) |
| 347 | getAPI('listZones').then(json => { |
| 348 | const zones = json.listzonesresponse.zone || [] |
| 349 | commit('SET_ZONES', zones) |
| 350 | }).catch(error => { |
| 351 | reject(error) |
| 352 | }) |
| 353 | getAPI('listApis').then(response => { |
| 354 | const apis = {} |
| 355 | const apiList = response.listapisresponse.api |
| 356 | for (var idx = 0; idx < apiList.length; idx++) { |
| 357 | const api = apiList[idx] |
| 358 | const apiName = api.name |
| 359 | apis[apiName] = { |
| 360 | params: api.params, |
| 361 | response: api.response, |
| 362 | isasync: api.isasync, |
| 363 | since: api.since, |
| 364 | description: api.description |
| 365 | } |
| 366 | } |