Sorting is now possible
This commit is contained in:
parent
11f9266f10
commit
ab5840babe
@ -22,8 +22,10 @@ class CustomNavElementHandler {
|
|||||||
function getCustomNavElement($id, $heskSettings) {
|
function getCustomNavElement($id, $heskSettings) {
|
||||||
$elements = $this->getAllCustomNavElements($heskSettings);
|
$elements = $this->getAllCustomNavElements($heskSettings);
|
||||||
|
|
||||||
if (isset($elements[$id])) {
|
foreach ($elements as $element) {
|
||||||
return $elements[$id];
|
if ($element->id === intval($id)) {
|
||||||
|
return output($element);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new ApiFriendlyException("Custom nav element {$id} not found!", "Element Not Found", 404);
|
throw new ApiFriendlyException("Custom nav element {$id} not found!", "Element Not Found", 404);
|
||||||
@ -47,15 +49,22 @@ class CustomNavElementHandler {
|
|||||||
|
|
||||||
function sortCustomNavElement($elementId, $direction, $heskSettings) {
|
function sortCustomNavElement($elementId, $direction, $heskSettings) {
|
||||||
/* @var $element CustomNavElement */
|
/* @var $element CustomNavElement */
|
||||||
$element = $this->customNavElementGateway->getAllCustomNavElements($heskSettings)[$elementId];
|
$elements = $this->customNavElementGateway->getAllCustomNavElements($heskSettings);
|
||||||
|
$elementToChange = null;
|
||||||
if ($direction === 'up') {
|
foreach ($elements as $element) {
|
||||||
$element->sort -= 15;
|
if ($element->id === intval($elementId)) {
|
||||||
} else {
|
$elementToChange = $element;
|
||||||
$element->sort += 15;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->customNavElementGateway->saveCustomNavElement($element, $heskSettings);
|
|
||||||
|
if ($direction === Direction::UP) {
|
||||||
|
$elementToChange->sort -= 15;
|
||||||
|
} else {
|
||||||
|
$elementToChange->sort += 15;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->customNavElementGateway->saveCustomNavElement($elementToChange, $heskSettings);
|
||||||
$this->customNavElementGateway->resortAllElements($heskSettings);
|
$this->customNavElementGateway->resortAllElements($heskSettings);
|
||||||
}
|
}
|
||||||
}
|
}
|
9
api/BusinessLogic/Navigation/Direction.php
Normal file
9
api/BusinessLogic/Navigation/Direction.php
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace BusinessLogic\Navigation;
|
||||||
|
|
||||||
|
|
||||||
|
class Direction {
|
||||||
|
const UP = 'up';
|
||||||
|
const DOWN = 'down';
|
||||||
|
}
|
@ -29,7 +29,7 @@ class CustomNavElementController extends InternalApiController {
|
|||||||
/* @var $handler CustomNavElementHandler */
|
/* @var $handler CustomNavElementHandler */
|
||||||
$handler = $applicationContext->get[CustomNavElementHandler::class];
|
$handler = $applicationContext->get[CustomNavElementHandler::class];
|
||||||
|
|
||||||
$handler->sortCustomNavElement($id, $direction, $hesk_settings);
|
$handler->sortCustomNavElement(intval($id), $direction, $hesk_settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
function get($id) {
|
function get($id) {
|
||||||
|
@ -10,7 +10,8 @@ class CustomNavElementGateway extends CommonDao {
|
|||||||
function getAllCustomNavElements($heskSettings) {
|
function getAllCustomNavElements($heskSettings) {
|
||||||
$this->init();
|
$this->init();
|
||||||
|
|
||||||
$columns = '`t1`.`id`, `t1`.`image_url`, `t1`.`font_icon`, `t1`.`place`, `t1`.`url`, `t2`.`language`, `t2`.`text`, `t2`.`subtext`';
|
$columns = '`t1`.`id`, `t1`.`image_url`, `t1`.`font_icon`, `t1`.`place`, `t1`.`url`, `t1`.`sort`,
|
||||||
|
`t2`.`language`, `t2`.`text`, `t2`.`subtext`';
|
||||||
|
|
||||||
$rs = hesk_dbQuery("SELECT {$columns} FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "custom_nav_element` AS `t1`
|
$rs = hesk_dbQuery("SELECT {$columns} FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "custom_nav_element` AS `t1`
|
||||||
INNER JOIN `" . hesk_dbEscape($heskSettings['db_pfix']) . "custom_nav_element_to_text` AS `t2`
|
INNER JOIN `" . hesk_dbEscape($heskSettings['db_pfix']) . "custom_nav_element_to_text` AS `t2`
|
||||||
@ -26,7 +27,7 @@ class CustomNavElementGateway extends CommonDao {
|
|||||||
$id = intval($row['id']);
|
$id = intval($row['id']);
|
||||||
if ($previousId !== $id) {
|
if ($previousId !== $id) {
|
||||||
if ($element !== null) {
|
if ($element !== null) {
|
||||||
$elements[$element->id] = $element;
|
$elements[] = $element;
|
||||||
}
|
}
|
||||||
$element = new CustomNavElement();
|
$element = new CustomNavElement();
|
||||||
$element->id = $id;
|
$element->id = $id;
|
||||||
@ -34,6 +35,7 @@ class CustomNavElementGateway extends CommonDao {
|
|||||||
$element->imageUrl = $row['image_url'];
|
$element->imageUrl = $row['image_url'];
|
||||||
$element->fontIcon = $row['font_icon'];
|
$element->fontIcon = $row['font_icon'];
|
||||||
$element->url = $row['url'];
|
$element->url = $row['url'];
|
||||||
|
$element->sort = $row['sort'];
|
||||||
$element->text = array();
|
$element->text = array();
|
||||||
$element->subtext = array();
|
$element->subtext = array();
|
||||||
}
|
}
|
||||||
@ -105,6 +107,7 @@ class CustomNavElementGateway extends CommonDao {
|
|||||||
SET `image_url` = {$imageUrl},
|
SET `image_url` = {$imageUrl},
|
||||||
`font_icon` = {$fontIcon},
|
`font_icon` = {$fontIcon},
|
||||||
`url` = '" . hesk_dbEscape($element->url) . "',
|
`url` = '" . hesk_dbEscape($element->url) . "',
|
||||||
|
`sort` = " . intval($element->sort) . ",
|
||||||
`place` = " . intval($element->place) .
|
`place` = " . intval($element->place) .
|
||||||
" WHERE `id` = " . intval($element->id));
|
" WHERE `id` = " . intval($element->id));
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ $(document).ready(function() {
|
|||||||
bindEditModal();
|
bindEditModal();
|
||||||
bindCreateModal();
|
bindCreateModal();
|
||||||
bindDeleteButton();
|
bindDeleteButton();
|
||||||
|
bindSortButtons();
|
||||||
|
|
||||||
$('[data-toggle="nav-iconpicker"]').iconpicker({
|
$('[data-toggle="nav-iconpicker"]').iconpicker({
|
||||||
iconset: ['fontawesome', 'octicon'],
|
iconset: ['fontawesome', 'octicon'],
|
||||||
@ -320,3 +321,26 @@ function bindDeleteButton() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function bindSortButtons() {
|
||||||
|
$(document).on('click', '[data-action="sort"]', function() {
|
||||||
|
$('#overlay').show();
|
||||||
|
var heskUrl = $('#heskUrl').text();
|
||||||
|
var direction = $(this).data('direction');
|
||||||
|
var element = elements[$(this).parent().parent().find('[data-property="id"]').text()];
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
method: 'POST',
|
||||||
|
url: heskUrl + '/api/v1-internal/custom-navigation/' + element.id + '/sort/' + direction,
|
||||||
|
headers: { 'X-Internal-Call': true },
|
||||||
|
success: function() {
|
||||||
|
console.log('Resorted');
|
||||||
|
loadTable();
|
||||||
|
},
|
||||||
|
error: function(data) {
|
||||||
|
console.error(data);
|
||||||
|
$('#overlay').hide();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
});
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user