Browse Source

Refactorings.

pull/332/head
Sebastian Stehle 7 years ago
parent
commit
8d9824fc52
  1. 12
      src/Squidex/app/features/content/shared/assets-editor.component.html
  2. 62
      src/Squidex/app/features/content/shared/assets-editor.component.ts
  3. 18
      src/Squidex/app/features/content/shared/references-editor.component.ts
  4. 2
      src/Squidex/app/features/schemas/pages/schemas/schemas-page.component.html
  5. 2
      src/Squidex/app/features/schemas/pages/schemas/schemas-page.component.ts
  6. 6
      src/Squidex/app/framework/angular/forms/dropdown.component.ts
  7. 2
      src/Squidex/app/shared/components/markdown-editor.component.ts
  8. 2
      src/Squidex/app/shared/components/rich-editor.component.ts

12
src/Squidex/app/features/content/shared/assets-editor.component.html

@ -23,10 +23,10 @@
<ng-container *ngIf="!isListView; else listTemplate"> <ng-container *ngIf="!isListView; else listTemplate">
<div class="row no-gutters"> <div class="row no-gutters">
<sqx-asset *ngFor="let file of newAssets" [initFile]="file" <sqx-asset *ngFor="let file of newAssets" [initFile]="file"
(failed)="onAssetFailed(file)" (loaded)="onAssetLoaded(file, $event)"> (failed)="removeLoadingAsset(file)" (loaded)="addAsset(file, $event)">
</sqx-asset> </sqx-asset>
<sqx-asset *ngFor="let asset of oldAssets" [asset]="asset" removeMode="true" isDisabled="true" <sqx-asset *ngFor="let asset of oldAssets" [asset]="asset" removeMode="true" isDisabled="true"
(removing)="onAssetRemoving($event)"> (removing)="removeLoadedAsset($event)">
</sqx-asset> </sqx-asset>
</div> </div>
</ng-container> </ng-container>
@ -34,13 +34,13 @@
<ng-template #listTemplate> <ng-template #listTemplate>
<div class="list-view"> <div class="list-view">
<sqx-asset *ngFor="let file of newAssets" [initFile]="file" <sqx-asset *ngFor="let file of newAssets" [initFile]="file"
[isListView]="true" (failed)="onAssetFailed(file)" (loaded)="onAssetLoaded(file, $event)"> [isListView]="true" (failed)="removeLoadingAsset(file)" (loaded)="addAsset(file, $event)">
</sqx-asset> </sqx-asset>
<div [sqxSortModel]="oldAssets.values" (sqxSorted)="sort($event)"> <div [sqxSortModel]="oldAssets.values" (sqxSorted)="sortAssets($event)">
<div *ngFor="let asset of oldAssets"> <div *ngFor="let asset of oldAssets">
<sqx-asset [asset]="asset" removeMode="true" isDisabled="true" <sqx-asset [asset]="asset" removeMode="true" isDisabled="true"
[isListView]="true" (removing)="onAssetRemoving($event)"> [isListView]="true" (removing)="removeLoadedAsset($event)">
</sqx-asset> </sqx-asset>
</div> </div>
</div> </div>
@ -50,5 +50,5 @@
</div> </div>
<ng-container *sqxModalView="assetsDialog;onRoot:true;closeAuto:false"> <ng-container *sqxModalView="assetsDialog;onRoot:true;closeAuto:false">
<sqx-assets-selector (selected)="onAssetsSelected($event)"></sqx-assets-selector> <sqx-assets-selector (selected)="selectAssets($event)"></sqx-assets-selector>
</ng-container> </ng-container>

62
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) this.assetsService.getAssets(this.appsState.appName, 0, 0, undefined, undefined, obj)
.subscribe(dtos => { .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) { if (this.oldAssets.length !== assetIds.length) {
this.updateValue(); this.updateValue();
} }
this.changeDetector.markForCheck();
}, () => { }, () => {
this.oldAssets = ImmutableArray.empty(); this.setAssets(ImmutableArray.empty());
this.changeDetector.markForCheck();
}); });
} }
} else { } else {
this.oldAssets = ImmutableArray.empty(); this.setAssets(ImmutableArray.empty());
this.changeDetector.markForCheck();
} }
} }
public setAssets(asset: ImmutableArray<AssetDto>) {
this.oldAssets = asset;
this.changeDetector.markForCheck();
}
public setDisabledState(isDisabled: boolean): void { public setDisabledState(isDisabled: boolean): void {
this.isDisabled = isDisabled; 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) { for (let asset of assets) {
this.oldAssets = this.oldAssets.push(asset); this.oldAssets = this.oldAssets.push(asset);
} }
@ -111,7 +111,16 @@ export class AssetsEditorComponent implements ControlValueAccessor {
this.assetsDialog.hide(); 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) { if (asset) {
this.oldAssets = this.oldAssets.remove(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.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) { public sortAssets(assets: AssetDto[]) {
this.newAssets = this.newAssets.remove(file); if (assets) {
this.oldAssets = ImmutableArray.of(assets);
this.updateValue();
}
} }
private updateValue() { private updateValue() {
@ -142,18 +158,4 @@ export class AssetsEditorComponent implements ControlValueAccessor {
this.changeDetector.markForCheck(); 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;
}
} }

18
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) this.contentsService.getContents(this.appsState.appName, this.schemaId, 10000, 0, undefined, contentIds)
.subscribe(dtos => { .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) { if (this.contentItems.length !== contentIds.length) {
this.updateValue(); this.updateValue();
} }
this.changeDetector.markForCheck();
}, () => { }, () => {
this.contentItems = ImmutableArray.empty(); this.setContentItems(ImmutableArray.empty());
this.changeDetector.markForCheck();
}); });
} }
} else { } else {
this.contentItems = ImmutableArray.empty(); this.setContentItems(ImmutableArray.empty());
this.changeDetector.markForCheck();
} }
} }
public setContentItems(contents: ImmutableArray<ContentDto>) {
this.contentItems = contents;
this.changeDetector.markForCheck();
}
public setDisabledState(isDisabled: boolean): void { public setDisabledState(isDisabled: boolean): void {
this.isDisabled = isDisabled; this.isDisabled = isDisabled;

2
src/Squidex/app/features/schemas/pages/schemas/schemas-page.component.html

@ -37,7 +37,7 @@
<ng-container *sqxModalView="addSchemaDialog;onRoot:true"> <ng-container *sqxModalView="addSchemaDialog;onRoot:true">
<sqx-schema-form [import]="import" <sqx-schema-form [import]="import"
(cancelled)="addSchemaDialog.hide()" (cancelled)="addSchemaDialog.hide()"
(created)="onSchemaCreated($event)"> (created)="redirectSchema($event)">
</sqx-schema-form> </sqx-schema-form>
</ng-container> </ng-container>

2
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.router.navigate([schema.name], { relativeTo: this.route });
this.addSchemaDialog.hide(); this.addSchemaDialog.hide();

6
src/Squidex/app/framework/angular/forms/dropdown.component.ts

@ -95,8 +95,10 @@ export class DropdownComponent implements AfterContentInit, ControlValueAccessor
return false; return false;
case KEY_ESCAPE: case KEY_ESCAPE:
case KEY_ENTER: case KEY_ENTER:
this.close(); if (this.dropdown.isOpen) {
return false; this.close();
return false;
}
} }
return true; return true;

2
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 = ''; let content = '';
for (let asset of assets) { for (let asset of assets) {

2
src/Squidex/app/shared/components/rich-editor.component.ts

@ -137,7 +137,7 @@ export class RichEditorComponent implements ControlValueAccessor, AfterViewInit,
this.callTouched = fn; this.callTouched = fn;
} }
public onAssetsSelected(assets: AssetDto[]) { public insertAssets(assets: AssetDto[]) {
let content = ''; let content = '';
for (let asset of assets) { for (let asset of assets) {

Loading…
Cancel
Save