|
|
|
@ -7,7 +7,7 @@ |
|
|
|
|
|
|
|
import { Component, OnDestroy, OnInit } from '@angular/core'; |
|
|
|
import { FormControl } from '@angular/forms'; |
|
|
|
import { Subscription } from 'rxjs'; |
|
|
|
import { Observable, Subscription } from 'rxjs'; |
|
|
|
|
|
|
|
import { |
|
|
|
ContentCreated, |
|
|
|
@ -52,15 +52,20 @@ export class ContentsPageComponent implements OnDestroy, OnInit { |
|
|
|
public contentsQuery = ''; |
|
|
|
public contentsPager = new Pager(0); |
|
|
|
|
|
|
|
public selectedItems: { [id: string]: boolean; } = {}; |
|
|
|
public selectionCount = 0; |
|
|
|
|
|
|
|
public canUnpublish = false; |
|
|
|
public canPublish = false; |
|
|
|
|
|
|
|
public languages: AppLanguageDto[] = []; |
|
|
|
public languageSelected: AppLanguageDto; |
|
|
|
public languageParameter: string; |
|
|
|
|
|
|
|
public isAllSelected = false; |
|
|
|
public isReadOnly = false; |
|
|
|
public isArchive = false; |
|
|
|
|
|
|
|
public columnWidth: number; |
|
|
|
|
|
|
|
constructor(public readonly ctx: AppContext, |
|
|
|
private readonly contentsService: ContentsService |
|
|
|
) { |
|
|
|
@ -113,64 +118,156 @@ export class ContentsPageComponent implements OnDestroy, OnInit { |
|
|
|
} |
|
|
|
|
|
|
|
public publishContent(content: ContentDto) { |
|
|
|
this.contentsService.publishContent(this.ctx.appName, this.schema.name, content.id, content.version) |
|
|
|
.subscribe(dto => { |
|
|
|
content = content.publish(this.ctx.userToken, dto.version); |
|
|
|
this.publishContentItem(content).subscribe(); |
|
|
|
} |
|
|
|
|
|
|
|
this.contentItems = this.contentItems.replaceBy('id', content); |
|
|
|
public publishSelected() { |
|
|
|
Observable.forkJoin( |
|
|
|
this.contentItems.values |
|
|
|
.filter(c => this.selectedItems[c.id]) |
|
|
|
.filter(c => c.status !== 'Published') |
|
|
|
.map(c => this.publishContentItem(c))) |
|
|
|
.finally(() => { |
|
|
|
this.updateSelectionSummary(); |
|
|
|
}) |
|
|
|
.subscribe(); |
|
|
|
} |
|
|
|
|
|
|
|
this.emitContentPublished(content); |
|
|
|
}, error => { |
|
|
|
private publishContentItem(content: ContentDto): Observable<any> { |
|
|
|
return this.contentsService.publishContent(this.ctx.appName, this.schema.name, content.id, content.version) |
|
|
|
.catch(error => { |
|
|
|
this.ctx.notifyError(error); |
|
|
|
|
|
|
|
return Observable.throw(error); |
|
|
|
}) |
|
|
|
.do(dto => { |
|
|
|
this.contentItems = this.contentItems.replaceBy('id', content.publish(this.ctx.userToken, dto.version)); |
|
|
|
|
|
|
|
this.emitContentPublished(content); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
public unpublishContent(content: ContentDto) { |
|
|
|
this.contentsService.unpublishContent(this.ctx.appName, this.schema.name, content.id, content.version) |
|
|
|
.subscribe(dto => { |
|
|
|
content = content.unpublish(this.ctx.userToken, dto.version); |
|
|
|
this.unpublishContentItem(content).subscribe(); |
|
|
|
} |
|
|
|
|
|
|
|
this.contentItems = this.contentItems.replaceBy('id', content); |
|
|
|
public unpublishSelected() { |
|
|
|
Observable.forkJoin( |
|
|
|
this.contentItems.values |
|
|
|
.filter(c => this.selectedItems[c.id]) |
|
|
|
.filter(c => c.status !== 'Unpublished') |
|
|
|
.map(c => this.unpublishContentItem(c))) |
|
|
|
.finally(() => { |
|
|
|
this.updateSelectionSummary(); |
|
|
|
}) |
|
|
|
.subscribe(); |
|
|
|
} |
|
|
|
|
|
|
|
this.emitContentUnpublished(content); |
|
|
|
}, error => { |
|
|
|
private unpublishContentItem(content: ContentDto): Observable<any> { |
|
|
|
return this.contentsService.unpublishContent(this.ctx.appName, this.schema.name, content.id, content.version) |
|
|
|
.catch(error => { |
|
|
|
this.ctx.notifyError(error); |
|
|
|
|
|
|
|
return Observable.throw(error); |
|
|
|
}) |
|
|
|
.do(dto => { |
|
|
|
this.contentItems = this.contentItems.replaceBy('id', content.unpublish(this.ctx.userToken, dto.version)); |
|
|
|
|
|
|
|
this.emitContentUnpublished(content); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
public archiveSelected() { |
|
|
|
Observable.forkJoin( |
|
|
|
this.contentItems.values.filter(c => this.selectedItems[c.id]) |
|
|
|
.map(c => this.archiveContentItem(c))) |
|
|
|
.finally(() => { |
|
|
|
this.load(); |
|
|
|
}) |
|
|
|
.subscribe(); |
|
|
|
} |
|
|
|
|
|
|
|
public archiveContent(content: ContentDto) { |
|
|
|
this.contentsService.archiveContent(this.ctx.appName, this.schema.name, content.id, content.version) |
|
|
|
.subscribe(dto => { |
|
|
|
content = content.archive(this.ctx.userToken, dto.version); |
|
|
|
this.archiveContentItem(content) |
|
|
|
.finally(() => { |
|
|
|
this.load(); |
|
|
|
}) |
|
|
|
.subscribe(); |
|
|
|
} |
|
|
|
|
|
|
|
this.removeContent(content); |
|
|
|
}, error => { |
|
|
|
public archiveContentItem(content: ContentDto): Observable<any> { |
|
|
|
return this.contentsService.archiveContent(this.ctx.appName, this.schema.name, content.id, content.version) |
|
|
|
.catch(error => { |
|
|
|
this.ctx.notifyError(error); |
|
|
|
|
|
|
|
return Observable.throw(error); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
public restoreSelected() { |
|
|
|
Observable.forkJoin( |
|
|
|
this.contentItems.values.filter(c => this.selectedItems[c.id]) |
|
|
|
.map(c => this.restoreContentItem(c))) |
|
|
|
.finally(() => { |
|
|
|
this.load(); |
|
|
|
}) |
|
|
|
.subscribe(); |
|
|
|
} |
|
|
|
|
|
|
|
public restoreContent(content: ContentDto) { |
|
|
|
this.contentsService.restoreContent(this.ctx.appName, this.schema.name, content.id, content.version) |
|
|
|
.subscribe(dto => { |
|
|
|
content = content.restore(this.ctx.userToken, dto.version); |
|
|
|
this.restoreContentItem(content) |
|
|
|
.finally(() => { |
|
|
|
this.load(); |
|
|
|
}) |
|
|
|
.subscribe(); |
|
|
|
} |
|
|
|
|
|
|
|
this.removeContent(content); |
|
|
|
}, error => { |
|
|
|
public restoreContentItem(content: ContentDto): Observable<any> { |
|
|
|
return this.contentsService.restoreContent(this.ctx.appName, this.schema.name, content.id, content.version) |
|
|
|
.catch(error => { |
|
|
|
this.ctx.notifyError(error); |
|
|
|
|
|
|
|
return Observable.throw(error); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
public deleteSelected(content: ContentDto) { |
|
|
|
Observable.forkJoin( |
|
|
|
this.contentItems.values.filter(c => this.selectedItems[c.id]) |
|
|
|
.map(c => this.deleteContentItem(c))) |
|
|
|
.finally(() => { |
|
|
|
this.load(); |
|
|
|
}) |
|
|
|
.subscribe(); |
|
|
|
} |
|
|
|
|
|
|
|
public deleteContent(content: ContentDto) { |
|
|
|
this.contentsService.deleteContent(this.ctx.appName, this.schema.name, content.id, content.version) |
|
|
|
.subscribe(() => { |
|
|
|
this.removeContent(content); |
|
|
|
}, error => { |
|
|
|
this.deleteContentItem(content) |
|
|
|
.finally(() => { |
|
|
|
this.load(); |
|
|
|
}) |
|
|
|
.subscribe(); |
|
|
|
} |
|
|
|
|
|
|
|
public deleteContentItem(content: ContentDto): Observable<any> { |
|
|
|
return this.contentsService.deleteContent(this.ctx.appName, this.schema.name, content.id, content.version) |
|
|
|
.do(() => { |
|
|
|
this.emitContentRemoved(content); |
|
|
|
}) |
|
|
|
.catch(error => { |
|
|
|
this.ctx.notifyError(error); |
|
|
|
|
|
|
|
return Observable.throw(error); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
public load(showInfo = false) { |
|
|
|
this.contentsService.getContents(this.ctx.appName, this.schema.name, this.contentsPager.pageSize, this.contentsPager.skip, this.contentsQuery, undefined, this.isArchive) |
|
|
|
.finally(() => { |
|
|
|
this.selectedItems = {}; |
|
|
|
|
|
|
|
this.updateSelectionSummary(); |
|
|
|
}) |
|
|
|
.subscribe(dtos => { |
|
|
|
this.contentItems = ImmutableArray.of(dtos.items); |
|
|
|
this.contentsPager = this.contentsPager.setCount(dtos.total); |
|
|
|
@ -213,6 +310,51 @@ export class ContentsPageComponent implements OnDestroy, OnInit { |
|
|
|
this.load(); |
|
|
|
} |
|
|
|
|
|
|
|
public isItemSelected(content: ContentDto): boolean { |
|
|
|
return !!this.selectedItems[content.id]; |
|
|
|
} |
|
|
|
|
|
|
|
public selectItem(content: ContentDto, isSelected: boolean) { |
|
|
|
this.selectedItems[content.id] = isSelected; |
|
|
|
|
|
|
|
this.updateSelectionSummary(); |
|
|
|
} |
|
|
|
|
|
|
|
public selectAll(isSelected: boolean) { |
|
|
|
this.selectedItems = {}; |
|
|
|
|
|
|
|
if (isSelected) { |
|
|
|
for (let c of this.contentItems.values) { |
|
|
|
this.selectedItems[c.id] = true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
this.updateSelectionSummary(); |
|
|
|
} |
|
|
|
|
|
|
|
private updateSelectionSummary() { |
|
|
|
this.isAllSelected = this.contentItems.length > 0; |
|
|
|
this.selectionCount = 0; |
|
|
|
this.canPublish = true; |
|
|
|
this.canUnpublish = true; |
|
|
|
|
|
|
|
for (let c of this.contentItems.values) { |
|
|
|
if (this.selectedItems[c.id]) { |
|
|
|
this.selectionCount++; |
|
|
|
|
|
|
|
if (c.status !== 'Published') { |
|
|
|
this.canUnpublish = false; |
|
|
|
} |
|
|
|
|
|
|
|
if (c.status === 'Published') { |
|
|
|
this.canPublish = false; |
|
|
|
} |
|
|
|
} else { |
|
|
|
this.isAllSelected = false; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public selectLanguage(language: AppLanguageDto) { |
|
|
|
this.languageSelected = language; |
|
|
|
} |
|
|
|
@ -234,17 +376,12 @@ export class ContentsPageComponent implements OnDestroy, OnInit { |
|
|
|
this.contentsQuery = ''; |
|
|
|
this.contentsFilter.setValue(''); |
|
|
|
this.contentsPager = new Pager(0); |
|
|
|
this.selectedItems = {}; |
|
|
|
|
|
|
|
this.updateSelectionSummary(); |
|
|
|
this.loadFields(); |
|
|
|
} |
|
|
|
|
|
|
|
private removeContent(content: ContentDto) { |
|
|
|
this.contentItems = this.contentItems.removeAll(x => x.id === content.id); |
|
|
|
this.contentsPager = this.contentsPager.decrementCount(); |
|
|
|
|
|
|
|
this.emitContentRemoved(content); |
|
|
|
} |
|
|
|
|
|
|
|
private loadFields() { |
|
|
|
this.contentFields = this.schema.fields.filter(x => x.properties.isListField); |
|
|
|
|
|
|
|
@ -255,12 +392,6 @@ export class ContentsPageComponent implements OnDestroy, OnInit { |
|
|
|
if (this.contentFields.length === 0) { |
|
|
|
this.contentFields = [<any>{}]; |
|
|
|
} |
|
|
|
|
|
|
|
if (this.contentFields.length > 0) { |
|
|
|
this.columnWidth = 100 / this.contentFields.length; |
|
|
|
} else { |
|
|
|
this.columnWidth = 100; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|