displayLinks.js 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. const linksBlock = document.getElementById('displayLinks')
  2. var localStorage = window.localStorage
  3. async function loadLinks(){
  4. linksBlock.innerHTML = ''
  5. let title = document.createElement('h5')
  6. title.innerHTML = 'Your generated SIN3D-app links'
  7. linksBlock.append(title)
  8. // retrieve expe links if exists
  9. if (localStorage.getItem('p3d-user-links')){
  10. expes_link = JSON.parse(localStorage.getItem('p3d-user-links'))
  11. for (expe in expes_link){
  12. let card = document.createElement('div')
  13. card.className = 'card border-light mb-12'
  14. card.style.border = '1px solid'
  15. let cardHeader = document.createElement('div')
  16. cardHeader.className = 'card-header'
  17. cardHeader.innerHTML = expe
  18. let cardBody = document.createElement('div')
  19. let cardBodyList = document.createElement('ul')
  20. cardBodyList.className = 'list-group border-light'
  21. for (experimentId in expes_link[expe]){
  22. for (userId in expes_link[expe][experimentId]){
  23. let userValue = expes_link[expe][experimentId][userId]
  24. let cardBodyItem = document.createElement('li')
  25. cardBodyItem.className = 'list-group-item d-flex justify-content-between align-items-center border-light'
  26. cardBodyItem.style.border = '1px solid'
  27. cardBodyItem.innerHTML = '<ul class="fa-ul">\
  28. <li><p><i class="fa-li fas fa-flask"></i> ' + experimentId + '</p></li> \
  29. <li><p><i class="fa-li fas fa-id-badge"></i> ' + userId + '</p></li>\
  30. </ul>\
  31. <a href="' + userValue.link + '"><span class="badge badge-primary badge-pill">Launch experiment <i class="fas fa-external-link-alt"></i></span></a>'
  32. cardBodyList.append(cardBodyItem)
  33. }
  34. }
  35. cardBody.append(cardBodyList)
  36. card.append(cardHeader)
  37. card.append(cardBody)
  38. linksBlock.append(card)
  39. }
  40. }
  41. else{
  42. let card = document.createElement('div')
  43. card.className = 'card border-warning mb-12'
  44. card.style.border = '1px solid'
  45. let cardHeader = document.createElement('div')
  46. cardHeader.className = 'card-header'
  47. cardHeader.innerHTML = 'Generated links information'
  48. let cardBody = document.createElement('div')
  49. cardBody.className = 'card-body'
  50. let bodyTitle = document.createElement('h4')
  51. bodyTitle.className = 'card-title'
  52. bodyTitle.innerHTML = 'No experiment links available'
  53. let bodyText = document.createElement('p')
  54. bodyText.className = 'card-text'
  55. bodyText.innerHTML = 'If you want to generate your experiment link, please use the form on the left'
  56. cardBody.append(bodyTitle)
  57. cardBody.append(bodyText)
  58. card.append(cardHeader)
  59. card.append(cardBody)
  60. linksBlock.append(card)
  61. }
  62. }
  63. loadLinks()