visual.js 9.28 KB

function showAttendance(student_rows, attendance_rows){
	var student = student_rows.result;
	var attendance = attendance_rows.result;

	for(var i = 0; i < student.length; i++){
		if($('#' + student[i].student_id).length <= 0){
			if(student[i].status == undefined){
				$("#student-table > tbody:last").append('<tr id="' + student[i].student_id + '"><td>' + student[i].student_id + '</td>' + '<td>' + student[i].student_name + '</td>' + '<td>' + '출석 정보 없음' + '</td>' +'<td class="bg-danger">' + '결석' + '</td>' +  '</tr>')
			}else{
				$("#student-table > tbody:last").append('<tr id="' + student[i].student_id + '"><td>' + student[i].student_id + '</td>' + '<td>' + student[i].student_name + '</td>' + '<td>' + student[i].timestamp + '</td>' +'<td class="bg-danger">' + '결석' + '</td>' +  '</tr>')

			}
		}
	}
	
	for(var i = 0; i < attendance.length; i++){
		if (attendance[i].status == 'attend')
		{
			$('#' + attendance[i].student_id).remove();
			$("#student-table > tbody:last").prepend('<tr id="' + attendance[i].student_id + '"><td>' + attendance[i].student_id + '</td>' + '<td>' + attendance[i].student_name + '</td>' + '<td>' + attendance[i].timestamp + '</td>' +'<td class="bg-primary">' + '출석' + '</td>' +  '</tr>')

		}
		else if (attendance[i].status == 'late')
		{
			$('#' + attendance[i].student_id).remove();
			$("#student-table > tbody:last").prepend('<tr id="' + attendance[i].student_id + '"><td>' + attendance[i].student_id + '</td>' + '<td>' + attendance[i].student_name + '</td>' + '<td>' + attendance[i].timestamp + '</td>' +'<td class="bg-warning">' + '지각' + '</td>' +  '</tr>')

		}
		else if (attendance[i].status == 'absent')
		{
			$('#' + attendance[i].student_id).remove();
			$("#student-table > tbody:last").prepend('<tr id="' + attendance[i].student_id + '"><td>' + attendance[i].student_id + '</td>' + '<td>' + attendance[i].student_name + '</td>' + '<td>' + attendance[i].timestamp + '</td>' +'<td class="bg-danger">' + '결석' + '</td>' +  '</tr>')

		}
	}
}

function showRequest(request_rows){
	var student = request_rows.result;
	
	$("#student-request-table > tbody").empty();
	for(var i = 0; i < student.length; i++){
		if($('#request' + student[i].student_id).length <= 0){
			if(student[i].status == "pending"){
				$("#student-request-table > tbody:last").append('<tr id="request' + student[i].student_id + '"><td>' + student[i].student_id + '</td>' + '<td>' + student[i].student_name + '</td>' + '<td>' + student[i].timestamp + '</td>' +'<td class="bg-secondary">' + student[i].status + '</td>' + '<td><button class="btn btn-primary" onclick="requestHandle(' +student[i].id + ', '+ student[i].student_id + ', \''+ student[i].student_name + '\', \'attend\')">출석</button><button class="btn btn-warning" onclick="requestHandle(' +student[i].id + ', '+ student[i].student_id + ', \''+ student[i].student_name + '\', \'late\')">지각</button><button class="btn btn-danger" onclick="requestHandle(' +student[i].id + ', '+ student[i].student_id + ', \''+ student[i].student_name + '\', \'absent\')">결석</button></td></tr>')

			}
			else if(student[i].status == "attend"){
				$("#student-request-table > tbody:last").append('<tr id="request' + student[i].student_id + '"><td>' + student[i].student_id + '</td>' + '<td>' + student[i].student_name + '</td>' + '<td>' + student[i].timestamp + '</td>' +'<td class="bg-primary">' + student[i].status + '</td>' + '<td><button class="btn btn-primary" onclick="requestHandle(' +student[i].id + ', '+ student[i].student_id + ', \''+ student[i].student_name + '\', \'attend\')">출석</button><button class="btn btn-warning" onclick="requestHandle(' +student[i].id + ', '+ student[i].student_id + ', \''+ student[i].student_name + '\', \'late\')">지각</button><button class="btn btn-danger" onclick="requestHandle(' +student[i].id + ', '+ student[i].student_id + ', \''+ student[i].student_name + '\', \'absent\')">결석</button></td></tr>')

			}
			else if(student[i].status == "absent"){
				$("#student-request-table > tbody:last").append('<tr id="request' + student[i].student_id + '"><td>' + student[i].student_id + '</td>' + '<td>' + student[i].student_name + '</td>' + '<td>' + student[i].timestamp + '</td>' +'<td class="bg-danger">' + student[i].status + '</td>' + '<td><button class="btn btn-primary" onclick="requestHandle(' +student[i].id + ', '+ student[i].student_id + ', \''+ student[i].student_name + '\', \'attend\')">출석</button><button class="btn btn-warning" onclick="requestHandle(' +student[i].id + ', '+ student[i].student_id + ', \''+ student[i].student_name + '\', \'late\')">지각</button><button class="btn btn-danger" onclick="requestHandle(' +student[i].id + ', '+ student[i].student_id + ', \''+ student[i].student_name + '\', \'absent\')">결석</button></td></tr>')
			}
			else if(student[i].status == "late"){
				$("#student-request-table > tbody:last").append('<tr id="request' + student[i].student_id + '"><td>' + student[i].student_id + '</td>' + '<td>' + student[i].student_name + '</td>' + '<td>' + student[i].timestamp + '</td>' +'<td class="bg-warning">' + student[i].status + '</td>' + '<td><button class="btn btn-primary" onclick="requestHandle(' +student[i].id + ', '+ student[i].student_id + ', \''+ student[i].student_name + '\', \'attend\')">출석</button><button class="btn btn-warning" onclick="requestHandle(' +student[i].id + ', '+ student[i].student_id + ', \''+ student[i].student_name + '\', \'late\')">지각</button><button class="btn btn-danger" onclick="requestHandle(' +student[i].id + ', '+ student[i].student_id + ', \''+ student[i].student_name + '\', \'absent\')">결석</button></td></tr>')
			}
		}
	}
	
}

function showImage(request_rows){
	var image = request_rows.result;
	
	$("#student-image-table > tbody").empty();
	for(var i = 0; i < image.length; i++){
		var bytes, blob;
		bytes = new Uint8Array(image[i].image);
		blob = new Blob([bytes], {type:'image/bmp'});
		var url = URL.createObjectURL(blob);

		if($('#request' + image[i].image).length <= 0){
			$("#student-image-table > tbody:last").append('<tr id="request' + image[i].image + '"><td><img src="' + url + '"/></td>' + '<td>' + image[i].timestamp + '</td></tr>')
		}
	}
	
}

function checkAttendance(){
	var lecture_id = '0'
	var url = '/lecture_student/' + lecture_id;
	var url2='/attendance/' + lecture_id;
	
	var student_rows;
	var attendance_rows;
	$.ajax({
		async: false,
		type: "GET",
		url: url,
		success: function(rows){
			student_rows = rows
			return 0;
		},
		error: function(xhr, status, err){
			var err = '';
			$.each(JSON.parse(xhr.responseText), function(i, item){
				err += '<li>' + item.msg + '</li>';
			});
			return 0;
		}
	});

	$.ajax({
		async: false,
		type: "GET",
		url: url2,
		success: function(rows){
			attendance_rows = rows
			return 0;
		},
		error: function(xhr, status, err){
			var err = '';
			$.each(JSON.parse(xhr.responseText), function(i, item){
				err += '<li>' + item.msg + '</li>';
			});
			return 0;
		}
	});
	showAttendance(student_rows, attendance_rows)
}

function checkRequest(){
	var lecture_id = '0'
	var url = '/admin/' + lecture_id;
	
	var request_rows;
	$.ajax({
		async: false,
		type: "GET",
		url: url,
		success: function(rows){
			request_rows = rows
			return 0;
		},
		error: function(xhr, status, err){
			var err = '';
			$.each(JSON.parse(xhr.responseText), function(i, item){
				err += '<li>' + item.msg + '</li>';
			});
			return 0;
		}
	});

	showRequest(request_rows)
}

function checkImage(){
	var lecture_id = '0'
	var url = '/admin/image/' + lecture_id;
	
	var request_rows;
	$.ajax({
		async: false,
		type: "GET",
		url: url,
		success: function(rows){
			request_rows = rows
			return 0;
		},
		error: function(xhr, status, err){
			var err = '';
			$.each(JSON.parse(xhr.responseText), function(i, item){
				err += '<li>' + item.msg + '</li>';
			});
			return 0;
		}
	});

	showImage(request_rows)
}

function addRequest(){
	var lecture_id = '0'
	var url = '/admin/request/' + lecture_id;

	var formData = $("#adminForm").serialize();

	$.ajax({
		async: false,
		type: "POST",
		url: url,
		data: formData,
		success: function(rows){
			attendance_rows = rows
			return 0;
		},
		error: function(xhr, status, err){
			var err = '';
			console.log(xhr);
			$.each(JSON.parse(xhr.responseText), function(i, item){
				err += '<li>' + item.msg + '</li>';
			});
			return 0;
		}
	});
	window.location.reload();
}

function requestHandle(request_id, student_id, student_name, status){
	var lecture_id = '0'
	var url = '/admin/attend';
	var url2 = '/admin/solve';

	var formData1 = {
		"request_id": request_id,
		'lecture_id': lecture_id,
		"student_id" : student_id,
		"student_name": student_name,
		"status": status 
	};

	$.ajax({
		async: false,
		type: "POST",
		url: url,
		dataType: 'json',
		data: formData1,
		success: function(rows){
			attendance_rows = rows
		},
		error: function(xhr, status, err){
			var err = '';
			$.each(JSON.parse(xhr.responseText), function(i, item){
				err += '<li>' + item.msg + '</li>';
			});
		}
	});

	$.ajax({
		async: false,
		type: "POST",
		url: url2,
		dataType: 'json',
		data: formData1,
		success: function(rows){
			attendance_rows = rows
			return 0;
		},
		error: function(xhr, status, err){
			var err = '';
			console.log(xhr);
			$.each(JSON.parse(xhr.responseText), function(i, item){
				err += '<li>' + item.msg + '</li>';
			});
			return 0;
		}
	});

	checkAttendance();
	checkRequest();
}