add login function : can login with account on moodle. add audit function : can show the all applications which need to be audited
This commit is contained in:
parent
4ca4ef1d62
commit
4e70160c94
22
api/audit.js
22
api/audit.js
@ -8,10 +8,9 @@ router.get("/", async function(req, res) {
|
||||
let conn;
|
||||
try {
|
||||
conn = await util.getDBConnection(); // get connection from db
|
||||
const query = ` //語法有問題
|
||||
SELECT
|
||||
item_form.application_id,
|
||||
item_form.item_info_id,
|
||||
const query =
|
||||
`
|
||||
SELECT item_form.application_id, item_form.item_info_id, item_info.item_content,
|
||||
item_form.application_unit,
|
||||
item_form.subsidy,
|
||||
scholarship_application.application_date,
|
||||
@ -20,12 +19,15 @@ router.get("/", async function(req, res) {
|
||||
FROM
|
||||
item_form
|
||||
RIGHT JOIN
|
||||
scholarship_application ON item_form.application_id = scholarship_application.application_id;
|
||||
RIGHT JOIN
|
||||
student ON scholarship_application.student_id = student.student_id;
|
||||
`;
|
||||
const result = await conn.query(query);
|
||||
res.json({ success: true, data: result });
|
||||
scholarship_application ON item_form.application_id = scholarship_application.application_id
|
||||
LEFT JOIN
|
||||
student ON scholarship_application.student_id = student.student_id
|
||||
LEFT JOIN
|
||||
item_info ON item_form.item_info_id = item_info.item_info_id
|
||||
;
|
||||
`;
|
||||
const result = await conn.query(query);
|
||||
res.json({ success: true, data: result });
|
||||
}
|
||||
catch(e) {
|
||||
console.error(e);
|
||||
|
||||
15
api/main.js
15
api/main.js
@ -31,6 +31,12 @@ router.post("/", async function(req, res) {
|
||||
console.log(req.body);
|
||||
// data
|
||||
const apply_infos = req.body.apply_infos; // get data from request
|
||||
const application_units = req.body.application_units;
|
||||
const subsidy_amounts = req.body.subsidy_amounts;
|
||||
const student_id = req.body.student_id;
|
||||
const student_name = req.body.student_name;
|
||||
const department_and_grade = req.body.department_and_grade;
|
||||
const advisor_id = req.body.advisor_name;
|
||||
const time = moment(new Date()).format("YYYY-MM-DD");
|
||||
|
||||
if (!student_id) {
|
||||
@ -40,8 +46,13 @@ router.post("/", async function(req, res) {
|
||||
conn = await util.getDBConnection(); // get connection from db
|
||||
await conn.beginTransaction();
|
||||
|
||||
// insert into student, if not existed
|
||||
const stu_existed = await conn.query("SELECT COUNT(*) FROM student WHERE student_id=?", student_id);
|
||||
if (!stu_existed[0]["COUNT(*)"]) {
|
||||
await conn.batch("INSERT INTO student VALUES(?, ?, ?, ?);", [student_id, department_and_grade, student_name, advisor_id]);
|
||||
}
|
||||
// insert data into table : scholarship_application
|
||||
const scholarship_application_info = await conn.batch("INSERT INTO scholarship_application(`application_date`, `student_id`) VALUES(?, ?);", [time, req.body.student_id]);
|
||||
const scholarship_application_info = await conn.batch("INSERT INTO scholarship_application(`application_date`, `student_id`) VALUES(?, ?);", [time, student_id]);
|
||||
const scholarship_application_id = scholarship_application_info.insertId; // get the application_id of previous record
|
||||
|
||||
// 這邊你們要再改
|
||||
@ -53,7 +64,7 @@ router.post("/", async function(req, res) {
|
||||
|
||||
// insert each apply item into item_form
|
||||
for (let i = 0;i < apply_infos.length;i++) {
|
||||
await conn.batch("INSERT INTO item_form(`application_id`, `item_info_id`, `application_unit`, `subsidy`) VALUES(?, ?, ?, ?);", [scholarship_application_id, apply_infos[i], application_unit, subsidy]);
|
||||
await conn.batch("INSERT INTO item_form(`application_id`, `item_info_id`, `application_unit`, `subsidy`) VALUES(?, ?, ?, ?);", [scholarship_application_id, apply_infos[i], application_units[i], subsidy_amounts[i]]);
|
||||
}
|
||||
await conn.commit();
|
||||
|
||||
|
||||
121
js/audit.js
121
js/audit.js
@ -1,4 +1,8 @@
|
||||
|
||||
let item_info_len = 0;
|
||||
let all_audit_data = null;
|
||||
let current_review_apllication_id;
|
||||
const application_detail_init_table_content = document.getElementById("application_detail").innerHTML;
|
||||
|
||||
async function getItemInfo() {
|
||||
// get the data from table : item_info
|
||||
@ -13,21 +17,106 @@ async function getItemInfo() {
|
||||
}
|
||||
}
|
||||
|
||||
function combineSameAppData(data) {
|
||||
// combine the same application id data in a same record
|
||||
let n_data = {};
|
||||
let next_record = true;
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
if (i > 0 && data[i].application_id != data[i-1].application_id) {
|
||||
// this record is different from the last
|
||||
next_record = true;
|
||||
}
|
||||
if (next_record) {
|
||||
// this is new record
|
||||
next_record = false;
|
||||
// init this record
|
||||
n_data[data[i].application_id] = {};
|
||||
n_data[data[i].application_id].application_id = data[i].application_id;
|
||||
n_data[data[i].application_id].application_date = data[i].application_date;
|
||||
n_data[data[i].application_id].student_id = data[i].student_id;
|
||||
n_data[data[i].application_id].student_name = data[i].student_name;
|
||||
n_data[data[i].application_id].application_units = [data[i].application_unit];
|
||||
n_data[data[i].application_id].item_contents = [data[i].item_content];
|
||||
n_data[data[i].application_id].subsidys = [data[i].subsidy];
|
||||
}
|
||||
else {
|
||||
n_data[data[i].application_id].application_units.push(data[i].application_unit);
|
||||
n_data[data[i].application_id].item_contents.push(data[i].item_content);
|
||||
n_data[data[i].application_id].subsidys.push(data[i].subsidy);
|
||||
}
|
||||
}
|
||||
all_audit_data = n_data;
|
||||
return n_data;
|
||||
}
|
||||
|
||||
function auditCase(application_id) {
|
||||
current_review_apllication_id = application_id;
|
||||
|
||||
// add item content
|
||||
const table_id = "application_detail";
|
||||
document.getElementById(table_id).innerHTML = application_detail_init_table_content;
|
||||
let table_content = document.getElementById(table_id).innerHTML;
|
||||
const data = all_audit_data[application_id];
|
||||
console.log(data);
|
||||
table_content += "<tr>";
|
||||
for (let i = 0;i < data.item_contents.length;i++) {
|
||||
if (data.item_contents[i].includes("已向")) {
|
||||
table_content +=
|
||||
`
|
||||
<td>${data.item_contents[i]} ,申請單位: ${data.application_units[i]} 獲得補助金額:NT$${data.subsidys[i]}</td>
|
||||
`
|
||||
}
|
||||
else {
|
||||
table_content +=
|
||||
`
|
||||
</tr>
|
||||
<tr>
|
||||
<td>${data.item_contents[i]}</td>
|
||||
`
|
||||
}
|
||||
}
|
||||
document.getElementById(table_id).innerHTML = table_content;
|
||||
|
||||
// add simple info
|
||||
document.getElementById("application_info").innerHTML =
|
||||
`
|
||||
申請編號:${data.application_id} <br/>
|
||||
申請日期:${data.application_date} <br/>
|
||||
申請人姓名:${data.student_name} <br/>
|
||||
申請人學號:${data.student_id} <br/>
|
||||
申請內容:
|
||||
`;
|
||||
|
||||
console.log();
|
||||
}
|
||||
|
||||
async function putDataInTable(table_id) {
|
||||
// get data
|
||||
const data = await getItemInfo();
|
||||
if (data != null && table_id != null) {
|
||||
const result = await getItemInfo();
|
||||
const data = combineSameAppData(result.data);
|
||||
const suc = result.success;
|
||||
if (suc && data != null && table_id != null) {
|
||||
// insert data into table
|
||||
let table_content = document.getElementById(table_id).innerHTML;
|
||||
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
|
||||
table_content += `
|
||||
const keys = (Object.keys(data));
|
||||
let next_record = false;
|
||||
let this_application_info = {};
|
||||
console.log(data);
|
||||
for (let i = 0; i < keys.length; i++) {
|
||||
table_content +=
|
||||
`
|
||||
<tr>
|
||||
<td>${data[i].item_content}</td>
|
||||
<br>
|
||||
</tr>`;
|
||||
<td>${data[keys[i]].application_id}</td>
|
||||
<td>${data[keys[i]].application_date}</td>
|
||||
<td>${data[keys[i]].student_id}</td>
|
||||
<td>${data[keys[i]].student_name}</td>
|
||||
<td><button id="audit_bt_${data[keys[i]].application_id}" onclick="auditCase(${data[keys[i]].application_id})">處理<br/>申請</button></td>
|
||||
</tr>
|
||||
`
|
||||
;
|
||||
}
|
||||
/*
|
||||
`<h2>證明文件是否備齊</h2>
|
||||
<div>
|
||||
<label>
|
||||
@ -71,6 +160,7 @@ async function putDataInTable(table_id) {
|
||||
</div>
|
||||
<br></br>
|
||||
`
|
||||
*/
|
||||
// write back data into table
|
||||
document.getElementById(table_id).innerHTML = table_content;
|
||||
// set info length
|
||||
@ -83,7 +173,11 @@ async function putDataInTable(table_id) {
|
||||
|
||||
async function setAssistantName() {
|
||||
// get student name, and show on page
|
||||
document.getElementById("assistant_name").innerHTML = "test";
|
||||
const queryString = window.location.search;
|
||||
const urlParams = new URLSearchParams(queryString);
|
||||
const s_num = urlParams.get("s_num");
|
||||
const name = urlParams.get("name");
|
||||
document.getElementById("assistant_name").innerHTML = name;
|
||||
}
|
||||
|
||||
async function sendApplyData() {
|
||||
@ -118,4 +212,11 @@ async function sendApplyData() {
|
||||
console.log(result);
|
||||
}
|
||||
|
||||
putDataInTable("info_item");
|
||||
async function sendReviewResult() {
|
||||
// send current review result of the application
|
||||
console.log(`send current review result of the application ${current_review_apllication_id}`);
|
||||
// 你們這邊要將編號為 current_review_apllication_id 的審核表的資料送去後端處理
|
||||
}
|
||||
|
||||
setAssistantName();
|
||||
putDataInTable("application_table");
|
||||
12
js/login.js
12
js/login.js
@ -1,13 +1,19 @@
|
||||
async function submit() {
|
||||
const account = document.getElementById("account").value;
|
||||
const password = document.getElementById("password").value;
|
||||
console.log(account, password);
|
||||
let data = {account : account, password : password};
|
||||
let suc_login = await axios.post('/api/login', data);
|
||||
let suc_login = await axios.post('http://163.22.17.184:5000/api/login', data);
|
||||
suc_login = suc_login.data;
|
||||
console.log(suc_login);
|
||||
if (suc_login.suc) {
|
||||
location.href = '/main';
|
||||
if (account.length >= 9) {
|
||||
// student
|
||||
location.href = `/main?name=${suc_login.authen_result}&s_num=${account}`;
|
||||
}
|
||||
else {
|
||||
// assistant
|
||||
location.href = `/audit?name=${suc_login.authen_result}&s_num=${account}`;
|
||||
}
|
||||
}
|
||||
else {
|
||||
alert("帳號或密碼錯誤");
|
||||
|
||||
15
js/main.js
15
js/main.js
@ -74,8 +74,8 @@ async function setStudentName() {
|
||||
|
||||
async function sendApplyData() {
|
||||
// get student name
|
||||
const student_name = document.getElementById("student_name").value;
|
||||
const student_id = document.getElementById("student_id").value;
|
||||
const student_name = document.getElementById("student_name").innerHTML;
|
||||
const student_id = document.getElementById("student_id").innerHTML;
|
||||
const department_and_grade = document.getElementById("department_and_grade").value;
|
||||
const advisor_name = document.getElementById("advisor_name").value;
|
||||
// get checked infos
|
||||
@ -101,9 +101,20 @@ async function sendApplyData() {
|
||||
application_units,
|
||||
subsidy_amounts
|
||||
};
|
||||
console.log(data);
|
||||
// send data
|
||||
let result = await axios.post('/api/main', data);
|
||||
console.log(result);
|
||||
}
|
||||
|
||||
function setUserInfo() {
|
||||
const queryString = window.location.search;
|
||||
const urlParams = new URLSearchParams(queryString);
|
||||
const s_num = urlParams.get("s_num");
|
||||
const name = urlParams.get("name");
|
||||
document.getElementById("student_id").innerHTML = s_num;
|
||||
document.getElementById("student_name").innerHTML = name;
|
||||
}
|
||||
|
||||
setUserInfo();
|
||||
putDataInTable("info_item");
|
||||
@ -97,8 +97,8 @@ CREATE TABLE `item_form` (
|
||||
`item_id` int(4) NOT NULL,
|
||||
`application_id` int(4) NOT NULL,
|
||||
`item_info_id` int(4) NOT NULL,
|
||||
`application_unit` varchar(50) NOT NULL,
|
||||
`subsidy` int(4) NOT NULL
|
||||
`application_unit` varchar(50) NULL,
|
||||
`subsidy` int(4) NULL
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
-- --------------------------------------------------------
|
||||
@ -159,7 +159,7 @@ CREATE TABLE `student` (
|
||||
`student_id` varchar(9) NOT NULL COMMENT '學號',
|
||||
`departmant_and_grade` varchar(10) NOT NULL COMMENT '系級',
|
||||
`student_name` varchar(20) NOT NULL COMMENT '學生姓名',
|
||||
`advisor_id` int(4) NOT NULL
|
||||
`advisor_id` int(4) NULL
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
--
|
||||
|
||||
@ -10,12 +10,7 @@
|
||||
|
||||
<div id="assistant">
|
||||
<div>
|
||||
<label>系所助理:</label>
|
||||
<select id="assistant_name" name="assistant_name" required>
|
||||
<option value="">請選系所助理</option>
|
||||
<option value="王慈君">王慈君</option>
|
||||
<option value="賴玫旋">賴玫旋</option>
|
||||
</select>
|
||||
<label>系所助理:<span id="assistant_name"></span></label>
|
||||
</div>
|
||||
<br>
|
||||
<div>
|
||||
@ -26,11 +21,80 @@
|
||||
</div>
|
||||
<br>
|
||||
<fieldset>
|
||||
<h2 align="center">申請資料</h2>
|
||||
<table border="1">
|
||||
<tr>
|
||||
<td>
|
||||
<h2 align="center">申請資料</h2>
|
||||
<table id="application_table" border="1">
|
||||
<tr>
|
||||
<td>申請編號</td>
|
||||
<td>申請日期</td>
|
||||
<td>申請人學號</td>
|
||||
<td>申請人姓名</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
<td>
|
||||
<h2 align="center">申請詳細資訊</h2>
|
||||
<div id="application_info"></div>
|
||||
<table id="application_detail" border="1">
|
||||
|
||||
</table>
|
||||
</td>
|
||||
<td>
|
||||
<h2 align="center">申請審核</h2>
|
||||
<h3>證明文件是否備齊</h3>
|
||||
<div>
|
||||
<label>
|
||||
<input type="radio" id="checkbox_yes_${i}" value="yes"/> 是
|
||||
</label>
|
||||
<label>
|
||||
<input type="radio" id="checkbox_no_${i}" value="no"/> 否
|
||||
</label>
|
||||
,尚須補繳:<input type="text" id="unit_${i}"/>
|
||||
</div>
|
||||
|
||||
<h2>學生事務委員會審核結果</h2>
|
||||
<div>
|
||||
|
||||
<input type="radio" id="passed" value="passed">
|
||||
<label >經</label>
|
||||
會議名稱("學期-次數"):<input type="text" id="passedTimes" style="width: 50px;">,核發獎學金
|
||||
<input type="number" id="scholarshipAmount" style="width: 100px;">元
|
||||
<br>
|
||||
|
||||
|
||||
|
||||
<blockquote>
|
||||
<div >
|
||||
<label>通過日期:</label>
|
||||
<input type="date" id="passed_date">
|
||||
</div>
|
||||
</blockquote>
|
||||
|
||||
|
||||
</div>
|
||||
<div>
|
||||
<input type="radio" id="notPassed" value="notPassed">
|
||||
<label>未通過</label>
|
||||
</div>
|
||||
<br>
|
||||
<div>
|
||||
<label for="noSupportProof"> 未獲補助證明檔案繳交處:</label>
|
||||
<input type="file" id="noSupportProof" accept=".pdf, .doc, .docx, .jpg, .jpeg, .png">
|
||||
|
||||
</div>
|
||||
<br></br>
|
||||
<button onclick="sendReviewResult()">送出審核結果</button>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</fieldset>
|
||||
<br>
|
||||
<fieldset>
|
||||
<h2 align="center">審核區</h2>
|
||||
<table id="audit_table" border="1">
|
||||
</table>
|
||||
<form id="audit_item" border="1">
|
||||
|
||||
|
||||
|
||||
@ -10,12 +10,10 @@
|
||||
|
||||
<div id="student">
|
||||
<div>
|
||||
<label>學生姓名:</label>
|
||||
<input type="text" id="student_name" name="student_name" required>
|
||||
<label>學生姓名:<span id = "student_name"></span></label>
|
||||
</div>
|
||||
<div>
|
||||
<label>學號:</label>
|
||||
<input type="text" id="student_id" name="student_id" required>
|
||||
<label>學號:<span id = "student_id"></span></label>
|
||||
</div>
|
||||
<div>
|
||||
<label for="department_and_grade">系所別(年級):</label>
|
||||
@ -35,19 +33,19 @@
|
||||
<label for="advisor_name">導師:</label>
|
||||
<select id="advisor_name" name="advisor_name" required>
|
||||
<option value="">請選擇導師</option>
|
||||
<option value="姜美玲">姜美玲</option>
|
||||
<option value="戴榮賦">戴榮賦</option>
|
||||
<option value="陳彥錚">陳彥錚</option>
|
||||
<option value="黃俊哲">黃俊哲</option>
|
||||
<option value="白炳豐">白炳豐</option>
|
||||
<option value="簡宏宇">簡宏宇</option>
|
||||
<option value="游子宜">游子宜</option>
|
||||
<option value="余菁蓉">余菁蓉</option>
|
||||
<option value="王育民">王育民</option>
|
||||
<option value="洪嘉良">洪嘉良</option>
|
||||
<option value="陳小芬">陳小芬</option>
|
||||
<option value="陳建宏">陳建宏</option>
|
||||
<option value="鄭育評">鄭育評</option>
|
||||
<option value="1">姜美玲</option>
|
||||
<option value="2">戴榮賦</option>
|
||||
<option value="3">陳彥錚</option>
|
||||
<option value="4">黃俊哲</option>
|
||||
<option value="5">白炳豐</option>
|
||||
<option value="6">簡宏宇</option>
|
||||
<option value="7">游子宜</option>
|
||||
<option value="8">余菁蓉</option>
|
||||
<option value="9">王育民</option>
|
||||
<option value="10">洪嘉良</option>
|
||||
<option value="11">陳小芬</option>
|
||||
<option value="12">陳建宏</option>
|
||||
<option value="13">鄭育評</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -4,10 +4,10 @@ const db = require("mariadb");
|
||||
|
||||
// create pool
|
||||
const pool = db.createPool({
|
||||
connectionLimit : 500,
|
||||
connectionLimit : 50,
|
||||
host : 'localhost',
|
||||
user : 'root',
|
||||
password : '',
|
||||
user : 'test',
|
||||
password : '123',
|
||||
database : 'scholarship'
|
||||
});
|
||||
|
||||
|
||||
@ -4,10 +4,10 @@ const db = require("mariadb");
|
||||
|
||||
// create pool
|
||||
const pool = db.createPool({
|
||||
connectionLimit : 500,
|
||||
connectionLimit : 50,
|
||||
host : 'localhost',
|
||||
user : 'user',
|
||||
password : '',
|
||||
user : 'test',
|
||||
password : '123',
|
||||
database : 'scholarship'
|
||||
});
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user