-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathRemoteFilesUpload.vue
More file actions
1006 lines (878 loc) · 33.8 KB
/
RemoteFilesUpload.vue
File metadata and controls
1006 lines (878 loc) · 33.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<script setup lang="ts">
import { faFolder, faGlobe, faPlus, faTimes, faUser } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";
import { BAlert, BFormCheckbox, BFormInput, BPagination } from "bootstrap-vue";
import { computed, nextTick, onMounted, ref, watch } from "vue";
import { useRouter } from "vue-router/composables";
import { browseRemoteFiles, fetchFileSources, type RemoteEntry } from "@/api/remoteFiles";
import type { BreadcrumbItem } from "@/components/Common";
import type { TableField } from "@/components/Common/GTable.types";
import { Model } from "@/components/FilesDialog/model";
import { fileSourcePluginToItem, selectionToArray } from "@/components/FilesDialog/utilities";
import type { SelectionItem } from "@/components/SelectionDialog/selectionTypes";
import { useFileSources } from "@/composables/fileSources";
import { useBulkUploadOperations } from "@/composables/upload/bulkUploadOperations";
import { useCollectionCreation } from "@/composables/upload/collectionCreation";
import { useUploadAdvancedMode } from "@/composables/upload/uploadAdvancedMode";
import { useUploadDefaults } from "@/composables/upload/uploadDefaults";
import { useUploadItemValidation } from "@/composables/upload/uploadItemValidation";
import { useUploadReadyState } from "@/composables/upload/uploadReadyState";
import { useUploadStaging } from "@/composables/upload/useUploadStaging";
import { useUrlTracker } from "@/composables/urlTracker";
import { errorMessageAsString } from "@/utils/simple-error";
import { buildPreparedUpload } from "@/utils/upload";
import { mapToRemoteFileUpload } from "@/utils/upload/itemMappers";
import { USER_FILE_PREFIX } from "@/utils/url";
import { bytesToString } from "@/utils/utils";
import type { PreparedUpload, UploadMethodComponent, UploadMethodConfig } from "../types";
import type { RemoteFileItem } from "../types/uploadItem";
import CollectionCreationConfig from "../CollectionCreationConfig.vue";
import RemoteEntryMetadata from "../shared/RemoteEntryMetadata.vue";
import UploadTableBulkDbKeyHeader from "../shared/UploadTableBulkDbKeyHeader.vue";
import UploadTableBulkExtensionHeader from "../shared/UploadTableBulkExtensionHeader.vue";
import UploadTableDbKeyCell from "../shared/UploadTableDbKeyCell.vue";
import UploadTableExtensionCell from "../shared/UploadTableExtensionCell.vue";
import UploadTableNameCell from "../shared/UploadTableNameCell.vue";
import UploadTableOptionsCell from "../shared/UploadTableOptionsCell.vue";
import UploadTableOptionsHeader from "../shared/UploadTableOptionsHeader.vue";
import GButton from "@/components/BaseComponents/GButton.vue";
import BreadcrumbNavigation from "@/components/Common/BreadcrumbNavigation.vue";
import GTable from "@/components/Common/GTable.vue";
import DataDialogSearch from "@/components/SelectionDialog/DataDialogSearch.vue";
interface Props {
method: UploadMethodConfig;
/** History ID where uploaded datasets will be added. */
targetHistoryId: string;
/** Allow creating dataset collections from selected remote files. */
allowCollections?: boolean;
/** Optional list of allowed formats to constrain selectable extensions. */
formats?: string[];
/** When false, restrict selection to a single remote file. */
multiple?: boolean;
/** When true, do not persist staging to the shared store (modal use). */
transient?: boolean;
}
const props = withDefaults(defineProps<Props>(), {
allowCollections: true,
formats: undefined,
multiple: true,
transient: false,
});
const emit = defineEmits<{
(e: "ready", ready: boolean): void;
}>();
const { advancedMode } = useUploadAdvancedMode();
const router = useRouter();
const filesSources = useFileSources();
const { effectiveExtensions, listDbKeys, configurationsReady, createItemDefaults } = useUploadDefaults(props.formats);
const tableContainerRef = ref<HTMLElement | null>(null);
const collectionConfigComponent = ref<InstanceType<typeof CollectionCreationConfig> | null>(null);
const remoteFileItems = ref<RemoteFileItem[]>([]);
const { clear: clearStaging } = useUploadStaging<RemoteFileItem>(props.method.id, remoteFileItems, {
disableStore: props.transient,
});
const { buildCollectionConfig, collectionState, handleCollectionStateChange, resetCollection } =
useCollectionCreation(collectionConfigComponent);
let nextId = 1;
function createRemoteFileItem(id: number, selectionItem: SelectionItem): RemoteFileItem {
const entry = selectionItem.entry as RemoteEntry;
const hashes = entry.class === "File" && entry.hashes ? entry.hashes : undefined;
return {
id,
url: selectionItem.url,
name: selectionItem.label,
size: entry.class === "File" ? entry.size : 0,
hashes,
...createItemDefaults(),
deferred: false,
};
}
const isSingleMode = computed(() => props.multiple === false);
const showBrowser = ref(true);
const selectionModel = ref<Model>(new Model({ multiple: !isSingleMode.value }));
const selectionCount = ref(0);
const urlTracker = useUrlTracker<SelectionItem>();
const browserItems = ref<SelectionItem[]>([]);
const allFetchedItems = ref<SelectionItem[]>([]); // Store all items for client-side pagination
const searchQuery = ref("");
const isBusy = ref(false);
const errorMessage = ref<string>();
const currentPage = ref(1);
const perPage = ref(25);
const totalMatches = ref(0);
/**
* Sequence id to track latest load request. Incremented on each navigation/load.
*/
const loadSequenceId = ref(0);
async function executeIfLatest<T>(
operation: () => Promise<T>,
onSuccess: (data: T) => void,
onError?: (error: unknown) => void,
): Promise<void> {
const seq = loadSequenceId.value;
isBusy.value = true;
errorMessage.value = undefined;
try {
const result = await operation();
// Ignore if a newer load started while we were fetching
if (seq === loadSequenceId.value) {
onSuccess(result);
}
} catch (error) {
if (seq === loadSequenceId.value) {
if (onError) {
onError(error);
} else {
errorMessage.value = errorMessageAsString(error);
}
}
} finally {
if (seq === loadSequenceId.value) {
isBusy.value = false;
}
}
}
const currentFileSourceUri = computed(() => urlTracker.current.value?.url);
const supportsServerPagination = computed(() => filesSources.supportsPagination(currentFileSourceUri.value));
const supportsServerSearch = computed(() => filesSources.supportsSearch(currentFileSourceUri.value));
const hasPagination = computed(() => {
if (urlTracker.isAtRoot.value || isBusy.value) {
return false;
}
const itemCount = supportsServerPagination.value ? totalMatches.value : allFetchedItems.value.length;
return itemCount > perPage.value;
});
const hasItems = computed(() => remoteFileItems.value.length > 0);
const hasSelection = computed(() => selectionCount.value > 0);
const addMoreFilesTitle = computed(() =>
isSingleMode.value ? "Change selected file" : "Add more remote files to the upload list",
);
const addMoreFilesLabel = computed(() => (isSingleMode.value ? "Change selected file" : "Add More Files"));
const breadcrumbs = computed(() => {
const crumbs: BreadcrumbItem[] = [{ title: "Sources", index: -1 }];
urlTracker.navigationHistory.value.forEach((item, index) => {
crumbs.push({ title: item.label, index });
});
return crumbs;
});
const { isNameValid, restoreOriginalName } = useUploadItemValidation();
const bulk = useBulkUploadOperations(remoteFileItems, effectiveExtensions);
const { isReadyToUpload } = useUploadReadyState(hasItems, collectionState);
watch(isReadyToUpload, (ready) => emit("ready", ready), { immediate: true });
const filesOnCurrentPage = computed(() => browserItems.value.filter((item) => item.isLeaf));
const allFilesSelected = computed(() => {
selectionCount.value;
const files = filesOnCurrentPage.value;
return files.length > 0 && files.every((file) => isSelected(file));
});
const someFilesSelected = computed(() => {
selectionCount.value;
const files = filesOnCurrentPage.value;
const selectedCount = files.filter((file) => isSelected(file)).length;
return selectedCount > 0 && selectedCount < files.length;
});
function toggleSelectAll() {
const files = filesOnCurrentPage.value;
const allSelected = files.every((file) => isSelected(file));
files.forEach((file) => {
const needsToggle = allSelected ? isSelected(file) : !isSelected(file);
if (needsToggle) {
selectionModel.value.add(file);
}
});
selectionCount.value = selectionModel.value.count();
}
function entryToSelectionItem(entry: RemoteEntry): SelectionItem {
return {
id: entry.uri,
label: entry.name,
url: entry.uri,
isLeaf: entry.class === "File",
details: "No details available",
entry: entry,
};
}
/**
* Comparator for sorting file sources.
* User-created sources come first, then alphabetical by label.
*/
function sortFileSources(a: SelectionItem, b: SelectionItem): number {
const aIsUser = a.url.startsWith(USER_FILE_PREFIX);
const bIsUser = b.url.startsWith(USER_FILE_PREFIX);
if (aIsUser && !bIsUser) {
return -1;
}
if (!aIsUser && bIsUser) {
return 1;
}
return a.label.localeCompare(b.label);
}
/**
* Apply client-side search filter to items
*/
function filterItemsBySearch(items: SelectionItem[]): SelectionItem[] {
if (!searchQuery.value) {
return items;
}
const query = searchQuery.value.toLowerCase();
return items.filter((item) => item.label.toLowerCase().includes(query));
}
/**
* Apply client-side pagination to items
*/
function paginateItems(items: SelectionItem[]): SelectionItem[] {
const start = (currentPage.value - 1) * perPage.value;
const end = start + perPage.value;
return items.slice(start, end);
}
/**
* Update browser items with client-side filtering and pagination
*/
function updateClientSideView() {
const filteredItems = filterItemsBySearch(allFetchedItems.value);
browserItems.value = paginateItems(filteredItems);
totalMatches.value = filteredItems.length;
}
async function loadFileSources() {
await executeIfLatest(
() => fetchFileSources(),
(sources) => {
let items = sources.map(fileSourcePluginToItem);
items = items.sort(sortFileSources);
// Apply search filter if present
if (searchQuery.value) {
const query = searchQuery.value.toLowerCase();
items = items.filter((item) => item.label.toLowerCase().includes(query));
}
browserItems.value = items;
},
);
}
async function loadDirectory(uri: string) {
const hasServerPagination = supportsServerPagination.value;
const hasServerSearch = supportsServerSearch.value;
// Only pass pagination/search params if the file source supports them
const limit = hasServerPagination ? perPage.value : undefined;
const offset = hasServerPagination ? (currentPage.value - 1) * perPage.value : undefined;
const query = hasServerSearch ? searchQuery.value || undefined : undefined;
await executeIfLatest(
() => browseRemoteFiles(uri, false, false, limit, offset, query),
(result) => {
const allEntries = result.entries.map(entryToSelectionItem);
if (hasServerPagination) {
// Server handles pagination and search
browserItems.value = allEntries;
totalMatches.value = result.totalMatches;
} else {
// Client-side filtering and pagination
allFetchedItems.value = allEntries;
updateClientSideView();
}
},
(error) => {
browserItems.value = [];
allFetchedItems.value = [];
totalMatches.value = 0;
errorMessage.value = errorMessageAsString(error);
},
);
}
async function load() {
// Bump sequence id so any in-flight requests are considered stale
loadSequenceId.value += 1;
if (urlTracker.isAtRoot.value) {
allFetchedItems.value = [];
await loadFileSources();
} else if (urlTracker.current.value) {
await loadDirectory(urlTracker.current.value.url);
}
}
function onItemClick(item: SelectionItem) {
// Don't allow navigation or selection while loading or if there's an error
if (isBusy.value || errorMessage.value) {
return;
}
if (!item.isLeaf) {
// Navigate into directory
open(item);
} else {
// Toggle file selection
selectionModel.value.add(item);
selectionCount.value = selectionModel.value.count();
}
}
function onRowClick(event: { item: SelectionItem }) {
onItemClick(event.item);
}
function open(item: SelectionItem) {
urlTracker.forward(item);
currentPage.value = 1;
clearSearch();
load();
}
function navigateToBreadcrumb(index: number) {
// Navigate to a specific breadcrumb by resetting navigation to that point
if (index === -1) {
// Navigate to root
urlTracker.reset();
} else {
// Navigate to specific index in history
const targetDepth = index + 1;
const currentDepth = urlTracker.navigationHistory.value.length;
const stepsBack = currentDepth - targetDepth;
for (let i = 0; i < stepsBack; i++) {
urlTracker.backward();
}
}
currentPage.value = 1;
clearSearch();
load();
}
function toggleFileSelection(item: SelectionItem) {
if (item.isLeaf) {
selectionModel.value.add(item);
selectionCount.value = selectionModel.value.count();
}
}
function isSelected(item: SelectionItem): boolean {
return selectionModel.value.exists(item.id);
}
function addSelectedFiles() {
let selectedItems = selectionToArray(selectionModel.value.finalize());
if (isSingleMode.value) {
selectedItems = selectedItems.slice(0, 1);
remoteFileItems.value = [];
}
// Filter out any items that already exist in remoteFileItems
const existingUrls = new Set(remoteFileItems.value.map((item) => item.url));
const newItems = selectedItems.filter((item) => !existingUrls.has(item.url));
// Add new items
for (const item of newItems) {
remoteFileItems.value.push(createRemoteFileItem(nextId++, item));
}
// Clear selection and switch to table view
selectionModel.value = new Model({ multiple: !isSingleMode.value });
selectionCount.value = 0;
showBrowser.value = false;
scrollToBottom();
}
function showFileList() {
showBrowser.value = false;
}
function showFileBrowser() {
showBrowser.value = true;
}
function scrollToBottom() {
nextTick(() => {
if (tableContainerRef.value) {
const container = tableContainerRef.value;
container.scrollTop = container.scrollHeight;
}
});
}
function removeItem(id: number) {
remoteFileItems.value = remoteFileItems.value.filter((item) => item.id !== id);
if (remoteFileItems.value.length === 0) {
showBrowser.value = true;
resetCollection();
}
}
function createNewFileSource() {
router.push("/file_source_instances/create");
}
// Browser table fields
const browserFields: TableField[] = [
{
key: "select",
label: "",
width: "40px",
align: "center",
},
{
key: "user",
label: "",
sortable: false,
width: "35px",
align: "center",
},
{
key: "name",
label: "Name",
sortable: false,
align: "center",
},
{
key: "details",
label: "Details",
sortable: false,
align: "left",
},
];
// File list table fields
const tableFields: TableField[] = [
{
key: "name",
label: "Name",
sortable: true,
width: "200px",
align: "center",
class: "file-name-cell",
},
{
key: "size",
label: "Size",
sortable: true,
width: "80px",
align: "center",
class: "size-column",
},
{
key: "url",
label: "URI",
sortable: false,
align: "center",
class: "uri-column",
},
{
key: "extension",
label: "Type",
sortable: false,
width: "180px",
align: "center",
},
{
key: "dbKey",
label: "Reference",
sortable: false,
width: "200px",
align: "center",
},
{
key: "options",
label: "Upload Settings",
sortable: false,
align: "center",
},
{
key: "actions",
label: "",
sortable: false,
width: "50px",
align: "center",
},
];
function reset() {
remoteFileItems.value = [];
resetCollection();
selectionModel.value = new Model({ multiple: !isSingleMode.value });
selectionCount.value = 0;
allFetchedItems.value = [];
clearSearch();
urlTracker.reset();
currentPage.value = 1;
load();
showBrowser.value = true;
clearStaging();
}
function clearSearch() {
searchQuery.value = "";
}
function updateSearchQuery(newQuery: string) {
searchQuery.value = newQuery;
}
function prepareUpload(): PreparedUpload | null {
if (remoteFileItems.value.length === 0) {
return null;
}
const uploads = remoteFileItems.value.map((item) => mapToRemoteFileUpload(item, props.targetHistoryId));
return buildPreparedUpload(uploads, buildCollectionConfig(props.targetHistoryId));
}
onMounted(() => {
load();
});
watch(searchQuery, () => {
currentPage.value = 1;
if (urlTracker.isAtRoot.value || supportsServerSearch.value) {
load();
} else if (allFetchedItems.value.length > 0) {
updateClientSideView();
}
});
watch(currentPage, () => {
if (urlTracker.isAtRoot.value) {
return;
}
if (supportsServerPagination.value) {
load();
} else if (allFetchedItems.value.length > 0) {
updateClientSideView();
}
});
function onErrorRetry() {
errorMessage.value = undefined;
currentPage.value = 1;
allFetchedItems.value = [];
clearSearch();
load();
}
function getItemEntry(item: SelectionItem): RemoteEntry {
return item.entry as RemoteEntry;
}
defineExpose<UploadMethodComponent>({ prepareUpload, reset });
</script>
<template>
<div class="remote-files-upload">
<!-- File Browser Phase -->
<div v-if="showBrowser" class="file-browser">
<!-- Navigation breadcrumb -->
<div class="browser-header mb-2">
<BreadcrumbNavigation
v-if="!urlTracker.isAtRoot.value"
:items="breadcrumbs"
@navigate="navigateToBreadcrumb" />
<div v-else>
<span class="font-weight-bold">Browse a File Source below</span> or
<GButton color="grey" size="small" @click="createNewFileSource">
<FontAwesomeIcon :icon="faPlus" class="mr-1" />
Connect New Remote Source
</GButton>
</div>
</div>
<!-- Search bar -->
<div class="search-bar-container mb-2">
<DataDialogSearch
:value="searchQuery"
:title="urlTracker.isAtRoot.value ? 'file sources' : 'files and folders'"
@input="updateSearchQuery" />
</div>
<!-- Error message -->
<BAlert v-if="errorMessage" variant="danger" show dismissible @dismissed="errorMessage = undefined">
<div class="d-flex justify-content-between align-items-center">
<span>{{ errorMessage }}</span>
<GButton color="red" class="ml-2" @click="onErrorRetry"> Retry </GButton>
</div>
</BAlert>
<!-- Browser table -->
<div class="browser-table-container">
<GTable
v-if="!errorMessage && (browserItems.length > 0 || isBusy)"
:items="browserItems"
:fields="browserFields"
:overlay-loading="isBusy"
hover
striped
clickable-rows
compact
fixed
class="browser-table"
@row-click="onRowClick">
<!-- Select column header (select all) -->
<template v-slot:head(select)>
<BFormCheckbox
v-if="
props.multiple !== false && !urlTracker.isAtRoot.value && filesOnCurrentPage.length > 0
"
data-test-id="remote-files-select-all"
:checked="allFilesSelected"
:indeterminate="someFilesSelected"
@change="toggleSelectAll"
@click.stop />
</template>
<!-- Select column (only for files) -->
<template v-slot:cell(select)="{ item }">
<BFormCheckbox
v-if="item.isLeaf"
data-test-id="remote-files-browser-item-checkbox"
:data-label="item.label"
:checked="isSelected(item)"
@change="toggleFileSelection(item)"
@click.stop />
</template>
<!-- Icon column (for highlighting user-created file sources) -->
<template v-slot:cell(user)="{ item }">
<span
v-if="urlTracker.isAtRoot.value && !item.isLeaf && item.url.startsWith(USER_FILE_PREFIX)"
v-g-tooltip.hover.noninteractive
title="You created this file source">
<FontAwesomeIcon :icon="faUser" class="text-primary" fixed-width />
</span>
<span
v-else-if="urlTracker.isAtRoot.value && !item.isLeaf"
v-g-tooltip.hover.noninteractive
title="This file source was created by an administrator and is globally available">
<FontAwesomeIcon :icon="faGlobe" class="text-primary" fixed-width />
</span>
</template>
<!-- Name column with icons -->
<template v-slot:cell(name)="{ item }">
<div class="d-flex align-items-center" :class="{ 'cursor-pointer': !item.isLeaf }">
<FontAwesomeIcon
v-if="!item.isLeaf"
:icon="faFolder"
class="mr-2 text-warning"
fixed-width />
<span
data-test-id="remote-files-browser-label"
:data-label="item.label"
:data-entry-kind="item.isLeaf ? 'file' : 'directory'">
{{ item.label }}
</span>
</div>
</template>
<!-- Details column -->
<template v-slot:cell(details)="{ item }">
<RemoteEntryMetadata v-if="item.isLeaf && getItemEntry(item)" :entry="getItemEntry(item)" />
<span v-else-if="urlTracker.isAtRoot && item.details">
{{ item.details }}
</span>
</template>
<!-- Loading slot -->
</GTable>
<!-- Empty state message when no items are available -->
<div v-else-if="!errorMessage && !isBusy" class="text-center text-muted my-5">
<p v-if="searchQuery" class="lead">
No {{ urlTracker.isAtRoot.value ? "file sources" : "files or folders" }} match your search "{{
searchQuery
}}"
</p>
<p v-else-if="urlTracker.isAtRoot.value" class="lead">
No file sources available. Connect a new remote source to get started.
</p>
<p v-else class="lead">This directory is empty.</p>
</div>
</div>
<!-- Pagination -->
<div v-if="hasPagination" class="mt-2">
<BPagination
v-model="currentPage"
:total-rows="totalMatches"
:per-page="perPage"
align="center"
size="sm" />
</div>
<!-- Action buttons -->
<div class="browser-actions mt-3">
<GButton v-if="hasItems && !hasSelection" color="grey" outline @click="showFileList">
View Selected Files ({{ remoteFileItems.length }})
</GButton>
<GButton
v-if="!urlTracker.isAtRoot.value"
color="blue"
:disabled="!hasSelection"
class="ml-auto"
data-test-id="remote-files-add-selected"
@click="addSelectedFiles">
<FontAwesomeIcon :icon="faPlus" class="mr-1" />
Add Selected Files ({{ selectionCount }})
</GButton>
</div>
</div>
<!-- File List Phase -->
<div v-else class="file-list">
<div class="file-list-header mb-2">
<div class="d-flex justify-content-between align-items-center">
<span class="font-weight-bold">{{ remoteFileItems.length }} file(s) selected</span>
</div>
</div>
<div ref="tableContainerRef" class="file-table-container">
<GTable :items="remoteFileItems" :fields="tableFields" hover striped table-class="table-sm file-table">
<!-- Name column -->
<template v-slot:cell(name)="{ item }">
<UploadTableNameCell
:value="item.name"
:state="isNameValid(item.name)"
@input="item.name = $event"
@blur="restoreOriginalName(item, item.name)" />
</template>
<!-- Size column -->
<template v-slot:cell(size)="{ item }">
{{ bytesToString(item.size) }}
</template>
<!-- URL column (read-only) -->
<template v-slot:cell(url)="{ item }">
<div class="d-flex align-items-center">
<BFormInput :value="item.url" size="sm" readonly class="uri-input" />
</div>
</template>
<!-- Extension column with bulk operations -->
<template v-slot:head(extension)>
<UploadTableBulkExtensionHeader
:value="bulk.bulkExtension.value"
:extensions="effectiveExtensions"
:warning="bulk.bulkExtensionWarning.value"
:disabled="!configurationsReady"
tooltip="Set file format for all files"
@input="bulk.setAllExtensions" />
</template>
<template v-slot:cell(extension)="{ item }">
<UploadTableExtensionCell
:value="item.extension"
:extensions="effectiveExtensions"
:warning="bulk.getExtensionWarning(item.extension)"
:disabled="!configurationsReady"
@input="item.extension = $event" />
</template>
<!-- DbKey column with bulk operations -->
<template v-slot:head(dbKey)>
<UploadTableBulkDbKeyHeader
:value="bulk.bulkDbKey.value"
:db-keys="listDbKeys"
:disabled="!configurationsReady"
tooltip="Set database key for all files"
@input="bulk.setAllDbKeys" />
</template>
<template v-slot:cell(dbKey)="{ item }">
<UploadTableDbKeyCell
:value="item.dbkey"
:db-keys="listDbKeys"
:disabled="!configurationsReady"
@input="item.dbkey = $event" />
</template>
<!-- Options column with bulk checkboxes -->
<template v-slot:head(options)>
<UploadTableOptionsHeader
:all-space-to-tab="bulk.allSpaceToTab.value"
:space-to-tab-indeterminate="bulk.spaceToTabIndeterminate.value"
:show-posix="advancedMode"
:all-to-posix-lines="bulk.allToPosixLines.value"
:to-posix-lines-indeterminate="bulk.toPosixLinesIndeterminate.value"
:show-deferred="true"
:all-deferred="bulk.allDeferred.value"
:deferred-indeterminate="bulk.deferredIndeterminate.value"
@toggle-space-to-tab="bulk.toggleAllSpaceToTab"
@toggle-to-posix-lines="bulk.toggleAllToPosixLines"
@toggle-deferred="bulk.toggleAllDeferred" />
</template>
<template v-slot:cell(options)="{ item }">
<UploadTableOptionsCell
:space-to-tab="item.spaceToTab"
:show-posix="advancedMode"
:to-posix-lines="item.toPosixLines"
:show-deferred="true"
:deferred="item.deferred"
@updateSpaceToTab="item.spaceToTab = $event"
@updateToPosixLines="item.toPosixLines = $event"
@updateDeferred="item.deferred = $event" />
</template>
<!-- Actions column -->
<template v-slot:cell(actions)="{ item }">
<button
v-g-tooltip.hover
class="btn btn-link text-danger remove-btn"
title="Remove file from list"
@click="removeItem(item.id)">
<FontAwesomeIcon :icon="faTimes" />
</button>
</template>
</GTable>
</div>
<!-- Collection Creation Section -->
<CollectionCreationConfig
v-if="props.allowCollections !== false"
ref="collectionConfigComponent"
:files="remoteFileItems"
@update:state="handleCollectionStateChange" />
<div class="file-list-actions mt-2">
<GButton
color="grey"
tooltip
tooltip-placement="top"
:title="addMoreFilesTitle"
@click="showFileBrowser">
<FontAwesomeIcon :icon="faPlus" class="mr-1" />
{{ addMoreFilesLabel }}
</GButton>
<GButton
outline
color="grey"
tooltip
tooltip-placement="top"
title="Remove all files from the upload list"
@click="reset">
Clear All
</GButton>
</div>
</div>
</div>
</template>
<style scoped lang="scss">
@import "@/style/scss/theme/blue.scss";
@import "../shared/upload-table-shared.scss";
.remote-files-upload {
height: 100%;
display: flex;
flex-direction: column;
overflow: hidden;
}
.file-browser {
flex: 1;
display: flex;
flex-direction: column;
overflow: hidden;
min-height: 0;
}
.browser-header {
flex-shrink: 0;
@include upload-list-header;
}
.search-bar-container {
flex-shrink: 0;
}
.browser-table-container {
flex: 1;
overflow: auto;
min-height: 0;
:deep(.browser-table thead) {
@include upload-table-header;
}
:deep(tbody tr) {
cursor: pointer;
&:hover {
background-color: rgba($brand-primary, 0.05);
}
}
}
.browser-actions {
flex-shrink: 0;
display: flex;
gap: 0.5rem;
padding-top: 1rem;
border-top: 1px solid $border-color;
}
.file-list {
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
overflow: hidden;
min-height: 0;
}
.file-list-header {
@include upload-list-header;
}
.file-table-container {
@include upload-table-container;
:deep(.file-table thead) {
@include upload-table-header;
}
:deep(.file-name-cell) {
min-width: 200px;
}
:deep(.uri-column) {
width: 100%;
max-width: 400px;
overflow: hidden;
.uri-input {
font-family: monospace;
font-size: 0.85rem;
background-color: $gray-200;
}
}
}
.file-list-actions {
@include upload-list-actions;