diff --git a/angular.json b/angular.json index cba4253..7d198bf 100644 --- a/angular.json +++ b/angular.json @@ -104,6 +104,10 @@ "replace": "src/app/_modules/layout/footer/footer.component.ts", "with": "src/vniigaz-v2/component/layout/footer/footer.component.ts" }, + { + "replace": "src/app/_modules/pages/page/page.component.ts", + "with": "src/vniigaz-v2/component/pages/page/page.component.ts" + }, { "replace": "src/app/_modules/layout/jumbotron/jumbotron.component.ts", "with": "src/vniigaz-v2/component/layout/jumbotron/jumbotron.component.ts" @@ -163,6 +167,10 @@ "replace": "src/app/_modules/layout/footer/footer.component.ts", "with": "src/vniigaz-v2/component/layout/footer/footer.component.ts" }, + { + "replace": "src/app/_modules/pages/page/page.component.ts", + "with": "src/vniigaz-v2/component/pages/page/page.component.ts" + }, { "replace": "src/app/_modules/layout/jumbotron/jumbotron.component.ts", "with": "src/vniigaz-v2/component/layout/jumbotron/jumbotron.component.ts" diff --git a/src/vniigaz-v2/component/pages/page/page.component.html b/src/vniigaz-v2/component/pages/page/page.component.html new file mode 100644 index 0000000..dc4b812 --- /dev/null +++ b/src/vniigaz-v2/component/pages/page/page.component.html @@ -0,0 +1,17 @@ +
+ +
+ + + + + +

Page type {{page?.type?.name}} is undefined

+
+
+
+ +
+ diff --git a/src/vniigaz-v2/component/pages/page/page.component.scss b/src/vniigaz-v2/component/pages/page/page.component.scss new file mode 100644 index 0000000..33f8f35 --- /dev/null +++ b/src/vniigaz-v2/component/pages/page/page.component.scss @@ -0,0 +1,9 @@ +@media screen and (min-width: 1330px){ + +} + + +@media screen and (max-width: 480px) { + + +} diff --git a/src/vniigaz-v2/component/pages/page/page.component.ts b/src/vniigaz-v2/component/pages/page/page.component.ts new file mode 100644 index 0000000..ab46268 --- /dev/null +++ b/src/vniigaz-v2/component/pages/page/page.component.ts @@ -0,0 +1,91 @@ +import {Component} from '@angular/core'; +import {NavigationEnd, Router} from "@angular/router"; +import {Subscription} from "rxjs"; +import {PagesService} from "@app/_services/pages.service"; +import {ListsService} from "@app/_services"; +import {Title} from "@angular/platform-browser"; + +@Component({ + templateUrl: 'page.component.html', + styleUrls: ['page.component.scss'] +}) +export class PageComponent { + public page: any; + public loading = false; + private url: string; + private inited = false; + routeSubscription?: Subscription; + listSubscription: Subscription; + + constructor( + private router: Router, + private pagesService: PagesService, + private listsService: ListsService, + private titleService:Title){ + this.routeSubscription = this.router.events.subscribe(event => { + if (event instanceof NavigationEnd) this.onNavigationEnd(event); + }); + } + + + get editMode() { + return this.pagesService.editMode; + } + + get permissions() { + return this.page?.permissions; + } + + get isEditable() { + return this.permissions?.edit || this.permissions?.anything; + } + + + ngOnInit() { + this.listSubscription = this.listsService.controls().subscribe(res => { + this.inited ? this.fetch() : this.inited = true; + }); + } + + ngOnDestroy() { + this.routeSubscription?.unsubscribe(); + this.listSubscription?.unsubscribe() + } + + onNavigationEnd(event: NavigationEnd) { + let url = event.url.split('(')[0].split('?')[0]; + if (url !== this.url) { + this.url = url; + this.fetch(); + this.pagesService.editMode = false; + } + } + + fetch() { + this.loading = true; + let include = [ + 'parents.children', + 'parents.picture', + 'children', + 'sections.type', + 'sections.groups.fields.value', + 'sections.objects.groups.fields.value', + 'sidebars.groups.fields.value', + 'sidebars.type', + 'permissions', + 'picture', + 'posters' + ]; + if (this.url == '/certification/voluntary/main') this.url = '/sertifikaciya/obyazatelnaya-sertifikaciya' + this.pagesService.find(this.url, {include: include.join(',')}).subscribe(res => { + this.page = res?.data; + if (this.page) { + this.pagesService.currentPage = this.page; + // this.titleService.setTitle(this.page.title||this.page.h1||this.page.name) + } + this.loading = false; + }, error => { + this.loading = false; + }); + } +}