From ea9822e5f68492be9ebbc5f99ed5cce28fd7d363 Mon Sep 17 00:00:00 2001 From: Paolo Arena Date: Tue, 23 Nov 2021 15:59:26 +0100 Subject: [PATCH] fixed CGallery 2 --- src/components/CGallery/CGallery.scss | 6 ++ src/components/CGallery/CGallery.ts | 90 +++++++++----------- src/components/CGallery/CGallery.vue | 42 +++++---- src/components/CMyPopupEdit/CMyPopupEdit.ts | 2 +- src/components/CMyPopupEdit/CMyPopupEdit.vue | 3 - src/model/GlobalStore.ts | 2 +- src/store/Modules/tools.ts | 14 ++- src/store/UserStore.ts | 2 +- 8 files changed, 84 insertions(+), 77 deletions(-) diff --git a/src/components/CGallery/CGallery.scss b/src/components/CGallery/CGallery.scss index 02d3a55c..e2ca7ada 100755 --- a/src/components/CGallery/CGallery.scss +++ b/src/components/CGallery/CGallery.scss @@ -19,8 +19,14 @@ $grayshadow: #555; .myimg { border-radius: 10px !important; height: 200px; + cursor: grab; } +.barwidth{ + width: 250px !important; +} + + .myimg-view { border-radius: 5px !important; height: 80px; diff --git a/src/components/CGallery/CGallery.ts b/src/components/CGallery/CGallery.ts index 84d5add3..34629385 100755 --- a/src/components/CGallery/CGallery.ts +++ b/src/components/CGallery/CGallery.ts @@ -62,8 +62,9 @@ export default defineComponent({ gallerylist.value = [] if (myarr) { myarr.forEach((pic: any) => { - if (pic.imagefile) + if (pic.imagefile) { gallerylist.value.push(pic) + } }) } } else { @@ -86,7 +87,8 @@ export default defineComponent({ function getlistimages() { if (gallerylist.value) - return gallerylist.value.slice().sort((a: any, b: any) => a.order! - b.order!) + // return gallerylist.value.slice().sort((a: any, b: any) => a.order! - b.order!) + return gallerylist.value else return null } @@ -126,8 +128,8 @@ export default defineComponent({ const draggedId = e.dataTransfer.getData('text') let dragout = '' try { - dragout = e.target.parentNode.parentNode.id - } catch (e) { + dragout = e.target.parentNode.parentNode.parentNode.id + } catch (err) { dragout = '' } const draggedEl = document.getElementById(draggedId) @@ -135,57 +137,31 @@ export default defineComponent({ console.log('dragout', dragout) // check if original parent node - if (draggedEl!.parentNode === e.target) { - e.target.classList.remove('drag-enter') - return + if (draggedEl) { + if (draggedEl.parentNode === e.target) { + e.target.classList.remove('drag-enter') + return + } } - const myindex = gallerylist.value.findIndex((rec: any) => rec._id === draggedId) - const myrec: IImgGallery = gallerylist.value[myindex] + const myindexIn = gallerylist.value.findIndex((rec: any) => rec._id === draggedId) + const myrecIn: IImgGallery = gallerylist.value[myindexIn] - let myrecprec: IImgGallery - let myrecout: IImgGallery + let myrecOut: IImgGallery const myindexout = gallerylist.value.findIndex((rec: any) => rec._id === dragout) - myrecout = gallerylist.value[myindexout] - let myindexprec = myindexout - 1 + myrecOut = gallerylist.value[myindexout] - if (myindexprec < 0) - myindexprec = 0 - - if (myindex === myindexout) + if (myindexIn === myindexout) return - myrecprec = gallerylist.value[myindexprec] - console.log('myrec', myrec, 'myrecprec', myrecout) - - 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) - if (diff <= 0) - diff++ - console.log('diff', diff) - let mynum = 0 - mynum = myrecprec.order! + diff - console.log('mynum', mynum) - myrec.order = mynum - } else { - myrec.order = Math.round(myrec.order!) - 1 - } - - console.log('myrec.order', myrec.order) + tools.array_move(gallerylist.value, myindexIn, myindexout) // make the exchange // draggedEl.parentNode.removeChild(draggedEl) // e.target.appendChild(draggedEl) e.target.classList.remove('drag-enter') - save() } } @@ -198,7 +174,7 @@ export default defineComponent({ return (props.edit || displayGall.value) ? 'myimg' : 'myimg-view' } - function getlastord() { + /*function getlastord() { if (gallerylist.value) { let myord = 0 for (const file of gallerylist.value) { @@ -208,13 +184,13 @@ export default defineComponent({ return myord + 10 } - } + }*/ function uploaded(info: any) { console.log('uploaded', info) if (gallerylist.value) { for (const file of info.files) { - gallerylist.value.push({ imagefile: file.name, order: getlastord() }) + gallerylist.value.push({ imagefile: file.name }) } if (!props.single) @@ -259,17 +235,30 @@ export default defineComponent({ tools.copyStringToClipboard($q, filename, true) } - async function deleteFile(rec: any) + function deleteFile(rec: any) { console.log('deleteFile....') const filename = getfullname(rec) + const filenamerel = filename.replace(/^.*[\\\/]/, '') - // Delete File on server: - const ris = await globalStore.DeleteFile({ filename }) - console.log('ris', ris) - if (ris) - deleted(rec) + $q.dialog({ + message: 'Eliminare il file ' + filenamerel + '?', + html: true, + ok: { + label: 'Elimina', + push: true, + }, + title: filenamerel, + cancel: true, + persistent: false, + }).onOk(async () => { + // Delete File on server: + const ris = await globalStore.DeleteFile({ filename }) + console.log('ris', ris) + if (ris) + deleted(rec) + }) } function save() { @@ -325,7 +314,6 @@ export default defineComponent({ onDrop, getclass, getclimg, - getlastord, copytoclipboard, deleteFile, getsrcimg, diff --git a/src/components/CGallery/CGallery.vue b/src/components/CGallery/CGallery.vue index dfb3f158..98d77327 100755 --- a/src/components/CGallery/CGallery.vue +++ b/src/components/CGallery/CGallery.vue @@ -9,8 +9,8 @@ -
- {{ getnumimages() }} files +
+ ({{ getnumimages() }})
@@ -31,7 +31,7 @@ v-model="order">-->
- mygallery : {{ mygallery}} + mygallery : {{ mygallery }}
+ label="Nome File"> @@ -138,13 +138,28 @@
+ + + +
+ Foto {{ index + 1 }} +
+ + +
- @dragover="onDragOver"> -
+
{{ mygallery.description }}
@@ -162,7 +177,7 @@ + label="Nome File"> @@ -177,15 +192,6 @@ debounce="1000" autofocus> - - - - - @@ -211,7 +217,7 @@
- + diff --git a/src/components/CMyPopupEdit/CMyPopupEdit.ts b/src/components/CMyPopupEdit/CMyPopupEdit.ts index b84f9f73..eef5922d 100755 --- a/src/components/CMyPopupEdit/CMyPopupEdit.ts +++ b/src/components/CMyPopupEdit/CMyPopupEdit.ts @@ -165,7 +165,7 @@ export default defineComponent({ myImgGall.value = [{ _id: '', imagefile: myvalue.value, - order: 1, + // order: 1, alt: 'img', }] } diff --git a/src/components/CMyPopupEdit/CMyPopupEdit.vue b/src/components/CMyPopupEdit/CMyPopupEdit.vue index 105cf890..15703662 100755 --- a/src/components/CMyPopupEdit/CMyPopupEdit.vue +++ b/src/components/CMyPopupEdit/CMyPopupEdit.vue @@ -83,7 +83,6 @@
- gall1:
- gall2:
- gall3: = arr.length) { + let k: any = new_index - arr.length + 1 + while (k--) { + arr.push(undefined) + } + } + arr.splice(new_index, 0, arr.splice(old_index, 1)[0]) + return arr // for testing + }, // getLocale() { // if (navigator.languages && navigator.languages.length > 0) { // return navigator.languages[0] diff --git a/src/store/UserStore.ts b/src/store/UserStore.ts index b1af5e76..8cf6de85 100755 --- a/src/store/UserStore.ts +++ b/src/store/UserStore.ts @@ -170,7 +170,7 @@ export const useUserStore = defineStore('UserStore', { const myrec = this.getUserByUsername(username) // console.log('myrec', myrec) if (myrec && myrec.profile && !!myrec.profile.img && myrec.profile.img !== '' && myrec.profile.img !== 'undefined') { - return myrec.profile.img + return 'upload/profile/' + this.my.username + '/' + myrec.profile.img } return '' },