Skip to content

Commit

Permalink
feat: API資料增加是否已有儲存成績欄位
Browse files Browse the repository at this point in the history
feat: 無儲存成績課程btn呈現diable紅色
  • Loading branch information
Chinlinlee committed Mar 15, 2021
1 parent 1cb9959 commit f75c3d3
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 4 deletions.
35 changes: 34 additions & 1 deletion routes/api/History_Scores/controller/get_History_Scores.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const data_log = require("../../../../models/common/data.js");
const {MongoExe} = require("../../../../models/common/data.js");
const {ntunhsApp} = require("../../../My_Func");
const myFunc = require("../../../My_Func");
const cheerio = require('cheerio');
Expand Down Expand Up @@ -109,7 +109,40 @@ async function getHistoryScores (req) {
result[key].courseTeacher = hitCourse.courseTeacher;
}
}
} else {
return false;
}
let conn = await MongoExe();
for (let key in result) {
let historyCourseScoreObj = result[key];
let courseName = historyCourseScoreObj.Course.substring(9);

let db = conn.db('My_ntunhs');
let collection = db.collection('storedHistoryScore');
try {
let queryString = {
$and : [
{
courseName : courseName
} ,
{
courseTeacher : new RegExp(historyCourseScoreObj.courseTeacher , "gi")
}
]
}
let docCount = await collection.countDocuments(queryString);
if (docCount > 0 ) {
result[key].haveStoredScore = true;
} else {
result[key].haveStoredScore = false;
}

} catch (e) {
console.error(e);
return Promise.resolve(false);
}
}
await conn.close();
req.session.HistoryScore = [result , result2 , sems];
return Promise.resolve([result , result2 , sems]);
}
Expand Down
6 changes: 3 additions & 3 deletions views/atm/History_Scores.html
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@
<td data-th="下學期成績" id="{{hs.Sem}}_content_empty" ng-show="RemoveSpace(hs.Down_Score);">
{{hs.Down_Score}}</td>
<td data-th="成績分佈圖">
<button class="btn btn-secondary btn-block" ng-click="getCourseScoreChart(hs);">顯示班上分佈圖</button>
<button class="btn btn-secondary btn-block" ng-click="getCourseScoreChartByTeacher(hs);">相關課程分佈圖</button>
<button class="btn btn-secondary btn-block" id="{{hs.Course.substring(9)}}-btn-chart-inClass" ng-click="getCourseScoreChart(hs);">顯示班上分佈圖</button>
<button class="btn btn-secondary btn-block" id="{{hs.Course.substring(9)}}-btn-chart-relateCourse" ng-click="getCourseScoreChartByTeacher(hs);">相關課程分佈圖</button>
</td>
</tr>
<tr ng-repeat="Con_hs in Conlist" ng-if="$index == semIndex">
Expand Down Expand Up @@ -135,7 +135,7 @@ <h5 class="modal-title" id="ModalChartTitle">圖表</h5>
</button>
</div>
<div class="modal-body">
<canvas id="scoreChart" width="400" height="400"></canvas>
<canvas id="scoreChart" width="400" height="200"></canvas>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">關閉</button>
Expand Down
24 changes: 24 additions & 0 deletions views/atm/scripts/History_Scores.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,22 @@ HSApp.controller("HSCtrl" , function($scope , HSService , commonService)
{
var History_Scores= res.data[0]
$scope.DataList = History_Scores;
for (let key in $scope.DataList) {
let data = $scope.DataList[key];
let course = data.Course.substring(9);
let checkDOMExist = setInterval(function () {
if ($(`#${course}-btn-chart-inClass`).length > 0 ) {
if (!data.haveStoredScore) {
addChartBtnDisable(`#${course}-btn-chart-inClass`);
addChartBtnDisable(`#${course}-btn-chart-relateCourse`);
} else {
removeChartBtnDisable(`#${course}-btn-chart-inClass`);
removeChartBtnDisable(`#${course}-btn-chart-relateCourse`);
}
clearInterval(checkDOMExist);
}
} , 100);
}
var HS_con = res.data[1];
$scope.Conlist = HS_con;
var Sems = res.data[2];
Expand All @@ -54,6 +70,14 @@ HSApp.controller("HSCtrl" , function($scope , HSService , commonService)
}
}))
}
function addChartBtnDisable (id) {
$(id).prop("disabled" , true);
$(id).removeClass("btn-secondary");
$(id).addClass("btn-danger");
}
function removeChartBtnDisable (id) {
$(id).removeProp("disabled");
}
$scope.uploadScore = function () {
$("#ModalCenter_Confirm").modal('hide');
commonFunc.blockUI();
Expand Down

0 comments on commit f75c3d3

Please sign in to comment.