diff --git a/package-lock.json b/package-lock.json index a3d4fc7..735f25d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10848,6 +10848,11 @@ "resolved": "https://registry.npm.taobao.org/vue-class-component/download/vue-class-component-7.1.0.tgz", "integrity": "sha1-sz78sQ4XI21oT3Cx6W8ZRux5Poc=" }, + "vue-cookies": { + "version": "1.5.13", + "resolved": "https://registry.npmjs.org/vue-cookies/-/vue-cookies-1.5.13.tgz", + "integrity": "sha512-8pjpXnvbNWx1Lft0t3MJnW+ylv0Wa2Tb6Ch617u/pQah3+SfXUZZdkh3EL3bSpe/Sw2Wdw3+DhycgQsKANSxXg==" + }, "vue-hot-reload-api": { "version": "2.3.3", "resolved": "https://registry.npm.taobao.org/vue-hot-reload-api/download/vue-hot-reload-api-2.3.3.tgz", diff --git a/package.json b/package.json index e956b28..2117965 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "v-charts": "^1.19.0", "vue": "^2.6.10", "vue-class-component": "^7.0.2", + "vue-cookies": "^1.5.13", "vue-property-decorator": "^8.1.0" }, "devDependencies": { diff --git a/src/components/app/app.ts b/src/components/app/app.ts index ca45f70..cebb43c 100644 --- a/src/components/app/app.ts +++ b/src/components/app/app.ts @@ -5,6 +5,7 @@ import Overall from '@/pages/overall/overall'; import Constants from '@/constants'; import JsonUtils from '@/utils/json-utils'; import pWaitFor from 'p-wait-for'; +import {HttpUtils} from '@/utils/http-utils'; /** * Objects of this interface represent assignment grades. @@ -31,6 +32,13 @@ export interface Course id: number, name: string, teacherName: string, + status: string, + + letterGrade?: string, + numericGrade?: number, + + level: string, + scaleUp: number, assignments: Grade[] } @@ -52,39 +60,93 @@ export default class App extends Vue // Are the course assignments loaded from the server. public assignmentsReady: boolean = false; + // Token + public token: string = ''; + + // Http Client + public http: HttpUtils = new HttpUtils(''); + + /** + * This is called when the instance is created. + */ + public created() + { + // Show splash + console.log(Constants.SPLASH); + } + /** * This is called when the user logs in. * - * @param courses Courses Json + * @param token Authorization token */ - public onLogin(courses: Course[]) + public onLogin(token: string) { // Hide login bar this.showLogin = false; - // Assign courses - this.courses = courses; + // Store token + this.token = token; - // Debug output TODO: Remove this - console.log(courses); + // Assign token to http client + this.http.token = token; + // Load data + this.loadCoursesAfterLogin(); + } + + /** + * Load courses data after login. + */ + public loadCoursesAfterLogin() + { + this.http.post('/courses', {}).then(response => + { + // Check success + if (response.success) + { + // Save courses + this.courses = response.data; + + // Load assignments + this.loadAssignments(); + } + else + { + // Show error message TODO: Show it properly + alert(response.data); + } + }) + .catch(alert); + } + + /** + * Load the assignments of the courses + * + * @param courses Courses Json + */ + public loadAssignments() + { // Get assignments for all the courses this.courses.forEach(course => { // Send request to get assignments - fetch(`${Constants.API_URL}/veracross/assignments?id=${course.assignmentsId}`).then(res => + this.http.post('/assignments', {id: course.assignmentsId}).then(response => { - // Get response body text - res.text().then(text => + // Check success + if (response.success) { + // Load assignments // Parse json and filter it - course.assignments = JsonUtils.filterAssignments(JSON.parse(text)); - }) + course.assignments = JsonUtils.filterAssignments(response.data); + } + else + { + // Show error message TODO: Show it properly + alert(response.data); + } }) - .catch(err => - { - alert(err); - }); + .catch(alert); }); // Wait for assignments to be ready. diff --git a/src/components/app/app.vue b/src/components/app/app.vue index baf4349..17879e9 100644 --- a/src/components/app/app.vue +++ b/src/components/app/app.vue @@ -1,6 +1,6 @@