Skip to content

Commit

Permalink
refactor(policy): render with twig
Browse files Browse the repository at this point in the history
add twig in method showValueInput policybase
add twig in method showValueInput policyboolean
add twig in method showValueInput policydeployapp
add twig in method showValueInput policydeployfile
add twig in method showValueInput policydropdown
maquetation in render template

Signed-off-by: Luis F. Gonzalez <[email protected]>
  • Loading branch information
ingluife authored and ajsb85 committed Jul 9, 2018
1 parent 95045c3 commit 88d7a0c
Show file tree
Hide file tree
Showing 9 changed files with 156 additions and 50 deletions.
27 changes: 27 additions & 0 deletions css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,31 @@ ul#menu ul.ssmenu {
.ui-slider .ui-widget-header {
background: #FEC95C;
cursor: pointer;
}

/*---------------- POLICY VALUE ----------------*/
.plugin_flyvemdm_policy_value{
display: inline-block;
width: 100%;
max-width: 100%;
overflow-y: auto;
}

.plugin_flyvemdm_policy_value table{
width: 100%
}
.plugin_flyvemdm_policy_value table > tbody > tr > td span.no-wrap a{
margin-right: .5em;
}
.plugin_flyvemdm_policy_value table > tbody > tr > td span.no-wrap{
margin-right: 3em;
}
.plugin_flyvemdm_policy_value table .select2-container{
width: 90%
}
.plugin_flyvemdm_policy_value table > tbody > tr > td span.no-wrap span.fa {
padding: 0;
}
.plugin_flyvemdm_policy_value table .select2-container .select2-choice {
max-width: none;
}
7 changes: 5 additions & 2 deletions inc/policybase.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,12 @@ public function post_unapply($value, $itemtype, $itemId, PluginFlyvemdmNotifiabl
* @return string
*/
public function showValueInput($value = '', $itemType = '', $itemId = 0) {
$html = '<input name="value" value="' . $value . '" >';

return $html;
$data['itemtype'] = $itemType;
$data['value'] = $value;
$data['typeTmpl'] = PluginFlyvemdmPolicyBase::class;
$twig = plugin_flyvemdm_getTemplateEngine();
return $twig->render('policy_value.html.twig', ['data' => $data]);
}

/**
Expand Down
8 changes: 7 additions & 1 deletion inc/policyboolean.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,13 @@ public function getMqttMessage($value, $itemtype, $itemId) {
* @return int|string
*/
public function showValueInput($value = '', $itemType = '', $itemId = 0) {
return Dropdown::showYesNo('value', $value, -1, ['display' => false]);
$data['itemtype'] = $itemType;
$data['typeTmpl'] = PluginFlyvemdmPolicyBoolean::class;
$data['dropdown'] = [
Dropdown::showYesNo('value', $value, -1, ['display' => false])
];
$twig = plugin_flyvemdm_getTemplateEngine();
return $twig->render('policy_value.html.twig', ['data' => $data]);
}

/**
Expand Down
28 changes: 11 additions & 17 deletions inc/policydeployapplication.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,26 +235,20 @@ public function showValueInput($value = '', $itemType = '', $itemId = 0) {
$removeOnDelete = $value['remove_on_delete'];
}

$packageDropdown = PluginFlyvemdmPackage::dropdown([
'display' => false,
'displaywith' => ['alias'],
'name' => 'items_id',
'value' => $itemId,
]);

$removeDropdown = Dropdown::showYesNo('value[remove_on_delete]', $removeOnDelete,
-1, ['display' => false]);

$data = [
'package' => [
'dropdown' => $packageDropdown,
'itemtype' => $itemtype
],
'remove' => $removeDropdown
$data['typeTmpl'] = $itemtype;
$data['itemtype'] = $itemtype;
$data['dropdown'] = [
PluginFlyvemdmPackage::dropdown([
'display' => false,
'displaywith' => ['alias'],
'name' => 'items_id',
'value' => $itemId,
]),
Dropdown::showYesNo('value[remove_on_delete]', $removeOnDelete, -1, ['display' => false])
];

$twig = plugin_flyvemdm_getTemplateEngine();
return $twig->render('policy_deploy_app_form.html.twig', $data);
return $twig->render('policy_value.html.twig', ['data' => $data]);
}

/**
Expand Down
43 changes: 16 additions & 27 deletions inc/policydeployfile.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -279,37 +279,26 @@ public function showValueInput($value = '', $itemType = '', $itemId = 0) {
$destination = substr($value['destination'], $cut);
$destination_base = substr($value['destination'], 0, $cut);
}
$filesDropdown = PluginFlyvemdmFile::dropdown([
'display' => false,
'name' => 'items_id',
'value' => $itemId,
]);

//Copy to
$path = new PluginFlyvemdmWellknownpath();
$path->getFromDBByPath($destination_base);

$knownPathDropdown = PluginFlyvemdmWellknownpath::dropdown([
'display' => false,
'name' => 'destination_base',
'value' => $path->getID(),
]);

$removeDropdown = Dropdown::showYesNo('value[remove_on_delete]', $removeOnDelete,
-1, ['display' => false]);

$data = [
'files' => [
'dropdown' => $filesDropdown,
'itemtype' => $itemtype,
'knownPath' => $knownPathDropdown,
'destination' => $destination,
],
'remove' => $removeDropdown,
$data['destination'] = $destination;
$data['typeTmpl'] = $itemtype;
$data['itemtype'] = $itemtype;
$data['dropdown'] = [
PluginFlyvemdmFile::dropdown([
'display' => false,
'name' => 'items_id',
'value' => $itemId,
]),
PluginFlyvemdmWellknownpath::dropdown([
'display' => false,
'name' => 'destination_base',
'value' => $path->getID(),
]),
Dropdown::showYesNo('value[remove_on_delete]', $removeOnDelete, -1, ['display' => false])
];

$twig = plugin_flyvemdm_getTemplateEngine();
return $twig->render('policy_deploy_file_form.html.twig', $data);
return $twig->render('policy_value.html.twig', ['data' => $data]);
}

/**
Expand Down
8 changes: 7 additions & 1 deletion inc/policydropdown.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,13 @@ public function translateData() {
* @return int|string
*/
public function showValueInput($value = '', $itemType = '', $itemId = 0) {
return Dropdown::showFromArray('value', $this->valueList, ['display' => false, 'value' => $value]);
$data['itemtype'] = $itemType;
$data['typeTmpl'] = PluginFlyvemdmPolicyDropdown::class;
$data['dropdown'] = [
Dropdown::showFromArray('value', $this->valueList, ['display' => false, 'value' => $value])
];
$twig = plugin_flyvemdm_getTemplateEngine();
return $twig->render('policy_value.html.twig', ['data' => $data]);
}

/**
Expand Down
6 changes: 5 additions & 1 deletion tests/suite-unit/PluginFlyvemdmPolicyBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,11 @@ public function testPre_unapply() {
*/
public function testShowValueInput() {
list($policy) = $this->createNewPolicyInstance();
$this->string($policy->showValueInput())->isEqualTo('<input name="value" value="" >');
$data['itemtype'] = '';
$data['value'] = '';
$data['typeTmpl'] = \PluginFlyvemdmPolicyBase::class;
$twig = plugin_flyvemdm_getTemplateEngine();
$this->string($policy->showValueInput())->isEqualTo($twig->render('policy_value.html.twig', ['data' => $data]));
}

/**
Expand Down
4 changes: 3 additions & 1 deletion tpl/fleet_policy.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@
});
function editPolicy(policyId, taskId) {
$('#policy_editor').dialog('open');
var editorId = "#policy_editor";
$(editorId).dialog('option', 'position', 'center');
$.ajax({
url: '../ajax/policyValue.php',
method: 'POST',
Expand All @@ -94,6 +95,7 @@
},
success: function (response) {
$('#policy_editor_form').html(response);
$(editorId).dialog('open');
}
});
}
Expand Down
75 changes: 75 additions & 0 deletions tpl/policy_value.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<script type="text/javascript">
var editorId = "#policy_editor";
</script>
{% if data.typeTmpl is same as("PluginFlyvemdmFile") %}
<!-- Template Deploy file -->
<div class="plugin_flyvemdm_policy_value">
<table>
<tbody>
<tr>
<td>
{{ data.dropdown[0]|raw }}
</td>
<td>
{{ __('copy to', 'flyvemdm') }}
</td>
<td>
{{ data.dropdown[1]|raw }}
</td>
<td>
<input type="text" name="value[destination]" value="{{ data.destination }}">
</td>
<td>
{{ __('Remove when the policy is removed', 'flyvemdm') }}
</td>
<td>
{{ data.dropdown[2]|raw }}
<input type="hidden" name="itemtype" value="{{ data.itemtype }}">
</td>
</tr>
</tbody>
</table>
</div>
<script type="text/javascript">
$(document).find(editorId).dialog("option", "width", 1000);
</script>
{% elseif data.typeTmpl is same as("PluginFlyvemdmPackage") %}
<!-- Template Package -->
<div class="plugin_flyvemdm_policy_value">
<table>
<tbody>
<tr>
<td>
{{ data.dropdown[0]|raw }}
</td>
<td style="text-align: center;">
{{ __('copy to', 'flyvemdm') }}
</td>
<td>
{{ data.dropdown[1]|raw }}
<input type="hidden" name="itemtype" value="{{ data.itemtype }}">
</td>
</tr>
</tbody>
</table>
</div>
<script type="text/javascript">
$(document).find(editorId).dialog("option", "width", 500);
</script>
{% elseif data.typeTmpl is same as("PluginFlyvemdmPolicyBoolean") or data.typeTmpl is same as("PluginFlyvemdmPolicyDropdown") %}
<!-- Template Boolean || Dropdown -->
<div class="plugin_flyvemdm_policy_value">
{{ data.dropdown[0]|raw }}
</div>
<script type="text/javascript">
$(document).find(editorId).dialog("option", "width", 200);
</script>
{% elseif data.typeTmpl is same as("PluginFlyvemdmPolicyBase") %}
<!-- Template Base -->
<div class="plugin_flyvemdm_policy_value">
<input name="value" value="{{ data.value }}" >
</div>
<script type="text/javascript">
$(document).find(editorId).dialog("option", "width", 200);
</script>
{% endif %}

0 comments on commit 88d7a0c

Please sign in to comment.