aboutsummaryrefslogtreecommitdiffstats
path: root/apps/settings/src/store/apps.js
diff options
context:
space:
mode:
Diffstat (limited to 'apps/settings/src/store/apps.js')
-rw-r--r--apps/settings/src/store/apps.js103
1 files changed, 64 insertions, 39 deletions
diff --git a/apps/settings/src/store/apps.js b/apps/settings/src/store/apps.js
index e6ddd76aaec..e0068d3892e 100644
--- a/apps/settings/src/store/apps.js
+++ b/apps/settings/src/store/apps.js
@@ -1,45 +1,29 @@
/**
- * @copyright Copyright (c) 2018 Julius Härtl <jus@bitgrid.net>
- *
- * @author John Molakvoæ <skjnldsv@protonmail.com>
- * @author Julius Härtl <jus@bitgrid.net>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @license AGPL-3.0-or-later
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
-import api from './api'
+import api from './api.js'
import Vue from 'vue'
+import axios from '@nextcloud/axios'
import { generateUrl } from '@nextcloud/router'
import { showError, showInfo } from '@nextcloud/dialogs'
-import '@nextcloud/dialogs/styles/toast.scss'
+import { loadState } from '@nextcloud/initial-state'
const state = {
apps: [],
+ bundles: loadState('settings', 'appstoreBundles', []),
categories: [],
- updateCount: 0,
+ updateCount: loadState('settings', 'appstoreUpdateCount', 0),
loading: {},
- loadingList: false,
+ gettingCategoriesPromise: null,
+ appApiEnabled: loadState('settings', 'appApiEnabled', false),
}
const mutations = {
APPS_API_FAILURE(state, error) {
- showError(t('settings', 'An error occured during the request. Unable to proceed.') + '<br>' + error.error.response.data.data.message, { isHTML: true })
+ showError(t('settings', 'An error occurred during the request. Unable to proceed.') + '<br>' + error.error.response.data.data.message, { isHTML: true })
console.error(state, error)
},
@@ -48,6 +32,10 @@ const mutations = {
state.updateCount = updateCount
},
+ updateCategories(state, categoriesPromise) {
+ state.gettingCategoriesPromise = categoriesPromise
+ },
+
setUpdateCount(state, updateCount) {
state.updateCount = updateCount
},
@@ -84,6 +72,16 @@ const mutations = {
const app = state.apps.find(app => app.id === appId)
app.active = true
app.groups = groups
+ if (app.id === 'app_api') {
+ state.appApiEnabled = true
+ }
+ },
+
+ setInstallState(state, { appId, canInstall }) {
+ const app = state.apps.find(app => app.id === appId)
+ if (app) {
+ app.canInstall = canInstall === true
+ }
},
disableApp(state, appId) {
@@ -93,6 +91,9 @@ const mutations = {
if (app.removable) {
app.canUnInstall = true
}
+ if (app.id === 'app_api') {
+ state.appApiEnabled = false
+ }
},
uninstallApp(state, appId) {
@@ -102,6 +103,9 @@ const mutations = {
state.apps.find(app => app.id === appId).installed = false
state.apps.find(app => app.id === appId).canUnInstall = false
state.apps.find(app => app.id === appId).canInstall = true
+ if (appId === 'app_api') {
+ state.appApiEnabled = false
+ }
},
updateApp(state, appId) {
@@ -142,6 +146,9 @@ const mutations = {
}
const getters = {
+ isAppApiEnabled(state) {
+ return state.appApiEnabled
+ },
loading(state) {
return function(id) {
return state.loading[id]
@@ -153,9 +160,15 @@ const getters = {
getAllApps(state) {
return state.apps
},
+ getAppBundles(state) {
+ return state.bundles
+ },
getUpdateCount(state) {
return state.updateCount
},
+ getCategoryById: (state) => (selectedCategoryId) => {
+ return state.categories.find((category) => category.id === selectedCategoryId)
+ },
}
const actions = {
@@ -179,19 +192,19 @@ const actions = {
})
// check for server health
- return api.get(generateUrl('apps/files'))
+ return axios.get(generateUrl('apps/files/'))
.then(() => {
if (response.data.update_required) {
showInfo(
t(
'settings',
- 'The app has been enabled but needs to be updated. You will be redirected to the update page in 5 seconds.'
+ 'The app has been enabled but needs to be updated. You will be redirected to the update page in 5 seconds.',
),
{
onClick: () => window.location.reload(),
close: false,
- }
+ },
)
setTimeout(function() {
location.reload()
@@ -200,10 +213,12 @@ const actions = {
})
.catch(() => {
if (!Array.isArray(appId)) {
+ showError(t('settings', 'Error: This app cannot be enabled because it makes the server unstable'))
context.commit('setError', {
appId: apps,
error: t('settings', 'Error: This app cannot be enabled because it makes the server unstable'),
})
+ context.dispatch('disableApp', { appId })
}
})
})
@@ -230,8 +245,7 @@ const actions = {
context.commit('startLoading', 'install')
return api.post(generateUrl('settings/apps/force'), { appId })
.then((response) => {
- // TODO: find a cleaner solution
- location.reload()
+ context.commit('setInstallState', { appId, canInstall: true })
})
.catch((error) => {
context.commit('stopLoading', apps)
@@ -242,6 +256,10 @@ const actions = {
})
context.commit('APPS_API_FAILURE', { appId, error })
})
+ .finally(() => {
+ context.commit('stopLoading', apps)
+ context.commit('stopLoading', 'install')
+ })
}).catch((error) => context.commit('API_FAILURE', { appId, error }))
},
disableApp(context, { appId }) {
@@ -313,18 +331,25 @@ const actions = {
.catch((error) => context.commit('API_FAILURE', error))
},
- getCategories(context) {
- context.commit('startLoading', 'categories')
- return api.get(generateUrl('settings/apps/categories'))
- .then((response) => {
- if (response.data.length > 0) {
- context.commit('appendCategories', response.data)
+ async getCategories(context, { shouldRefetchCategories = false } = {}) {
+ if (shouldRefetchCategories || !context.state.gettingCategoriesPromise) {
+ context.commit('startLoading', 'categories')
+ try {
+ const categoriesPromise = api.get(generateUrl('settings/apps/categories'))
+ context.commit('updateCategories', categoriesPromise)
+ const categoriesPromiseResponse = await categoriesPromise
+ if (categoriesPromiseResponse.data.length > 0) {
+ context.commit('appendCategories', categoriesPromiseResponse.data)
context.commit('stopLoading', 'categories')
return true
}
+ context.commit('stopLoading', 'categories')
return false
- })
- .catch((error) => context.commit('API_FAILURE', error))
+ } catch (error) {
+ context.commit('API_FAILURE', error)
+ }
+ }
+ return context.state.gettingCategoriesPromise
},
}