From 20f1be3356ea4515106dd678c11d68fdba784190 Mon Sep 17 00:00:00 2001
From: "Hahn Axel (hahn)" <axel.hahn@iml.unibe.ch>
Date: Thu, 15 Dec 2022 13:38:47 +0100
Subject: [PATCH] update class

---
 public_html/classes/render-adminlte.class.php | 75 +++++++++++++------
 1 file changed, 51 insertions(+), 24 deletions(-)

diff --git a/public_html/classes/render-adminlte.class.php b/public_html/classes/render-adminlte.class.php
index 35e62ca..0f25163 100755
--- a/public_html/classes/render-adminlte.class.php
+++ b/public_html/classes/render-adminlte.class.php
@@ -83,8 +83,8 @@ class renderadminlte {
             'values'=>[
                 ''=>'no value',
                 'outline'=>'small stripe on top',
-                'solid'=>'',
-                'gradient'=>'',
+                'solid'=>'full filled widget',
+                'gradient'=>'full filled with gradient',
             ]
         ],
         'visibility'=>[
@@ -118,6 +118,16 @@ class renderadminlte {
         ],
     ];
 
+    var $_aValueMappings=[
+        'shadow'=>[
+            'default'  => '',
+            'none'     => 'shadow-none',
+            'small'    => 'shadow-small',
+            'regular'  => 'shadow',
+            'large'    => 'shadow-lg',
+        ]
+    ];
+
     var $_aElements=[];
     
     /**
@@ -232,6 +242,11 @@ class renderadminlte {
                 'params'=>[
                     'type'        => ['select'=>$this->aPresets['type'],     'example_value'=>'primary'],
                     'size'        => ['select'=>$this->aPresets['size'],     'example_value'=>''],
+                    'class'       => [
+                        'group'=>'styling', 
+                        'description'=>'optional: css classes', 
+                        'example_value'=>''
+                    ],
                     'text'        => [
                         'group'=>'content', 
                         'description'=>'Text/ html code on the button', 
@@ -271,8 +286,8 @@ class renderadminlte {
                 'method'=>'getCard',
         
                 'params'=>[
-                    'type'        => ['select'=>$this->aPresets['type'],     'example_value'=>''],
-                    'variant'     => ['select'=>$this->aPresets['variant'],  'example_value'=>''],
+                    'type'        => ['select'=>$this->aPresets['type'],     'example_value'=>'primary'],
+                    'variant'     => ['select'=>$this->aPresets['variant'],  'example_value'=>'outline'],
                     'class'       => [
                         'group'=>'styling', 
                         'description'=>'optional: css classes', 
@@ -298,7 +313,7 @@ class renderadminlte {
                     'tools'       => [
                         'group'=>'content', 
                         'description'=>'Html code for the top right', 
-                        'example_value'=>'Tools'
+                        'example_value'=>''
                     ],
                     'text'        => [
                         'group'=>'content', 
@@ -691,6 +706,18 @@ class renderadminlte {
 
     // ----------------------------------------------------------------------
 
+    /**
+     * helper: add a css value with prefix
+     * this handles option keys in get[COMPONENT] methods
+     * if a value is set then this function returns a space + prefix (param 2) + value
+     * @param  {string}  $sValue   option value
+     * @param  {string}  $sPrefix  prefix in front of css value
+     * @return {string}
+     */
+    protected function _addClassValue($sValue, $sPrefix=''){
+        return $sValue ? ' '.$sPrefix.$sValue : '';
+    }
+
     /**
      * helper function for get[COMPONENTNAME] methods:
      * ensure that all wanted keys exist in an array. Non existing keys will be added with value false
@@ -753,8 +780,8 @@ class renderadminlte {
 
         $aElement=[
             'class'=>'alert'
-                . ($aOptions['type']        ? ' alert-'.$aOptions['type']  : '')
-                . ($aOptions['dismissible'] ? ' alert-dismissible' : '')
+                . $this->_addClassValue($aOptions['type'], 'alert-')
+                . $this->_addClassValue($aOptions['dismissible'], 'alert-')
                 ,
             'label'=>''
                 . ($aOptions['dismissible'] ? '<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>' : '')
@@ -790,9 +817,9 @@ class renderadminlte {
         $aOptions=$this->_ensureOptions('badge', $aOptions);
         $aElement=[];
         $aElement['class']='badge'
-            . ($aOptions['class']   ? ' badge-'.$aOptions['class'] : '')
-            . ($aOptions['type']    ? ' badge-'.$aOptions['type'] : '')
-            . ($aOptions['bgcolor'] ? ' bg-'.$aOptions['bgcolor']   : '')
+            . $this->_addClassValue($aOptions['class'],   '')
+            . $this->_addClassValue($aOptions['type'],    'badge-')
+            . $this->_addClassValue($aOptions['bgcolor'], 'bg-')
             ;
         if ($aOptions['id']){
             $aElement['id']=$aOptions['id'];
@@ -822,10 +849,10 @@ class renderadminlte {
         $aOptions=$this->_ensureOptions('button', $aOptions);
         $aElement=$aOptions;
         $aElement['class']='btn'
-                .($aOptions['class'] ? ' '.$aOptions['class'] : '')
-                .($aOptions['type'] ? ' btn-'.$aOptions['type'] : '')
-                .($aOptions['size'] ? ' btn-'.$aOptions['size'] : '')
-                ;
+            . $this->_addClassValue($aOptions['type'],    'btn-')
+            . $this->_addClassValue($aOptions['size'],    'btn-')
+            . $this->_addClassValue($aOptions['class'],   '')
+            ;
         $aElement['label']=$aOptions['text'] ? $aOptions['text'] : '&nbsp;';
         foreach(['_infos', 'type', 'size', 'icon', 'text'] as $sDeleteKey){
             unset($aElement[$sDeleteKey]);
@@ -850,9 +877,9 @@ class renderadminlte {
     public function getCallout($aOptions){
         $aOptions=$this->_ensureOptions('callout', $aOptions);
         $sClass='callout'
-                .($aOptions['class'] ? ' '.$aOptions['class'] : '')
-                .($aOptions['type']  ? ' callout-'.$aOptions['type'] : '')
-                ;
+            . $this->_addClassValue($aOptions['type'],    'callout-')
+            . $this->_addClassValue($aOptions['class'],   '')
+            ;
 
         return $this->addWrapper(
             'div', ['class'=>$sClass],
@@ -919,8 +946,8 @@ class renderadminlte {
 
         $sVariantPrefix=$aVariants[$aOptions['variant']] ? $aVariants[$aOptions['variant']] : $aVariants['default'];
         $sClass='card'
-                .($aOptions['class'] ? ' '.$aOptions['class'] : '')
-                .($aOptions['type']  ? ' '.$sVariantPrefix.$aOptions['type'] : '')
+                . $this->_addClassValue($aOptions['type'],    $sVariantPrefix)
+                . $this->_addClassValue($aOptions['class'],   '')
                 ;
 
         // check window state
@@ -973,8 +1000,8 @@ class renderadminlte {
 
         // print_r($aOptions);
         $sClass='info-box'
-                .($aOptions['class'] ? ' '.$aOptions['class'] : '')
-                .($aOptions['type']  ? ' bg-'.$aOptions['type'] : '')
+                . $this->_addClassValue($aOptions['type'],    'bg-')
+                . $this->_addClassValue($aOptions['class'],   '')
                 .($aOptions['shadow'] && isset($this->_aValueMappings['shadow'][$aOptions['shadow']]) 
                     ? ' '.$this->_aValueMappings['shadow'][$aOptions['shadow']] : '')
                 ;
@@ -1033,9 +1060,9 @@ class renderadminlte {
         ];
         // print_r($aOptions);
         $sClass='small-box'
-                .($aOptions['class'] ? ' '.$aOptions['class'] : '')
-                .($aOptions['type']  ? ' bg-'.$aOptions['type'] : '')
-                .($aOptions['shadow'] && isset($aShadows) && $aShadows[$aOptions['shadow']] ? ' '.$aShadows[$aOptions['shadow']] : '')
+                . $this->_addClassValue($aOptions['type'],    'bg-')
+                .($aOptions['shadow'] && isset($this->_aValueMappings['shadow'][$aOptions['shadow']]) 
+                    ? ' '.$this->_aValueMappings['shadow'][$aOptions['shadow']] : '')
                 ;
         
         // build parts
-- 
GitLab