summaryrefslogtreecommitdiffstats
path: root/modules-available/roomplanner
diff options
context:
space:
mode:
authorSimon Rettberg2017-12-01 13:25:39 +0100
committerSimon Rettberg2017-12-01 13:25:39 +0100
commitd11ebcb652fb76391928bbbc0c338d4a5737e3a9 (patch)
tree404420d63e8c0162aac9773e10a761d4aca545ab /modules-available/roomplanner
parent[roomplanner] Fallback to ip if hostname is empty (diff)
downloadslx-admin-d11ebcb652fb76391928bbbc0c338d4a5737e3a9.tar.gz
slx-admin-d11ebcb652fb76391928bbbc0c338d4a5737e3a9.tar.xz
slx-admin-d11ebcb652fb76391928bbbc0c338d4a5737e3a9.zip
[roomplanner] Sort already placed machines to the bottom
Diffstat (limited to 'modules-available/roomplanner')
-rw-r--r--modules-available/roomplanner/clientscript.js40
-rw-r--r--modules-available/roomplanner/js/grid.js9
-rw-r--r--modules-available/roomplanner/page.inc.php4
3 files changed, 36 insertions, 17 deletions
diff --git a/modules-available/roomplanner/clientscript.js b/modules-available/roomplanner/clientscript.js
index 1cd65132..722e3909 100644
--- a/modules-available/roomplanner/clientscript.js
+++ b/modules-available/roomplanner/clientscript.js
@@ -11,10 +11,16 @@ var selectMachinInitialized = false;
var placedMachines = [];
+function makeCombinedFieldSingle(item)
+{
+ item.combined = (item.machineuuid + " " + item.hostname + " " + item.clientip + " " + item.macaddr + " " + item.macaddr.replace(/-/g, ':')).toLocaleLowerCase();
+ item.sortField = (item.fixedlocationid === null ? 'a' : 'z') + item.hostname;
+}
+
function makeCombinedField(machineArray)
{
machineArray.forEach(function (v,i,a){
- machineArray[i].combined = (v.machineuuid + " " + v.hostname + " " + v.clientip + " " + v.macaddr + " " + v.macaddr.replace(/-/g, ':')).toLocaleLowerCase();
+ makeCombinedFieldSingle(machineArray[i]);
});
return machineArray;
}
@@ -25,15 +31,14 @@ function renderMachineEntry(item, escape) {
// console.log('used uuids is ');
// console.log(placedMachines);
- var isUsed = $.inArray(item.machineuuid, placedMachines) > -1;
var extraClass = '';
var extraText = '';
- if (isUsed) {
- extraText = ' (already placed)';
- extraClass = 'used';
- } else if (item.otherroom) {
+ if (item.otherroom) {
extraText = ' (in ' + item.otherroom + ')';
extraClass = 'used';
+ } else if (item.fixedlocationid !== null) {
+ extraText = ' (already placed)';
+ extraClass = 'used';
}
return '<div class="machine-entry ' + extraClass +'">'
//+ ' <div class="machine-logo"><i class="glyphicon glyphicon-hdd"></i></div>'
@@ -120,7 +125,7 @@ function initSelectize() {
render : { option : renderMachineEntry, item: renderMachineSelected},
load: loadMachines,
maxItems: 1,
- sortField: 'hostname',
+ sortField: 'sortField',
sortDirection: 'asc',
onChange: clearSubnetBox
});
@@ -136,7 +141,7 @@ function initSelectize() {
create: false,
render : { option : renderMachineEntry, item: renderMachineSelected},
maxItems: 1,
- sortField: 'hostname',
+ sortField: 'sortField',
sortDirection: 'asc',
onChange: clearSearchBox
});
@@ -148,13 +153,16 @@ function initSelectize() {
}
function onBtnSelect() {
/* check which one has a value */
- console.assert($selectizeSubnet.length == 1);
- console.assert($selectizeSearch.length == 1);
+ console.assert($selectizeSubnet.length === 1);
+ console.assert($selectizeSearch.length === 1);
var bySubnet = machineCache[$selectizeSubnet[0].selectize.getValue()];
var bySearch = machineCache[$selectizeSearch[0].selectize.getValue()];
- var value = (bySubnet === undefined || bySubnet == "") ? bySearch : bySubnet;
+ var value = !bySubnet ? bySearch : bySubnet;
+ value.fixedlocationid = -1;
+ makeCombinedFieldSingle(value);
+
var result = {muuid: value.machineuuid, ip: value.clientip, mac_address : value.macaddr, hostname: value.hostname};
currentCallback(result);
@@ -165,6 +173,14 @@ function onBtnSelect() {
clearSearchBox();
}
+function onPcDelete(muuid) {
+ var bySubnet = machineCache[muuid];
+ var bySearch = machineCache[muuid];
+ var value = !bySubnet ? bySearch : bySubnet;
+ value.fixedlocationid = null;
+ makeCombinedFieldSingle(value);
+}
+
/* to be called from berryous' code */
function selectMachine(usedUuids, callback) {
initSelectize();
@@ -172,7 +188,7 @@ function selectMachine(usedUuids, callback) {
placedMachines = usedUuids;
$modal.modal('show');
$modal.one('hidden.bs.modal', function () {
- if (currentCallback != null) {
+ if (currentCallback) {
currentCallback(false);
}
});
diff --git a/modules-available/roomplanner/js/grid.js b/modules-available/roomplanner/js/grid.js
index 334057bf..466e42aa 100644
--- a/modules-available/roomplanner/js/grid.js
+++ b/modules-available/roomplanner/js/grid.js
@@ -74,10 +74,13 @@ if (!roomplanner) var roomplanner = {
initDelete: function(el) {
$(el).append('<div class="deleteHandle glyphicon glyphicon-remove-sign"></div>');
$(el).find('.deleteHandle').click(function() {
- if ($(this).parent().attr('itemtype') == "pc") {
+ if ($(this).parent().attr('itemtype') === "pc") {
var self = this;
BootstrapDialog.confirm(__('are you sure'),function(result) {
if (result) {
+ if (onPcDelete) {
+ onPcDelete($(self).parent().attr('muuid'));
+ }
$(self).parent().remove();
}
});
@@ -169,8 +172,8 @@ if (!roomplanner) var roomplanner = {
var mw = $(this).resizable("option","maxWidth");
var mh = $(this).resizable("option","maxHeight");
- var hLimit = ($(this).attr('scalable') == 'v');
- var vLimit = ($(this).attr('scalable') == 'h');
+ var hLimit = ($(this).attr('scalable') === 'v');
+ var vLimit = ($(this).attr('scalable') === 'h');
if(collides.length) {
$(collides).each(function(idx,item) {
diff --git a/modules-available/roomplanner/page.inc.php b/modules-available/roomplanner/page.inc.php
index b44d945d..bae9db7b 100644
--- a/modules-available/roomplanner/page.inc.php
+++ b/modules-available/roomplanner/page.inc.php
@@ -100,7 +100,7 @@ class Page_Roomplanner extends Page
$query = Request::get('query', false, 'string');
$aquery = preg_replace('/[^\x01-\x7f]+/', '%', $query);
- $result = Database::simpleQuery('SELECT machineuuid, macaddr, clientip, hostname '
+ $result = Database::simpleQuery('SELECT machineuuid, macaddr, clientip, hostname, fixedlocationid '
. 'FROM machine '
. 'WHERE machineuuid LIKE :aquery '
. ' OR macaddr LIKE :aquery '
@@ -289,7 +289,7 @@ class Page_Roomplanner extends Page
protected function getPotentialMachines()
{
- $result = Database::simpleQuery('SELECT m.machineuuid, m.macaddr, m.clientip, m.hostname, l.locationname AS otherroom
+ $result = Database::simpleQuery('SELECT m.machineuuid, m.macaddr, m.clientip, m.hostname, l.locationname AS otherroom, m.fixedlocationid
FROM machine m
LEFT JOIN location l ON (m.fixedlocationid = l.locationid AND m.subnetlocationid <> m.fixedlocationid)
WHERE subnetlocationid = :locationid', ['locationid' => $this->locationid]);