-
-
Notifications
You must be signed in to change notification settings - Fork 625
Expand file tree
/
Copy pathSelector.vue
More file actions
212 lines (192 loc) · 7.33 KB
/
Selector.vue
File metadata and controls
212 lines (192 loc) · 7.33 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
<template>
<Uploader
ref="uploader"
:container="container.id"
:path="currentPath"
:enabled="container.can_upload"
@updated="(uploads) => $refs.browser?.uploadsUpdated(uploads)"
@upload-complete="(asset) => $refs.browser?.uploadCompleted(asset)"
@error="(upload, uploads) => $refs.browser?.uploadError(upload, uploads)"
v-slot="{ dragging }"
>
<div class="relative h-full">
<div class="drag-notification" v-show="dragging">
<Icon name="upload-cloud-large" class="m-4 size-13" />
<span>{{ __('Drop File to Upload') }}</span>
</div>
<div class="flex h-full min-h-0 flex-col">
<div class="flex flex-1 flex-col gap-4 overflow-auto p-4">
<AssetBrowser
ref="browser"
:container="container"
:initial-per-page="$config.get('paginationSize')"
:initial-columns="columns"
:selected-path="folder"
:selected-assets="browserSelections"
:restrict-folder-navigation="restrictFolderNavigation"
:max-files="maxFiles"
:query-scopes="queryScopes"
:autoselect-uploads="true"
:uploader="uploaderInstance"
allow-selecting-existing-upload
:allow-bulk-actions="false"
@selections-updated="selectionsUpdated"
@edit-asset="toggleAssetSelection"
@initialized="focusSearchInput"
@path-changed="currentPath = $event"
>
<template #initializing>
<div class="flex flex-1">
<div class="absolute inset-0 z-200 flex items-center justify-center text-center">
<Icon name="loading" />
</div>
</div>
</template>
<template #header="{ canUpload, openFileBrowser, canCreateFolders, startCreatingFolder, mode, modeChanged }">
<div class="flex items-center gap-2 sm:gap-3 mb-4">
<div class="flex flex-1 items-center gap-2 sm:gap-3">
<Search ref="search" />
</div>
<Button v-if="canUpload" :text="__('Upload')" icon="upload" @click="openFileBrowser" />
<Button v-if="canCreateFolders" :text="__('Create Folder')" icon="folder-add" @click="startCreatingFolder" />
<ToggleGroup :model-value="mode" @update:model-value="modeChanged">
<ToggleItem icon="layout-grid" value="grid" />
<ToggleItem icon="layout-list" value="table" />
</ToggleGroup>
</div>
</template>
</AssetBrowser>
</div>
<div class="flex items-center justify-between border-t bg-gray-100 dark:bg-gray-850 dark:border-gray-700 px-4 py-2 sm:p-4">
<div
class="dark:text-gray-200 text-sm text-gray-700"
v-text="
hasMaxFiles
? __n(':count/:max selected', browserSelections, { max: maxFiles })
: __n(':count asset selected|:count assets selected', browserSelections)
"
/>
<div class="flex items-center space-x-3">
<Button variant="ghost" @click="close">
{{ __('Cancel') }}
</Button>
<Button variant="primary" @click="select">
{{ __('Select') }}
</Button>
</div>
</div>
</div>
</div>
</Uploader>
</template>
<script>
import AssetBrowser from './Browser/Browser.vue'
import Uploader from './Uploader.vue'
import {
Button,
ToggleGroup,
ToggleItem,
ListingTable as Table,
ListingSearch as Search,
ListingPagination as Pagination,
Panel,
PanelFooter,
ListingPagination, Slider, PanelHeader,
Icon,
} from '@/components/ui';
import HasPreferences from '@/components/data-list/HasPreferences.js';
import Breadcrumbs from '@/components/assets/Browser/Breadcrumbs.vue';
import Grid from '@/components/assets/Browser/Grid.vue';
import Uploads from '@/components/assets/Uploads.vue';
export default {
mixins: [HasPreferences],
components: {
Uploads,
Uploader,
PanelHeader, Grid,
Slider,
ListingPagination, Breadcrumbs,
AssetBrowser,
Button,
ToggleGroup,
ToggleItem,
Table,
Search,
Pagination,
Panel,
PanelFooter,
Icon,
},
props: {
container: Object,
folder: String,
selected: Array,
maxFiles: Number,
queryScopes: Array,
columns: Array,
restrictFolderNavigation: {
type: Boolean,
default() {
return false;
},
},
},
data() {
return {
// We will initialize the browser component with the selections, but not pass in the selections directly.
// We only want selection changes to be reflected in the fieldtype once the user is ready to commit
// them. They should be able to cancel at any time and have their updated selections discarded.
browserSelections: this.selected,
currentPath: this.folder,
uploaderInstance: null,
};
},
mounted() {
this.uploaderInstance = this.$refs.uploader;
},
computed: {
hasMaxFiles() {
return this.maxFiles === Infinity ? false : Boolean(this.maxFiles);
},
},
watch: {
browserSelections: {
deep: true,
handler: function (selections) {
if (this.maxFiles === 1 && selections.length === 1) {
this.select();
}
}
},
},
methods: {
/**
* Confirm the updated selections
*/
select() {
this.$emit('selected', this.browserSelections);
this.close();
},
/**
* Close this selector
*/
close() {
this.$emit('closed');
},
/**
* Selections have been updated within the browser component.
*/
selectionsUpdated(selections) {
this.browserSelections = selections;
},
toggleAssetSelection(asset) {
this.browserSelections = this.browserSelections.includes(asset.id)
? this.browserSelections.filter(id => id !== asset.id)
: [...this.browserSelections, asset.id];
},
focusSearchInput() {
this.$nextTick(() => this.$refs.search.focus());
},
},
};
</script>