Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 0 additions & 30 deletions settings/ajax/apps/categories.php

This file was deleted.

65 changes: 0 additions & 65 deletions settings/ajax/apps/index.php

This file was deleted.

10 changes: 9 additions & 1 deletion settings/application.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -44,7 +45,14 @@ public function __construct(array $urlParams=array()){
$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
*/
Expand Down
132 changes: 132 additions & 0 deletions settings/controller/appsettingscontroller.php
Original file line number Diff line number Diff line change
@@ -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,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your tabbing is going too far!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mhm - works for me locally, according to our coding guidelines:

Use tabs to indent
A tab is 4 spaces wide

And then it matches:

screen shot 2014-10-28 at 11 12 31

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');
}

}
6 changes: 2 additions & 4 deletions settings/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
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 */
Expand Down Expand Up @@ -80,10 +82,6 @@
// 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')
Expand Down