From 7011bc163b49209ae8cccf251031f6218e3f32d0 Mon Sep 17 00:00:00 2001 From: Michael Bromley Date: Wed, 5 Feb 2020 15:58:16 +0100 Subject: [PATCH] refactor(admin-ui): Split AssetPreview into dialog & component --- .../src/app/catalog/catalog.module.ts | 3 --- .../product-assets.component.ts | 13 +++--------- .../asset-gallery/asset-gallery.component.ts | 4 ++-- .../asset-preview-dialog.component.html | 7 +++++++ .../asset-preview-dialog.component.scss | 3 +++ .../asset-preview-dialog.component.ts | 15 ++++++++++++++ .../asset-preview.component.html | 20 +++++++------------ .../asset-preview.component.scss | 8 +++++--- .../asset-preview/asset-preview.component.ts | 9 +++++---- .../src/app/shared/shared-declarations.ts | 4 ++++ .../admin-ui/src/app/shared/shared.module.ts | 11 +++++++++- 11 files changed, 61 insertions(+), 36 deletions(-) create mode 100644 packages/admin-ui/src/app/shared/components/asset-preview-dialog/asset-preview-dialog.component.html create mode 100644 packages/admin-ui/src/app/shared/components/asset-preview-dialog/asset-preview-dialog.component.scss create mode 100644 packages/admin-ui/src/app/shared/components/asset-preview-dialog/asset-preview-dialog.component.ts rename packages/admin-ui/src/app/{catalog => shared}/components/asset-preview/asset-preview.component.html (72%) rename packages/admin-ui/src/app/{catalog => shared}/components/asset-preview/asset-preview.component.scss (93%) rename packages/admin-ui/src/app/{catalog => shared}/components/asset-preview/asset-preview.component.ts (78%) diff --git a/packages/admin-ui/src/app/catalog/catalog.module.ts b/packages/admin-ui/src/app/catalog/catalog.module.ts index c969649968..22adaa85e1 100644 --- a/packages/admin-ui/src/app/catalog/catalog.module.ts +++ b/packages/admin-ui/src/app/catalog/catalog.module.ts @@ -7,7 +7,6 @@ import { SharedModule } from '../shared/shared.module'; import { catalogRoutes } from './catalog.routes'; import { ApplyFacetDialogComponent } from './components/apply-facet-dialog/apply-facet-dialog.component'; import { AssetListComponent } from './components/asset-list/asset-list.component'; -import { AssetPreviewComponent } from './components/asset-preview/asset-preview.component'; import { AssignProductsToChannelDialogComponent } from './components/assign-products-to-channel-dialog/assign-products-to-channel-dialog.component'; import { CollectionContentsComponent } from './components/collection-contents/collection-contents.component'; import { CollectionDetailComponent } from './components/collection-detail/collection-detail.component'; @@ -53,7 +52,6 @@ import { ProductVariantsResolver } from './providers/routing/product-variants-re CollectionTreeNodeComponent, CollectionContentsComponent, ProductVariantsTableComponent, - AssetPreviewComponent, ProductSearchInputComponent, OptionValueInputComponent, UpdateProductOptionDialogComponent, @@ -62,7 +60,6 @@ import { ProductVariantsResolver } from './providers/routing/product-variants-re ], entryComponents: [ ApplyFacetDialogComponent, - AssetPreviewComponent, UpdateProductOptionDialogComponent, AssignProductsToChannelDialogComponent, ], diff --git a/packages/admin-ui/src/app/catalog/components/product-assets/product-assets.component.ts b/packages/admin-ui/src/app/catalog/components/product-assets/product-assets.component.ts index fc1239fa78..5f3aa71bca 100644 --- a/packages/admin-ui/src/app/catalog/components/product-assets/product-assets.component.ts +++ b/packages/admin-ui/src/app/catalog/components/product-assets/product-assets.component.ts @@ -1,11 +1,4 @@ -import { - CdkDrag, - CdkDragDrop, - CdkDragMove, - CdkDropList, - CdkDropListGroup, - moveItemInArray, -} from '@angular/cdk/drag-drop'; +import { CdkDrag, CdkDragMove, CdkDropList, CdkDropListGroup, moveItemInArray } from '@angular/cdk/drag-drop'; import { ViewportRuler } from '@angular/cdk/overlay'; import { AfterViewInit, @@ -22,8 +15,8 @@ import { unique } from 'shared/unique'; import { Asset } from '../../../common/generated-types'; import { AssetPickerDialogComponent } from '../../../shared/components/asset-picker-dialog/asset-picker-dialog.component'; +import { AssetPreviewDialogComponent } from '../../../shared/components/asset-preview-dialog/asset-preview-dialog.component'; import { ModalService } from '../../../shared/providers/modal/modal.service'; -import { AssetPreviewComponent } from '../asset-preview/asset-preview.component'; export interface AssetChange { assetIds: string[]; @@ -103,7 +96,7 @@ export class ProductAssetsComponent implements AfterViewInit { previewAsset(asset: Asset) { this.modalService - .fromComponent(AssetPreviewComponent, { + .fromComponent(AssetPreviewDialogComponent, { size: 'xl', closable: true, locals: { asset }, diff --git a/packages/admin-ui/src/app/shared/components/asset-gallery/asset-gallery.component.ts b/packages/admin-ui/src/app/shared/components/asset-gallery/asset-gallery.component.ts index dcdf79375b..3488f7fde9 100644 --- a/packages/admin-ui/src/app/shared/components/asset-gallery/asset-gallery.component.ts +++ b/packages/admin-ui/src/app/shared/components/asset-gallery/asset-gallery.component.ts @@ -1,8 +1,8 @@ import { ChangeDetectionStrategy, Component, EventEmitter, Input, Output } from '@angular/core'; -import { AssetPreviewComponent } from '../../../catalog/components/asset-preview/asset-preview.component'; import { Asset } from '../../../common/generated-types'; import { ModalService } from '../../providers/modal/modal.service'; +import { AssetPreviewDialogComponent } from '../asset-preview-dialog/asset-preview-dialog.component'; @Component({ selector: 'vdr-asset-gallery', @@ -52,7 +52,7 @@ export class AssetGalleryComponent { previewAsset(asset: Asset) { this.modalService - .fromComponent(AssetPreviewComponent, { + .fromComponent(AssetPreviewDialogComponent, { size: 'xl', closable: true, locals: { asset }, diff --git a/packages/admin-ui/src/app/shared/components/asset-preview-dialog/asset-preview-dialog.component.html b/packages/admin-ui/src/app/shared/components/asset-preview-dialog/asset-preview-dialog.component.html new file mode 100644 index 0000000000..16f23ec148 --- /dev/null +++ b/packages/admin-ui/src/app/shared/components/asset-preview-dialog/asset-preview-dialog.component.html @@ -0,0 +1,7 @@ + +
+ {{ asset.name }} +
+
+ + diff --git a/packages/admin-ui/src/app/shared/components/asset-preview-dialog/asset-preview-dialog.component.scss b/packages/admin-ui/src/app/shared/components/asset-preview-dialog/asset-preview-dialog.component.scss new file mode 100644 index 0000000000..3e754646c1 --- /dev/null +++ b/packages/admin-ui/src/app/shared/components/asset-preview-dialog/asset-preview-dialog.component.scss @@ -0,0 +1,3 @@ +:host { + height: 70vh; +} diff --git a/packages/admin-ui/src/app/shared/components/asset-preview-dialog/asset-preview-dialog.component.ts b/packages/admin-ui/src/app/shared/components/asset-preview-dialog/asset-preview-dialog.component.ts new file mode 100644 index 0000000000..cc88ab9ddc --- /dev/null +++ b/packages/admin-ui/src/app/shared/components/asset-preview-dialog/asset-preview-dialog.component.ts @@ -0,0 +1,15 @@ +import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core'; + +import { Asset } from '../../../common/generated-types'; +import { Dialog } from '../../providers/modal/modal.service'; + +@Component({ + selector: 'vdr-asset-preview-dialog', + templateUrl: './asset-preview-dialog.component.html', + styleUrls: ['./asset-preview-dialog.component.scss'], + changeDetection: ChangeDetectionStrategy.OnPush, +}) +export class AssetPreviewDialogComponent implements Dialog { + asset: Asset; + resolveWith: (result?: void) => void; +} diff --git a/packages/admin-ui/src/app/catalog/components/asset-preview/asset-preview.component.html b/packages/admin-ui/src/app/shared/components/asset-preview/asset-preview.component.html similarity index 72% rename from packages/admin-ui/src/app/catalog/components/asset-preview/asset-preview.component.html rename to packages/admin-ui/src/app/shared/components/asset-preview/asset-preview.component.html index 159984d318..bbd9bea39e 100644 --- a/packages/admin-ui/src/app/catalog/components/asset-preview/asset-preview.component.html +++ b/packages/admin-ui/src/app/shared/components/asset-preview/asset-preview.component.html @@ -1,15 +1,9 @@ - -
- {{ asset.name }} -
-
-
- -
+
+