diff options
Diffstat (limited to '')
-rwxr-xr-x | dist/js/app.js | 2 | ||||
-rw-r--r-- | dist/js/grades.js | 6 | ||||
-rw-r--r-- | dist/js/gradings.js | 3 | ||||
-rw-r--r-- | dist/js/gsec.js | 9 |
4 files changed, 11 insertions, 9 deletions
diff --git a/dist/js/app.js b/dist/js/app.js index 053135a..8e89709 100755 --- a/dist/js/app.js +++ b/dist/js/app.js @@ -3,7 +3,7 @@ const app_version = "1.0.14-beta"; -const previous_commit = "20505fc48713c600c345814d4a9c2e0747c77152"; +const previous_commit = "07ff5e29f0c460cd541a1bc6d65b5290ed94de61"; if ("serviceWorker" in navigator) { navigator.serviceWorker.register("/sw.js") diff --git a/dist/js/grades.js b/dist/js/grades.js index dceb911..b1bfb3d 100644 --- a/dist/js/grades.js +++ b/dist/js/grades.js @@ -2,12 +2,14 @@ let checkbox_state=false;var grades;async function checkLogin(){localforage.getItem("logged_in").then((value)=>{if(value!==true){window.location.replace("/index.html");}}).catch((err)=>{console.log(err);});} function setLoading(state){if(state){$("#loading-bar").removeClass("hidden");}else{$("#loading-bar").addClass("hidden");}} async function loadGrades(force_refresh=false){setLoading(true);let promises_to_run=[localforage.getItem("username").then((value)=>{username=value;}),localforage.getItem("password").then((value)=>{password=value;}),localforage.getItem("grades").then((value)=>{grades=value;})];await Promise.all(promises_to_run);if(grades==null||grades==[]||force_refresh){try{let gsecInstance=new gsec();await gsecInstance.login(username,password);gsecInstance.fetchGrades().then((value)=>{grades=value;localforage.setItem("grades",value).then(()=>{displayGrades();setLoading(false);});setLoading(false);}).catch((err)=>{gsecErrorHandlerUI(err);setLoading(false);});}catch(err){gsecErrorHandlerUI(err);setLoading(false);}}else{displayGrades();setLoading(false);}} -function displayGrades(){let grades_by_subject={};grades.forEach((grade,index)=>{if(!(grade["subject"]in grades_by_subject)){grades_by_subject[grade["subject"]]=[];} +function displayGrades(){let grades_by_subject={};let zakljucne_grades_by_subject={};grades.forEach((grade,index)=>{if(grade["gradeType"]!=GSEC_NORMAL_GRADE){zakljucne_grades_by_subject[grade["subject"]]=grade["grade"];break;} +if(!(grade["subject"]in grades_by_subject)){grades_by_subject[grade["subject"]]=[];} let grade_object={date:dateString.longFormatted(grade["date"]),teacher:grade["teacher"],subject:grade["subject"],title:grade["name"][0],type:grade["name"][1],term:grade["name"][2],grade:grade["grade"],temporary:grade["temporary"],index:index} grades_by_subject[grade["subject"]].push(grade_object);});let root_element=document.getElementById("grades-collapsible");Object.keys(grades_by_subject).forEach((subject)=>{let subject_entry=document.createElement("li");let subject_header=document.createElement("div");subject_header.classList.add("collapsible-header");subject_header.classList.add("collapsible-header-root");let subject_header_text=document.createElement("span");subject_header_text.innerText=subject;let subject_body=document.createElement("div");subject_body.className="collapsible-body";let subject_body_root=document.createElement("ul");subject_body_root.className="collection";let grade_sum=0;let grade_tot=0;grades_by_subject[subject].forEach((grade)=>{let grade_node=document.createElement("li");grade_node.className="collection-item";grade_node.classList.add("collection-item") grade_node.classList.add("grade-node");grade_node.dataset["index"]=grade["index"];let grade_node_div=document.createElement("div");let grade_text=document.createElement("span");let grade_number=document.createElement("div");grade_number.className="secondary-content";if(grade["temporary"]){let grade_text_italic=document.createElement("i");grade_text_italic.innerText=grade["date"]+" - "+grade["title"];grade_text.appendChild(grade_text_italic);let grade_number_italic=document.createElement("i");grade_number_italic.innerText=grade["grade"].toString();grade_number.appendChild(grade_number_italic);}else{grade_text.innerText=grade["date"]+" - "+grade["title"];grade_number.innerText=grade["grade"].toString();} grade_node_div.appendChild(grade_text);grade_node_div.appendChild(grade_number);grade_node.appendChild(grade_node_div);if(!grade["temporary"]||!checkbox_state){grade_sum+=grade["grade"];grade_tot+=1;} -subject_body_root.appendChild(grade_node);});let grade_average=(grade_tot===0)?"N/A":(Math.round(((grade_sum/grade_tot)+Number.EPSILON)*100)/100);let subject_header_average=document.createElement("div");subject_header_average.className="collapsible-header-right";subject_header_average.innerText=grade_average.toString();subject_header.appendChild(subject_header_text);subject_header.appendChild(subject_header_average);subject_body.append(subject_body_root);subject_entry.append(subject_header);subject_entry.append(subject_body);root_element.append(subject_entry);});$("#grades-collapsible").append(root_element);refreshClickHandlers();} +subject_body_root.appendChild(grade_node);});let grade_average=(grade_tot===0)?"N/A":(Math.round(((grade_sum/grade_tot)+Number.EPSILON)*100)/100);let subject_header_average=document.createElement("div");subject_header_average.className="collapsible-header-right";if(subject in zakljucne_grades_by_subject){subject_header_average.innerText=zakljucne_grades_by_subject[subject];subject_header_average.classList.add="zakljucna-grade";}else{subject_header_average.innerText=grade_average.toString();} +subject_header.appendChild(subject_header_text);subject_header.appendChild(subject_header_average);subject_body.append(subject_body_root);subject_entry.append(subject_header);subject_entry.append(subject_body);root_element.append(subject_entry);});$("#grades-collapsible").append(root_element);refreshClickHandlers();} function clearGrades(){const table=document.getElementById("grades-collapsible");while(table.firstChild){table.removeChild(table.firstChild);}} function refreshGrades(force){clearGrades();loadGrades(force);} function refreshClickHandlers(){$("#grades-collapsible").find(".collection-item.grade-node").click(function(){let grade_obj=grades[parseInt(this.dataset["index"])];document.getElementById("grade-header").innerText=grade_obj["subject"]+": "+grade_obj["grade"];document.getElementById("grade-date").innerText=dateString.longFormatted(grade_obj["date"]);document.getElementById("grade-title").innerText=grade_obj["name"][0];document.getElementById("grade-type").innerText=S("type")+": "+grade_obj["name"][1];let term_element=document.getElementById("grade-term");if(grade_obj["name"][2]!==""){term_element.innerText=S("term")+": "+grade_obj["name"][2];term_element.style["display"]="";}else{term_element.style["display"]="none";} diff --git a/dist/js/gradings.js b/dist/js/gradings.js index de5f21b..713ea20 100644 --- a/dist/js/gradings.js +++ b/dist/js/gradings.js @@ -14,5 +14,4 @@ async function validateInputs(){if($("#input-grading-name").val()!=null&&$("#inp function gradingClickHandler(eventClickInfo){let grading_id=parseInt(eventClickInfo.event.id);let grading_subject=gradings[grading_id]["subject"];let grading_date_obj=gradings[grading_id]["date"];let grading_date=dateString.longFormatted(grading_date_obj);let grading_description=gradings[grading_id]["description"];$("#grading-subject").text(grading_subject);$("#grading-date").text(grading_date);$("#grading-description").text(grading_description);const modal=document.querySelectorAll(".side-modal")[0];M.Sidenav.getInstance(modal).open();} function setupPickers(){var date_object=new Date();let elems=document.querySelectorAll('#datepicker-add');let options={autoClose:true,format:"dd.mm.yyyy",defaultDate:date_object,setDefaultDate:true,firstDay:1} instances=M.Datepicker.init(elems,options);} - -document.addEventListener("DOMContentLoaded",()=>{checkLogin();var calendarEl=document.getElementById("calendar");calendar_obj=new FullCalendar.Calendar(calendarEl,{firstDay:1,plugins:["dayGrid"],defaultDate:getDateString(),navLinks:false,editable:false,events:[],eventClick:gradingClickHandler,height:"parent"});calendar_obj.render();loadGradings(true);$("#refresh-icon").click(()=>{loadGradings(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});}); +document.addEventListener("DOMContentLoaded",()=>{checkLogin();var calendarEl=document.getElementById("calendar");calendar_obj=new FullCalendar.Calendar(calendarEl,{firstDay:1,plugins:["dayGrid"],defaultDate:getDateString(),navLinks:false,editable:false,events:[],eventClick:gradingClickHandler,height:"parent"});calendar_obj.render();loadGradings(true);$("#refresh-icon").click(()=>{loadGradings(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 diff --git a/dist/js/gsec.js b/dist/js/gsec.js index 7925d00..36d49a5 100644 --- a/dist/js/gsec.js +++ b/dist/js/gsec.js @@ -4,7 +4,7 @@ function stripHtml(html){var tmp=document.createElement("DIV");tmp.innerHTML=htm function slDayToInt(inputString){let fourChars=inputString.substring(1,5);let fourCharDays=["oned","orek","reda","etrt","etek","obot","edel"];return fourCharDays.indexOf(fourChars);} const GSE_URL="https://zgimsis.gimb.tk/gse/";const GSEC_ERR_NET="GSEC NETWORK ERROR (ajax error)";const GSEC_ERR_NET_POSTBACK_GET="GSEC NETWORK ERROR (ajax error) in postback GET" const GSEC_ERR_NET_POSTBACK_POST="GSEC NETWORK ERROR (ajax error) in postback POST" -const GSEC_MSGTYPE_RECEIVED=0;const GSEC_MSGTYPE_SENT=1;const GSEC_MSGTYPE_DELETED=2;const GSEC_ERR_LOGIN="GSEC LOGIN ERROR";const GSEC_NO_ABSENCES="noAbsences";const GSEC_MSGTYPES=["msgReceived","msgSent","msgDeleted"];class gsec{constructor(){} +const GSEC_MSGTYPE_RECEIVED=0;const GSEC_MSGTYPE_SENT=1;const GSEC_MSGTYPE_DELETED=2;const GSEC_ERR_LOGIN="GSEC LOGIN ERROR";const GSEC_NO_ABSENCES="noAbsences";const GSEC_MSGTYPES=["msgReceived","msgSent","msgDeleted"];const GSEC_NORMAL_GRADE="GSEC NORMAL GRADE";const GSEC_ZAKLJUCNA_GRADE="GSEC ZAKLJUCNA GRADE";class gsec{constructor(){} parseAndPost(inputHTML,params,formId=null,useDiffAction=null){return new Promise((resolve,reject)=>{let parser=new DOMParser();let parsed=parser.parseFromString(inputHTML,"text/html");var form;if(formId==null){form=parsed.getElementsByTagName("form")[0];}else{form=parsed.getElementById(formId);} var otherParams=$(form).serializeArray();for(const input of otherParams){if(!(input.name in params)){params[input.name]=input.value;}} var action;if(useDiffAction==null||useDiffAction==false){action=new URL($(form).attr("action"),GSE_URL);}else{action=useDiffAction;} @@ -32,12 +32,13 @@ var dataToBeSent={"ctl00$ContentPlaceHolder1$edtDatZacetka":`${fromDate.getDay() var absences=[];for(const izostanek of rowElements){var subFields=izostanek.getElementsByTagName("td");var date=subFields[0].innerHTML.trim().split(".");var dateObj=new Date(Date.parse(`${date[2]}-${date[1]}-${date[0]}`));var subjects=[];subFields[2].innerHTML.match(SUBJECT_LIST_REGEX).forEach((subject)=>{subjects.push(subject);});var absencesBySubject={};for(const subject of subjects){const matched_info=FIELDS_REGEX.exec(subject);var subjectName=matched_info[1];var status=Number(matched_info[2]);var period=matched_info[3];period=period.includes("P")?Number(period.replace("P",""))+7:Number(period);absencesBySubject[period]={status:status,subject:subjectName};} absences.push({subjects:absencesBySubject,date:dateObj});} resolve(absences);});});} -fetchGrades(){var grades=[];return new Promise((resolve,reject)=>{$.ajax({xhrFields:{withCredentials:true},crossDomain:true,url:GSE_URL+"Page_Gim/Ucenec/OceneUcenec.aspx",cache:false,type:"GET",dataType:"html",processData:false,success:(data)=>{let parser=new DOMParser();let parsed=parser.parseFromString(data,"text/html");let gradeSpans=parsed.getElementsByClassName("txtVOcObd");for(const grade of gradeSpans){var ist=grade.getElementsByTagName("span")[0].getAttribute("title").split("\n");var date=ist[0].split(": ")[1].trim().split(".");var dateObj=new Date(Date.parse(`${date[2]}-${date[1]}-${date[0]}`));var teacher=ist[1].split(": ")[1].trim();var subject=ist[2].split(": ")[1].trim();var name=[];name.push(ist[3].split(": ")[1].trim()) +fetchGrades(){var grades=[];return new Promise((resolve,reject)=>{$.ajax({xhrFields:{withCredentials:true},crossDomain:true,url:GSE_URL+"Page_Gim/Ucenec/OceneUcenec.aspx",cache:false,type:"GET",dataType:"html",processData:false,success:(data)=>{let parser=new DOMParser();let parsed=parser.parseFromString(data,"text/html");let gradeSpans=parsed.getElementsByClassName("txtVOcObd");for(const grade of gradeSpans){var ist=grade.getElementsByTagName("span")[0].getAttribute("title").split("\n");if(ist.length==1){var gradeToAdd={"gradeType":GSEC_ZAKLJUCNA_GRADE,"grade":Number(grade.getElementsByTagName("span")[0].innerHTML),"subject":grade.parentElement.parentElement.parentElement.parentElement.getElementsByTagName("th")[0].innerText} +grades.push(gradeToAdd);}else{var date=ist[0].split(": ")[1].trim().split(".");var dateObj=new Date(Date.parse(`${date[2]}-${date[1]}-${date[0]}`));var teacher=ist[1].split(": ")[1].trim();var subject=ist[2].split(": ")[1].trim();var name=[];name.push(ist[3].split(": ")[1].trim()) name.push(ist[4].split(": ")[1].trim()) name.push(ist[5].split(": ")[1].trim()) -var gradeNumber=Number(grade.getElementsByTagName("span")[0].innerHTML);var temporary=grade.getElementsByTagName("span")[0].classList.contains("ocVmesna");var gradeToAdd={"date":dateObj,"teacher":teacher,"subject":subject,"name":name,"temporary":temporary,"grade":gradeNumber};if(grade.getElementsByTagName("span").length>1){if(grade.getElementsByTagName("span")[1].classList.contains("ocVmesna")){gradeToAdd["temporary"]=true;}else{gradeToAdd["temporary"]=false;} +var gradeNumber=Number(grade.getElementsByTagName("span")[0].innerHTML);var temporary=grade.getElementsByTagName("span")[0].classList.contains("ocVmesna");var gradeToAdd={"gradeType":GSEC_NORMAL_GRADE,"date":dateObj,"teacher":teacher,"subject":subject,"name":name,"temporary":temporary,"grade":gradeNumber};if(grade.getElementsByTagName("span").length>1){if(grade.getElementsByTagName("span")[1].classList.contains("ocVmesna")){gradeToAdd["temporary"]=true;}else{gradeToAdd["temporary"]=false;} gradeToAdd["grade"]=Number(grade.getElementsByTagName("span")[1].innerHTML);gradeToAdd["oldgrade"]=Number(grade.getElementsByTagName("span")[0].innerHTML);} -grades.push(gradeToAdd);} +grades.push(gradeToAdd);}} resolve(grades);},error:()=>{reject(new Error(GSEC_ERR_NET));}});});} fetchMessageOld(selectId){const TIME_REGEX=/ \(.+ (.+?)\)/;const DATE_REGEX=/ \(.+? /;const SENDER_REGEX=/^(.+?) \(/;var message;return new Promise((resolve)=>{var dataToBeSent={"__EVENTTARGET":"ctl00$ContentPlaceHolder1$gvwSporocila","__EVENTARGUMENT":"Select$"+selectId};this.postback(GSE_URL+"Page_Gim/Uporabnik/Sporocila.aspx",dataToBeSent,null,true).then((response)=>{let parser=new DOMParser();let parsed=parser.parseFromString(response.data,"text/html");let subject=parsed.getElementsByClassName("msgSubjectS")[0].innerHTML.trim();let body=parsed.getElementsByClassName("gCursorAuto")[0].innerHTML.trim();let sender=SENDER_REGEX.exec(parsed.querySelectorAll("[id$=Label7]")[0].innerHTML)[1];let recipient=parsed.querySelectorAll("[id$=Label8]")[0].innerHTML;var date=DATE_REGEX.exec(parsed.querySelectorAll("[id$=Label7]")[0].innerHTML)[1];var tume=TIME_REGEX.exec(parsed.querySelectorAll("[id$=Label7]")[0].innerHTML)[1];var dateObj=new Date(Date.parse(`${date[2]}-${date[1]}-${date[0]} ${tume}`));var msgId=parsed.getElementById("ctl00_ContentPlaceHolder1_hfIdSporocilo").getAttribute("value");message={"subject":subject,"body":body,"sender":sender,"recipient":recipient,"date":dateObj,"msgId":msgId};resolve(message);});});} fetchMessagesLastPageNumber(category=GSEC_MSGTYPE_RECEIVED){var msgCategory=GSEC_MSGTYPES[category];return new Promise((resolve)=>{var dataToBeSent={"ctl00$ContentPlaceHolder1$ddlPrikaz":msgCategory,"__EVENTARGUMENT":"Page$Last","__EVENTTARGET":"ctl00$ContentPlaceHolder1$gvwSporocila"};this.postback(GSE_URL+"Page_Gim/Uporabnik/Sporocila.aspx",dataToBeSent,null,true).then((response)=>{let parser=new DOMParser();let parsed=parser.parseFromString(response.data,"text/html");let currentPage;if(parsed.getElementsByClassName("pager").length==0){currentPage=1;}else{currentPage=Number(parsed.getElementsByClassName("pager")[0].getElementsByTagName("span")[0].innerHTML);} |