ModalCard.vue 10 KB

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