big refactoring, opening flagcollection (folder) on the left of main-content

This commit is contained in:
2020-11-27 23:02:59 +01:00
parent 420a879a4e
commit 93c4707c45
19 changed files with 656 additions and 253 deletions

View File

@ -1,5 +1,5 @@
<template>
<article class="card">
<article class="card search-card">
<header>
<h1>{{ item.title }}</h1>
<h4>{{ item.field_short_description }}</h4>
@ -45,10 +45,12 @@
<script>
import { mapState, mapActions } from 'vuex'
import cardMixins from 'vuejs/components/cardMixins'
export default {
name: "Card",
props: ['item'],
mixins: [cardMixins],
data() {
return {
blanksrc:`${drupalSettings.path.themePath}/assets/img/blank.gif`,
@ -60,54 +62,6 @@ export default {
flagcolls: state => state.User.flagcolls
})
},
directives: {
lazy: {
bind(img,binding){
// console.log('lazy bind', img, binding);
if(binding.value === 0){
img.setAttribute('src', img.getAttribute('data-src'))
img.removeAttribute('data-src')
img.classList.remove('lazy')
}
}
},
switcher: {
inserted(el,binding){
// switch images on mousemove
el.addEventListener('mousemove', function(event) {
let figs = this.querySelectorAll('figure')
// console.log('mousemove', this, event, figs.length);
// let len = figs.length
// let w = this.clientWidth;
// let g = w / len;
// let delta = Math.floor(event.layerX / g)
let delta = Math.floor(event.layerX / (this.clientWidth / figs.length))
// console.log('delta', delta);
figs.forEach((fig, index) => {
// console.log(index);
if(index == delta){
fig.style.display = "block"
}else{
fig.style.display = "none"
}
})
})
}
}
},
mounted() {
// lazy load images on mouseover
this.$el.addEventListener('mouseover', function(event) {
let imgs = this.querySelectorAll('.images figure img.lazy')
// console.log('mouseover', this, imgs);
imgs.forEach((img) => {
// console.log('forEach img',img);
img.setAttribute('src', img.getAttribute('data-src'))
img.removeAttribute('data-src')
img.classList.remove('lazy')
})
}, {once : true})
},
methods: {
...mapActions({
flag: 'User/flag',

View File

@ -0,0 +1,93 @@
<template>
<article class="card minicard">
<header>
<h1>{{ item.title }}</h1>
<span class="ref">{{ item.field_reference }}</span>
</header>
<nav class="tools">
<section class="tool flags">
<span class="mdi mdi-folder-remove-outline"/>
</section>
</nav>
<section class="images" v-switcher>
<figure
v-for="(img, index) in item.images"
:key="img.url"
>
<img
class="lazy"
v-lazy="index"
:data-src="img.url"
:title="img.title"
/>
<img class="blank" :src="blanksrc">
</figure>
</section>
</article>
</template>
<script>
import { mapState, mapActions } from 'vuex'
import cardMixins from 'vuejs/components/cardMixins'
export default {
name: "MiniCard",
props: ['item'],
mixins: [cardMixins],
data() {
return {
blanksrc:`${drupalSettings.path.themePath}/assets/img/blank.gif`,
// loadingFlag: false
}
},
computed: {
// ...mapState({
// flagcolls: state => state.User.flagcolls
// })
},
methods: {
// ...mapActions({
// flag: 'User/flag',
// unFlag: 'User/unFlag'
// }),
// flagIsActive(collid) {
// // console.log(this.item.uuid);
// // console.log(this.flagcolls[collid].items_uuids);
// return this.flagcolls[collid].items_uuids.indexOf(this.item.uuid) !== -1;
// },
// flagIsLoading(collid) {
// // console.log(this.item.uuid);
// // console.log(this.flagcolls[collid].items_uuids);
// return collid === this.loadingFlag;
// },
// onFlagActionCard (e) {
// console.log("Card onFlagActionCard", e);
// if (!this.loadingFlag) {
// let collid = e.target.getAttribute('collid');
// let isActive = this.flagIsActive(collid);
// // console.log('collid', collid);
// // console.log("this.item", this.item);
// this.loadingFlag = collid;
// if (isActive) {
// this.unFlag({uuid: this.item.uuid, collid: collid})
// .then(data => {
// console.log("onFlagActionCard then", data);
// this.loadingFlag = false;
// })
// }else{
// this.flag({uuid: this.item.uuid, collid: collid})
// .then(data => {
// console.log("onFlagActionCard then", data);
// this.loadingFlag = false;
// })
// }
// }
// }
}
}
</script>
<style lang="scss" scoped>
</style>

View File

@ -1,13 +1,16 @@
<template>
<div id="Base">
<div class="loading" v-if="!items.length">
<div class="loading" v-if="!searchinfos">
<span>Loading ...</span>
</div>
<div class="cards-list" v-else>
<aside class="search-info">
{{ searchinfos }}
</aside>
<ul>
<div class="loading" v-if="!items.length & !noresults">
<span>Loading ...</span>
</div>
<ul v-else>
<li v-for="item in items" v-bind:key="item.uuid">
<Card :item="item"/>
</li>
@ -42,6 +45,7 @@ export default {
items: state => state.Search.items,
searchinfos: state => state.Search.infos,
count: state => state.Search.count,
noresults: state => state.Search.noresults,
limit: state => state.Search.limit
})
},

View File

@ -1,11 +1,20 @@
<template>
<section class="flag-collection">
<h3>{{collection.name}}</h3>
<header>
<h3 class="mdi mdi-folder-outline">{{collection.name}}</h3>
<span
class="mdi mdi-close"
title="close"
@click.prevent="onCloseFlagColl"
/>
</header>
<ul v-if="loadedItems">
<li
v-for="item in loadedItems"
:key="item.id"
>{{item.attributes.title}}</li>
>
<MiniCard :item="item"/>
</li>
</ul>
<span v-else class="loading">Loading</span>
</section>
@ -13,6 +22,7 @@
<script>
import { mapState, mapActions } from 'vuex'
import MiniCard from 'vuejs/components/Content/MiniCard'
export default {
name: "FlagCollection",
@ -22,8 +32,8 @@ export default {
}),
computed: {
...mapState({
flagcolls: state => state.User.flagcolls
// openedCollid: state => state.User.openedCollid
flagcolls: state => state.User.flagcolls,
openedCollid: state => state.User.openedCollid
})
},
// watch: {
@ -35,11 +45,22 @@ export default {
// }
// },
created() {
if (typeof this.collection.loadedItems !== 'undefined') {
// if loadedItems are alredy loaded,
// the mutation occurs before this subscription
// so we first check if they are already available
this.loadedItems = this.collection.loadedItems
}
this.unsubscribe = this.$store.subscribe((mutation, state) => {
if (mutation.type === 'User/setLoadedCollItems') {
this.loadedItems = state.User.flagcolls[this.collection.id].loadedItems
console.log("mutation setLoadedCollItems collid", this.openedCollid)
// mutation is triggered before the component update
// so this.collection.id is not good
this.loadedItems = state.User.flagcolls[this.openedCollid].loadedItems
}
});
})
},
beforeDestroy() {
this.unsubscribe()
@ -49,11 +70,17 @@ export default {
// this.
// }
// },
// methods: {
// ...mapActions({
// loadFlagCollItems: 'User/loadFlagCollItems'
// })
// }
methods: {
...mapActions({
closeFlagColl: 'User/closeFlagColl'
}),
onCloseFlagColl(e) {
this.closeFlagColl()
}
},
components: {
MiniCard
}
}
</script>
<style lang="scss" scoped>

View File

@ -26,7 +26,7 @@
<span
class="add-btn mdi"
:class="addFlagBtnClassObj"
@click.prevent="onCreateFlagColl"
@click.prevent.stop="onCreateFlagColl"
/>
</li>
</ul>
@ -92,7 +92,7 @@ export default {
},
onOpenFlagColl (e) {
const flagcollid = e.target.getAttribute('flagcollid');
console.log("UserFlags onDeleteFlagColl", flagcollid);
console.log("UserFlags onOpenFlagColl", flagcollid);
this.openFlagColl(flagcollid)
.then(() => {
// console.log("onDeleteFlagColl then", data);

View File

@ -0,0 +1,56 @@
// https://forum.vuejs.org/t/how-to-use-helper-functions-for-imported-modules-in-vuejs-vue-template/6266/5
export default {
directives: {
lazy: {
bind(img,binding){
// console.log('lazy bind', img, binding);
if(binding.value === 0){
img.setAttribute('src', img.getAttribute('data-src'))
img.removeAttribute('data-src')
img.classList.remove('lazy')
}
}
},
switcher: {
inserted(el,binding){
// switch images on mousemove
el.addEventListener('mousemove', function(event) {
let figs = this.querySelectorAll('figure')
// console.log('mousemove', this, event, figs.length);
// let len = figs.length
// let w = this.clientWidth;
// let g = w / len;
// let delta = Math.floor(event.layerX / g)
let delta = Math.floor(event.layerX / (this.clientWidth / figs.length))
// console.log('delta', delta);
figs.forEach((fig, index) => {
// console.log(index);
if(index == delta){
fig.style.display = "block"
}else{
fig.style.display = "none"
}
})
})
}
}
},
mounted() {
// lazy load images on mouseover
this.$el.addEventListener('mouseover', function(event) {
let imgs = this.querySelectorAll('.images figure img.lazy')
// console.log('mouseover', this, imgs);
imgs.forEach((img) => {
// console.log('forEach img',img);
img.setAttribute('src', img.getAttribute('data-src'))
img.removeAttribute('data-src')
img.classList.remove('lazy')
})
}, {once : true})
},
methods: {
// deg2rad (deg) {
// return deg * (Math.PI / 180)
// },
}
}