From 8d9824fc529883cde6f2e1cb2e1dbdb66d262d7f Mon Sep 17 00:00:00 2001 From: Sebastian Stehle Date: Fri, 2 Nov 2018 20:53:05 +0100 Subject: [PATCH] Refactorings. --- .../shared/assets-editor.component.html | 12 ++-- .../content/shared/assets-editor.component.ts | 62 ++++++++++--------- .../shared/references-editor.component.ts | 18 +++--- .../pages/schemas/schemas-page.component.html | 2 +- .../pages/schemas/schemas-page.component.ts | 2 +- .../angular/forms/dropdown.component.ts | 6 +- .../components/markdown-editor.component.ts | 2 +- .../components/rich-editor.component.ts | 2 +- 8 files changed, 55 insertions(+), 51 deletions(-) diff --git a/src/Squidex/app/features/content/shared/assets-editor.component.html b/src/Squidex/app/features/content/shared/assets-editor.component.html index e12d1061e..d00c49cb7 100644 --- a/src/Squidex/app/features/content/shared/assets-editor.component.html +++ b/src/Squidex/app/features/content/shared/assets-editor.component.html @@ -23,10 +23,10 @@
+ (failed)="removeLoadingAsset(file)" (loaded)="addAsset(file, $event)"> + (removing)="removeLoadedAsset($event)">
@@ -34,13 +34,13 @@
+ [isListView]="true" (failed)="removeLoadingAsset(file)" (loaded)="addAsset(file, $event)"> -
+
+ [isListView]="true" (removing)="removeLoadedAsset($event)">
@@ -50,5 +50,5 @@
- + \ No newline at end of file diff --git a/src/Squidex/app/features/content/shared/assets-editor.component.ts b/src/Squidex/app/features/content/shared/assets-editor.component.ts index 11a27a768..bb9d9d7dc 100644 --- a/src/Squidex/app/features/content/shared/assets-editor.component.ts +++ b/src/Squidex/app/features/content/shared/assets-editor.component.ts @@ -59,26 +59,26 @@ export class AssetsEditorComponent implements ControlValueAccessor { this.assetsService.getAssets(this.appsState.appName, 0, 0, undefined, undefined, obj) .subscribe(dtos => { - this.oldAssets = ImmutableArray.of(assetIds.map(id => dtos.items.find(x => x.id === id)).filter(a => !!a).map(a => a!)); + this.setAssets(ImmutableArray.of(assetIds.map(id => dtos.items.find(x => x.id === id)!).filter(a => !!a))); if (this.oldAssets.length !== assetIds.length) { this.updateValue(); } - - this.changeDetector.markForCheck(); }, () => { - this.oldAssets = ImmutableArray.empty(); - - this.changeDetector.markForCheck(); + this.setAssets(ImmutableArray.empty()); }); } } else { - this.oldAssets = ImmutableArray.empty(); - - this.changeDetector.markForCheck(); + this.setAssets(ImmutableArray.empty()); } } + public setAssets(asset: ImmutableArray) { + this.oldAssets = asset; + + this.changeDetector.markForCheck(); + } + public setDisabledState(isDisabled: boolean): void { this.isDisabled = isDisabled; @@ -99,7 +99,7 @@ export class AssetsEditorComponent implements ControlValueAccessor { } } - public onAssetsSelected(assets: AssetDto[]) { + public selectAssets(assets: AssetDto[]) { for (let asset of assets) { this.oldAssets = this.oldAssets.push(asset); } @@ -111,7 +111,16 @@ export class AssetsEditorComponent implements ControlValueAccessor { this.assetsDialog.hide(); } - public onAssetRemoving(asset: AssetDto) { + public addAsset(file: File, asset: AssetDto) { + if (asset && file) { + this.newAssets = this.newAssets.remove(file); + this.oldAssets = this.oldAssets.pushFront(asset); + + this.updateValue(); + } + } + + public removeLoadedAsset(asset: AssetDto) { if (asset) { this.oldAssets = this.oldAssets.remove(asset); @@ -119,15 +128,22 @@ export class AssetsEditorComponent implements ControlValueAccessor { } } - public onAssetLoaded(file: File, asset: AssetDto) { + public removeLoadingAsset(file: File) { this.newAssets = this.newAssets.remove(file); - this.oldAssets = this.oldAssets.pushFront(asset); + } - this.updateValue(); + public changeView(isListView: boolean) { + this.localStore.set('assetView', isListView ? 'List' : 'Grid'); + + this.isListView = isListView; } - public onAssetFailed(file: File) { - this.newAssets = this.newAssets.remove(file); + public sortAssets(assets: AssetDto[]) { + if (assets) { + this.oldAssets = ImmutableArray.of(assets); + + this.updateValue(); + } } private updateValue() { @@ -142,18 +158,4 @@ export class AssetsEditorComponent implements ControlValueAccessor { this.changeDetector.markForCheck(); } - - public sort(assets: AssetDto[]) { - if (assets) { - this.oldAssets = ImmutableArray.of(assets); - - this.updateValue(); - } - } - - public changeView(isListView: boolean) { - this.localStore.set('assetView', isListView ? 'List' : 'Grid'); - - this.isListView = isListView; - } } \ No newline at end of file diff --git a/src/Squidex/app/features/content/shared/references-editor.component.ts b/src/Squidex/app/features/content/shared/references-editor.component.ts index 08d8d1175..bbe28ba16 100644 --- a/src/Squidex/app/features/content/shared/references-editor.component.ts +++ b/src/Squidex/app/features/content/shared/references-editor.component.ts @@ -89,26 +89,26 @@ export class ReferencesEditorComponent implements ControlValueAccessor, OnInit { this.contentsService.getContents(this.appsState.appName, this.schemaId, 10000, 0, undefined, contentIds) .subscribe(dtos => { - this.contentItems = ImmutableArray.of(contentIds.map(id => dtos.items.find(c => c.id === id)).filter(r => !!r).map(r => r!)); + this.setContentItems(ImmutableArray.of(contentIds.map(id => dtos.items.find(c => c.id === id)!).filter(r => !!r))); if (this.contentItems.length !== contentIds.length) { this.updateValue(); } - - this.changeDetector.markForCheck(); }, () => { - this.contentItems = ImmutableArray.empty(); - - this.changeDetector.markForCheck(); + this.setContentItems(ImmutableArray.empty()); }); } } else { - this.contentItems = ImmutableArray.empty(); - - this.changeDetector.markForCheck(); + this.setContentItems(ImmutableArray.empty()); } } + public setContentItems(contents: ImmutableArray) { + this.contentItems = contents; + + this.changeDetector.markForCheck(); + } + public setDisabledState(isDisabled: boolean): void { this.isDisabled = isDisabled; diff --git a/src/Squidex/app/features/schemas/pages/schemas/schemas-page.component.html b/src/Squidex/app/features/schemas/pages/schemas/schemas-page.component.html index ac70fa7a0..f13edf18f 100644 --- a/src/Squidex/app/features/schemas/pages/schemas/schemas-page.component.html +++ b/src/Squidex/app/features/schemas/pages/schemas/schemas-page.component.html @@ -37,7 +37,7 @@ + (created)="redirectSchema($event)"> diff --git a/src/Squidex/app/features/schemas/pages/schemas/schemas-page.component.ts b/src/Squidex/app/features/schemas/pages/schemas/schemas-page.component.ts index 5414d50ee..6b212f8b5 100644 --- a/src/Squidex/app/features/schemas/pages/schemas/schemas-page.component.ts +++ b/src/Squidex/app/features/schemas/pages/schemas/schemas-page.component.ts @@ -86,7 +86,7 @@ export class SchemasPageComponent implements OnDestroy, OnInit { } } - public onSchemaCreated(schema: SchemaDto) { + public redirectSchema(schema: SchemaDto) { this.router.navigate([schema.name], { relativeTo: this.route }); this.addSchemaDialog.hide(); diff --git a/src/Squidex/app/framework/angular/forms/dropdown.component.ts b/src/Squidex/app/framework/angular/forms/dropdown.component.ts index 0ac506678..1547138f1 100644 --- a/src/Squidex/app/framework/angular/forms/dropdown.component.ts +++ b/src/Squidex/app/framework/angular/forms/dropdown.component.ts @@ -95,8 +95,10 @@ export class DropdownComponent implements AfterContentInit, ControlValueAccessor return false; case KEY_ESCAPE: case KEY_ENTER: - this.close(); - return false; + if (this.dropdown.isOpen) { + this.close(); + return false; + } } return true; diff --git a/src/Squidex/app/shared/components/markdown-editor.component.ts b/src/Squidex/app/shared/components/markdown-editor.component.ts index 0b54f7711..129abb011 100644 --- a/src/Squidex/app/shared/components/markdown-editor.component.ts +++ b/src/Squidex/app/shared/components/markdown-editor.component.ts @@ -196,7 +196,7 @@ export class MarkdownEditorComponent implements ControlValueAccessor, AfterViewI }); } - public onAssetsSelected(assets: AssetDto[]) { + public insertAssets(assets: AssetDto[]) { let content = ''; for (let asset of assets) { diff --git a/src/Squidex/app/shared/components/rich-editor.component.ts b/src/Squidex/app/shared/components/rich-editor.component.ts index 4789dd670..c2e94cf0b 100644 --- a/src/Squidex/app/shared/components/rich-editor.component.ts +++ b/src/Squidex/app/shared/components/rich-editor.component.ts @@ -137,7 +137,7 @@ export class RichEditorComponent implements ControlValueAccessor, AfterViewInit, this.callTouched = fn; } - public onAssetsSelected(assets: AssetDto[]) { + public insertAssets(assets: AssetDto[]) { let content = ''; for (let asset of assets) {