diff options
author | Christian Klinger | 2016-06-15 13:04:15 +0200 |
---|---|---|
committer | Christian Klinger | 2016-06-15 13:04:15 +0200 |
commit | a0139c37aaafa845157335627ece7a5a88f4085f (patch) | |
tree | ed4319e1651533e1dcb2bb014e77caceb5aae762 | |
parent | Added date and time pickers. (diff) | |
download | slx-admin-a0139c37aaafa845157335627ece7a5a88f4085f.tar.gz slx-admin-a0139c37aaafa845157335627ece7a5a88f4085f.tar.xz slx-admin-a0139c37aaafa845157335627ece7a5a88f4085f.zip |
First version of a visualization.
-rw-r--r-- | modules-available/exams/page.inc.php | 115 | ||||
-rw-r--r-- | modules-available/exams/style.css | 7 | ||||
-rw-r--r-- | modules-available/exams/templates/page-add-exam.html | 6 | ||||
-rw-r--r-- | modules-available/exams/templates/page-exams.html | 101 |
4 files changed, 189 insertions, 40 deletions
diff --git a/modules-available/exams/page.inc.php b/modules-available/exams/page.inc.php index 78d5b21c..c0b6c48d 100644 --- a/modules-available/exams/page.inc.php +++ b/modules-available/exams/page.inc.php @@ -5,6 +5,95 @@ class Page_Exams extends Page var $action; var $exams; var $locations; + var $lectures; + + + protected function readLocations() + { + $tmp = Database::simpleQuery("select * from location;", []); + while ($loc = $tmp->fetch(PDO::FETCH_ASSOC)) { + $this->locations[] = $loc; + } + } + + protected function readExams() + { + $tmp = Database::simpleQuery("select * from exams NATURAL LEFT OUTER JOIN location;", []); + while ($exam = $tmp->fetch(PDO::FETCH_ASSOC)) { + $this->exams[] = $exam; + } + + } + + protected function readLectures() + { + $tmp = Database::simpleQuery("select * from sat.lecture NATURAL JOIN sat.lecture_x_location"); + while ($lecture = $tmp->fetch(PDO::FETCH_ASSOC)) { + $this->lectures[] = $lecture; + } + } + + protected function makeItemsForVis() + { + $out = []; + /* foreach group also add an invisible item on top */ + foreach ($this->locations as $l) { + $out[] = [ 'id' => 'spacer_' . $l['locationid'], + 'group' => $l['locationid'], + 'className' => 'spacer', + 'start' => 0, + 'content' => 'spacer', + 'end' => 99999999999999, + 'subgroup' => 0 + ]; + + } + foreach ($this->exams as $e) { + // $out[] = [ 'id' => $e['examid'], + // 'content' => $e['description'], + // 'start' => $e['starttime'], + // 'end' => $e['endtime'], + // 'group' => $e['locationid'], + // 'subgroup' => $i++ + // ]; + /* show them only as a red shadow */ + $out[] = [ 'id' => 'shadow_' . $e['examid'], + 'content' => '', + 'start' => $e['starttime'], + 'end' => $e['endtime'], + 'type' => 'background', + 'group' => $e['locationid'], + ]; + /* also add the shadow for all subrooms */ + } + /* add the lectures */ + $i = 2; + foreach ($this->lectures as $l) { + $out[] = [ + 'id' => $l['lectureid'], + 'content' => $l['displayname'], + 'start' => date(DATE_ISO8601, $l['starttime']), + 'end' => date(DATE_ISO8601, $l['endtime']), + 'group' => $l['locationid'], + 'subgroup' => $i++ + ]; + + } + + return json_encode($out); + } + + protected function makeGroupsForVis() + { + $out = []; + foreach ($this->locations as $l) { + $out[] = [ + 'id' => $l['locationid'], + 'content' => $l['locationname'] + ]; + } + return json_encode($out); + } protected function doPreprocess() { @@ -16,24 +105,20 @@ class Page_Exams extends Page } if ($this->action === 'show') { - $tmp = Database::simpleQuery("select * from exams NATURAL LEFT OUTER JOIN location;", []); - while ($exam = $tmp->fetch(PDO::FETCH_ASSOC)) { - $this->exams[] = $exam; - } + $this->readExams(); + $this->readLocations(); + $this->readLectures(); } elseif ($this->action === 'add') { - $tmp = Database::simpleQuery("select * from location;", []); - while ($loc = $tmp->fetch(PDO::FETCH_ASSOC)) { - $this->locations[] = $loc; - } - + $this->readLocations(); if (Request::isPost()) { /* process form-data */ $locationid = Request::post('location'); $starttime = Request::post('starttime_date') . " " . Request::post('starttime_time'); $endtime = Request::post('endtime_date') . " " . Request::post('endtime_time'); + $description = Request::post('description'); - $res = Database::exec("INSERT INTO exams(locationid, starttime, endtime) VALUES(:locationid, :starttime, :endtime);", - compact('locationid', 'starttime', 'endtime')); + $res = Database::exec("INSERT INTO exams(locationid, starttime, endtime, description) VALUES(:locationid, :starttime, :endtime, :description);", + compact('locationid', 'starttime', 'endtime', 'description')); if ($res === false) { Message::addError('exam-not-added'); @@ -65,7 +150,13 @@ class Page_Exams extends Page if ($this->action === "show") { Render::setTitle("All Exams"); - Render::addTemplate('page-exams', ['exams' => $this->exams]); + Render::addTemplate('page-exams', + [ 'exams' => $this->exams, + 'exams_json' => $this->makeItemsForVis(), + 'rooms_json' => $this->makeGroupsForVis(), + 'vis_begin' => date('Y-m-d'), + 'vis_end' => date('Y-m-d', strtotime("+2 day")) + ]); } elseif ($this->action === "add") { Render::setTitle("Add Exam"); Render::addTemplate('page-add-exam', ['locations' => $this->locations]); diff --git a/modules-available/exams/style.css b/modules-available/exams/style.css new file mode 100644 index 00000000..bc5ae53e --- /dev/null +++ b/modules-available/exams/style.css @@ -0,0 +1,7 @@ + .vis-item.vis-background { + background-color: #E8A7A7 !important; +} + .vis-item.spacer { + visibility: hidden; + background-color: green !important; + } diff --git a/modules-available/exams/templates/page-add-exam.html b/modules-available/exams/templates/page-add-exam.html index b6a8f6b1..a537e7e9 100644 --- a/modules-available/exams/templates/page-add-exam.html +++ b/modules-available/exams/templates/page-add-exam.html @@ -31,6 +31,12 @@ <input type="texxt" class="form-control timepicker" name="endtime_time" /> </div> </div> + <div class="row"> + <div class="form-group col-xs-12"> + <label for="description">Description</label> + <textarea class="form-control" type="textarea" name="description"></textarea> + </div> + </div> <input type="hidden" name="token" value="{{token}}" /> <input type="submit" class="btn btn-success" value="Add Exam"></input> diff --git a/modules-available/exams/templates/page-exams.html b/modules-available/exams/templates/page-exams.html index 6c67fa2c..8758b408 100644 --- a/modules-available/exams/templates/page-exams.html +++ b/modules-available/exams/templates/page-exams.html @@ -1,32 +1,77 @@ +<div class="container-fluid"> + <h1>All Exams</h1> -<h1>All Exams</h1> - -<table class="table"> - <tr> - <th>ID</th> - <th>Location</th> - <th>Begin</th> - <th>End</th> - <th>Actions</th> - </tr> - {{#exams}} + <table class="table"> <tr> - <td>{{examid}}</td> - <td> - <a href="?do=baseconfig&module=locations&locationid={{locationid}}"> {{locationname}} </a> - </td> - <td>{{starttime}}</td> - <td>{{endtime}}</td> - <td> - <form method="POST" action="?do=exams&action=delete" - onsubmit="return confirm('delete really?');"> - <input type="hidden" name="token" value="{{token}}"/> - <input type="hidden" name="examid" value="{{examid}}"/> - <input type="submit" value="Delete" class="btn btn-sm" /> - </form> - </td> + <th>ID</th> + <th>Location</th> + <th>Begin</th> + <th>End</th> + <th>Actions</th> </tr> - {{/exams}} + {{#exams}} + <tr> + <td>{{examid}}</td> + <td> + <a href="?do=baseconfig&module=locations&locationid={{locationid}}"> {{locationname}} </a> + </td> + <td>{{starttime}}</td> + <td>{{endtime}}</td> + <td> + <form method="POST" action="?do=exams&action=delete" + onsubmit="return confirm('delete really?');"> + <input type="hidden" name="token" value="{{token}}"/> + <input type="hidden" name="examid" value="{{examid}}"/> + <input type="submit" value="Delete" class="btn btn-sm" /> + </form> + </td> + </tr> + {{/exams}} -</table> -<a href="?do=exams&action=add" class="btn btn-success">Add Exam </a> + </table> + <a href="?do=exams&action=add" class="btn btn-success">Add Exam </a> + + <div id="timeline"> </div> + +</div> +<script type="application/javascript"><!-- + + +function customOrder(a, b) { + console.log("a is "); + console.log(a); + console.log("b is "); + console.log(b); + return 1000; +} + +document.addEventListener("DOMContentLoaded", function () { + var container = document.getElementById('timeline'); + var groups_plain = JSON.parse('{{{rooms_json}}}'); + var items_plain = JSON.parse('{{{exams_json}}}'); + console.log(groups_plain); + console.log(items_plain); + var groups = new vis.DataSet(groups_plain); + var items = new vis.DataSet(items_plain); + // var groups = new vis.DataSet([ + // { id: 1, content:'RZ -101' }, + // { id: 2, content:'RZ -104' } + // ]); + // var items = new vis.DataSet([ + // { id: 1, group: 1, content: 'Bio 1', start: '2016-06-15 10:30', end : '2016-06-15 14:45'}, + // { id: 2, group: 1, content: 'Bio 2', start: '2016-06-15 10:45', end : '2016-06-15 15:00'}, + // { id: 3, group: 2, content: 'Englisch', start: '2016-06-15 16:00', end : '2016-06-15 17:15'}, + // { id: 4, group: 1, content: 'BACKGROUND', start: '2016-06-15-11:00', end: '2016-06-15 18:00', type: 'background'} + // ]); + + var options = { + 'start' : '{{{vis_begin}}}', + 'end' : '{{{vis_end}}}', + 'stack' : false, + 'order' : customOrder + }; + + var timeline = new vis.Timeline(container, items, groups, options); +}, false); + +// --></script> |