Skip to content

Commit

Permalink
Change on the ordering of cabinets for lists opendcim#528
Browse files Browse the repository at this point in the history
  • Loading branch information
wilpig committed Jan 30, 2015
1 parent 75807fc commit b27210f
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 41 deletions.
5 changes: 3 additions & 2 deletions api/v1/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,8 @@ function authenticate(\Slim\Route $route) {
$app->get( '/cabinet/bydept/:deptid', function($deptid) {
$cab = new Cabinet;
$dc = new DataCenter();
$cList = $cab->ListCabinets(intval($deptid));
$cab->DeptID=$deptid;
$cList = $cab->GetCabinetsByDept();

$response['error'] = false;
$response['errorcode'] = 200;
Expand Down Expand Up @@ -658,4 +659,4 @@ function authenticate(\Slim\Route $route) {
});

$app->run();
?>
?>
86 changes: 47 additions & 39 deletions assets.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,13 +208,15 @@ function GetCabinet(){
}
}

static function ListCabinets($deptid=null) {
static function ListCabinets($orderbydc=null){
global $dbh;

global $config;

$cabinetList=array();

$dept=(!is_null($deptid))?" WHERE AssignedTo=".intval($deptid):'';
$sql="SELECT * FROM fac_Cabinet$dept ORDER BY DataCenterID, Location ASC, LENGTH(Location);";
// if AppendCabDC is set then we will be appending the DC to lists so sort them accordingly
$orderbydc=(!is_null($orderby) || $config->ParameterArray['AppendCabDC']=='enabled')?'DataCenterID, ':'';
$sql="SELECT * FROM fac_Cabinet ORDER BY $orderbydc LocationSortable ASC;";

foreach($dbh->query($sql) as $cabinetRow){
$cabinetList[]=Cabinet::RowToObject($cabinetRow);
Expand All @@ -228,19 +230,45 @@ function ListCabinetsByDC($limit=false,$limitzone=false){

$this->MakeSafe();

$hascoords=($limit)?'AND MapX1!=MapX2 AND MapY1!=MapY2':'';
$limitzone=($limitzone && $this->ZoneID>0)?" AND ZoneID=$this->ZoneID":'';
$cabinetList=$this->ListCabinets(true);
foreach($cabinetList as $i => $cab){
if(
($cab->DataCenterID!=$this->DataCenterID) &&
($limitzone && $this->ZoneID>0 && $cab->ZoneID!=$this->ZoneID) &&
($limit && $cab->MapX1!=$cab->MapX2 && $cab->MapY1!=$cab->MapY2)
)
{unset($cabinetList[$i]);}
}

$sql="SELECT * FROM fac_Cabinet WHERE DataCenterID=$this->DataCenterID $hascoords$limitzone ORDER BY Location ASC, LENGTH(Location);";
return $cabinetList;
}

$cabinetList=array();
foreach($dbh->query($sql) as $cabinetRow){
$cabinetList[]=Cabinet::RowToObject($cabinetRow);
function GetCabinetsByDept(){
global $dbh;

$this->MakeSafe();

$cabinetList=$this->ListCabinets();
foreach($cabinetList as $i => $cab){
if($cab->DeptID!=$this->DeptID){unset($cabinetList[$i]);}
}

return $cabinetList;
}

function GetCabinetsByZone(){
global $dbh;

$this->MakeSafe();

$cabinetList=$this->ListCabinets();
foreach($cabinetList as $i => $cab){
if($cab->ZoneID!=$this->ZoneID){unset($cabinetList[$i]);}
}

return $cabinetList;
}

function CabinetOccupancy($CabinetID){
global $dbh;

Expand Down Expand Up @@ -361,7 +389,7 @@ function GetCabinetsByRow($rear=false){

// Order first by row layout then by natural sort
$sql="SELECT * FROM fac_Cabinet WHERE CabRowID=$cabrow->CabRowID ORDER BY $order
Location ASC, LENGTH(Location);";
LocationSortable ASC;";

$cabinetList=array();
foreach($dbh->query($sql) as $cabinetRow){
Expand All @@ -375,20 +403,6 @@ function GetCabinetsByRow($rear=false){
return $cabinetList;
}

function GetCabinetsByZone(){
global $dbh;

$this->MakeSafe();

$sql="SELECT * FROM fac_Cabinet WHERE ZoneID=$this->ZoneID;";

$cabinetList=array();
foreach($dbh->query($sql) as $cabinetRow){
$cabinetList[]=Cabinet::RowToObject($cabinetRow);
}
return $cabinetList;
}

function GetCabRowSelectList(){
global $dbh;

Expand Down Expand Up @@ -434,9 +448,9 @@ function BuildCabinetTree(){
global $dbh;

$dc=new DataCenter();
$dept=new Department();

$deptList=Department::GetDepartmentListIndexedbyID();
$dcList=$dc->GetDCList();
$cabList=Cabinet::ListCabinets(true);

if(count($dcList) >0){
$tree="<ul class=\"mktree\" id=\"datacenters\">\n";
Expand All @@ -451,18 +465,10 @@ function BuildCabinetTree(){

$tree.="\t<li class=\"$classType\" id=\"dc$dcID\"><a href=\"dc_stats.php?dc=$datacenter->DataCenterID\">$datacenter->Name</a>/\n\t\t<ul>\n";

$sql="SELECT * FROM fac_Cabinet WHERE DataCenterID=\"$dcID\" ORDER BY Location ASC, LENGTH(Location);";

foreach($dbh->query($sql) as $cabRow){
$dept->DeptID = $cabRow["AssignedTo"];

if($dept->DeptID==0){
$dept->Name = "General Use";
}else{
$dept->GetDeptByID();
}
foreach($cabList as $cab){
$deptName=($cab->AssignedTo==0)?"General Use":$deptList[$cab->AssignedTo]->Name;

$tree.="\t\t\t<li id=\"cab{$cabRow['CabinetID']}\"><a href=\"cabnavigator.php?cabinetid={$cabRow['CabinetID']}\">{$cabRow['Location']} [$dept->Name]</a></li>\n";
$tree.="\t\t\t<li id=\"cab$cab->CabinetID\"><a href=\"cabnavigator.php?cabinetid=$cab->CabinetID\">$cab->Location [$deptName]</a></li>\n";
}

$tree.="\t\t</ul>\n </li>\n";
Expand Down Expand Up @@ -542,7 +548,9 @@ function SearchByOwner( $db = null ) {
function SearchByCustomTag( $tag=null ) {
global $dbh;

$sql="SELECT a.* from fac_Cabinet a, fac_CabinetTags b, fac_Tags c WHERE a.CabinetID=b.CabinetID AND b.TagID=c.TagID AND UCASE(c.Name) LIKE UCASE('%".sanitize($tag)."%');";
$sql="SELECT a.* from fac_Cabinet a, fac_CabinetTags b, fac_Tags c WHERE
a.CabinetID=b.CabinetID AND b.TagID=c.TagID AND UCASE(c.Name) LIKE
UCASE('%".sanitize($tag)."%') ORDER BY LocationSortable;";

$cabinetList=array();

Expand Down
6 changes: 6 additions & 0 deletions db-3.3-to-4.0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,9 @@ INSERT INTO fac_Config set Parameter='AppendCabDC', Value='disabled', UnitOfMeas
-- Extend fac_PowerSource table for more load options to match CDUs
--
ALTER TABLE fac_PowerSource ADD OID2 VARCHAR( 80 ) NOT NULL AFTER LoadOID, ADD OID3 VARCHAR( 80 ) NOT NULL AFTER OID2;

--
-- Extend fac_Cabinet table for better sorting
--
ALTER TABLE fac_Cabinet ADD LocationSortable VARCHAR( 20 ) NOT NULL AFTER Location;
UPDATE fac_Cabinet SET LocationSortable = REPLACE(Location, ' ', '');

0 comments on commit b27210f

Please sign in to comment.