11<script setup lang="ts">
22import " ui/hoverhighlight" ;
33
4- import { faSquare } from " @fortawesome/free-regular-svg-icons" ;
5- import { faMinus , faSortAlphaDown , faTimes , faUndo } from " @fortawesome/free-solid-svg-icons" ;
4+ import { faEdit , faSquare } from " @fortawesome/free-regular-svg-icons" ;
5+ import { faGripLines , faMinus , faSortAlphaDown , faTimes , faUndo } from " @fortawesome/free-solid-svg-icons" ;
66import { FontAwesomeIcon } from " @fortawesome/vue-fontawesome" ;
77import { BAlert } from " bootstrap-vue" ;
88import { computed , ref , watch } from " vue" ;
@@ -18,6 +18,7 @@ import { type Mode, useCollectionCreator } from "./common/useCollectionCreator";
1818
1919import GButton from " ../BaseComponents/GButton.vue" ;
2020import GButtonGroup from " ../BaseComponents/GButtonGroup.vue" ;
21+ import GModal from " ../BaseComponents/GModal.vue" ;
2122import FormSelectMany from " ../Form/Elements/FormSelectMany/FormSelectMany.vue" ;
2223import HelpText from " ../Help/HelpText.vue" ;
2324import CollectionCreator from " @/components/Collections/common/CollectionCreator.vue" ;
@@ -343,12 +344,39 @@ function addUploadedFiles(files: HDASummary[]) {
343344 });
344345}
345346
347+ /** If we are creating a collection from a history (not a pre-selection of elements),
348+ * once we have some selected elements, we provide an option to rename them in a modal.
349+ */
350+ const canRenameElements = computed (() => {
351+ return ! props .fromSelection && inListElements .value .length > 0 ;
352+ });
353+ /** A toggle for the modal that allows renaming elements in the selected list */
354+ const renamingElements = ref (false );
346355/** find the element in the workingElements array and update its name */
347356function renameElement(element : any , name : string ) {
357+ // We do this whole process of removing and readding because inListElements
358+ // might be reacting to changes in workingElements, and we want to
359+ // prevent that from causing issues with producing duplicate elements in either list:
360+
361+ // first check at what index of inlistElements the element is
362+ const index = inListElements .value .findIndex ((e ) => e .id === element .id );
363+ if (index < 0 ) {
364+ return ;
365+ }
366+
367+ // remove from inListElements
368+ inListElements .value = inListElements .value .filter ((e ) => e .id !== element .id );
369+
370+ // then find the element in workingElements, and rename it
348371 element = workingElements .value .find ((e ) => e .id === element .id );
349372 if (element ) {
350373 element .name = name ;
351374 }
375+
376+ // now add again to inListElements at same index
377+ if (index >= 0 ) {
378+ inListElements .value .splice (index , 0 , element );
379+ }
352380}
353381
354382function selectionAsHdaSummary(value : any ): HDASummary {
@@ -413,11 +441,13 @@ function selectionAsHdaSummary(value: any): HDASummary {
413441 :show-buttons =" showButtonsForModal"
414442 :collection-name =" collectionName"
415443 :mode =" mode"
444+ :can-rename-elements =" canRenameElements"
416445 @on-update-collection-name =" onUpdateCollectionName"
417446 @add-uploaded-files =" addUploadedFiles"
418447 @on-update-datatype-toggle =" changeDatatypeFilter"
419448 @onUpdateHideSourceItems =" onUpdateHideSourceItems"
420449 @remove-extensions-toggle =" removeExtensionsToggle"
450+ @clicked-rename =" renamingElements = true"
421451 @clicked-create =" attemptCreate" >
422452 <template v-slot :help-content >
423453 <p >
@@ -443,7 +473,7 @@ function selectionAsHdaSummary(value: any): HDASummary {
443473 <li v-if =" !fromSelection" >
444474 The filter textbox can be used to rapidly find the datasets of interest by name.
445475 </li >
446- <li >
476+ <li v-if = " fromSelection " >
447477 {{ localize("Change the identifier of elements in the list by clicking on") }}
448478 <i data-target =" .collection-element .name" >
449479 {{ localize("the existing name") }}
@@ -520,6 +550,24 @@ function selectionAsHdaSummary(value: any): HDASummary {
520550 </i >
521551 {{ localize(".") }}
522552 </p >
553+
554+ <p v-if =" !fromSelection" >
555+ <strong >
556+ {{ localize("Optional:") }}
557+ </strong >
558+ {{
559+ localize(
560+ [
561+ "Once you have made your selection, if you wish to rename identifiers for elements in the list",
562+ " or change/set the order in which they exist in the final list, you can click on ",
563+ ].join("")
564+ )
565+ }}
566+ <i data-target =" .rename-elements" >
567+ {{ localize("Rename/Reorder list elements") }}
568+ </i >
569+ {{ localize(". This opens a modal where you can perform these actions.") }}
570+ </p >
523571 </template >
524572
525573 <template v-slot :middle-content >
@@ -646,6 +694,7 @@ function selectionAsHdaSummary(value: any): HDASummary {
646694 <draggable
647695 v-model =" workingElements"
648696 class =" collection-elements scroll-container flex-row drop-zone"
697+ style =" max-height : 400px "
649698 chosen-class =" bg-secondary" >
650699 <DatasetCollectionElementView
651700 v-for =" element in workingElements"
@@ -669,14 +718,49 @@ function selectionAsHdaSummary(value: any): HDASummary {
669718 :options =" workingElements.map((e) => ({ label: e.name || '', value: e }))" >
670719 <template v-slot :label-area =" { value } " >
671720 <DatasetCollectionElementView
672- class =" w-100"
721+ text-only
722+ not-editable
673723 :element =" selectionAsHdaSummary(value)"
674- :hide-extension =" !showElementExtension"
675- @onRename =" (name) => renameElement(value, name)" />
724+ :hide-extension =" !showElementExtension" />
676725 </template >
677726 </FormSelectMany >
678727 </template >
679728 </CollectionCreator >
729+
730+ <GModal
731+ class =" rename-elements-modal"
732+ :show.sync =" renamingElements"
733+ fixed-height
734+ size =" small"
735+ title =" Rename and Reorder List Elements" >
736+ <div >
737+ <FontAwesomeIcon :icon =" faEdit" fixed-width />
738+ {{ localize("Here, you can change the identifiers of the elements in the list.") }}
739+ {{
740+ localize(
741+ "The final list will then have these identifiers, and this does not modify the original datasets."
742+ )
743+ }}
744+ </div >
745+ <div >
746+ <FontAwesomeIcon :icon =" faGripLines" fixed-width />
747+ {{ localize("Also, you can click and drag to reorder the elements in the list.") }}
748+ </div >
749+ <hr class =" w-100 my-2" />
750+ <draggable
751+ v-model =" inListElements"
752+ class =" collection-elements scroll-container flex-row"
753+ chosen-class =" bg-secondary"
754+ @wheel.stop >
755+ <DatasetCollectionElementView
756+ v-for =" value in inListElements"
757+ :key =" value.id"
758+ class =" w-100"
759+ :element =" selectionAsHdaSummary(value)"
760+ :hide-extension =" !showElementExtension"
761+ @onRename =" (name) => renameElement(value, name)" />
762+ </draggable >
763+ </GModal >
680764 </div >
681765 </div >
682766</template >
@@ -686,6 +770,15 @@ function selectionAsHdaSummary(value: any): HDASummary {
686770@import " theme/blue.scss" ;
687771
688772.list-collection-creator {
773+ .rename-elements-modal {
774+ .collection-element {
775+ cursor : grab ;
776+ & :focus {
777+ cursor : grabbing ;
778+ }
779+ }
780+ }
781+
689782 .footer {
690783 margin-top : 8px ;
691784 }
@@ -709,7 +802,6 @@ function selectionAsHdaSummary(value: any): HDASummary {
709802 }
710803
711804 .collection-elements {
712- max-height : 400px ;
713805 border : 0px solid lightgrey ;
714806 overflow-y : auto ;
715807 overflow-x : hidden ;
@@ -732,11 +824,6 @@ function selectionAsHdaSummary(value: any): HDASummary {
732824 border-color : black ;
733825 }
734826 }
735- & :not (.with-actions ) {
736- & :hover {
737- border : none ;
738- }
739- }
740827
741828 & :last-of-type {
742829 margin-bottom : 2px ;
0 commit comments