Skip to content

Commit 06d2c2c

Browse files
committed
Merge pull request #5 from BenMQ/minqi/recess-week
Support for recess week
2 parents 957e2fc + 7b5afcb commit 06d2c2c

File tree

6 files changed

+111
-56
lines changed

6 files changed

+111
-56
lines changed

claims/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Configuration
4545
**Activity Object**
4646

4747
- `activity_type`: Use the pre-defined constants: **ASSIGNMENT_MARKING** | **COURSE_MATERIAL_PREPARATION** | **TUTORIAL** | **CONSULTATION**
48-
- `week`: An integer, indicating the week number of the sem. This is to facilitate convenient calculation of the date of activity. The script only supports activities performed from week 1 onwards, excluding recess week and reading week. If your activity falls on recess/reading week, you will have to add them into the system yourself manually.
48+
- `week`: A positive integer, or string `'RECESS'`, indicating the week number of the sem. This is to facilitate convenient calculation of the date of activity. The script only supports activities performed from week 1 onwards.
4949
- `day`: A string, with one of these values: **"MONDAY"**, **"TUESDAY"**, **"WEDNESDAY"**, **"THURSDAY"**, **"FRIDAY"**, **"SATURDAY"**, **"SUNDAY"**.
5050
- `start_time`: A 4-character string, representing the starting time of the activity in 24-hour format. The minute value has to be 00 or 30.
5151
- `end_time`: Similar to `start_time`, but represents the ending time of the activity.

claims/claim-cs1010s.js

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -112,47 +112,60 @@ function Claim(config) {
112112
this.remarks = config.duties;
113113
this.first_day_of_sem = config.first_day_of_sem;
114114
this.error = false;
115+
115116
var that = this;
117+
118+
// Ensure claiming for correct module!
119+
if ($('h3:contains("Module")').text().substr(8) !== config.module) {
120+
alert('Ensure that the module in config matches that of this page.');
121+
// Else you will have invisible claims taking up your time.
122+
throw new Error('Incorrect module in config.');
123+
}
124+
116125
function createActivity(activity_type, week, day, start_time, end_time) {
117-
// obj has the properties:
118126
var day_upper = day.toUpperCase();
119127
try {
120-
if (ACTIVITY_DICT[activity_type] == undefined || typeof activity_type != "string") {
121-
throw "Activity error: " + activity_type + ". Activity type not supported.";
128+
if (ACTIVITY_DICT[activity_type] === undefined || typeof activity_type !== 'string') {
129+
throw 'Activity error: ' + activity_type + '. Activity type not supported.';
122130
}
123-
if (typeof week != "number" || week <= 0) {
124-
throw "Week error: " + week + ". Week value has to be a positive number.";
131+
if (typeof week !== 'number' && week !== 'RECESS' || week <= 0) {
132+
throw 'Week error: ' + week + '. Week value has to be a positive number or RECESS.';
125133
}
126-
if (DAY_DICT[day_upper] == undefined || typeof day_upper != "string") {
127-
throw "Day error: " + day + ". Day value has to be a valid day string.";
134+
if (DAY_DICT[day_upper] === undefined || typeof day_upper !== 'string') {
135+
throw 'Day error: ' + day + '. Day value has to be a valid day string.';
128136
}
137+
129138
function checkTime(time) {
130139
var start_time_hour = time.slice(0,2);
131140
var start_time_min = time.slice(2);
132-
if (typeof time != "string" ||
141+
if (typeof time !== 'string' ||
133142
time.length != 4 ||
134143
!(parseInt(start_time_hour) >= 0 && parseInt(start_time_hour) <= 23) ||
135-
!(start_time_min == "00" || start_time_min == "30")) {
136-
throw "Time error: " + time + ". Time has to be string in 24-hr format at half-hour intervals.";
144+
!(start_time_min === '00' || start_time_min === '30')) {
145+
throw 'Time error: ' + time + '. Time has to be string in 24-hr format at half-hour intervals.';
137146
}
138147
}
148+
139149
checkTime(start_time);
140150
checkTime(end_time);
141151
var start_time_hour = parseInt(start_time.slice(0,2));
142152
var end_time_hour = parseInt(end_time.slice(0,2));
153+
143154
if (start_time_hour > end_time_hour || start_time === end_time) {
144-
throw "Time error: end_time: " + end_time + " must be after start_time: " + start_time + ".";
155+
throw 'Time error: end_time: ' + end_time + ' must be after start_time: ' + start_time + '.';
145156
} else if (end_time_hour - start_time_hour > 8) {
146-
throw "Time error: " + start_time + " - " + end_time + ". Activity cannot be more than 8 hours.";
147-
}
157+
throw 'Time error: ' + start_time + ' - ' + end_time + '. Activity cannot be more than 8 hours.';
158+
}
148159
} catch (err) {
149160
error = true;
150161
console.log(err);
151162
}
152-
return function() {
163+
164+
return function() {
153165
that.makeClaim(activity_type, week, day, start_time, end_time);
154166
};
155167
}
168+
156169
var activities = config.activities_list_fn();
157170
this.activities_list = [];
158171
for (var i = 0; i < activities.length; i++) {
@@ -178,7 +191,11 @@ function Claim(config) {
178191

179192
Claim.prototype.makeClaim = function(activity_type, week, day, start_time, end_time) {
180193
var day_num = DAY_DICT[day];
181-
var number_of_days = (week < 7 ? week - 1 : week)*7 + day_num;
194+
if (week === 'RECESS') {
195+
var number_of_days = 6*7 + day_num;
196+
} else {
197+
var number_of_days = (week < 7 ? week - 1 : week)*7 + day_num;
198+
}
182199
var activity_date = new Date();
183200
activity_date.setTime(this.first_day_of_sem.getTime() + (number_of_days * 24 * 60 * 60 * 1000));
184201
var claim_date_array = activity_date.toDateString().split(' ');
@@ -215,7 +232,7 @@ Claim.prototype.makeClaim = function(activity_type, week, day, start_time, end_t
215232
Claim.prototype.deleteAllClaims = function() {
216233
var that = this;
217234
function deleteClaim(claim_id) {
218-
$.post(POST_URL, {
235+
$.post(POST_URL, {
219236
mod_c: that.module,
220237
claim_id: claim_id,
221238
action: 'DELETE',
@@ -226,10 +243,11 @@ Claim.prototype.deleteAllClaims = function() {
226243
count += 1;
227244
if (count === $existing_claims.length) {
228245
alert('All claims deleted! Press OK to continue.');
229-
window.location.href = window.location.protocol +'//'+ window.location.host + END_REDIRECT_URL;
246+
window.location.href = window.location.protocol + '//' + window.location.host + END_REDIRECT_URL;
230247
}
231248
});
232249
}
250+
233251
var count = 0;
234252
var $existing_claims = $('#claim-info-div table [name="claim_id"]');
235253
$existing_claims.each(function() {
@@ -244,4 +262,4 @@ Claim.prototype.makeAllClaims = function() {
244262
}
245263

246264
var c = new Claim(config);
247-
c.makeAllClaims();
265+
// c.makeAllClaims();

claims/claim-cs1101s.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ var config = {
6363
// 2h grading * 14 weeks = 28 hours
6464
//
6565
// TOTAL: 70 hours
66-
for (var week = 1; week <= 14; week++) {
66+
for (var week = 1; week <= 13; week++) {
6767
activities_list.push({
6868
activity_type: ASSIGNMENT_MARKING,
6969
week: week,
@@ -72,8 +72,8 @@ var config = {
7272
end_time: '1500'
7373
});
7474

75-
if (week === 1 || week === 7 || week === 9) {
76-
// there was no tutorial in week 1, 7 (recess) and 9 (PH)
75+
if (week === 1 || week === 8) {
76+
// there was no tutorial in week 1 and 8 (PH)
7777
} else {
7878
activities_list.push({
7979
activity_type: TUTORIAL,
@@ -94,7 +94,13 @@ var config = {
9494
});
9595
}
9696
};
97-
97+
activities_list.push({
98+
activity_type: ASSIGNMENT_MARKING,
99+
week: 'RECESS',
100+
day: 'SATURDAY',
101+
start_time: '1300',
102+
end_time: '1500'
103+
});
98104
return activities_list;
99105
}
100106
}
@@ -134,8 +140,8 @@ function Claim(config) {
134140
if (ACTIVITY_DICT[activity_type] === undefined || typeof activity_type !== 'string') {
135141
throw 'Activity error: ' + activity_type + '. Activity type not supported.';
136142
}
137-
if (typeof week !== 'number' || week <= 0) {
138-
throw 'Week error: ' + week + '. Week value has to be a positive number.';
143+
if (typeof week !== 'number' && week !== 'RECESS' || week <= 0) {
144+
throw 'Week error: ' + week + '. Week value has to be a positive number or RECESS.';
139145
}
140146
if (DAY_DICT[day_upper] === undefined || typeof day_upper !== 'string') {
141147
throw 'Day error: ' + day + '. Day value has to be a valid day string.';
@@ -197,7 +203,11 @@ function Claim(config) {
197203

198204
Claim.prototype.makeClaim = function(activity_type, week, day, start_time, end_time) {
199205
var day_num = DAY_DICT[day];
200-
var number_of_days = (week < 7 ? week - 1 : week)*7 + day_num;
206+
if (week === 'RECESS') {
207+
var number_of_days = 6*7 + day_num;
208+
} else {
209+
var number_of_days = (week < 7 ? week - 1 : week)*7 + day_num;
210+
}
201211
var activity_date = new Date();
202212
activity_date.setTime(this.first_day_of_sem.getTime() + (number_of_days * 24 * 60 * 60 * 1000));
203213
var claim_date_array = activity_date.toDateString().split(' ');

claims/claim-cs3216.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ function Claim(config) {
123123
if (ACTIVITY_DICT[activity_type] === undefined || typeof activity_type !== 'string') {
124124
throw 'Activity error: ' + activity_type + '. Activity type not supported.';
125125
}
126-
if (typeof week !== 'number' || week <= 0) {
127-
throw 'Week error: ' + week + '. Week value has to be a positive number.';
126+
if (typeof week !== 'number' && week !== 'RECESS' || week <= 0) {
127+
throw 'Week error: ' + week + '. Week value has to be a positive number or RECESS.';
128128
}
129129
if (DAY_DICT[day_upper] === undefined || typeof day_upper !== 'string') {
130130
throw 'Day error: ' + day + '. Day value has to be a valid day string.';
@@ -186,7 +186,11 @@ function Claim(config) {
186186

187187
Claim.prototype.makeClaim = function(activity_type, week, day, start_time, end_time) {
188188
var day_num = DAY_DICT[day];
189-
var number_of_days = (week < 7 ? week - 1 : week)*7 + day_num;
189+
if (week === 'RECESS') {
190+
var number_of_days = 6*7 + day_num;
191+
} else {
192+
var number_of_days = (week < 7 ? week - 1 : week)*7 + day_num;
193+
}
190194
var activity_date = new Date();
191195
activity_date.setTime(this.first_day_of_sem.getTime() + (number_of_days * 24 * 60 * 60 * 1000));
192196
var claim_date_array = activity_date.toDateString().split(' ');

claims/claim-cs3217.js

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ var ACTIVITY_DICT = {};
100100
ACTIVITY_DICT[ASSIGNMENT_MARKING] = '003';
101101
ACTIVITY_DICT[COURSE_MATERIAL_PREPARATION] = '006';
102102
ACTIVITY_DICT[TUTORIAL] = 'T';
103+
ACTIVITY_DICT[CONSULTATION] = 'C';
103104

104105
var DAY_DICT = { 'MONDAY': 0, 'TUESDAY': 1, 'WEDNESDAY': 2, 'THURSDAY': 3, 'FRIDAY': 4, 'SATURDAY': 5, 'SUNDAY': 6 };
105106

@@ -109,47 +110,60 @@ function Claim(config) {
109110
this.remarks = config.duties;
110111
this.first_day_of_sem = config.first_day_of_sem;
111112
this.error = false;
113+
112114
var that = this;
115+
116+
// Ensure claiming for correct module!
117+
if ($('h3:contains("Module")').text().substr(8) !== config.module) {
118+
alert('Ensure that the module in config matches that of this page.');
119+
// Else you will have invisible claims taking up your time.
120+
throw new Error('Incorrect module in config.');
121+
}
122+
113123
function createActivity(activity_type, week, day, start_time, end_time) {
114-
// obj has the properties:
115124
var day_upper = day.toUpperCase();
116125
try {
117-
if (ACTIVITY_DICT[activity_type] == undefined || typeof activity_type != "string") {
118-
throw "Activity error: " + activity_type + ". Activity type not supported.";
126+
if (ACTIVITY_DICT[activity_type] === undefined || typeof activity_type !== 'string') {
127+
throw 'Activity error: ' + activity_type + '. Activity type not supported.';
119128
}
120-
if (typeof week != "number" || week <= 0) {
121-
throw "Week error: " + week + ". Week value has to be a positive number.";
129+
if (typeof week !== 'number' && week !== 'RECESS' || week <= 0) {
130+
throw 'Week error: ' + week + '. Week value has to be a positive number or RECESS.';
122131
}
123-
if (DAY_DICT[day_upper] == undefined || typeof day_upper != "string") {
124-
throw "Day error: " + day + ". Day value has to be a valid day string.";
132+
if (DAY_DICT[day_upper] === undefined || typeof day_upper !== 'string') {
133+
throw 'Day error: ' + day + '. Day value has to be a valid day string.';
125134
}
135+
126136
function checkTime(time) {
127137
var start_time_hour = time.slice(0,2);
128138
var start_time_min = time.slice(2);
129-
if (typeof time != "string" ||
139+
if (typeof time !== 'string' ||
130140
time.length != 4 ||
131141
!(parseInt(start_time_hour) >= 0 && parseInt(start_time_hour) <= 23) ||
132-
!(start_time_min == "00" || start_time_min == "30")) {
133-
throw "Time error: " + time + ". Time has to be string in 24-hr format at half-hour intervals.";
142+
!(start_time_min === '00' || start_time_min === '30')) {
143+
throw 'Time error: ' + time + '. Time has to be string in 24-hr format at half-hour intervals.';
134144
}
135145
}
146+
136147
checkTime(start_time);
137148
checkTime(end_time);
138149
var start_time_hour = parseInt(start_time.slice(0,2));
139150
var end_time_hour = parseInt(end_time.slice(0,2));
151+
140152
if (start_time_hour > end_time_hour || start_time === end_time) {
141-
throw "Time error: end_time: " + end_time + " must be after start_time: " + start_time + ".";
153+
throw 'Time error: end_time: ' + end_time + ' must be after start_time: ' + start_time + '.';
142154
} else if (end_time_hour - start_time_hour > 8) {
143-
throw "Time error: " + start_time + " - " + end_time + ". Activity cannot be more than 8 hours.";
144-
}
155+
throw 'Time error: ' + start_time + ' - ' + end_time + '. Activity cannot be more than 8 hours.';
156+
}
145157
} catch (err) {
146158
error = true;
147159
console.log(err);
148160
}
149-
return function() {
161+
162+
return function() {
150163
that.makeClaim(activity_type, week, day, start_time, end_time);
151164
};
152165
}
166+
153167
var activities = config.activities_list_fn();
154168
this.activities_list = [];
155169
for (var i = 0; i < activities.length; i++) {
@@ -175,7 +189,11 @@ function Claim(config) {
175189

176190
Claim.prototype.makeClaim = function(activity_type, week, day, start_time, end_time) {
177191
var day_num = DAY_DICT[day];
178-
var number_of_days = (week < 7 ? week - 1 : week)*7 + day_num;
192+
if (week === 'RECESS') {
193+
var number_of_days = 6*7 + day_num;
194+
} else {
195+
var number_of_days = (week < 7 ? week - 1 : week)*7 + day_num;
196+
}
179197
var activity_date = new Date();
180198
activity_date.setTime(this.first_day_of_sem.getTime() + (number_of_days * 24 * 60 * 60 * 1000));
181199
var claim_date_array = activity_date.toDateString().split(' ');
@@ -212,7 +230,7 @@ Claim.prototype.makeClaim = function(activity_type, week, day, start_time, end_t
212230
Claim.prototype.deleteAllClaims = function() {
213231
var that = this;
214232
function deleteClaim(claim_id) {
215-
$.post(POST_URL, {
233+
$.post(POST_URL, {
216234
mod_c: that.module,
217235
claim_id: claim_id,
218236
action: 'DELETE',
@@ -223,10 +241,11 @@ Claim.prototype.deleteAllClaims = function() {
223241
count += 1;
224242
if (count === $existing_claims.length) {
225243
alert('All claims deleted! Press OK to continue.');
226-
window.location.href = window.location.protocol +'//'+ window.location.host + END_REDIRECT_URL;
244+
window.location.href = window.location.protocol + '//' + window.location.host + END_REDIRECT_URL;
227245
}
228246
});
229247
}
248+
230249
var count = 0;
231250
var $existing_claims = $('#claim-info-div table [name="claim_id"]');
232251
$existing_claims.each(function() {
@@ -241,4 +260,4 @@ Claim.prototype.makeAllClaims = function() {
241260
}
242261

243262
var c = new Claim(config);
244-
// c.makeAllClaims();
263+
// c.makeAllClaims();

0 commit comments

Comments
 (0)