Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix260b #262

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
composer.lock
vendor

4 changes: 2 additions & 2 deletions CHANGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Change Log: `yii2-tree-manager`
## Version 1.1.3

**Date:** _under development_

- (enh #260): Separate User Mode and Admin Mode Views
- (bug #259): Correct icons list display based on `iconEditSettings['show']`.
- (enh #258): Enhanced BS4 custom checkbox and radio styling for toggle inputs.
- (enh #257): Enhance search close icon styling.
Expand Down Expand Up @@ -211,4 +211,4 @@ Change Log: `yii2-tree-manager`
- (enh #4): Error trapping enhancements to `Tree::activateNode` and `Tree::removeNode`
- (enh #3): Set dependencies for Asset Bundles.
- (bug #2): Empty node validation on tree init.
- Initial release
- Initial release
8 changes: 8 additions & 0 deletions src/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ class Module extends \kartik\base\Module
* Save node action
*/
const NODE_SAVE = 'save';
/**
* Flip node action
*/
const NODE_FLIP = 'flip';

/**
* Tree details form view - Section Part 1
*/
Expand Down Expand Up @@ -80,6 +85,8 @@ class Module extends \kartik\base\Module
*/
public $treeViewSettings = [
'nodeView' => '@kvtree/views/_form',
'nodeUser' => '@kvtree/views/_user',
'modeView' => 0,
'nodeAddlViews' => [
self::VIEW_PART_1 => '',
self::VIEW_PART_2 => '',
Expand Down Expand Up @@ -129,6 +136,7 @@ public function init()
self::NODE_SAVE => Url::to(['/treemanager/node/save']),
self::NODE_REMOVE => Url::to(['/treemanager/node/remove']),
self::NODE_MOVE => Url::to(['/treemanager/node/move']),
self::NODE_FLIP => Url::to(['/treemanager/node/flip']),
];
$this->treeViewSettings['nodeActions'] = $nodeActions;
}
Expand Down
8 changes: 7 additions & 1 deletion src/TreeSecurity.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
use yii\helpers\Json;
use yii\helpers\VarDumper;
use yii\console\Application;

/**
Expand All @@ -41,7 +42,9 @@ public static function parseManageData($data = [])
'defaultBtnCss' => '',
'formAction' => '',
'currUrl' => '',
'nodeView' => '',
'nodeView' => '@kvtree/views/_form',
'nodeUser' => '@kvtree/views/_user',
'modeView' => 0,
'nodeSelected' => '',
'nodeTitle' => $nodeTitles['node'],
'nodeTitlePlural' => $nodeTitles['nodes'],
Expand All @@ -61,6 +64,9 @@ public static function parseManageData($data = [])
'iconsList' => [],
'breadcrumbs' => [],
];

// yii::debug( 'data: ' . VarDumper::dumpAsString($data));

$out = static::getParsedData($defaults, $data, function ($type, $key, $value) {
if ($type === 'array' && $key === 'iconsList' && is_array($value)) {
$new = [];
Expand Down
62 changes: 58 additions & 4 deletions src/TreeView.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ class TreeView extends Widget
* Create tree node button
*/
const BTN_CREATE = 'create';
/**
* Flip View Mode button
*/
const BTN_FLIPVIEW = 'flipview';
/**
* Remove tree node button
*/
Expand Down Expand Up @@ -136,6 +140,16 @@ class TreeView extends Widget
*/
public $nodeView;

/**
* @var string the view file that will render the form for displaying the node data.
*/
public $nodeUser;

/**
* @var int The view mode when in isAdmin mode. 0=admin, 1=user.
*/
public $modeView = 0;

/**
* @var array the markup for the submit and reset button labels in the node view form
*/
Expand Down Expand Up @@ -921,11 +935,19 @@ public function initOptions()
'options' => ['title' => Yii::t('kvtree', 'Refresh')],
'url' => Yii::$app->request->url,
],
self::BTN_FLIPVIEW => [
'icon' => 'user',
'options' => ['title' => 'Flip View'],
],

];

$this->toolbar = array_replace_recursive($defaultToolbar, $this->toolbar);

if (!$this->allowNewRoots) {
unset($this->toolbar[self::BTN_CREATE_ROOT]);
}
unset($this->toolbar[self::BTN_CREATE_ROOT]);
}

$this->sortToolbar();
$this->_nodeIconsList = $this->getIconsList();
}
Expand Down Expand Up @@ -978,6 +1000,8 @@ public function renderWrapper()
*/
public function renderToolbar()
{
if (!$this->isAdmin ) return;

$out = Html::beginTag('div', $this->toolbarOptions) . "\n" .
Html::beginTag('div', $this->buttonGroupOptions);
foreach ($this->toolbar as $btn => $settings) {
Expand Down Expand Up @@ -1049,6 +1073,7 @@ public function renderHeader()
*/
public function renderFooter()
{
if (!$this->isAdmin ) return ("");
return Html::tag('div', $this->footerTemplate, $this->footerOptions);
}

Expand Down Expand Up @@ -1217,6 +1242,9 @@ public function renderDetail()
$node->$iconTypeAttribute = ArrayHelper::getValue($this->iconEditSettings, 'type', self::ICON_CSS);
}
$url = Yii::$app->request->url;

$this->initViewMode();

$manageData = TreeSecurity::parseManageData([
'formOptions' => $this->nodeFormOptions,
'hideCssClass' => $this->hideCssClass,
Expand All @@ -1232,6 +1260,8 @@ public function renderDetail()
'showIDAttribute' => $this->showIDAttribute,
'showNameAttribute' => $this->showNameAttribute,
'nodeView' => $this->nodeView,
'nodeUser' => $this->nodeUser,
'modeView' => $this->modeView,
'nodeAddlViews' => $this->nodeAddlViews,
'nodeViewButtonLabels' => $this->nodeViewButtonLabels,
'nodeViewParams' => serialize($this->nodeViewParams),
Expand All @@ -1252,11 +1282,18 @@ public function renderDetail()
]);
$params = $this->_module->treeStructure + $this->_module->dataStructure + [
'node' => $node,
'modeView' => $this->modeView,
'treeManageHash' => $manageData['newHash'],
'treeRemoveHash' => $removeData['newHash'],
'treeMoveHash' => $moveData['newHash'],
] + $manageData['out'] + $this->nodeViewParams;
$content = $this->render($this->nodeView, ['params' => $params]);

$view = $this->nodeUser;
if ($this->isAdmin and $this->modeView ) {
$view =$this->nodeView;
}

$content = $this->render($view,['params' => $params]);
return Html::tag('div', $content, $this->detailOptions);
}

Expand Down Expand Up @@ -1298,6 +1335,7 @@ public function registerAssets()
'showIDAttribute' => $this->showIDAttribute,
'showNameAttribute' => $this->showNameAttribute,
'nodeView' => $this->nodeView,
'nodeUser' => $this->nodeUser,
'nodeAddlViews' => $this->nodeAddlViews,
'nodeViewParams' => serialize($this->nodeViewParams),
'nodeViewButtonLabels' => $this->nodeViewButtonLabels,
Expand Down Expand Up @@ -1339,7 +1377,7 @@ protected function initTreeView()
if (empty($this->emptyNodeMsg)) {
$this->emptyNodeMsg = Yii::t(
'kvtree',
'No valid {nodes} are available for display. Use toolbar buttons to add {nodes}.',
'No valid {nodes} are available for display.',
['node' => $this->nodeTitle, 'nodes' => $this->nodeTitlePlural]
);
}
Expand Down Expand Up @@ -1383,6 +1421,22 @@ protected function initSelectedNode()
$session->set($id, null);
}

/**
* Initializes the view mode
*
* @return void
*/
protected function initViewMode()
{
if (Yii::$app->has('session')) {
$session = Yii::$app->session;
yii::debug( 'modeView = ' . $this->modeView . ' isAdmin = ' . $this->isAdmin );
$this->modeView = $session->get('modeView', $this->isAdmin );
yii::debug( 'modeView = ' . $this->modeView . ' isAdmin = ' . $this->isAdmin );
}
// $session->set('modeView', 0);
}

/**
* Validation of source query data
*
Expand Down
Loading