Use speaking ids
This commit is contained in:
parent
618a08aa00
commit
e19c49295a
|
@ -42,6 +42,8 @@ use OCP\IConfig;
|
||||||
* @package OC\Settings\Controller
|
* @package OC\Settings\Controller
|
||||||
*/
|
*/
|
||||||
class AppSettingsController extends Controller {
|
class AppSettingsController extends Controller {
|
||||||
|
const CAT_ENABLED = 0;
|
||||||
|
const CAT_DISABLED = 1;
|
||||||
|
|
||||||
/** @var \OCP\IL10N */
|
/** @var \OCP\IL10N */
|
||||||
private $l10n;
|
private $l10n;
|
||||||
|
@ -94,12 +96,39 @@ class AppSettingsController extends Controller {
|
||||||
return new DataResponse();
|
return new DataResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string|int $category
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
protected function getCategory($category) {
|
||||||
|
if (is_string($category)) {
|
||||||
|
foreach ($this->listCategories() as $cat) {
|
||||||
|
if (isset($cat['ident']) && $cat['ident'] === $category) {
|
||||||
|
$category = (int) $cat['id'];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Didn't find the category, falling back to enabled
|
||||||
|
if (is_string($category)) {
|
||||||
|
$category = self::CAT_ENABLED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (int) $category;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @NoCSRFRequired
|
* @NoCSRFRequired
|
||||||
* @param int $category
|
* @param string $category
|
||||||
* @return TemplateResponse
|
* @return TemplateResponse
|
||||||
*/
|
*/
|
||||||
public function viewApps($category = 0) {
|
public function viewApps($category = '') {
|
||||||
|
$categoryId = $this->getCategory($category);
|
||||||
|
if ($categoryId === self::CAT_ENABLED) {
|
||||||
|
// Do not use an arbitrary input string, because we put the category in html
|
||||||
|
$category = 'enabled';
|
||||||
|
}
|
||||||
|
|
||||||
$params = [];
|
$params = [];
|
||||||
$params['experimentalEnabled'] = $this->config->getSystemValue('appstore.experimental.enabled', false);
|
$params['experimentalEnabled'] = $this->config->getSystemValue('appstore.experimental.enabled', false);
|
||||||
$params['category'] = $category;
|
$params['category'] = $category;
|
||||||
|
@ -123,8 +152,8 @@ class AppSettingsController extends Controller {
|
||||||
return $this->cache->get('listCategories');
|
return $this->cache->get('listCategories');
|
||||||
}
|
}
|
||||||
$categories = [
|
$categories = [
|
||||||
['id' => 0, 'displayName' => (string)$this->l10n->t('Enabled')],
|
['id' => self::CAT_ENABLED, 'ident' => 'enabled', 'displayName' => (string)$this->l10n->t('Enabled')],
|
||||||
['id' => 1, 'displayName' => (string)$this->l10n->t('Not enabled')],
|
['id' => self::CAT_DISABLED, 'ident' => 'disabled', 'displayName' => (string)$this->l10n->t('Not enabled')],
|
||||||
];
|
];
|
||||||
|
|
||||||
if($this->ocsClient->isAppStoreEnabled()) {
|
if($this->ocsClient->isAppStoreEnabled()) {
|
||||||
|
@ -132,9 +161,12 @@ class AppSettingsController extends Controller {
|
||||||
$ocs = $this->ocsClient->getCategories(\OC_Util::getVersion());
|
$ocs = $this->ocsClient->getCategories(\OC_Util::getVersion());
|
||||||
if ($ocs) {
|
if ($ocs) {
|
||||||
foreach($ocs as $k => $v) {
|
foreach($ocs as $k => $v) {
|
||||||
|
$name = str_replace('ownCloud ', '', $v);
|
||||||
|
$ident = str_replace(' ', '-', urlencode(strtolower($name)));
|
||||||
$categories[] = [
|
$categories[] = [
|
||||||
'id' => $k,
|
'id' => $k,
|
||||||
'displayName' => str_replace('ownCloud ', '', $v)
|
'ident' => $ident,
|
||||||
|
'displayName' => $name,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -148,12 +180,13 @@ class AppSettingsController extends Controller {
|
||||||
/**
|
/**
|
||||||
* Get all available apps in a category
|
* Get all available apps in a category
|
||||||
*
|
*
|
||||||
* @param int $category
|
* @param string $category
|
||||||
* @param bool $includeUpdateInfo Should we check whether there is an update
|
* @param bool $includeUpdateInfo Should we check whether there is an update
|
||||||
* in the app store?
|
* in the app store?
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function listApps($category = 0, $includeUpdateInfo = true) {
|
public function listApps($category = '', $includeUpdateInfo = true) {
|
||||||
|
$category = $this->getCategory($category);
|
||||||
$cacheName = 'listApps-' . $category . '-' . (int) $includeUpdateInfo;
|
$cacheName = 'listApps-' . $category . '-' . (int) $includeUpdateInfo;
|
||||||
|
|
||||||
if(!is_null($this->cache->get($cacheName))) {
|
if(!is_null($this->cache->get($cacheName))) {
|
||||||
|
|
|
@ -40,8 +40,8 @@ OC.Settings.Apps = OC.Settings.Apps || {
|
||||||
}
|
}
|
||||||
|
|
||||||
var categories = [
|
var categories = [
|
||||||
{displayName: t('settings', 'Enabled'), id: '0'},
|
{displayName: t('settings', 'Enabled'), ident: 'enabled', id: '0'},
|
||||||
{displayName: t('settings', 'Not enabled'), id: '1'}
|
{displayName: t('settings', 'Not enabled'), ident: 'disabled', id: '1'}
|
||||||
];
|
];
|
||||||
|
|
||||||
var source = $("#categories-template").html();
|
var source = $("#categories-template").html();
|
||||||
|
@ -49,7 +49,7 @@ OC.Settings.Apps = OC.Settings.Apps || {
|
||||||
var html = template(categories);
|
var html = template(categories);
|
||||||
$('#apps-categories').html(html);
|
$('#apps-categories').html(html);
|
||||||
|
|
||||||
OC.Settings.Apps.loadCategory(parseInt($('#app-navigation').attr('data-category'), 10));
|
OC.Settings.Apps.loadCategory($('#app-navigation').attr('data-category'));
|
||||||
|
|
||||||
this._loadCategoriesCall = $.ajax(OC.generateUrl('settings/apps/categories'), {
|
this._loadCategoriesCall = $.ajax(OC.generateUrl('settings/apps/categories'), {
|
||||||
data:{},
|
data:{},
|
||||||
|
|
|
@ -24,7 +24,7 @@ script(
|
||||||
?>
|
?>
|
||||||
<script id="categories-template" type="text/x-handlebars-template">
|
<script id="categories-template" type="text/x-handlebars-template">
|
||||||
{{#each this}}
|
{{#each this}}
|
||||||
<li id="app-category-{{id}}" data-category-id="{{id}}" tabindex="0">
|
<li id="app-category-{{ident}}" data-category-id="{{ident}}" tabindex="0">
|
||||||
<a>{{displayName}}</a>
|
<a>{{displayName}}</a>
|
||||||
</li>
|
</li>
|
||||||
{{/each}}
|
{{/each}}
|
||||||
|
|
|
@ -132,10 +132,12 @@ class AppSettingsControllerTest extends TestCase {
|
||||||
$expected = [
|
$expected = [
|
||||||
[
|
[
|
||||||
'id' => 0,
|
'id' => 0,
|
||||||
|
'ident' => 'enabled',
|
||||||
'displayName' => 'Enabled',
|
'displayName' => 'Enabled',
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'id' => 1,
|
'id' => 1,
|
||||||
|
'ident' => 'disabled',
|
||||||
'displayName' => 'Not enabled',
|
'displayName' => 'Not enabled',
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
@ -157,27 +159,33 @@ class AppSettingsControllerTest extends TestCase {
|
||||||
$expected = [
|
$expected = [
|
||||||
[
|
[
|
||||||
'id' => 0,
|
'id' => 0,
|
||||||
|
'ident' => 'enabled',
|
||||||
'displayName' => 'Enabled',
|
'displayName' => 'Enabled',
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'id' => 1,
|
'id' => 1,
|
||||||
|
'ident' => 'disabled',
|
||||||
'displayName' => 'Not enabled',
|
'displayName' => 'Not enabled',
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'id' => 0,
|
'id' => 0,
|
||||||
|
'ident' => 'tools',
|
||||||
'displayName' => 'Tools',
|
'displayName' => 'Tools',
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'id' => 1,
|
'id' => 1,
|
||||||
'displayName' => 'Awesome Games',
|
'ident' => 'games',
|
||||||
|
'displayName' => 'Games',
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'id' => 2,
|
'id' => 2,
|
||||||
'displayName' => 'PIM',
|
'ident' => 'productivity',
|
||||||
|
'displayName' => 'Productivity',
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'id' => 3,
|
'id' => 3,
|
||||||
'displayName' => 'Papershop',
|
'ident' => 'multimedia',
|
||||||
|
'displayName' => 'Multimedia',
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -201,9 +209,9 @@ class AppSettingsControllerTest extends TestCase {
|
||||||
->will($this->returnValue(
|
->will($this->returnValue(
|
||||||
[
|
[
|
||||||
'ownCloud Tools',
|
'ownCloud Tools',
|
||||||
'Awesome Games',
|
'Games',
|
||||||
'ownCloud PIM',
|
'ownCloud Productivity',
|
||||||
'Papershop',
|
'Multimedia',
|
||||||
]
|
]
|
||||||
));
|
));
|
||||||
|
|
||||||
|
@ -223,7 +231,7 @@ class AppSettingsControllerTest extends TestCase {
|
||||||
$policy = new ContentSecurityPolicy();
|
$policy = new ContentSecurityPolicy();
|
||||||
$policy->addAllowedImageDomain('https://apps.owncloud.com');
|
$policy->addAllowedImageDomain('https://apps.owncloud.com');
|
||||||
|
|
||||||
$expected = new TemplateResponse('settings', 'apps', ['experimentalEnabled' => false, 'category' => 0], 'user');
|
$expected = new TemplateResponse('settings', 'apps', ['experimentalEnabled' => false, 'category' => 'enabled'], 'user');
|
||||||
$expected->setContentSecurityPolicy($policy);
|
$expected->setContentSecurityPolicy($policy);
|
||||||
|
|
||||||
$this->assertEquals($expected, $this->appSettingsController->viewApps());
|
$this->assertEquals($expected, $this->appSettingsController->viewApps());
|
||||||
|
@ -242,9 +250,9 @@ class AppSettingsControllerTest extends TestCase {
|
||||||
$policy = new ContentSecurityPolicy();
|
$policy = new ContentSecurityPolicy();
|
||||||
$policy->addAllowedImageDomain('https://apps.owncloud.com');
|
$policy->addAllowedImageDomain('https://apps.owncloud.com');
|
||||||
|
|
||||||
$expected = new TemplateResponse('settings', 'apps', ['experimentalEnabled' => false, 'category' => 1], 'user');
|
$expected = new TemplateResponse('settings', 'apps', ['experimentalEnabled' => false, 'category' => 'disabled'], 'user');
|
||||||
$expected->setContentSecurityPolicy($policy);
|
$expected->setContentSecurityPolicy($policy);
|
||||||
|
|
||||||
$this->assertEquals($expected, $this->appSettingsController->viewApps(1));
|
$this->assertEquals($expected, $this->appSettingsController->viewApps('disabled'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue