|
|
@ -1,7 +1,6 @@ |
|
|
|
import { Injectable } from '@angular/core'; |
|
|
|
import { Injectable } from '@angular/core'; |
|
|
|
import { environment } from '../../environments/environment.development'; |
|
|
|
|
|
|
|
import { HttpClient, HttpParams } from '@angular/common/http'; |
|
|
|
import { HttpClient, HttpParams } from '@angular/common/http'; |
|
|
|
import { Observable, from } from 'rxjs'; |
|
|
|
import { Observable } from 'rxjs'; |
|
|
|
import { Script } from '../model/script'; |
|
|
|
import { Script } from '../model/script'; |
|
|
|
import { LinkScriptTag } from '../model/link-script-tag'; |
|
|
|
import { LinkScriptTag } from '../model/link-script-tag'; |
|
|
|
|
|
|
|
|
|
|
@ -9,29 +8,37 @@ import { LinkScriptTag } from '../model/link-script-tag'; |
|
|
|
providedIn: 'root' |
|
|
|
providedIn: 'root' |
|
|
|
}) |
|
|
|
}) |
|
|
|
export class ScriptService { |
|
|
|
export class ScriptService { |
|
|
|
private apiServerUrl = environment.apiBaseUrl; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
constructor(private http: HttpClient) { } |
|
|
|
constructor(private http: HttpClient) { } |
|
|
|
|
|
|
|
|
|
|
|
public retreiveScripts(): Observable<Script[]>{ |
|
|
|
public retreiveScripts(): Observable<Script[]>{ |
|
|
|
return this.http.get<Script[]>(`${this.apiServerUrl}/api/scripts`); |
|
|
|
return this.http.get<Script[]>(`/api/scripts`); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public getAllScriptsWithTags(): Observable<LinkScriptTag[]>{ |
|
|
|
public getAllScriptsWithTags(): Observable<LinkScriptTag[]>{ |
|
|
|
return this.http.get<LinkScriptTag[]>(`${this.apiServerUrl}/api/scripts/link`); |
|
|
|
return this.http.get<LinkScriptTag[]>(`/api/scripts/link`); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public deleteScript(name: String){ |
|
|
|
public deleteScript(name: String){ |
|
|
|
return this.http.delete<void>(`${this.apiServerUrl}/api/script/delete/${name}`); |
|
|
|
return this.http.delete<void>(`/api/script/delete/${name}`); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public addOneScript(script: Script, description: String, tagList: String[], id: number){ |
|
|
|
public addOneScript(script: Script, description: String, tagList: String[], id: number){ |
|
|
|
const paramsAddScript = new HttpParams().set('name', script.name.toString()).set('desc', description.toString()).set('tagList', tagList.join(', ')).set('linkid', id); |
|
|
|
const paramsAddScript = new HttpParams() |
|
|
|
return this.http.post<void>(`${this.apiServerUrl}/api/script/add`, script.data, {params: paramsAddScript}); |
|
|
|
.set('name', script.name.toString()) |
|
|
|
|
|
|
|
.set('desc', description.toString()) |
|
|
|
|
|
|
|
.set('tagList', tagList.join(', ')) |
|
|
|
|
|
|
|
.set('linkid', id); |
|
|
|
|
|
|
|
return this.http.post<void>(`/api/script/add`, script.data, {params: paramsAddScript}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public editScript(content: String, defaultName: String, newName: String, description: String, tagList: String[], id: number){ |
|
|
|
public editScript(content: String, defaultName: String, newName: String, description: String, tagList: String[], id: number){ |
|
|
|
const paramsAddScript = new HttpParams().set('defaultname', defaultName.toString()).set('newname', newName.toString()).set('desc', description.toString()).set('tagList', tagList.join(', ')).set('linkid', id); |
|
|
|
const paramsAddScript = new HttpParams() |
|
|
|
return this.http.post<void>(`${this.apiServerUrl}/api/script/edit`, content, {params: paramsAddScript}); |
|
|
|
.set('defaultname', defaultName.toString()) |
|
|
|
|
|
|
|
.set('newname', newName.toString()) |
|
|
|
|
|
|
|
.set('desc', description.toString()) |
|
|
|
|
|
|
|
.set('tagList', tagList.join(', ')) |
|
|
|
|
|
|
|
.set('linkid', id); |
|
|
|
|
|
|
|
return this.http.post<void>(`/api/script/edit`, content, {params: paramsAddScript}); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|