summaryrefslogtreecommitdiffstats
path: root/settings
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@owncloud.com>2015-10-20 12:02:08 +0200
committerJoas Schilling <nickvergessen@owncloud.com>2015-10-26 16:15:15 +0100
commite19c49295a4bba82b2e1fa613ad03608c79d6443 (patch)
treedb431dbf13f6044a687a03086ec566cb6217e4c2 /settings
parent618a08aa00160c6b709a0da2bf8566b9002073ff (diff)
downloadnextcloud-server-e19c49295a4bba82b2e1fa613ad03608c79d6443.tar.gz
nextcloud-server-e19c49295a4bba82b2e1fa613ad03608c79d6443.zip
Use speaking ids
Diffstat (limited to 'settings')
-rw-r--r--settings/controller/appsettingscontroller.php47
-rw-r--r--settings/js/apps.js6
-rw-r--r--settings/templates/apps.php2
3 files changed, 44 insertions, 11 deletions
diff --git a/settings/controller/appsettingscontroller.php b/settings/controller/appsettingscontroller.php
index 9022e48a342..bde00df062f 100644
--- a/settings/controller/appsettingscontroller.php
+++ b/settings/controller/appsettingscontroller.php
@@ -42,6 +42,8 @@ use OCP\IConfig;
* @package OC\Settings\Controller
*/
class AppSettingsController extends Controller {
+ const CAT_ENABLED = 0;
+ const CAT_DISABLED = 1;
/** @var \OCP\IL10N */
private $l10n;
@@ -95,11 +97,38 @@ class AppSettingsController extends Controller {
}
/**
+ * @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
- * @param int $category
+ * @param string $category
* @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['experimentalEnabled'] = $this->config->getSystemValue('appstore.experimental.enabled', false);
$params['category'] = $category;
@@ -123,8 +152,8 @@ class AppSettingsController extends Controller {
return $this->cache->get('listCategories');
}
$categories = [
- ['id' => 0, 'displayName' => (string)$this->l10n->t('Enabled')],
- ['id' => 1, 'displayName' => (string)$this->l10n->t('Not enabled')],
+ ['id' => self::CAT_ENABLED, 'ident' => 'enabled', 'displayName' => (string)$this->l10n->t('Enabled')],
+ ['id' => self::CAT_DISABLED, 'ident' => 'disabled', 'displayName' => (string)$this->l10n->t('Not enabled')],
];
if($this->ocsClient->isAppStoreEnabled()) {
@@ -132,9 +161,12 @@ class AppSettingsController extends Controller {
$ocs = $this->ocsClient->getCategories(\OC_Util::getVersion());
if ($ocs) {
foreach($ocs as $k => $v) {
+ $name = str_replace('ownCloud ', '', $v);
+ $ident = str_replace(' ', '-', urlencode(strtolower($name)));
$categories[] = [
'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
*
- * @param int $category
+ * @param string $category
* @param bool $includeUpdateInfo Should we check whether there is an update
* in the app store?
* @return array
*/
- public function listApps($category = 0, $includeUpdateInfo = true) {
+ public function listApps($category = '', $includeUpdateInfo = true) {
+ $category = $this->getCategory($category);
$cacheName = 'listApps-' . $category . '-' . (int) $includeUpdateInfo;
if(!is_null($this->cache->get($cacheName))) {
diff --git a/settings/js/apps.js b/settings/js/apps.js
index 0734ad54ae0..df1181b1e71 100644
--- a/settings/js/apps.js
+++ b/settings/js/apps.js
@@ -40,8 +40,8 @@ OC.Settings.Apps = OC.Settings.Apps || {
}
var categories = [
- {displayName: t('settings', 'Enabled'), id: '0'},
- {displayName: t('settings', 'Not enabled'), id: '1'}
+ {displayName: t('settings', 'Enabled'), ident: 'enabled', id: '0'},
+ {displayName: t('settings', 'Not enabled'), ident: 'disabled', id: '1'}
];
var source = $("#categories-template").html();
@@ -49,7 +49,7 @@ OC.Settings.Apps = OC.Settings.Apps || {
var html = template(categories);
$('#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'), {
data:{},
diff --git a/settings/templates/apps.php b/settings/templates/apps.php
index 5d9abe021ac..bb01d991e5e 100644
--- a/settings/templates/apps.php
+++ b/settings/templates/apps.php
@@ -24,7 +24,7 @@ script(
?>
<script id="categories-template" type="text/x-handlebars-template">
{{#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>
</li>
{{/each}}