UNPKG

corporate-frontend-mithril

Version:

Corporate frontend MithrilJS modules

103 lines (91 loc) 4.06 kB
const _ = require('lodash'); const AemBoardHelper = require('../aem-board-helper'); class ComparedBundlesPanelModel { constructor(){ } getDisplayList(source, destination) { // Source data source = JSON.parse(JSON.stringify(source)); AemBoardHelper.insertServerToBundles(source.bundleGroups, source.server, 1); // //Destination data destination = JSON.parse(JSON.stringify(destination)); AemBoardHelper.insertServerToBundles(destination.bundleGroups, destination.server, 1); let environments = _.sortBy(_.concat(source.bundleGroups, destination.bundleGroups)); return this._generateComparedList(environments, source.server, destination.server); } getBundleStateClass(bundle) { return AemBoardHelper.getBundleStateClass(bundle); } getBundleStateText(bundle) { return AemBoardHelper.getBundleStateText(bundle); } getBundleNameClass(bundleGroup){ return Object.is(this.getDestinationBundleClass(bundleGroup, 'author1'), '') && Object.is(this.getDestinationBundleClass(bundleGroup, 'publish1'), '') && Object.is(this.getDestinationBundleClass(bundleGroup, 'publish2'), '') && Object.is(this.getDestinationBundleClass(bundleGroup, 'publish3'), '') ? '' : '.b-featured-table__cell--dark'; } getDestinationBundleClass(bundleGroup, instance) { let sourceInstance = instance.includes('publish') ? 'publish1' : instance.includes('author') ? 'author1' : instance; let bundleClass = '.b-featured-table__cell--dark'; //source and destination all undefined or all defined with the same version return Object.is( !Object.is(bundleGroup.source[sourceInstance], undefined), !Object.is(bundleGroup.destination[instance], undefined) ) && Object.is( bundleGroup.source[sourceInstance] && bundleGroup.source[sourceInstance].version, bundleGroup.destination[instance] && bundleGroup.destination[instance].version ) ? '' : bundleClass; } /**--------------------- Helpers --------------------------- */ /** * * @param {*} environments * @param {*} sourceServer * @param {*} destinationServer * @example - a bundle object looks like this: * { // 'name': '', // 'source' : { // 'server': '', // 'author1' : {}, // 'publish1' : {}, // }, // 'destination' : { // 'server': '', // 'author1' : {}, // 'publish1' : {}, // }, // }; */ _generateComparedList(environments, sourceServer, destinationServer) { let bundleGroups = {}; _.each(environments, (env)=> { //create bundle object if(Object.is(bundleGroups[env[0]], undefined)) { bundleGroups[env[0]] = {}; } //add the name bundleGroups[env[0]].name = env[0]; //source if(env[1] === sourceServer) { bundleGroups[env[0]].source = { server: sourceServer, author1: AemBoardHelper.findInstanceBundle(env[2], 'author1'), publish1: AemBoardHelper.findInstanceBundle(env[2], 'publish1'), }; } //destination if(env[1] === destinationServer) { bundleGroups[env[0]].destination = { server: destinationServer, author1: AemBoardHelper.findInstanceBundle(env[2], 'author1'), publish1: AemBoardHelper.findInstanceBundle(env[2], 'publish1'), publish2: AemBoardHelper.findInstanceBundle(env[2], 'publish2'), publish3: AemBoardHelper.findInstanceBundle(env[2], 'publish3'), }; } }); return bundleGroups; } } module.exports = new ComparedBundlesPanelModel();