ModalCard.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. <template>
  2. <div class="loading" v-if="!material || loading">
  3. <span>Loading ...</span>
  4. </div>
  5. <article v-else class="card modal-card">
  6. <section class="col col-right">
  7. <header>
  8. <h1>{{ material.title }}</h1>
  9. <h4>{{ material.short_description }}</h4>
  10. <span class="ref">{{ material.reference }}</span>
  11. </header>
  12. <nav class="tools">
  13. <section class="tool close">
  14. <span
  15. class="btn mdi mdi-close"
  16. @click.prevent="onCloseModalCard"
  17. />
  18. </section>
  19. <section class="tool flags">
  20. <span class="btn mdi mdi-folder-outline"/>
  21. <div class="tool-content">
  22. <span class="label">{{ $t("materio.My folders") }}</span>
  23. <ul>
  24. <li v-if="flagcolls" v-for="coll in flagcolls" :key="coll.id">
  25. <span
  26. class="flag mdi"
  27. :class="[
  28. flagIsLoading(coll.id) ? 'mdi-loading mdi-spin' : flagIsActive(coll.id) ? 'mdi-close-circle isActive' : 'mdi-plus'
  29. ]"
  30. :collid="coll.id"
  31. @click.prevent="onFlagActionCard"
  32. >
  33. {{ coll.name }}
  34. </span>
  35. </li>
  36. </ul>
  37. </div>
  38. </section>
  39. <section class="tool samples" v-if="item.samples && item.samples.length">
  40. <span class="btn mdi mdi-beaker-outline"/>
  41. <div class="tool-content">
  42. <span class="label">{{ $t("materio.Samples") }}</span>
  43. <ul>
  44. <li
  45. v-for="sample in material.samples"
  46. :key="sample.showroom.id"
  47. >
  48. <span class="showroom">{{ sample.showroom.name }}</span>: {{ sample.location }}
  49. </li>
  50. </ul>
  51. </div>
  52. </section>
  53. <!-- <section class="tool industriels" v-if="material.manufacturer || material.distributor">
  54. <span class="btn mdi mdi-factory"/>
  55. <div class="tool-content">
  56. <section v-if="material.distributor">
  57. <span class="label">{{ $t("materio.Distributor") }}</span>
  58. <ul>
  59. <li v-for="distrib in material.distributor" v-bind:key="distrib.id">
  60. <h2>{{ distrib.name }}</h2>
  61. <p v-if="distrib.website">
  62. <a target="_blank" :href="distrib.website.url">distrib.website.url</a>
  63. </p>
  64. <p v-if="distrib.email"><a :href="'mailto:'+distrib.email">{{ distrib.email }}</a></p>
  65. </li>
  66. </ul>
  67. </section>
  68. <section v-if="material.manufacturer">
  69. <span class="label">{{ $t("materio.Manufacturer") }}</span>
  70. <ul>
  71. <li v-for="manu in material.manufacturer" v-bind:key="manu.id">
  72. <h2>{{ manu.name }}</h2>
  73. <p v-if="manu.website">
  74. <a target="_blank" :href="manu.website.url">manu.website.url</a>
  75. </p>
  76. <p v-if="manu.email"><a :href="'mailto:'+manu.email">{{ manu.email }}</a></p>
  77. </li>
  78. </ul>
  79. </section>
  80. </div>
  81. </section> -->
  82. </nav>
  83. <section class="body" v-html="material.body"/>
  84. <vsa-list>
  85. <vsa-item v-if="material.linked_materials">
  86. <vsa-heading>
  87. <span class="label">{{ $t("materio.Linked materials") }}</span>
  88. </vsa-heading>
  89. <vsa-content>
  90. <section class="linked-materials">
  91. <ul>
  92. <li v-for="m in material.linked_materials" v-bind:key="m.id">
  93. <LinkedMaterialCard :item="m"/>
  94. </li>
  95. </ul>
  96. </section>
  97. </vsa-content>
  98. </vsa-item>
  99. <vsa-item v-if="material.manufacturer || material.distributor">
  100. <vsa-heading>
  101. <span class="label">{{ $t("default.Contact") }}</span>
  102. </vsa-heading>
  103. <vsa-content>
  104. <section class="industriels">
  105. <section v-if="material.distributor">
  106. <span class="label">{{ $t("materio.Distributor") }}</span>
  107. <ul>
  108. <li v-for="distrib in material.distributor" v-bind:key="distrib.id">
  109. <h2>{{ distrib.name }}</h2>
  110. <p v-if="distrib.website">
  111. <a target="_blank" :href="distrib.website.url">{{distrib.website.url}}</a>
  112. </p>
  113. <p v-if="distrib.email"><a :href="'mailto:'+distrib.email">{{ distrib.email }}</a></p>
  114. </li>
  115. </ul>
  116. </section>
  117. <section v-if="material.manufacturer">
  118. <span class="label">{{ $t("materio.Manufacturer") }}</span>
  119. <ul>
  120. <li v-for="manu in material.manufacturer" v-bind:key="manu.id">
  121. <h2>{{ manu.name }}</h2>
  122. <p v-if="manu.website">
  123. <a target="_blank" :href="manu.website.url">{{manu.website.url}}</a>
  124. </p>
  125. <p v-if="manu.email"><a :href="'mailto:'+manu.email">{{ manu.email }}</a></p>
  126. </li>
  127. </ul>
  128. </section>
  129. </section>
  130. </vsa-content>
  131. </vsa-item>
  132. <vsa-item v-if="material.attachments && material.attachments.length">
  133. <vsa-heading>
  134. <span class="label">{{ $t("materio.Attachments") }}</span>
  135. </vsa-heading>
  136. <vsa-content>
  137. <section class="attachments">
  138. <ul>
  139. <li
  140. v-for="attachmt in material.attachments" :key="attachmt.file.fid"
  141. >
  142. <a target="_blank" :href="attachmt.file.url">{{ attachmt.file.filename}} <span>({{ prettyFileSize(attachmt.file.filesize) }})</span></a>
  143. <p v-if="attachmt.description" class="description" v-html="attachmt.description" />
  144. </li>
  145. </ul>
  146. </section>
  147. </vsa-content>
  148. </vsa-item>
  149. </vsa-list>
  150. </section>
  151. <section class="col col-left images" v-switcher>
  152. <figure
  153. v-for="(img, index) in material.images"
  154. :key="img.url"
  155. >
  156. <img
  157. class="lazy"
  158. v-lazy="index"
  159. :data-src="img.style_cardfull.url"
  160. :title="img.title"
  161. />
  162. <img
  163. class="blank"
  164. :src="blanksrc"
  165. @click="lightbox_index = index"
  166. >
  167. </figure>
  168. </section>
  169. <CoolLightBox
  170. :items="material.images"
  171. :index="lightbox_index"
  172. srcName="url"
  173. :loop="true"
  174. @close="lightbox_index = null">
  175. </CoolLightBox>
  176. </article>
  177. </template>
  178. <script>
  179. import { mapState, mapActions } from 'vuex'
  180. import LinkedMaterialCard from 'vuejs/components/Content/LinkedMaterialCard'
  181. import cardMixins from 'vuejs/components/cardMixins'
  182. import { MGQ } from 'vuejs/api/graphql-axios'
  183. import { print } from 'graphql/language/printer'
  184. import gql from 'graphql-tag'
  185. import materiauFields from 'vuejs/api/gql/materiaumodal.fragment.gql'
  186. const prettyBytes = require('pretty-bytes')
  187. export default {
  188. name: "ModalCard",
  189. props: ['item'],
  190. mixins: [cardMixins],
  191. components: {
  192. LinkedMaterialCard
  193. },
  194. data() {
  195. return {
  196. material: null,
  197. loading: false,
  198. blanksrc:`${drupalSettings.path.themePath}/assets/img/blank.gif`,
  199. loadingFlag: false,
  200. lightbox_index: null
  201. }
  202. },
  203. computed: {
  204. ...mapState({
  205. flagcolls: state => state.User.flagcolls,
  206. showrooms: state => state.Showrooms.showrooms_by_tid
  207. })
  208. },
  209. created () {
  210. console.log('modale item', this.item)
  211. this.loadMaterial()
  212. },
  213. methods: {
  214. ...mapActions({
  215. flagUnflag: 'User/flagUnflag'
  216. }),
  217. loadMaterial(){
  218. console.log('loadMaterial', this.item.id)
  219. this.loading = true
  220. let ast = gql`{
  221. materiau(id: ${this.item.id}, lang: "${drupalDecoupled.lang_code}") {
  222. ...MateriauFields
  223. }
  224. }
  225. ${ materiauFields }
  226. `
  227. MGQ.post('', { query: print(ast)
  228. })
  229. .then(({ data:{data:{materiau}}}) => {
  230. console.log('loadMaterial material loaded', materiau )
  231. this.material = materiau
  232. this.loading = false
  233. // delay the lazyload to let the card the time to update dom
  234. // maybe not the best method
  235. setTimeout(function () {
  236. this.activateLazyLoad()
  237. }.bind(this), 5)
  238. })
  239. .catch(error => {
  240. console.warn('Issue with loadMaterial', error)
  241. Promise.reject(error)
  242. })
  243. },
  244. flagIsActive(collid) {
  245. // console.log(this.item.uuid);
  246. // console.log(this.flagcolls[collid].items_uuids);
  247. // return this.flagcolls[collid].items_uuids.indexOf(this.item.uuid) !== -1;
  248. return this.flagcolls[collid].items.indexOf(this.item.id) !== -1;
  249. },
  250. flagIsLoading(collid) {
  251. // console.log(this.item.uuid);
  252. // console.log(this.flagcolls[collid].items_uuids);
  253. return collid === this.loadingFlag;
  254. },
  255. onFlagActionCard (e) {
  256. console.log("Card onFlagActionCard", e);
  257. if (!this.loadingFlag) {
  258. let collid = e.target.getAttribute('collid');
  259. let isActive = this.flagIsActive(collid);
  260. let action = isActive ? 'unflag' : 'flag';
  261. // console.log('collid', collid);
  262. // console.log("this.item", this.item);
  263. this.loadingFlag = collid;
  264. this.flagUnflag({ action: action, id: this.item.id, collid: collid})
  265. .then(data => {
  266. console.log("onFlagActionCard then", data);
  267. this.loadingFlag = false;
  268. })
  269. }
  270. },
  271. onCloseModalCard (e) {
  272. // this.$modal.hideAll()
  273. this.$modal.hide(`modal-${this.item.id}`)
  274. },
  275. prettyFileSize(bytes){
  276. return prettyBytes(parseInt(bytes))
  277. }
  278. }
  279. }
  280. </script>
  281. <style lang="scss" scoped>
  282. </style>