|
|
@@ -1,5 +1,4 @@
|
|
|
import { CdkDragDrop, moveItemInArray } from '@angular/cdk/drag-drop';
|
|
|
-import { ViewportRuler } from '@angular/cdk/overlay';
|
|
|
import {
|
|
|
ChangeDetectionStrategy,
|
|
|
ChangeDetectorRef,
|
|
|
@@ -7,7 +6,6 @@ import {
|
|
|
EventEmitter,
|
|
|
HostBinding,
|
|
|
Input,
|
|
|
- Optional,
|
|
|
Output,
|
|
|
} from '@angular/core';
|
|
|
import {
|
|
|
@@ -19,27 +17,25 @@ import {
|
|
|
} from '@vendure/admin-ui/core';
|
|
|
import { unique } from '@vendure/common/lib/unique';
|
|
|
|
|
|
-import { CollectionDetailComponent } from '../collection-detail/collection-detail.component';
|
|
|
-
|
|
|
export interface AssetChange {
|
|
|
assets: Asset[];
|
|
|
featuredAsset: Asset | undefined;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * A component which displays the Assets associated with a product, and allows assets to be removed and
|
|
|
+ * A component which displays the Assets, and allows assets to be removed and
|
|
|
* added, and for the featured asset to be set.
|
|
|
*
|
|
|
* Note: rather complex code for drag drop is due to a limitation of the default CDK implementation
|
|
|
* which is addressed by a work-around from here: https://github.com/angular/components/issues/13372#issuecomment-483998378
|
|
|
*/
|
|
|
@Component({
|
|
|
- selector: 'vdr-product-assets',
|
|
|
- templateUrl: './product-assets.component.html',
|
|
|
- styleUrls: ['./product-assets.component.scss'],
|
|
|
+ selector: 'vdr-assets',
|
|
|
+ templateUrl: './assets.component.html',
|
|
|
+ styleUrls: ['./assets.component.scss'],
|
|
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
|
})
|
|
|
-export class ProductAssetsComponent {
|
|
|
+export class AssetsComponent {
|
|
|
@Input('assets') set assetsSetter(val: Asset[]) {
|
|
|
// create a new non-readonly array of assets
|
|
|
this.assets = (val || []).slice();
|
|
|
@@ -53,23 +49,10 @@ export class ProductAssetsComponent {
|
|
|
|
|
|
public assets: Asset[] = [];
|
|
|
|
|
|
- private readonly updateCollectionPermissions = [Permission.UpdateCatalog, Permission.UpdateCollection];
|
|
|
- private readonly updateProductPermissions = [Permission.UpdateCatalog, Permission.UpdateProduct];
|
|
|
-
|
|
|
- get updatePermissions(): Permission[] {
|
|
|
- if (this.collectionDetailComponent) {
|
|
|
- return this.updateCollectionPermissions;
|
|
|
- } else {
|
|
|
- return this.updateProductPermissions;
|
|
|
- }
|
|
|
- }
|
|
|
+ @Input()
|
|
|
+ updatePermissions: string | string[] | Permission | Permission[];
|
|
|
|
|
|
- constructor(
|
|
|
- private modalService: ModalService,
|
|
|
- private changeDetector: ChangeDetectorRef,
|
|
|
- private viewportRuler: ViewportRuler,
|
|
|
- @Optional() private collectionDetailComponent?: CollectionDetailComponent,
|
|
|
- ) {}
|
|
|
+ constructor(private modalService: ModalService, private changeDetector: ChangeDetectorRef) {}
|
|
|
|
|
|
selectAssets() {
|
|
|
this.modalService
|