ModalCard.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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">
  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. <section v-if="material.attachments" class="attachments">
  85. <span class="label">{{ $t("materio.Attachments") }}</span>
  86. <ul>
  87. <li
  88. v-for="attachmt in material.attachments" :key="attachmt.file.fid"
  89. >
  90. <a target="_blank" :href="attachmt.file.url">{{ attachmt.file.filename}} <span>({{ prettyFileSize(attachmt.file.filesize) }})</span></a>
  91. <p v-if="attachmt.description" class="description" v-html="attachmt.description" />
  92. </li>
  93. </ul>
  94. </section>
  95. <section v-if="material.linked_materials" class="linked-materials">
  96. <span class="label">{{ $t("materio.Linked materials") }}</span>
  97. <ul>
  98. <li v-for="m in material.linked_materials" v-bind:key="m.id">
  99. <LinkedMaterialCard :item="m"/>
  100. </li>
  101. </ul>
  102. </section>
  103. </section>
  104. <section class="col col-left images" v-switcher>
  105. <figure
  106. v-for="(img, index) in material.images"
  107. :key="img.url"
  108. >
  109. <img
  110. class="lazy"
  111. v-lazy="index"
  112. :data-src="img.style_cardfull.url"
  113. :title="img.title"
  114. />
  115. <img
  116. class="blank"
  117. :src="blanksrc"
  118. @click="lightbox_index = index"
  119. >
  120. </figure>
  121. </section>
  122. <CoolLightBox
  123. :items="material.images"
  124. :index="lightbox_index"
  125. srcName="url"
  126. :loop="true"
  127. @close="lightbox_index = null">
  128. </CoolLightBox>
  129. </article>
  130. </template>
  131. <script>
  132. import { mapState, mapActions } from 'vuex'
  133. import LinkedMaterialCard from 'vuejs/components/Content/LinkedMaterialCard'
  134. import cardMixins from 'vuejs/components/cardMixins'
  135. import { MGQ } from 'vuejs/api/graphql-axios'
  136. import { print } from 'graphql/language/printer'
  137. import gql from 'graphql-tag'
  138. import materiauFields from 'vuejs/api/gql/materiaumodal.fragment.gql'
  139. const prettyBytes = require('pretty-bytes')
  140. export default {
  141. name: "ModalCard",
  142. props: ['item'],
  143. mixins: [cardMixins],
  144. components: {
  145. LinkedMaterialCard
  146. },
  147. data() {
  148. return {
  149. material: null,
  150. loading: false,
  151. blanksrc:`${drupalSettings.path.themePath}/assets/img/blank.gif`,
  152. loadingFlag: false,
  153. lightbox_index: null
  154. }
  155. },
  156. computed: {
  157. ...mapState({
  158. flagcolls: state => state.User.flagcolls,
  159. showrooms: state => state.Showrooms.showrooms_by_tid
  160. })
  161. },
  162. created () {
  163. console.log('modale item', this.item)
  164. this.loadMaterial()
  165. },
  166. methods: {
  167. ...mapActions({
  168. flagUnflag: 'User/flagUnflag'
  169. }),
  170. loadMaterial(){
  171. console.log('loadMaterial', this.item.id)
  172. this.loading = true
  173. let ast = gql`{
  174. materiau(id: ${this.item.id}, lang: "${drupalDecoupled.lang_code}") {
  175. ...MateriauFields
  176. }
  177. }
  178. ${ materiauFields }
  179. `
  180. MGQ.post('', { query: print(ast)
  181. })
  182. .then(({ data:{data:{materiau}}}) => {
  183. console.log('loadMaterial material loaded', materiau )
  184. this.material = materiau
  185. this.loading = false
  186. // delay the lazyload to let the card the time to update dom
  187. // maybe not the best method
  188. setTimeout(function () {
  189. this.activateLazyLoad()
  190. }.bind(this), 5)
  191. })
  192. .catch(error => {
  193. console.warn('Issue with loadMaterial', error)
  194. Promise.reject(error)
  195. })
  196. },
  197. flagIsActive(collid) {
  198. // console.log(this.item.uuid);
  199. // console.log(this.flagcolls[collid].items_uuids);
  200. // return this.flagcolls[collid].items_uuids.indexOf(this.item.uuid) !== -1;
  201. return this.flagcolls[collid].items.indexOf(this.item.id) !== -1;
  202. },
  203. flagIsLoading(collid) {
  204. // console.log(this.item.uuid);
  205. // console.log(this.flagcolls[collid].items_uuids);
  206. return collid === this.loadingFlag;
  207. },
  208. onFlagActionCard (e) {
  209. console.log("Card onFlagActionCard", e);
  210. if (!this.loadingFlag) {
  211. let collid = e.target.getAttribute('collid');
  212. let isActive = this.flagIsActive(collid);
  213. let action = isActive ? 'unflag' : 'flag';
  214. // console.log('collid', collid);
  215. // console.log("this.item", this.item);
  216. this.loadingFlag = collid;
  217. this.flagUnflag({ action: action, id: this.item.id, collid: collid})
  218. .then(data => {
  219. console.log("onFlagActionCard then", data);
  220. this.loadingFlag = false;
  221. })
  222. }
  223. },
  224. onCloseModalCard (e) {
  225. // this.$modal.hideAll()
  226. this.$modal.hide(`modal-${this.item.id}`)
  227. },
  228. prettyFileSize(bytes){
  229. return prettyBytes(parseInt(bytes))
  230. }
  231. }
  232. }
  233. </script>
  234. <style lang="scss" scoped>
  235. </style>