fleet/website/api/controllers/view-pricing.js
Eric 4feff451da
Website: Update pricing features yaml and pricing page. (#15294)
Closes: #15265

Changes:
- Updated `pricing-features-table.yml`:
- Changed the structure of the file so it is a flat array of features
(previously, features were nested under a category)
   - Added `productCategories` arrays to features that did not have them
   - Added `usualDepartment` values to features.
- Updated the pricing features validation in `build-static-content` to
work with the new file structure and made `productCategories` a required
value for features.
- Updated `view-pricing.js` to:
- categorize features based on the values of the `productCategories`
array
- build a single array of features (previously, it would also build an
array of features for security-focused buyers).
   - sort premium features to the bottom of the pricing table.
- Updated the `pricing.ejs` to:
   - render only the list of all features server-side
- conditionally show features in the pricing table, depending on the
selected pricing mode
2023-11-22 18:33:32 -06:00

58 lines
1.7 KiB
JavaScript
Vendored

module.exports = {
friendlyName: 'View pricing',
description: 'Display "Pricing" page.',
exits: {
success: {
viewTemplatePath: 'pages/pricing'
},
badConfig: {
responseType: 'badConfig'
},
},
fn: async function () {
if(!_.isObject(sails.config.builtStaticContent) || !_.isArray(sails.config.builtStaticContent.pricingTable)) {
throw {badConfig: 'builtStaticContent.pricingTable'};
}
let pricingTableFeatures = sails.config.builtStaticContent.pricingTable;
let pricingTable = [];
// Note: These product categories are hardcoded in to reduce complexity, an alternative way of building this from the pricingFeaturesTable is: let productCategories = _.union(_.flatten(_.pluck(pricingTableFeatures, 'productCategories')));
let productCategories = ['Endpoint operations', 'Device management', 'Vulnerability management'];
for(let category of productCategories) {
// Get all the features in that have a productCategories array that contains this category.
let featuresInThisCategory = _.filter(pricingTableFeatures, (feature)=>{
return _.contains(feature.productCategories, category);
});
// Build a dictionary containing the category name, and all features in the category, sorting premium features to the bottom of the list.
let allFeaturesInThisCategory = {
categoryName: category,
features: _.sortBy(featuresInThisCategory, (feature)=>{
return feature.tier !== 'Free';
})
};
// Add the dictionaries to the arrays that we'll use to build the features table.
pricingTable.push(allFeaturesInThisCategory);
}
// Respond with view.
return {
pricingTable
};
}
};