Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Add API service to connect to backend.
Added environment files, to launch locally do: npm run start:local Added example usage of resource service.
- Loading branch information
Showing
10 changed files
with
139 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,32 @@ | ||
import { Component } from '@angular/core'; | ||
import { Component, OnInit } from '@angular/core'; | ||
import { ResourceService } from './services/api/resource.service'; | ||
|
||
@Component({ | ||
selector: 'app-root', | ||
templateUrl: './app.component.html', | ||
styleUrls: ['./app.component.css'] | ||
}) | ||
export class AppComponent { | ||
export class AppComponent implements OnInit { | ||
|
||
title = 'SystemNavigationFrontend'; | ||
|
||
constructor( | ||
private resourceService: ResourceService | ||
) {} | ||
|
||
ngOnInit() { | ||
// Example usage of resource service. | ||
this.resourceService.getResourceStandard('test.txt', 'text').toPromise().then(val => console.log('Test file', val)) | ||
.catch(err => console.log(err)); | ||
this.resourceService.getResourcePDF('radar.pdf').toPromise().then(val => { | ||
console.log('Radar pdf', val); | ||
const file = new Blob([val], { type: 'application/pdf' }); | ||
const url = URL.createObjectURL(file); | ||
console.log('PDF Viewable at', url); | ||
console.log('Adblock prevents it from opening'); | ||
// window.open(url); | ||
}) | ||
.catch(err => console.log(err)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http'; | ||
import { environment } from 'src/environments/environment'; | ||
|
||
export class APIService { | ||
|
||
protected baseURL = environment.baseURL + '/api'; | ||
|
||
constructor( | ||
private http: HttpClient | ||
) {} | ||
|
||
_get(endpoint: string, options?: any) { | ||
return this.http.get(`${this.baseURL}/${endpoint}`, options); | ||
} | ||
|
||
_post(endpoint: string, body: any) { | ||
return this.http.post(`${this.baseURL}/${endpoint}`, body); | ||
} | ||
|
||
_put(endpoint: string, body: any) { | ||
return this.http.put(`${this.baseURL}/${endpoint}`, body); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { APIService } from './api.service'; | ||
import { Injectable } from '@angular/core'; | ||
import { HttpClient } from '@angular/common/http'; | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class ResourceService extends APIService { | ||
|
||
baseEndpoint = 'resources'; | ||
|
||
constructor( | ||
http: HttpClient | ||
) { | ||
super(http); | ||
} | ||
|
||
get(endpoint: string, options?: any) { | ||
return super._get(`${this.baseEndpoint}/${endpoint}`, options); | ||
} | ||
|
||
post(endpoint: string, body: any) { | ||
return super._post(`${this.baseEndpoint}/${endpoint}`, body); | ||
} | ||
|
||
put(endpoint: string, body: any) { | ||
return super._put(`${this.baseEndpoint}/${endpoint}`, body); | ||
} | ||
|
||
getResourceStandard(key: string, responseType: string) { | ||
return this.get(key, { responseType }); | ||
} | ||
|
||
getResourcePDF(key: string) { | ||
return this.get(`pdf/${key}`, { | ||
responseType: 'arraybuffer' | ||
}); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export const environment = { | ||
production: false, | ||
envName: 'dev', | ||
baseURL: 'replaceMe' | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// This file can be replaced during build by using the `fileReplacements` array. | ||
// `ng build --prod` replaces `environment.ts` with `environment.prod.ts`. | ||
// The list of file replacements can be found in `angular.json`. | ||
|
||
export const environment = { | ||
production: false, | ||
envName: 'local', | ||
baseURL: 'http://localhost:8080/3dsysnavbackend' | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
export const environment = { | ||
production: true | ||
production: true, | ||
envName: 'production', | ||
baseURL: 'replaceMe' | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters