Files
mixtape/zero.Backoffice.UI/old_app/components/pickers/mediaPicker/overlay.vue
T

297 lines
6.8 KiB
Vue
Raw Normal View History

2020-05-14 16:05:33 +02:00
<template>
2020-05-15 14:23:47 +02:00
<ui-form ref="form" class="ui-mediapicker-overlay" v-slot="form">
<h2 class="ui-headline">Select or upload media</h2>
<ui-search class="ui-mediapicker-overlay-search" v-model="query" />
<nav class="ui-mediapicker-overlay-hierarchy">
2020-06-02 12:52:58 +02:00
<button type="button" class="ui-mediapicker-overlay-hierarchy-item" @click="selectFolder(null)"><i class="fth-home"></i></button>
2020-09-03 14:59:20 +02:00
<button type="button" v-for="item in hierarchy" class="ui-mediapicker-overlay-hierarchy-item" @click="selectFolder(item.id)" v-localize="item.name"></button>
2020-05-15 14:23:47 +02:00
<button type="button" class="ui-mediapicker-overlay-hierarchy-item" @click="addFolder"><i class="fth-plus"></i></button>
</nav>
<div class="ui-mediapicker-overlay-items">
2020-06-02 13:36:33 +02:00
<div v-if="folderId" class="ui-mediapicker-overlay-item is-upload">
<input class="ui-mediapicker-overlay-upload" type="file" multiple @change="onUpload" />
2020-05-15 14:23:47 +02:00
<span class="-preview"><i class="fth-plus"></i></span>
<p class="ui-mediapicker-overlay-item-text">
Upload media
</p>
2020-06-02 13:36:33 +02:00
</div>
2020-05-15 14:23:47 +02:00
<button type="button" v-for="item in items" class="ui-mediapicker-overlay-item" @click="select(item)">
2020-09-03 14:59:20 +02:00
<img class="-preview" v-if="item.image" :src="item.image" />
<span class="-preview" v-if="!item.image"><i :class="item.isFolder ? 'fth-folder' : 'fth-file'"></i></span>
2020-05-15 14:23:47 +02:00
<p class="ui-mediapicker-overlay-item-text">
{{item.name}}
2020-06-02 12:52:58 +02:00
<span class="-minor" v-if="item.size"><br><span v-filesize="item.size"></span></span>
2020-05-15 14:23:47 +02:00
</p>
</button>
</div>
2020-05-14 16:05:33 +02:00
<!--<div class="app-confirm-buttons">
<ui-button v-if="!disabled" type="light" :submit="true" :state="form.state" label="@ui.save"></ui-button>
<ui-button type="light" :label="config.closeLabel" :disabled="loading" @click="config.close"></ui-button>
</div>-->
</ui-form>
</template>
<script>
2020-11-20 15:17:41 +01:00
import MediaApi from 'zero/api/media.js'
import MediaFolderApi from 'zero/api/media-folder.js';
import Overlay from 'zero/helpers/overlay.js'
2020-11-01 22:20:29 +01:00
import AddFolderOverlay from 'zero/pages/media/overlays/folder.vue'
import UploadStatusOverlay from 'zero/pages/media/overlays/upload-status.vue'
2020-06-02 13:15:41 +02:00
import { debounce as _debounce, filter as _filter } from 'underscore'
2020-05-14 16:05:33 +02:00
export default {
props: {
model: String,
config: Object
},
data: () => ({
2020-06-02 12:52:58 +02:00
folderId: null,
2020-05-14 16:05:33 +02:00
icon: null,
query: '',
2020-05-15 14:23:47 +02:00
items: [],
2020-06-02 12:52:58 +02:00
hierarchy: []
2020-05-14 16:05:33 +02:00
}),
watch: {
2020-06-02 12:52:58 +02:00
'config.folderId': function (id)
{
this.folderId = id;
},
2020-05-14 16:05:33 +02:00
model()
{
2020-05-15 14:23:47 +02:00
//this.init();
2020-05-14 16:05:33 +02:00
},
query()
{
this.debouncedSearch();
}
},
created()
{
2020-06-02 12:52:58 +02:00
this.folderId = this.config.folderId;
2020-05-14 16:05:33 +02:00
this.debouncedSearch = _debounce(this.search, 100);
2020-05-15 14:23:47 +02:00
//this.items = this.config.items;
//this.init();
2020-06-02 12:52:58 +02:00
//this.gridConfig = {
// search: null,
// width: 160,
// component: MediaItem,
// items: this.getItems
//};
2020-05-14 16:05:33 +02:00
},
mounted()
{
2020-06-02 12:52:58 +02:00
this.getItems();
2020-05-14 16:05:33 +02:00
},
methods: {
2020-06-02 12:52:58 +02:00
// get items (media + subfolders) in the current folder
getItems(query)
{
if (!query)
{
query = {};
}
query.folderId = this.folderId;
2020-12-10 01:03:22 +01:00
query.pageSize = 100;
2020-06-02 12:52:58 +02:00
2020-09-03 14:59:20 +02:00
this.getFolderHierarchy(query.folderId);
return MediaApi.getListByQuery(query).then(response =>
2020-06-02 12:52:58 +02:00
{
2020-09-03 14:59:20 +02:00
this.items = response.items;
2020-06-02 12:52:58 +02:00
});
},
2020-09-03 14:59:20 +02:00
getFolderHierarchy(id)
2020-06-02 12:52:58 +02:00
{
2020-09-03 14:59:20 +02:00
MediaFolderApi.getHierarchy(id).then(res =>
2020-06-02 12:52:58 +02:00
{
2020-09-03 14:59:20 +02:00
this.hierarchy = res;
this.current = res[res.length - 1];
});
2020-06-02 12:52:58 +02:00
},
2020-05-15 14:23:47 +02:00
// switches view to the selected folder
selectFolder(id)
2020-05-14 16:05:33 +02:00
{
2020-06-02 12:52:58 +02:00
this.folderId = id;
this.getItems();
2020-05-14 16:05:33 +02:00
},
2020-05-15 14:23:47 +02:00
// adds a new folder within the current parent
addFolder()
{
2020-06-02 13:15:41 +02:00
Overlay.open({
component: AddFolderOverlay,
model: { parentId: this.folderId },
theme: 'dark'
2020-06-02 13:36:33 +02:00
}).then(() => { }, () =>
2020-06-02 13:15:41 +02:00
{
setTimeout(() =>
{
this.selectFolder(item.model.id);
}, 1000);
2020-06-02 13:36:33 +02:00
});
2020-05-15 14:23:47 +02:00
},
// uploads a new media item within the current parent
2020-06-02 13:36:33 +02:00
onUpload(event)
2020-05-15 14:23:47 +02:00
{
2020-06-02 13:36:33 +02:00
let options = {
title: 'Upload status',
closeLabel: '@ui.close',
component: UploadStatusOverlay,
isCreate: true,
model: event.target.files,
folderId: this.folderId,
theme: 'dark',
width: 520
};
return Overlay.open(options).then(value =>
{
setTimeout(() =>
{
this.getItems();
}, 500);
}, () => { });
2020-05-15 14:23:47 +02:00
},
// select an item, this can either be a folder or a media item
2020-05-14 16:05:33 +02:00
select(item)
{
2020-09-03 14:59:20 +02:00
if (item.isFolder)
2020-05-14 16:05:33 +02:00
{
2020-05-15 14:23:47 +02:00
return this.selectFolder(item.id);
2020-05-14 16:05:33 +02:00
}
2020-06-02 13:36:33 +02:00
else
{
this.config.confirm(item, this.config);
}
2020-05-14 16:05:33 +02:00
}
}
}
</script>
<style lang="scss">
2020-05-15 14:23:47 +02:00
.ui-mediapicker-overlay
2020-05-14 16:05:33 +02:00
{
2020-05-15 14:23:47 +02:00
text-align: left;
2020-05-14 16:05:33 +02:00
}
2020-05-15 14:23:47 +02:00
.ui-mediapicker-overlay-search.ui-searchinput .ui-input
2020-05-14 16:05:33 +02:00
{
2020-05-15 14:23:47 +02:00
margin-top: 25px;
}
.ui-mediapicker-overlay-hierarchy
{
text-align: left;
margin-top: 20px;
}
.ui-mediapicker-overlay-hierarchy-item
{
line-height: 1.4;
& + .ui-mediapicker-overlay-hierarchy-item:before
{
content: '/';
margin: 0 0.5em;
color: var(--color-text-dim);
2020-05-15 14:23:47 +02:00
}
}
.ui-mediapicker-overlay-items
{
margin-top: 25px;
max-height: 495px;
overflow-y: auto;
}
.ui-mediapicker-overlay-item
{
width: 100%;
height: 70px;
2020-05-14 16:05:33 +02:00
display: grid;
2020-05-15 14:23:47 +02:00
grid-template-columns: 70px 1fr;
gap: 15px;
2020-05-14 16:05:33 +02:00
align-items: center;
2020-05-15 14:23:47 +02:00
line-height: 1.4;
2020-05-14 16:05:33 +02:00
2020-05-15 14:23:47 +02:00
& + .ui-mediapicker-overlay-item
2020-05-14 16:05:33 +02:00
{
2020-05-15 14:23:47 +02:00
margin-top: 15px;
}
2020-05-14 16:05:33 +02:00
2020-05-15 14:23:47 +02:00
.-preview
{
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
height: 70px;
width: 70px;
object-fit: cover;
background: var(--color-box-nested);
2020-05-15 14:23:47 +02:00
border-radius: var(--radius);
position: relative;
text-align: center;
2020-09-03 14:59:20 +02:00
font-size: 20px;
2020-05-15 14:23:47 +02:00
}
2020-06-02 13:36:33 +02:00
&.is-upload
{
position: relative;
}
2020-05-15 14:23:47 +02:00
.-extension
{
font-size: 12px;
font-style: normal;
margin-top: 8px;
}
.-minor
{
color: var(--color-text-dim);
2020-05-15 14:23:47 +02:00
font-size: var(--font-size-s);
2020-05-14 16:05:33 +02:00
}
}
2020-05-15 14:23:47 +02:00
.ui-mediapicker-overlay-item-text
2020-05-14 16:05:33 +02:00
{
2020-05-15 14:23:47 +02:00
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
margin: 0;
2020-05-14 16:05:33 +02:00
}
2020-06-02 13:36:33 +02:00
input[type="file"].ui-mediapicker-overlay-upload
{
position: absolute;
height: 100%;
top: 0;
left: 0;
width: 100%;
z-index: 1;
bottom: 0;
opacity: 0.001;
cursor: pointer;
}
2020-05-14 16:05:33 +02:00
</style>