Skip to content

Commit 887a197

Browse files
committed
Initial code for front-end categorization status view
1 parent 93d1491 commit 887a197

File tree

3 files changed

+87
-13
lines changed

3 files changed

+87
-13
lines changed

classes/constellation.php

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ public function render_incidents($future=false, $offset=0, $limit = 5, $admin =
7272
public function render_status($admin = false, $heading = true){
7373
global $mysqli;
7474

75-
$query = $mysqli->query("SELECT id, name FROM services");
75+
//$query = $mysqli->query("SELECT id, name, description FROM services");
76+
$query = $mysqli->query("SELECT services.id, services.name, services.description, services_groups.name as group_name FROM services LEFT JOIN services_groups ON services.group_id=services_groups.id ORDER BY services_groups.name ");
7677
$array = array();
7778
if ($query->num_rows){
7879
$timestamp = time();
@@ -87,10 +88,10 @@ public function render_status($admin = false, $heading = true){
8788
$tmp = $sql->get_result();
8889
if ($tmp->num_rows)
8990
{
90-
$array[] = new Service($result['id'], $result['name'], $tmp->fetch_assoc()['type']);
91+
$array[] = new Service($result['id'], $result['name'], $result['description'], $result['group_name'], $tmp->fetch_assoc()['type']);
9192
}
9293
else{
93-
$array[] = new Service($result['id'], $result['name']);
94+
$array[] = new Service($result['id'], $result['name'], $result['description'], $result['group_name']);
9495
}
9596
}
9697
if ($heading)
@@ -103,11 +104,27 @@ public function render_status($admin = false, $heading = true){
103104
}
104105
if (!$admin)
105106
{
106-
echo '<div id="status-container" class="clearfix">';
107+
?>
108+
<script>
109+
$(document).ready(function(){
110+
$('[data-toggle="tooltip"]').tooltip();
111+
});
112+
</script>
113+
<?php
114+
//echo '<div id="status-container" class="clearfix">';
115+
//$arrCompletedGroups = array();
107116
foreach($array as $service){
117+
//print_r($service);
118+
//if ( !empty($service->group_name) && !in_array($service->group_name, $arrCompletedGroups)) {
119+
//print $service->name;
120+
// $arrCompletedGroups[] = $service['group_name'];
121+
// $service->render(true);
122+
//} else {
108123
$service->render();
124+
//}
109125
}
110-
echo '</div>';
126+
echo '</ul>';
127+
//echo '</div>';
111128
}
112129
else{
113130
return $array;

classes/service.php

Lines changed: 61 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,24 @@ class Service implements JsonSerializable
66
{
77
private $id;
88
private $name;
9+
private $description;
10+
private $group_name;
911
private $status;
1012

1113
/**
1214
* Constructs service from its data.
1315
* @param int $id service ID
1416
* @param String $name service name
17+
* @param String $descriotion service description for tooltip
1518
* @param int $status current service status
1619
*/
17-
function __construct($id, $name, $status=3)
20+
function __construct($id, $name, $description=null, $group_name='', $status=3)
1821
{
1922
//TODO: Maybe get data from ID?
2023
$this->id = $id;
2124
$this->name = $name;
25+
$this->description = $description;
26+
$this->group_name = $group_name;
2227
$this->status = $status;
2328
}
2429

@@ -49,6 +54,15 @@ public function get_name()
4954
return $this->name;
5055
}
5156

57+
/**
58+
* Returns description of this service
59+
* @return String description
60+
*/
61+
public function get_description()
62+
{
63+
return $this->description;
64+
}
65+
5266
/**
5367
* Processes submitted form and adds service unless problem is encountered,
5468
* calling this is possible only for admin or higher rank. Also checks requirements
@@ -192,24 +206,64 @@ public static function current_status($array){
192206

193207
/**
194208
* Renders this service.
209+
* @param $boolGroup set to true if the groups name is to be rendered
195210
* @return void
196211
*/
197212
public function render(){
198213
global $statuses;
199214
global $classes;
200-
?>
201-
<div class="item clearfix">
202-
<div class="service"><?php echo $this->name; ?></div>
203-
<?php if ($this->status!=-1){?><div class="status <?php echo $classes[$this->status];?>"><?php echo _($statuses[$this->status]);?></div><?php }?>
204-
</div>
205-
<?php
215+
static $arrCompletedGroups = array();
216+
//static $boolClosed;
217+
static $boolOpened;
218+
219+
// Check if previous ul has been opened, and if a empty/new group is being
220+
// render_header, close the UL first.
221+
if ( $boolOpened ) {
222+
if ( empty($this->group_name) || !in_array($this->group_name, $arrCompletedGroups) ) {
223+
echo '</ul>';
224+
$boolOpened = false;
225+
}
226+
}
227+
228+
// If no group exist or group is new, start a new UL
229+
if ( !empty($this->group_name) && !in_array($this->group_name, $arrCompletedGroups)) {
230+
echo '<ul class="list-group components">';
231+
//echo '<ul class="platforms list-group mb-2">';
232+
// Render the group status if it exists
233+
echo '<li class="list-group-item list-group-item-success group-name"><span><i class="glyphicon glyphicon-plus"></i></span>&nbsp;' . $this->group_name .'<div class="status '. $classes[$this->status] .'">'. _($statuses[$this->status]).'</div></li>';
234+
//echo '<li class="cist-group-item d-flex flex-row justify-content-between platform list-group-item-action py-0 expanded" role="button">' . $this->group_name .'<div class="status '. $classes[$this->status] .'"'. _($statuses[$this->status]).'</div></li>';
235+
$arrCompletedGroups[] = $this->group_name;
236+
$boolOpened = true;
237+
}
238+
239+
if ( empty($this->group_name)) {
240+
echo '<ul class="list-group components">';
241+
242+
// echo '<ul class="platforms list-group mb-2">';
243+
$boolFinish = true;
244+
}
245+
246+
// Render the service status
247+
echo '<li class="list-group-item sub-component"><strong>' . $this->name .'</strong>';
248+
//echo '<li class="list-group-item d-flex flex-columns justify-content-between><span>+</span><h3 class="py-2 my-0 flex-fill expanded">' . $this->name . '</h3>';
249+
if(!empty($this->description)) {
250+
echo '<a class="desc-tool-tip" data-toggle="tooltip" data-placement="top" title="'.$this->description.'"> <span><i class="glyphicon glyphicon-question-sign"></i></span></a>';
251+
}
252+
if ($this->status!=-1){?><div class="status pull-right <?php echo $classes[$this->status];?>"><?php echo _($statuses[$this->status]);?></div>
253+
<?php
254+
}
255+
echo '</li>';
256+
if ( isset($boolFinish) && $boolFinish) {
257+
echo '</ul>';
258+
}
206259
}
207260

208261
public function jsonSerialize() {
209262
global $statuses;
210263
return [
211264
"id" => $this->id,
212265
"name" => $this->name,
266+
"description" => $this->description,
213267
"status" => $this->status,
214268
"status_string" => $statuses[$this->status]
215269
];

css/main.css

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ a:focus {
2727
color:#f5f4f4;
2828
}
2929

30+
a.desc-tool-tip, a.desc-tool-tip:hover, a.desc-tool-tip:visited {
31+
color: grey;
32+
}
33+
3034
.centered {
3135
text-align: center
3236
}
@@ -686,4 +690,3 @@ input:checked + .slider:before {
686690
.slider.round:before {
687691
border-radius: 50%;
688692
}
689-

0 commit comments

Comments
 (0)