add options to select apps that must be displayed in the top menu (replace exteral sites option)

This commit is contained in:
Simon Vieille 2020-08-12 10:51:49 +02:00
parent caa9c092ef
commit ffab77aff2
Signed by: deblan
GPG key ID: 03383D15A1D31745
8 changed files with 66 additions and 22 deletions

View file

@ -20,6 +20,11 @@
margin: 10px 0 10px 0;
}
#side-menu-section input[type="checkbox"] {
vertical-align: middle;
}
#side-menu-section select {
margin: 10px 0 10px 0;
}
@ -32,3 +37,5 @@
color: #555;
border-radius: 3px;
}

View file

@ -61,6 +61,7 @@ class JsController extends Controller
'hide-when-no-apps' => (bool) $this->config->getAppValue('side_menu', 'hide-when-no-apps', '0'),
'loader-enabled' => (bool) $this->config->getAppValue('side_menu', 'loader-enabled', '1'),
'big-menu' => (bool) $this->config->getAppValue('side_menu', 'big-menu', '0'),
'top-menu-apps' => (array) json_decode($this->config->getAppValue('side_menu', 'top-menu-apps', '[]'), true),
];
$response = new TemplateResponse('side_menu', 'js/script', $parameters, 'blank');

View file

@ -23,6 +23,7 @@ use OCP\IL10N;
use OCP\ILogger;
use OCP\Settings\ISettings;
use OCP\IConfig;
use OCA\SideMenu\Service\AppRepository;
class Admin implements ISettings
{
@ -41,11 +42,17 @@ class Admin implements ISettings
*/
private $config;
public function __construct(IL10N $l, ILogger $logger, IConfig $config)
/**
* @var AppRepository
*/
private $appRepository;
public function __construct(IL10N $l, ILogger $logger, IConfig $config, AppRepository $appRepository)
{
$this->l = $l;
$this->logger = $logger;
$this->config = $config;
$this->appRepository = $appRepository;
}
/**
@ -74,7 +81,8 @@ class Admin implements ISettings
'hide-when-no-apps' => $this->config->getAppValue('side_menu', 'hide-when-no-apps', '0'),
'size-icon' => $this->config->getAppValue('side_menu', 'size-icon', 'normal'),
'size-text' => $this->config->getAppValue('side_menu', 'size-text', 'normal'),
'external-sites-in-top-menu' => $this->config->getAppValue('side_menu', 'external-sites-in-top-menu', '0'),
'top-menu-apps' => (array) json_decode($this->config->getAppValue('side_menu', 'top-menu-apps', '[]'), true),
'apps' => $this->appRepository->getVisibleApps(),
];
return new TemplateResponse('side_menu', 'settings/admin-form', $parameters, '');

View file

@ -63,7 +63,7 @@ export default {
var dataId = parent.getAttribute('data-id')
dataId = dataId !== null ? dataId : ''
if (this.ignoreExternalSites && dataId.indexOf('external_index') !== -1) {
if (!parent.classList.contains('app-hidden')) {
continue
}
@ -113,7 +113,6 @@ export default {
this.retrieveApps()
this.retrieveLogo()
this.forceLightIcon = document.querySelector('#side-menu-container').getAttribute('data-forcelighticon') == 1;
this.ignoreExternalSites = document.querySelector('#side-menu-container').getAttribute('data-externalsitesintopmenu') == 1;
const menu = document.querySelector('#appmenu')

View file

@ -32,8 +32,24 @@ const appConfig = (name, value, callbacks) => {
const saveSettings = (key) => {
const element = elements.get(key)
const name = $(element).attr('name')
let value = $(element).val()
let value
let name
if ($(element).is('[data-checkbox]')) {
name = $(element).attr('data-name')
const inputs = $('input[name="' + name + '[]"]:checked')
value = []
inputs.each((i, v) => {
value.push(v.value)
})
value = JSON.stringify(value)
} else {
name = $(element).attr('name')
value = $(element).val()
}
const size = elements.length
if (element === 'side-menu-cache') {

View file

@ -1,5 +1,3 @@
sideMenuContainer.attr('data-externalsitesintopmenu', '1')
var menuCache = null
var updateTopMenu = function() {
@ -31,7 +29,7 @@ var updateTopMenu = function() {
return
}
if (dataId.indexOf('external_index') === -1) {
if (topMenuApps.indexOf(dataId) === -1) {
app.classList.add('hidden')
app.classList.add('app-hidden')
} else {

View file

@ -104,7 +104,9 @@
sideMenuOpener.insertAfter('#nextcloud')
<?php endif; ?>
<?php if ($_['external-sites-in-top-menu']): ?>
<?php require_once __DIR__.'/_externalSitesInTopMenu.js'; ?>
<?php if (!empty($_['top-menu-apps'])): ?>
var topMenuApps = <?php echo json_encode($_['top-menu-apps']); ?>;
<?php require_once __DIR__.'/_topMenuApps.js'; ?>
<?php endif; ?>
})();

View file

@ -311,24 +311,37 @@ $choicesSizes = [
<?php endforeach; ?>
</select>
</div>
</div>
<div class="section">
<h2>
<?php p($l->t('Top menu')); ?>
</h2>
<div>
<label for="side-menu-external-sites-in-top-menu">
<?php p($l->t('Do not move external sites in the side menu')); ?>
<label for="side-menu-top-menu-apps">
<?php p($l->t('Apps that not must be moved in the side menu')); ?>
<small><span class="warning">Experimental</span></small>
</label>
</div>
<p><em>Should be enabled with the <code>big menu</code> display.</em></p>
<p><em>Selected apps will be displayed in the <code>big menu</code> display and in the top menu.</em></p>
<div>
<select id="side-menu-external-sites-in-top-menu" name="external-sites-in-top-menu" class="side-menu-setting">
<?php foreach ($choicesYesNo as $label => $value): ?>
<option value="<?php echo $value ?>" <?php if ($value === $_['external-sites-in-top-menu']): ?>selected<?php endif; ?>>
<?php echo $l->t($label); ?>
</option>
<?php endforeach; ?>
</select>
<div class="side-menu-setting" data-name="top-menu-apps" data-checkbox>
<?php foreach ($_['apps'] as $app): ?>
<div>
<input
type="checkbox"
name="top-menu-apps[]"
value="<?php echo $app['id'] ?>"
id="top-menu-app-<?php echo $app['id'] ?>"
<?php if (in_array($app['id'], $_['top-menu-apps'])): ?>checked<?php endif; ?>
/>
<label for="top-menu-app-<?php echo $app['id'] ?>">
<?php echo $app['name'] ?>
</label>
</div>
<?php endforeach; ?>
</div>
</div>