druxt-views 0.20.0 → 0.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/DruxtView.vue +80 -17
- package/dist/components/DruxtViewsFilter.vue +11 -1
- package/dist/components/DruxtViewsFilters.vue +10 -0
- package/dist/components/DruxtViewsPager.vue +10 -0
- package/dist/components/DruxtViewsSorts.vue +10 -0
- package/dist/druxt-views.esm.js +24 -5
- package/dist/druxt-views.ssr.js +24 -5
- package/package.json +9 -9
|
@@ -79,6 +79,17 @@ export default {
|
|
|
79
79
|
default: 'default',
|
|
80
80
|
},
|
|
81
81
|
|
|
82
|
+
/**
|
|
83
|
+
* Module settings object.
|
|
84
|
+
*
|
|
85
|
+
* @type {ModuleSettings}
|
|
86
|
+
* @default {}
|
|
87
|
+
*/
|
|
88
|
+
settings: {
|
|
89
|
+
type: Object,
|
|
90
|
+
default: () => ({}),
|
|
91
|
+
},
|
|
92
|
+
|
|
82
93
|
/**
|
|
83
94
|
* JSON:API Resource type.
|
|
84
95
|
*
|
|
@@ -330,6 +341,14 @@ export default {
|
|
|
330
341
|
},
|
|
331
342
|
},
|
|
332
343
|
|
|
344
|
+
mounted() {
|
|
345
|
+
// If static, re-fetch data allowing for cache-bypass.
|
|
346
|
+
// @TODO - Don't re-fetch in serverless configuration.
|
|
347
|
+
if (this.$store.app.context.isStatic) {
|
|
348
|
+
this.$fetch()
|
|
349
|
+
}
|
|
350
|
+
},
|
|
351
|
+
|
|
333
352
|
methods: {
|
|
334
353
|
/**
|
|
335
354
|
* Builds the query for the JSON:API request.
|
|
@@ -447,12 +466,22 @@ export default {
|
|
|
447
466
|
async fetchData(settings) {
|
|
448
467
|
const viewId = this.viewId || (((this.view || {}).data || {}).attributes || {}).drupal_internal__id
|
|
449
468
|
if (viewId) {
|
|
469
|
+
// Check if we need to bypass cache.
|
|
470
|
+
let bypassCache = false
|
|
471
|
+
if (typeof (settings.query || {}).bypassCache === 'boolean') {
|
|
472
|
+
bypassCache = settings.query.bypassCache
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
// Build query.
|
|
450
476
|
const query = this.getQuery(settings)
|
|
477
|
+
|
|
478
|
+
// Execute the resquest.
|
|
451
479
|
this.resource = await this.getResults({
|
|
452
480
|
displayId: this.displayId,
|
|
453
481
|
prefix: this.lang,
|
|
454
482
|
query: stringify(query),
|
|
455
|
-
viewId
|
|
483
|
+
viewId,
|
|
484
|
+
bypassCache
|
|
456
485
|
})
|
|
457
486
|
}
|
|
458
487
|
},
|
|
@@ -475,10 +504,22 @@ export default {
|
|
|
475
504
|
/**
|
|
476
505
|
* Component settings.
|
|
477
506
|
*/
|
|
478
|
-
settings: (
|
|
479
|
-
const
|
|
507
|
+
settings: (context, wrapperSettings) => {
|
|
508
|
+
const { $druxt, settings } = context
|
|
509
|
+
|
|
510
|
+
// Start with the `nuxt.config.js` `druxt.settings.views` settings and
|
|
511
|
+
// merge the Wrapper component settings on top.
|
|
512
|
+
let mergedSettings = merge(($druxt.settings || {}).views || {}, wrapperSettings || {}, { arrayMerge: (dest, src) => src })
|
|
513
|
+
// Merge the DruxtViews component `settings` property on top.
|
|
514
|
+
mergedSettings = merge(mergedSettings || {}, settings || {}, { arrayMerge: (dest, src) => src })
|
|
515
|
+
|
|
516
|
+
// Evaluate the bypass cache function.
|
|
517
|
+
if (typeof (mergedSettings.query || {}).bypassCache === 'function') {
|
|
518
|
+
mergedSettings.query.bypassCache = !!mergedSettings.query.bypassCache(context)
|
|
519
|
+
}
|
|
520
|
+
|
|
480
521
|
return {
|
|
481
|
-
query:
|
|
522
|
+
query: mergedSettings.query || {},
|
|
482
523
|
}
|
|
483
524
|
},
|
|
484
525
|
|
|
@@ -641,6 +682,16 @@ export default {
|
|
|
641
682
|
|
|
642
683
|
return scopedSlots
|
|
643
684
|
},
|
|
685
|
+
|
|
686
|
+
/**
|
|
687
|
+
* Druxt development template tool configuration.
|
|
688
|
+
*/
|
|
689
|
+
template: {
|
|
690
|
+
debug: "{ view, results }",
|
|
691
|
+
mixins: {
|
|
692
|
+
'DruxtViewsViewMixin': 'druxt-views'
|
|
693
|
+
}
|
|
694
|
+
}
|
|
644
695
|
}
|
|
645
696
|
}
|
|
646
697
|
|
|
@@ -683,28 +734,40 @@ export default {
|
|
|
683
734
|
* or the Wrapper component `druxt` object.
|
|
684
735
|
*
|
|
685
736
|
* @typedef {object} ModuleSettings
|
|
686
|
-
* @param {
|
|
687
|
-
* @param {
|
|
688
|
-
* @param {
|
|
689
|
-
*
|
|
690
|
-
* @
|
|
691
|
-
* {
|
|
692
|
-
* bundleFilter: false,
|
|
693
|
-
* fields: [],
|
|
694
|
-
* resourceTypes: []
|
|
695
|
-
* }
|
|
737
|
+
* @param {object} query - View results query settings:
|
|
738
|
+
* @param {(boolean|function)} query.bypassCache - Whether to pull the data from the Vuex store or from the JSON:API.
|
|
739
|
+
* @param {boolean} query.bundleFilter - Whether to automatically detect Resource types to filter, based on the View `bundle` filter.
|
|
740
|
+
* @param {string[]} query.fields - An array of fields to filter from the JSON:API Views Resource types.
|
|
741
|
+
* @param {string[]} query.resourceTypes - An array of Resource types to be used by the Fields filter.
|
|
696
742
|
*
|
|
697
|
-
* @example @lang vue
|
|
743
|
+
* @example <caption>DruxtView Wrapper component</caption> @lang vue
|
|
698
744
|
* <script>
|
|
699
745
|
* export default {
|
|
700
746
|
* druxt: {
|
|
701
747
|
* query: {
|
|
748
|
+
* bypassCache: ({ $store }) => $store.$auth.loggedIn,
|
|
702
749
|
* bundleFilter: false,
|
|
703
|
-
* fields: [
|
|
750
|
+
* fields: [],
|
|
704
751
|
* resourceTypes: ['node--article'],
|
|
705
752
|
* },
|
|
706
|
-
* }
|
|
753
|
+
* },
|
|
707
754
|
* }
|
|
755
|
+
*
|
|
756
|
+
* @example <caption>DruxtView component with settings</caption> @lang vue
|
|
757
|
+
* <template>
|
|
758
|
+
* <DruxtView
|
|
759
|
+
* display-id="block_1"
|
|
760
|
+
* view-id="promoted_items
|
|
761
|
+
* :settings="{
|
|
762
|
+
* query: {
|
|
763
|
+
* bypassCache: true,
|
|
764
|
+
* bundleFilter: false,
|
|
765
|
+
* fields: ['title']
|
|
766
|
+
* resourceTypes: [],
|
|
767
|
+
* }
|
|
768
|
+
* }"
|
|
769
|
+
* />
|
|
770
|
+
* </template>
|
|
708
771
|
*/
|
|
709
772
|
|
|
710
773
|
/**
|
|
@@ -44,7 +44,17 @@ export default {
|
|
|
44
44
|
* @param {object} context - The module component ViewModel.
|
|
45
45
|
* @returns {PropsData}
|
|
46
46
|
*/
|
|
47
|
-
propsData: ({ filter, model }) => ({ filter, value: model })
|
|
47
|
+
propsData: ({ filter, model }) => ({ filter, value: model }),
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Druxt development template tool configuration.
|
|
51
|
+
*/
|
|
52
|
+
template: {
|
|
53
|
+
debug: "{ filter, model }",
|
|
54
|
+
mixins: {
|
|
55
|
+
'DruxtViewsFilterMixin': 'druxt-views'
|
|
56
|
+
}
|
|
57
|
+
}
|
|
48
58
|
},
|
|
49
59
|
}
|
|
50
60
|
|
|
@@ -115,6 +115,16 @@ export default {
|
|
|
115
115
|
|
|
116
116
|
return scopedSlots
|
|
117
117
|
},
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Druxt development template tool configuration.
|
|
121
|
+
*/
|
|
122
|
+
template: {
|
|
123
|
+
debug: "{ options, filters, model, type }",
|
|
124
|
+
mixins: {
|
|
125
|
+
'DruxtViewsFiltersMixin': 'druxt-views'
|
|
126
|
+
}
|
|
127
|
+
}
|
|
118
128
|
},
|
|
119
129
|
}
|
|
120
130
|
|
|
@@ -167,6 +167,16 @@ export default {
|
|
|
167
167
|
]),
|
|
168
168
|
])
|
|
169
169
|
}
|
|
170
|
+
},
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Druxt development template tool configuration.
|
|
174
|
+
*/
|
|
175
|
+
template: {
|
|
176
|
+
debug: "{ count, options, resource, type, model }",
|
|
177
|
+
mixins: {
|
|
178
|
+
'DruxtViewsPagerMixin': 'druxt-views'
|
|
179
|
+
}
|
|
170
180
|
}
|
|
171
181
|
}
|
|
172
182
|
}
|
|
@@ -112,6 +112,16 @@ export default {
|
|
|
112
112
|
])))
|
|
113
113
|
]),
|
|
114
114
|
}
|
|
115
|
+
},
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Druxt development template tool configuration.
|
|
119
|
+
*/
|
|
120
|
+
template: {
|
|
121
|
+
debug: "{ model, options, sorts, type }",
|
|
122
|
+
mixins: {
|
|
123
|
+
'DruxtViewsSortsMixin': 'druxt-views'
|
|
124
|
+
}
|
|
115
125
|
}
|
|
116
126
|
}
|
|
117
127
|
}
|
package/dist/druxt-views.esm.js
CHANGED
|
@@ -101,17 +101,36 @@ const DruxtViewsStore = ({ store }) => {
|
|
|
101
101
|
if (!state.results[viewId][displayId][prefix])
|
|
102
102
|
Vue.set(state.results[viewId][displayId], prefix, {});
|
|
103
103
|
Vue.set(state.results[viewId][displayId][prefix], hash, results);
|
|
104
|
+
},
|
|
105
|
+
flushResults(state, { viewId, displayId, prefix, hash }) {
|
|
106
|
+
if (!viewId)
|
|
107
|
+
Vue.set(state, "results", {});
|
|
108
|
+
else if (viewId && !displayId && !prefix && !hash)
|
|
109
|
+
Vue.set(state.results, viewId, {});
|
|
110
|
+
else if (viewId && displayId && !prefix && !hash)
|
|
111
|
+
Vue.set(state.results[viewId], displayId, {});
|
|
112
|
+
else if (viewId && displayId && prefix && !hash)
|
|
113
|
+
Vue.set(state.results[viewId][displayId], prefix, {});
|
|
114
|
+
else if (viewId && displayId && (prefix || prefix === void 0) && hash)
|
|
115
|
+
Vue.set(state.results[viewId][displayId][prefix], hash, {});
|
|
104
116
|
}
|
|
105
117
|
},
|
|
106
118
|
actions: {
|
|
107
|
-
async getResults({ commit, state }, { viewId, displayId, query, prefix }) {
|
|
119
|
+
async getResults({ commit, state }, { viewId, displayId, query, prefix, bypassCache = false }) {
|
|
108
120
|
const hash = query ? md5(this.$druxt.buildQueryUrl("", query)) : "_default";
|
|
121
|
+
let cache;
|
|
109
122
|
if (typeof (((state.results[viewId] || {})[displayId] || {})[prefix] || {})[hash] !== "undefined") {
|
|
110
|
-
|
|
123
|
+
cache = state.results[viewId][displayId][prefix][hash];
|
|
124
|
+
if (!bypassCache)
|
|
125
|
+
return cache;
|
|
126
|
+
}
|
|
127
|
+
try {
|
|
128
|
+
const results = await this.$druxt.getResource(`views--${viewId}`, displayId, query, prefix);
|
|
129
|
+
commit("addResults", { results, viewId, displayId, prefix, hash });
|
|
130
|
+
return results;
|
|
131
|
+
} catch (e) {
|
|
132
|
+
return cache ? cache : false;
|
|
111
133
|
}
|
|
112
|
-
const results = await this.$druxt.getResource(`views--${viewId}`, displayId, query, prefix);
|
|
113
|
-
commit("addResults", { results, viewId, displayId, prefix, hash });
|
|
114
|
-
return results;
|
|
115
134
|
}
|
|
116
135
|
}
|
|
117
136
|
};
|
package/dist/druxt-views.ssr.js
CHANGED
|
@@ -111,17 +111,36 @@ const DruxtViewsStore = ({ store }) => {
|
|
|
111
111
|
if (!state.results[viewId][displayId][prefix])
|
|
112
112
|
Vue__default["default"].set(state.results[viewId][displayId], prefix, {});
|
|
113
113
|
Vue__default["default"].set(state.results[viewId][displayId][prefix], hash, results);
|
|
114
|
+
},
|
|
115
|
+
flushResults(state, { viewId, displayId, prefix, hash }) {
|
|
116
|
+
if (!viewId)
|
|
117
|
+
Vue__default["default"].set(state, "results", {});
|
|
118
|
+
else if (viewId && !displayId && !prefix && !hash)
|
|
119
|
+
Vue__default["default"].set(state.results, viewId, {});
|
|
120
|
+
else if (viewId && displayId && !prefix && !hash)
|
|
121
|
+
Vue__default["default"].set(state.results[viewId], displayId, {});
|
|
122
|
+
else if (viewId && displayId && prefix && !hash)
|
|
123
|
+
Vue__default["default"].set(state.results[viewId][displayId], prefix, {});
|
|
124
|
+
else if (viewId && displayId && (prefix || prefix === void 0) && hash)
|
|
125
|
+
Vue__default["default"].set(state.results[viewId][displayId][prefix], hash, {});
|
|
114
126
|
}
|
|
115
127
|
},
|
|
116
128
|
actions: {
|
|
117
|
-
async getResults({ commit, state }, { viewId, displayId, query, prefix }) {
|
|
129
|
+
async getResults({ commit, state }, { viewId, displayId, query, prefix, bypassCache = false }) {
|
|
118
130
|
const hash = query ? md5__default["default"](this.$druxt.buildQueryUrl("", query)) : "_default";
|
|
131
|
+
let cache;
|
|
119
132
|
if (typeof (((state.results[viewId] || {})[displayId] || {})[prefix] || {})[hash] !== "undefined") {
|
|
120
|
-
|
|
133
|
+
cache = state.results[viewId][displayId][prefix][hash];
|
|
134
|
+
if (!bypassCache)
|
|
135
|
+
return cache;
|
|
136
|
+
}
|
|
137
|
+
try {
|
|
138
|
+
const results = await this.$druxt.getResource(`views--${viewId}`, displayId, query, prefix);
|
|
139
|
+
commit("addResults", { results, viewId, displayId, prefix, hash });
|
|
140
|
+
return results;
|
|
141
|
+
} catch (e) {
|
|
142
|
+
return cache ? cache : false;
|
|
121
143
|
}
|
|
122
|
-
const results = await this.$druxt.getResource(`views--${viewId}`, displayId, query, prefix);
|
|
123
|
-
commit("addResults", { results, viewId, displayId, prefix, hash });
|
|
124
|
-
return results;
|
|
125
144
|
}
|
|
126
145
|
}
|
|
127
146
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "druxt-views",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.22.0",
|
|
4
4
|
"description": "Drupal Views components for Druxt with support for filters, pagination and sorting.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cms",
|
|
@@ -41,17 +41,17 @@
|
|
|
41
41
|
"templates"
|
|
42
42
|
],
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"axios": "^
|
|
45
|
-
"deepmerge": "^4.
|
|
46
|
-
"drupal-jsonapi-params": "^2.
|
|
47
|
-
"druxt": "^0.
|
|
48
|
-
"druxt-blocks": "^0.
|
|
49
|
-
"druxt-entity": "^0.
|
|
50
|
-
"druxt-router": "^0.
|
|
44
|
+
"axios": "^1.4.0",
|
|
45
|
+
"deepmerge": "^4.3.1",
|
|
46
|
+
"drupal-jsonapi-params": "^2.2.0",
|
|
47
|
+
"druxt": "^0.22.0",
|
|
48
|
+
"druxt-blocks": "^0.17.1",
|
|
49
|
+
"druxt-entity": "^0.28.0",
|
|
50
|
+
"druxt-router": "^0.29.1",
|
|
51
51
|
"md5": "^2.3.0"
|
|
52
52
|
},
|
|
53
53
|
"optionalDependencies": {
|
|
54
|
-
"vue": "^2.
|
|
54
|
+
"vue": "^2.7.14",
|
|
55
55
|
"vuex": "^3.6.2"
|
|
56
56
|
},
|
|
57
57
|
"publishConfig": {
|