|
|
@ -6,6 +6,7 @@ |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
|
|
|
import { Component, OnDestroy, OnInit } from '@angular/core'; |
|
|
import { Component, OnDestroy, OnInit } from '@angular/core'; |
|
|
|
|
|
import { Location } from '@angular/common'; |
|
|
import { AbstractControl, FormControl, FormGroup, ValidatorFn, Validators } from '@angular/forms'; |
|
|
import { AbstractControl, FormControl, FormGroup, ValidatorFn, Validators } from '@angular/forms'; |
|
|
import { ActivatedRoute, Router } from '@angular/router'; |
|
|
import { ActivatedRoute, Router } from '@angular/router'; |
|
|
import { Subscription } from 'rxjs'; |
|
|
import { Subscription } from 'rxjs'; |
|
|
@ -13,7 +14,9 @@ import { Subscription } from 'rxjs'; |
|
|
import { |
|
|
import { |
|
|
ContentCreated, |
|
|
ContentCreated, |
|
|
ContentDeleted, |
|
|
ContentDeleted, |
|
|
ContentUpdated |
|
|
ContentPublished, |
|
|
|
|
|
ContentUpdated, |
|
|
|
|
|
ContentUnpublished |
|
|
} from './../messages'; |
|
|
} from './../messages'; |
|
|
|
|
|
|
|
|
import { |
|
|
import { |
|
|
@ -38,7 +41,9 @@ import { |
|
|
templateUrl: './content-page.component.html' |
|
|
templateUrl: './content-page.component.html' |
|
|
}) |
|
|
}) |
|
|
export class ContentPageComponent extends AppComponentBase implements OnDestroy, OnInit { |
|
|
export class ContentPageComponent extends AppComponentBase implements OnDestroy, OnInit { |
|
|
private messageSubscription: Subscription; |
|
|
private contentDeletedSubscription: Subscription; |
|
|
|
|
|
private contentPublishedSubscription: Subscription; |
|
|
|
|
|
private contentUnpublishedSubscription: Subscription; |
|
|
private version: Version = new Version(''); |
|
|
private version: Version = new Version(''); |
|
|
|
|
|
|
|
|
public schema: SchemaDetailsDto; |
|
|
public schema: SchemaDetailsDto; |
|
|
@ -48,12 +53,14 @@ export class ContentPageComponent extends AppComponentBase implements OnDestroy, |
|
|
public contentData: any = null; |
|
|
public contentData: any = null; |
|
|
public contentId: string; |
|
|
public contentId: string; |
|
|
|
|
|
|
|
|
|
|
|
public isPublished = false; |
|
|
public isNewMode = true; |
|
|
public isNewMode = true; |
|
|
|
|
|
|
|
|
public languages: AppLanguageDto[] = []; |
|
|
public languages: AppLanguageDto[] = []; |
|
|
|
|
|
|
|
|
constructor(apps: AppsStoreService, notifications: NotificationService, users: UsersProviderService, |
|
|
constructor(apps: AppsStoreService, notifications: NotificationService, users: UsersProviderService, |
|
|
private readonly contentsService: ContentsService, |
|
|
private readonly contentsService: ContentsService, |
|
|
|
|
|
private readonly location: Location, |
|
|
private readonly route: ActivatedRoute, |
|
|
private readonly route: ActivatedRoute, |
|
|
private readonly router: Router, |
|
|
private readonly router: Router, |
|
|
private readonly messageBus: MessageBus |
|
|
private readonly messageBus: MessageBus |
|
|
@ -62,11 +69,13 @@ export class ContentPageComponent extends AppComponentBase implements OnDestroy, |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public ngOnDestroy() { |
|
|
public ngOnDestroy() { |
|
|
this.messageSubscription.unsubscribe(); |
|
|
this.contentDeletedSubscription.unsubscribe(); |
|
|
|
|
|
this.contentPublishedSubscription.unsubscribe(); |
|
|
|
|
|
this.contentUnpublishedSubscription.unsubscribe(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public ngOnInit() { |
|
|
public ngOnInit() { |
|
|
this.messageSubscription = |
|
|
this.contentDeletedSubscription = |
|
|
this.messageBus.of(ContentDeleted) |
|
|
this.messageBus.of(ContentDeleted) |
|
|
.subscribe(message => { |
|
|
.subscribe(message => { |
|
|
if (message.id === this.contentId) { |
|
|
if (message.id === this.contentId) { |
|
|
@ -74,6 +83,22 @@ export class ContentPageComponent extends AppComponentBase implements OnDestroy, |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
this.contentPublishedSubscription = |
|
|
|
|
|
this.messageBus.of(ContentPublished) |
|
|
|
|
|
.subscribe(message => { |
|
|
|
|
|
if (message.id === this.contentId) { |
|
|
|
|
|
this.isPublished = true; |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
this.contentUnpublishedSubscription = |
|
|
|
|
|
this.messageBus.of(ContentUnpublished) |
|
|
|
|
|
.subscribe(message => { |
|
|
|
|
|
if (message.id === this.contentId) { |
|
|
|
|
|
this.isPublished = false; |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
this.route.parent.data.map(p => p['appLanguages']) |
|
|
this.route.parent.data.map(p => p['appLanguages']) |
|
|
.subscribe((languages: AppLanguageDto[]) => { |
|
|
.subscribe((languages: AppLanguageDto[]) => { |
|
|
this.languages = languages; |
|
|
this.languages = languages; |
|
|
@ -90,7 +115,15 @@ export class ContentPageComponent extends AppComponentBase implements OnDestroy, |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public saveContent() { |
|
|
public saveAndPublish() { |
|
|
|
|
|
this.saveContent(true); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public saveAsDraft() { |
|
|
|
|
|
this.saveContent(false); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private saveContent(publish: boolean) { |
|
|
this.contentFormSubmitted = true; |
|
|
this.contentFormSubmitted = true; |
|
|
|
|
|
|
|
|
if (this.contentForm.valid) { |
|
|
if (this.contentForm.valid) { |
|
|
@ -100,11 +133,17 @@ export class ContentPageComponent extends AppComponentBase implements OnDestroy, |
|
|
|
|
|
|
|
|
if (this.isNewMode) { |
|
|
if (this.isNewMode) { |
|
|
this.appName() |
|
|
this.appName() |
|
|
.switchMap(app => this.contentsService.postContent(app, this.schema.name, data, this.version)) |
|
|
.switchMap(app => this.contentsService.postContent(app, this.schema.name, data, publish, this.version)) |
|
|
.subscribe(created => { |
|
|
.subscribe(created => { |
|
|
this.messageBus.publish(new ContentCreated(created.id, created.data, this.version.value)); |
|
|
this.contentId = created.id; |
|
|
|
|
|
|
|
|
this.router.navigate(['../'], { relativeTo: this.route }); |
|
|
this.messageBus.publish(new ContentCreated(created.id, created.data, this.version.value, publish)); |
|
|
|
|
|
|
|
|
|
|
|
this.enable(); |
|
|
|
|
|
this.finishCreation(); |
|
|
|
|
|
this.updateUrl(); |
|
|
|
|
|
|
|
|
|
|
|
this.notifyInfo('Content created successfully.'); |
|
|
}, error => { |
|
|
}, error => { |
|
|
this.notifyError(error); |
|
|
this.notifyError(error); |
|
|
this.enable(); |
|
|
this.enable(); |
|
|
@ -115,7 +154,9 @@ export class ContentPageComponent extends AppComponentBase implements OnDestroy, |
|
|
.subscribe(() => { |
|
|
.subscribe(() => { |
|
|
this.messageBus.publish(new ContentUpdated(this.contentId, data, this.version.value)); |
|
|
this.messageBus.publish(new ContentUpdated(this.contentId, data, this.version.value)); |
|
|
|
|
|
|
|
|
this.router.navigate(['../'], { relativeTo: this.route }); |
|
|
this.enable(); |
|
|
|
|
|
|
|
|
|
|
|
this.notifyInfo('Content saved successfully.'); |
|
|
}, error => { |
|
|
}, error => { |
|
|
this.notifyError(error); |
|
|
this.notifyError(error); |
|
|
this.enable(); |
|
|
this.enable(); |
|
|
@ -124,6 +165,16 @@ export class ContentPageComponent extends AppComponentBase implements OnDestroy, |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private finishCreation() { |
|
|
|
|
|
this.isNewMode = false; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private updateUrl() { |
|
|
|
|
|
const newUrl = this.router.createUrlTree(['../', this.contentId], { relativeTo: this.route, replaceUrl: true }); |
|
|
|
|
|
|
|
|
|
|
|
this.location.replaceState(newUrl.toString()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
private enable() { |
|
|
private enable() { |
|
|
for (const field of this.schema.fields.filter(f => !f.isDisabled)) { |
|
|
for (const field of this.schema.fields.filter(f => !f.isDisabled)) { |
|
|
const fieldForm = this.contentForm.controls[field.name]; |
|
|
const fieldForm = this.contentForm.controls[field.name]; |
|
|
@ -191,6 +242,7 @@ export class ContentPageComponent extends AppComponentBase implements OnDestroy, |
|
|
} else { |
|
|
} else { |
|
|
this.contentData = content.data; |
|
|
this.contentData = content.data; |
|
|
this.contentId = content.id; |
|
|
this.contentId = content.id; |
|
|
|
|
|
this.isPublished = content.isPublished; |
|
|
this.isNewMode = false; |
|
|
this.isNewMode = false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|