From 5e1ebbdb43c803ecfe7739811fe696689e4caec3 Mon Sep 17 00:00:00 2001 From: Alex Akopyan Date: Fri, 15 Nov 2019 16:08:10 -0500 Subject: [PATCH 1/2] Added funtionality to send selected courses to backend --- web/src/app/app.component.ts | 2 + web/src/app/header/component.html | 5 ++ web/src/app/header/component.ts | 2 + .../app/header/term-selector/component.html | 4 +- web/src/app/listing/component.ts | 55 ++++++++++++++++++- 5 files changed, 65 insertions(+), 3 deletions(-) diff --git a/web/src/app/app.component.ts b/web/src/app/app.component.ts index 722cb6ba..d8396360 100644 --- a/web/src/app/app.component.ts +++ b/web/src/app/app.component.ts @@ -1,5 +1,6 @@ import { Component, Input } from '@angular/core'; import { NoticeService } from './services/notice.service'; +import { v4 as uuid } from 'uuid'; @Component({ selector: 'app-root', @@ -17,6 +18,7 @@ export class AppComponent { ngOnInit () { this.showingSidebar = true; + sessionStorage.setItem('userID', uuid()); } public toggleSidebar (): void { diff --git a/web/src/app/header/component.html b/web/src/app/header/component.html index a7a8ac57..f54a06a0 100644 --- a/web/src/app/header/component.html +++ b/web/src/app/header/component.html @@ -40,6 +40,11 @@ + diff --git a/web/src/app/header/component.ts b/web/src/app/header/component.ts index f5727d61..8cb91a4a 100644 --- a/web/src/app/header/component.ts +++ b/web/src/app/header/component.ts @@ -24,6 +24,7 @@ export class HeaderComponent { //keyup.enter generic search search (term: string) { if (this.isValidSearchTerm(term) && !this.dropDownSelected) { + console.log(term);//TODO send the search term to the backend this.router.navigate(['/courses'], { queryParams: { search: term } }); } this.dropDownSelected = false; @@ -50,6 +51,7 @@ export class HeaderComponent { //function for on-click typeahead bar selectedCourse ($event: any) { + console.log($event.item);//TODO send the search to the backend this.router.navigate(['/courses'], { queryParams: { longname: $event.item diff --git a/web/src/app/header/term-selector/component.html b/web/src/app/header/term-selector/component.html index a44257e8..103f5b94 100644 --- a/web/src/app/header/term-selector/component.html +++ b/web/src/app/header/term-selector/component.html @@ -1,9 +1,9 @@ -   +   {{ internalName }} View Only   - + diff --git a/web/src/app/listing/component.ts b/web/src/app/listing/component.ts index fac28ec0..9b3a6bc5 100644 --- a/web/src/app/listing/component.ts +++ b/web/src/app/listing/component.ts @@ -4,6 +4,8 @@ import { ScheduleEvent } from '../models/schedule-event.model'; import { SelectionService } from '../services/selection.service'; import { ConflictsService } from '../services/conflicts.service'; import { SidebarService } from '../services/sidebar.service'; +import { v4 as uuid } from 'uuid'; +import { HttpClient, HttpHeaders } from '@angular/common/http'; @Component({ selector: 'course', @@ -21,7 +23,10 @@ export class ListingComponent implements OnInit{ constructor ( public selectionService : SelectionService, public sidebarService : SidebarService, - private conflictsService: ConflictsService) { } + private conflictsService: ConflictsService, + private http: HttpClient + ) { } + onKeydown(evt: KeyboardEvent) { const keyCode = evt.which; @@ -71,6 +76,34 @@ export class ListingComponent implements OnInit{ } public clickCourse () { + + + let event: string; + if(this.isCourseSelected()){ + event = "2"; + }else{ + event = "1"; + } + let time: number = Date.now(); + //console.log(time); + + for(let sec of this.listing.sections){ + if(event == "1" || this.isSectionSelected(sec)){ + this.http.post('https://api.yacs.maoyu.wang/userEvent', { + "uid": sessionStorage.getItem('userID'), + "eventID": event, + "data": { + 'Course CRN' : sec.crn + + }, + "createdAt": time + }).subscribe( + data => {console.log(data)}, + err => {console.log(err)} + ); + } + } + this.selectionService.toggleCourse(this.listing); } @@ -84,6 +117,26 @@ export class ListingComponent implements OnInit{ public clickSection (section: Section): void { this.selectionService.toggleSection(section); + + let event: string; + if(this.isSectionSelected(section)){ + event = "2"; + }else{ + event = "1"; + } + //Sends the info about the course to the user system backend + this.http.post('https://api.yacs.maoyu.wang/userEvent', { + "uid": sessionStorage.getItem('userID'), + "eventID": event, + "data": { + 'Course CRN' : section.crn + + }, + "createdAt": Date.now() + }).subscribe( + data => {console.log(data)}, + err => {console.log(err)} + ); } public findProf (teacher: string): boolean{ From 233bc849d25eeba65928344725cd5674384dc6bd Mon Sep 17 00:00:00 2001 From: Alex Akopyan Date: Tue, 3 Dec 2019 15:59:23 -0500 Subject: [PATCH 2/2] added functionality to send data when a user clicks on a school and when a user searches for a class --- web/src/app/header/component.ts | 31 +++++++++++++-- web/src/app/listing/component.ts | 8 +--- web/src/app/school-list/school/component.ts | 44 ++++++++++++++++++++- 3 files changed, 73 insertions(+), 10 deletions(-) diff --git a/web/src/app/header/component.ts b/web/src/app/header/component.ts index 8cb91a4a..9962c51f 100644 --- a/web/src/app/header/component.ts +++ b/web/src/app/header/component.ts @@ -2,6 +2,8 @@ import { Component } from '@angular/core'; import { Router } from '@angular/router'; import { Observable } from 'rxjs/Observable'; import { Listing } from 'yacs-api-client'; +import { HttpClient, HttpHeaders } from '@angular/common/http'; +import qs from 'qs'; import 'rxjs/add/operator/switchMap'; import 'rxjs/add/operator/debounceTime'; @@ -19,12 +21,24 @@ export class HeaderComponent { dropDownSelected: boolean = false; navbarCollapsed: boolean = true; - constructor (private router: Router) { } + constructor (private router: Router, private http: HttpClient) { } //keyup.enter generic search search (term: string) { if (this.isValidSearchTerm(term) && !this.dropDownSelected) { - console.log(term);//TODO send the search term to the backend + //Sends the info about the user's search to the user system backend + this.http.post('https://api.yacs.maoyu.wang/userEvent', { + "uid": sessionStorage.getItem('userID'), + "eventID": "3", + "data": { + 'Search' : term + + }, + "createdAt": Date.now() + }).subscribe( + data => {console.log(data)}, + err => {console.log(err)} + ); this.router.navigate(['/courses'], { queryParams: { search: term } }); } this.dropDownSelected = false; @@ -51,7 +65,18 @@ export class HeaderComponent { //function for on-click typeahead bar selectedCourse ($event: any) { - console.log($event.item);//TODO send the search to the backend + this.http.post('https://api.yacs.maoyu.wang/userEvent', { + "uid": sessionStorage.getItem('userID'), + "eventID": "3", + "data": { + 'Search' : $event.item + }, + "createdAt": Date.now() + }).subscribe( + data => {console.log(data)}, + err => {console.log(err)} + ); + this.router.navigate(['/courses'], { queryParams: { longname: $event.item diff --git a/web/src/app/listing/component.ts b/web/src/app/listing/component.ts index 9b3a6bc5..24ad2de7 100644 --- a/web/src/app/listing/component.ts +++ b/web/src/app/listing/component.ts @@ -4,7 +4,6 @@ import { ScheduleEvent } from '../models/schedule-event.model'; import { SelectionService } from '../services/selection.service'; import { ConflictsService } from '../services/conflicts.service'; import { SidebarService } from '../services/sidebar.service'; -import { v4 as uuid } from 'uuid'; import { HttpClient, HttpHeaders } from '@angular/common/http'; @Component({ @@ -76,8 +75,6 @@ export class ListingComponent implements OnInit{ } public clickCourse () { - - let event: string; if(this.isCourseSelected()){ event = "2"; @@ -85,7 +82,6 @@ export class ListingComponent implements OnInit{ event = "1"; } let time: number = Date.now(); - //console.log(time); for(let sec of this.listing.sections){ if(event == "1" || this.isSectionSelected(sec)){ @@ -120,9 +116,9 @@ export class ListingComponent implements OnInit{ let event: string; if(this.isSectionSelected(section)){ - event = "2"; - }else{ event = "1"; + }else{ + event = "2"; } //Sends the info about the course to the user system backend this.http.post('https://api.yacs.maoyu.wang/userEvent', { diff --git a/web/src/app/school-list/school/component.ts b/web/src/app/school-list/school/component.ts index 7ef574d2..37cc6277 100644 --- a/web/src/app/school-list/school/component.ts +++ b/web/src/app/school-list/school/component.ts @@ -1,6 +1,7 @@ import { Component, OnInit, Input } from '@angular/core'; import { Router } from '@angular/router'; import { School } from 'yacs-api-client'; +import { HttpClient, HttpHeaders } from '@angular/common/http'; @Component({ selector: 'school', @@ -10,9 +11,30 @@ import { School } from 'yacs-api-client'; export class SchoolComponent { @Input() school: School; - constructor(private router:Router){} + constructor(private router:Router, private http: HttpClient){} public changeRoute(id): void { + //gets the name of the department + let schoolName: string; + for(let sub of this.school.subjects){ + if(sub.id == id){ + schoolName = sub.longname; + } + } + //Sends the department the user clicked to the user system backend + this.http.post('https://api.yacs.maoyu.wang/userEvent', { + "uid": sessionStorage.getItem('userID'), + "eventID": "5", + "data": { + 'Department Title' : schoolName + + }, + "createdAt": Date.now() + }).subscribe( + data => {console.log(data)}, + err => {console.log(err)} + ); + this.router.navigateByUrl('/courses?subject_id=' + id); } @@ -20,6 +42,26 @@ export class SchoolComponent { const keyCode = evt.which; const enterKey = 13; if(enterKey == keyCode){ + //gets the name of the department + let schoolName: string; + for(let sub of this.school.subjects){ + if(sub.id == id){ + schoolName = sub.longname; + } + } + //Sends the department the user clicked to the user system backend + this.http.post('https://api.yacs.maoyu.wang/userEvent', { + "uid": sessionStorage.getItem('userID'), + "eventID": "5", + "data": { + 'Department Title' : schoolName + + }, + "createdAt": Date.now() + }).subscribe( + data => {console.log(data)}, + err => {console.log(err)} + ); this.router.navigateByUrl('/courses?subject_id=' + id); } }