ModalCard.vue 10 KB

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