project.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643
  1. // https://codeburst.io/dynamic-modules-with-vuex-and-vue-b9c481ca792
  2. // https://www.brophy.org/post/instance-aware-vuex-modules-1/
  3. // import qs from 'querystring'
  4. // import { REST } from 'api/rest-axios'
  5. import { GRAPHQL } from 'api/graphql-axios'
  6. import Query from 'graphql-query-builder'
  7. import { VIMEO } from 'api/vimeo-axios'
  8. import qs from 'querystring'
  9. import * as THREE from 'three'
  10. import { ThreeBSP } from 'three-js-csg-es6'
  11. export default {
  12. namespaced: true,
  13. // initial state
  14. state: {
  15. debug: true,
  16. obj3d: null,
  17. size: { x: 0, y: 0, z: 0 },
  18. position: { x: 0, y: 0, z: 0 },
  19. walls3dObj: null,
  20. wallsPos: null,
  21. top3dObj: null,
  22. topPos: null,
  23. topColor: null,
  24. floor3dObj: null,
  25. floorPos: null,
  26. florrColor: null,
  27. levels3dObj: null,
  28. levelsPos: null,
  29. wall: {
  30. wallW: 0.001,
  31. // dig windows on face and back
  32. winW: 2 + Math.random() * 2,
  33. // winH: 4 + Math.random() * 4,
  34. winH: 0,
  35. margin: 2,
  36. nbrWinX: 0,
  37. paddingX: 0,
  38. nbrWinY: 0,
  39. paddingY: 0,
  40. nbrWinZ: 0,
  41. paddingZ: 0
  42. },
  43. contents: {},
  44. contents_size_factor: 1, // factor to get the contents (grid) size proportional to windows
  45. contentTypes: ['visible', 'context', 'process', 'concept'],
  46. grids: null,
  47. gridCel: {
  48. width: 6,
  49. height: 4.5
  50. },
  51. gridsContentPlaced: {},
  52. // gridBebug3dObj: null,
  53. activeLevel: 'visibles'
  54. },
  55. // getters
  56. getters: {
  57. position: (state) => {
  58. return state.position
  59. },
  60. size: (state) => {
  61. return state.size
  62. },
  63. createGradientCanvas: (state) => (c1, c2) => {
  64. var ctx = document.createElement('canvas').getContext('2d')
  65. ctx.canvas.width = 1024
  66. ctx.canvas.height = 1024
  67. var lingrad = ctx.createLinearGradient(0, 0, 0, 1024)
  68. lingrad.addColorStop(0, c1)
  69. lingrad.addColorStop(1, c2)
  70. ctx.fillStyle = lingrad
  71. ctx.fillRect(0, 0, 1024, 1024)
  72. return ctx.canvas
  73. }
  74. },
  75. // mutations
  76. mutations: {
  77. setSize: (state, size) => {
  78. state.size = size
  79. },
  80. setPosition: (state, pos) => {
  81. state.position = pos
  82. },
  83. setWalls3dObj: (state, obj) => { state.walls3dObj = obj },
  84. setWallsPos: (state, pos) => { state.wallsPos = pos },
  85. setTop3dObj: (state, obj) => { state.top3dObj = obj },
  86. setTopPos: (state, pos) => { state.topPos = pos },
  87. setFloor3dObj: (state, obj) => { state.floor3dObj = obj },
  88. setFloorPos: (state, pos) => { state.floorPos = pos },
  89. setTopColor: (state, col) => { state.topColor = col },
  90. setFloorColor: (state, col) => { state.floorColor = col },
  91. setLevels3dObj: (state, obj) => { state.levels3dObj = obj },
  92. setLevelsPos: (state, pos) => { state.levelsPos = pos },
  93. setContents: (state, contents) => { state.contents = contents },
  94. setGrids: (state, grids) => { state.grids = grids },
  95. // setDebugGrids3dObj: (state, obj) => { state.gridBebug3dObj = obj },
  96. shiftGrid: (state, c) => {
  97. let side
  98. switch (c.face) {
  99. case 'back':
  100. case 'front':
  101. side = 'x'
  102. break
  103. case 'left':
  104. case 'right':
  105. side = 'z'
  106. break
  107. }
  108. // console.log(`shiftGrid side: ${side}, face: ${c.face}, type: ${c.type}, id: ${c.id}`)
  109. let p = state.grids[side][c.face][c.type].pop()
  110. if (!state.gridsContentPlaced[side]) {
  111. state.gridsContentPlaced[side] = {}
  112. }
  113. if (!state.gridsContentPlaced[side][c.face]) {
  114. state.gridsContentPlaced[side][c.face] = {}
  115. }
  116. if (!state.gridsContentPlaced[side][c.face][c.type]) {
  117. state.gridsContentPlaced[side][c.face][c.type] = {}
  118. }
  119. state.gridsContentPlaced[side][c.face][c.type][c.id] = p
  120. },
  121. setActiveLevel: (state, l) => {
  122. state.activeLevel = l
  123. }
  124. },
  125. // actions
  126. actions: {
  127. init ({ dispatch, commit, state, rootGetters }) {
  128. console.log(`Init Project module ${state.id}`, state)
  129. dispatch('sizingBuilding')
  130. dispatch('build3dObjs')
  131. },
  132. sizingBuilding ({ dispatch, commit, state, rootGetters }) {
  133. console.log('sizingBuilding, state', state)
  134. let totalW = rootGetters['Projects/totalW']
  135. // console.log('totalW', totalW)
  136. let margin = rootGetters['Projects/marginBetweenBuildings']
  137. // console.log('margin', margin)
  138. // positioning buildings on x regarding the widths
  139. // & setting up the window sizing
  140. // & setting up the content grid
  141. // let wall, a
  142. // let grid
  143. // X POS
  144. let x
  145. if (state.index === 0) {
  146. // if it's the first
  147. x = -1 * totalW / 2 + state.size.x / 2
  148. } else {
  149. // else get the precedent pos
  150. let prevProjID = rootGetters['Projects/projectID'](state.index - 1)
  151. // console.log('prevProjID', prevProjID)
  152. let prevProjPos = rootGetters[`project:${prevProjID}/position`]
  153. // console.log(`project:${prevProjID}/position.x`, prevProjPos.x)
  154. let prevProjSize = rootGetters[`project:${prevProjID}/size`]
  155. // console.log(`project:${prevProjID}/size.x`, prevProjSize.x)
  156. // console.log('state.size.x', state.size.x)
  157. // prev X + alf of prev size x + margin + half of current size x
  158. x = prevProjPos.x + prevProjSize.x / 2 + margin + state.size.x / 2
  159. }
  160. // console.log('x', x)
  161. commit('setPosition', {
  162. x: x,
  163. // y: -1 * state.size.y / 2 + 10 + Math.random() * 30, // -10 + Math.random() * this.size.y / 2
  164. y: -state.size.y / 4,
  165. z: 0// -10 + Math.random() * 10
  166. })
  167. // WINDOWS
  168. let a = 0
  169. state.wall.nbrWinX = Math.floor((state.size.x - 2 * state.wall.margin) / state.wall.winW)
  170. // removing windows on X until padding is enough
  171. while (state.wall.paddingX < 0.4) {
  172. state.wall.nbrWinX -= a
  173. state.wall.paddingX = (state.size.x - 2 * state.wall.margin - state.wall.winW * state.wall.nbrWinX) / (state.wall.nbrWinX - 1)
  174. a++
  175. }
  176. a = 0
  177. // state.wall.nbrWinY = Math.floor((state.size.y - 2 * state.wall.margin) / state.wall.winH)
  178. state.wall.nbrWinY = 4 * 10
  179. state.wall.winH = (state.size.y - 2 * state.wall.margin) / state.wall.nbrWinY
  180. // removing windows on Y until padding is enough
  181. while (state.wall.paddingY < 0.4) {
  182. state.wall.nbrWinY -= a
  183. state.wall.paddingY = (state.size.y - 2 * state.wall.margin - state.wall.winH * state.wall.nbrWinY) / (state.wall.nbrWinY - 1)
  184. a += 4
  185. }
  186. a = 0
  187. state.wall.nbrWinZ = Math.floor((state.size.z - 2 * state.wall.margin) / state.wall.winW)
  188. while (state.wall.paddingZ < 0.4) {
  189. state.wall.nbrWinZ -= a
  190. state.wall.paddingZ = (state.size.z - 2 * state.wall.margin - state.wall.winW * state.wall.nbrWinZ) / (state.wall.nbrWinZ - 1)
  191. a++
  192. }
  193. // CONTENTS GRID
  194. // create grids for right/left & face/back
  195. let grids = {
  196. x: { front: {}, back: {} },
  197. z: { left: {}, right: {} }
  198. }
  199. // console.log('grids', grids)
  200. let grid, rows, cols, t, cel, paddingH
  201. // console.log('Object.keys(grids)', Object.keys(grids))
  202. // Object.keys(grids).map(function (side) {
  203. Object.keys(grids).forEach(side => {
  204. // console.log('# GRID side:', side)
  205. // create one grid for each face x & z
  206. // will then clone both for each face front/back or left/right)
  207. grid = {}
  208. // calculate cols nbr regarding the face orientation
  209. switch (side) {
  210. case 'z':
  211. // cols = state.wall.nbrWinZ / state.contents_size_factor
  212. cols = Math.floor(state.size.z / state.gridCel.width)
  213. // compute padding to centering the grid horizontaly
  214. paddingH = (state.size.z - cols * state.gridCel.width) / 2
  215. break
  216. case 'x':
  217. // cols = state.wall.nbrWinX / state.contents_size_factor
  218. cols = Math.floor(state.size.x / state.gridCel.width)
  219. // compute padding to centering the grid horizontaly
  220. paddingH = (state.size.x - cols * state.gridCel.width) / 2
  221. break
  222. }
  223. // calculate rows
  224. // rows = state.wall.nbrWinY / state.contents_size_factor
  225. rows = Math.floor(state.size.y / state.gridCel.height)
  226. // dispatch grid rows on to 4 levels (t)
  227. for (var m = rows - 1; m > 0; m--) { // rows
  228. if (m > rows / 4 * 3 + 1) {
  229. t = state.contentTypes[0]
  230. } else if (m > rows / 4 * 2 + 1) {
  231. t = state.contentTypes[1]
  232. } else if (m > rows / 4 + 1) {
  233. t = state.contentTypes[2]
  234. } else {
  235. t = state.contentTypes[3]
  236. }
  237. // create level if not exists
  238. if (!grid[t]) {
  239. grid[t] = []
  240. // // skip the first level's row as we will display wall title
  241. // continue
  242. }
  243. // create cols for each rows
  244. for (var l = cols - 1; l >= 0; l--) { // cols
  245. // cel = { y: margin + state.wall.winH * state.contents_size_factor * m }
  246. cel = { y: state.position.y - state.size.y / 2 + state.gridCel.height * m }
  247. switch (side) {
  248. case 'z':
  249. // cel.z = margin + state.wall.winW * state.contents_size_factor * l
  250. cel.z = state.position.z - state.size.z / 2 + paddingH + state.gridCel.width * l
  251. break
  252. case 'x':
  253. // cel.x = margin + state.wall.winW * state.contents_size_factor * l
  254. cel.x = state.position.x - state.size.x / 2 + paddingH + state.gridCel.width * l
  255. break
  256. }
  257. grid[t].push(cel)
  258. }
  259. }
  260. // console.log('grid', grid)
  261. // apply grid for each face of each side
  262. // Object.keys(grids[side]).map(function (face) {
  263. Object.keys(grids[side]).forEach(face => {
  264. // console.log('## GRID face:', face)
  265. // // shuffling the grid
  266. // for (var i = 0; i < state.contentTypes.length; i++) {
  267. // for (let n = grid[state.contentTypes[i]].length - 1; n > 0; n--) {
  268. // const o = Math.floor(Math.random() * n)
  269. // const temp = grid[state.contentTypes[i]][n]
  270. // grid[state.contentTypes[i]][n] = grid[state.contentTypes[i]][o]
  271. // grid[state.contentTypes[i]][o] = temp
  272. // }
  273. // }
  274. // // console.log('shuffeld grid', grid)
  275. // cloning the grid for each face
  276. // grids[side][face] = { ...grid } this is not working as it is not deep copy
  277. grids[side][face] = JSON.parse(JSON.stringify(grid))
  278. // comput common values
  279. let x, z, ry
  280. switch (face) {
  281. case 'front': // side x
  282. z = state.position.z + state.size.z / 2 - 0.1
  283. ry = 180
  284. break
  285. case 'back': // side x
  286. z = state.position.z - state.size.z / 2 + 0.1
  287. ry = 0
  288. break
  289. case 'left': // side z
  290. x = state.position.x - state.size.x / 2 + 0.1
  291. ry = 90
  292. break
  293. case 'right': // side z
  294. x = state.position.x + state.size.x / 2 - 0.1
  295. ry = -90
  296. break
  297. }
  298. // loop through levels
  299. // apply common values
  300. // Object.keys(grids[side][face]).map(function (level) {
  301. Object.keys(grids[side][face]).forEach(level => {
  302. // console.log(`${side} ${face} ${level} x: ${x}, z: ${z}, ry: ${ry}`)
  303. // loop through all cels of the level
  304. for (var i = 0; i < grids[side][face][level].length; i++) {
  305. grids[side][face][level][i].ry = ry
  306. switch (side) {
  307. case 'z':
  308. grids[side][face][level][i].x = x
  309. break
  310. case 'x':
  311. grids[side][face][level][i].z = z
  312. break
  313. }
  314. }
  315. })
  316. })
  317. })
  318. commit('setGrids', grids)
  319. console.log('state.grids', state.grids)
  320. },
  321. build3dObjs ({ dispatch, commit, state, getters, rootGetters }) {
  322. console.log('build3dObjs')
  323. // http://learningthreejs.com/blog/2011/12/10/constructive-solid-geometry-with-csg-js/
  324. let frontGeom = new THREE.BoxGeometry(state.size.x, state.size.y, state.wall.wallW)
  325. let frontMesh = new THREE.Mesh(frontGeom)
  326. frontMesh.position.z = 0.5 * state.size.z
  327. let frontBSP = new ThreeBSP(frontMesh)
  328. // https://medium.com/techtrument/multithreading-javascript-46156179cf9a
  329. let winGeom = new THREE.BoxGeometry(state.wall.winW, state.wall.winH, state.wall.wallW)
  330. let winMesh = new THREE.Mesh(winGeom)
  331. let windowsGeom = new THREE.Geometry()
  332. for (var i = 0; i < state.wall.nbrWinX; i++) {
  333. for (var j = 0; j < state.wall.nbrWinY; j++) {
  334. winMesh.position.z = 0.5 * state.size.z
  335. winMesh.position.x = -0.5 * state.size.x + state.wall.margin + state.wall.winW * 0.5 + i * (state.wall.winW + state.wall.paddingX)
  336. winMesh.position.y = 0.5 * state.size.y - state.wall.margin - state.wall.winH * 0.5 - j * (state.wall.winH + state.wall.paddingY)
  337. // winMesh.updateMatrix()
  338. windowsGeom.mergeMesh(winMesh)
  339. }
  340. }
  341. let windowsBSP = new ThreeBSP(windowsGeom)
  342. let frontWindowedBSP = frontBSP.subtract(windowsBSP)
  343. // console.log('state.Faces_opaques', state.Faces_opaques)
  344. let backWindowedMesh
  345. if (state.Faces_opaques === 3) {
  346. backWindowedMesh = frontMesh.clone()
  347. } else {
  348. let frontWindowedMesh = frontWindowedBSP.toMesh()
  349. backWindowedMesh = frontWindowedMesh.clone()
  350. }
  351. backWindowedMesh.position.z = -0.5 * state.size.z
  352. let backWindowedBSP = new ThreeBSP(backWindowedMesh)
  353. let rightGeom = new THREE.BoxGeometry(state.wall.wallW, state.size.y, state.size.z)
  354. let rightMesh = new THREE.Mesh(rightGeom)
  355. rightMesh.position.x = 0.5 * state.size.x
  356. // rightMesh.position.z = 0.5 * state.size.z
  357. let rightBSP = new ThreeBSP(rightMesh)
  358. let leftMesh = rightMesh.clone()
  359. leftMesh.position.x = -0.5 * state.size.x
  360. // leftMesh.position.z = 0.5 * state.size.z
  361. let leftBSP = new ThreeBSP(leftMesh)
  362. let buildingBSP = frontWindowedBSP.union(rightBSP)
  363. buildingBSP = buildingBSP.union(backWindowedBSP)
  364. buildingBSP = buildingBSP.union(leftBSP)
  365. // convert back to three.js mesh
  366. let building = buildingBSP.toMesh()
  367. // create a classical material for building
  368. // let topColor = `hsla(201, 100%, 95%, 1)`
  369. let hTop = Math.round(190 + Math.random() * 20)
  370. let sTop = Math.round(20 + Math.random() * 60)
  371. let lTop = Math.round(75)
  372. // let hFloor = Math.round(205 + Math.random() * 10)
  373. let hFloor = hTop
  374. // let sFloor = Math.round(30 + Math.random() * 40)
  375. let sFloor = sTop
  376. // let lFloor = Math.round(10 + Math.random() * 20)
  377. let lFloor = Math.round(10)
  378. let topColor = `hsla(${hTop}, ${sTop}%, ${lTop}%, 1)`
  379. commit('setTopColor', topColor)
  380. let floorColor = `hsla(${hFloor}, ${sFloor}%, ${lFloor}%, 1)`
  381. commit('setFloorColor', floorColor)
  382. let gradientTexture = new THREE.CanvasTexture(getters.createGradientCanvas(topColor, floorColor))
  383. let materialOpts = {
  384. color: 0xffffff,
  385. side: THREE.DoubleSide,
  386. shininess: 30,
  387. map: gradientTexture
  388. }
  389. building.material = new THREE.MeshPhongMaterial(materialOpts)
  390. // commiting walls
  391. commit('setWalls3dObj', building)
  392. let buildingPos = { ...state.position, ...{ z: state.position.z + 0.5 * state.size.z } }
  393. commit('setWallsPos', buildingPos)
  394. // TOP & FLOOR
  395. let topGeom = new THREE.BoxGeometry(state.size.x, state.wall.wallW, state.size.z)
  396. let topOpts = {
  397. color: new THREE.Color(`hsl(${hTop}, ${sTop}%, ${lTop}%)`),
  398. shininess: 30
  399. }
  400. let topMat = new THREE.MeshPhongMaterial(topOpts)
  401. let topMesh = new THREE.Mesh(topGeom, topMat)
  402. commit('setTop3dObj', topMesh)
  403. let topPosition = { ...state.position, ...{ y: state.position.y + 0.5 * state.size.y } }
  404. commit('setTopPos', topPosition)
  405. let floorOpts = {
  406. color: new THREE.Color(`hsl(${hFloor}, ${sFloor}%, ${lFloor}%)`),
  407. shininess: 10
  408. }
  409. let floorMat = new THREE.MeshPhongMaterial(floorOpts)
  410. let floorMesh = new THREE.Mesh(topGeom, floorMat)
  411. commit('setFloor3dObj', floorMesh)
  412. let floorPosition = { ...state.position, ...{ y: state.position.y - 0.5 * state.size.y } }
  413. commit('setFloorPos', floorPosition)
  414. // LEVELS
  415. let levelGeom = new THREE.BoxGeometry(state.size.x - state.wall.wallW * 2, 0.1, state.size.z - state.wall.wallW * 2)
  416. let levelMesh = new THREE.Mesh(levelGeom)
  417. let levelBSP = new ThreeBSP(levelMesh)
  418. let levelHoleGeom = new THREE.BoxGeometry(state.size.x - state.wall.wallW * 2 - 3, 0.1, state.size.z - state.wall.wallW * 2 - 3)
  419. let levelHoleMesh = new THREE.Mesh(levelHoleGeom)
  420. let levelHoleBSP = new ThreeBSP(levelHoleMesh)
  421. levelBSP = levelBSP.subtract(levelHoleBSP)
  422. levelMesh = levelBSP.toMesh()
  423. let levelsGeom = new THREE.Geometry()
  424. for (var k = -1; k < 2; k++) {
  425. levelMesh.position.y = k * state.size.y * 0.25
  426. levelsGeom.mergeMesh(levelMesh)
  427. }
  428. let levelsOpts = {
  429. color: new THREE.Color(`hsl(${hTop}, ${sTop}%, ${lTop}%)`),
  430. shininess: 10
  431. }
  432. let levelsMat = new THREE.MeshPhongMaterial(levelsOpts)
  433. let levelsMesh = new THREE.Mesh(levelsGeom, levelsMat)
  434. commit('setLevels3dObj', levelsMesh)
  435. let levelsPos = { ...state.position }
  436. commit('setLevelsPos', levelsPos)
  437. // // DEBUG GRID
  438. // if (state.debug) {
  439. // let celDebugGeom = new THREE.BoxGeometry(1, 1, 0.01)
  440. // let celDebugMesh = new THREE.Mesh(celDebugGeom)
  441. // let gridsDebugGeom = new THREE.Geometry()
  442. // Object.keys(state.grids).map(function (side) {
  443. // Object.keys(state.grids[side]).map(function (face) {
  444. // Object.keys(state.grids[side][face]).map(function (level) {
  445. // state.grids[side][face][level].forEach((item, i) => {
  446. // // console.log(`grid ${side} ${face} ${level} ${i}`, item)
  447. // celDebugMesh.position.y = state.grids[side][face][level][i].y
  448. // celDebugMesh.position.x = state.grids[side][face][level][i].x
  449. // celDebugMesh.position.z = state.grids[side][face][level][i].z
  450. // celDebugMesh.rotation.y = state.grids[side][face][level][i].ry
  451. // gridsDebugGeom.mergeMesh(celDebugMesh)
  452. // })
  453. // })
  454. // })
  455. // })
  456. // let gridsDebugOpts = {
  457. // color: 0xff0000
  458. // }
  459. // let gridsDebugMat = new THREE.MeshPhongMaterial(gridsDebugOpts)
  460. // let gridsDebugMesh = new THREE.Mesh(gridsDebugGeom, gridsDebugMat)
  461. // commit('setDebugGrids3dObj', gridsDebugMesh)
  462. // }
  463. },
  464. getContents ({ dispatch, commit, state }) {
  465. return new Promise((resolve, reject) => {
  466. // get the list of corpuses (aka authors)
  467. dispatch('loadContents')
  468. .then(({ data: { data: { project } = null } }) => {
  469. console.log('graphql contents', project)
  470. dispatch('computeContents', project)
  471. .then((contents) => {
  472. console.log('computed contents', contents)
  473. commit('setContents', project)
  474. })
  475. })
  476. .catch((error) => {
  477. console.warn('Issue with getContents', error)
  478. Promise.reject(error)
  479. })
  480. })
  481. },
  482. loadContents ({ dispatch, commit, state }) {
  483. console.log('loadContents')
  484. let contentsQuery = new Query('project', { id: state.id })
  485. let visiblesQuery = new Query('visibles')
  486. visiblesQuery.filter({ Published: true })
  487. visiblesQuery.find(['id', 'Name', 'Text2', 'Vimeo', 'Url', 'categories'])
  488. contentsQuery.find([visiblesQuery])
  489. console.log('contentsQuery', `${contentsQuery}`)
  490. return GRAPHQL.post('', { query: `query {
  491. project(id: "${state.id}") {
  492. visibles(
  493. where: {Published: "true"},
  494. sort: "Weight:asc"
  495. ){
  496. id
  497. Name
  498. Media {
  499. url
  500. size
  501. }
  502. Text2
  503. Vimeo
  504. Url
  505. categories
  506. country{
  507. id
  508. Name
  509. }
  510. Weight
  511. }
  512. contexts(
  513. where: { Published: "true" },
  514. sort: "Weight:asc"
  515. ){
  516. id
  517. Name
  518. Images {
  519. url
  520. size
  521. }
  522. Text2
  523. Vimeo
  524. Url
  525. country{
  526. id
  527. Name
  528. }
  529. }
  530. processes(
  531. where: { Published: "true" },
  532. sort: "Weight:asc"
  533. ){
  534. id
  535. Name
  536. Media {
  537. url
  538. size
  539. }
  540. Text2
  541. Vimeo
  542. Url
  543. country{
  544. id
  545. Name
  546. }
  547. }
  548. concepts(
  549. where: { Published: "true" },
  550. sort: "Weight:asc"
  551. ){
  552. id
  553. Name
  554. Images {
  555. url
  556. size
  557. }
  558. Text2
  559. Vimeo
  560. }
  561. }
  562. }` })
  563. },
  564. computeContents ({ dispatch, commit, state }, contents) {
  565. console.log('computeContents')
  566. return Promise.all(Object.keys(contents).map(function (level) {
  567. return Promise.all(contents[level].map(function (content) {
  568. if (content.Vimeo) {
  569. // console.log('Vimeo', content.Vimeo)
  570. // GET https://vimeo.com/api/oembed.json?url=https%3A//vimeo.com/286898202&width=480&height=360
  571. let params = {
  572. url: content.Vimeo,
  573. width: 1280,
  574. height: 720,
  575. responsive: true
  576. }
  577. let q = qs.stringify(params)
  578. return VIMEO.get('?' + q, {})
  579. .then(({ data }) => {
  580. // console.log('Vimeo data', data)
  581. content.Vimeo = data// thumbnail_url_with_play_button
  582. return content
  583. })
  584. .catch((error) => {
  585. console.warn('Issue with vimeo', error)
  586. })
  587. } else {
  588. return content
  589. }
  590. })).then((cts) => {
  591. // return an object with the right level (visible, etc, ...)
  592. // console.log(`${level} cts`, cts)
  593. let o = {}
  594. o[level] = cts
  595. return o
  596. })
  597. })).then((a) => {
  598. // return an object with the right keys (visible, etc, ...)
  599. console.log('a', a)
  600. let o = {}
  601. for (var i = 0; i < a.length; i++) {
  602. o = { ...o, ...a[i] }
  603. }
  604. return o
  605. })
  606. }
  607. // getGridPos ({ state, commit }) {
  608. // let p = state.grid[0]
  609. // commit('shiftGrid')
  610. // Promise.resolve(p)
  611. // }
  612. }
  613. }