import {Injectable} from '@angular/core'; import {HttpClient} from '@angular/common/http'; import {environment} from '@environments/environment'; import {Observable, BehaviorSubject} from "rxjs"; @Injectable({providedIn: 'root'}) export class PagesService { constructor(private http: HttpClient) { this.pagesTree = new BehaviorSubject({data:[]}) this.changedPages() } public pagesTree: BehaviorSubject public editMode = new BehaviorSubject(false); public currentPage = new BehaviorSubject({data:[]}) changedPages(){ let include = ['children.children.children.children.children.children.children']; this.root({include: include.join(',')}).subscribe(res => { this.pagesTree.next(res) }); } root(params?: {}): Observable { return this.http.get(`${environment.apiUrl}/api/pages/root`, {params: params}); } find(url: string, params?: any): Observable { if (!params) params = {}; params.url = url; return this.http.get(`${environment.apiUrl}/api/pages/find`, {params: params}); } list(params?: {}): Observable { return this.http.get(`${environment.apiUrl}/api/pages`, {params: params}); } show(id: string, params?: {}): Observable { return this.http.get(`${environment.apiUrl}/api/pages/${id}`, {params: params}); } delete(id: string): Observable { return this.http.delete(`${environment.apiUrl}/api/pages/${id}`); } deleteBackground(id: string): Observable { return this.http.delete(`${environment.apiUrl}/api/pages/background/${id}`); } move(id: string, data: any): Observable { return this.http.put(`${environment.apiUrl}/api/pages/${id}`, data); } }