diff options
author | Danijel Andjelkovic <adanijel99@gmail.com> | 2022-05-05 00:46:39 +0000 |
---|---|---|
committer | Danijel Andjelkovic <adanijel99@gmail.com> | 2022-05-05 00:46:39 +0000 |
commit | c77c5289d01f1f02a57a060dc2166b449e597881 (patch) | |
tree | cb64f2775335cdd856e81ec9e8ba0bed93fa0985 /frontend/src/app/_services | |
parent | 6f48458e058d3e5a8d559adc22adbe78cba9a253 (diff) | |
parent | 15c60cb0c179d2d3c353ab3e19370e16d02176eb (diff) |
Merge branch 'redesign' into 'master'
merge
See merge request igrannonica/neuronstellar!29
Diffstat (limited to 'frontend/src/app/_services')
-rw-r--r-- | frontend/src/app/_services/auth.service.ts | 30 | ||||
-rw-r--r-- | frontend/src/app/_services/configuration.service.spec.ts | 16 | ||||
-rw-r--r-- | frontend/src/app/_services/configuration.service.ts | 20 | ||||
-rw-r--r-- | frontend/src/app/_services/csv-parse.service.ts | 40 | ||||
-rw-r--r-- | frontend/src/app/_services/datasets.service.ts | 7 | ||||
-rw-r--r-- | frontend/src/app/_services/experiments.service.ts | 6 | ||||
-rw-r--r-- | frontend/src/app/_services/models.service.ts | 20 | ||||
-rw-r--r-- | frontend/src/app/_services/predictors.service.ts | 10 | ||||
-rw-r--r-- | frontend/src/app/_services/signal-r.service.ts | 13 | ||||
-rw-r--r-- | frontend/src/app/_services/user-info.service.ts | 2 |
10 files changed, 128 insertions, 36 deletions
diff --git a/frontend/src/app/_services/auth.service.ts b/frontend/src/app/_services/auth.service.ts index 9e3f9f2f..cc5ad688 100644 --- a/frontend/src/app/_services/auth.service.ts +++ b/frontend/src/app/_services/auth.service.ts @@ -3,7 +3,7 @@ import { HttpClient, HttpHeaders } from '@angular/common/http'; import { JwtHelperService } from '@auth0/angular-jwt'; import { CookieService } from 'ngx-cookie-service'; import shared from '../Shared'; -import { Configuration } from '../configuration.service'; +import { Configuration } from './configuration.service'; const jwtHelper = new JwtHelperService(); @@ -12,9 +12,8 @@ const jwtHelper = new JwtHelperService(); }) export class AuthService { - public loggedInEvent: EventEmitter<boolean> = new EventEmitter(); - shared = shared; + public loggedInEvent: EventEmitter<boolean> = new EventEmitter(); constructor(private http: HttpClient, private cookie: CookieService) { } @@ -23,7 +22,7 @@ export class AuthService { } register(user: any) { - return this.http.post(`${Configuration.settings.apiURL}/auth/register`, { ...user }, { responseType: 'text' }); + return this.http.post(`${Configuration.settings.apiURL}/auth/register`, { ...user },{ headers: this.authHeader() , responseType: 'text' }); } getGuestToken() { @@ -53,26 +52,19 @@ export class AuthService { } var property = jwtHelper.decodeToken(this.cookie.get('token')); var username = property['name']; - if (username != "") { this.refresher = setTimeout(() => { this.http.post(`${Configuration.settings.apiURL}/auth/renewJwt`, {}, { headers: this.authHeader(), responseType: 'text' }).subscribe((response) => { this.authenticate(response); }); }, exp.getTime() - new Date().getTime() - 60000); - } - else { - this.refresher = setTimeout(() => { - this.getGuestToken().subscribe((response) => { - this.authenticate(response); - }); - }, exp.getTime() - new Date().getTime() - 60000); - } + } addGuestToken() { this.getGuestToken().subscribe((token) => { this.authenticate(token); + location.reload(); }); } @@ -83,7 +75,6 @@ export class AuthService { } this.cookie.set('token', token, exp); this.updateUser(); - this.loggedInEvent.emit(true); } updateUser() { @@ -108,4 +99,15 @@ export class AuthService { authHeader() { return new HttpHeaders().set("Authorization", "Bearer " + this.cookie.get('token')); } + alreadyGuest(){ + if(this.cookie.check('token')){ + const token = this.cookie.get('token'); + const decodedToken = jwtHelper.decodeToken(token); + if(decodedToken.role=="Guest") + return true; + } + return false; + } + + } diff --git a/frontend/src/app/_services/configuration.service.spec.ts b/frontend/src/app/_services/configuration.service.spec.ts new file mode 100644 index 00000000..4b9322b5 --- /dev/null +++ b/frontend/src/app/_services/configuration.service.spec.ts @@ -0,0 +1,16 @@ +import { TestBed } from '@angular/core/testing'; + +import { Configuration as ConfigurationService } from './configuration.service'; + +describe('ConfigurationService', () => { + let service: ConfigurationService; + + beforeEach(() => { + TestBed.configureTestingModule({}); + service = TestBed.inject(ConfigurationService); + }); + + it('should be created', () => { + expect(service).toBeTruthy(); + }); +}); diff --git a/frontend/src/app/_services/configuration.service.ts b/frontend/src/app/_services/configuration.service.ts new file mode 100644 index 00000000..cda1091a --- /dev/null +++ b/frontend/src/app/_services/configuration.service.ts @@ -0,0 +1,20 @@ +import { Injectable } from '@angular/core'; +import { HttpClient } from '@angular/common/http'; +import { IConfig } from '../_data/IConfig' + +@Injectable() +export class Configuration { + static settings: IConfig; + constructor(private http: HttpClient) { } + load() { + const jsonFile = 'assets/config.json'; + return new Promise<void>((resolve, reject) => { + this.http.get(jsonFile).toPromise().then((response) => { + Configuration.settings = <IConfig>response; + resolve(); + }).catch((response: any) => { + reject(`Could not load file '${jsonFile}': ${JSON.stringify(response)}`); + }); + }); + } +}
\ No newline at end of file diff --git a/frontend/src/app/_services/csv-parse.service.ts b/frontend/src/app/_services/csv-parse.service.ts index 4a05535a..aae10193 100644 --- a/frontend/src/app/_services/csv-parse.service.ts +++ b/frontend/src/app/_services/csv-parse.service.ts @@ -1,4 +1,10 @@ import { Injectable } from "@angular/core"; +import * as FileSaver from 'file-saver'; +import * as XLSX from 'xlsx'; + +const EXCEL_TYPE = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=UTF-8'; +const EXCEL_EXTENSION = '.xlsx'; + @Injectable({ providedIn: 'root' }) export class CsvParseService { @@ -47,10 +53,42 @@ export class CsvParseService { if (strMatchedValue.length > 0) arrData[arrData.length - 1].push(strMatchedValue); - else + else arrData[arrData.length - 1].push(null); } return (arrData); } + + ConvertJSONToCSV(objArray: string, headerList: { [x: string]: any; }) { + let array = typeof objArray != 'object' ? JSON.parse(objArray) : objArray; + let str = ''; + let row = 'S.No,'; + for (let index in headerList) { + row += headerList[index] + ','; + } + row = row.slice(0, -1); + str += row + '\r\n'; + for (let i = 0; i < array.length; i++) { + let line = (i + 1) + ''; + for (let index in headerList) { + let head = headerList[index]; + line += ',' + array[i][head]; + } + str += line + '\r\n'; + } + return str; + } + + public exportAsExcelFile(json: any[], excelFileName: string): void { + const worksheet: XLSX.WorkSheet = XLSX.utils.json_to_sheet(json); + const workbook: XLSX.WorkBook = { Sheets: { 'data': worksheet }, SheetNames: ['data'] }; + const excelBuffer: any = XLSX.write(workbook, { bookType: 'xlsx', type: 'array' }); + this.saveAsExcelFile(excelBuffer, excelFileName); + } + + private saveAsExcelFile(buffer: any, fileName: string): void { + const data: Blob = new Blob([buffer], { type: EXCEL_TYPE }); + FileSaver.saveAs(data, fileName + '_export_' + new Date().getTime() + EXCEL_EXTENSION); + } }
\ No newline at end of file diff --git a/frontend/src/app/_services/datasets.service.ts b/frontend/src/app/_services/datasets.service.ts index b2272f0a..2211996f 100644 --- a/frontend/src/app/_services/datasets.service.ts +++ b/frontend/src/app/_services/datasets.service.ts @@ -1,7 +1,7 @@ import { HttpClient } from '@angular/common/http'; import { Injectable } from '@angular/core'; import { Observable } from 'rxjs'; -import { Configuration } from '../configuration.service'; +import { Configuration } from './configuration.service'; import Dataset from '../_data/Dataset'; import { AuthService } from './auth.service'; @@ -25,7 +25,10 @@ export class DatasetsService { } getDatasetFile(fileId: any): any { - return this.http.get(`${Configuration.settings.apiURL}/file/csvRead/true/${fileId}`, { headers: this.authService.authHeader(), responseType: 'text' }); + return this.http.get(`${Configuration.settings.apiURL}/file/csvRead/${fileId}/-1/11`, { headers: this.authService.authHeader(), responseType: 'text' }); + } + getDatasetFilePartial(fileId: any, startRow: number, rowNum: number): Observable<any> { + return this.http.get(`${Configuration.settings.apiURL}/file/csvRead/${fileId}/${startRow}/${rowNum}`, { headers: this.authService.authHeader(), responseType: 'text' }); } editDataset(dataset: Dataset): Observable<Dataset> { diff --git a/frontend/src/app/_services/experiments.service.ts b/frontend/src/app/_services/experiments.service.ts index 0d0d372b..29569fca 100644 --- a/frontend/src/app/_services/experiments.service.ts +++ b/frontend/src/app/_services/experiments.service.ts @@ -1,7 +1,7 @@ import { HttpClient } from '@angular/common/http'; import { Injectable } from '@angular/core'; import { Observable } from 'rxjs'; -import { Configuration } from '../configuration.service'; +import { Configuration } from './configuration.service'; import Experiment from '../_data/Experiment'; import { AuthService } from './auth.service'; @@ -19,4 +19,8 @@ export class ExperimentsService { getMyExperiments(): Observable<Experiment[]> { return this.http.get<Experiment[]>(`${Configuration.settings.apiURL}/experiment/getmyexperiments`, { headers: this.authService.authHeader() }); } + + updateExperiment(experiment: Experiment): Observable<Experiment> { + return this.http.put<Experiment>(`${Configuration.settings.apiURL}/experiment/` + experiment._id, experiment, { headers: this.authService.authHeader() }); + } } diff --git a/frontend/src/app/_services/models.service.ts b/frontend/src/app/_services/models.service.ts index 1130b12c..fc888556 100644 --- a/frontend/src/app/_services/models.service.ts +++ b/frontend/src/app/_services/models.service.ts @@ -1,10 +1,10 @@ import { HttpClient, HttpParams } from '@angular/common/http'; import { Injectable } from '@angular/core'; -import Model, { ProblemType } from '../_data/Model'; +import Model from '../_data/Model'; import { AuthService } from './auth.service'; import { Observable } from 'rxjs'; import Dataset from '../_data/Dataset'; -import { Configuration } from '../configuration.service'; +import { Configuration } from '../_services/configuration.service'; @Injectable({ providedIn: 'root' @@ -31,16 +31,20 @@ export class ModelsService { addModel(model: Model): Observable<any> { return this.http.post(`${Configuration.settings.apiURL}/model/add`, model, { headers: this.authService.authHeader() }); } + addDataset(dataset: Dataset): Observable<any> { + return this.http.post(`${Configuration.settings.apiURL}/dataset/add`, dataset, { headers: this.authService.authHeader() }); + } trainModel(modelId: string, experimentId: string): Observable<any> { return this.http.post(`${Configuration.settings.apiURL}/model/trainmodel`, { ModelId: modelId, ExperimentId: experimentId }, { headers: this.authService.authHeader(), responseType: 'text' }); } + getMyDatasets(): Observable<Dataset[]> { + return this.http.get<Dataset[]>(`${Configuration.settings.apiURL}/dataset/mydatasets`, { headers: this.authService.authHeader() }); + } + getMyModels(): Observable<Model[]> { return this.http.get<Model[]>(`${Configuration.settings.apiURL}/model/mymodels`, { headers: this.authService.authHeader() }); } - getMyModelsByType(problemType: ProblemType): Observable<Model[]> { - return this.http.get<Model[]>(`${Configuration.settings.apiURL}/model/mymodelsbytype/` + problemType, { headers: this.authService.authHeader() }); - } editModel(model: Model): Observable<Model> { return this.http.put<Model>(`${Configuration.settings.apiURL}/model/`, model, { headers: this.authService.authHeader() }); @@ -49,5 +53,9 @@ export class ModelsService { deleteModel(model: Model) { return this.http.delete(`${Configuration.settings.apiURL}/model/` + model.name, { headers: this.authService.authHeader(), responseType: "text" }); } - + + getPublicModels(): Observable<Model[]> { + return this.http.get<Model[]>(`${Configuration.settings.apiURL}/model/publicmodels`, { headers: this.authService.authHeader() }); + } + } diff --git a/frontend/src/app/_services/predictors.service.ts b/frontend/src/app/_services/predictors.service.ts index a24ee708..e2033e3e 100644 --- a/frontend/src/app/_services/predictors.service.ts +++ b/frontend/src/app/_services/predictors.service.ts @@ -1,9 +1,8 @@ import { HttpClient } from '@angular/common/http'; import { Injectable } from '@angular/core'; import { Observable } from 'rxjs'; -import { Configuration } from '../configuration.service'; +import { Configuration } from './configuration.service'; import Predictor from '../_data/Predictor'; -import { Column } from '../_pages/predict/predict.component'; import { AuthService } from './auth.service'; @Injectable({ @@ -31,3 +30,10 @@ export class PredictorsService { return this.http.get<Predictor[]>(`${Configuration.settings.apiURL}/predictor/mypredictors`, { headers: this.authService.authHeader() }); } } + +export class Column { + constructor( + public name: string, + public value: (number | string)) { + } +}
\ No newline at end of file diff --git a/frontend/src/app/_services/signal-r.service.ts b/frontend/src/app/_services/signal-r.service.ts index 6a2e61e9..234636fe 100644 --- a/frontend/src/app/_services/signal-r.service.ts +++ b/frontend/src/app/_services/signal-r.service.ts @@ -1,7 +1,7 @@ import { Injectable } from '@angular/core'; import * as signalR from "@microsoft/signalr"; import { CookieService } from 'ngx-cookie-service'; -import { Configuration } from '../configuration.service'; +import { Configuration } from './configuration.service'; @Injectable({ providedIn: 'root' }) @@ -16,18 +16,13 @@ export class SignalRService { }).build(); this.hubConnection.on("Notify", (message: string) => { - //console.log(" " + message); + console.log(" " + message); }); this.hubConnection .start() - .then(() => {}) - .catch(err => {}) + .then(() => console.log("con Started")) + .catch(err => console.log("Error" + err)) } - - public stopConnection = () => { - this.hubConnection?.stop(); - } - constructor(private cookie: CookieService) { } } diff --git a/frontend/src/app/_services/user-info.service.ts b/frontend/src/app/_services/user-info.service.ts index 5d3394f6..8efeb903 100644 --- a/frontend/src/app/_services/user-info.service.ts +++ b/frontend/src/app/_services/user-info.service.ts @@ -1,7 +1,7 @@ import { HttpClient } from '@angular/common/http'; import { Injectable } from '@angular/core'; import { Observable } from 'rxjs'; -import { Configuration } from '../configuration.service'; +import { Configuration } from './configuration.service'; import User from '../_data/User'; import { AuthService } from './auth.service'; |