2023-01-20 16:57:03 +01:00
|
|
|
import { Injectable } from '@angular/core';
|
2023-01-26 10:55:02 +01:00
|
|
|
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
|
2023-01-25 16:08:32 +01:00
|
|
|
import { ResourceType,Protocol,WfHistoryEntry,SimpleResource } from './model/controller.model';
|
2023-01-20 16:57:03 +01:00
|
|
|
import { Observable, Observer } from 'rxjs';
|
|
|
|
|
|
|
|
@Injectable({
|
|
|
|
providedIn: 'root'
|
|
|
|
})
|
|
|
|
export class ISService {
|
|
|
|
|
|
|
|
constructor(public client:HttpClient) { }
|
|
|
|
|
|
|
|
|
|
|
|
loadResourceTypes():Observable<ResourceType[]> {
|
|
|
|
return this.client.get<ResourceType[]>("/ajax/resourceTypes");
|
|
|
|
}
|
|
|
|
|
2023-01-25 16:08:32 +01:00
|
|
|
loadResourceType(id:string):Observable<ResourceType> {
|
|
|
|
return this.client.get<ResourceType>("/ajax/resourceTypes/" + encodeURIComponent(id));
|
|
|
|
}
|
|
|
|
|
2023-01-20 16:57:03 +01:00
|
|
|
loadInfo():Observable<any[]> {
|
|
|
|
return this.client.get<any[]>("/ajax/info/");
|
|
|
|
}
|
|
|
|
|
|
|
|
loadProtocols():Observable<Protocol[]> {
|
|
|
|
return this.client.get<Protocol[]>("/ajax/protocols/");
|
|
|
|
}
|
|
|
|
|
2023-01-25 16:08:32 +01:00
|
|
|
loadSimpleResources(type:string):Observable<SimpleResource[]> {
|
|
|
|
return this.client.get<SimpleResource[]>("/ajax/resources/" + encodeURIComponent(type));
|
|
|
|
}
|
|
|
|
|
2023-01-26 10:55:02 +01:00
|
|
|
loadSimpleResourceContent(id:any):Observable<string> {
|
|
|
|
const headers = new HttpHeaders().set('Content-Type', 'text/plain; charset=utf-8');
|
|
|
|
return this.client.get<string>("/ajax/resources/" + encodeURIComponent(id) + '/content', {
|
|
|
|
headers, responseType: 'text' as 'json'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-01-25 16:08:32 +01:00
|
|
|
saveSimpleResourceMedatata(res:SimpleResource):Observable<void> {
|
|
|
|
return this.client.post<void>('/ajax/resources/' + encodeURIComponent(res.id) + '/metadata', res);
|
|
|
|
}
|
|
|
|
|
2023-01-26 10:55:02 +01:00
|
|
|
saveSimpleResourceContent(id:string, content:string):Observable<void> {
|
|
|
|
const headers = new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded')
|
|
|
|
let body = new HttpParams().set('content', content);
|
|
|
|
return this.client.post<void>('/ajax/resources/' + encodeURIComponent(id) + '/content', body, { headers: headers });
|
|
|
|
}
|
|
|
|
|
|
|
|
addSimpleResource(name:string, type:string, description:string, content:string):Observable<void> {
|
|
|
|
const headers = new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded')
|
|
|
|
let body = new HttpParams()
|
|
|
|
.set('name', name)
|
|
|
|
.set('type', type)
|
|
|
|
.set('description', description)
|
|
|
|
.set('content', content);
|
|
|
|
return this.client.post<void>('/ajax/resources/', body, { headers: headers });
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-01-25 16:08:32 +01:00
|
|
|
deleteSimpleResource(res:SimpleResource):Observable<void> {
|
|
|
|
return this.client.delete<void>('/ajax/resources/' + encodeURIComponent(res.id));
|
|
|
|
}
|
|
|
|
|
2023-01-20 16:57:03 +01:00
|
|
|
loadWfHistory(total?:number, from?:number, to?:number):Observable<WfHistoryEntry[]> {
|
|
|
|
let params = new HttpParams();
|
|
|
|
|
|
|
|
if (total && total > 0) { params = params.append('total', total); }
|
|
|
|
if (from && from > 0) { params = params.append('from', from); }
|
|
|
|
if (to && to > 0) { params = params.append('to', to); }
|
2023-01-25 16:08:32 +01:00
|
|
|
|
2023-01-20 16:57:03 +01:00
|
|
|
return this.client.get<WfHistoryEntry[]>('/ajax/wfs/', {params: params});
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|