diff options
author | Lukas Reschke <lukas@owncloud.com> | 2014-10-28 11:13:20 +0100 |
---|---|---|
committer | Lukas Reschke <lukas@owncloud.com> | 2014-10-28 11:13:20 +0100 |
commit | 437a660680ee563d75ce2a3fc916244ff5512e2a (patch) | |
tree | 08bc1737df3e26cb10c9016655d8ca6831a54134 | |
parent | 4461e69873aac223fea410d8e78c3e7674541c17 (diff) | |
parent | e4227658d9d80725620ab33b68de5c26c8ed67ad (diff) | |
download | nextcloud-server-437a660680ee563d75ce2a3fc916244ff5512e2a.tar.gz nextcloud-server-437a660680ee563d75ce2a3fc916244ff5512e2a.zip |
Merge pull request #11600 from owncloud/refactor-appsettings-to-app-framework
Migrate new app settings to AppFramework
-rw-r--r-- | settings/ajax/apps/categories.php | 30 | ||||
-rw-r--r-- | settings/ajax/apps/index.php | 65 | ||||
-rw-r--r-- | settings/application.php | 10 | ||||
-rw-r--r-- | settings/controller/appsettingscontroller.php | 132 | ||||
-rw-r--r-- | settings/routes.php | 6 |
5 files changed, 143 insertions, 100 deletions
diff --git a/settings/ajax/apps/categories.php b/settings/ajax/apps/categories.php deleted file mode 100644 index 3bde28be99b..00000000000 --- a/settings/ajax/apps/categories.php +++ /dev/null @@ -1,30 +0,0 @@ -<?php -/** - * Copyright (c) 2014 Thomas Müller <deepdiver@owncloud.com> - * This file is licensed under the Affero General Public License version 3 or - * later. - * See the COPYING-README file. - */ - -OC_JSON::checkAdminUser(); - -$l = OC_L10N::get('settings'); - -$categories = array( - array('id' => 0, 'displayName' => (string)$l->t('Enabled') ), - array('id' => 1, 'displayName' => (string)$l->t('Not enabled') ), -); - -if(OC_Config::getValue('appstoreenabled', true)) { - $categories[] = array('id' => 2, 'displayName' => (string)$l->t('Recommended') ); - // apps from external repo via OCS - $ocs = OC_OCSClient::getCategories(); - foreach($ocs as $k => $v) { - $categories[] = array( - 'id' => $k, - 'displayName' => str_replace('ownCloud ', '', $v) - ); - } -} - -OCP\JSON::success($categories); diff --git a/settings/ajax/apps/index.php b/settings/ajax/apps/index.php deleted file mode 100644 index 24fba8be312..00000000000 --- a/settings/ajax/apps/index.php +++ /dev/null @@ -1,65 +0,0 @@ -<?php -/** - * Copyright (c) 2014 Thomas Müller <deepdiver@owncloud.com> - * This file is licensed under the Affero General Public License version 3 or - * later. - * See the COPYING-README file. - */ - -OC_JSON::checkAdminUser(); - -$l = OC_L10N::get('settings'); - -$category = intval($_GET['category']); -$apps = array(); - -switch($category) { - // installed apps - case 0: - $apps = \OC_App::listAllApps(true); - $apps = array_filter($apps, function($app) { - return $app['active']; - }); - break; - // not-installed apps - case 1: - $apps = \OC_App::listAllApps(true); - $apps = array_filter($apps, function($app) { - return !$app['active']; - }); - break; - default: - if ($category === 2) { - $apps = \OC_App::getAppstoreApps('approved'); - $apps = array_filter($apps, function($app) { - return isset($app['internalclass']) && $app['internalclass'] === 'recommendedapp'; - }); - } else { - $apps = \OC_App::getAppstoreApps('approved', $category); - } - if (!$apps) { - $apps = array(); - } - usort($apps, function ($a, $b) { - $a = (int)$a['score']; - $b = (int)$b['score']; - if ($a === $b) { - return 0; - } - return ($a > $b) ? -1 : 1; - }); - break; -} - -// fix groups to be an array -$apps = array_map(function($app){ - $groups = array(); - if (is_string($app['groups'])) { - $groups = json_decode($app['groups']); - } - $app['groups'] = $groups; - $app['canUnInstall'] = !$app['active'] && $app['removable']; - return $app; -}, $apps); - -OCP\JSON::success(array("apps" => $apps)); diff --git a/settings/application.php b/settings/application.php index b17ca01c2f3..99d78aff2cc 100644 --- a/settings/application.php +++ b/settings/application.php @@ -11,6 +11,7 @@ namespace OC\Settings; use OC\AppFramework\Utility\SimpleContainer; +use OC\Settings\Controller\AppSettingsController; use OC\Settings\Controller\MailSettingsController; use \OCP\AppFramework\App; use \OCP\Util; @@ -44,7 +45,14 @@ class Application extends App { $c->query('DefaultMailAddress') ); }); - + $container->registerService('AppSettingsController', function(SimpleContainer $c) { + return new AppSettingsController( + $c->query('AppName'), + $c->query('Request'), + $c->query('L10N'), + $c->query('Config') + ); + }); /** * Core class wrappers */ diff --git a/settings/controller/appsettingscontroller.php b/settings/controller/appsettingscontroller.php new file mode 100644 index 00000000000..27205400aff --- /dev/null +++ b/settings/controller/appsettingscontroller.php @@ -0,0 +1,132 @@ +<?php +/** + * @author Lukas Reschke + * @author Thomas Müller + * @copyright 2014 Lukas Reschke lukas@owncloud.com, 2014 Thomas Müller deepdiver@owncloud.com + * + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace OC\Settings\Controller; + +use \OCP\AppFramework\Controller; +use OCP\IRequest; +use OCP\IL10N; +use OCP\IConfig; + +/** + * @package OC\Settings\Controller + */ +class AppSettingsController extends Controller { + + /** @var \OCP\IL10N */ + private $l10n; + /** @var IConfig */ + private $config; + + /** + * @param string $appName + * @param IRequest $request + * @param IL10N $l10n + * @param IConfig $config + */ + public function __construct($appName, + IRequest $request, + IL10N $l10n, + IConfig $config) { + parent::__construct($appName, $request); + $this->l10n = $l10n; + $this->config = $config; + } + + /** + * Get all available categories + * @return array + */ + public function listCategories() { + + $categories = array( + array('id' => 0, 'displayName' => (string)$this->l10n->t('Enabled') ), + array('id' => 1, 'displayName' => (string)$this->l10n->t('Not enabled') ), + ); + + if($this->config->getSystemValue('appstoreenabled', true)) { + $categories[] = array('id' => 2, 'displayName' => (string)$this->l10n->t('Recommended') ); + // apps from external repo via OCS + $ocs = \OC_OCSClient::getCategories(); + foreach($ocs as $k => $v) { + $categories[] = array( + 'id' => $k, + 'displayName' => str_replace('ownCloud ', '', $v) + ); + } + } + + $categories['status'] = 'success'; + + return $categories; + } + + /** + * Get all available categories + * @param int $category + * @return array + */ + public function listApps($category = 0) { + $apps = array(); + + switch($category) { + // installed apps + case 0: + $apps = \OC_App::listAllApps(true); + $apps = array_filter($apps, function($app) { + return $app['active']; + }); + break; + // not-installed apps + case 1: + $apps = \OC_App::listAllApps(true); + $apps = array_filter($apps, function($app) { + return !$app['active']; + }); + break; + default: + if ($category === 2) { + $apps = \OC_App::getAppstoreApps('approved'); + $apps = array_filter($apps, function($app) { + return isset($app['internalclass']) && $app['internalclass'] === 'recommendedapp'; + }); + } else { + $apps = \OC_App::getAppstoreApps('approved', $category); + } + if (!$apps) { + $apps = array(); + } + usort($apps, function ($a, $b) { + $a = (int)$a['score']; + $b = (int)$b['score']; + if ($a === $b) { + return 0; + } + return ($a > $b) ? -1 : 1; + }); + break; + } + + // fix groups to be an array + $apps = array_map(function($app){ + $groups = array(); + if (is_string($app['groups'])) { + $groups = json_decode($app['groups']); + } + $app['groups'] = $groups; + $app['canUnInstall'] = !$app['active'] && $app['removable']; + return $app; + }, $apps); + + return array('apps' => $apps, 'status' => 'success'); + } + +} diff --git a/settings/routes.php b/settings/routes.php index b91b085f3a1..82167ea6396 100644 --- a/settings/routes.php +++ b/settings/routes.php @@ -13,6 +13,8 @@ $application->registerRoutes($this, array('routes' =>array( array('name' => 'MailSettings#setMailSettings', 'url' => '/settings/admin/mailsettings', 'verb' => 'POST'), array('name' => 'MailSettings#storeCredentials', 'url' => '/settings/admin/mailsettings/credentials', 'verb' => 'POST'), array('name' => 'MailSettings#sendTestMail', 'url' => '/settings/admin/mailtest', 'verb' => 'POST'), + array('name' => 'AppSettings#listCategories', 'url' => '/settings/apps/categories', 'verb' => 'GET'), + array('name' => 'AppSettings#listApps', 'url' => '/settings/apps/list', 'verb' => 'GET') ))); /** @var $this \OCP\Route\IRouter */ @@ -80,10 +82,6 @@ $this->create('settings_cert_remove', '/settings/ajax/removeRootCertificate') // apps $this->create('settings_ajax_enableapp', '/settings/ajax/enableapp.php') ->actionInclude('settings/ajax/enableapp.php'); -$this->create('settings_ajax_load_app_categories', '/settings/apps/categories') - ->actionInclude('settings/ajax/apps/categories.php'); -$this->create('settings_ajax_load_apps', '/settings/apps/list') - ->actionInclude('settings/ajax/apps/index.php'); $this->create('settings_ajax_disableapp', '/settings/ajax/disableapp.php') ->actionInclude('settings/ajax/disableapp.php'); $this->create('settings_ajax_updateapp', '/settings/ajax/updateapp.php') |