242 lines
10 KiB
PHP
242 lines
10 KiB
PHP
<?php
|
|
|
|
class PoprackController extends mfBaseController
|
|
{
|
|
protected function apiAction()
|
|
{
|
|
$do = $this->request->do;
|
|
|
|
$data = [];
|
|
|
|
switch ($do) {
|
|
case "addRack":
|
|
$return = $this->addRack();
|
|
break;
|
|
case "editRack":
|
|
$return = $this->editRack();
|
|
break;
|
|
case "removeRack":
|
|
$return = $this->removeRack();
|
|
break;
|
|
case "sortRack":
|
|
$return = $this->sortRack();
|
|
break;
|
|
case "generateRack":
|
|
$rack_id = $this->request->id;
|
|
$side = $this->request->side ?? 'front';
|
|
$rackDataArray = PoprackModel::getAllbyRack($rack_id);
|
|
$rackData = $rackDataArray[0] ?? null;
|
|
if ($rackData) {
|
|
$modules_to_render = $rackData['modules'][$side] ?? [];
|
|
$rack_he = $rackData['rack']['he'];
|
|
$plugs[1] = "LC/APC";
|
|
$plugs[2] = "SC/APC";
|
|
$plugs[3] = "E2000/APC";
|
|
include(dirname(__FILE__) . "/../../Layout/default/Pop/_rack_body.php");
|
|
}
|
|
exit;
|
|
default:
|
|
$return = false;
|
|
}
|
|
|
|
if (!is_array($return) || !count($return)) {
|
|
$data = ["status" => "error"];
|
|
$this->returnJson($data);
|
|
}
|
|
$data['status'] = "OK";
|
|
$data['result'] = $return;
|
|
$this->returnJson($data);
|
|
}
|
|
|
|
private function addRack()
|
|
{
|
|
$r = $this->request;
|
|
$pop_id = $r->pop_id;
|
|
$data = [];
|
|
$data['name'] = trim($r->name);
|
|
$data['he'] = trim($r->he);
|
|
$data['pop_id'] = trim($pop_id);
|
|
$poprack = PoprackModel::create($data);
|
|
|
|
$new_id = $poprack->save();
|
|
// var_dump($r);die();
|
|
if (!$new_id) {
|
|
$response['success'] = false;
|
|
} else {
|
|
$response['success'] = true;
|
|
}
|
|
echo json_encode($response);
|
|
exit;
|
|
}
|
|
|
|
private function editRack()
|
|
{
|
|
$r = $this->request;
|
|
$id = $r->poprack_id;
|
|
$poprack = new Poprack($id);
|
|
$response['success'] = false;
|
|
if ($poprack->id) {
|
|
$data = [];
|
|
$data['name'] = $r->name;
|
|
$data['he'] = $r->he;
|
|
$poprack->update($data);
|
|
if ($poprack->save()) {
|
|
$response['success'] = true;
|
|
}
|
|
}
|
|
echo json_encode($response);
|
|
exit;
|
|
}
|
|
|
|
private function sortRack()
|
|
{
|
|
$r = $this->request;
|
|
$racksortids = $r->racksortids;
|
|
// var_dump($racksortids);
|
|
// die();
|
|
|
|
foreach ($racksortids as $sort => $id) {
|
|
$poprack = new Poprack($id);
|
|
$response['success'] = false;
|
|
if ($poprack->id) {
|
|
$data = [];
|
|
$data['sort'] = $sort;
|
|
$poprack->update($data);
|
|
if ($poprack->save()) {
|
|
$response['success'] = true;
|
|
}
|
|
}
|
|
}
|
|
echo json_encode($response);
|
|
exit;
|
|
}
|
|
|
|
|
|
private function removeRack()
|
|
{
|
|
$id = $this->request->id;
|
|
$poprack = new Poprack($id);
|
|
if (!$poprack->id || $poprack->id != $id) {
|
|
$response['success'] = false;
|
|
} else {
|
|
$poprack->delete();
|
|
$response['success'] = true;
|
|
}
|
|
echo json_encode($response);
|
|
exit;
|
|
|
|
}
|
|
|
|
private function generateRack()
|
|
{
|
|
$id = $this->request->id;
|
|
$side=$this->request->side;
|
|
$cellwidth = 227;
|
|
$blocktd = 0;
|
|
$poprack = PoprackModel::getAllbyRack($id);
|
|
$plugs[1] = "LC";
|
|
$plugs[2] = "SC";
|
|
$plugs[3] = "E2000";
|
|
for ($i = 1; $i <= $poprack[0]['rack']['he']; $i++) :
|
|
echo '<tr>
|
|
<td class="border-right w-15 p-0 pl-1 pr-1 border-bottom font-13 rack-he user-select-none"
|
|
data-toggle="modal" data-target="#rackModuleModal"
|
|
style="cursor: pointer" data-he="' . $i . '">He' . $i . '</td>';
|
|
foreach ($poprack[0][$side]['modules'] as $module) {
|
|
|
|
if ($module['start_he'] == $i) {
|
|
$modulestart = 1;
|
|
|
|
$modulelenght = $module['end_he'] - $module['start_he'] + 1;
|
|
$position = 1;
|
|
$slotcounter = 0;
|
|
$calcwidth = 0;
|
|
$extText = "";
|
|
$extTextspan="";
|
|
foreach ($module['slots'] as $slots) {
|
|
$extText = "";
|
|
$title=$slots['modulname'];
|
|
if ($slots['type'] == '0') {
|
|
$color = '#9fff6e';
|
|
$colorclass = "rack-color-lwl";
|
|
if ($slots['plug']) {
|
|
|
|
$extText = " (" . $plugs[$slots['plug']] . "/" . $slots['ports'] . "P)";
|
|
$extTextspan = "<span style='font-size: 12px;font-weight: 400'>".$extText."</span>";
|
|
}
|
|
} else if ($slots['type'] == '1') {
|
|
$slots['modulname']='<a style="color: #000000;text-decoration: underline;" target="_self" href="'.self::getUrl("Device", "detail", ["id" => $slots['device_id']]).'">'.$slots['modulname'].'</a>';
|
|
$color = '#b6c6ff';
|
|
$colorclass = "rack-color-device";
|
|
} else if ($slots['type'] == '2') {
|
|
|
|
$color = '#ff8100';
|
|
$colorclass = "rack-color-rpanel";
|
|
} else if ($slots['type'] == '3') {
|
|
$color = '#ffad59';
|
|
$colorclass = "rack-color-infra";
|
|
} else if ($slots['type'] == '4') {
|
|
$color = '#96f3de';
|
|
$colorclass = "rack-color-panel";
|
|
} else if ($slots['type'] == '5') {
|
|
$color = '#96f3de';
|
|
$colorclass = "rack-color-blocked";
|
|
}
|
|
if ($slots['width'] == "12") {
|
|
$width = "85%";
|
|
$maxwidth = $cellwidth;
|
|
} else if ($slots['width'] == "6") {
|
|
$width = "42%";
|
|
$maxwidth = intval($cellwidth / 2);
|
|
} else if ($slots['width'] == "4") {
|
|
$width = "28%";
|
|
$maxwidth = intval($cellwidth / 3);
|
|
} else if ($slots['width'] == "3") {
|
|
$width = "21%";
|
|
$maxwidth = intval($cellwidth / 4);
|
|
}
|
|
if ($slots['width'] < 12 && $position != $slots['position']) {
|
|
echo '<td colspan="' . $slots['width'] . '" style="width: ' . $width . ';" class="text-center border-top border-bottom border-right pl-1 pr-1" rowspan="' . $modulelenght . '">frei</td>';
|
|
$position++;
|
|
$calcwidth = $calcwidth + $slots['width'];
|
|
|
|
}
|
|
if ($slots['width'] < 12 && $position != $slots['position']) {
|
|
echo '<td colspan="' . $slots['width'] . '" style="width: ' . $width . ';" class="text-center border-top border-bottom border-right pl-1 pr-1" rowspan="' . $modulelenght . '">frei</td>';
|
|
$position++;
|
|
$calcwidth = $calcwidth + $slots['width'];
|
|
}
|
|
if ($slots['width'] < 12 && $position != $slots['position']) {
|
|
echo '<td colspan="' . $slots['width'] . '" style="width: ' . $width . ';" class="text-center border-top border-bottom border-right pl-1 pr-1" rowspan="' . $modulelenght . '">frei</td>';
|
|
$position++;
|
|
$calcwidth = $calcwidth + $slots['width'];
|
|
}
|
|
echo '<td title="' . $title . $extText . '" colspan="' . $slots['width'] . '" class="text-center border-top border-bottom border-right pl-1 pr-1 ' . $colorclass . '" data-id="' . $slots['moduleid'] . '" data-type="' . $slots['type'] . '" data-name="' . $title . '" data-starthe="' . $module['start_he'] . '" data-ports="' . $slots['ports'] . '" data-plug="' . $slots['plug'] . '" rowspan="' . $modulelenght . '" style="width: ' . $width . '; background-color: ' . $color . ';border-color: #797979 !important;max-width: ' . $maxwidth . 'px;"><span></span> ' . $slots['modulname'] . $extTextspan . '</td>';
|
|
$position++;
|
|
$calcwidth = $calcwidth + $slots['width'];
|
|
}
|
|
if ($calcwidth != 12) {
|
|
echo '<td colspan="' . $slots['width'] . '" style="width: ' . $width . ';" class="text-center border-top border-bottom border-right pl-1 pr-1" rowspan="' . $modulelenght . '">frei</td>';
|
|
$calcwidth = $calcwidth + $slots['width'];
|
|
}
|
|
if ($calcwidth != 12) {
|
|
echo '<td colspan="' . $slots['width'] . '" style="width: ' . $width . ';" class="text-center border-top border-bottom border-right pl-1 pr-1" rowspan="' . $modulelenght . '">frei</td>';
|
|
$calcwidth = $calcwidth + $slots['width'];
|
|
}
|
|
if ($calcwidth != 12) {
|
|
echo '<td colspan="' . $slots['width'] . '" style="width: ' . $width . ';" class="text-center border-top border-bottom border-right pl-1 pr-1" rowspan="' . $modulelenght . '">frei</td>';
|
|
$calcwidth = $calcwidth + $slots['width'];
|
|
}
|
|
|
|
$blocktd = $modulelenght + $i;
|
|
|
|
}
|
|
}
|
|
if ($i >= $blocktd) {
|
|
echo '<td colspan="12" style="background-color: #fff;" class="text-center he-free" ><span></span> frei</td>';
|
|
}
|
|
echo '</tr>';
|
|
endfor;
|
|
die();
|
|
}
|
|
} |