From 0fcb6b139d0f9ce5d4d1e3c2b2202ae4d7a709e8 Mon Sep 17 00:00:00 2001 From: Sebastian Stehle Date: Sun, 10 Sep 2017 21:36:47 +0200 Subject: [PATCH] Archive feature and bugfixes. --- .../Api/Schemas/SchemasController.cs | 2 +- .../pages/content/content-page.component.html | 11 ++- .../pages/content/content-page.component.ts | 10 ++- .../contents/contents-page.component.html | 18 ++++- .../pages/contents/contents-page.component.ts | 78 +++++++++++++++---- .../pages/contents/search-form.component.html | 2 +- .../pages/contents/search-form.component.ts | 3 + .../app/features/content/pages/messages.ts | 2 +- .../shared/content-item.component.html | 12 ++- .../content/shared/content-item.component.ts | 6 ++ .../shared/references-editor.component.ts | 4 + .../app/shared/services/contents.service.ts | 2 +- 12 files changed, 116 insertions(+), 34 deletions(-) diff --git a/src/Squidex/Controllers/Api/Schemas/SchemasController.cs b/src/Squidex/Controllers/Api/Schemas/SchemasController.cs index 916706ffd..d3806c93f 100644 --- a/src/Squidex/Controllers/Api/Schemas/SchemasController.cs +++ b/src/Squidex/Controllers/Api/Schemas/SchemasController.cs @@ -125,7 +125,7 @@ namespace Squidex.Controllers.Api.Schemas var context = await CommandBus.PublishAsync(command); var result = context.Result>(); - var response = new EntityCreatedDto { Id = command.Name, Version = result.Version }; + var response = new EntityCreatedDto { Id = command.SchemaId.ToString(), Version = result.Version }; return CreatedAtAction(nameof(GetSchema), new { name = request.Name }, response); } diff --git a/src/Squidex/app/features/content/pages/content/content-page.component.html b/src/Squidex/app/features/content/pages/content/content-page.component.html index a75d7e44a..a6cf09326 100644 --- a/src/Squidex/app/features/content/pages/content/content-page.component.html +++ b/src/Squidex/app/features/content/pages/content/content-page.component.html @@ -4,7 +4,7 @@
-
+
-
- + +

New Content

-

+

Edit Content

+

+ Show Content +

diff --git a/src/Squidex/app/features/content/pages/content/content-page.component.ts b/src/Squidex/app/features/content/pages/content/content-page.component.ts index f0ffc00c6..0d1fff1b8 100644 --- a/src/Squidex/app/features/content/pages/content/content-page.component.ts +++ b/src/Squidex/app/features/content/pages/content/content-page.component.ts @@ -12,7 +12,7 @@ import { Observable, Subscription } from 'rxjs'; import { ContentCreated, - ContentDeleted, + ContentRemoved, ContentUpdated, ContentVersionSelected } from './../messages'; @@ -40,10 +40,10 @@ import { export class ContentPageComponent extends AppComponentBase implements CanComponentDeactivate, OnDestroy, OnInit { private contentDeletedSubscription: Subscription; private contentVersionSelectedSubscription: Subscription; - private content: ContentDto; public schema: SchemaDetailsDto; + public content: ContentDto; public contentFormSubmitted = false; public contentForm: FormGroup; @@ -78,7 +78,7 @@ export class ContentPageComponent extends AppComponentBase implements CanCompone }); this.contentDeletedSubscription = - this.messageBus.of(ContentDeleted) + this.messageBus.of(ContentRemoved) .subscribe(message => { if (this.content && message.content.id === this.content.id) { this.router.navigate(['../'], { relativeTo: this.route }); @@ -232,6 +232,10 @@ export class ContentPageComponent extends AppComponentBase implements CanCompone fieldForm.controls['iv'].setValue(fieldValue['iv']); } } + + if (this.content.isArchived) { + this.contentForm.disable(); + } } } } diff --git a/src/Squidex/app/features/content/pages/contents/contents-page.component.html b/src/Squidex/app/features/content/pages/contents/contents-page.component.html index 404cdd0b3..0658e4ad9 100644 --- a/src/Squidex/app/features/content/pages/contents/contents-page.component.html +++ b/src/Squidex/app/features/content/pages/contents/contents-page.component.html @@ -21,7 +21,13 @@ @@ -33,12 +39,16 @@
-

+

Contents

+ +

+ Archive +

- References + Refs

@@ -82,6 +92,8 @@ [schema]="schema" (unpublishing)="unpublishContent(content)" (publishing)="publishContent(content)" + (archiving)="archiveContent(content)" + (restoring)="restoreContent(content)" (deleting)="deleteContent(content)"> diff --git a/src/Squidex/app/features/content/pages/contents/contents-page.component.ts b/src/Squidex/app/features/content/pages/contents/contents-page.component.ts index f914ca7da..617eb42b8 100644 --- a/src/Squidex/app/features/content/pages/contents/contents-page.component.ts +++ b/src/Squidex/app/features/content/pages/contents/contents-page.component.ts @@ -12,7 +12,7 @@ import { Subscription } from 'rxjs'; import { ContentCreated, - ContentDeleted, + ContentRemoved, ContentUpdated } from './../messages'; @@ -57,6 +57,7 @@ export class ContentsPageComponent extends AppComponentBase implements OnDestroy public languageParameter: string; public isReadOnly = false; + public isArchive = false; public columnWidth: number; @@ -112,13 +113,6 @@ export class ContentsPageComponent extends AppComponentBase implements OnDestroy return { content, schemaId: this.schema.id }; } - public search() { - this.contentsQuery = this.contentsFilter.value; - this.contentsPager = new Pager(0); - - this.load(); - } - public publishContent(content: ContentDto) { this.appNameOnce() .switchMap(app => this.contentsService.publishContent(app, this.schema.name, content.id, content.version)) @@ -139,14 +133,35 @@ export class ContentsPageComponent extends AppComponentBase implements OnDestroy }); } + public archiveContent(content: ContentDto) { + this.appNameOnce() + .switchMap(app => this.contentsService.archiveContent(app, this.schema.name, content.id, content.version)) + .subscribe(() => { + content = content.archive(this.authService.user!.token); + + this.removeContent(content); + }, error => { + this.notifyError(error); + }); + } + + public restoreContent(content: ContentDto) { + this.appNameOnce() + .switchMap(app => this.contentsService.restoreContent(app, this.schema.name, content.id, content.version)) + .subscribe(() => { + content = content.restore(this.authService.user!.token); + + this.removeContent(content); + }, error => { + this.notifyError(error); + }); + } + public deleteContent(content: ContentDto) { this.appNameOnce() .switchMap(app => this.contentsService.deleteContent(app, this.schema.name, content.id, content.version)) .subscribe(() => { - this.contentItems = this.contentItems.removeAll(x => x.id === content.id); - this.contentsPager = this.contentsPager.decrementCount(); - - this.emitContentDeleted(content); + this.removeContent(content); }, error => { this.notifyError(error); }); @@ -154,7 +169,7 @@ export class ContentsPageComponent extends AppComponentBase implements OnDestroy public load(showInfo = false) { this.appNameOnce() - .switchMap(app => this.contentsService.getContents(app, this.schema.name, this.contentsPager.pageSize, this.contentsPager.skip, this.contentsQuery)) + .switchMap(app => this.contentsService.getContents(app, this.schema.name, this.contentsPager.pageSize, this.contentsPager.skip, this.contentsQuery, null, this.isArchive)) .subscribe(dtos => { this.contentItems = ImmutableArray.of(dtos.items); this.contentsPager = this.contentsPager.setCount(dtos.total); @@ -167,8 +182,22 @@ export class ContentsPageComponent extends AppComponentBase implements OnDestroy }); } - public selectLanguage(language: AppLanguageDto) { - this.languageSelected = language; + public updateArchive(isArchive: boolean) { + this.contentsQuery = this.contentsFilter.value; + this.contentsPager = new Pager(0); + + this.isArchive = isArchive; + + this.searchModal.hide(); + + this.load(); + } + + public search() { + this.contentsQuery = this.contentsFilter.value; + this.contentsPager = new Pager(0); + + this.load(); } public goNext() { @@ -183,8 +212,12 @@ export class ContentsPageComponent extends AppComponentBase implements OnDestroy this.load(); } - private emitContentDeleted(content: ContentDto) { - this.messageBus.emit(new ContentDeleted(content)); + public selectLanguage(language: AppLanguageDto) { + this.languageSelected = language; + } + + private emitContentRemoved(content: ContentDto) { + this.messageBus.emit(new ContentRemoved(content)); } private resetContents() { @@ -196,6 +229,13 @@ export class ContentsPageComponent extends AppComponentBase implements OnDestroy 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); @@ -203,6 +243,10 @@ export class ContentsPageComponent extends AppComponentBase implements OnDestroy this.contentFields = [this.schema.fields[0]]; } + if (this.contentFields.length === 0) { + this.contentFields = [{}]; + } + if (this.contentFields.length > 0) { this.columnWidth = 100 / this.contentFields.length; } else { diff --git a/src/Squidex/app/features/content/pages/contents/search-form.component.html b/src/Squidex/app/features/content/pages/contents/search-form.component.html index 1f92fda29..ee3ad5c71 100644 --- a/src/Squidex/app/features/content/pages/contents/search-form.component.html +++ b/src/Squidex/app/features/content/pages/contents/search-form.component.html @@ -25,7 +25,7 @@ -
+
diff --git a/src/Squidex/app/features/content/pages/contents/search-form.component.ts b/src/Squidex/app/features/content/pages/contents/search-form.component.ts index 2ba10aee8..8fcc6a0eb 100644 --- a/src/Squidex/app/features/content/pages/contents/search-form.component.ts +++ b/src/Squidex/app/features/content/pages/contents/search-form.component.ts @@ -28,6 +28,9 @@ export class SearchFormComponent implements OnChanges { @Output() public archivedChanged = new EventEmitter(); + @Input() + public canArchive = true; + public searchForm = this.formBuilder.group({ odataOrderBy: '', diff --git a/src/Squidex/app/features/content/pages/messages.ts b/src/Squidex/app/features/content/pages/messages.ts index 13a340fcd..9834b95b2 100644 --- a/src/Squidex/app/features/content/pages/messages.ts +++ b/src/Squidex/app/features/content/pages/messages.ts @@ -21,7 +21,7 @@ export class ContentUpdated { } } -export class ContentDeleted { +export class ContentRemoved { constructor( public readonly content: ContentDto ) { diff --git a/src/Squidex/app/features/content/shared/content-item.component.html b/src/Squidex/app/features/content/shared/content-item.component.html index 35d158a1f..75d92db75 100644 --- a/src/Squidex/app/features/content/shared/content-item.component.html +++ b/src/Squidex/app/features/content/shared/content-item.component.html @@ -17,13 +17,19 @@