Jakub Man | 81d1f0c | 2020-12-21 10:04:09 +0100 | [diff] [blame^] | 1 | /**
|
| 2 | * Author: Jakub Man <xmanja00@stud.fit.vutbr.cz>
|
| 3 | * Service for handling profile operations
|
| 4 | */
|
| 5 | import { Injectable } from '@angular/core';
|
| 6 | import { HttpClient, HttpParams } from '@angular/common/http';
|
| 7 | import { Observable } from 'rxjs';
|
| 8 | import { ProfileDevice } from "../classes/ProfileDevice";
|
| 9 | import {ProfileItem} from '../classes/ProfileItem';
|
| 10 | import {GenericServerResponse} from '../classes/GenericServerResponse';
|
| 11 |
|
| 12 | // TODO: Caching to prevent multiple unnecessary HTTP requests
|
| 13 |
|
| 14 | @Injectable({
|
| 15 | providedIn: 'root'
|
| 16 | })
|
| 17 | export class ProfileService {
|
| 18 | constructor(
|
| 19 | private http: HttpClient
|
| 20 | ) {}
|
| 21 |
|
| 22 | /**
|
| 23 | * Get all devices from profile, that uses sets as a default profile
|
| 24 | */
|
| 25 | public getOnLoginProfile(): Observable<{devices: ProfileDevice[], name: string, connectOnLogin: boolean}> {
|
| 26 | return this.http.get<{devices: ProfileDevice[], name: string, connectOnLogin: boolean}>('/netconf/profileOnLogin');
|
| 27 | }
|
| 28 |
|
| 29 | public getProfileDevices(profileName: string): Observable<ProfileDevice[]> {
|
| 30 | return this.http.get<ProfileDevice[]>('/netconf/profile/' + profileName);
|
| 31 |
|
| 32 | }
|
| 33 |
|
| 34 | public getAllProfileNames(): Observable<string[]> {
|
| 35 | return this.http.get<string[]>('/netconf/profiles');
|
| 36 | }
|
| 37 |
|
| 38 | public addProfile(name: string): Observable<object> {
|
| 39 | return this.http.post<object>('/netconf/profile', {profile: name});
|
| 40 | }
|
| 41 |
|
| 42 | public removeProfile(name: string): Observable<object> {
|
| 43 | return this.http.post<object>('/netconf/removeProfile', {profile: name});
|
| 44 | }
|
| 45 |
|
| 46 | public setActiveProfile(profileName: string): Observable<object> {
|
| 47 | return this.http.post<object>('/netconf/activateProfile', {profile: profileName});
|
| 48 | }
|
| 49 |
|
| 50 | public saveProfile(profileName: string, profiles: ProfileItem[]): Observable<GenericServerResponse> {
|
| 51 | return this.http.post<GenericServerResponse>('/netconf/profileSet', {profile: profileName, value: profiles});
|
| 52 | }
|
| 53 |
|
| 54 | public setProfileConnectOnLogin(profileName: string, value: boolean): Observable<GenericServerResponse> {
|
| 55 | return this.http.post<GenericServerResponse>('/netconf/profile/setConnectOnLogin', {profile: profileName, value});
|
| 56 | }
|
| 57 | }
|