Commit 5b82041d authored by Carsten  Rose's avatar Carsten Rose
Browse files

Refs #8348 - first implementation for Bootstrap dropdown menu's - fully SIP supported.

parent 98fe89cb
Pipeline #1856 passed with stage
in 2 minutes and 30 seconds
......@@ -1595,6 +1595,7 @@ const TOKEN_PAGE = 'p';
const TOKEN_UID = 'uid';
const TOKEN_DOWNLOAD = 'd';
const TOKEN_COPY_TO_CLIPBOARD = 'y';
const TOKEN_DROPDOWN = 'z';
const TOKEN_TEXT = 't';
const TOKEN_ALT_TEXT = 'a';
......
......@@ -43,19 +43,30 @@ require_once(__DIR__ . '/Thumbnail.php');
* D:delete
* e:encryption 0|1
* E:edit
* f:
* F:File
* g:target
* G:Glyph
* h:
* H:Help
* i:
* I:information
* j:
* J:
* k:
* K:
* l:
* L:
* m:mailto
* M:Mode
* n:
* N:new
* o:ToolTip
* O:Monitor
* p:page
* P:picture [file]
* q:question <text>
* Q:
* r:render
* R:right
* s:sip
......@@ -64,18 +75,25 @@ require_once(__DIR__ . '/Thumbnail.php');
* T:Thumbnail
* u:url
* U:URL Param
* v:
* V:
* w:
* W:Dimension
* x:Delete
* X:
* y:Copy to clipboard
* Y:
* z:DropDown Menu
* Z:
*
*/
const NAME_URL = 'url';
const NAME_MAIL = 'mail';
const NAME_PAGE = 'page';
const NAME_UID = 'uid';
const NAME_TEXT = 'text';
const NAME_DROPDOWN = 'dropdown';
const NAME_DOWNLOAD = DOWNLOAD_EXPORT_FILENAME;
const NAME_COLLECT_ELEMENTS = 'downloadElements'; // array with element sources
const NAME_DOWNLOAD_MODE = 'mode';
......@@ -171,6 +189,7 @@ class Link {
TOKEN_PAGE => 'buildPage',
TOKEN_COPY_TO_CLIPBOARD => 'buildCopyToClipboard',
TOKEN_DOWNLOAD => 'buildDownload',
TOKEN_DROPDOWN => 'buildDropdown',
TOKEN_TOOL_TIP => 'buildToolTip',
TOKEN_PICTURE => 'buildPicture',
TOKEN_BULLET => 'buildBullet',
......@@ -193,6 +212,7 @@ class Link {
TOKEN_MAIL => NAME_MAIL,
TOKEN_PAGE => NAME_PAGE,
TOKEN_UID => NAME_UID,
TOKEN_DROPDOWN => NAME_DROPDOWN,
TOKEN_DOWNLOAD => NAME_DOWNLOAD,
TOKEN_DOWNLOAD_MODE => NAME_DOWNLOAD_MODE,
TOKEN_TEXT => NAME_TEXT,
......@@ -371,6 +391,101 @@ class Link {
}
/**
* @param string $str
*
* @return string
* @throws CodeException
* @throws UserFormException
* @throws UserReportException
*/
private function processDropdown($str) {
$menuHtml = '';
$menuEntryStrArr = array();
$menuEntryLinkArr = array();
$tokenCollect = array();
$dropdownStr = null;
$paramArr = KeyValueStringParser::explodeEscape(PARAM_DELIMITER, $str);
// Iterate over token. Find delimiter to separate dropdown definition and all menu entries.
foreach ($paramArr as $tokenStr) {
$tokenArr = explode(PARAM_TOKEN_DELIMITER, $tokenStr, 2);
switch ($tokenArr[0] ?? '') {
// No further need: skip
case TOKEN_DROPDOWN:
break;
// Indicator to start menu entry: force a flush of existing token and start a new round.
case TOKEN_URL:
case TOKEN_MAIL:
case TOKEN_PAGE:
case TOKEN_DOWNLOAD:
case TOKEN_COPY_TO_CLIPBOARD:
case '':
// New menu entry
$menuEntryStrArr[] = implode(PARAM_DELIMITER, $tokenCollect);
$tokenCollect = array();
$tokenCollect[] = $tokenStr;
break;
default:
$tokenCollect[] = $tokenStr;
}
}
// 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);
}
return $this->renderDropdown($dropdownStr, $menuEntryLinkArr);
}
/**
* Start
* <span class="dropdown">
* <span class="glyphicon glyphicon-option-vertical dropdown-toggle" id="dropdownMenu11" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
* </span>
* <ul class="dropdown-menu" aria-labelledby="dropdownMenu11">
* <li><a href="#">Action</a></li>
* <li><a href="#">Another action</a></li>
* <li><a href="#">Something else here</a></li>
* <li role="separator" class="divider"></li>
* <li><a href="#">Separated link</a></li>
* </ul>
* </span>
* End
*
* @param $dropdownStr
* @param $menuEntryLinkArr
* @return string
*/
private function renderDropdown($dropdownStr, $menuEntryLinkArr) {
static $count = 0;
$time = microtime(false);
if (defined('PHPUNIT_QFQ')) {
$time = '0.123 1234';
}
$htmlId = $time . $count++;
$tmp = '';
foreach ($menuEntryLinkArr as $link) {
$tmp .= '<li>' . $link . '</li>';
}
$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>';
return Support::wrapTag('<span class="dropdown">', $symbol . $ul);
}
/**
* Build the whole link.
*
......@@ -391,6 +506,11 @@ class Link {
return '';
}
// Check for dropdown menu
if (($str[0] ?? '') == TOKEN_DROPDOWN) {
return $this->processDropdown($str);
}
$vars = $this->fillParameter($str, $tokenGiven);
$vars = $this->processParameter($vars, $tokenGiven);
$mode = $this->getModeRender($vars, $tokenGiven);
......@@ -489,10 +609,10 @@ class Link {
$key = substr($value, 0, 2);
if (strlen($key) == 1) {
$key .= ':';
$key .= PARAM_TOKEN_DELIMITER;
}
if ($key == TOKEN_DOWNLOAD . ':') {
if ($key == TOKEN_DOWNLOAD . PARAM_TOKEN_DELIMITER) {
$prio[] = $value;
} else {
$regular[] = $value;
......@@ -1094,7 +1214,7 @@ class Link {
$level = ($arr[QUESTION_INDEX_LEVEL] === '') ? DEFAULT_QUESTION_LEVEL : $arr[QUESTION_INDEX_LEVEL];
$ok = ($arr[QUESTION_INDEX_BUTTON_OK] === '') ? 'Ok' : $arr[QUESTION_INDEX_BUTTON_OK];
$cancel = ($arr[QUESTION_INDEX_BUTTON_FALSE] === '') ? 'Cancel' : $arr[QUESTION_INDEX_BUTTON_FALSE];
$cancel = ($cancel=='-') ? '': ", { label: '$cancel',eventName: 'cancel'}";
$cancel = ($cancel == '-') ? '' : ", { label: '$cancel',eventName: 'cancel'}";
$timeout = ($arr[QUESTION_INDEX_TIMEOUT] === '') ? '0' : $arr[QUESTION_INDEX_TIMEOUT] * 1000;
$flagModalStatus = ($arr[QUESTION_INDEX_FLAG_MODAL] === '') ? '1' : $arr[QUESTION_INDEX_FLAG_MODAL];
......@@ -1137,7 +1257,7 @@ EOF;
$attributes .= Support::doAttribute('class', $vars[FINAL_CLASS]);
$attributes .= Support::doAttribute('target', $vars[NAME_TARGET]);
$attributes .= Support::doAttribute('title', $vars[FINAL_TOOL_TIP]);
if ( $vars[NAME_ATTRIBUTE] != '') {
if ($vars[NAME_ATTRIBUTE] != '') {
$attributes .= $vars[NAME_ATTRIBUTE] . ' ';
}
$attributes .= $vars[FINAL_QUESTION];
......
......@@ -1458,7 +1458,35 @@ EOF;
$this->assertEquals('', $result);
}
/**
* @throws CodeException
* @throws UserFormException
* @throws UserReportException
*/
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>';
$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>';
$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>';
$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>';
$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>';
$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