2019-12-27 20:36:37 +01:00
|
|
|
import Vue from 'vue'
|
|
|
|
|
import { Component, Prop, Watch } from 'vue-property-decorator'
|
|
|
|
|
|
|
|
|
|
import { tools } from '../../store/Modules/tools'
|
|
|
|
|
import { toolsext } from '@src/store/Modules/toolsext'
|
|
|
|
|
import { IGallery, IImgGallery } from '../../model/GlobalStore'
|
|
|
|
|
import { CMyPage } from '../CMyPage'
|
|
|
|
|
import GlobalModule from '../../store/Modules/GlobalStore'
|
|
|
|
|
import { GlobalStore } from '../../store/Modules'
|
2020-01-27 15:09:11 +01:00
|
|
|
import MixinBase from '../../mixins/mixin-base'
|
2019-12-27 20:36:37 +01:00
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
name: 'CGallery',
|
|
|
|
|
components: { CMyPage }
|
|
|
|
|
})
|
|
|
|
|
|
2020-01-27 15:09:11 +01:00
|
|
|
export default class CGallery extends MixinBase {
|
2019-12-27 20:36:37 +01:00
|
|
|
@Prop({ required: true }) public edit: boolean
|
|
|
|
|
@Prop({ required: true }) public gall: IGallery
|
|
|
|
|
@Prop({ required: true }) public listimages: IImgGallery[]
|
2020-02-02 04:07:24 +01:00
|
|
|
public mygall: IGallery = {}
|
|
|
|
|
public mylistimages: IImgGallery[] = []
|
|
|
|
|
|
|
|
|
|
@Watch('gall')
|
|
|
|
|
public gallchanged() {
|
|
|
|
|
this.mygall = this.gall
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Watch('listimages')
|
|
|
|
|
public listimageschanged() {
|
|
|
|
|
this.mylistimages = this.listimages
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public created() {
|
|
|
|
|
this.mygall = this.gall
|
|
|
|
|
this.mylistimages = this.listimages
|
|
|
|
|
}
|
2019-12-27 20:36:37 +01:00
|
|
|
|
|
|
|
|
get tools() {
|
|
|
|
|
return tools
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get getlistimages() {
|
2020-02-02 04:07:24 +01:00
|
|
|
if (this.mylistimages)
|
|
|
|
|
return this.mylistimages.slice().sort((a, b) => a.order - b.order)
|
2019-12-27 20:36:37 +01:00
|
|
|
else
|
|
|
|
|
return null
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public onDragStart(e) {
|
|
|
|
|
console.log('onDragStart')
|
|
|
|
|
e.dataTransfer.setData('text', e.target.id)
|
|
|
|
|
e.dataTransfer.dropEffect = 'move'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public onDragEnter(e) {
|
|
|
|
|
// don't drop on other draggables
|
|
|
|
|
if (e.target.draggable !== true) {
|
|
|
|
|
e.target.classList.add('drag-enter')
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public onDragLeave(e) {
|
|
|
|
|
e.target.classList.remove('drag-enter')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public onDragOver(e) {
|
|
|
|
|
e.preventDefault()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public onDrop(e) {
|
|
|
|
|
console.log('onDrop', e)
|
|
|
|
|
e.preventDefault()
|
|
|
|
|
|
|
|
|
|
// don't drop on other draggables
|
|
|
|
|
if (e.target.draggable === true) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const draggedId = e.dataTransfer.getData('text')
|
2019-12-28 02:17:07 +01:00
|
|
|
let dragout = ''
|
|
|
|
|
try {
|
|
|
|
|
dragout = e.target.parentNode.parentNode.id
|
|
|
|
|
} catch (e) {
|
|
|
|
|
dragout = ''
|
|
|
|
|
}
|
2019-12-27 20:36:37 +01:00
|
|
|
const draggedEl = document.getElementById(draggedId)
|
|
|
|
|
console.log('draggedId', draggedId, 'draggedEl', draggedEl)
|
2019-12-28 02:17:07 +01:00
|
|
|
console.log('dragout', dragout)
|
2019-12-27 20:36:37 +01:00
|
|
|
|
|
|
|
|
// check if original parent node
|
|
|
|
|
if (draggedEl.parentNode === e.target) {
|
|
|
|
|
e.target.classList.remove('drag-enter')
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-02 04:07:24 +01:00
|
|
|
const myindex = this.mylistimages.findIndex((rec) => rec._id === draggedId)
|
|
|
|
|
const myrec: IImgGallery = this.mylistimages[myindex]
|
2019-12-28 02:17:07 +01:00
|
|
|
|
|
|
|
|
let myrecprec: IImgGallery = null
|
|
|
|
|
let myrecout: IImgGallery = null
|
2020-02-02 04:07:24 +01:00
|
|
|
const myindexout = this.mylistimages.findIndex((rec) => rec._id === dragout)
|
|
|
|
|
myrecout = this.mylistimages[myindexout]
|
2019-12-28 02:17:07 +01:00
|
|
|
let myindexprec = myindexout - 1
|
|
|
|
|
|
|
|
|
|
if (myindexprec < 0)
|
|
|
|
|
myindexprec = 0
|
|
|
|
|
|
|
|
|
|
if (myindex === myindexout)
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
myrecprec = this.listimages[myindexprec]
|
2019-12-27 20:36:37 +01:00
|
|
|
|
2019-12-28 02:17:07 +01:00
|
|
|
console.log('myrec', myrec, 'myrecprec', myrecout)
|
2019-12-27 20:36:37 +01:00
|
|
|
|
2019-12-28 02:17:07 +01:00
|
|
|
if (myrec && myrecout)
|
|
|
|
|
console.log('myrec', myrec, 'myrecprec', myrecout, 'ord1', myrec.order, 'myrecout', myrecout.order)
|
|
|
|
|
|
|
|
|
|
if (myrecout) {
|
|
|
|
|
let diff = 0
|
|
|
|
|
const ord2 = myrecprec.order
|
|
|
|
|
const ord1 = myrecout.order
|
|
|
|
|
diff = Math.round((ord1 - ord2) / 2)
|
2019-12-27 20:36:37 +01:00
|
|
|
if (diff <= 0)
|
|
|
|
|
diff++
|
2019-12-28 02:17:07 +01:00
|
|
|
console.log('diff', diff)
|
|
|
|
|
let mynum = 0
|
|
|
|
|
mynum = myrecprec.order + diff
|
|
|
|
|
console.log('mynum', mynum)
|
|
|
|
|
myrec.order = mynum
|
2019-12-27 20:36:37 +01:00
|
|
|
} else {
|
2019-12-28 02:17:07 +01:00
|
|
|
myrec.order = Math.round(myrec.order) - 1
|
2019-12-27 20:36:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
console.log('myrec.order', myrec.order)
|
|
|
|
|
|
|
|
|
|
// make the exchange
|
|
|
|
|
// draggedEl.parentNode.removeChild(draggedEl)
|
|
|
|
|
// e.target.appendChild(draggedEl)
|
|
|
|
|
e.target.classList.remove('drag-enter')
|
|
|
|
|
|
|
|
|
|
this.save()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get getclass() {
|
|
|
|
|
return (this.edit) ? 'my-card-gallery' : 'my-card-gallery-view' + ' text-center'
|
|
|
|
|
}
|
2019-12-28 02:17:07 +01:00
|
|
|
|
2019-12-27 20:36:37 +01:00
|
|
|
get getclimg() {
|
|
|
|
|
return (this.edit) ? 'myimg' : 'myimg-view'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get getlastord() {
|
|
|
|
|
let myord = 0
|
2020-02-02 04:07:24 +01:00
|
|
|
for (const file of this.mylistimages) {
|
2019-12-27 20:36:37 +01:00
|
|
|
if (file.order > myord)
|
|
|
|
|
myord = file.order
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return myord + 10
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public uploaded(info) {
|
|
|
|
|
console.log(info)
|
|
|
|
|
for (const file of info.files) {
|
2020-02-02 04:07:24 +01:00
|
|
|
this.mylistimages.push({ imagefile: file.name, order: this.getlastord })
|
2019-12-27 20:36:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.save()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public deleted(rec) {
|
2020-02-02 04:07:24 +01:00
|
|
|
// console.table(this.mylistimages)
|
2019-12-27 20:36:37 +01:00
|
|
|
|
2020-02-02 04:07:24 +01:00
|
|
|
const index = this.mylistimages.findIndex((elem) => elem.imagefile === rec.imagefile)
|
2019-12-27 20:36:37 +01:00
|
|
|
if (index > -1) {
|
2020-02-02 04:07:24 +01:00
|
|
|
this.mylistimages.splice(index, 1)
|
2019-12-27 20:36:37 +01:00
|
|
|
}
|
|
|
|
|
|
2020-02-02 04:07:24 +01:00
|
|
|
// this.mylistimages = this.mylistimages.pop((elem) => elem.imagefile !== rec.imagefile)
|
2019-12-27 20:36:37 +01:00
|
|
|
|
2020-02-02 04:07:24 +01:00
|
|
|
// console.table(this.mylistimages)
|
2019-12-27 20:36:37 +01:00
|
|
|
|
|
|
|
|
this.save()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public getfullname(rec) {
|
2020-02-02 04:07:24 +01:00
|
|
|
return 'statics/upload/' + this.mygall.directory + `/` + rec.imagefile
|
2019-12-27 20:36:37 +01:00
|
|
|
}
|
|
|
|
|
|
2019-12-28 02:17:07 +01:00
|
|
|
public copytoclipboard(rec) {
|
|
|
|
|
const filename = this.getfullname(rec)
|
2020-01-27 15:09:11 +01:00
|
|
|
tools.copyStringToClipboard(this, filename)
|
2019-12-28 02:17:07 +01:00
|
|
|
}
|
|
|
|
|
|
2019-12-27 20:36:37 +01:00
|
|
|
public async deleteFile(rec) {
|
|
|
|
|
const filename = this.getfullname(rec)
|
|
|
|
|
|
|
|
|
|
// Delete File on server:
|
2019-12-28 02:17:07 +01:00
|
|
|
const ris = await GlobalStore.actions.DeleteFile({ filename })
|
2019-12-27 20:36:37 +01:00
|
|
|
if (ris)
|
|
|
|
|
this.deleted(rec)
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public save() {
|
2020-02-02 04:07:24 +01:00
|
|
|
this.$emit('showandsave', this.mylistimages)
|
2019-12-27 20:36:37 +01:00
|
|
|
}
|
|
|
|
|
|
2019-12-28 02:17:07 +01:00
|
|
|
public getsrcimg(mygallery) {
|
|
|
|
|
|
|
|
|
|
if (tools.getextfile(mygallery.imagefile) === 'pdf')
|
|
|
|
|
return 'statics/images/images/pdf.jpg'
|
|
|
|
|
else
|
2020-02-02 04:07:24 +01:00
|
|
|
return 'statics/upload/' + this.mygall.directory + `/` + mygallery.imagefile
|
2019-12-28 02:17:07 +01:00
|
|
|
}
|
|
|
|
|
|
2019-12-27 20:36:37 +01:00
|
|
|
}
|