Skip to content

Commit 8555a98

Browse files
committed
add network checks
1 parent c025d7b commit 8555a98

6 files changed

Lines changed: 161 additions & 81 deletions

File tree

public/js/app.js

Lines changed: 74 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1993,7 +1993,7 @@ __webpack_require__.r(__webpack_exports__);
19931993
components: {
19941994
SingleQuestion: _SingleQuestion__WEBPACK_IMPORTED_MODULE_0__["default"]
19951995
},
1996-
props: ['questions', 'hours', 'minutes', 'subject', 'student'],
1996+
props: ['questions', 'hours', 'minutes', 'subject', 'student', 'examId', 'studentId'],
19971997
data: function data() {
19981998
return {
19991999
currentQuestion: null,
@@ -2009,7 +2009,9 @@ __webpack_require__.r(__webpack_exports__);
20092009
if (!this.hasStarted) {
20102010
this.$store.dispatch('startExam', {
20112011
hours: this.hours,
2012-
minutes: this.minutes
2012+
minutes: this.minutes,
2013+
examId: this.examId,
2014+
studentId: this.studentId
20132015
}).then(function () {
20142016
_this.currentQuestion = _this.questions[0];
20152017
_this.questionNumber = 1;
@@ -2047,11 +2049,7 @@ __webpack_require__.r(__webpack_exports__);
20472049
});
20482050

20492051
if (check.length > 0) {
2050-
if (check[0].choice == null) {
2051-
return true;
2052-
} else {
2053-
return false;
2054-
}
2052+
return check[0].choice == null;
20552053
} else {
20562054
return true;
20572055
}
@@ -2106,7 +2104,7 @@ __webpack_require__.r(__webpack_exports__);
21062104
return this.$store.state.currentSelectedOption;
21072105
},
21082106
hasStarted: function hasStarted() {
2109-
return this.$store.getters.hasStarted;
2107+
return this.$store.getters.hasStarted(this.studentId, this.examId);
21102108
},
21112109
hasEnded: function hasEnded() {
21122110
return this.$store.getters.hasEnded;
@@ -2322,15 +2320,14 @@ __webpack_require__.r(__webpack_exports__);
23222320
//
23232321
/* harmony default export */ __webpack_exports__["default"] = ({
23242322
name: "Timer",
2325-
props: ["hours", "minutes"],
2323+
props: ["hours", "minutes", 'examId', 'studentId'],
23262324
data: function data() {
23272325
return {
23282326
currentHour: this.hasStarted ? "-" : this.hours,
23292327
currentMinute: this.hasStarted ? "-" : this.minutes,
23302328
currentSecond: this.hasStarted ? "-" : 0,
23312329
interval: null,
23322330
duration: null,
2333-
examIsAlmostEnding: false,
23342331
x: null,
23352332
dialog: false,
23362333
pauseDialog: false,
@@ -2339,7 +2336,13 @@ __webpack_require__.r(__webpack_exports__);
23392336
},
23402337
computed: {
23412338
hasStarted: function hasStarted() {
2342-
return this.$store.getters.hasStarted;
2339+
return this.$store.getters.hasStarted(this.studentId, this.examId);
2340+
},
2341+
examIsAlmostEnding: function examIsAlmostEnding() {
2342+
return this.interval <= 0.1 * this.duration;
2343+
},
2344+
studentCanNowSubmit: function studentCanNowSubmit() {
2345+
return this.interval <= 0.5 * this.duration;
23432346
}
23442347
},
23452348
watch: {
@@ -2350,33 +2353,31 @@ __webpack_require__.r(__webpack_exports__);
23502353
this.currentMinute = 0;
23512354
this.currentSecond = 0;
23522355
this.submitExam();
2353-
} else if (newValue <= 0.1 * this.duration) {
2354-
this.examIsAlmostEnding = true;
23552356
}
23562357
},
23572358
hasStarted: function hasStarted(newValue) {
23582359
this.setInterval();
23592360
}
23602361
},
23612362
methods: {
2362-
checkState: function checkState() {
2363+
triggerOfflineStatus: function triggerOfflineStatus() {
2364+
if (this.x) {
2365+
clearInterval(this.x);
2366+
this.x = null;
2367+
this.pauseDialog = true;
2368+
}
2369+
},
2370+
networkReactivationCheck: function networkReactivationCheck() {
23632371
var _this = this;
23642372

2365-
setInterval(function () {
2366-
_this.$http.get("network-status").then(function (res) {
2367-
if (_this.hasStarted && _this.x === null) {
2368-
_this.pauseDialog = false;
2373+
if (this.hasStarted && this.x === null && this.pauseDialog) {
2374+
//make a call to the network status to be sure the server is reachable not just that the system is online
2375+
this.$http.get("network-status").then(function (res) {
2376+
_this.pauseDialog = false;
23692377

2370-
_this.setInterval();
2371-
}
2372-
})["catch"](function (err) {
2373-
if (_this.x) {
2374-
clearInterval(_this.x);
2375-
_this.x = null;
2376-
_this.pauseDialog = true;
2377-
}
2378+
_this.setInterval();
23782379
});
2379-
}, 1000);
2380+
}
23802381
},
23812382
setInterval: function (_setInterval) {
23822383
function setInterval() {
@@ -2411,16 +2412,28 @@ __webpack_require__.r(__webpack_exports__);
24112412
this.$store.dispatch("endExam").then(function (res) {
24122413
_this2.btnLoading = false;
24132414
_this2.dialog = false;
2415+
localStorage.removeItem("timeLeft");
24142416
window.location.href = "/success";
24152417
})["catch"](function (err) {
24162418
_this2.btnLoading = false;
2419+
console.log(err.response.data);
2420+
var errorMessage = err.response.status === 403 ? err.response.data.message : "Sorry, there was an error submitting your examination. Kindly contact the invigilator for assistance.";
24172421

2418-
_this2.$noty.error("Error submitting examination: ".concat(err.response.data.message));
2422+
_this2.$noty.error(errorMessage);
24192423
});
24202424
}
24212425
},
24222426
mounted: function mounted() {
2423-
this.checkState();
2427+
if (this.hasStarted) {
2428+
this.setInterval();
2429+
}
2430+
2431+
window.addEventListener('offline', this.triggerOfflineStatus);
2432+
window.addEventListener('online', this.networkReactivationCheck);
2433+
},
2434+
destroyed: function destroyed() {
2435+
window.removeEventListener('offline', this.triggerOfflineStatus);
2436+
window.removeEventListener('online', this.networkReactivationCheck);
24242437
}
24252438
});
24262439

@@ -73800,7 +73813,7 @@ var render = function() {
7380073813
tile: "",
7380173814
block: "",
7380273815
color: "bg-warning",
73803-
disabled: !_vm.hasStarted
73816+
disabled: !_vm.hasStarted || !_vm.studentCanNowSubmit
7380473817
},
7380573818
on: {
7380673819
click: function($event) {
@@ -76638,7 +76651,7 @@ var render = function() {
7663876651
_c(
7663976652
"td",
7664076653
[
76641-
!_vm.student.deleted_at
76654+
!_vm.student.deactivated_at
7664276655
? _c(
7664376656
"v-btn",
7664476657
{
@@ -76818,15 +76831,15 @@ var render = function() {
7681876831
_c(
7681976832
"v-card",
7682076833
[
76821-
_vm.student.deleted_at
76834+
_vm.student.deactivated_at
7682276835
? _c("v-card-title", { staticClass: "headline" }, [
7682376836
_vm._v("Restore Examination Access?")
7682476837
])
7682576838
: _c("v-card-title", { staticClass: "headline" }, [
7682676839
_vm._v("Disable Examination Access?")
7682776840
]),
7682876841
_vm._v(" "),
76829-
_vm.student.deleted_at
76842+
_vm.student.deactivated_at
7683076843
? _c("v-card-text", [
7683176844
_vm._v(
7683276845
"\n Please confirm that you want to restore\n "
@@ -76879,7 +76892,7 @@ var render = function() {
7687976892
},
7688076893
on: {
7688176894
click: function($event) {
76882-
_vm.student.deleted_at
76895+
_vm.student.deactivated_at
7688376896
? _vm.restoreStudent()
7688476897
: _vm.disableStudent()
7688576898
}
@@ -135817,7 +135830,7 @@ vue__WEBPACK_IMPORTED_MODULE_12___default.a.prototype.$http.interceptors.respons
135817135830
throw err;
135818135831
}
135819135832
} else if (err.request) {
135820-
throw err; // Vue.prototype.$noty.error("Oops! There was an error sending this request, please confirm that you are connected to the network and try again.")
135833+
vue__WEBPACK_IMPORTED_MODULE_12___default.a.prototype.$noty.error("Oops! There was an error sending this request, please confirm that you are connected to the network and try again.");
135821135834
} else {
135822135835
console.log(err.message);
135823135836
vue__WEBPACK_IMPORTED_MODULE_12___default.a.prototype.$noty.error("An error seems to have been encountered sending this request, please refresh the page and try again.");
@@ -137239,7 +137252,14 @@ __webpack_require__.r(__webpack_exports__);
137239137252
},
137240137253
getters: {
137241137254
hasStarted: function hasStarted(state) {
137242-
return !!state.examParams;
137255+
return function (studentId, examId) {
137256+
if (!state.examParams) {
137257+
return false;
137258+
}
137259+
137260+
var examParams = JSON.parse(state.examParams);
137261+
return examParams.studentId === studentId && examParams.examId === examId;
137262+
};
137243137263
},
137244137264
choices: function choices(state) {
137245137265
return JSON.parse(state.choices);
@@ -137249,6 +137269,12 @@ __webpack_require__.r(__webpack_exports__);
137249137269
},
137250137270
timeExamEnds: function timeExamEnds(state) {
137251137271
return state.examParams ? JSON.parse(state.examParams).endsAt : null;
137272+
},
137273+
studentId: function studentId(state) {
137274+
return state.examParams ? JSON.parse(state.examParams).studentId : null;
137275+
},
137276+
examId: function examId(state) {
137277+
return state.examParams ? JSON.parse(state.examParams).examId : null;
137252137278
}
137253137279
},
137254137280
mutations: {
@@ -137282,14 +137308,23 @@ __webpack_require__.r(__webpack_exports__);
137282137308
var commit = _ref.commit;
137283137309
return new Promise(function (resolve, reject) {
137284137310
var hours = data.hours,
137285-
minutes = data.minutes;
137311+
minutes = data.minutes,
137312+
examId = data.examId,
137313+
studentId = data.studentId;
137286137314
var timeExamStarted = new Date().getTime();
137287137315
var timeExamEnds = timeExamStarted + hours * 60 * 60 * 1000 + minutes * 60 * 1000;
137288137316
var examParams = JSON.stringify({
137289137317
startedAt: timeExamStarted,
137290-
endsAt: timeExamEnds
137318+
endsAt: timeExamEnds,
137319+
studentId: studentId,
137320+
examId: examId
137321+
});
137322+
localStorage.setItem('exam_params', examParams); // remove anything formerly in local storage
137323+
137324+
var keysToRemove = ['choices', 'tabClosed', 'timeLeft'];
137325+
keysToRemove.forEach(function (key) {
137326+
return localStorage.removeItem(key);
137291137327
});
137292-
localStorage.setItem('exam_params', examParams);
137293137328
commit('START_EXAM', examParams);
137294137329
resolve();
137295137330
});

resources/js/app.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ Vue.prototype.$http.interceptors.response.use(undefined, function (err) {
4040
}
4141

4242
else if (err.request) {
43-
throw err;
44-
// Vue.prototype.$noty.error("Oops! There was an error sending this request, please confirm that you are connected to the network and try again.")
43+
Vue.prototype.$noty.error("Oops! There was an error sending this request, please confirm that you are connected to the network and try again.")
4544
}
4645

4746
else {

resources/js/components/student/Questions.vue

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export default {
6868
components: {
6969
SingleQuestion
7070
},
71-
props: ['questions', 'hours', 'minutes', 'subject', 'student'],
71+
props: ['questions', 'hours', 'minutes', 'subject', 'student', 'examId', 'studentId'],
7272
data() {
7373
return {
7474
currentQuestion: null,
@@ -83,6 +83,8 @@ export default {
8383
this.$store.dispatch('startExam', {
8484
hours: this.hours,
8585
minutes: this.minutes,
86+
examId: this.examId,
87+
studentId: this.studentId
8688
})
8789
.then(() => {
8890
this.currentQuestion = this.questions[0]
@@ -116,12 +118,7 @@ export default {
116118
hasNotBeenAnswered(questionNumber) {
117119
let check = this.choices.filter(choice => choice.question == questionNumber)
118120
if (check.length > 0) {
119-
if (check[0].choice == null) {
120-
return true
121-
}
122-
else {
123-
return false
124-
}
121+
return check[0].choice == null
125122
}
126123
else {
127124
return true
@@ -181,7 +178,7 @@ export default {
181178
return this.$store.state.currentSelectedOption
182179
},
183180
hasStarted() {
184-
return this.$store.getters.hasStarted
181+
return this.$store.getters.hasStarted(this.studentId, this.examId);
185182
},
186183
hasEnded() {
187184
return this.$store.getters.hasEnded

0 commit comments

Comments
 (0)