Browse Source

added fix option to eslint

Bachir Soussi Chiadmi 3 years ago
parent
commit
ed9e62718c

+ 7 - 2
.eslintrc.js

@@ -11,10 +11,14 @@ module.exports = {
   ],
   plugins: [
     'vue',
-    'vue-a11y'
+    'vue-a11y',
+    'no-autofix'
   ],
   rules: {
     'no-unused-vars': ["warn"],
+    'camelcase': 'warn',
+    'eqeqeq': 'warn',
+    'no-redeclare': 'warn'
   },
   ignorePatterns: [
     "vendor/**",
@@ -33,6 +37,7 @@ module.exports = {
     "Modernizr": true,
     "Popper": true,
     "Sortable": true,
-    "CKEDITOR": true
+    "CKEDITOR": true,
+    "drupalDecoupled": true
   }
 }

+ 1 - 0
build/webpack.config.base.js

@@ -82,6 +82,7 @@ module.exports = {
     }),
     new VueLoaderPlugin(),
     new ESLintPlugin({
+      fix: true
       // exclude: ['node_modules', 'vendor', 'web/core']
       // cache: false,
       // ignore: true,

+ 15 - 0
package-lock.json

@@ -6402,6 +6402,15 @@
         }
       }
     },
+    "eslint-plugin-no-autofix": {
+      "version": "1.0.1",
+      "resolved": "https://registry.npmjs.org/eslint-plugin-no-autofix/-/eslint-plugin-no-autofix-1.0.1.tgz",
+      "integrity": "sha512-ZwQF1S+tsl9alr8DuoHX9KcNI+BxCK+D08I1n6NXlitIJg3AB+1EtHYMoxz0LFKKsewoUYo2M4QcHZxGqV1T7w==",
+      "dev": true,
+      "requires": {
+        "eslint-rule-composer": "^0.3.0"
+      }
+    },
     "eslint-plugin-node": {
       "version": "11.1.0",
       "resolved": "https://registry.npmjs.org/eslint-plugin-node/-/eslint-plugin-node-11.1.0.tgz",
@@ -6576,6 +6585,12 @@
         }
       }
     },
+    "eslint-rule-composer": {
+      "version": "0.3.0",
+      "resolved": "https://registry.npmjs.org/eslint-rule-composer/-/eslint-rule-composer-0.3.0.tgz",
+      "integrity": "sha512-bt+Sh8CtDmn2OajxvNO+BX7Wn4CIWMpTRm3MaiKPCQcnnlm0CS2mhui6QaoeQugs+3Kj2ESKEEGJUdVafwhiCg==",
+      "dev": true
+    },
     "eslint-scope": {
       "version": "4.0.3",
       "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-4.0.3.tgz",

+ 1 - 0
package.json

@@ -44,6 +44,7 @@
     "eslint-config-standard": "^16.0.2",
     "eslint-plugin-import": "^2.22.1",
     "eslint-plugin-jsx-a11y": "^6.4.1",
+    "eslint-plugin-no-autofix": "^1.0.1",
     "eslint-plugin-node": "^11.1.0",
     "eslint-plugin-prettier": "^3.1.4",
     "eslint-plugin-promise": "^4.2.1",

File diff suppressed because it is too large
+ 4 - 92
web/themes/custom/materiotheme/assets/dist/main.css


File diff suppressed because it is too large
+ 0 - 107
web/themes/custom/materiotheme/assets/dist/main.js


+ 17 - 0
web/themes/custom/materiotheme/assets/dist/main.js.LICENSE.txt

@@ -0,0 +1,17 @@
+/*!
+ * Vue.js v2.6.12
+ * (c) 2014-2020 Evan You
+ * Released under the MIT License.
+ */
+
+/*!
+ * vue-infinite-loading v2.4.5
+ * (c) 2016-2020 PeachScript
+ * MIT License
+ */
+
+/*!
+ * vuex v3.6.0
+ * (c) 2020 Evan You
+ * @license MIT
+ */

+ 86 - 89
web/themes/custom/materiotheme/assets/scripts/main.js

@@ -1,16 +1,17 @@
+/* eslint-disable import/first */
 import Vue from 'vue'
 
-import InfiniteLoading from 'vue-infinite-loading';
+import InfiniteLoading from 'vue-infinite-loading'
 Vue.use(InfiniteLoading, {
   props: {
-    spinner: 'spiral',
+    spinner: 'spiral'
     // slots.noMore: ''
-  },
+  }
   // system: {
   //   throttleLimit: 50,
   //   /* other settings need to configure */
   // }
-});
+})
 
 // import vueVimeoPlayer from 'vue-vimeo-player'
 // Vue.use(vueVimeoPlayer)
@@ -31,43 +32,40 @@ import { mapState } from 'vuex'
 // require('theme/assets/styles/main.scss');
 import 'theme/assets/styles/main.scss'
 
-(function(Drupal, drupalSettings, drupalDecoupled) {
+(function (Drupal, drupalSettings, drupalDecoupled) {
+  const MaterioTheme = function () {
+    let _v_sitebranding_block, _v_user_block, _v_header_menu,
+      _v_pagetitle_block, _v_search_block,
+      _v_main_content
+    const _is_front = drupalSettings.path.isFront
 
-  var MaterioTheme = function(){
-
-    var _v_sitebranding_block, _v_user_block, _v_header_menu
-      , _v_pagetitle_block, _v_search_block
-      , _v_main_content;
-    var _is_front = drupalSettings.path.isFront;
-
-
-    console.log('drupalSettings', drupalSettings);
+    console.log('drupalSettings', drupalSettings)
 
     //  ___      _ _
     // |_ _|_ _ (_) |_
     //  | || ' \| |  _|
     // |___|_||_|_|\__|
-    function init(){
-      console.log("MaterioTheme init()")
+    function init () {
+      console.log('MaterioTheme init()')
       initVues()
     }
 
-    function checkNoVuePages(){
+    function checkNoVuePages () {
       // return drupalDecoupled.sys_path != '/cart'
       // && drupalDecoupled.sys_path.indexOf('checkout') != 1;
-      if( drupalDecoupled.route_name.indexOf('commerce') == -1 &&
+      if (drupalDecoupled.route_name.indexOf('commerce') == -1 &&
           drupalDecoupled.route_name.indexOf('flagging_collection') == -1 &&
-          drupalDecoupled.route_name.indexOf('user') == -1){
-        return false;
-      }else{
-        return true;
+          drupalDecoupled.route_name.indexOf('user') == -1) {
+        return false
+      } else {
+        return true
       }
     }
 
-    function initVues(){
+    function initVues () {
       // only launch views if we are not in commerce pages
-      if(!checkNoVuePages()){
-        initVRouter();
+      if (!checkNoVuePages()) {
+        initVRouter()
         initVSiteBrandingBlock()
         initVPagetitleBlock()
         initVHeaderMenu()
@@ -77,19 +75,19 @@ import 'theme/assets/styles/main.scss'
       initVUserBlock()
     }
 
-    function initVRouter(){
+    function initVRouter () {
       // we need this to update the title and body classes while using history nav
       router.beforeEach((to, from, next) => {
         // console.log('router beforeEach to ', to);
         // commit new title to store
-        let title = null;
+        let title = null
         switch (to.name) {
           case 'home':
             title = null
-            break;
+            break
           case 'article':
             title = false
-            break;
+            break
           default:
             title = to.name
         }
@@ -98,47 +96,46 @@ import 'theme/assets/styles/main.scss'
         }
 
         // remove all path related body classes
-        let body_classes = document.querySelector('body').classList;
-        let classes_to_rm = [];
+        const body_classes = document.querySelector('body').classList
+        const classes_to_rm = []
         for (var i = 0; i < body_classes.length; i++) {
-          if(body_classes[i].startsWith('path-')){
-            classes_to_rm.push(body_classes[i]);
+          if (body_classes[i].startsWith('path-')) {
+            classes_to_rm.push(body_classes[i])
           }
         }
-        document.querySelector('body').classList.remove(...classes_to_rm);
+        document.querySelector('body').classList.remove(...classes_to_rm)
         // add new path classes to body
-        let classes = [];
-        if(to.path == '/'){
-          classes.push('path-home');
-        }else{
-          let path_parts = to.path.replace(/^\//, '').split('/');
+        const classes = []
+        if (to.path == '/') {
+          classes.push('path-home')
+        } else {
+          const path_parts = to.path.replace(/^\//, '').split('/')
           // TODO: remove language relative prefix from path classes (fr, en, etc)
           for (var i = 0; i < path_parts.length; i++) {
-            if(i == 0){
-              var c = "path-" + path_parts[i];
-            }else if (path_parts[i] !== ''){
-              var c = classes[i-1] +'-'+ path_parts[i];
+            if (i == 0) {
+              var c = 'path-' + path_parts[i]
+            } else if (path_parts[i] !== '') {
+              var c = classes[i - 1] + '-' + path_parts[i]
             }
             classes.push(c)
           }
-
         }
-        document.querySelector('body').classList.add(...classes);
+        document.querySelector('body').classList.add(...classes)
 
         // trigger router
-        next();
+        next()
       })
     }
 
-    function initVSiteBrandingBlock(){
+    function initVSiteBrandingBlock () {
       _v_sitebranding_block = new Vue({
         store,
         router,
         el: '#block-sitebranding',
         methods: {
-          onclick(event){
+          onclick (event) {
             // console.log("Clicked on logo event", event);
-            let href = event.target.getAttribute('href');
+            const href = event.target.getAttribute('href')
             // console.log("Clicked on logo href", href);
             this.$router.push(href)
             // replaced by router.beforeEach
@@ -148,11 +145,11 @@ import 'theme/assets/styles/main.scss'
       })
     }
 
-    function initVPagetitleBlock(){
-      let $blk = document.querySelector('#block-pagetitle')
-      let $h2 = $blk.querySelector('h2')
+    function initVPagetitleBlock () {
+      const $blk = document.querySelector('#block-pagetitle')
+      const $h2 = $blk.querySelector('h2')
       // get the loaded pagetitle
-      let title = $h2.innerText
+      const title = $h2.innerText
       // if not front recorde the loaded pagetitle in store
       if (!_is_front) {
         store.commit('Common/setPagetitle', title)
@@ -168,25 +165,26 @@ import 'theme/assets/styles/main.scss'
           ...mapState({
             pagetitle: state => state.Common.pagetitle
           })
-        },
+        }
       })
     }
 
-    function initVUserBlock(){
-      let mount_point = drupalSettings.user.uid !== 0 ? 'block-userblock' : 'block-userlogin';
-      let props = {
-        title: "",
-        loginblock:""
-      };
+    function initVUserBlock () {
+      const mount_point = drupalSettings.user.uid !== 0 ? 'block-userblock' : 'block-userlogin'
+      const props = {
+        title: '',
+        loginblock: ''
+      }
+      let $block
       switch (mount_point) {
         case 'block-userlogin':
-          let $block = document.getElementById(mount_point);
-          console.log('initVUserBlock login form html', $block);
+          $block = document.getElementById(mount_point)
+          console.log('initVUserBlock login form html', $block)
           props.loginblock = $block.outerHTML.trim()
-          break;
+          break
         case 'block-userblock':
         default:
-          break;
+          break
       }
 
       _v_user_block = new Vue({
@@ -198,17 +196,17 @@ import 'theme/assets/styles/main.scss'
         // },
         created () {
           // if already loggedin, call store.user to get the user infos
-          if(drupalSettings.user.uid !== 0){
+          if (drupalSettings.user.uid !== 0) {
             this.$store.commit('User/setUid', drupalSettings.user.uid)
             this.$store.dispatch('User/getUser')
           }
         },
-        render: h => h(VUserBlock, {props:props})
-      }).$mount('#'+mount_point)
+        render: h => h(VUserBlock, { props: props })
+      }).$mount('#' + mount_point)
       // console.log('initVUserBlock', _v_user_block);
     }
 
-    function initVHeaderMenu(){
+    function initVHeaderMenu () {
       // console.log('initVHeaderMenu');
       // adding vuejs attributes has it wont work on twig template (see menu--header.html.twig)
       // not working : String contains an invalid character
@@ -220,11 +218,11 @@ import 'theme/assets/styles/main.scss'
       _v_header_menu = new Vue({
         store,
         router,
-        el: `#block-header`,
+        el: '#block-header',
         methods: {
-          onclick(event){
+          onclick (event) {
             // console.log("Clicked on header menu link", event);
-            let href = event.target.getAttribute('href');
+            const href = event.target.getAttribute('href')
             // let title = event.target.innerText;
             // console.log("Clicked on header menu link : href", href);
             this.$router.push(href)
@@ -235,45 +233,44 @@ import 'theme/assets/styles/main.scss'
       })
     }
 
-    function initVMainContent(){
-      let id = "main-content"
-      let $main_content = document.querySelector('#'+id)
+    function initVMainContent () {
+      const id = 'main-content'
+      const $main_content = document.querySelector('#' + id)
       // console.log('main-content', $main_content);
-      let main_html = $main_content.innerHTML
+      const main_html = $main_content.innerHTML
       _v_main_content = new Vue({
         store,
-        render: h => h(VMainContent, {props:{id:id, html:main_html, isfront:drupalSettings.path.isFront}})
-      }).$mount('#'+id)
+        render: h => h(VMainContent, { props: { id: id, html: main_html, isfront: drupalSettings.path.isFront } })
+      }).$mount('#' + id)
     }
 
-    function initVSearchBlock(){
+    function initVSearchBlock () {
       // console.log('initVSearchBlock');
-      let id = "block-materiosapisearchblock"
+      const id = 'block-materiosapisearchblock'
       let $search_block = document.getElementById(id)
-      var formhtml = null
-      if($search_block){
+      let formhtml = null
+      if ($search_block) {
         // get the search form html to pass it as template to the vue
         // we gain display speed vs async downloaded data
         formhtml = $search_block.innerHTML
-      }else{
+      } else {
         // else create the empty block to fill it later with async data
         $search_block = document.createElement('div')
         $search_block.setAttribute('id', id)
         // TODO: get region by REST
-        let $region = document.getElementById('header-bottom');
-        $region.appendChild($search_block);
+        const $region = document.getElementById('header-bottom')
+        $region.appendChild($search_block)
       }
 
       // in any case create the vue
       _v_search_block = new Vue({
         store,
-        render: h => h(VSearchBlock, {props:{blockid:id, formhtml:formhtml}})
-      }).$mount('#'+id)
+        render: h => h(VSearchBlock, { props: { blockid: id, formhtml: formhtml } })
+      }).$mount('#' + id)
     }
 
     init()
   } // end MaterioTheme()
 
-  var materiotheme = new MaterioTheme();
-
-})(Drupal, drupalSettings, drupalDecoupled);
+  const materiotheme = new MaterioTheme()
+})(Drupal, drupalSettings, drupalDecoupled)

+ 23 - 25
web/themes/custom/materiotheme/vuejs/store/modules/blabla.js

@@ -7,8 +7,8 @@ export default {
   namespaced: true,
 
   // initial state
-  state : {
-    contenttype:null,
+  state: {
+    contenttype: null,
     items: [],
     page: 0,
     // infinteState will come from vue-infinite-loading plugin
@@ -17,24 +17,24 @@ export default {
   },
 
   // getters
-  getters : {},
+  getters: {},
 
   // mutations
-  mutations : {
+  mutations: {
     setItems (state, items) {
       state.items = state.items.concat(items)
     },
-    incrementPage(state){
-      state.page += 1;
+    incrementPage (state) {
+      state.page += 1
     },
-    setInfiniteState(state, infiniteLoadingstate){
+    setInfiniteState (state, infiniteLoadingstate) {
       state.infiniteLoadingState = infiniteLoadingstate
     }
   },
 
   // actions
-  actions : {
-    getItems({ dispatch, commit, state }){
+  actions: {
+    getItems ({ dispatch, commit, state }) {
       // if(!state.contenttype){
       //   REST.get('/entity/node_type/article?_format=json', {})
       //   .then(({ data }) => {
@@ -48,36 +48,34 @@ export default {
       return REST.get(`/blabla_rest?_format=json&page=${state.page}`, {})
         .then(({ data }) => {
           console.log('blabla REST: data', data)
-          if(data.length){
-            commit('setItems',data)
+          if (data.length) {
+            commit('setItems', data)
             // console.log('items.length', this.items.length);
-            if(state.infiniteLoadingState)
-              state.infiniteLoadingState.loaded()
-          }else{
-            if(state.infiniteLoadingState)
-              state.infiniteLoadingState.complete()
+            if (state.infiniteLoadingState) { state.infiniteLoadingState.loaded() }
+          } else {
+            if (state.infiniteLoadingState) { state.infiniteLoadingState.complete() }
           }
         })
-        .catch(( error ) => {
-            console.warn('Issue with blabla getitems', error)
-            Promise.reject(error)
+        .catch((error) => {
+          console.warn('Issue with blabla getitems', error)
+          Promise.reject(error)
         })
     },
     nextPage ({ dispatch, commit, state }, $infiniteLoadingstate) {
-      console.log("blabla nextPage", $infiniteLoadingstate);
+      console.log('blabla nextPage', $infiniteLoadingstate)
       commit('incrementPage')
       commit('setInfiniteState', $infiniteLoadingstate)
       dispatch('getItems')
     },
-    getItemIndex({ dispatch, commit, state}, uuid) {
-      return state.items.findIndex((e) =>{
+    getItemIndex ({ dispatch, commit, state }, uuid) {
+      return state.items.findIndex((e) => {
         return e.uuid == uuid
       })
     },
-    getPrevNextItems({ dispatch, commit, state }, index) {
+    getPrevNextItems ({ dispatch, commit, state }, index) {
       return {
-        prev:state.items[index-1],
-        next:state.items[index+1]
+        prev: state.items[index - 1],
+        next: state.items[index + 1]
       }
     }
   }

+ 6 - 6
web/themes/custom/materiotheme/vuejs/store/modules/common.js

@@ -6,22 +6,22 @@ export default {
   namespaced: true,
 
   // initial state
-  state : {
-    pagetitle:null,
+  state: {
+    pagetitle: null
   },
 
   // getters
-  getters : {},
+  getters: {},
 
   // mutations
-  mutations : {
+  mutations: {
     setPagetitle (state, title) {
-      console.log('Common, setPagetitle', title);
+      console.log('Common, setPagetitle', title)
       state.pagetitle = title
     }
   },
 
   // actions
-  actions : {}
+  actions: {}
 
 }

+ 11 - 11
web/themes/custom/materiotheme/vuejs/store/modules/pages.js

@@ -7,31 +7,31 @@ export default {
   namespaced: true,
 
   // initial state
-  state : {
-    pricing: {},
+  state: {
+    pricing: {}
   },
 
   // getters
-  getters : {},
+  getters: {},
 
   // mutations
-  mutations : {
+  mutations: {
     setPricing (state, page) {
       state.pricing = page
     }
   },
 
   // actions
-  actions : {
-    getPricing({ dispatch, commit, state }){
-      REST.get(`/pricing_rest?_format=json`, {})
+  actions: {
+    getPricing ({ dispatch, commit, state }) {
+      REST.get('/pricing_rest?_format=json', {})
         .then(({ data }) => {
           console.log('pricing REST: data', data)
-          commit('setPricing',data)
+          commit('setPricing', data)
         })
-        .catch(( error ) => {
-            console.warn('Issue with pricing', error)
-            Promise.reject(error)
+        .catch((error) => {
+          console.warn('Issue with pricing', error)
+          Promise.reject(error)
         })
     }
   }

+ 50 - 50
web/themes/custom/materiotheme/vuejs/store/modules/search.js

@@ -7,9 +7,9 @@ export default {
   namespaced: true,
 
   // initial state
-  state : {
-    keys: "",
-    term: "",
+  state: {
+    keys: '',
+    term: '',
     uuids: [],
     items: [],
     offset: 0,
@@ -22,10 +22,10 @@ export default {
   },
 
   // getters
-  getters : {},
+  getters: {},
 
   // mutations
-  mutations : {
+  mutations: {
     setUuids (state, uuids) {
       state.uuids = state.uuids.concat(uuids)
     },
@@ -50,21 +50,21 @@ export default {
     setCount (state, count) {
       state.count = count
     },
-    resetOffset(state) {
+    resetOffset (state) {
       state.offset = 0
     },
-    incrementOffset(state) {
+    incrementOffset (state) {
       state.offset += state.limit
     },
-    setInfiniteState(state, infiniteLoadingstate){
+    setInfiniteState (state, infiniteLoadingstate) {
       state.infiniteLoadingState = infiniteLoadingstate
     }
   },
 
   // actions
-  actions : {
-    newSearch({ dispatch, commit, state }) {
-      console.log('Search newSearch');
+  actions: {
+    newSearch ({ dispatch, commit, state }) {
+      console.log('Search newSearch')
       commit('resetUuids')
       commit('resetItems')
       commit('resetOffset')
@@ -72,21 +72,21 @@ export default {
       dispatch('getResults')
     },
     nextPage ({ dispatch, commit, state }, $infiniteLoadingstate) {
-      console.log("Search nextPage", $infiniteLoadingstate);
+      console.log('Search nextPage', $infiniteLoadingstate)
       commit('incrementOffset')
       commit('setInfiniteState', $infiniteLoadingstate)
       dispatch('getResults')
     },
     getResults ({ dispatch, commit, state }) {
-      let params = {
+      const params = {
         keys: state.keys,
         term: state.term,
-        offset:state.offset,
+        offset: state.offset,
         limit: state.limit
       }
       // console.log('Search getResults params', params);
-      let q = qs.stringify(params)
-      return MA.get(`/materio_sapi/getresults?`+q)
+      const q = qs.stringify(params)
+      return MA.get('/materio_sapi/getresults?' + q)
         .then(({ data }) => {
           console.log('search MA getresults data', data)
           // commit('setItems', data.items)
@@ -95,79 +95,79 @@ export default {
           commit('setUuids', data.uuids)
           dispatch('getItems', data.uuids)
         })
-        .catch(( error ) => {
-            console.warn('Issue with getResults', error)
-            Promise.reject(error)
+        .catch((error) => {
+          console.warn('Issue with getResults', error)
+          Promise.reject(error)
         })
     },
-    getItems({ dispatch, commit, state }, uuids) {
-      let params = {
+    getItems ({ dispatch, commit, state }, uuids) {
+      const params = {
         // include: 'images', // no needs to include thanks to consumers_image_styles module
         // include: 'drupal_internal__nid',
         'filter[uuids-groupe][group][conjunction]': 'OR'
-      };
-      for (var i = 0; i < uuids.length; i++) {
-        let uuid = uuids[i]
+      }
+      for (let i = 0; i < uuids.length; i++) {
+        const uuid = uuids[i]
         params[`filter[${uuid}][condition][path]`] = 'id'
         params[`filter[${uuid}][condition][value]`] = uuid
         params[`filter[${uuid}][condition][operator]`] = '='
         params[`filter[${uuid}][condition][memberOf]`] = 'uuids-groupe'
       }
       // console.log('search JSONAPI params', params);
-      let q = qs.stringify(params)
-      return JSONAPI.get('node/materiau?'+q)
+      const q = qs.stringify(params)
+      return JSONAPI.get('node/materiau?' + q)
         .then(({ data }) => {
           console.log('search getItems data', data)
-          dispatch('parseItems', {data:data.data, uuids:uuids})
+          dispatch('parseItems', { data: data.data, uuids: uuids })
           // commit('setItems', data.items)
         })
-        .catch(( error ) => {
-            console.warn('Issue with getItems', error)
-            Promise.reject(error)
+        .catch((error) => {
+          console.warn('Issue with getItems', error)
+          Promise.reject(error)
         })
     },
-    parseItems({ dispatch, commit, state }, { data, uuids }) {
+    parseItems ({ dispatch, commit, state }, { data, uuids }) {
       // data comes from jsonapi query
       // uuids comes from solr search query (we loop from uuids to conserve the search results order)
       console.log('search parseItems data, uuids', data, uuids)
-      let items = []
+      const items = []
       // for (var i = 0; i < data.length; i++) {
-      for (var i = 0; i < uuids.length; i++) {
-        let uuid = uuids[i]
+      for (let i = 0; i < uuids.length; i++) {
+        const uuid = uuids[i]
         // https://stackoverflow.com/questions/11258077/how-to-find-index-of-an-object-by-key-and-value-in-an-javascript-array
-        let item_index = data.findIndex(p => p.id == uuid)
+        const item_index = data.findIndex(p => p.id == uuid)
         // console.log('item_index', item_index);
-        if(item_index == -1) continue;
+        if (item_index == -1) continue
 
-        let item_src = data[item_index]
-        let attrs = item_src.attributes
-        let relations = item_src.relationships
+        const item_src = data[item_index]
+        const attrs = item_src.attributes
+        const relations = item_src.relationships
 
         // get field values
-        let item = {
+        const item = {
           uuid: uuid,
           title: attrs.title,
           field_short_description: attrs.field_short_description,
           body: attrs.body,
-          field_reference: attrs.field_reference,
+          field_reference: attrs.field_reference
         }
 
         // get images included values
-        let img_src = relations.images.data
+        const img_src = relations.images.data
         // console.log('img_src', img_src);
         // this is a temporary deactivation of images
         // img_src = [];
         item.images = []
-        for (var j = 0; j < img_src.length; j++) {
-          if(img_src[j].meta.imageDerivatives){
+        for (let j = 0; j < img_src.length; j++) {
+          if (img_src[j].meta.imageDerivatives) {
             item.images.push({
               title: img_src[j].meta.title,
               // meta.imageDerivatives.style.href link is provided by drupal consumers_image_styles module
               // BUG: missing all image derivative but first
               url: img_src[j].meta.imageDerivatives.links.card_medium.href
             })
-          }else{
-            console.warn('missing image derivative '+j+'/'+img_src.length+' for '+attrs.title);
+          } else {
+            console.warn('missing image derivative ' + j + '/' + img_src.length + ' for ' + attrs.title)
           }
         }
 
@@ -175,13 +175,13 @@ export default {
       }
       console.log('items', items)
       commit('setItems', items)
-      if(state.infiniteLoadingState){
+      if (state.infiniteLoadingState) {
         if (state.offset + state.limit > state.count) {
-          console.log('Search infinite completed');
+          console.log('Search infinite completed')
           // tell to vue-infinite-loading plugin that there si no new page
           state.infiniteLoadingState.complete()
-        }else{
-          console.log('Search infinite loaded');
+        } else {
+          console.log('Search infinite loaded')
           // tell to vue-infinite-loading plugin that newpage is loaded
           state.infiniteLoadingState.loaded()
         }

+ 11 - 11
web/themes/custom/materiotheme/vuejs/store/modules/showrooms.js

@@ -7,31 +7,31 @@ export default {
   namespaced: true,
 
   // initial state
-  state : {
-    items: [],
+  state: {
+    items: []
   },
 
   // getters
-  getters : {},
+  getters: {},
 
   // mutations
-  mutations : {
+  mutations: {
     setItems (state, items) {
       state.items = state.items.concat(items)
     }
   },
 
   // actions
-  actions : {
-    getItems({ dispatch, commit, state }){
-      REST.get(`/showrooms_rest?_format=json`, {})
+  actions: {
+    getItems ({ dispatch, commit, state }) {
+      REST.get('/showrooms_rest?_format=json', {})
         .then(({ data }) => {
           console.log('showrooms REST: data', data)
-          commit('setItems',data)
+          commit('setItems', data)
         })
-        .catch(( error ) => {
-            console.warn('Issue with showrooms', error)
-            Promise.reject(error)
+        .catch((error) => {
+          console.warn('Issue with showrooms', error)
+          Promise.reject(error)
         })
     }
   }

+ 149 - 150
web/themes/custom/materiotheme/vuejs/store/modules/user.js

@@ -1,7 +1,7 @@
-import { REST } from "vuejs/api/rest-axios";
+import { REST } from 'vuejs/api/rest-axios'
 // import { JSONAPI } from 'vuejs/api/json-axios';
-import { MA } from "vuejs/api/ma-axios";
-import qs from "querystring-es3";
+import { MA } from 'vuejs/api/ma-axios'
+import qs from 'querystring-es3'
 
 export default {
   namespaced: true,
@@ -10,7 +10,7 @@ export default {
   state: {
     uid: null,
     // username: '',
-    mail: "",
+    mail: '',
     csrf_token: null,
     logout_token: null,
     isloggedin: false,
@@ -26,141 +26,141 @@ export default {
 
   // mutations
   mutations: {
-    SetCsrftoken(state, token) {
-      console.log('SetCsrftoken', token);
-      state.csrf_token = token;
+    SetCsrftoken (state, token) {
+      console.log('SetCsrftoken', token)
+      state.csrf_token = token
     },
-    setToken(state, data) {
-      state.uid = data.current_user.uid;
+    setToken (state, data) {
+      state.uid = data.current_user.uid
       // state.username = data.username;
-      state.mail = data.current_user.mail;
-      state.csrf_token = data.csrf_token;
-      state.isloggedin = true;
-      state.logout_token = data.logout_token;
+      state.mail = data.current_user.mail
+      state.csrf_token = data.csrf_token
+      state.isloggedin = true
+      state.logout_token = data.logout_token
     },
-    setUid(state, uid) {
-      state.uid = uid;
-      state.isloggedin = true;
+    setUid (state, uid) {
+      state.uid = uid
+      state.isloggedin = true
     },
-    setUser(state, data) {
-      state.mail = data.mail[0].value;
-      state.uuid = data.uuid[0].value;
+    setUser (state, data) {
+      state.mail = data.mail[0].value
+      state.uuid = data.uuid[0].value
     },
-    setRoles(state, roles) {
-      console.log("User setRoles", roles);
-      state.roles = [];
+    setRoles (state, roles) {
+      console.log('User setRoles', roles)
+      state.roles = []
       for (let i = 0; i < roles.length; i++) {
-        state.roles.push(roles[i].target_id);
+        state.roles.push(roles[i].target_id)
       }
       // check if admin
       if (
-        state.roles.indexOf("admin") !== -1 ||
-        state.roles.indexOf("root") !== -1
+        state.roles.indexOf('admin') !== -1 ||
+        state.roles.indexOf('root') !== -1
       ) {
         // console.log('is admin');
-        state.isAdmin = true;
+        state.isAdmin = true
       }
       // check if has access to search
-      if (state.roles.indexOf("adherent") !== -1) {
+      if (state.roles.indexOf('adherent') !== -1) {
         // console.log('is admin');
-        state.canSearch = true;
-        state.isAdherent = true;
+        state.canSearch = true
+        state.isAdherent = true
       }
     },
-    setLoggedOut(state) {
-      console.log("setLoggedOut state", state);
-      state.uid = null;
-      state.mail = "";
-      state.csrf_token = null;
-      state.isloggedin = false;
-      state.logout_token = null;
+    setLoggedOut (state) {
+      console.log('setLoggedOut state', state)
+      state.uid = null
+      state.mail = ''
+      state.csrf_token = null
+      state.isloggedin = false
+      state.logout_token = null
       if (state.isAdmin) {
         // TODO: what if on a page where login is needed (as commerce checkout and cart)
-        window.location.reload(true);
+        window.location.reload(true)
       }
-      state.asAdmin = false;
-      state.canSearch = false;
+      state.asAdmin = false
+      state.canSearch = false
     },
-    setFlagColls(state, flagcolls) {
-      console.log("User setFlagColls", flagcolls);
-      state.flagcolls = flagcolls;
+    setFlagColls (state, flagcolls) {
+      console.log('User setFlagColls', flagcolls)
+      state.flagcolls = flagcolls
     }
   },
 
   // actions
   actions: {
-    userRegister({ dispatch, commit, state }, credentials) {
+    userRegister ({ dispatch, commit, state }, credentials) {
       return new Promise((resolve) => {
-        REST.get("/session/token").then(({ token }) => {
-          commit("SetCsrftoken", token);
-          REST.post("/user/register?_format=json", credentials, {
-            "X-CSRF-Token": state.csrftoken
+        REST.get('/session/token').then(({ token }) => {
+          commit('SetCsrftoken', token)
+          REST.post('/user/register?_format=json', credentials, {
+            'X-CSRF-Token': state.csrftoken
           })
             .then(({ data }) => {
-              console.log("user REST registered", data);
-              dispatch("userLogin", credentials).then(() => {
-                resolve();
-              });
+              console.log('user REST registered', data)
+              dispatch('userLogin', credentials).then(() => {
+                resolve()
+              })
             })
             .catch(error => {
-              console.warn("Issue with register", error);
-              Promise.reject(error);
-            });
-        });
-      });
+              console.warn('Issue with register', error)
+              Promise.reject(error)
+            })
+        })
+      })
     },
-    userLogin({ dispatch, state }, credentials) {
+    userLogin ({ dispatch, state }, credentials) {
       return new Promise((resolve, reject) => {
-        dispatch("getToken", credentials).then(() => {
-          dispatch("getUser").then(userdata => {
-            console.log("User Loggedin");
+        dispatch('getToken', credentials).then(() => {
+          dispatch('getUser').then(userdata => {
+            console.log('User Loggedin')
             if (state.isAdmin) {
-              window.location.reload(true);
+              window.location.reload(true)
             }
-            resolve();
-          });
-        });
-      });
+            resolve()
+          })
+        })
+      })
     },
-    getToken({ dispatch, commit, state }, credentials) {
-      return REST.post("/user/login?_format=json", credentials)
+    getToken ({ dispatch, commit, state }, credentials) {
+      return REST.post('/user/login?_format=json', credentials)
         .then(({ data }) => {
-          console.log("user REST getToken data", data);
-          commit("setToken", data);
+          console.log('user REST getToken data', data)
+          commit('setToken', data)
         })
         .catch(error => {
-          console.warn("Issue with getToken", error);
-          Promise.reject(error);
-        });
+          console.warn('Issue with getToken', error)
+          Promise.reject(error)
+        })
     },
-    getUser({ dispatch, commit, state }) {
+    getUser ({ dispatch, commit, state }) {
       return new Promise((resolve, reject) => {
-        REST.get("/session/token").then(({ data }) => {
-          console.log('csrftoken', data);
-          commit("SetCsrftoken", data);
-          console.log('state.csrf_token', state.csrf_token);
+        REST.get('/session/token').then(({ data }) => {
+          console.log('csrftoken', data)
+          commit('SetCsrftoken', data)
+          console.log('state.csrf_token', state.csrf_token)
           const params = {
             token: state.csrf_token
-          };
+          }
           REST.get(`/user/${state.uid}?_format=json`, params)
             .then(({ data }) => {
-              console.log("user REST getUser data", data);
-              console.log("roles", data.roles);
-              commit("setUser", data);
+              console.log('user REST getUser data', data)
+              console.log('roles', data.roles)
+              commit('setUser', data)
               if (data.roles) {
-                commit("setRoles", data.roles);
+                commit('setRoles', data.roles)
               }
-              dispatch("getUserFlagColls");
-              resolve();
+              dispatch('getUserFlagColls')
+              resolve()
             })
             .catch(error => {
-              console.warn("Issue with getUser", error);
-              Promise.reject(error);
-            });
-        });
-      });
+              console.warn('Issue with getUser', error)
+              Promise.reject(error)
+            })
+        })
+      })
     },
-    getUserFlagColls({ dispatch, commit, state }) {
+    getUserFlagColls ({ dispatch, commit, state }) {
       // flags
       // REST.get('/flagging_collection/1?_format=json')
       //   .then(( data ) => {
@@ -171,111 +171,110 @@ export default {
       //       Promise.reject(error)
       //   })
 
-      return MA.get("materio_flag/user_flagging_collections")
+      return MA.get('materio_flag/user_flagging_collections')
         .then(({ data }) => {
-          console.log("user MA getFlags data", data);
-          commit("setFlagColls", data);
+          console.log('user MA getFlags data', data)
+          commit('setFlagColls', data)
         })
         .catch(error => {
-          console.warn("Issue USER MA getFlags", error);
-          Promise.reject(error);
-        });
+          console.warn('Issue USER MA getFlags', error)
+          Promise.reject(error)
+        })
     },
     // https://drupal.stackexchange.com/questions/248539/cant-get-flagging-api-to-accept-post-request
-    createFlagColl({ dispatch, commit, state }, new_collection_name) {
-      console.log("user createFlagColl", new_collection_name);
+    createFlagColl ({ dispatch, commit, state }, new_collection_name) {
+      console.log('user createFlagColl', new_collection_name)
       return new Promise((resolve, reject) => {
         const params = {
           name: new_collection_name
-        };
-        MA.post("materio_flag/create_user_flagging_collection", params)
+        }
+        MA.post('materio_flag/create_user_flagging_collection', params)
           .then(({ data }) => {
-            console.log("user MA createFlagColl data", data);
+            console.log('user MA createFlagColl data', data)
             if (data.status) {
               dispatch('getUserFlagColls').then(() => {
-                resolve();
+                resolve()
               })
             }
           })
           .catch(error => {
-            console.warn("Issue USER MA createFlag", error);
-            reject(error);
-          });
-      });
+            console.warn('Issue USER MA createFlag', error)
+            reject(error)
+          })
+      })
     },
-    deleteFlagColl({ dispatch, commit, state }, flagcollid) {
-      console.log("user deleteFlagColl", flagcollid);
+    deleteFlagColl ({ dispatch, commit, state }, flagcollid) {
+      console.log('user deleteFlagColl', flagcollid)
       return new Promise((resolve, reject) => {
         const params = {
           flagcollid: flagcollid
-        };
-        MA.post("materio_flag/delete_user_flagging_collection", params)
+        }
+        MA.post('materio_flag/delete_user_flagging_collection', params)
           .then(({ data }) => {
-            console.log("user MA deleteFlagColl data", data);
-            dispatch('getUserFlagColls').then(() =>{
-              resolve();
-            });
+            console.log('user MA deleteFlagColl data', data)
+            dispatch('getUserFlagColls').then(() => {
+              resolve()
+            })
           })
           .catch(error => {
-            console.warn("Issue USER MA createFlag", error);
-            reject(error);
-          });
-      });
+            console.warn('Issue USER MA createFlag', error)
+            reject(error)
+          })
+      })
     },
-    flag({ dispatch, commit, state }, args) {
-      console.log("user flag", args.uuid, args.collid);
+    flag ({ dispatch, commit, state }, args) {
+      console.log('user flag', args.uuid, args.collid)
       return new Promise((resolve, reject) => {
         const params = {
           flagid: state.flagcolls[args.collid].flag_id,
           uuid: args.uuid,
           flagcollid: args.collid
-        };
-        return MA.post(`materio_flag/flag`, params)
+        }
+        return MA.post('materio_flag/flag', params)
           .then(({ data }) => {
-            console.log("user MA flag", data);
-            dispatch('getUserFlagColls').then(() =>{
-              resolve();
-            });
+            console.log('user MA flag', data)
+            dispatch('getUserFlagColls').then(() => {
+              resolve()
+            })
           })
           .catch(error => {
-            console.warn("Issue USER MA flag", error);
-          });
-      });
-
+            console.warn('Issue USER MA flag', error)
+          })
+      })
     },
-    unFlag({ dispatch, commit, state }, args) {
-      console.log("user unFlag", args.uuid, args.collid);
+    unFlag ({ dispatch, commit, state }, args) {
+      console.log('user unFlag', args.uuid, args.collid)
       return new Promise((resolve, reject) => {
         const params = {
           flagid: state.flagcolls[args.collid].flag_id,
           uuid: args.uuid,
           flagcollid: args.collid
-        };
-        return MA.post(`materio_flag/unflag`, params)
+        }
+        return MA.post('materio_flag/unflag', params)
           .then(({ data }) => {
-            console.log("user MA unFlag", data);
-            dispatch('getUserFlagColls').then(() =>{
-              resolve();
-            });
+            console.log('user MA unFlag', data)
+            dispatch('getUserFlagColls').then(() => {
+              resolve()
+            })
           })
           .catch(error => {
-            console.warn("Issue USER MA unFlag", error);
-          });
-      });
+            console.warn('Issue USER MA unFlag', error)
+          })
+      })
     },
-    userLogout({ commit, state }) {
+    userLogout ({ commit, state }) {
       const credentials = qs.stringify({
         token: state.csrf_token
-      });
-      REST.post("/user/logout", credentials)
+      })
+      REST.post('/user/logout', credentials)
         .then(resp => {
-          console.log("userLogout resp", resp);
-          commit("setLoggedOut");
+          console.log('userLogout resp', resp)
+          commit('setLoggedOut')
         })
         .catch(error => {
-          console.warn("Issue with logout", error);
-          Promise.reject(error);
-        });
+          console.warn('Issue with logout', error)
+          Promise.reject(error)
+        })
     }
   }
-};
+}

Some files were not shown because too many files changed in this diff