Commit b4cb55fa authored by Thomas Frion's avatar Thomas Frion

[UPDF|CLEAN] Get services saved in the database via API

* We update the model of Service to add a method aims get a setting by his name
* We remove unless components
parent c1c6523f
<div class="main-container">
<app-sidebar-left class="left-menu"></app-sidebar-left>
<app-map></app-map>
</div>
<!-- NOT DONE YET:
<app-sidebar-right class='right-menu'></app-sidebar-right> #}
<app-coord-map></app-coord-map>
-->
</div>
\ No newline at end of file
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { CoordMapComponent } from './coord-map.component';
describe('CoordMapComponent', () => {
let component: CoordMapComponent;
let fixture: ComponentFixture<CoordMapComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ CoordMapComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(CoordMapComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
import { Component, OnInit } from '@angular/core';
/**
* @CoordMapComponent:
* Component to display the coordinates of the pointer on the map,
* they are displayed at the bottom-roght of the scree
*/
@Component({
selector: 'app-coord-map',
templateUrl: './coord-map.component.html',
styleUrls: ['./coord-map.component.scss']
})
export class CoordMapComponent implements OnInit {
constructor() { }
ngOnInit(): void {
}
}
......@@ -7,22 +7,22 @@ import { IApiService } from '../api-client.interface';
import { AuthGuard } from '../../auth-guard.service';;
@Injectable()
export class ServiceApi extends ApiService<models.Service> implements IApiService<models.Service>{
export class ServiceApi extends ApiService<models.IService> implements IApiService<models.IService>{
constructor(protected http: HttpClient, protected authGuard : AuthGuard) {
super(http, authGuard);
}
public all(headers?: HttpHeaders): Promise<models.Service[]> {
public all(headers?: HttpHeaders): Promise<models.IService[]> {
return this.get('/services/', headers);
}
public one(selector: any, headers?: HttpHeaders): Promise<models.Service> {
public one(selector: any, headers?: HttpHeaders): Promise<models.IService> {
return this.read('/services/' + selector, headers);
}
public save(elem: models.Service, headers?: HttpHeaders): Promise<models.Service> {
let result : Promise<models.Service>;
public save(elem: models.Service, headers?: HttpHeaders): Promise<models.IService> {
let result : Promise<models.IService>;
if(elem.id !== undefined){
result = this.update('/services/' + elem.id, JSON.stringify(elem), headers);
......
......@@ -12,11 +12,44 @@ export interface ServiceSettings{
* @interface :
* Model representing an external service
*/
export interface Service {
export interface IService {
readonly id?: number,
readonly serviceSettings?: ServiceSettings[],
name: string,
baseUrl: string,
key?: string,
desc?: string
}
export class Service {
readonly id?: number;
readonly serviceSettings?: ServiceSettings[];
name: string;
baseUrl: string;
key?: string;
desc?: string;
constructor(contract: IService){
this.id = contract.id;
this.serviceSettings = contract.serviceSettings;
this.name = contract.name;
this.baseUrl = contract.baseUrl;
this.key = contract.key;
this.desc = contract.desc;
}
public getSetting(name: string) : ServiceSettings {
let i = 0;
let setting : ServiceSettings = null;
while(i < this.serviceSettings.length && setting == null){
if(this.serviceSettings[i].name == name){
setting = this.serviceSettings[i];
}
i++;
}
return setting;
}
}
\ No newline at end of file
<div class="right-container">
</div>
\ No newline at end of file
.right-container{
background: #fff;
display: inline-block;
width: 200px;
height: 150px;
z-index: 24;
}
\ No newline at end of file
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { SidebarRightComponent } from './sidebar-right.component';
describe('SidebarRightComponent', () => {
let component: SidebarRightComponent;
let fixture: ComponentFixture<SidebarRightComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ SidebarRightComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(SidebarRightComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
import { Component, OnInit } from '@angular/core';
/**
* @SidebarRightComponent :
* Component for the side bar on the right of the screen
*/
@Component({
selector: 'app-sidebar-right',
templateUrl: './sidebar-right.component.html',
styleUrls: ['./sidebar-right.component.scss']
})
export class SidebarRightComponent implements OnInit {
constructor() { }
ngOnInit(): void {
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment