From a4e132ac96d7a541f36ee447c5f331db863b0afa Mon Sep 17 00:00:00 2001 From: Michael Bromley Date: Thu, 2 Jul 2020 17:49:03 +0200 Subject: [PATCH] feat(admin-ui): Improve multi-selection in Asset gallery component Relates to #380. This commit introduces the ability to shift-click to select a range of assets --- .../asset-gallery.component.html | 44 ++++++++----------- .../asset-gallery.component.scss | 18 +++++--- .../asset-gallery/asset-gallery.component.ts | 13 +++++- 3 files changed, 41 insertions(+), 34 deletions(-) diff --git a/packages/admin-ui/src/lib/core/src/shared/components/asset-gallery/asset-gallery.component.html b/packages/admin-ui/src/lib/core/src/shared/components/asset-gallery/asset-gallery.component.html index a5ddbced58..64af98418a 100644 --- a/packages/admin-ui/src/lib/core/src/shared/components/asset-gallery/asset-gallery.component.html +++ b/packages/admin-ui/src/lib/core/src/shared/components/asset-gallery/asset-gallery.component.html @@ -7,7 +7,7 @@ >
- +
{{ lastSelected().name }}
-
- {{ 'asset.original-asset-size' | translate }}: {{ lastSelected().fileSize | filesize }} -
-
- -
-
- - {{ 'common.edit' | translate }} - -
-
+
{{ 'asset.original-asset-size' | translate }}: {{ lastSelected().fileSize | filesize }}
+ +
+ +
+ +
+
@@ -56,15 +56,9 @@
- -
- {{ 'asset.assets-selected-count' | translate: { count: selection.length } }} -
- -
    -
  • {{ asset.name }}
  • -
-
-
+ {{ 'asset.assets-selected-count' | translate: { count: selection.length } }} +
    +
  • {{ asset.name }}
  • +
diff --git a/packages/admin-ui/src/lib/core/src/shared/components/asset-gallery/asset-gallery.component.scss b/packages/admin-ui/src/lib/core/src/shared/components/asset-gallery/asset-gallery.component.scss index 13430db602..f261ba9f53 100644 --- a/packages/admin-ui/src/lib/core/src/shared/components/asset-gallery/asset-gallery.component.scss +++ b/packages/admin-ui/src/lib/core/src/shared/components/asset-gallery/asset-gallery.component.scss @@ -1,4 +1,4 @@ -@import "variables"; +@import 'variables'; :host { display: flex; @@ -36,7 +36,7 @@ border-radius: 50%; top: -12px; left: -12px; - box-shadow: 0px 5px 5px -4px rgba(0,0,0,0.75); + box-shadow: 0px 5px 5px -4px rgba(0, 0, 0, 0.75); transition: opacity 0.1s; } @@ -87,19 +87,23 @@ .selection-count { opacity: 0; + position: relative; text-align: center; visibility: hidden; transition: opacity 0.3s, visibility 0s 0.3s; - .trigger { - cursor: pointer; - color: $color-grey-400; - text-decoration: underline; - } &.visible { opacity: 1; visibility: visible; transition: opacity 0.3s, visibility 0s; } + ul { + text-align: left; + list-style-type: none; + margin-left: 12px; + li { + font-size: 12px; + } + } } .placeholder { diff --git a/packages/admin-ui/src/lib/core/src/shared/components/asset-gallery/asset-gallery.component.ts b/packages/admin-ui/src/lib/core/src/shared/components/asset-gallery/asset-gallery.component.ts index 71301cafd4..e71465c9f6 100644 --- a/packages/admin-ui/src/lib/core/src/shared/components/asset-gallery/asset-gallery.component.ts +++ b/packages/admin-ui/src/lib/core/src/shared/components/asset-gallery/asset-gallery.component.ts @@ -38,8 +38,17 @@ export class AssetGalleryComponent implements OnChanges { toggleSelection(event: MouseEvent, asset: Asset) { const index = this.selection.findIndex((a) => a.id === asset.id); - if (index === -1) { - if (this.multiSelect && event.ctrlKey) { + 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); + const start = currentIndex < lastSelectionIndex ? currentIndex : lastSelectionIndex; + const end = currentIndex > lastSelectionIndex ? currentIndex + 1 : lastSelectionIndex; + this.selection.push( + ...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)) { this.selection.push(asset); } else { this.selection = [asset];