diff --git a/public_html/classes/render-adminlte.class.php b/public_html/classes/render-adminlte.class.php index c48847c832060a11b988583145534f5980d6fe65..757ddf036b3ae7f58340177f7dda3fc92a6da38f 100755 --- a/public_html/classes/render-adminlte.class.php +++ b/public_html/classes/render-adminlte.class.php @@ -21,6 +21,7 @@ class renderadminlte { 'bgcolor'=>[ // for colors see https://adminlte.io/docs/3.2/layout.html + '', // none 'primary', 'blue', 'secondary', 'success', 'green', @@ -76,6 +77,15 @@ class renderadminlte { ], ]; + var $_aValueMappings=[ + 'shadow'=>[ + 'default' => '', + 'none' => 'shadow-none', + 'small' => 'shadow-small', + 'regular' => 'shadow', + 'large' => 'shadow-lg', + ], +]; /** * instance of htmlelements * @var object @@ -625,6 +635,59 @@ class renderadminlte { */ public function getInfobox($aOptions){ $aOptions=$this->_ensureOptions($aOptions, ['type', 'bgcolor', 'shadow', 'icon', 'text', 'number', 'progressvalue', 'progresstext']); + + // print_r($aOptions); + $sClass='info-box' + .($aOptions['class'] ? ' '.$aOptions['class'] : '') + .($aOptions['type'] ? ' bg-'.$aOptions['type'] : '') + .($aOptions['shadow'] && isset($this->_aValueMappings['shadow'][$aOptions['shadow']]) + ? ' '.$this->_aValueMappings['shadow'][$aOptions['shadow']] : '') + ; + + // build parts + $sIcon=$aOptions['icon'] + ? $this->addWrapper("span", [ + 'class'=>'info-box-icon'.($aOptions['iconbg'] ? ' bg-'.$aOptions['iconbg'] : '') + ], $this->_tag('i',['class'=>$aOptions['icon']])) + : '' + ; + $sContent=$this->addWrapper("div", ['class'=>'info-box-content'], + '' + . ($aOptions['text'] ? $this->_tag('span', ['class'=>'info-box-text', 'label'=>$aOptions['text']]) : '') + . ($aOptions['number'] ? $this->_tag('span', ['class'=>'info-box-number', 'label'=>$aOptions['number']]) : '') + . ($aOptions['progressvalue']!==false && $aOptions['progressvalue']!=='' + ? $this->addWrapper('div', ['class'=>'progress'], + $this->_tag('div', ['class'=>'progress-bar'. ($aOptions['iconbg'] ? ' bg-'.$aOptions['iconbg'] : ''), 'style'=>'width: '.(int)$aOptions['progressvalue'].'%' ]) + ) + . ($aOptions['progresstext'] ? $this->_tag('span', ['class'=>'progress-description', 'label'=>$aOptions['progresstext']]) : '' ) + : '' + ) + ); + + // merge all + return $this->_tag('div', ['class'=>$sClass], $sIcon.$sContent); + } + + + /** + * return an info-box: + * A colored box with large icon, text and a value. + * https://adminlte.io/docs/3.2/components/boxes.html + * + * @param type $aOptions hash with keys for all options + * styling: + * - type - color of the box; one of [none]|danger|dark|info|primary|secondary|success|warning + + * content + * - icon - icon class for icon on the right + * - text - information text + * - number - value (comes in bold text) + * - url - integer: progress bar; range: 0..100 + * - linktext- text below progress bar + * @return string + */ + public function getSmallbox($aOptions){ + $aOptions=$this->_ensureOptions($aOptions, ['type', 'bgcolor', 'shadow', 'icon', 'text', 'number', 'progressvalue', 'progresstext']); $aShadows=[ 'default' => '', 'none' => 'shadow-none', @@ -943,7 +1006,7 @@ class renderadminlte { * - url * @return string */ - public function getSmallBox($aOptions) { + public function MIGRATED__getSmallBox($aOptions) { foreach (array('bgcolor','color', 'title', 'text', 'icon', 'footer') as $sKey){ if(!isset($aOptions[$sKey])){ $aOptions[$sKey]=false; diff --git a/public_html/inc_functions.php b/public_html/inc_functions.php index 3118b316e074e29edeef04277a1badfe700af412..6a98c305452da030c02922778c9621c910c8ae6d 100644 --- a/public_html/inc_functions.php +++ b/public_html/inc_functions.php @@ -1,10 +1,16 @@ <?php -function showExample($sPhpcode){ +function getOutput($sPhpcode){ global $renderAdminLTE; $sOut = ''; eval("\$sOut=$sPhpcode;"); + return $sOut; +} + +function showExample($sPhpcode){ + // global $renderAdminLTE; + $sOut = getOutput($sPhpcode); return ' <table class="table"> @@ -26,7 +32,7 @@ function showExample($sPhpcode){ '.$sOut.' </td> <td> - <pre>'.htmlentities(str_replace([">", "</"], [">\n", "\n</"], $sOut)).'</pre> + <pre>'.htmlentities(str_replace([">", "</", "\n\n" ], [">\n", "\n</", "\n"], $sOut)).'</pre> </td> </tr> </tbody> diff --git a/public_html/pages/component.php b/public_html/pages/component.php index 290c17b07397921cc02a6f2876a84a587fa0de3f..f8493894e02945c966df34462185845b106cc2fe 100644 --- a/public_html/pages/component.php +++ b/public_html/pages/component.php @@ -1,28 +1,71 @@ <?php $sComponent=(isset($_GET['id']) ? preg_replace('/[^a-z]/', '', $_GET['id']) : ''); -echo "DEBUG: sComponent = $sComponent<br>"; +// ---------------------------------------------------------------------- +// pre defined values - used for dropdowns +// ---------------------------------------------------------------------- +$aPresets=[ + + 'yesno'=>[ + ''=>'no value', + '0'=>'no', + '1'=>'yes', + ], + 'type'=>[ + ''=>'no value', + 'danger'=>'red', + 'dark'=>'dark gray', + 'gray'=>'gray', + 'info'=>'aqua', + 'primary'=>'blue', + 'secondary'=>'gray', + 'success'=>'green', + 'warning'=>'yellow', + ], + 'shadow'=>[ + ''=>'no value', + 'none'=>'none', + 'small'=>'small', + 'regular'=>'regular', + 'large'=>'large' + ] +]; + +// ---------------------------------------------------------------------- +// definition of a component +// ---------------------------------------------------------------------- $aComponents=[ + + // ------------------------------------------------------------ + 'alert'=>[ + 'label'=>'Alert', + 'description'=>'', + 'method'=>'getAlert', + + 'params'=>[ + 'type' =>['select'=>$aPresets['type'], 'default'=>'warning'], + 'dismissible' =>['select'=>$aPresets['yesno'], 'default'=>''], + 'title'=>['default'=>' I need your attention'], + 'text'=>['default'=>'Please check it. Maybe there is something wrong here.'], + ] + ], + // ------------------------------------------------------------ 'infobox'=>[ 'label'=>'Infobox', 'description'=>'', 'method'=>'getInfobox', - 'examples'=>[ - [ - 'description'=>'Success infobox with progress', - 'params'=>[ - 'type'=>'success', - 'iconbg'=>'', - 'shadow'=>'', - 'icon'=>'far fa-thumbs-up', - 'text'=>'Likes', - 'number'=>"41,410", - 'progressvalue'=>70, - 'progresstext'=>'70% Increase in 30 Days' - ] - ], + + 'params'=>[ + 'type'=>['select'=>$aPresets['type'], 'default'=>''], + 'iconbg'=>['select'=>$aPresets['type'], 'default'=>'info'], + 'shadow'=>['select'=>$aPresets['shadow'], 'default'=>''], + 'icon'=>['default'=>'far fa-thumbs-up'], + 'text'=>['default'=>'Likes'], + 'number'=>['default'=>"41,410"], + 'progressvalue'=>['default'=>70], + 'progresstext'=>['default'=>'70% Increase in 30 Days'] ] ], ]; @@ -36,25 +79,102 @@ if(!isset($aComponents[$sComponent])){ $aComp=$aComponents[$sComponent]; + + + // --------- prepare output for parameter Testing + $sTester='<form + method="GET" + action="?" + > + + <input type="hidden" name="id" value="'.$sComponent.'"> + <table class="table"> + <tbody> + '; + + $aWidgetOptions=[]; + foreach($aComp['params'] as $sOptionkey=>$aParam){ + $sInput=''; + $sValue=(isset($_GET[$sOptionkey]) ? $_GET[$sOptionkey] : ( + isset($aParam['default']) + ? $aParam['default'] + : '' + )); + $aWidgetOptions[$sOptionkey]=$sValue; + + if (isset($aParam['select'])){ + foreach($aParam['select'] as $sSelectItem=>$sLabel){ + // $sInput.='<option value="'.$sSelectItem.'">'.($sSelectItem ? $sSelectItem : '-- none --').'</option>'; + $sInput.='<option value="'.$sSelectItem.'"' + .($sValue==$sSelectItem ? ' selected="selected"' : '') + .'>'.$sSelectItem .' -> '. $sLabel.'</option>'; + } + $sInput='<select size="1" name="'.$sOptionkey.'" onchange="form.submit();">'.$sInput.'</select>' + .' <button name="doloop" value="'.$sOptionkey.'">Loop</button><br>'; + + + } else { + $sInput.='<input type="text" name="'.$sOptionkey.'" value="'.$sValue.'"/>'; + } + $sTester.='<tr><td>'.$sOptionkey .'</td><td colspan="2">'. $sInput.'</td></tr>'; + } + $sTester.=' + + <tr><td><button>Submit</button></td></tr> + </tbody></table> + </form> + '; + + // --------- loop over a single var + $sLooper=''; + if(isset($_GET['doloop']) && isset($aComp['params'][$_GET['doloop']])){ + $sLoopvar=$_GET['doloop']; + + /* + $sLooper.=$renderAdminLTE->addRow( + '<h3 id="#loops">Loop over option key ['.$sLoopvar.']</h3>' + . implode(" | ", array_keys($aComp['params'][$sLoopvar]['select'])) + ); + */ + + foreach(array_keys($aComp['params'][$sLoopvar]['select']) as $sLoopValue){ + $aLoopoptions=$aWidgetOptions; + $aLoopoptions[$sLoopvar]=$sLoopValue; + + $sLooper.=$renderAdminLTE->addCol( + '<h4>"'.$sLoopvar.'" => "'.$sLoopValue.'"</h4>' + .getOutput('$renderAdminLTE->'.$aComp['method'].'('.var_export($aLoopoptions, 1).')'), + 3 + ); + } + } + + // ---------- output echo $renderAdminLTE->addRow( '<h2>'.$aComp['label'].'</h2>' ) + .$renderAdminLTE->addRow( - '<h3>Syntax</h3> - <code>echo $renderAdminLTE-><strong>'.$aComp['method'].'</strong>($aOptions)</code> - ' - ); - - foreach($aComp['examples'] as $aExample){ - echo $renderAdminLTE->addRow( - '<h4>'.$aExample['description'].'</h4>' - ) - .$renderAdminLTE->addRow( - showExample('$renderAdminLTE->'.$aComp['method'].'('.var_export($aExample['params'], 1).')') - ); - } - -; -} + $renderAdminLTE->getCard(['title'=>'Syntax', 'text'=>'<pre>echo $renderAdminLTE-><strong>'.$aComp['method'].'</strong>($aOptions)</pre>']) + ) -; \ No newline at end of file + .$renderAdminLTE->addRow( + '<h3>Testing section</h3>' + ) + .$renderAdminLTE->addRow( + $renderAdminLTE->addCol( + $renderAdminLTE->getCard(['title'=>'Parameter keys for '.$sComponent, 'text'=>$sTester]), + 3 + ).$renderAdminLTE->addCol( + showExample('$renderAdminLTE->'.$aComp['method'].'('.var_export($aWidgetOptions, 1).')') , + 9 + ) + ) + .( + $sLooper + ? $renderAdminLTE->addRow($sLooper) + + : '' + ) + ; +} \ No newline at end of file