2019-03-20 04:37:33 +00:00
|
|
|
<template lang='pug'>
|
|
|
|
v-card.editor-modal-media.animated.fadeInLeft(flat, tile)
|
|
|
|
v-container.pa-3(grid-list-lg, fluid)
|
|
|
|
v-layout(row, wrap)
|
2019-06-22 16:44:32 +00:00
|
|
|
v-flex(xs12, lg9)
|
2019-08-10 16:18:14 +00:00
|
|
|
v-card.radius-7.animated.fadeInLeft.wait-p1s(:light='!$vuetify.theme.dark', :dark='$vuetify.theme.dark')
|
2019-03-20 04:37:33 +00:00
|
|
|
v-card-text
|
2019-04-07 22:10:44 +00:00
|
|
|
.d-flex
|
2019-08-10 16:18:14 +00:00
|
|
|
v-toolbar.radius-7(:color='$vuetify.theme.dark ? `teal` : `teal lighten-5`', dense, flat, height='44')
|
|
|
|
.body-2(:class='$vuetify.theme.dark ? `white--text` : `teal--text`') {{$t('editor:assets.title')}}
|
2019-06-01 05:34:16 +00:00
|
|
|
v-spacer
|
2019-08-25 18:23:56 +00:00
|
|
|
v-btn(text, icon, @click='refresh')
|
2019-08-10 16:18:14 +00:00
|
|
|
v-icon(:color='$vuetify.theme.dark ? `white` : `teal`') mdi-refresh
|
2019-05-19 18:46:08 +00:00
|
|
|
v-dialog(v-model='newFolderDialog', max-width='550')
|
2019-08-04 02:51:29 +00:00
|
|
|
template(v-slot:activator='{ on }')
|
|
|
|
v-btn.ml-3.my-0.mr-0.radius-7(outlined, large, color='teal', :icon='$vuetify.breakpoint.xsOnly', v-on='on')
|
|
|
|
v-icon(:left='$vuetify.breakpoint.mdAndUp') mdi-plus
|
2019-08-10 16:18:14 +00:00
|
|
|
span.hidden-sm-and-down(:class='$vuetify.theme.dark ? `teal--text text--lighten-3` : ``') {{$t('editor:assets.newFolder')}}
|
2019-08-04 02:51:29 +00:00
|
|
|
v-card
|
|
|
|
.dialog-header.is-short.subtitle-1 {{$t('editor:assets.newFolder')}}
|
2019-08-25 18:23:56 +00:00
|
|
|
v-card-text.pt-5
|
2019-05-19 18:46:08 +00:00
|
|
|
v-text-field.md2(
|
2019-08-04 02:51:29 +00:00
|
|
|
outlined
|
|
|
|
prepend-icon='mdi-folder-outline'
|
2019-05-19 18:46:08 +00:00
|
|
|
v-model='newFolderName'
|
2019-06-15 21:05:56 +00:00
|
|
|
:label='$t(`editor:assets.folderName`)'
|
2019-05-19 18:46:08 +00:00
|
|
|
counter='255'
|
|
|
|
@keyup.enter='createFolder'
|
|
|
|
@keyup.esc='newFolderDialog = false'
|
|
|
|
ref='folderNameIpt'
|
|
|
|
)
|
2019-06-15 21:05:56 +00:00
|
|
|
i18next.caption.grey--text.text--darken-1.pl-5(path='editor:assets.folderNameNamingRules', tag='div')
|
|
|
|
a(place='namingRules', href='https://docs-beta.requarks.io/guide/assets#naming-restrictions', target='_blank') {{$t('editor:assets.folderNameNamingRulesLink')}}
|
2019-05-19 18:46:08 +00:00
|
|
|
v-card-chin
|
|
|
|
v-spacer
|
2019-08-04 02:51:29 +00:00
|
|
|
v-btn(text, @click='newFolderDialog = false') {{$t('common:actions.cancel')}}
|
|
|
|
v-btn.px-3(color='primary', @click='createFolder', :disabled='!isFolderNameValid', :loading='newFolderLoading') {{$t('common:actions.create')}}
|
2019-08-10 16:18:14 +00:00
|
|
|
v-toolbar(flat, dense, :color='$vuetify.theme.dark ? `grey darken-3` : `white`')
|
2019-06-01 05:34:16 +00:00
|
|
|
template(v-if='folderTree.length > 0')
|
|
|
|
.body-2
|
|
|
|
span.mr-1 /
|
|
|
|
template(v-for='folder of folderTree')
|
|
|
|
span(:key='folder.id') {{folder.name}}
|
|
|
|
span.mx-1 /
|
|
|
|
.body-2(v-else) / #[em root]
|
2019-05-21 20:45:27 +00:00
|
|
|
template(v-if='folders.length > 0 || currentFolderId > 0')
|
2019-08-10 16:18:14 +00:00
|
|
|
v-btn.is-icon.mx-1(:color='$vuetify.theme.dark ? `grey lighten-1` : `grey darken-2`', outlined, :dark='currentFolderId > 0', @click='upFolder()', :disabled='currentFolderId === 0')
|
2019-08-04 02:51:29 +00:00
|
|
|
v-icon mdi-folder-upload
|
2019-06-01 05:34:16 +00:00
|
|
|
v-btn.btn-normalcase.mx-1(v-for='folder of folders', :key='folder.id', depressed, color='grey darken-2', dark, @click='downFolder(folder)')
|
2019-08-04 02:51:29 +00:00
|
|
|
v-icon(left) mdi-folder
|
2019-08-25 18:23:56 +00:00
|
|
|
span.caption(style='text-transform: none;') {{ folder.name }}
|
2019-05-21 20:45:27 +00:00
|
|
|
v-divider.mt-2
|
2019-05-18 06:27:30 +00:00
|
|
|
v-data-table(
|
|
|
|
:items='assets'
|
|
|
|
:headers='headers'
|
2019-08-04 02:51:29 +00:00
|
|
|
:page.sync='pagination'
|
|
|
|
:items-per-page='15'
|
2019-05-18 06:27:30 +00:00
|
|
|
:loading='loading'
|
|
|
|
must-sort,
|
2019-08-04 02:51:29 +00:00
|
|
|
hide-default-footer,
|
|
|
|
dense
|
2019-05-18 06:27:30 +00:00
|
|
|
)
|
2019-08-04 02:51:29 +00:00
|
|
|
template(slot='item', slot-scope='props')
|
2019-05-18 06:27:30 +00:00
|
|
|
tr.is-clickable(
|
|
|
|
@click.left='currentFileId = props.item.id'
|
2019-05-19 18:46:08 +00:00
|
|
|
@click.right.prevent=''
|
2019-08-10 16:18:14 +00:00
|
|
|
:class='currentFileId === props.item.id ? ($vuetify.theme.dark ? `grey darken-3-d5` : `teal lighten-5`) : ``'
|
2019-05-18 06:27:30 +00:00
|
|
|
)
|
2019-09-01 02:10:58 +00:00
|
|
|
td.caption(v-if='$vuetify.breakpoint.smAndUp') {{ props.item.id }}
|
2019-05-18 06:27:30 +00:00
|
|
|
td
|
2019-09-01 02:10:58 +00:00
|
|
|
.body-2: strong(:class='currentFileId === props.item.id ? `teal--text` : ``') {{ props.item.filename }}
|
2019-05-19 18:46:08 +00:00
|
|
|
.caption.grey--text {{ props.item.description }}
|
2019-05-18 06:27:30 +00:00
|
|
|
td.text-xs-center(v-if='$vuetify.breakpoint.lgAndUp')
|
2019-09-01 02:10:58 +00:00
|
|
|
v-chip.ma-0(x-small, :color='$vuetify.theme.dark ? `grey darken-4` : `grey lighten-4`')
|
|
|
|
.overline {{props.item.ext.toUpperCase().substring(1)}}
|
|
|
|
td.caption(v-if='$vuetify.breakpoint.mdAndUp') {{ props.item.fileSize | prettyBytes }}
|
|
|
|
td.caption(v-if='$vuetify.breakpoint.mdAndUp') {{ props.item.createdAt | moment('from') }}
|
2019-05-18 06:27:30 +00:00
|
|
|
td(v-if='$vuetify.breakpoint.smAndUp')
|
2019-08-04 02:51:29 +00:00
|
|
|
v-menu(offset-x, min-width='200')
|
|
|
|
template(v-slot:activator='{ on }')
|
|
|
|
v-btn(icon, v-on='on', tile, small)
|
|
|
|
v-icon(color='grey darken-2') mdi-dots-horizontal
|
|
|
|
v-list(nav, style='border-top: 5px solid #444;')
|
2019-07-29 04:50:03 +00:00
|
|
|
v-list-item(@click='', disabled)
|
2019-08-04 02:51:29 +00:00
|
|
|
v-list-item-avatar(size='24')
|
|
|
|
v-icon(color='teal') mdi-text-short
|
2019-07-29 04:50:03 +00:00
|
|
|
v-list-item-content {{$t('common:actions.properties')}}
|
2019-05-18 06:27:30 +00:00
|
|
|
template(v-if='props.item.kind === `IMAGE`')
|
2019-07-29 04:50:03 +00:00
|
|
|
v-list-item(@click='previewDialog = true', disabled)
|
2019-08-04 02:51:29 +00:00
|
|
|
v-list-item-avatar(size='24')
|
|
|
|
v-icon(color='green') mdi-image-search-outline
|
2019-07-29 04:50:03 +00:00
|
|
|
v-list-item-content {{$t('common:actions.preview')}}
|
|
|
|
v-list-item(@click='', disabled)
|
2019-08-04 02:51:29 +00:00
|
|
|
v-list-item-avatar(size='24')
|
|
|
|
v-icon(color='indigo') mdi-crop-rotate
|
2019-07-29 04:50:03 +00:00
|
|
|
v-list-item-content {{$t('common:actions.edit')}}
|
|
|
|
v-list-item(@click='', disabled)
|
2019-08-04 02:51:29 +00:00
|
|
|
v-list-item-avatar(size='24')
|
|
|
|
v-icon(color='purple') mdi-flash-circle
|
2019-07-29 04:50:03 +00:00
|
|
|
v-list-item-content {{$t('common:actions.optimize')}}
|
|
|
|
v-list-item(@click='openRenameDialog')
|
2019-08-04 02:51:29 +00:00
|
|
|
v-list-item-avatar(size='24')
|
|
|
|
v-icon(color='orange') mdi-keyboard-outline
|
2019-07-29 04:50:03 +00:00
|
|
|
v-list-item-content {{$t('common:actions.rename')}}
|
|
|
|
v-list-item(@click='', disabled)
|
2019-08-04 02:51:29 +00:00
|
|
|
v-list-item-avatar(size='24')
|
|
|
|
v-icon(color='blue') mdi-file-move
|
2019-07-29 04:50:03 +00:00
|
|
|
v-list-item-content {{$t('common:actions.move')}}
|
|
|
|
v-list-item(@click='deleteDialog = true')
|
2019-08-04 02:51:29 +00:00
|
|
|
v-list-item-avatar(size='24')
|
|
|
|
v-icon(color='red') mdi-file-hidden
|
2019-07-29 04:50:03 +00:00
|
|
|
v-list-item-content {{$t('common:actions.delete')}}
|
2019-05-18 06:27:30 +00:00
|
|
|
template(slot='no-data')
|
2019-08-04 02:51:29 +00:00
|
|
|
v-alert.mt-3.radius-7(icon='mdi-folder-open-outline', :value='true', outlined, color='teal') {{$t('editor:assets.folderEmpty')}}
|
2019-05-18 06:27:30 +00:00
|
|
|
.text-xs-center.py-2(v-if='this.pageTotal > 1')
|
2019-08-04 02:51:29 +00:00
|
|
|
v-pagination(v-model='pagination', :length='pageTotal', color='teal')
|
2019-04-07 16:12:30 +00:00
|
|
|
.d-flex.mt-3
|
2019-08-10 16:18:14 +00:00
|
|
|
v-toolbar.radius-7(flat, :color='$vuetify.theme.dark ? `grey darken-2` : `grey lighten-4`', dense, height='44')
|
|
|
|
.body-2(:class='$vuetify.theme.dark ? `grey--text text--lighten-1` : `grey--text text--darken-1`') {{$t('editor:assets.fileCount', { count: assets.length })}}
|
2019-05-18 06:27:30 +00:00
|
|
|
v-btn.ml-3.mr-0.my-0.radius-7(color='teal', large, @click='insert', :disabled='!currentFileId', :dark='currentFileId !== null')
|
2019-08-04 02:51:29 +00:00
|
|
|
v-icon(left) mdi-playlist-plus
|
2019-06-15 21:05:56 +00:00
|
|
|
span {{$t('common:actions.insert')}}
|
2019-04-07 16:12:30 +00:00
|
|
|
|
2019-06-22 16:44:32 +00:00
|
|
|
v-flex(xs12, lg3)
|
2019-08-10 16:18:14 +00:00
|
|
|
v-card.radius-7.animated.fadeInRight.wait-p3s(:light='!$vuetify.theme.dark', :dark='$vuetify.theme.dark')
|
2019-04-07 16:12:30 +00:00
|
|
|
v-card-text
|
2019-05-13 05:15:27 +00:00
|
|
|
.d-flex
|
2019-08-10 16:18:14 +00:00
|
|
|
v-toolbar.radius-7(:color='$vuetify.theme.dark ? `teal` : `teal lighten-5`', dense, flat, height='44')
|
|
|
|
v-icon.mr-3(:color='$vuetify.theme.dark ? `white` : `teal`') mdi-cloud-upload
|
|
|
|
.body-2(:class='$vuetify.theme.dark ? `white--text` : `teal--text`') {{$t('editor:assets.uploadAssets')}}
|
2019-08-04 02:51:29 +00:00
|
|
|
v-btn.my-0.ml-3.mr-0.radius-7(outlined, large, color='teal', @click='browse', v-if='$vuetify.breakpoint.mdAndUp')
|
|
|
|
v-icon(left) mdi-library-plus
|
2019-08-10 16:18:14 +00:00
|
|
|
span(:class='$vuetify.theme.dark ? `teal--text text--lighten-3` : ``') {{$t('common:actions.browse')}}
|
2019-04-07 16:12:30 +00:00
|
|
|
file-pond.mt-3(
|
2019-03-20 04:37:33 +00:00
|
|
|
name='mediaUpload'
|
|
|
|
ref='pond'
|
2019-06-15 21:05:56 +00:00
|
|
|
:label-idle='$t(`editor:assets.uploadAssetsDropZone`)'
|
2019-03-20 04:37:33 +00:00
|
|
|
allow-multiple='true'
|
|
|
|
:files='files'
|
2019-04-21 00:49:05 +00:00
|
|
|
max-files='10'
|
2019-05-13 05:15:27 +00:00
|
|
|
server='/u'
|
|
|
|
:instant-upload='false'
|
|
|
|
:allow-revert='false'
|
|
|
|
@processfile='onFileProcessed'
|
2019-03-20 04:37:33 +00:00
|
|
|
)
|
2019-04-07 16:12:30 +00:00
|
|
|
v-divider
|
|
|
|
v-card-actions.pa-3
|
2019-04-21 00:49:05 +00:00
|
|
|
.caption.grey--text.text-darken-2 Max 10 files, 5 MB each
|
2019-04-07 16:12:30 +00:00
|
|
|
v-spacer
|
2019-08-04 02:51:29 +00:00
|
|
|
v-btn.px-4(color='teal', dark, @click='upload') {{$t('common:actions.upload')}}
|
2019-04-07 16:12:30 +00:00
|
|
|
|
2019-08-10 16:18:14 +00:00
|
|
|
v-card.mt-3.radius-7.animated.fadeInRight.wait-p4s(:light='!$vuetify.theme.dark', :dark='$vuetify.theme.dark')
|
2019-04-07 16:12:30 +00:00
|
|
|
v-card-text.pb-0
|
2019-08-10 16:18:14 +00:00
|
|
|
v-toolbar.radius-7(:color='$vuetify.theme.dark ? `teal` : `teal lighten-5`', dense, flat)
|
|
|
|
v-icon.mr-3(:color='$vuetify.theme.dark ? `white` : `teal`') mdi-cloud-download
|
|
|
|
.body-2(:class='$vuetify.theme.dark ? `white--text` : `teal--text`') {{$t('editor:assets.fetchImage')}}
|
2019-05-24 18:01:08 +00:00
|
|
|
v-spacer
|
|
|
|
v-chip(label, color='white', small).teal--text coming soon
|
2019-04-07 16:12:30 +00:00
|
|
|
v-text-field.mt-3(
|
|
|
|
v-model='remoteImageUrl'
|
2019-08-04 02:51:29 +00:00
|
|
|
outlined
|
|
|
|
color='teal'
|
2019-04-07 16:12:30 +00:00
|
|
|
single-line
|
|
|
|
placeholder='https://example.com/image.jpg'
|
|
|
|
)
|
|
|
|
v-divider
|
|
|
|
v-card-actions.pa-3
|
|
|
|
.caption.grey--text.text-darken-2 Max 5 MB
|
|
|
|
v-spacer
|
2019-08-04 02:51:29 +00:00
|
|
|
v-btn.px-4(color='teal', disabled) {{$t('common:actions.fetch')}}
|
2019-04-07 16:12:30 +00:00
|
|
|
|
2019-08-10 16:18:14 +00:00
|
|
|
v-card.mt-3.radius-7.animated.fadeInRight.wait-p4s(:light='!$vuetify.theme.dark', :dark='$vuetify.theme.dark')
|
2019-04-07 16:12:30 +00:00
|
|
|
v-card-text.pb-0
|
2019-08-10 16:18:14 +00:00
|
|
|
v-toolbar.radius-7(:color='$vuetify.theme.dark ? `teal` : `teal lighten-5`', dense, flat)
|
|
|
|
v-icon.mr-3(:color='$vuetify.theme.dark ? `white` : `teal`') mdi-format-align-top
|
|
|
|
.body-2(:class='$vuetify.theme.dark ? `white--text` : `teal--text`') {{$t('editor:assets.imageAlign')}}
|
2019-04-07 16:12:30 +00:00
|
|
|
v-select.mt-3(
|
|
|
|
v-model='imageAlignment'
|
|
|
|
:items='imageAlignments'
|
2019-08-04 02:51:29 +00:00
|
|
|
outlined
|
2019-04-07 16:12:30 +00:00
|
|
|
single-line
|
2019-08-04 02:51:29 +00:00
|
|
|
color='teal'
|
2019-04-07 16:12:30 +00:00
|
|
|
placeholder='None'
|
|
|
|
)
|
2019-05-26 01:38:29 +00:00
|
|
|
|
|
|
|
//- RENAME DIALOG
|
|
|
|
|
|
|
|
v-dialog(v-model='renameDialog', max-width='550', persistent)
|
2019-08-25 18:23:56 +00:00
|
|
|
v-card
|
2019-05-26 01:38:29 +00:00
|
|
|
.dialog-header.is-short.is-orange
|
2019-08-25 18:23:56 +00:00
|
|
|
v-icon.mr-2(color='white') mdi-keyboard
|
2019-06-15 21:05:56 +00:00
|
|
|
span {{$t('editor:assets.renameAsset')}}
|
2019-08-25 18:23:56 +00:00
|
|
|
v-card-text.pt-5
|
2019-06-15 21:05:56 +00:00
|
|
|
.body-2 {{$t('editor:assets.renameAssetSubtitle')}}
|
2019-05-26 01:38:29 +00:00
|
|
|
v-text-field(
|
2019-08-25 18:23:56 +00:00
|
|
|
outlined
|
2019-05-26 01:38:29 +00:00
|
|
|
single-line
|
|
|
|
:counter='255'
|
|
|
|
v-model='renameAssetName'
|
|
|
|
@keyup.enter='renameAsset'
|
|
|
|
:disabled='renameAssetLoading'
|
|
|
|
)
|
|
|
|
v-card-chin
|
|
|
|
v-spacer
|
2019-08-25 18:23:56 +00:00
|
|
|
v-btn(text, @click='renameDialog = false', :disabled='renameAssetLoading') {{$t('common:actions.cancel')}}
|
|
|
|
v-btn.px-3(color='orange darken-3', @click='renameAsset', :loading='renameAssetLoading').white--text {{$t('common:actions.rename')}}
|
2019-05-26 01:38:29 +00:00
|
|
|
|
|
|
|
//- DELETE DIALOG
|
|
|
|
|
|
|
|
v-dialog(v-model='deleteDialog', max-width='550', persistent)
|
2019-08-25 18:23:56 +00:00
|
|
|
v-card
|
2019-05-26 01:38:29 +00:00
|
|
|
.dialog-header.is-short.is-red
|
2019-08-25 18:23:56 +00:00
|
|
|
v-icon.mr-2(color='white') mdi-trash-can-outline
|
2019-06-15 21:05:56 +00:00
|
|
|
span {{$t('editor:assets.deleteAsset')}}
|
2019-08-25 18:23:56 +00:00
|
|
|
v-card-text.pt-5
|
2019-06-15 21:05:56 +00:00
|
|
|
.body-2 {{$t('editor:assets.deleteAssetConfirm')}}
|
2019-05-26 01:38:29 +00:00
|
|
|
.body-2.red--text.text--darken-2 {{currentAsset.filename}}?
|
2019-06-15 21:05:56 +00:00
|
|
|
.caption.mt-3 {{$t('editor:assets.deleteAssetWarn')}}
|
2019-05-26 01:38:29 +00:00
|
|
|
v-card-chin
|
|
|
|
v-spacer
|
2019-08-25 18:23:56 +00:00
|
|
|
v-btn(text, @click='deleteDialog = false', :disabled='deleteAssetLoading') {{$t('common:actions.cancel')}}
|
|
|
|
v-btn.px-3(color='red darken-2', @click='deleteAsset', :loading='deleteAssetLoading').white--text {{$t('common:actions.delete')}}
|
2019-03-20 04:37:33 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2019-05-13 05:15:27 +00:00
|
|
|
import _ from 'lodash'
|
2019-07-14 20:23:33 +00:00
|
|
|
import { get, sync } from 'vuex-pathify'
|
2019-03-20 04:37:33 +00:00
|
|
|
import vueFilePond from 'vue-filepond'
|
|
|
|
import 'filepond/dist/filepond.min.css'
|
|
|
|
|
2019-05-13 05:15:27 +00:00
|
|
|
import listAssetQuery from 'gql/editor/editor-media-query-list.gql'
|
2019-05-21 20:45:27 +00:00
|
|
|
import listFolderAssetQuery from 'gql/editor/editor-media-query-folder-list.gql'
|
|
|
|
import createAssetFolderMutation from 'gql/editor/editor-media-mutation-folder-create.gql'
|
2019-05-26 01:38:29 +00:00
|
|
|
import renameAssetMutation from 'gql/editor/editor-media-mutation-asset-rename.gql'
|
|
|
|
import deleteAssetMutation from 'gql/editor/editor-media-mutation-asset-delete.gql'
|
2019-04-21 00:49:05 +00:00
|
|
|
|
2019-05-18 06:27:30 +00:00
|
|
|
const FilePond = vueFilePond()
|
2019-05-19 18:46:08 +00:00
|
|
|
const localeSegmentRegex = /^[A-Z]{2}(-[A-Z]{2})?$/i
|
|
|
|
const disallowedFolderChars = /[A-Z()=.!@#$%?&*+`~<>,;:\\/[\]¬{| ]/
|
2019-03-20 04:37:33 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
components: {
|
|
|
|
FilePond
|
|
|
|
},
|
|
|
|
props: {
|
|
|
|
value: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
2019-05-21 20:45:27 +00:00
|
|
|
folders: [],
|
2019-04-07 16:12:30 +00:00
|
|
|
files: [],
|
2019-05-18 06:27:30 +00:00
|
|
|
assets: [],
|
2019-08-04 02:51:29 +00:00
|
|
|
pagination: 1,
|
2019-04-07 16:12:30 +00:00
|
|
|
remoteImageUrl: '',
|
|
|
|
imageAlignments: [
|
|
|
|
{ text: 'None', value: '' },
|
2019-05-21 20:45:27 +00:00
|
|
|
{ text: 'Left', value: 'left' },
|
2019-04-07 16:12:30 +00:00
|
|
|
{ text: 'Centered', value: 'center' },
|
|
|
|
{ text: 'Right', value: 'right' },
|
|
|
|
{ text: 'Absolute Top Right', value: 'abstopright' }
|
|
|
|
],
|
2019-05-18 06:27:30 +00:00
|
|
|
imageAlignment: '',
|
2019-05-19 18:46:08 +00:00
|
|
|
loading: false,
|
|
|
|
newFolderDialog: false,
|
2019-05-21 20:45:27 +00:00
|
|
|
newFolderName: '',
|
2019-05-26 01:38:29 +00:00
|
|
|
newFolderLoading: false,
|
|
|
|
previewDialog: false,
|
|
|
|
renameDialog: false,
|
|
|
|
renameAssetName: '',
|
|
|
|
renameAssetLoading: false,
|
|
|
|
deleteDialog: false,
|
|
|
|
deleteAssetLoading: false
|
2019-03-20 04:37:33 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
isShown: {
|
|
|
|
get() { return this.value },
|
|
|
|
set(val) { this.$emit('input', val) }
|
2019-04-07 16:12:30 +00:00
|
|
|
},
|
2019-05-18 06:27:30 +00:00
|
|
|
activeModal: sync('editor/activeModal'),
|
2019-07-14 20:23:33 +00:00
|
|
|
folderTree: get('editor/media@folderTree'),
|
|
|
|
currentFolderId: sync('editor/media@currentFolderId'),
|
|
|
|
currentFileId: sync('editor/media@currentFileId'),
|
2019-05-18 06:27:30 +00:00
|
|
|
pageTotal () {
|
2019-08-04 02:51:29 +00:00
|
|
|
if (!this.assets) {
|
2019-05-18 06:27:30 +00:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2019-08-04 02:51:29 +00:00
|
|
|
return Math.ceil(this.assets.length / 15)
|
2019-05-18 06:27:30 +00:00
|
|
|
},
|
|
|
|
headers() {
|
|
|
|
return _.compact([
|
2019-09-01 02:10:58 +00:00
|
|
|
this.$vuetify.breakpoint.smAndUp && { text: this.$t('editor:assets.headerId'), value: 'id', width: 80 },
|
2019-06-15 21:05:56 +00:00
|
|
|
{ text: this.$t('editor:assets.headerFilename'), value: 'filename' },
|
2019-09-01 02:10:58 +00:00
|
|
|
this.$vuetify.breakpoint.lgAndUp && { text: this.$t('editor:assets.headerType'), value: 'ext', width: 90 },
|
2019-06-15 21:05:56 +00:00
|
|
|
this.$vuetify.breakpoint.mdAndUp && { text: this.$t('editor:assets.headerFileSize'), value: 'fileSize', width: 110 },
|
|
|
|
this.$vuetify.breakpoint.mdAndUp && { text: this.$t('editor:assets.headerAdded'), value: 'createdAt', width: 175 },
|
2019-09-01 02:10:58 +00:00
|
|
|
this.$vuetify.breakpoint.smAndUp && { text: this.$t('editor:assets.headerActions'), value: '', width: 80, sortable: false, align: 'right' }
|
2019-05-18 06:27:30 +00:00
|
|
|
])
|
2019-05-19 18:46:08 +00:00
|
|
|
},
|
|
|
|
isFolderNameValid() {
|
|
|
|
return this.newFolderName.length > 1 && !localeSegmentRegex.test(this.newFolderName) && !disallowedFolderChars.test(this.newFolderName)
|
2019-05-26 01:38:29 +00:00
|
|
|
},
|
|
|
|
currentAsset () {
|
|
|
|
return _.find(this.assets, ['id', this.currentFileId]) || {}
|
2019-05-19 18:46:08 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
newFolderDialog(newValue, oldValue) {
|
|
|
|
if (newValue) {
|
|
|
|
this.$nextTick(() => {
|
|
|
|
this.$refs.folderNameIpt.focus()
|
|
|
|
})
|
|
|
|
}
|
2019-05-18 06:27:30 +00:00
|
|
|
}
|
2019-03-20 04:37:33 +00:00
|
|
|
},
|
2019-05-13 05:15:27 +00:00
|
|
|
filters: {
|
|
|
|
prettyBytes(num) {
|
|
|
|
if (typeof num !== 'number' || isNaN(num)) {
|
|
|
|
throw new TypeError('Expected a number')
|
|
|
|
}
|
|
|
|
|
2019-05-21 20:45:27 +00:00
|
|
|
let exponent
|
|
|
|
let unit
|
|
|
|
let neg = num < 0
|
|
|
|
let units = ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
|
2019-05-13 05:15:27 +00:00
|
|
|
|
|
|
|
if (neg) {
|
|
|
|
num = -num
|
|
|
|
}
|
|
|
|
if (num < 1) {
|
|
|
|
return (neg ? '-' : '') + num + ' B'
|
|
|
|
}
|
|
|
|
exponent = Math.min(Math.floor(Math.log(num) / Math.log(1000)), units.length - 1)
|
|
|
|
num = (num / Math.pow(1000, exponent)).toFixed(2) * 1
|
|
|
|
unit = units[exponent]
|
|
|
|
|
|
|
|
return (neg ? '-' : '') + num + ' ' + unit
|
|
|
|
}
|
|
|
|
},
|
2019-03-20 04:37:33 +00:00
|
|
|
methods: {
|
2019-05-21 20:45:27 +00:00
|
|
|
async refresh() {
|
|
|
|
await this.$apollo.queries.assets.refetch()
|
|
|
|
this.$store.commit('showNotification', {
|
2019-06-15 21:05:56 +00:00
|
|
|
message: this.$t('editor:assets.refreshSuccess'),
|
2019-06-01 05:34:16 +00:00
|
|
|
style: 'success',
|
|
|
|
icon: 'check'
|
|
|
|
})
|
2019-05-21 20:45:27 +00:00
|
|
|
},
|
2019-04-07 16:12:30 +00:00
|
|
|
insert () {
|
2019-05-19 18:46:08 +00:00
|
|
|
const asset = _.find(this.assets, ['id', this.currentFileId])
|
2019-05-21 20:45:27 +00:00
|
|
|
const assetPath = this.folderTree.map(f => f.slug).join('/')
|
2019-05-19 18:46:08 +00:00
|
|
|
this.$root.$emit('editorInsert', {
|
|
|
|
kind: asset.kind,
|
2019-05-21 20:45:27 +00:00
|
|
|
path: this.currentFolderId > 0 ? `/${assetPath}/${asset.filename}` : `/${asset.filename}`,
|
|
|
|
text: asset.filename,
|
|
|
|
align: this.imageAlignment
|
2019-05-19 18:46:08 +00:00
|
|
|
})
|
2019-04-07 16:12:30 +00:00
|
|
|
this.activeModal = ''
|
2019-04-21 00:49:05 +00:00
|
|
|
},
|
2019-05-13 05:15:27 +00:00
|
|
|
browse () {
|
|
|
|
this.$refs.pond.browse()
|
|
|
|
},
|
2019-04-21 00:49:05 +00:00
|
|
|
async upload () {
|
|
|
|
const files = this.$refs.pond.getFiles()
|
2019-05-13 05:15:27 +00:00
|
|
|
if (files.length < 1) {
|
|
|
|
return this.$store.commit('showNotification', {
|
2019-06-15 21:05:56 +00:00
|
|
|
message: this.$t('editor:assets.noUploadError'),
|
2019-05-13 05:15:27 +00:00
|
|
|
style: 'warning',
|
|
|
|
icon: 'warning'
|
2019-04-21 00:49:05 +00:00
|
|
|
})
|
2019-05-13 05:15:27 +00:00
|
|
|
}
|
|
|
|
for (let file of files) {
|
|
|
|
file.setMetadata({
|
2019-05-21 20:45:27 +00:00
|
|
|
folderId: this.currentFolderId
|
2019-05-13 05:15:27 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
await this.$refs.pond.processFiles()
|
|
|
|
},
|
|
|
|
async onFileProcessed (err, file) {
|
|
|
|
if (err) {
|
|
|
|
return this.$store.commit('showNotification', {
|
2019-06-15 21:05:56 +00:00
|
|
|
message: this.$t('editor:assets.uploadFailed'),
|
2019-05-13 05:15:27 +00:00
|
|
|
style: 'error',
|
|
|
|
icon: 'error'
|
|
|
|
})
|
|
|
|
}
|
|
|
|
_.delay(() => {
|
|
|
|
this.$refs.pond.removeFile(file.id)
|
|
|
|
}, 5000)
|
|
|
|
|
|
|
|
await this.$apollo.queries.assets.refetch()
|
2019-05-19 18:46:08 +00:00
|
|
|
},
|
2019-05-21 20:45:27 +00:00
|
|
|
downFolder(folder) {
|
2019-07-14 20:23:33 +00:00
|
|
|
this.$store.commit('editor/pushMediaFolderTree', folder)
|
2019-05-21 20:45:27 +00:00
|
|
|
this.currentFolderId = folder.id
|
|
|
|
this.currentFileId = null
|
|
|
|
},
|
|
|
|
upFolder() {
|
2019-07-14 20:23:33 +00:00
|
|
|
this.$store.commit('editor/popMediaFolderTree')
|
2019-05-21 20:45:27 +00:00
|
|
|
const parentFolder = _.last(this.folderTree)
|
|
|
|
this.currentFolderId = parentFolder ? parentFolder.id : 0
|
|
|
|
this.currentFileId = null
|
|
|
|
},
|
2019-05-19 18:46:08 +00:00
|
|
|
async createFolder() {
|
2019-05-21 20:45:27 +00:00
|
|
|
this.$store.commit(`loadingStart`, 'editor-media-createfolder')
|
|
|
|
this.newFolderLoading = true
|
|
|
|
try {
|
|
|
|
const resp = await this.$apollo.mutate({
|
|
|
|
mutation: createAssetFolderMutation,
|
|
|
|
variables: {
|
|
|
|
parentFolderId: this.currentFolderId,
|
|
|
|
slug: this.newFolderName
|
|
|
|
}
|
|
|
|
})
|
|
|
|
if (_.get(resp, 'data.assets.createFolder.responseResult.succeeded', false)) {
|
|
|
|
await this.$apollo.queries.folders.refetch()
|
|
|
|
this.$store.commit('showNotification', {
|
2019-06-15 21:05:56 +00:00
|
|
|
message: this.$t('editor:assets.folderCreateSuccess'),
|
2019-05-21 20:45:27 +00:00
|
|
|
style: 'success',
|
|
|
|
icon: 'check'
|
|
|
|
})
|
|
|
|
this.newFolderDialog = false
|
|
|
|
this.newFolderName = ''
|
|
|
|
} else {
|
|
|
|
this.$store.commit('pushGraphError', new Error(_.get(resp, 'data.assets.createFolder.responseResult.message')))
|
|
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
this.$store.commit('pushGraphError', err)
|
|
|
|
}
|
|
|
|
this.newFolderLoading = false
|
|
|
|
this.$store.commit(`loadingStop`, 'editor-media-createfolder')
|
2019-05-26 01:38:29 +00:00
|
|
|
},
|
|
|
|
openRenameDialog() {
|
|
|
|
this.renameAssetName = this.currentAsset.filename
|
|
|
|
this.renameDialog = true
|
|
|
|
},
|
|
|
|
async renameAsset() {
|
|
|
|
this.$store.commit(`loadingStart`, 'editor-media-renameasset')
|
|
|
|
this.renameAssetLoading = true
|
|
|
|
try {
|
|
|
|
const resp = await this.$apollo.mutate({
|
|
|
|
mutation: renameAssetMutation,
|
|
|
|
variables: {
|
|
|
|
id: this.currentFileId,
|
|
|
|
filename: this.renameAssetName
|
|
|
|
}
|
|
|
|
})
|
|
|
|
if (_.get(resp, 'data.assets.renameAsset.responseResult.succeeded', false)) {
|
|
|
|
await this.$apollo.queries.assets.refetch()
|
|
|
|
this.$store.commit('showNotification', {
|
2019-06-15 21:05:56 +00:00
|
|
|
message: this.$t('editor:assets.renameSuccess'),
|
2019-05-26 01:38:29 +00:00
|
|
|
style: 'success',
|
|
|
|
icon: 'check'
|
|
|
|
})
|
|
|
|
this.renameDialog = false
|
|
|
|
this.renameAssetName = ''
|
|
|
|
} else {
|
|
|
|
this.$store.commit('pushGraphError', new Error(_.get(resp, 'data.assets.renameAsset.responseResult.message')))
|
|
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
this.$store.commit('pushGraphError', err)
|
|
|
|
}
|
|
|
|
this.renameAssetLoading = false
|
|
|
|
this.$store.commit(`loadingStop`, 'editor-media-renameasset')
|
|
|
|
},
|
|
|
|
async deleteAsset() {
|
|
|
|
this.$store.commit(`loadingStart`, 'editor-media-deleteasset')
|
|
|
|
this.deleteAssetLoading = true
|
|
|
|
try {
|
|
|
|
const resp = await this.$apollo.mutate({
|
|
|
|
mutation: deleteAssetMutation,
|
|
|
|
variables: {
|
|
|
|
id: this.currentFileId
|
|
|
|
}
|
|
|
|
})
|
|
|
|
if (_.get(resp, 'data.assets.deleteAsset.responseResult.succeeded', false)) {
|
|
|
|
this.currentFileId = null
|
|
|
|
await this.$apollo.queries.assets.refetch()
|
|
|
|
this.$store.commit('showNotification', {
|
2019-06-15 21:05:56 +00:00
|
|
|
message: this.$t('editor:assets.deleteSuccess'),
|
2019-05-26 01:38:29 +00:00
|
|
|
style: 'success',
|
|
|
|
icon: 'check'
|
|
|
|
})
|
|
|
|
this.deleteDialog = false
|
|
|
|
} else {
|
|
|
|
this.$store.commit('pushGraphError', new Error(_.get(resp, 'data.assets.deleteAsset.responseResult.message')))
|
|
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
this.$store.commit('pushGraphError', err)
|
|
|
|
}
|
|
|
|
this.deleteAssetLoading = false
|
|
|
|
this.$store.commit(`loadingStop`, 'editor-media-deleteasset')
|
2019-05-13 05:15:27 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
apollo: {
|
2019-05-21 20:45:27 +00:00
|
|
|
folders: {
|
|
|
|
query: listFolderAssetQuery,
|
|
|
|
variables() {
|
|
|
|
return {
|
|
|
|
parentFolderId: this.currentFolderId
|
|
|
|
}
|
|
|
|
},
|
|
|
|
fetchPolicy: 'network-only',
|
|
|
|
update: (data) => data.assets.folders,
|
|
|
|
watchLoading (isLoading) {
|
|
|
|
this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'editor-media-folders-list-refresh')
|
|
|
|
}
|
|
|
|
},
|
2019-05-13 05:15:27 +00:00
|
|
|
assets: {
|
|
|
|
query: listAssetQuery,
|
2019-05-21 20:45:27 +00:00
|
|
|
variables() {
|
|
|
|
return {
|
|
|
|
folderId: this.currentFolderId,
|
|
|
|
kind: 'ALL'
|
|
|
|
}
|
2019-05-13 05:15:27 +00:00
|
|
|
},
|
|
|
|
throttle: 1000,
|
|
|
|
fetchPolicy: 'network-only',
|
|
|
|
update: (data) => data.assets.list,
|
|
|
|
watchLoading (isLoading) {
|
2019-05-18 06:27:30 +00:00
|
|
|
this.loading = isLoading
|
2019-05-13 05:15:27 +00:00
|
|
|
this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'editor-media-list-refresh')
|
2019-04-21 00:49:05 +00:00
|
|
|
}
|
2019-04-07 16:12:30 +00:00
|
|
|
}
|
2019-03-20 04:37:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang='scss'>
|
|
|
|
.editor-modal-media {
|
2019-08-31 01:27:02 +00:00
|
|
|
position: fixed !important;
|
2019-05-13 05:15:27 +00:00
|
|
|
top: 112px;
|
|
|
|
left: 64px;
|
|
|
|
z-index: 10;
|
|
|
|
width: calc(100vw - 64px - 17px);
|
|
|
|
height: calc(100vh - 112px - 24px);
|
|
|
|
background-color: rgba(darken(mc('grey', '900'), 3%), .9) !important;
|
|
|
|
overflow: auto;
|
|
|
|
|
2019-05-18 06:27:30 +00:00
|
|
|
@include until($tablet) {
|
|
|
|
left: 40px;
|
|
|
|
width: calc(100vw - 40px);
|
|
|
|
height: calc(100vh - 112px - 24px);
|
|
|
|
}
|
|
|
|
|
2019-05-13 05:15:27 +00:00
|
|
|
.filepond--root {
|
|
|
|
margin-bottom: 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
.filepond--drop-label {
|
|
|
|
cursor: pointer;
|
|
|
|
|
|
|
|
> label {
|
|
|
|
cursor: pointer;
|
|
|
|
}
|
|
|
|
}
|
2019-05-18 06:27:30 +00:00
|
|
|
|
|
|
|
.v-btn--icon {
|
|
|
|
padding: 0 20px;
|
|
|
|
}
|
2019-03-20 04:37:33 +00:00
|
|
|
}
|
|
|
|
</style>
|