Skip to content

Commit

Permalink
feat(admin-ui): Auto-select newly uploaded assets in AssetPickerDialog
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbromley committed Jul 15, 2021
1 parent 1b218ed commit 96cc8f9
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div
class="card"
*ngFor="let asset of assets"
(click)="toggleSelection($event, asset)"
(click)="toggleSelection(asset, $event)"
[class.selected]="isSelected(asset)"
>
<div class="card-img">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ export class AssetGalleryComponent implements OnChanges {
}
}

toggleSelection(event: MouseEvent, asset: Asset) {
toggleSelection(asset: AssetLike, event?: MouseEvent) {
const index = this.selection.findIndex(a => a.id === asset.id);
if (this.multiSelect && event.shiftKey && 1 <= this.selection.length) {
if (this.multiSelect && event?.shiftKey && 1 <= this.selection.length) {
const lastSelection = this.selection[this.selection.length - 1];
const lastSelectionIndex = this.assets.findIndex(a => a.id === lastSelection.id);
const currentIndex = this.assets.findIndex(a => a.id === asset.id);
Expand All @@ -50,13 +50,13 @@ export class AssetGalleryComponent implements OnChanges {
...this.assets.slice(start, end).filter(a => !this.selection.find(s => s.id === a.id)),
);
} else if (index === -1) {
if (this.multiSelect && (event.ctrlKey || event.shiftKey)) {
if (this.multiSelect && (event?.ctrlKey || event?.shiftKey)) {
this.selection.push(asset);
} else {
this.selection = [asset];
}
} else {
if (this.multiSelect && event.ctrlKey) {
if (this.multiSelect && event?.ctrlKey) {
this.selection.splice(index, 1);
} else if (1 < this.selection.length) {
this.selection = [asset];
Expand All @@ -69,6 +69,11 @@ export class AssetGalleryComponent implements OnChanges {
this.selectionChange.emit(this.selection);
}

selectMultiple(assets: AssetLike[]) {
this.selection = assets;
this.selectionChange.emit(this.selection);
}

isSelected(asset: AssetLike): boolean {
return !!this.selection.find(a => a.id === asset.id);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
[assets]="(assets$ | async)! | paginate: paginationConfig"
[multiSelect]="multiSelect"
(selectionChange)="selection = $event"
#assetGalleryComponent
></vdr-asset-gallery>

<div class="paging-controls">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { debounceTime, delay, finalize, map, take as rxjsTake, takeUntil, tap }

import {
Asset,
CreateAssets,
GetAssetList,
LogicalOperator,
SortOrder,
Expand All @@ -22,6 +23,7 @@ import { DataService } from '../../../data/providers/data.service';
import { QueryResult } from '../../../data/query-result';
import { Dialog } from '../../../providers/modal/modal.service';
import { NotificationService } from '../../../providers/notification/notification.service';
import { AssetGalleryComponent } from '../asset-gallery/asset-gallery.component';
import { AssetSearchInputComponent } from '../asset-search-input/asset-search-input.component';

/**
Expand All @@ -43,6 +45,8 @@ export class AssetPickerDialogComponent implements OnInit, AfterViewInit, OnDest
};
@ViewChild('assetSearchInputComponent')
private assetSearchInputComponent: AssetSearchInputComponent;
@ViewChild('assetGalleryComponent')
private assetGalleryComponent: AssetGalleryComponent;

multiSelect = true;
initialTags: string[] = [];
Expand Down Expand Up @@ -119,6 +123,10 @@ export class AssetPickerDialogComponent implements OnInit, AfterViewInit, OnDest
this.notificationService.success(_('asset.notify-create-assets-success'), {
count: files.length,
});
const assets = res.createAssets.filter(
a => a.__typename === 'Asset',
) as CreateAssets.AssetInlineFragment[];
this.assetGalleryComponent.selectMultiple(assets);
});
}
}
Expand Down

0 comments on commit 96cc8f9

Please sign in to comment.