added fix option to eslint

This commit is contained in:
Bachir Soussi Chiadmi 2020-11-25 22:49:17 +01:00
parent 1c1fb294c5
commit ed9e62718c
14 changed files with 384 additions and 4076 deletions

View File

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

View File

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

15
package-lock.json generated
View File

@ -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": { "eslint-plugin-node": {
"version": "11.1.0", "version": "11.1.0",
"resolved": "https://registry.npmjs.org/eslint-plugin-node/-/eslint-plugin-node-11.1.0.tgz", "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": { "eslint-scope": {
"version": "4.0.3", "version": "4.0.3",
"resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-4.0.3.tgz", "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-4.0.3.tgz",

View File

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

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -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
*/

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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