adminmate-express-mongoose 1.3.4 → 1.3.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "adminmate-express-mongoose",
3
- "version": "1.3.4",
3
+ "version": "1.3.5",
4
4
  "description": "Adminmate Express/Mongoose connector",
5
5
  "author": "Marc Delalonde",
6
6
  "homepage": "http://adminmate.io",
@@ -23,7 +23,7 @@
23
23
  "url": "https://github.com/Adminmate/adminmate-express-mongoose.git"
24
24
  },
25
25
  "dependencies": {
26
- "adminmate-express-core": "~1.2.1",
26
+ "adminmate-express-core": "~1.2.3",
27
27
  "joi": "^17.6.0",
28
28
  "lodash": "^4.17.21",
29
29
  "moment": "^2.29.1",
@@ -10,6 +10,7 @@ module.exports = _conf => {
10
10
  const filters = req.query.filters;
11
11
  const fieldsToFetch = req.headers['am-model-fields'] || [];
12
12
  const refFields = req.headers['am-ref-fields'] || {};
13
+ const inlineActions = req.headers['am-inline-actions'] || [];
13
14
  const fieldsToSearchIn = req.query.search_in_fields || [];
14
15
  const page = parseInt(req.query.page || 1);
15
16
  const nbItemPerPage = 10;
@@ -21,6 +22,9 @@ module.exports = _conf => {
21
22
  return res.status(403).json({ message: 'Invalid request' });
22
23
  }
23
24
 
25
+ // Model actions
26
+ const currentModelActions = fnHelper.getModelActions(modelName);
27
+
24
28
  // Get model properties
25
29
  const keys = fnHelper.getModelProperties(currentModel);
26
30
 
@@ -104,6 +108,16 @@ module.exports = _conf => {
104
108
  return fnHelper.refFields(item, fieldsToPopulate);
105
109
  });
106
110
 
111
+ // Inline actions button
112
+ const _inlineActions = currentModelActions.filter(action => inlineActions.includes(action.code));
113
+ if (_inlineActions.length) {
114
+ formattedData.forEach(item => {
115
+ item._am_inline_actions = _inlineActions
116
+ .filter(action => typeof action.filter === 'undefined' || action.filter(item))
117
+ .map(action => action.code);
118
+ })
119
+ }
120
+
107
121
  res.json({
108
122
  data: formattedData,
109
123
  count: dataCount,
@@ -434,6 +434,15 @@ module.exports = _conf => {
434
434
  return currentModel.segments;
435
435
  };
436
436
 
437
+ const getModelActions = modelCode => {
438
+ const currentModel = getModel(modelCode);
439
+ if (!currentModel) {
440
+ return null;
441
+ }
442
+
443
+ return currentModel.actions || [];
444
+ };
445
+
437
446
  const getModelSegment = (modelCode, segmentCode) => {
438
447
  const currentModel = getModel(modelCode);
439
448
  if (!currentModel || !currentModel.segments || currentModel.segments.length === 0) {
@@ -498,6 +507,7 @@ module.exports = _conf => {
498
507
  validateOrderStructure,
499
508
  getModelSegment,
500
509
  getModelSegments,
510
+ getModelActions,
501
511
  getModelObject,
502
512
  getModelAssociations,
503
513
  getModelPrimaryKeys,