Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Pulled from master and fixed conflicts
  • Loading branch information
jos15101 committed Feb 11, 2020
2 parents 9dc8340 + 714b4e1 commit edae4c0
Show file tree
Hide file tree
Showing 11 changed files with 150 additions and 18 deletions.
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -10,9 +10,9 @@
* `npm i -g @angular/cli` Install angular cli
* `npm i` Install dependencies

### Run
### Run With Local Backend

* `npm start`
* `npm run start:local`

Project server is now live at `localhost:4200`

Expand Down
22 changes: 22 additions & 0 deletions angular.json
Expand Up @@ -60,6 +60,22 @@
"maximumError": "10kb"
}
]
},
"local": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.local.ts"
}
]
},
"dev": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.dev.ts"
}
]
}
}
},
Expand All @@ -71,6 +87,12 @@
"configurations": {
"production": {
"browserTarget": "SystemNavigationFrontend:build:production"
},
"local": {
"browserTarget": "SystemNavigationFrontend:build:local"
},
"dev": {
"browserTarget": "SystemNavigationFrontend:build:dev"
}
}
},
Expand Down
6 changes: 6 additions & 0 deletions package.json
Expand Up @@ -5,6 +5,12 @@
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"start:local": "ng serve -c=local",
"build:local": "ng build -c=local",
"start:dev": "ng serve -c=dev",
"build:dev": "ng build -c=dev",
"start:prod": "ng serve -c=prod",
"build:prod": "ng build -c=prod",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
Expand Down
26 changes: 24 additions & 2 deletions src/app/app.component.ts
@@ -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));
}

}
24 changes: 12 additions & 12 deletions src/app/app.module.ts
@@ -1,14 +1,14 @@
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { BrowserModule } from "@angular/platform-browser";
import { NgModule } from "@angular/core";

import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { TreeComponent } from './tree/tree.component';
import {ButtonModule, MessageService, TreeModule} from 'primeng/primeng';
import {HttpClientModule} from '@angular/common/http';
import { MainComponent } from './main/main.component';
import { CenterComponent } from './center/center.component';
import { LeftComponent } from './left/left.component';
import { AppRoutingModule } from "./app-routing.module";
import { AppComponent } from "./app.component";
import { TreeComponent } from "./tree/tree.component";
import { ButtonModule, MessageService, TreeModule } from "primeng/primeng";
import { MainComponent } from "./main/main.component";
import { CenterComponent } from "./center/center.component";
import { LeftComponent } from "./left/left.component";
import { HttpClientModule } from "@angular/common/http";

@NgModule({
declarations: [
Expand All @@ -25,7 +25,7 @@ import { LeftComponent } from './left/left.component';
HttpClientModule,
ButtonModule
],
providers: [ MessageService],
providers: [MessageService],
bootstrap: [AppComponent]
})
export class AppModule { }
export class AppModule {}
24 changes: 24 additions & 0 deletions src/app/services/api/api.service.ts
@@ -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);
}

}
40 changes: 40 additions & 0 deletions src/app/services/api/resource.service.ts
@@ -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'
});
}

}
5 changes: 5 additions & 0 deletions src/environments/environment.dev.ts
@@ -0,0 +1,5 @@
export const environment = {
production: false,
envName: 'dev',
baseURL: 'replaceMe'
};
9 changes: 9 additions & 0 deletions src/environments/environment.local.ts
@@ -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'
};
4 changes: 3 additions & 1 deletion src/environments/environment.prod.ts
@@ -1,3 +1,5 @@
export const environment = {
production: true
production: true,
envName: 'production',
baseURL: 'replaceMe'
};
4 changes: 3 additions & 1 deletion src/environments/environment.ts
Expand Up @@ -3,7 +3,9 @@
// The list of file replacements can be found in `angular.json`.

export const environment = {
production: false
production: false,
envName: 'default',
baseURL: 'http://localhost:8080/3dsysnavbackend'
};

/*
Expand Down

0 comments on commit edae4c0

Please sign in to comment.