/// /// Copyright © 2016-2020 The Thingsboard Authors /// /// Licensed under the Apache License, Version 2.0 (the "License"); /// you may not use this file except in compliance with the License. /// You may obtain a copy of the License at /// /// http://www.apache.org/licenses/LICENSE-2.0 /// /// Unless required by applicable law or agreed to in writing, software /// distributed under the License is distributed on an "AS IS" BASIS, /// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. /// See the License for the specific language governing permissions and /// limitations under the License. /// import { Injectable } from '@angular/core'; import { defaultHttpOptionsFromConfig, RequestConfig } from './http-utils'; import { Observable } from 'rxjs'; import { HttpClient } from '@angular/common/http'; import { PageLink, TimePageLink } from '@shared/models/page/page-link'; import { PageData } from '@shared/models/page/page-data'; import { EntitySubtype } from '@app/shared/models/entity-type.models'; import { Edge, EdgeEvent, EdgeInfo, EdgeSearchQuery } from "@shared/models/edge.models"; import { EntityId } from "@shared/models/id/entity-id"; import { EdgeId } from "@shared/models/id/edge-id"; @Injectable({ providedIn: 'root' }) export class EdgeService { constructor( private http: HttpClient ) { } public getEdges(edgeIds: Array, config?: RequestConfig): Observable> { return this.http.get>(`/api/edges?edgeIds=${edgeIds.join(',')}`, defaultHttpOptionsFromConfig(config)); } public getEdge(edgeId: string, config?: RequestConfig): Observable { return this.http.get(`/api/edge/${edgeId}`, defaultHttpOptionsFromConfig(config)); } public getEdgeInfo(edgeId: string, config?: RequestConfig): Observable { return this.http.get(`/api/edge/info/${edgeId}`, defaultHttpOptionsFromConfig(config)); } public saveEdge(edge: Edge, config?: RequestConfig): Observable { return this.http.post('/api/edge', edge, defaultHttpOptionsFromConfig(config)); } public deleteEdge(edgeId: string, config?: RequestConfig) { return this.http.delete(`/api/edge/${edgeId}`, defaultHttpOptionsFromConfig(config)); } public getEdgeTypes(config?: RequestConfig): Observable> { return this.http.get>('/api/edge/types', defaultHttpOptionsFromConfig(config)); } public getCustomerEdgeInfos(customerId: string, pageLink: PageLink, type: string = '', config?: RequestConfig): Observable> { return this.http.get>(`/api/customer/${customerId}/edgeInfos${pageLink.toQuery()}&type=${type}`, defaultHttpOptionsFromConfig(config)); } public assignEdgeToCustomer(customerId: string, edgeId: string, config?: RequestConfig): Observable { return this.http.post(`/api/customer/${customerId}/edge/${edgeId}`, defaultHttpOptionsFromConfig(config)); } public unassignEdgeFromCustomer(edgeId: string, config?: RequestConfig) { return this.http.delete(`/api/customer/edge/${edgeId}`, defaultHttpOptionsFromConfig(config)); } public makeEdgePublic(edgeId: string, config?: RequestConfig): Observable { return this.http.post(`/api/customer/public/edge/${edgeId}`, null, defaultHttpOptionsFromConfig(config)); } public getTenantEdgeInfos(pageLink: PageLink, type: string = '', config?: RequestConfig): Observable> { return this.http.get>(`/api/tenant/edgeInfos${pageLink.toQuery()}&type=${type}`, defaultHttpOptionsFromConfig(config)); } public findByQuery(query: EdgeSearchQuery, config?: RequestConfig): Observable> { return this.http.post>('/api/edges', query, defaultHttpOptionsFromConfig(config)); } public getEdgeEvents(entityId: EntityId, pageLink: TimePageLink, config?: RequestConfig): Observable> { return this.http.get>(`/api/edge/${entityId.id}/events` + `${pageLink.toQuery()}`, defaultHttpOptionsFromConfig(config)); } public syncEdge(edgeId: EdgeId, config?: RequestConfig) { return this.http.post(`/api/edge/sync`, edgeId, defaultHttpOptionsFromConfig(config)); } }