added fix option to eslint
This commit is contained in:
parent
1c1fb294c5
commit
ed9e62718c
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -82,6 +82,7 @@ module.exports = {
|
|||
}),
|
||||
new VueLoaderPlugin(),
|
||||
new ESLintPlugin({
|
||||
fix: true
|
||||
// exclude: ['node_modules', 'vendor', 'web/core']
|
||||
// cache: false,
|
||||
// ignore: true,
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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 one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -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
|
||||
*/
|
|
@ -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)
|
||||
|
@ -32,23 +33,20 @@ import { mapState } from 'vuex'
|
|||
import 'theme/assets/styles/main.scss'
|
||||
|
||||
(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()")
|
||||
console.log('MaterioTheme init()')
|
||||
initVues()
|
||||
}
|
||||
|
||||
|
@ -58,16 +56,16 @@ import 'theme/assets/styles/main.scss'
|
|||
if (drupalDecoupled.route_name.indexOf('commerce') == -1 &&
|
||||
drupalDecoupled.route_name.indexOf('flagging_collection') == -1 &&
|
||||
drupalDecoupled.route_name.indexOf('user') == -1) {
|
||||
return false;
|
||||
return false
|
||||
} else {
|
||||
return true;
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
function initVues () {
|
||||
// only launch views if we are not in commerce pages
|
||||
if (!checkNoVuePages()) {
|
||||
initVRouter();
|
||||
initVRouter()
|
||||
initVSiteBrandingBlock()
|
||||
initVPagetitleBlock()
|
||||
initVHeaderMenu()
|
||||
|
@ -82,14 +80,14 @@ import 'theme/assets/styles/main.scss'
|
|||
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,35 +96,34 @@ 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]);
|
||||
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 = [];
|
||||
const classes = []
|
||||
if (to.path == '/') {
|
||||
classes.push('path-home');
|
||||
classes.push('path-home')
|
||||
} 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)
|
||||
for (var i = 0; i < path_parts.length; i++) {
|
||||
if (i == 0) {
|
||||
var c = "path-" + path_parts[i];
|
||||
var c = 'path-' + 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)
|
||||
}
|
||||
|
||||
}
|
||||
document.querySelector('body').classList.add(...classes);
|
||||
document.querySelector('body').classList.add(...classes)
|
||||
|
||||
// trigger router
|
||||
next();
|
||||
next()
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -138,7 +135,7 @@ import 'theme/assets/styles/main.scss'
|
|||
methods: {
|
||||
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
|
||||
|
@ -149,10 +146,10 @@ import 'theme/assets/styles/main.scss'
|
|||
}
|
||||
|
||||
function initVPagetitleBlock () {
|
||||
let $blk = document.querySelector('#block-pagetitle')
|
||||
let $h2 = $blk.querySelector('h2')
|
||||
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:""
|
||||
};
|
||||
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({
|
||||
|
@ -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) {
|
||||
// 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)
|
||||
|
@ -236,10 +234,10 @@ import 'theme/assets/styles/main.scss'
|
|||
}
|
||||
|
||||
function initVMainContent () {
|
||||
let id = "main-content"
|
||||
let $main_content = document.querySelector('#'+id)
|
||||
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 } })
|
||||
|
@ -248,9 +246,9 @@ import 'theme/assets/styles/main.scss'
|
|||
|
||||
function initVSearchBlock () {
|
||||
// console.log('initVSearchBlock');
|
||||
let id = "block-materiosapisearchblock"
|
||||
const id = 'block-materiosapisearchblock'
|
||||
let $search_block = document.getElementById(id)
|
||||
var formhtml = null
|
||||
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
|
||||
|
@ -260,8 +258,8 @@ import 'theme/assets/styles/main.scss'
|
|||
$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
|
||||
|
@ -274,6 +272,5 @@ import 'theme/assets/styles/main.scss'
|
|||
init()
|
||||
} // end MaterioTheme()
|
||||
|
||||
var materiotheme = new MaterioTheme();
|
||||
|
||||
})(Drupal, drupalSettings, drupalDecoupled);
|
||||
const materiotheme = new MaterioTheme()
|
||||
})(Drupal, drupalSettings, drupalDecoupled)
|
||||
|
|
|
@ -25,7 +25,7 @@ export default {
|
|||
state.items = state.items.concat(items)
|
||||
},
|
||||
incrementPage (state) {
|
||||
state.page += 1;
|
||||
state.page += 1
|
||||
},
|
||||
setInfiniteState (state, infiniteLoadingstate) {
|
||||
state.infiniteLoadingState = infiniteLoadingstate
|
||||
|
@ -51,11 +51,9 @@ export default {
|
|||
if (data.length) {
|
||||
commit('setItems', data)
|
||||
// console.log('items.length', this.items.length);
|
||||
if(state.infiniteLoadingState)
|
||||
state.infiniteLoadingState.loaded()
|
||||
if (state.infiniteLoadingState) { state.infiniteLoadingState.loaded() }
|
||||
} else {
|
||||
if(state.infiniteLoadingState)
|
||||
state.infiniteLoadingState.complete()
|
||||
if (state.infiniteLoadingState) { state.infiniteLoadingState.complete() }
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
|
@ -64,7 +62,7 @@ export default {
|
|||
})
|
||||
},
|
||||
nextPage ({ dispatch, commit, state }, $infiniteLoadingstate) {
|
||||
console.log("blabla nextPage", $infiniteLoadingstate);
|
||||
console.log('blabla nextPage', $infiniteLoadingstate)
|
||||
commit('incrementPage')
|
||||
commit('setInfiniteState', $infiniteLoadingstate)
|
||||
dispatch('getItems')
|
||||
|
|
|
@ -7,7 +7,7 @@ export default {
|
|||
|
||||
// initial state
|
||||
state: {
|
||||
pagetitle:null,
|
||||
pagetitle: null
|
||||
},
|
||||
|
||||
// getters
|
||||
|
@ -16,7 +16,7 @@ export default {
|
|||
// mutations
|
||||
mutations: {
|
||||
setPagetitle (state, title) {
|
||||
console.log('Common, setPagetitle', title);
|
||||
console.log('Common, setPagetitle', title)
|
||||
state.pagetitle = title
|
||||
}
|
||||
},
|
||||
|
|
|
@ -8,7 +8,7 @@ export default {
|
|||
|
||||
// initial state
|
||||
state: {
|
||||
pricing: {},
|
||||
pricing: {}
|
||||
},
|
||||
|
||||
// getters
|
||||
|
@ -24,7 +24,7 @@ export default {
|
|||
// actions
|
||||
actions: {
|
||||
getPricing ({ dispatch, commit, state }) {
|
||||
REST.get(`/pricing_rest?_format=json`, {})
|
||||
REST.get('/pricing_rest?_format=json', {})
|
||||
.then(({ data }) => {
|
||||
console.log('pricing REST: data', data)
|
||||
commit('setPricing', data)
|
||||
|
|
|
@ -8,8 +8,8 @@ export default {
|
|||
|
||||
// initial state
|
||||
state: {
|
||||
keys: "",
|
||||
term: "",
|
||||
keys: '',
|
||||
term: '',
|
||||
uuids: [],
|
||||
items: [],
|
||||
offset: 0,
|
||||
|
@ -64,7 +64,7 @@ export default {
|
|||
// actions
|
||||
actions: {
|
||||
newSearch ({ dispatch, commit, state }) {
|
||||
console.log('Search newSearch');
|
||||
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,
|
||||
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)
|
||||
|
@ -101,20 +101,20 @@ export default {
|
|||
})
|
||||
},
|
||||
getItems ({ dispatch, commit, state }, uuids) {
|
||||
let params = {
|
||||
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)
|
||||
const q = qs.stringify(params)
|
||||
return JSONAPI.get('node/materiau?' + q)
|
||||
.then(({ data }) => {
|
||||
console.log('search getItems data', data)
|
||||
|
@ -130,35 +130,35 @@ export default {
|
|||
// 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++) {
|
||||
for (let j = 0; j < img_src.length; j++) {
|
||||
if (img_src[j].meta.imageDerivatives) {
|
||||
item.images.push({
|
||||
title: img_src[j].meta.title,
|
||||
|
@ -167,7 +167,7 @@ export default {
|
|||
url: img_src[j].meta.imageDerivatives.links.card_medium.href
|
||||
})
|
||||
} 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)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -177,11 +177,11 @@ export default {
|
|||
commit('setItems', items)
|
||||
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');
|
||||
console.log('Search infinite loaded')
|
||||
// tell to vue-infinite-loading plugin that newpage is loaded
|
||||
state.infiniteLoadingState.loaded()
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ export default {
|
|||
|
||||
// initial state
|
||||
state: {
|
||||
items: [],
|
||||
items: []
|
||||
},
|
||||
|
||||
// getters
|
||||
|
@ -24,7 +24,7 @@ export default {
|
|||
// actions
|
||||
actions: {
|
||||
getItems ({ dispatch, commit, state }) {
|
||||
REST.get(`/showrooms_rest?_format=json`, {})
|
||||
REST.get('/showrooms_rest?_format=json', {})
|
||||
.then(({ data }) => {
|
||||
console.log('showrooms REST: data', data)
|
||||
commit('setItems', data)
|
||||
|
|
|
@ -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,
|
||||
|
@ -27,63 +27,63 @@ export default {
|
|||
// mutations
|
||||
mutations: {
|
||||
SetCsrftoken (state, token) {
|
||||
console.log('SetCsrftoken', token);
|
||||
state.csrf_token = token;
|
||||
console.log('SetCsrftoken', token)
|
||||
state.csrf_token = token
|
||||
},
|
||||
setToken (state, data) {
|
||||
state.uid = data.current_user.uid;
|
||||
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;
|
||||
state.uid = uid
|
||||
state.isloggedin = true
|
||||
},
|
||||
setUser (state, data) {
|
||||
state.mail = data.mail[0].value;
|
||||
state.uuid = data.uuid[0].value;
|
||||
state.mail = data.mail[0].value
|
||||
state.uuid = data.uuid[0].value
|
||||
},
|
||||
setRoles (state, roles) {
|
||||
console.log("User setRoles", roles);
|
||||
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;
|
||||
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;
|
||||
console.log('User setFlagColls', flagcolls)
|
||||
state.flagcolls = flagcolls
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -91,74 +91,74 @@ export default {
|
|||
actions: {
|
||||
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) {
|
||||
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)
|
||||
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 }) {
|
||||
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 }) {
|
||||
// flags
|
||||
|
@ -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);
|
||||
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);
|
||||
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);
|
||||
console.log('user MA deleteFlagColl data', data)
|
||||
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)
|
||||
})
|
||||
})
|
||||
},
|
||||
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) => {
|
||||
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);
|
||||
console.log('user MA flag', data)
|
||||
dispatch('getUserFlagColls').then(() => {
|
||||
resolve();
|
||||
});
|
||||
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);
|
||||
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);
|
||||
console.log('user MA unFlag', data)
|
||||
dispatch('getUserFlagColls').then(() => {
|
||||
resolve();
|
||||
});
|
||||
resolve()
|
||||
})
|
||||
})
|
||||
.catch(error => {
|
||||
console.warn("Issue USER MA unFlag", error);
|
||||
});
|
||||
});
|
||||
console.warn('Issue USER MA unFlag', error)
|
||||
})
|
||||
})
|
||||
},
|
||||
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)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue