summaryrefslogtreecommitdiffstats
path: root/dist/js/timetable.js
diff options
context:
space:
mode:
authorsijanec <anton@sijanec.eu>2021-05-16 16:49:09 +0200
committersijanec <anton@sijanec.eu>2021-05-16 16:49:09 +0200
commitabd9011fa84bdc1f6ee583e387d0ec686c3dc3ab (patch)
tree297222608598dae2478c79f4e82b655c6c497292 /dist/js/timetable.js
parentMerge branch 'master' into dev (diff)
downloadbeziapp-abd9011fa84bdc1f6ee583e387d0ec686c3dc3ab.tar
beziapp-abd9011fa84bdc1f6ee583e387d0ec686c3dc3ab.tar.gz
beziapp-abd9011fa84bdc1f6ee583e387d0ec686c3dc3ab.tar.bz2
beziapp-abd9011fa84bdc1f6ee583e387d0ec686c3dc3ab.tar.lz
beziapp-abd9011fa84bdc1f6ee583e387d0ec686c3dc3ab.tar.xz
beziapp-abd9011fa84bdc1f6ee583e387d0ec686c3dc3ab.tar.zst
beziapp-abd9011fa84bdc1f6ee583e387d0ec686c3dc3ab.zip
Diffstat (limited to 'dist/js/timetable.js')
-rwxr-xr-xdist/js/timetable.js12
1 files changed, 6 insertions, 6 deletions
diff --git a/dist/js/timetable.js b/dist/js/timetable.js
index aa73a9a..d74a32f 100755
--- a/dist/js/timetable.js
+++ b/dist/js/timetable.js
@@ -3,9 +3,7 @@ var calendar_obj=null;function checkLogin(){localforage.getItem("logged_in").the
function setLoading(state){if(state){$("#loading-bar").removeClass("hidden");}else{$("#loading-bar").addClass("hidden");}}
function hashCode(str){var hash=0;for(var i=0;i<str.length;i++){hash=str.charCodeAt(i)+((hash<<5)-hash);}
return hash;}
-function intToRGB(i){var c=(i&0x00FFFFFF).toString(16).toUpperCase();return"00000".substring(0,6-c.length)+c;}
function getForegroundFromBackground(background_color){let color_hex=background_color.replace("#","");let rgb=[parseInt(color_hex.substring(0,2),16),parseInt(color_hex.substring(2,4),16),parseInt(color_hex.substring(4,6),16)];let o=Math.round(((parseInt(rgb[0])*299)+(parseInt(rgb[1])*587)+(parseInt(rgb[2])*114))/1000);if(o>180){return"#000000";}else{return"#ffffff";}}
-function getHexColorFromString(str){return"#"+intToRGB(hashCode(str));}
function getDateString(date){let year_str=date.getFullYear();let month_str=date.getMonth()+1
month_str=month_str.toString().padStart(2,"0");let day_str=date.getDate();day_str=day_str.toString().padStart(2,"0");let date_string=year_str+"-"+month_str+"-"+day_str;return date_string;}
function getLastMonday(date_object){if(date_object.getDay()===0){date_object.setDate(date_object.getDate()-6);}else{date_object.setDate(date_object.getDate()-date_object.getDay()+1);}
@@ -14,8 +12,10 @@ async function loadTimetable(date_object,force_refresh=false){setLoading(true);v
if(!containsPeriods){UIAlert(D("noPeriods"));setLoading(false);}else{if(timetable===null){timetable={};}
timetable[date_string]=value;localforage.setItem("timetable",timetable).then(()=>{displayTimetable(value,date_monday);setLoading(false);});}}).catch((err)=>{gsecErrorHandlerUI(err);setLoading(false);});}catch(err){gsecErrorHandlerUI(err);setLoading(false);}}else{displayTimetable(timetable[date_string],date_monday);setLoading(false);}}
function getLessonTimes(lesson_number){const lessonTimes=[["07:10:00","07:55:00"],["08:00:00","08:45:00"],["08:50:00","09:35:00"],["09:40:00","10:25:00"],["10:55:00","11:40:00"],["11:45:00","12:30:00"],["12:35:00","13:20:00"],["13:25:00","14:10:00"],["14:15:00","15:00:00"],["15:05:00","15:50:00"],["15:55:00","16:40:00"],["16:45:00","17:30:00"],["17:35:00","18:20:00"],["18:25:00","19:10:00"]];return lessonTimes[lesson_number];}
-function displayTimetable(weekly_timetable,date_object){let transformed_timetable=[];let num_days=Object.keys(weekly_timetable).length;for(let i=0;i<num_days;i++){let date_string=getDateString(date_object);date_object.setDate(date_object.getDate()+1);let daily_timetable=weekly_timetable[i.toString()];Object.keys(daily_timetable).forEach((lesson_number)=>{let lesson=daily_timetable[lesson_number];let lesson_times=getLessonTimes(parseInt(lesson_number));let bg_color=getHexColorFromString(lesson["acronym"]);let fg_color=getForegroundFromBackground(bg_color);let lesson_metadata={subject:lesson["subject"],class:lesson["class"],teacher:lesson["teacher"],classroom:lesson["place"],start:lesson_times[0].substring(0,5),end:lesson_times[1].substring(0,5)}
-let lesson_object={id:JSON.stringify(lesson_metadata),title:lesson["acronym"],start:date_string+" "+lesson_times[0],end:date_string+" "+lesson_times[1],backgroundColor:bg_color,textColor:fg_color};transformed_timetable.push(lesson_object);});}
+function displayTimetable(weekly_timetable,date_object){let transformed_timetable=[];let num_days=Object.keys(weekly_timetable).length;for(let i=0;i<num_days;i++){let date_string=getDateString(date_object);date_object.setDate(date_object.getDate()+1);let daily_timetable=weekly_timetable[i.toString()];Object.keys(daily_timetable).forEach((lesson_number)=>{let lesson=daily_timetable[lesson_number];let lesson_times=getLessonTimes(parseInt(lesson_number));let bg_color=getHexColorFromString(lesson["acronym"]);let fg_color=getForegroundFromBackground(bg_color);let lesson_metadata={subject:lesson["subject"],class:lesson["class"],teacher:lesson["teacher"],classroom:lesson["place"],substitution:lesson["substitution"],start:lesson_times[0].substring(0,5),end:lesson_times[1].substring(0,5)}
+let lesson_object={id:JSON.stringify(lesson_metadata),title:lesson["acronym"],start:date_string+" "+lesson_times[0],end:date_string+" "+lesson_times[1],backgroundColor:bg_color,textColor:fg_color,};if(lesson["substitution"])
+lesson_object.borderColor="red";transformed_timetable.push(lesson_object);});}
calendar_obj.removeAllEvents();calendar_obj.addEventSource(transformed_timetable);}
-function eventClickHandler(eventClickInfo){let lesson_metadata=JSON.parse(eventClickInfo.event.id);let lesson_subject=lesson_metadata["subject"];let lesson_teacher=lesson_metadata["teacher"];let lesson_classroom=lesson_metadata["classroom"];let lesson_class=lesson_metadata["class"];let lesson_duration=lesson_metadata["start"]+" - "+lesson_metadata["end"];$("#lesson-subject").text(lesson_subject);$("#lesson-teacher").text(lesson_teacher);$("#lesson-class").text(lesson_class);$("#lesson-classroom").text(lesson_classroom);$("#lesson-duration").text(lesson_duration);const modal=document.querySelectorAll(".side-modal")[0];M.Sidenav.getInstance(modal).open();}
-document.addEventListener("DOMContentLoaded",()=>{checkLogin();let calendarEl=document.getElementById("calendar");calendar_obj=new FullCalendar.Calendar(calendarEl,{plugins:["timeGrid"],eventClick:eventClickHandler,defaultView:"timeGridWeek",contentHeight:"auto",height:"auto",width:"auto",timeGridEventMinHeight:35,nowIndicator:true,firstDay:1,weekends:false,timeFormat:'H(:mm)',minTime:"07:10:00",maxTime:"19:10:00"});calendar_obj.render();loadTimetable(new Date());$(".fc-today-button, .fc-prev-button, .fc-next-button").click(()=>{loadTimetable(calendar_obj.getDate());});$("#refresh-icon").click(()=>{loadTimetable(calendar_obj.getDate(),true);});const menus=document.querySelectorAll(".side-menu");M.Sidenav.init(menus,{edge:"right",draggable:true});const modals=document.querySelectorAll('.side-modal');M.Sidenav.init(modals,{edge:'left',draggable:false});}); \ No newline at end of file
+function eventClickHandler(eventClickInfo){let lesson_metadata=JSON.parse(eventClickInfo.event.id);let lesson_subject=lesson_metadata["subject"];let lesson_teacher=lesson_metadata["teacher"];let lesson_classroom=lesson_metadata["classroom"];let lesson_class=lesson_metadata["class"];let lesson_duration=lesson_metadata["start"]+" - "+lesson_metadata["end"];$("#lesson-subject").text(lesson_subject+(lesson_metadata["substitution"]?(" ("+s("substitution")+")"):""));$("#lesson-teacher").text(lesson_teacher);$("#lesson-class").text(lesson_class);$("#lesson-classroom").text(lesson_classroom);$("#lesson-duration").text(lesson_duration);const modal=document.querySelectorAll(".side-modal")[0];M.Sidenav.getInstance(modal).open();}
+var urnikTheme="privzeta";document.addEventListener("DOMContentLoaded",async function(){urnikTheme=await localforage.getItem("urnikTheme");if(urnikTheme==null||urnikTheme==undefined||urnikTheme==false)
+urnikTheme="privzeta";checkLogin();let calendarEl=document.getElementById("calendar");calendar_obj=new FullCalendar.Calendar(calendarEl,{plugins:["timeGrid"],eventClick:eventClickHandler,defaultView:"timeGridWeek",contentHeight:"auto",height:"auto",width:"auto",timeGridEventMinHeight:35,nowIndicator:true,firstDay:1,weekends:false,timeFormat:'H(:mm)',minTime:"07:10:00",maxTime:"19:10:00"});calendar_obj.render();loadTimetable(new Date());$(".fc-today-button, .fc-prev-button, .fc-next-button").click(()=>{loadTimetable(calendar_obj.getDate());});$("#refresh-icon").click(()=>{loadTimetable(calendar_obj.getDate(),true);});const menus=document.querySelectorAll(".side-menu");M.Sidenav.init(menus,{edge:"right",draggable:true});const modals=document.querySelectorAll('.side-modal');M.Sidenav.init(modals,{edge:'left',draggable:false});}); \ No newline at end of file