apollodec/Apollo/assets/js/controllers/schCtrl.js
2019-02-15 18:02:42 +05:30

797 lines
23 KiB
JavaScript

'use strict';
/**
* controllers for ng-table
* Simple table with sorting and filtering on AngularJS
*/
app.controller('schCtrl', ["$scope","$rootScope","toaster", "$filter", "ngTableParams", "API_POINTS", "$sessionStorage", "$http", "$state", function ($scope,$rootScope,toaster, $filter, ngTableParams, apiPoint, $sessionStorage, $http, $state) {
$scope.myModel = {
"studentName": "",
"mobileNumber": "",
"universityName":"",
"semsterName":""
};
$scope.myModelAdd = {
"date": "",
"periodStart": "",
"periodEnd":"",
};
$scope.details = [];
$scope.viewPage = {
"CourseDetails":[]
};
$scope.editId = -1;
$scope.editModel = {
"editSubject": "",
"editScheduleDate": "",
"editFromTime":"",
"editToTime":"",
};
$scope.semDropDownShowLoading1 = false;
$scope.semDetailsLoadingStatus1 = false;
$scope.semDetailsLoadingTxt1 = "";
$scope.setEditId = function (pid,cid,schid,subid,c) {
var branchid=JSON.parse(sessionStorage.getItem('localObj')).localBranchID;
$scope.semDetailsLoadingStatus1 = true;
$scope.semDetailsLoadingTxt1 = "Loading...";
//alert(branchid);
//alert(pid);
$scope.editModel.editSubject = c.SubjectName;
$scope.editModel.editScheduleDate = c.ScheduleDate;
$scope.editModel.editFromTime = c.FromTime;
$scope.editModel.editToTime = c.ToTime;
//$scope.localUniversityDetails="";
//$scope.localUniversityDetails = JSON.parse(sessionStorage.getItem('localUniversityDetails'));
$scope.editId = pid;
$scope.courseCode = cid;
$scope.mappingid = schid;
//$scope.sample=subid;
$scope.sample1=c;
//alert(mappingid+'n');
var getsheduledetails = {
method: 'POST',
url: apiPoint.url + 'getSheduleDetails/',
headers: {
'Content-Type': 'application/json'
},
data: {
//requestedBy: JSON.parse(sessionStorage.getItem('localObj')).localUserID,
mapid:$scope.mappingid,
subid:subid,
branchcode:branchid,
courseDetails:$scope.sample1
}
};
$http(getsheduledetails).then(function (response) {
if (response.data.status==200)
{
$scope.unsheduledetails=response.data.getunSheduleDetailsinfo.scheduleDetails;
} else {
$scope.unsheduledetails="";
}
});
};
// $scope.details = [];
$scope.cancel = function () {
$scope.init();
$scope.editId = -1;
};
$scope.semDropDownShow = false;
$scope.semDropDownShowLoading = false;
$scope.saveButtonDisabled = false;
$scope.saveButtonTxt = "SAVE";
$rootScope.userType = JSON.parse(sessionStorage.getItem('localObj')).localType;
$scope.semDetailsLoadingStatus = false;
$scope.semDetailsLoadingTxt = "";
$scope.selectedCourseName = [];
$scope.selectedUniversityCourseName = '';
$scope.selectedSemSubjetcsSem1 = [];
$scope.selectedSemSubjetcsSem2 = [];
$scope.selectedSemSubjetcsSem3 = [];
$scope.selectedSemSubjetcsSem4 = [];
$scope.selectedSemSubjetcsSem5 = [];
$scope.selectedSemSubjetcsSem6 = [];
$scope.selectedSemSubjetcsSem7 = [];
$scope.selectedSemSubjetcsSem8 = [];
$scope.overallSelectedSubjetcs = [];
// sorting function for table params
$scope.sort = function(keyname){
$scope.sortKey = keyname; //set the sortKey to the param passed
$scope.reverse = !$scope.reverse; //if true make it false and vice versa
}
//Assign Courses to Course array for Multiple select
$scope.getuniversity = function(){
$scope.selectedUniversityCourseName = $scope.myModel.universityName.courseDetails;
if($scope.selectedUniversityCourseName.length == 0){ swal('No Courses Available','','info'); }
$scope.selectedCourseNameC = {
list: $scope.selectedCourseName,
}
}
$scope.Sem_Year_Details='';
$scope.check = function(selectedCourseNameC)
{
var first_CourseId = selectedCourseNameC.first();
console.log(first_CourseId)
if((first_CourseId == '')||(first_CourseId == undefined) ||(first_CourseId == null))
{
$scope.Sem_Year_Details='';
}
var get_CourseSem_details = {
method: 'POST',
url: apiPoint.url + 'CourseSemDetails/',
headers: {
'Content-Type': 'application/json'
},
data: {
CourseId: first_CourseId,
branch: JSON.parse(sessionStorage.getItem('localObj')).localBranchID
}
}
$http(get_CourseSem_details).then(function (response) {
// console.log(response.data.status);
if(response.data.status == 200)
{
$scope.Sem_Year_Details = response.data.details
//console.log($scope.Sem_Year_Details);
}
});
}
Array.prototype.first = function ()
{
return this[0];
};
/*
* get course semester,subjects details
* created by TamilBala
* */
var course='';
$scope.getSemSubDetails = function(UID,COURSES){
course=COURSES;
//console.log($scope.myModel.Sem_Year);return false;
var firstError = null;
if (form.$invalid) {
var field = null, firstError = null;
for (field in form) {
if (field[0] != '$') {
if (firstError === null && !form[field].$valid) {
firstError = form[field].$name;
}
if (form[field].$pristine) {
form[field].$dirty = true;
}
}
}
angular.element('.ng-invalid[name=' + firstError + ']').focus();
}
else
{
var Sem_Year =$scope.myModel.Sem_Year;
if(UID == undefined || UID == '')
{
swal("Select University");
return false;
}
if(COURSES.list == '')
{
swal("Select Course");
return false;
}
if(Sem_Year == undefined || Sem_Year =='')
{
swal("Select Sem/Year");
return false;
}
$scope.editId=1;
$scope.semDropDownShowLoading = false;
$scope.semDropDownShow = false;
$scope.semDropDownShowLoading = true;
var getsubject = {
method: 'POST',
url: apiPoint.url + 'getExistingMapping/',
headers: {
'Content-Type': 'application/json'
},
data: {
universityID : UID,
courseID : COURSES,
Sem_Year : Sem_Year,
requestedBy: JSON.parse(sessionStorage.getItem('localObj')).localUserID,
branchId:JSON.parse(sessionStorage.getItem('localObj')).localBranchID
}
};
$http(getsubject).then(function (response) {
console.log(response);
if(response.data.status == 200)
{
$scope.semDropDownShowLoading = false;
$scope.semDropDownShow = true;
$scope.subjects = [];// For Main Dropdown
$scope.subjectsFromDBtoComapare = [];
//$scope.semesters = response.data.semesterDetails;
$scope.subjectsFromDB = response.data.subjectDetails; //Store Response Data to subjectsFromDB
angular.forEach($scope.subjectsFromDB,function(value,key){
$scope.subjects.push({
"Subject":value,
"ScheduleDate":"",
"ScheduleStartTime":"",
"ScheduleEndTime":""
});// For Main Dropdown
});
}
},function(error){
$scope.semDropDownShowLoading = false;
swal(error.data.message,'','error');
$state.go($state.current, {}, {reload: true});
} );
}
}
$scope.remove = function () {
$scope.init();
$scope.semDropDownShow = false;
};
/*
* Remove Subjects from Master Subjects Arry
* after selecting subjects for each semester
* created by TamilBala
* */
$scope.removeSelectedSubjetcs = function(newsublist){
//Every time copy all subjetcs from subjectsFromDB to ompare
angular.forEach($scope.subjectsFromDB,function(value,key){
$scope.subjectsFromDBtoComapare.push(value);
});
//For Compare Single Semesters Array and Master Subjetcs Array and remove selected subjects from Master Subjetcs Array
angular.forEach(newsublist,function(value,key){
angular.forEach($scope.subjects,function(value2,key2){
if(value.SubjectID == value2.SubjectID)
{
$scope.subjects.splice(key2,1);
}
});
});
//For Concat all subjetcs from all semsters.
$scope.overallSelectedSubjetcs=[].concat($scope.selectedSubjetcsSem1C.list,$scope.selectedSubjetcsSem2C.list,$scope.selectedSubjetcsSem3C.list,$scope.selectedSubjetcsSem4C.list,$scope.selectedSubjetcsSem5C.list,$scope.selectedSubjetcsSem6C.list,$scope.selectedSubjetcsSem7C.list,$scope.selectedSubjetcsSem8C.list);
//For Compare Over all selected subjects And Master Subjetcs to avoid duplicate.
angular.forEach($scope.overallSelectedSubjetcs,function(value,key){
angular.forEach($scope.subjectsFromDBtoComapare,function(value2,key2){
if(value.SubjectID != value2.SubjectID)
{
if ($scope.overallSelectedSubjetcs.indexOf(value2) == -1 && $scope.subjects.indexOf(value2) == -1)
{
$scope.subjects.push(value2);
$scope.subjectsFromDBtoComapare.splice(key2,1);
}
}
});
});
$scope.subjectsFromDBtoComapare = [];
}
var date= '';
var stime= '';
var etime='';
var subjectname= '';
var subjectcode = '';
var c='';
var subid='';
var subjectId= '';
$scope.details = [];
$scope.add= function(index,myModelAdd,p)
{
var subname = p.SubjectName;
var item=[];
c = $scope.details.length + 1;
var formate = "dd-MM-yyyy";
date = $filter('date')(new Date(myModelAdd.date), formate);
stime = myModelAdd.periodStart;
etime = myModelAdd.periodEnd;
subjectname = p.SubjectName;
subjectcode = p.SubjectCode;
subid = p.SubjectID;
item.push({
date : date,
stime : stime,
etime : etime,
subjectname : subjectname,
subjectcode : subjectcode,
subjectId : subid
});
$scope.details.splice(0,0,item);
}
/* upload file for batch schedule
* created by bala
* */
$scope.extractFileDetails="";
$scope.readUploadBatchDetails = function (workbook) {
/* DO SOMETHING WITH workbook HERE */
for (var sheetName in workbook.Sheets) {
var jsonData = XLSX.utils.sheet_to_json(workbook.Sheets[sheetName]);
if(jsonData.length!=0){
$scope.extractFileDetails=jsonData;
}
}
$scope.error = function (e) {
/* DO SOMETHING WHEN ERROR IS THROWN */
//console.log(e);
}
}
/*upload file and extract data Created By bala */
$scope.UploadFileData = function (FileDetails,myModel,courseDetails) {
$scope.courseDetailsArray=courseDetails.list;
$scope.universityDetails=myModel.universityName.universityID;
// //console.log($scope.universityDetails);
// $scope.scheduledDetails=[];
// $scope.scheduledDetails.push({
// "universityID":myModel.universityName.universityID,
// });
// console.log(myModel);
// return false;
var updateUniversityEnrolment = {
method: 'POST',
url: apiPoint.url + 'batchUploadDataDetails/',
headers: {
'Content-Type': 'application/json'
},
data: {
details: FileDetails,
universityDetails : $scope.universityDetails,
courseDetails : $scope.courseDetailsArray,
Sem_Year : myModel.Sem_Year,
requestedBy: JSON.parse(sessionStorage.getItem('localObj')).localUserID,
branchId:JSON.parse(sessionStorage.getItem('localObj')).localBranchID
}
};
$http(updateUniversityEnrolment).then(function (response) {
//console.log(response);
if (response.data.status == 200) {
swal("", "Saved Successfully", "success");
$state.go($state.current, {}, {reload: true});
} else {
swal("",response.data.message, "error");
$state.go($state.current, {}, {reload: true});
}
},function(error){
$scope.semDropDownShowLoading = false;
swal(error.data.message,'','error');
$state.go($state.current, {}, {reload: true});
} );
}
// end
$scope.saveAll= function(myModel,courseDetails,subjectsDetails)
{
$scope.courseDetailsArray=courseDetails.list;
//console.log(myModel.Sem_Year);return false;
$scope.scheduledDetails=[];
angular.forEach(subjectsDetails,function (value) {
if((value.ScheduleDate!='' && value.ScheduleDate!=undefined) && (value.ScheduleStartTime!='' && value.ScheduleStartTime!=undefined) && (value.ScheduleEndTime!='' && value.ScheduleEndTime!=undefined)){
// var timeToaddAM = "05:30:00";
// var timeToaddPM = "15:30:00";
// var tempDate = $filter('date')(value.ScheduleDate, 'yyyy-MM-dd');
// var ScheduleStartTime = value.ScheduleStartTime;
// var STARTAMPM = ScheduleStartTime.substr(-2);
// var ScheduleStartTime = ScheduleStartTime.substr(0,5)+":00";
// console.log('ScheduleStartTime'+ScheduleStartTime);
// var timeToAddArr = "";
// if(STARTAMPM == 'AM' || STARTAMPM == 'am')
// {
// timeToAddArr = timeToaddAM.split(":");
// }else { timeToAddArr = timeToaddPM.split(":"); }
// var ms = (60 * 60 * parseInt(timeToAddArr[0]) + 60 * (parseInt(timeToAddArr[1])) ) * 1000;
// var newStartTime =new Date('1970-01-01T' + ScheduleStartTime ).getTime() + ms
// var finalStartTime = new Date(newStartTime).toLocaleString('en-GB').slice(12 ,20);
// finalStartTime = tempDate+'T'+finalStartTime+':000Z';
// console.log(finalStartTime);
// var ScheduleEndTime = value.ScheduleEndTime;
// var ENDAMPM = ScheduleEndTime.substr(-2);
// var ScheduleEndTime = ScheduleEndTime.substr(0,5)+":00";
// console.log('ScheduleEndTime'+ScheduleEndTime);
// var timeToAddArr2 = '';
// if(ENDAMPM == 'AM' || ENDAMPM == 'am')
// {
// timeToAddArr2 = timeToaddAM.split(":");
// }else { timeToAddArr2 = timeToaddPM.split(":"); }
// var ms2 = (60 * 60 * parseInt(timeToAddArr2[0]) + 60 * (parseInt(timeToAddArr2[1])) ) * 1000;
// var newEndTime =new Date('1970-01-01T' + ScheduleEndTime ).getTime() + ms2
// var finalEndTime = new Date(newEndTime).toLocaleString('en-GB').slice(12 ,20);
// finalEndTime = tempDate+'T'+finalEndTime+':000Z';
// console.log(finalEndTime);
$scope.scheduledDetails.push({
"universityID":myModel.universityName.universityID,
//"courseID":courseDetails.list[0],
"subjectID":value.Subject.SubjectID,
"scheduleDate":$filter('date')(value.ScheduleDate, 'dd-MM-yyyy'),
"scheduleStart":value.ScheduleStartTime,
"scheduleEnd":value.ScheduleEndTime,
});
}
});
//return false;
var saveAllInfo = {
method: 'POST',
url: apiPoint.url + 'saveBatchSchedule/',
headers: {
'Content-Type': 'application/json'
},
data: {
getuniversityid :myModel.universityName.universityID,
//getcourseid :courseDetails.list[0],
courseDetails : $scope.courseDetailsArray,
scheduleDetails : $scope.scheduledDetails,
Sem_Year : myModel.Sem_Year,
requestedBy: JSON.parse(sessionStorage.getItem('localObj')).localUserID,
branchId:JSON.parse(sessionStorage.getItem('localObj')).localBranchID
}
};
$http(saveAllInfo).then(function(response)
{
//console.log(status);
if (response.data.status==200)
{
swal(" Saved successfully", "", "success");
//$scope.init();
$state.go($state.current, {}, {reload: true});
}
},function(error){
swal('Some Thing Went Wrong!','Try Later','error');
$state.go($state.current, {}, {reload: true});
});
}
$scope.updateShedule = function (unsheduledetails) {
$scope.UpdatescheduledDetails=[];
angular.forEach(unsheduledetails,function (value) {
if((value.ScheduleDate!='' && value.ScheduleDate!=undefined) && (value.FromTime!='' && value. FromTime!=undefined) && (value.ToTime!='' && value.ToTime!=undefined)){
$scope.UpdatescheduledDetails.push({
"SchId":value.SchId,
"SubjectID":value.SubjectID,
"schChildId":value.SchChildId,
"scheduleDate":$filter('date')(value.ScheduleDate, 'dd-MM-yyyy'),
"scheduleStart":value.FromTime,
"scheduleEnd":value.ToTime,
});
}
});
var update = {
method: 'POST',
url: apiPoint.url + 'updateSheduleDetails/',
headers: {
'Content-Type': 'application/json'
},
data: {
updatescheduledetails : $scope.UpdatescheduledDetails,
//status: myModel.IsActive,
createdBy: JSON.parse(sessionStorage.getItem('localObj')).localUserID,
scheduleID:$scope.mappingid
}
};
$http(update).then(function (response) {
if (response.data.status==200 ) {
// $scope.ldloading[loading.replace('-', '_')] = false;
//
swal("", "Saved Successfully.", "success");
//$scope.editId = -1;
// $scope.init();
$state.go($state.current, {}, {reload: true});
} else {
$scope.ldloading[loading.replace('-', '_')] = false;
swal("", response.data.message,"error");
$state.go($state.current, {}, {reload: true});
}
});
};
$scope.addForm ={
submit:function(myModelAdd,addmoreItem)
{
//alert();
time = myModelAdd.ScheduleTime;
$scope.details.push({
time:time})
}
};
$scope.processDataforViewPage = function()
{
$scope.viewPage.UniversityID = $scope.existSemesterSubjectMapDetails[0].UniversityID;
$scope.viewPage.UniversityName = $scope.existSemesterSubjectMapDetails[0].UniversityName;
var tArry = [];
angular.forEach($scope.existSemesterSubjectMapDetails,function(value,key){
if(tArry.indexOf(value.CourseID) == -1)
{
tArry.push(value.CourseID);
var tempArray = {'CourseID':value.CourseID,'CourseCode':value.CourseCode,'CourseName':value.CourseName};
$scope.viewPage.CourseDetails.push(tempArray);
}
});
}
/*
* init function
* created by TamilBala
* */
$scope.init = function () {
var logcheck = JSON.parse(sessionStorage.getItem('localObj'));
const LOCALTYPE = logcheck.localType;
if (logcheck != null && (LOCALTYPE == 'R003' || LOCALTYPE == 'R004' || LOCALTYPE == 'R002' || LOCALTYPE == 'R005')) {
console.log("if");
}else {
if(logcheck != null && LOCALTYPE !='R001') {
console.log("else if");
$state.go('app.dashboard');
} else {
console.log("else else");
//ipCookie.remove('cookiechk');
window.sessionStorage.clear();
$state.go('login.signin');
}
}
var branchid=JSON.parse(sessionStorage.getItem('localObj')).localBranchID;
//alert(branchid);
$scope.semDetailsLoadingStatus = true;
$scope.semDetailsLoadingTxt = "Loading...";
var getUniv = {
method: 'POST',
url: apiPoint.url + 'getUniversityCourseDetails/',
headers: {
'Content-Type': 'application/json'
},
data: {
requestedBy: JSON.parse(sessionStorage.getItem('localObj')).localUserID,
branchId:JSON.parse(sessionStorage.getItem('localObj')).localBranchID
}
};
$http(getUniv).then(function (response) {
if (response.data.status==200 && response.data.universityStatus) {
$scope.university=response.data.univerSityDetails;
} else {
$scope.university="";
}
});
$scope.selectedCourseNameC = {
list: $scope.selectedCourseName,
}
/*
* getUnivid function
* created by TamilBala
* */
var getUnivid = {
method: 'POST',
url: apiPoint.url + 'getUniversityCourseId/',
headers: {
'Content-Type': 'application/json'
},
data: {
//requestedBy: JSON.parse(sessionStorage.getItem('localObj')).localUserID,
branchCode:branchid,
}
};
$http(getUnivid).then(function (response) {
if (response.data.status==200)
{
$scope.universitycourse=response.data.getUnivDetailsinfo;
} else {
$scope.universitycourse="";
}
});
}
$scope.batchschedule={
submit: function (form, myModelAdd)
{
var alldata = $("#batchsch");
},
};
$scope.validateTime = function(time,ide){
//alert(time);
var tempTime = time;
var tempID = ide.target.attributes.id.value;
///console.log(tempID);
var arrayTime = time.split(":");
////console.log(!isNaN(arrayTime[0]));
//console.log(!isNaN(arrayTime[1].substr(0,2)));
//console.log(isNaN(arrayTime[1].substr(-2)));
//return false;
if(time.length != 7 || isNaN(arrayTime[0]) || isNaN(arrayTime[1].substr(0,2)) || !isNaN(arrayTime[1].substr(-2))){
swal('Wrong Time Format...!',' Enter as "09:00AM" ','error');
document.getElementById(tempID).value = "";
window.setTimeout(function ()
{
document.getElementById(tempID).focus();
}, 0);
//return false;
}
}
}]);