summaryrefslogtreecommitdiffstats
path: root/settings
diff options
context:
space:
mode:
authorJulius Härtl <jus@bitgrid.net>2018-06-02 09:51:14 +0200
committerJulius Härtl <jus@bitgrid.net>2018-06-06 11:40:09 +0200
commita5509aa2539e37deb067b2d870666f5869a53bab (patch)
tree40ba22a90ed88117043c374b82a019fa89c32495 /settings
parent64c2e946f4d17e877105116ddc6e02f9c2aa042b (diff)
downloadnextcloud-server-a5509aa2539e37deb067b2d870666f5869a53bab.tar.gz
nextcloud-server-a5509aa2539e37deb067b2d870666f5869a53bab.zip
Move filtering to javascript
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Diffstat (limited to 'settings')
-rw-r--r--settings/Controller/AppSettingsController.php109
-rw-r--r--settings/src/components/appList.vue34
-rw-r--r--settings/src/store/apps.js35
-rw-r--r--settings/src/views/Apps.vue6
4 files changed, 81 insertions, 103 deletions
diff --git a/settings/Controller/AppSettingsController.php b/settings/Controller/AppSettingsController.php
index 9f4acc27d1f..fbcc21b1970 100644
--- a/settings/Controller/AppSettingsController.php
+++ b/settings/Controller/AppSettingsController.php
@@ -81,6 +81,9 @@ class AppSettingsController extends Controller {
/** @var ILogger */
private $logger;
+ /** @var array */
+ private $allApps = [];
+
/**
* @param string $appName
* @param IRequest $request
@@ -197,6 +200,41 @@ class AppSettingsController extends Controller {
return $formattedCategories;
}
+ private function fetchApps() {
+ $appClass = new \OC_App();
+ $apps = $appClass->listAllApps();
+ foreach ($apps as $app) {
+ $app['installed'] = true;
+ $this->allApps[$app['id']] = $app;
+ }
+
+ $apps = $this->getAppsForCategory('');
+ foreach ($apps as $app) {
+ $app['appstore'] = true;
+ if (!array_key_exists($app['id'], $this->allApps)) {
+ $this->allApps[$app['id']] = $app;
+ } else {
+ $this->allApps[$app['id']] = array_merge($this->allApps[$app['id']], $app);
+ }
+ }
+
+ // add bundle information
+ $bundles = $this->bundleFetcher->getBundles();
+ foreach($bundles as $bundle) {
+ foreach($bundle->getAppIdentifiers() as $identifier) {
+ foreach($this->allApps as &$app) {
+ if($app['id'] === $identifier) {
+ $app['bundleId'] = $bundle->getIdentifier();
+ continue;
+ }
+ }
+ }
+ }
+ }
+
+ private function getAllApps() {
+ return $this->allApps;
+ }
/**
* Get all available apps in a category
*
@@ -204,75 +242,16 @@ class AppSettingsController extends Controller {
* @return JSONResponse
* @throws \Exception
*/
- public function listApps($category = ''): JSONResponse {
- $appClass = new \OC_App();
+ public function listApps(): JSONResponse {
- switch ($category) {
- case 'installed':
- $apps = $appClass->listAllApps();
- break;
- case 'updates':
- $apps = $this->getAppsWithUpdates();
- break;
- case 'enabled':
- $apps = $appClass->listAllApps();
- $apps = array_filter($apps, function ($app) {
- return $app['active'];
- });
- break;
- case 'disabled':
- $apps = $appClass->listAllApps();
- $apps = array_filter($apps, function ($app) {
- return !$app['active'];
- });
- break;
- case 'app-bundles':
- $bundles = $this->bundleFetcher->getBundles();
- $apps = [];
- $installedApps = $appClass->listAllApps();
- $appstoreApps = $this->getAppsForCategory();
- foreach($bundles as $bundle) {
- foreach($bundle->getAppIdentifiers() as $identifier) {
- $alreadyMatched = false;
- foreach($installedApps as $app) {
- if($app['id'] === $identifier) {
- $app['bundleId'] = $bundle->getIdentifier();
- $apps[] = $app;
- $alreadyMatched = true;
- continue;
- }
- }
- if (!$alreadyMatched) {
- foreach ($appstoreApps as $app) {
- if ($app['id'] === $identifier) {
- $app['bundleId'] = $bundle->getIdentifier();
- $apps[] = $app;
- continue;
- }
- }
- }
- }
- }
- break;
- default:
- $apps = $this->getAppsForCategory($category);
- break;
- }
-
-
- // Fetch all apps from appstore
- $allAppStoreApps = [];
- $fetchedApps = $this->appFetcher->get();
- foreach ($fetchedApps as $app) {
- $allAppStoreApps[$app['id']] = $app;
- }
+ $this->fetchApps();
+ $apps = $this->getAllApps();
$dependencyAnalyzer = new DependencyAnalyzer(new Platform($this->config), $this->l10n);
// Extend existing app details
- $apps = array_map(function($appData) use ($allAppStoreApps, $dependencyAnalyzer) {
- $appstoreData = $allAppStoreApps[$appData['id']];
- $appData['appstoreData'] = $appstoreData;
+ $apps = array_map(function($appData) use ($dependencyAnalyzer) {
+ $appstoreData = $appData['appstoreData'];
$appData['screenshot'] = isset($appstoreData['screenshots'][0]['url']) ? 'https://usercontent.apps.nextcloud.com/'.base64_encode($appstoreData['screenshots'][0]['url']) : '';
$newVersion = $this->installer->isUpdateAvailable($appData['id']);
@@ -310,7 +289,7 @@ class AppSettingsController extends Controller {
}
/**
- * Get all apps for a category
+ * Get all apps for a category from the app store
*
* @param string $requestedCategory
* @return array
diff --git a/settings/src/components/appList.vue b/settings/src/components/appList.vue
index ab8d30b1227..734bc9d55fa 100644
--- a/settings/src/components/appList.vue
+++ b/settings/src/components/appList.vue
@@ -80,15 +80,45 @@ export default {
return this.$store.getters.loading('list');
},
apps() {
- return this.$store.getters.getApps
+ let apps = this.$store.getters.getAllApps
.filter(app => app.name.toLowerCase().search(this.search.toLowerCase()) !== -1)
+ .sort(function (a, b) {
+ if (a.active !== b.active) {
+ return (a.active ? -1 : 1)
+ }
+ if (a.update !== b.update) {
+ return (a.update ? -1 : 1)
+ }
+ return OC.Util.naturalSortCompare(a.name, b.name);
+ });
+
+ if (this.category === 'installed') {
+ return apps.filter(app => app.installed);
+ }
+ if (this.category === 'enabled') {
+ return apps.filter(app => app.active);
+ }
+ if (this.category === 'disabled') {
+ return apps.filter(app => !app.active);
+ }
+ if (this.category === 'app-bundles') {
+ return apps.filter(app => app.bundles);
+ }
+ if (this.category === 'updates') {
+ return apps.filter(app => app.update);
+ }
+ // filter app store categories
+ return apps.filter(app => {
+ return app.appstore && app.category !== undefined &&
+ (app.category === this.category || app.category.indexOf(this.category) > -1);
+ });
},
bundles() {
return this.$store.getters.getServerData.bundles;
},
bundleApps() {
return function(bundle) {
- return this.$store.getters.getApps
+ return this.$store.getters.getAllApps
.filter(app => app.bundleId === bundle);
}
},
diff --git a/settings/src/store/apps.js b/settings/src/store/apps.js
index 97d7aaa6cb0..2247e68996c 100644
--- a/settings/src/store/apps.js
+++ b/settings/src/store/apps.js
@@ -26,7 +26,6 @@ import Vue from 'vue';
const state = {
apps: [],
- allApps: [],
categories: [],
updateCount: 0,
loading: {},
@@ -58,12 +57,8 @@ const mutations = {
state.categories = categoriesArray;
},
- setApps(state, apps) {
- state.apps = apps;
- },
-
setAllApps(state, apps) {
- state.allApps = apps;
+ state.apps = apps;
},
setError(state, {appId, error}) {
@@ -145,19 +140,8 @@ const getters = {
getCategories(state) {
return state.categories;
},
- getApps(state) {
- return state.apps.concat([]).sort(function (a, b) {
- if (a.active !== b.active) {
- return (a.active ? -1 : 1)
- }
- if (a.update !== b.update) {
- return (a.update ? -1 : 1)
- }
- return OC.Util.naturalSortCompare(a.name, b.name);
- });
- },
getAllApps(state) {
- return state.allApps;
+ return state.apps;
},
getUpdateCount(state) {
return state.updateCount;
@@ -279,23 +263,12 @@ const actions = {
}).catch((error) => context.commit('API_FAILURE', { appId, error }));
},
- getApps(context, { category }) {
- context.commit('startLoading', 'list');
- return api.get(OC.generateUrl(`settings/apps/list?category=${category}`))
- .then((response) => {
- context.commit('setApps', response.data.apps);
- context.commit('stopLoading', 'list');
- return true;
- })
- .catch((error) => context.commit('API_FAILURE', error))
- },
-
getAllApps(context) {
- context.commit('startLoading', 'all');
+ context.commit('startLoading', 'list');
return api.get(OC.generateUrl(`settings/apps/list`))
.then((response) => {
context.commit('setAllApps', response.data.apps);
- context.commit('stopLoading', 'all');
+ context.commit('stopLoading', 'list');
return true;
})
.catch((error) => context.commit('API_FAILURE', error))
diff --git a/settings/src/views/Apps.vue b/settings/src/views/Apps.vue
index 994677700e1..1bd76b8718e 100644
--- a/settings/src/views/Apps.vue
+++ b/settings/src/views/Apps.vue
@@ -69,7 +69,6 @@ export default {
},
beforeMount() {
this.$store.dispatch('getCategories');
- this.$store.dispatch('getApps', {category: this.category});
this.$store.dispatch('getAllApps');
this.$store.dispatch('getGroups');
this.$store.commit('setUpdateCount', this.$store.getters.getServerData.updateCount)
@@ -89,11 +88,8 @@ export default {
}
},
watch: {
- // watch url change and group select
category: function (val, old) {
- this.$store.commit('resetApps');
this.setSearch('');
- this.$store.dispatch('getApps', { category: this.category });
}
},
computed: {
@@ -110,7 +106,7 @@ export default {
return this.$store.getters.getCategories;
},
apps() {
- return this.$store.getters.getApps;
+ return this.$store.getters.getAllApps;
},
updateCount() {
return this.$store.getters.getUpdateCount;