Commit c3a8b180 authored by Carsten  Rose's avatar Carsten Rose
Browse files

Refs #8348 - Menu might be disabled. Buttons.

parent 5b82041d
Pipeline #1857 failed with stage
in 2 minutes and 14 seconds
......@@ -400,11 +400,17 @@ class Link {
* @throws UserReportException
*/
private function processDropdown($str) {
$menuHtml = '';
$menuEntryStrArr = array();
$menuEntryLinkArr = array();
$tokenCollect = array();
$dropdownStr = null;
static $count = 0;
$time = microtime(false);
if (defined('PHPUNIT_QFQ')) {
$time = '0.123 1234';
}
$htmlId = $time . ' ' . $count++;
$paramArr = KeyValueStringParser::explodeEscape(PARAM_DELIMITER, $str);
......@@ -436,14 +442,19 @@ class Link {
// Flush remaining element
$menuEntryStrArr[] = implode(PARAM_DELIMITER, $tokenCollect);
$dropdownStr = array_shift($menuEntryStrArr);
// For each menu entry get the link
foreach ($menuEntryStrArr as $str) {
$menuEntryLinkArr[] = $this->renderLink($str);
// Remove first array element - that's the menu, not the menu entry. Render the menu.
$flagMenuEnabled = false;
$dropdownSymbol = $this->renderDropdownSymbol(array_shift($menuEntryStrArr), $htmlId, $flagMenuEnabled);
if ($flagMenuEnabled) {
// For each menu entry get the link
foreach ($menuEntryStrArr as $str) {
$menuEntryLinkArr[] = $this->renderLink($str);
}
}
return $this->renderDropdown($dropdownStr, $menuEntryLinkArr);
return $this->renderDropdown($dropdownSymbol, $menuEntryLinkArr, $htmlId, $flagMenuEnabled);
}
......@@ -462,28 +473,86 @@ class Link {
* </span>
* End
*
* @param $dropdownStr
* @param $menuEntryLinkArr
* @param string $dropdownSymbol
* @param array $menuEntryLinkArr
* @param string $htmlId
* @param bool $flagMenuEnabled
* @return string
*/
private function renderDropdown($dropdownStr, $menuEntryLinkArr) {
static $count = 0;
$time = microtime(false);
private function renderDropdown(string $dropdownSymbol, array $menuEntryLinkArr, $htmlId, $flagMenuEnabled) {
$ul = '';
if (defined('PHPUNIT_QFQ')) {
$time = '0.123 1234';
if ($flagMenuEnabled) {
$tmp = '';
foreach ($menuEntryLinkArr as $link) {
$tmp .= '<li>' . $link . '</li>';
}
$ul = Support::wrapTag('<ul class="dropdown-menu" aria-labelledby="' . $htmlId . '">', $tmp);
}
return Support::wrapTag('<span class="dropdown">', $dropdownSymbol . $ul);
}
/**
* @param string $dropdownStr
* @param string $htmlId
* @return string
* @throws CodeException
* @throws UserFormException
* @throws UserReportException
*/
private function renderDropdownSymbol($dropdownStr, $htmlId, &$flagMenuEnabled) {
$class = '';
$paramArr = KeyValueStringParser::parse($dropdownStr, PARAM_TOKEN_DELIMITER, PARAM_DELIMITER);
foreach ([TOKEN_URL, TOKEN_MAIL, TOKEN_PAGE, TOKEN_DOWNLOAD, TOKEN_COPY_TO_CLIPBOARD] as $token) {
if (isset($paramArr[$token])) {
throw new UserReportException("Dropdown / broken definition: Token '$token' can't be part of " . TOKEN_DROPDOWN, ERROR_INVALID_VALUE);
}
}
$htmlId = $time . $count++;
$tmp = '';
foreach ($menuEntryLinkArr as $link) {
$tmp .= '<li>' . $link . '</li>';
// All render mode <3 means: enabled
$flagMenuEnabled = ($paramArr[TOKEN_RENDER] ?? 0) < 3;
// Misuse the link class to render the menu symbol: this gives tooltip, glyph, button, text ... - set render mode to '3' = 'no link'
$paramArr[TOKEN_RENDER] = '3';
if (!isset($paramArr[TOKEN_GLYPH])) {
$paramArr[TOKEN_GLYPH] = 'glyphicon-option-vertical';
}
$ul = Support::wrapTag('<ul class="dropdown-menu" aria-labelledby="' . $htmlId . '">', $tmp);
$symbol = '<span class="glyphicon glyphicon-option-vertical dropdown-toggle" id="' . $htmlId . '" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true"></span>';
if (isset($paramArr[TOKEN_BOOTSTRAP_BUTTON])) {
$vars = $this->buildBootstrapButton(array(), $paramArr[TOKEN_BOOTSTRAP_BUTTON]);
$class = ' ' . ($vars[NAME_BOOTSTRAP_BUTTON] ?? '');
}
if (!isset($paramArr[TOKEN_ATTRIBUTE])) {
$paramArr[TOKEN_ATTRIBUTE] = 'data-toggle="dropdown" aria-haspopup="true" aria-expanded="true"';
}
if (!$flagMenuEnabled) {
$class .= ' disabled';
// In case there is no button: set the text an glyphicon to 'muted'
if (($vars[NAME_BOOTSTRAP_BUTTON] ?? '') === '') {
if (($paramArr[TOKEN_TEXT] ?? '') != '') {
$paramArr[TOKEN_TEXT] = Support::wrapTag('<span class="text-muted">', $paramArr[TOKEN_TEXT]);
}
if (($paramArr[TOKEN_GLYPH] ?? '') != '') {
$paramArr[TOKEN_GLYPH] .= ' text-muted';
}
}
}
$paramArr[TOKEN_ATTRIBUTE] .= ' class="dropdown-toggle' . $class . '"';
$paramArr[TOKEN_ATTRIBUTE] .= ' id="' . $htmlId . '"';
return $this->renderLink(KeyValueStringParser::unparse($paramArr, PARAM_TOKEN_DELIMITER, PARAM_DELIMITER));
// $symbol = '<span class="glyphicon glyphicon-option-vertical dropdown-toggle" id="' . $htmlId . '" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true"></span>';
return Support::wrapTag('<span class="dropdown">', $symbol . $ul);
}
/**
......@@ -689,7 +758,7 @@ class Link {
unset($rcTokenGiven[$key]); // Skip Bookkeeping for TOKEN_URL_PARAM | TOKEN_FILE | TOKEN_URL.
continue;
} else {
// TOKEN_GLYPH should not treated as an regular image. Same applies to the other Glyph symbols, but those don't have a value, and therefore do not fill $vars['image'].
// TOKEN_GLYPH should not be treated as an regular image. Same applies to the other Glyph symbols, but those don't have a value, and therefore do not fill $vars['image'].
if ($key != TOKEN_GLYPH) {
$vars[$keyName] = $value;
}
......@@ -1149,7 +1218,7 @@ class Link {
$html .= '<img ' . $tags . '>';
}
if ($vars[NAME_GLYPH] !== '') {
if ($vars[NAME_GLYPH] !== '' && $vars[NAME_GLYPH] !== '0') {
$tags = Support::doAttribute('class', 'glyphicon ' . $vars[NAME_GLYPH]);
$html .= Support::wrapTag('<span ' . $tags . '>', '', false);
}
......
......@@ -1466,27 +1466,28 @@ EOF;
public function testLinkDropdown() {
$link = new Link($this->sip, DB_INDEX_DEFAULT, true);
$expect = '<span class="dropdown"><span class="glyphicon glyphicon-option-vertical dropdown-toggle" id="0.123 12340" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true"></span><ul class="dropdown-menu" aria-labelledby="0.123 12340"></ul></span>';
$expect = '<span class="dropdown"><span class="glyphicon glyphicon-option-vertical dropdown-toggle" id="0.123 1234 0" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true"></span><ul class="dropdown-menu" aria-labelledby="0.123 1234 0"></ul></span>';
$expect = '<span class="dropdown"><span title="Details" class="dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true" id="0.123 1234 0" ><span class="glyphicon glyphicon-option-vertical" ></span></span><ul class="dropdown-menu" aria-labelledby="0.123 1234 0"></ul></span>';
$result = $link->renderLink('z');
$this->assertEquals($expect, $result);
$expect = '<span class="dropdown"><span class="glyphicon glyphicon-option-vertical dropdown-toggle" id="0.123 12341" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true"></span><ul class="dropdown-menu" aria-labelledby="0.123 12341"></ul></span>';
$expect = '<span class="dropdown"><span class="glyphicon glyphicon-option-vertical dropdown-toggle" id="0.123 1234 1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true"></span><ul class="dropdown-menu" aria-labelledby="0.123 1234 1"></ul></span>';
$result = $link->renderLink('z:');
$this->assertEquals($expect, $result);
$expect = '<span class="dropdown"><span class="glyphicon glyphicon-option-vertical dropdown-toggle" id="0.123 12342" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true"></span><ul class="dropdown-menu" aria-labelledby="0.123 12342"></ul></span>';
$expect = '<span class="dropdown"><span class="glyphicon glyphicon-option-vertical dropdown-toggle" id="0.123 1234 2" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true"></span><ul class="dropdown-menu" aria-labelledby="0.123 1234 2"></ul></span>';
$result = $link->renderLink('z|t:Menu|G:glyph-icon-left|o:Open menu');
$this->assertEquals($expect, $result);
$expect = '<span class="dropdown"><span class="glyphicon glyphicon-option-vertical dropdown-toggle" id="0.123 12343" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true"></span><ul class="dropdown-menu" aria-labelledby="0.123 12343"><li><a href="?id=home" >Home</a></li></ul></span>';
$expect = '<span class="dropdown"><span class="glyphicon glyphicon-option-vertical dropdown-toggle" id="0.123 1234 3" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true"></span><ul class="dropdown-menu" aria-labelledby="0.123 1234 3"><li><a href="?id=home" >Home</a></li></ul></span>';
$result = $link->renderLink('z|t:Menu|G:glyph-icon-left|o:Open menu|p:home|t:Home');
$this->assertEquals($expect, $result);
$expect = '<span class="dropdown"><span class="glyphicon glyphicon-option-vertical dropdown-toggle" id="0.123 12344" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true"></span><ul class="dropdown-menu" aria-labelledby="0.123 12344"><li><a href="index.php?id=home&s=badcaffee1234" >Home</a></li><li><a href="?id=back" title="Navigate back" >Back</a></li></ul></span>';
$expect = '<span class="dropdown"><span class="glyphicon glyphicon-option-vertical dropdown-toggle" id="0.123 1234 4" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true"></span><ul class="dropdown-menu" aria-labelledby="0.123 1234 4"><li><a href="index.php?id=home&s=badcaffee1234" >Home</a></li><li><a href="?id=back" title="Navigate back" >Back</a></li></ul></span>';
$result = $link->renderLink('z|t:Menu|G:glyph-icon-left|o:Open menu|p:home|t:Home|s|p:back|t:Back|o:Navigate back');
$this->assertEquals($expect, $result);
}
/**
* @expectedException \qfq\UserReportException
*
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment