dynamic config

This commit is contained in:
2020-06-10 13:54:51 +07:00
parent 9b11d59407
commit d3bf129a2a
6 changed files with 287 additions and 859 deletions

33
widgets/ConfigTree.php Normal file
View File

@@ -0,0 +1,33 @@
<?php
namespace app\widgets;
use yii\base\Widget;
class ConfigTree extends Widget {
public $configLists;
public $isRoot;
public $parent_id;
public $parent_key;
public function init() {
parent::init();
}
public function run() {
$public_root = ['engine', 'recognition', 'open_door'];
$public_cfg = ['engine|cam_id', 'engine|server_authen', 'recognition|server_recog', 'open_door|enable', 'open_door|port_name'];
return $this->render("config-tree", [
"configLists" => $this->configLists,
"isRoot" => $this->isRoot,
"parent_id" => $this->parent_id,
"parent_key" => $this->parent_key,
"public_root" => $public_root,
"public_cfg" => $public_cfg
]);
}
}

View File

@@ -0,0 +1,34 @@
{$username=Yii::$app->user->identity->username}
<ul {if $isRoot}class="tree"{/if}>
{$c=0}
{foreach from=$configLists item=cf key=k}
{$c=$c+1}
{$hidden=false}
{if $username!='admin'}
{if $isRoot}
{if !in_array($k,$public_root)}
{$hidden=true}
{/if}
{else}
{$tree=$parent_key|cat:"|"|cat:$k}
{if !in_array($tree,$public_cfg)}
{$hidden=true}
{/if}
{/if}
{/if}
<li {if $hidden}class='hidden'{/if}>
<input type="checkbox" checked="checked" id="{$parent_id}_{$c}" />
<label class="tree_label" for="{$parent_id}_{$c}">{$k}</label>
{if is_array($cf)}
{if $parent_key===""}
{$parentKey=$k}
{else}
{$parentKey=$parent_key|cat:"|"|cat:$k}
{/if}
{\app\widgets\ConfigTree::widget(['configLists' => $cf,'isRoot'=>false,'parent_id'=>$parent_id|cat:"_"|cat:$c,'parent_key'=>$parentKey])}
{else}
<b>:</b> <div contenteditable="" id="text_{$parent_id}_{$c}" data-parent="{$parent_key}" data-key="{$k}" class="editform">{$cf}</div>
{/if}
</li>
{/foreach}
</ul>