main.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. import Vue from 'vue'
  2. import store from 'vuejs/store'
  3. import VUserBlock from 'vuejs/components/Block/UserBlock'
  4. import VMainContent from 'vuejs/components/Content/MainContent'
  5. import VSearchBlock from 'vuejs/components/Block/SearchBlock'
  6. import { mapState } from 'vuex'
  7. // require('theme/assets/styles/main.scss');
  8. import 'theme/assets/styles/main.scss'
  9. (function(Drupal, drupalSettings) {
  10. var MaterioTheme = function(){
  11. var _v_user_block, _v_main_content, _v_search_block;
  12. var _is_front = drupalSettings.path.isFront;
  13. console.log('drupalSettings', drupalSettings);
  14. // ___ _ _
  15. // |_ _|_ _ (_) |_
  16. // | || ' \| | _|
  17. // |___|_||_|_|\__|
  18. function init(){
  19. console.log("MaterioTheme init()")
  20. initVues()
  21. }
  22. function initVues(){
  23. initVUserBlock()
  24. initVMainContent()
  25. initVSearchBlock()
  26. }
  27. function initVUserBlock(){
  28. let mount_point = drupalSettings.user.uid !== 0 ? 'block-userblock' : 'block-userlogin';
  29. let props = {
  30. title: "",
  31. loginblock:""
  32. };
  33. switch (mount_point) {
  34. case 'block-userlogin':
  35. let $block = document.getElementById(mount_point);
  36. console.log('initVUserBlock login form html', $block);
  37. props.loginblock = $block.outerHTML.trim()
  38. break;
  39. case 'block-userblock':
  40. default:
  41. break;
  42. }
  43. _v_user_block = new Vue({
  44. store,
  45. // computed: {
  46. // ...mapState({
  47. // isloggedin: state => state.User.isloggedin
  48. // })
  49. // },
  50. created () {
  51. // if already loggedin, call store.user to get the user infos
  52. if(drupalSettings.user.uid !== 0){
  53. this.$store.commit('User/setUid', drupalSettings.user.uid)
  54. this.$store.dispatch('User/getUser')
  55. }
  56. },
  57. render: h => h(VUserBlock, {props:props})
  58. }).$mount('#'+mount_point)
  59. // console.log('initVUserBlock', _v_user_block);
  60. }
  61. function initVMainContent(){
  62. let $main_content = document.querySelector('#main-content')
  63. // console.log('main-content', $main_content);
  64. let main_html = $main_content.innerHTML
  65. _v_main_content = new Vue({
  66. store,
  67. render: h => h(VMainContent, {props:{html:main_html}})
  68. }).$mount('#main-content')
  69. // console.log('initTestVContent', v_test_content);
  70. }
  71. function initVSearchBlock(){
  72. // console.log('initVSearchBlock');
  73. let id = "block-materiosapisearchblock"
  74. let $search_block = document.getElementById(id)
  75. var formhtml = null
  76. if($search_block){
  77. // get the search form html to pass it as template to the vue
  78. // we gain display speed vs async downloaded data
  79. formhtml = $search_block.innerHTML
  80. }else{
  81. // else create the empty block to fill it later with async data
  82. $search_block = document.createElement('div')
  83. $search_block.setAttribute('id', id)
  84. let $region = document.getElementById('content-top');
  85. $region.appendChild($search_block);
  86. }
  87. // in any case create the vue
  88. _v_search_block = new Vue({
  89. store,
  90. render: h => h(VSearchBlock, {props:{blockid:id, formhtml:formhtml}})
  91. }).$mount('#'+id)
  92. }
  93. init()
  94. } // end MaterioTheme()
  95. var materiotheme = new MaterioTheme();
  96. })(Drupal, drupalSettings);