From 3df1aaf371786bf2696ab8fdffff48396a4665ea Mon Sep 17 00:00:00 2001 From: SimonGschnell Date: Tue, 4 Jun 2024 08:24:58 +0200 Subject: [PATCH] uses the new fhcApi factory to make the roomInformation get request from the frontent/v1/stundenplan api and uses the CalendarDate class to get the first day of the week and the last day of the week to make the request for the room information over the whole week --- .../api/frontend/v1/Stundenplan.php | 90 +++++++++++++++++++ .../components/Cis/Stundenplan.php | 3 - .../models/ressource/Stundenplan_model.php | 9 +- public/js/api/fhcapifactory.js | 4 +- public/js/api/studenplan.js | 15 ++++ public/js/apps/Cis/RoomInformation.js | 63 ++++--------- public/js/components/Calendar/Week/Page.js | 1 - 7 files changed, 132 insertions(+), 53 deletions(-) create mode 100644 application/controllers/api/frontend/v1/Stundenplan.php create mode 100644 public/js/api/studenplan.js diff --git a/application/controllers/api/frontend/v1/Stundenplan.php b/application/controllers/api/frontend/v1/Stundenplan.php new file mode 100644 index 000000000..5e35ae3c9 --- /dev/null +++ b/application/controllers/api/frontend/v1/Stundenplan.php @@ -0,0 +1,90 @@ +. + */ + +if (! defined('BASEPATH')) exit('No direct script access allowed'); + +/** + * This controller operates between (interface) the JS (GUI) and the SearchBarLib (back-end) + * Provides data to the ajax get calls about the searchbar component + * This controller works with JSON calls on the HTTP GET and the output is always JSON + */ +class Stundenplan extends FHCAPI_Controller +{ + + /** + * Object initialization + */ + public function __construct() + { + + parent::__construct([ + 'roomInformation' => self::PERM_LOGGED, + 'Stunden' => self::PERM_LOGGED + ]); + + // Load the library ... + // $this->load->library(''); + } + + //------------------------------------------------------------------------------------------------------------------ + // Public methods + + /** + * Gets a JSON body via HTTP POST and provides the parameters + */ + public function roomInformation() + { + // storing the get parameter in local variables + $ort_kurzbz = $this->input->get('ort_kurzbz', TRUE); + $start_date = $this->input->get('start_date', TRUE); + $end_date = $this->input->get('end_date', TRUE); + + $this->addMeta("ort",$ort_kurzbz); + $this->addMeta("start date",$start_date); + $this->addMeta("end date",$end_date); + $this->addMeta("testKey","testValue"); + + $this->load->model('ressource/Stundenplan_model', 'StundenplanModel'); + + $result = $this->StundenplanModel->getRoomDataOnDay($ort_kurzbz,$start_date,$end_date); + if(isError($result)){ + $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL); + } + + $result = hasData($result) ? getData($result) : []; + //echo($this->db->last_query()); + $this->terminateWithSuccess($result); + + } + + public function Stunden() + { + $this->load->model('ressource/Stunde_model', 'StundeModel'); + + $result = $this->StundeModel->load(); + + if (isError($result)){ + $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL); + } + + $result = hasData($result)? getData($result) : []; + + $this->terminateWithSuccess($result); + } +} + diff --git a/application/controllers/components/Cis/Stundenplan.php b/application/controllers/components/Cis/Stundenplan.php index e0c163bac..76535befa 100755 --- a/application/controllers/components/Cis/Stundenplan.php +++ b/application/controllers/components/Cis/Stundenplan.php @@ -69,9 +69,6 @@ class Stundenplan extends Auth_Controller public function RoomInformation() { $this->load->model('ressource/Stundenplan_model', 'StundenplanModel'); - - - $result = $this->StundenplanModel->getRoomDataOnDay('EDV_A2.06','2024-05-21'); $result = hasData($result) ? getData($result) : []; diff --git a/application/models/ressource/Stundenplan_model.php b/application/models/ressource/Stundenplan_model.php index f67eab166..64550ccbf 100755 --- a/application/models/ressource/Stundenplan_model.php +++ b/application/models/ressource/Stundenplan_model.php @@ -18,7 +18,7 @@ class Stundenplan_model extends DB_Model * * @return stdClass */ - public function getRoomDataOnDay($ort_kurzbz,$date){ + public function getRoomDataOnDay($ort_kurzbz='EDV_A2.06',$start_date='2024-05-21',$end_date='2024-05-21'){ $this->addSelect(['*',"CONCAT(UPPER(sp.stg_typ),UPPER(sp.stg_kurzbz),'-',COALESCE(CAST(sp.semester AS varchar),'/'),COALESCE(CAST(sp.verband AS varchar),'/')) as stg","lektor","CONCAT(lehrfach,'-',lehrform) as lv_info" ]); @@ -28,12 +28,13 @@ class Stundenplan_model extends DB_Model $res = $this->loadWhere(['ort_kurzbz'=>$ort_kurzbz,'datum'=>$date]); $res = hasData($res) ? getData($res): null; return $res; */ - $this->db->where('ort_kurzbz','EDV_A2.06',true); - $this->db->where('datum >=','2024-05-21',true); + $this->db->where('ort_kurzbz',$ort_kurzbz,true); + $this->db->where('datum >=',$start_date,true); + $this->db->where('datum <=',$end_date,true); $query = $this->db->get_compiled_select('lehre.vw_stundenplan sp'); - return $this->execQuery($query, [$ort_kurzbz, $date]); + return $this->execQuery($query, [$ort_kurzbz, $start_date, $end_date]); } /** diff --git a/public/js/api/fhcapifactory.js b/public/js/api/fhcapifactory.js index 41c89ef50..d5d07e000 100644 --- a/public/js/api/fhcapifactory.js +++ b/public/js/api/fhcapifactory.js @@ -20,11 +20,13 @@ import phrasen from "./phrasen.js"; import navigation from "./navigation.js"; import filter from "./filter.js"; import studstatus from "./studstatus.js"; +import stundenplan from "./studenplan.js"; export default { search, phrasen, navigation, filter, - studstatus + studstatus, + stundenplan, }; diff --git a/public/js/api/studenplan.js b/public/js/api/studenplan.js new file mode 100644 index 000000000..2da67a737 --- /dev/null +++ b/public/js/api/studenplan.js @@ -0,0 +1,15 @@ + +export default { + getRoomInfo(ort_kurzbz, start_date, end_date) { + return this.$fhcApi.get( + '/api/frontend/v1/Stundenplan/roomInformation', + { ort_kurzbz, start_date, end_date} + ); + }, + getStunden() { + return this.$fhcApi.get( + '/api/frontend/v1/Stundenplan/Stunden', + {} + ); + }, +}; \ No newline at end of file diff --git a/public/js/apps/Cis/RoomInformation.js b/public/js/apps/Cis/RoomInformation.js index cc7aec2bb..fbe49386d 100644 --- a/public/js/apps/Cis/RoomInformation.js +++ b/public/js/apps/Cis/RoomInformation.js @@ -1,4 +1,6 @@ import FhcCalendar from "../../components/Calendar/Calendar.js"; +import CalendarDate from "../../composables/CalendarDate.js"; +import FhcApi from "../../plugin/FhcApi.js"; const app = Vue.createApp({ components: { @@ -8,25 +10,26 @@ const app = Vue.createApp({ return { stunden: [], events: null, - testDate: new Date('2024-05-21'), - } + calendarWeek: new CalendarDate(new Date()), + } }, + computed:{ + currentDate: function(){ + return new Date(this.calendarWeek.y, this.calendarWeek.m, this.calendarWeek.d); + }, + }, created() { - axios.get(FHC_JS_DATA_STORAGE_OBJECT.app_root + FHC_JS_DATA_STORAGE_OBJECT.ci_router + '/components/Cis/Stundenplan/Stunden').then(res => { - - - res.data.retval.forEach(std => { + + this.$fhcApi.factory.stundenplan.getStunden().then(res =>{ + res.data.forEach(std => { this.stunden[std.stunde] = std; // TODO(chris): geht besser }); - console.log("this are the loaded stunden", this.stunden) - axios.get(FHC_JS_DATA_STORAGE_OBJECT.app_root + FHC_JS_DATA_STORAGE_OBJECT.ci_router + '/components/Cis/Stundenplan/RoomInformation').then(res => { + this.$fhcApi.factory.stundenplan.getRoomInfo('EDV_A6.09', this.calendarWeek.firstDayOfWeek, this.calendarWeek.lastDayOfWeek).then(res =>{ let events; - console.log(" this is the res of the api call room information",res); if (res.data && res.data.forEach) { res.data.forEach((el, i) => { - console.log(el,"this is the element that gets changed") el.id = i; el.color = '#' + (el.farbe || 'CCCCCC'); el.start = new Date(el.datum + ' ' + this.stunden[el.stunde].beginn); @@ -35,45 +38,16 @@ const app = Vue.createApp({ if (el.lehrform) el.title += '-' + el.lehrform; }); - events = res.data; - //console.log("this are the room events",events) - this.events = events; + + this.events = res.data; } - }).catch((e)=>{console.log(e,"this is the exception")}) - }); - - /* axios.get(FHC_JS_DATA_STORAGE_OBJECT.app_root + FHC_JS_DATA_STORAGE_OBJECT.ci_router + '/components/Cis/Stundenplan').then(res => { - - let events; - console.log(" this is the res of the api call stundenplan",res); - if (res.data.retval && res.data.retval.forEach) { - res.data.retval.forEach((el, i) => { - el.id = i; - el.color = '#' + (el.farbe || 'CCCCCC'); - el.start = new Date(el.datum + ' ' + this.stunden[el.stunde].beginn); - el.end = new Date(el.datum + ' ' + this.stunden[el.stunde].ende); - el.title = el.lehrfach; - if (el.lehrform) - el.title += '-' + el.lehrform; - }); - events = res.data.retval; - console.log("this are the events of the stundenplan",events) - } - - // TODO(chris): do we need that - - }).catch((e)=>{console.log(e,"this is the exception")}) - - - */ - - + }) + }); }, template: /*html*/`
- - +
{{event.orig.lv_info}} {{event.orig.stg}} @@ -84,4 +58,5 @@ const app = Vue.createApp({ `, }); app.config.unwrapInjectedRef = true; +app.use(FhcApi); app.mount('#content'); \ No newline at end of file diff --git a/public/js/components/Calendar/Week/Page.js b/public/js/components/Calendar/Week/Page.js index cd0ec816e..c6636ad43 100755 --- a/public/js/components/Calendar/Week/Page.js +++ b/public/js/components/Calendar/Week/Page.js @@ -41,7 +41,6 @@ export default { }, eventsPerDayAndHour() { const res = {}; - console.log("this are the days",this.days) this.days.forEach(day => { let key = day.toDateString();