-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into vs-modules
- Loading branch information
Showing
47 changed files
with
1,244 additions
and
433 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { cmsPageModule } from './store/page' | ||
import { cmsBlockModule } from './store/block' | ||
import { cmsHierarchyModule } from './store/hierarchy' | ||
import { VueStorefrontModule, VueStorefrontModuleConfig } from '@vue-storefront/core/lib/module' | ||
import { plugin } from './store/plugin' | ||
import { initCacheStorage } from '@vue-storefront/core/helpers/initCacheStorage'; | ||
|
||
export const KEY = 'cms' | ||
export const cacheStorage = initCacheStorage(KEY) | ||
|
||
const moduleConfig: VueStorefrontModuleConfig = { | ||
key: KEY, | ||
store: { modules: [ | ||
{ key: 'cmsPage', module: cmsPageModule }, | ||
{ key: 'cmsBlock', module: cmsBlockModule }, | ||
{ key: 'cmsHierarchy', module: cmsHierarchyModule } | ||
], plugin }, | ||
} | ||
|
||
export const Cms = new VueStorefrontModule(moduleConfig) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import { ActionTree } from "vuex" | ||
import { quickSearchByQuery } from '@vue-storefront/store/lib/search' | ||
import * as types from './mutation-types' | ||
import SearchQuery from '@vue-storefront/store/lib/search/searchQuery' | ||
import RootState from '@vue-storefront/store/types/RootState'; | ||
import CmsBlockState from "../../types/CmsBlockState" | ||
|
||
const actions: ActionTree<CmsBlockState, RootState> = { | ||
|
||
/** | ||
* Retrieve cms blocks | ||
* | ||
* @param context | ||
* @param {any} filterValues | ||
* @param {any} filterField | ||
* @param {any} size | ||
* @param {any} start | ||
* @param {any} excludeFields | ||
* @param {any} includeFields | ||
* @returns {Promise<T> & Promise<any>} | ||
*/ | ||
list (context, { filterValues = null, filterField = 'identifier', size = 150, start = 0, excludeFields = null, includeFields = null, skipCache = false }) { | ||
let query = new SearchQuery() | ||
if (filterValues) { | ||
query = query.applyFilter({key: filterField, value: {'like': filterValues}}) | ||
} | ||
if (skipCache || (!context.state.items || context.state.items.length === 0)) { | ||
return quickSearchByQuery({ query, entityType: 'cms_block', excludeFields, includeFields }) | ||
.then((resp) => { | ||
context.commit(types.CMS_BLOCK_UPDATE_CMS_BLOCKS, resp.items) | ||
return resp.items | ||
}) | ||
.catch(err => { | ||
console.error(err) | ||
}) | ||
} else { | ||
return new Promise((resolve, reject) => { | ||
let resp = context.state.items | ||
resolve(resp) | ||
}) | ||
} | ||
}, | ||
|
||
/** | ||
* Retrieve single cms block by key value | ||
* | ||
* @param context | ||
* @param {any} key | ||
* @param {any} value | ||
* @param {any} excludeFields | ||
* @param {any} includeFields | ||
* @returns {Promise<T> & Promise<any>} | ||
*/ | ||
single (context, { key = 'identifier', value, excludeFields = null, includeFields = null, skipCache = false }) { | ||
const state = context.state | ||
if (skipCache || (!state.items || state.items.length === 0)) { | ||
let query = new SearchQuery() | ||
if (value) { | ||
query = query.applyFilter({key: key, value: {'like': value}}) | ||
} | ||
return quickSearchByQuery({ query, entityType: 'cms_block', excludeFields, includeFields }) | ||
.then((resp) => { | ||
context.commit(types.CMS_BLOCK_ADD_CMS_BLOCK, resp.items[0]) | ||
return resp.items[0] | ||
}) | ||
.catch(err => { | ||
console.error(err) | ||
}) | ||
} else { | ||
return new Promise((resolve, reject) => { | ||
if (state.items.length > 0) { | ||
let cmsBlock = state.items.find((itm) => { return itm[key] === value }) | ||
if (cmsBlock) { | ||
resolve(cmsBlock) | ||
} else { | ||
reject(new Error('CMS block query returned empty result ' + key + ' = ' + value)) | ||
} | ||
} else { | ||
resolve() | ||
} | ||
}) | ||
} | ||
}, | ||
|
||
addItem ({ commit }, block) { | ||
commit(types.CMS_BLOCK_ADD_CMS_BLOCK, block ) | ||
} | ||
} | ||
|
||
export default actions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { GetterTree } from 'vuex' | ||
import CmsBlockState from '../../types/CmsBlockState' | ||
import RootState from '@vue-storefront/store/types/RootState' | ||
|
||
const getters: GetterTree<CmsBlockState, RootState> = { | ||
cmsBlocks: (state) => state.items, | ||
cmsBlockIdentifier: (state) => (identifier) => { | ||
return state.items.find(item => item.identifier === identifier) | ||
}, | ||
cmsBlockId: (state) => (id) => { | ||
return state.items.find(item => item.id === id) | ||
}, | ||
} | ||
|
||
export default getters |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Module } from 'vuex' | ||
import actions from './actions' | ||
import getters from './getters' | ||
import mutations from './mutations' | ||
import RootState from '@vue-storefront/store/types/RootState' | ||
import CmsBlockState from '../../types/CmsBlockState' | ||
|
||
export const cmsBlockStorageKey = 'cms-blocks' | ||
|
||
export const cmsBlockModule: Module<CmsBlockState, RootState> = { | ||
namespaced: true, | ||
state: { | ||
items: [], | ||
}, | ||
getters, | ||
actions, | ||
mutations | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const SN_CMS_BLOCK = 'cmsBlock' | ||
export const CMS_BLOCK_UPDATE_CMS_BLOCKS = SN_CMS_BLOCK + '/UPDATE_CMS_BLOCKS' | ||
export const CMS_BLOCK_ADD_CMS_BLOCK = SN_CMS_BLOCK + '/ADD_CMS_BLOCK' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { MutationTree } from 'vuex' | ||
import * as types from './mutation-types' | ||
import CmsBlockState from '../../types/CmsBlockState' | ||
|
||
const mutations: MutationTree<CmsBlockState> = { | ||
/** | ||
* Store CMS Blocks by identifier in state and localForage | ||
* @param {} state | ||
* @param {Array} cmsBlocks | ||
*/ | ||
[types.CMS_BLOCK_UPDATE_CMS_BLOCKS] (state, cmsBlocks) { | ||
state.items = cmsBlocks || [] | ||
}, | ||
[types.CMS_BLOCK_ADD_CMS_BLOCK] (state, cmsBlock ) { | ||
const record = state.items.find(c => c.id === cmsBlock.id) | ||
if (!record) { | ||
state.items.push(cmsBlock) | ||
} | ||
} | ||
} | ||
|
||
export default mutations |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { ActionTree } from "vuex" | ||
import { quickSearchByQuery } from '@vue-storefront/store/lib/search' | ||
import SearchQuery from '@vue-storefront/store/lib/search/searchQuery' | ||
import RootState from '@vue-storefront/store/types/RootState'; | ||
import CmsHierarchyState from "../../types/CmsHierarchyState" | ||
|
||
const actions: ActionTree<CmsHierarchyState, RootState> = { | ||
/** | ||
* Retrieve cms hierarchy | ||
* | ||
* @param context | ||
* @param {any} query | ||
* @param {any} entityType | ||
* @param {any} excludeFields | ||
* @param {any} includeFields | ||
* @returns {Promise<T> & Promise<any>} | ||
*/ | ||
list (context, { id, entityType = 'cms_hierarchy', excludeFields = null, includeFields = null}) { | ||
let query = new SearchQuery() | ||
|
||
if (id) { | ||
query = query.applyFilter({key: 'identifier', value: {'eq': id}}) | ||
} | ||
|
||
return quickSearchByQuery({ query, entityType, excludeFields, includeFields }).catch(err => { | ||
console.error(err) | ||
}) | ||
} | ||
} | ||
|
||
export default actions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Module } from 'vuex' | ||
import actions from './actions' | ||
import RootState from '@vue-storefront/store/types/RootState' | ||
import CmsHierarchyState from '../../types/CmsHierarchyState' | ||
|
||
export const cmsHierarchyModule: Module<CmsHierarchyState, RootState> = { | ||
namespaced: true, | ||
state: { | ||
items: [], | ||
}, | ||
actions | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const SN_CMS_HIERARCHY = 'cms_hierarchy' | ||
export const CMS_HIERARCHY_UPDATE_CMS_HIERARCHIES = SN_CMS_HIERARCHY + '/UPDATE_CMS_HIERARCHIES' |
Oops, something went wrong.