From db02e8bdbaae109456791230526a55c4f2964b5c Mon Sep 17 00:00:00 2001 From: hrushikesh07 Date: Tue, 27 Sep 2016 16:51:10 +0530 Subject: [PATCH 01/12] Changed the split up data, added path for analytics in jquery page clear filter changed --- .../dashboard/analytics/analytics.html | 18 +++++++-------- .../sections/dashboard/analytics/analytics.js | 10 +++++--- .../analytics/controller/costCtrl.js | 14 ++++++----- client/htmls/private/index.html | 23 ++++++++++++++++++- 4 files changed, 46 insertions(+), 19 deletions(-) diff --git a/client/cat3/src/partials/sections/dashboard/analytics/analytics.html b/client/cat3/src/partials/sections/dashboard/analytics/analytics.html index 683ce3bfe..86f795f6f 100644 --- a/client/cat3/src/partials/sections/dashboard/analytics/analytics.html +++ b/client/cat3/src/partials/sections/dashboard/analytics/analytics.html @@ -88,8 +88,8 @@
- - + +
@@ -109,18 +109,18 @@
- - - - + + + +
- + - {{filter.title}} :{{filter.name}} + {{filt.title}} :{{filt.name}}
diff --git a/client/cat3/src/partials/sections/dashboard/analytics/analytics.js b/client/cat3/src/partials/sections/dashboard/analytics/analytics.js index d78ee10c5..12f865892 100644 --- a/client/cat3/src/partials/sections/dashboard/analytics/analytics.js +++ b/client/cat3/src/partials/sections/dashboard/analytics/analytics.js @@ -75,7 +75,9 @@ //$rootScope.$emit('treeNameUpdate', treeNames); $rootScope.$emit('HEADER_NAV_CHANGE', 'ANALYTICS'); $rootScope.organNewEnt=[]; + $rootScope.filterNewEnt={}; $rootScope.organNewEnt.org = '0'; + $rootScope.filterNewEnt.period='month'; $rootScope.splitUpCosts=[]; analytic.viewByFilter='orgView'; $scope.$watch(function() { return analytic.viewByFilter}, function(newVal, oldVal) { @@ -83,6 +85,7 @@ $rootScope.viewType='ProviderView'; $state.params.filterView.provi=true; } else { + $rootScope.organNewEnt.provider='' $rootScope.viewType='orgView'; $state.params.filterView.provi=false; } @@ -94,15 +97,16 @@ $scope.$watch(function() { return analytic.splitUp}, function(newVal, oldVal) { $scope.$broadcast('CHANGE_VIEW',newVal); }, true); - $rootScope.filterNewEnt={}; analytic.applyCount=0 - analytic.applyFilter = function(filterApp){ + analytic.applyFilter = function(filterApp,period){ $rootScope.filterApply= new Date(); var obj=$rootScope.organObject, or=$rootScope.organNewEnt.org, bu=$rootScope.organNewEnt.buss, pr=$rootScope.organNewEnt.proj; - $rootScope.filterNewEnt={} + if(period) + $rootScope.filterNewEnt.period=period; + if(or){ $rootScope.filterNewEnt.org={name:obj[or].name,id:obj[or].rowid,title:'Org'}; $rootScope.filterNewEnt.provider=''; diff --git a/client/cat3/src/partials/sections/dashboard/analytics/controller/costCtrl.js b/client/cat3/src/partials/sections/dashboard/analytics/controller/costCtrl.js index 15885d7a9..ec1226b8e 100644 --- a/client/cat3/src/partials/sections/dashboard/analytics/controller/costCtrl.js +++ b/client/cat3/src/partials/sections/dashboard/analytics/controller/costCtrl.js @@ -109,19 +109,21 @@ } else { entityId=fltObj.org.id; } - param.url='/analytics/cost/aggregate?parentEntityId='+fltObj.org.id+'&entityId='+entityId+'&toTimeStamp='+new Date()+'&period=month'; + param.url='/analytics/cost/aggregate?parentEntityId='+fltObj.org.id+'&entityId='+entityId+'&toTimeStamp='+new Date()+'&period='+fltObj.period; } genSevs.promiseGet(param).then(function (result) { costObj.chartData=result; $rootScope.splitUpCosts=[]; - console.log('aaa',result.splitUpCosts); if(result.splitUpCosts) { angular.forEach(result.splitUpCosts, function (val, key) { - $rootScope.splitUpCosts.push(key); + var a=key.replace(/([A-Z])/g, ' $1').replace(/^./, function(str) { + return str.toUpperCase(); + }); + $rootScope.splitUpCosts.push({id:key,val:a}); }); - $scope.$emit('CHANGE_splitUp', $rootScope.splitUpCosts[0]); - costObj.createLable(result, $rootScope.splitUpCosts[0]); + $scope.$emit('CHANGE_splitUp', $rootScope.splitUpCosts[0].id); + costObj.createLable(result, $rootScope.splitUpCosts[0].id); } else { costObj.createLable(result,'provider'); } @@ -250,7 +252,7 @@ } else { entityId=fltObj.org.id; } - param.url='/analytics/cost/trend?parentEntityId='+fltObj.org.id+'&entityId='+fltObj.org.id+'&toTimeStamp='+new Date()+'&period=month&interval=86400' + param.url='/analytics/cost/trend?parentEntityId='+fltObj.org.id+'&entityId='+fltObj.org.id+'&toTimeStamp='+new Date()+'&period='+fltObj.period+'&interval=86400' } genSevs.promiseGet(param).then(function (result) { diff --git a/client/htmls/private/index.html b/client/htmls/private/index.html index e3b419898..17adab73a 100644 --- a/client/htmls/private/index.html +++ b/client/htmls/private/index.html @@ -47,6 +47,11 @@ + @@ -754,7 +759,23 @@
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- -
-
-
- -
-
-
    -
  • First itemitemitemitem
  • -
  • Second item
  • -
  • Third item
  • -
-
-
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+
+
+ +
+
+
    +
  • {{resource.platformId}}
  • +
+
- - -
- -
+
+
+ + +

@@ -108,22 +113,21 @@
-
- - - - - -
+
+ + + + + +
{{filt.title}} :{{filt.name}}
-
diff --git a/client/cat3/src/partials/sections/dashboard/analytics/analytics.js b/client/cat3/src/partials/sections/dashboard/analytics/analytics.js index 12f865892..9c64d1f66 100644 --- a/client/cat3/src/partials/sections/dashboard/analytics/analytics.js +++ b/client/cat3/src/partials/sections/dashboard/analytics/analytics.js @@ -19,7 +19,6 @@ deferred.reject({redirectTo: 'dashboard'}); } return deferred.promise; - }] } }).state('dashboard.analytics.capacity', { @@ -38,14 +37,13 @@ deferred.reject({redirectTo: 'dashboard'}); } return deferred.promise; - }] } }).state('dashboard.analytics.usage', { url: "usage/", templateUrl: "src/partials/sections/dashboard/analytics/view/usage.html", controller: "usageCtrl as usage", - params:{filterView:{org:true,provi:true,region:true,resources:true}}, + params:{filterView:{org:true,provi:true,region:false,instanceType:true,resources:true}}, resolve: { auth: ["$q", function ($q) { var deferred = $q.defer(); @@ -57,7 +55,6 @@ deferred.reject({redirectTo: 'dashboard'}); } return deferred.promise; - }] } }) @@ -79,16 +76,17 @@ $rootScope.organNewEnt.org = '0'; $rootScope.filterNewEnt.period='month'; $rootScope.splitUpCosts=[]; + $scope.selectedResources = []; analytic.viewByFilter='orgView'; $scope.$watch(function() { return analytic.viewByFilter}, function(newVal, oldVal) { - if(newVal === 'ProviderView'){ - $rootScope.viewType='ProviderView'; - $state.params.filterView.provi=true; - } else { - $rootScope.organNewEnt.provider='' - $rootScope.viewType='orgView'; - $state.params.filterView.provi=false; - } + if(newVal === 'ProviderView'){ + $rootScope.viewType='ProviderView'; + $state.params.filterView.provi=true; + } else { + $rootScope.organNewEnt.provider='' + $rootScope.viewType='orgView'; + $state.params.filterView.provi=false; + } $rootScope.stateItems = $state.params; }, true); $scope.$on('CHANGE_splitUp', function (event, data) { @@ -131,7 +129,7 @@ analytic.splitUp=$rootScope.splitUpCosts[0]; } }; - // // get organigetion + //get organisation genericServices.getTreeNew().then(function (orgs) { $rootScope.organObject = orgs; analytic.applyFilter(true); @@ -165,6 +163,8 @@ $scope.getProviders = function() { workzoneServices.getProviders().then(function(response) { $scope.providers = response.data; + $scope.filter = []; + $scope.filter.providerId = response.data[0]._id; }, function(error) { toastr.error(error); }); @@ -209,5 +209,40 @@ $scope.getProviderRegions(); } }; + $scope.getResourse = function(instType) { + if(instType === 'Managed') { + workzoneServices.getManagedInstances($scope.filter.providerId).then(function(response) { + $scope.resourceList = response.data; + }, function(error) { + toastr.error(error); + }); + } + if(instType === 'Assigned') { + workzoneServices.getAssignedInstances($scope.filter.providerId).then(function(response) { + $scope.resourceList = response.data.unmanagedInstances; + }, function(error) { + toastr.error(error); + }); + } + if(instType === 'Unassigned') { + workzoneServices.getUnassignedInstances($scope.filter.providerId).then(function(response) { + $scope.resourceList = response.data.data; + }, function(error) { + toastr.error(error); + }); + } + }; + $scope.toggleResourceSelection = function(resourceId) { + var idx = $scope.selectedResources.indexOf(resourceId); + if(idx > -1) { + $scope.selectedResources.splice(idx, 1); + } else { + if($scope.selectedResources.length === 5){ + toastr.error('Maximum 5 resources allowed.'); + }else{ + $scope.selectedResources.push(resourceId); + } + } + }; }]); -})(angular); +})(angular); \ No newline at end of file diff --git a/client/cat3/src/partials/sections/dashboard/analytics/analytics.scss b/client/cat3/src/partials/sections/dashboard/analytics/analytics.scss index ec22e0e14..f05b6671a 100644 --- a/client/cat3/src/partials/sections/dashboard/analytics/analytics.scss +++ b/client/cat3/src/partials/sections/dashboard/analytics/analytics.scss @@ -227,8 +227,8 @@ } .bp-panel-body { - max-height:150px; - min-height: 100px; + max-height: 105px; + min-height: 80px; overflow-y: auto; } @@ -264,4 +264,8 @@ .filter-name { margin-top: -21px; } + + .selected { + background: #ddd; + } } \ No newline at end of file From 23f5c2a5c5ff2a42b1c8f750f5c54b3cb529dbc6 Mon Sep 17 00:00:00 2001 From: Karthik K N Date: Wed, 28 Sep 2016 13:39:35 +0530 Subject: [PATCH 03/12] Service costs aggregation enabled for AWS providers --- .../AWSResourceCostsAggregation.js | 9 +- server/app/services/analyticsService.js | 178 ++++++++++++++---- server/app/services/resourceService.js | 8 + 3 files changed, 152 insertions(+), 43 deletions(-) diff --git a/server/app/cronjobs/aws-cost-aggregation/AWSResourceCostsAggregation.js b/server/app/cronjobs/aws-cost-aggregation/AWSResourceCostsAggregation.js index a2bed5614..8d9041e8d 100644 --- a/server/app/cronjobs/aws-cost-aggregation/AWSResourceCostsAggregation.js +++ b/server/app/cronjobs/aws-cost-aggregation/AWSResourceCostsAggregation.js @@ -21,6 +21,7 @@ var S3 = require('_pr/lib/s3.js') var AWSProvider = require('_pr/model/classes/masters/cloudprovider/awsCloudProvider.js') var MasterUtils = require('_pr/lib/utils/masterUtil.js') var resourceService = require('_pr/services/resourceService') +var analyticsService = require('_pr/services/analyticsService') var CatalystCronJob = require('_pr/cronjobs/CatalystCronJob') var dateUtil = require('_pr/lib/utils/dateUtil') var AdmZip = require('adm-zip') @@ -229,7 +230,7 @@ function aggregateEntityCostsByOrg(orgs, callback) { async.forEach(Object.keys(costAggregationPeriods), function(period, next0) { // Organization children entities cost aggregation async.forEach(orgs, function(org, next1) { - resourceService.aggregateEntityCosts('organization', org.rowid, {'organizationId': org.rowid}, + analyticsService.aggregateEntityCosts('organization', org.rowid, {'organizationId': org.rowid}, AWSResourceCostsAggregation.currentCronRunTime, period, next1) }, function(err) { if(err) { @@ -256,7 +257,7 @@ function aggregateEntityCostsByProvider(providers, callback) { async.forEach(Object.keys(costAggregationPeriods), function(period, next0) { // Provider children entities cost aggregation async.forEach(providers, function (provider, next2) { - resourceService.aggregateEntityCosts('provider', provider._id, {'providerId': provider._id}, + analyticsService.aggregateEntityCosts('provider', provider._id, {'providerId': provider._id}, AWSResourceCostsAggregation.currentCronRunTime, period, next2) }, function (err) { if (err) { @@ -293,7 +294,7 @@ function aggregateEntityCostTrendByOrg(orgs, callback) { async.forEach(orgs, function (org, next0) { async.forEach(endOfDayTimeStamps, function(dayTimeStamp, next1) { - resourceService.aggregateEntityCosts('organization', org.rowid, {'organizationId': org.rowid}, + analyticsService.aggregateEntityCosts('organization', org.rowid, {'organizationId': org.rowid}, new Date(dayTimeStamp), 'day', next1) }, function(err) { if(err) { @@ -326,7 +327,7 @@ function aggregateEntityCostTrendByProvider(providers, callback) { async.forEach(providers, function (provider, next0) { async.forEach(endOfDayTimeStamps, function(dayTimeStamp, next1) { - resourceService.aggregateEntityCosts('provider', provider._id, {'providerId': provider._id}, + analyticsService.aggregateEntityCosts('provider', provider._id, {'providerId': provider._id}, new Date(dayTimeStamp), 'day', next1) }, function(err) { if(err) { diff --git a/server/app/services/analyticsService.js b/server/app/services/analyticsService.js index cfbb4f12f..bec16e5c7 100644 --- a/server/app/services/analyticsService.js +++ b/server/app/services/analyticsService.js @@ -24,7 +24,141 @@ var async = require('async') var d4dModelNew = require('_pr/model/d4dmasters/d4dmastersmodelnew.js') var AWSProvider = require('_pr/model/classes/masters/cloudprovider/awsCloudProvider.js') -var analyticsService = module.exports = {}; +var analyticsService = module.exports = {} + +analyticsService.aggregateEntityCosts + = function aggregateEntityCosts(parentEntity, parentEntityId, parentEntityQuery, endTime, period, callback) { + var catalystEntityHierarchy = appConfig.catalystEntityHierarchy + var costAggregationPeriods = appConfig.costAggregationPeriods + var platformServices = Object.keys(appConfig.aws.services).map(function(key) { + return appConfig.aws.services[key] + }) + + var startTime + var interval + switch (period) { + case 'month': + startTime = dateUtil.getStartOfAMonthInUTC(endTime) + interval = costAggregationPeriods.month.intervalInSeconds + break + case 'day': + startTime = dateUtil.getStartOfADayInUTC(endTime) + interval = costAggregationPeriods.day.intervalInSeconds + break + } + + async.forEach(catalystEntityHierarchy[parentEntity].children, function (childEntity, next0) { + var query = parentEntityQuery + query.startTime = {$gte: Date.parse(startTime)} + query.endTime = {$lte: Date.parse(endTime)} + + async.waterfall([ + function(next1) { + resourceCostsModel.aggregate([ + {$match: query}, + {$group: {_id: "$" + catalystEntityHierarchy[childEntity].key, + totalCost: {$sum: "$cost"}}} + ], next1) + }, + function(totalCosts, next1) { + var serviceCosts = [] + async.forEach(platformServices, + function(service, next2) { + query['platformDetails.serviceId'] = service + + resourceCostsModel.aggregate([ + {$match: query}, + {$group: {_id: "$" + catalystEntityHierarchy[childEntity].key, + totalCost: {$sum: "$cost"}, + service: {$first: "$platformDetails.serviceId"}}} + ], function(err, serviceCost) { + if(err) { + next2(err) + } else { + serviceCosts.push(serviceCost) + next2() + } + }) + }, + function(err) { + if(err) { + return next1(err) + } + var aggregatedCosts = {totalCosts: totalCosts} + aggregatedCosts.serviceCosts = serviceCosts + + next1(null, aggregatedCosts) + } + ) + } + ], + function(err, aggregateCosts) { + if(err) + return next0(err) + + var entityCosts = {} + for(var i = 0; i < aggregateCosts.totalCosts.length; i++) { + entityCosts[aggregateCosts.totalCosts[i]._id] = { + entity: { + id: aggregateCosts.totalCosts[i]._id, + type: childEntity + }, + parentEntity: { + id: parentEntityId, + type: parentEntity + }, + costs: { + totalCost: Math.round(aggregateCosts.totalCosts[i].totalCost * 100) / 100, + AWS: { + totalCost: Math.round(aggregateCosts.totalCosts[i].totalCost * 100) / 100, + serviceCosts: {} + } + }, + startTime: Date.parse(startTime), + endTime: Date.parse(endTime), + period: period, + interval: interval + } + } + + for(var i = 0; i < aggregateCosts.serviceCosts.length; i++) { + for(var j = 0; j < aggregateCosts.serviceCosts[i].length; j++) { + if(aggregateCosts.serviceCosts[i][j]._id in entityCosts) { + entityCosts[aggregateCosts.serviceCosts[i][j]._id] + .costs.AWS.serviceCosts[aggregateCosts.serviceCosts[i][j].service] + = Math.round(aggregateCosts.serviceCosts[i][j].totalCost * 100) / 100 + } + } + } + + if(Object.keys(entityCosts).length > 0) + analyticsService.updateEntityCosts(entityCosts, next0) + else + next0() + }) + + }, function (err) { + if (err) { + return callback(err) + } else { + callback() + } + }) +} + +analyticsService.updateEntityCosts = function updateEntityCosts(entityCosts, callback) { + async.forEach(entityCosts, + function(entityCost, next) { + entityCostsModel.upsertEntityCost(entityCost, next) + }, + function(err) { + if(err) + return callback(err) + + return callback() + } + ) +} // @TODO To be reviewed and improved analyticsService.validateAndParseCostQuery @@ -140,7 +274,6 @@ analyticsService.formatAggregateCost = function formatAggregateCost(entityCosts, async.waterfall([ function(next) { - var totalCost = Math.round(entityCosts.totalCost[0].costs.totalCost * 100) / 100 var formattedAggregateCost = { period: entityCosts.totalCost[0].period, fromTime: entityCosts.totalCost[0].startTime, @@ -150,15 +283,7 @@ analyticsService.formatAggregateCost = function formatAggregateCost(entityCosts, id: entityCosts.totalCost[0].entity.id, name: entityCosts.totalCost[0].entity.name }, - cost: { - totalCost: totalCost, - AWS: { - totalCost: totalCost, - serviceCosts: { - Other: totalCost - } - } - }, + cost: entityCosts.totalCost[0].costs, splitUpCosts: {} } @@ -188,15 +313,7 @@ analyticsService.formatAggregateCost = function formatAggregateCost(entityCosts, var splitUpCost = { id: costEntry.entity.id, // name: costEntry.entity.name, - cost: { - totalCost: Math.round(costEntry.costs.totalCost * 100) / 100, - AWS: { - totalCost: Math.round(costEntry.costs.totalCost * 100) / 100, - serviceCosts: { - Other: Math.round(costEntry.costs.totalCost * 100) / 100 - } - } - } + cost: costEntry.costs } if (costEntry.entity.id != 'Unassigned' && costEntry.entity.id != 'Other' @@ -250,7 +367,6 @@ analyticsService.formatCostTrend = function formatCostTrend(entityCosts, callbac costTrends: [] } if(entityCosts.totalCost != null) { - var totalCost = Math.round(entityCosts.totalCost[0].costs.totalCost * 100) / 100 formattedCostTrend = { period: entityCosts.totalCost[0].period, fromTime: entityCosts.totalCost[0].startTime, @@ -260,15 +376,7 @@ analyticsService.formatCostTrend = function formatCostTrend(entityCosts, callbac id: entityCosts.totalCost[0].entity.id, name: entityCosts.totalCost[0].entity.name }, - cost: { - totalCost: totalCost, - AWS: { - totalCost: totalCost, - serviceCosts: { - Other: totalCost - } - } - }, + cost: entityCosts.totalCost[0].costs, costTrends: [] } } @@ -291,15 +399,7 @@ analyticsService.formatCostTrend = function formatCostTrend(entityCosts, callbac var trend = { fromTime: costEntry.startTime, toTime: costEntry.endTime, - cost: { - totalCost: Math.round(costEntry.costs.totalCost * 100)/100, - AWS: { - totalCost: Math.round(costEntry.costs.totalCost * 100)/100, - serviceCosts: { - Other: Math.round(costEntry.costs.totalCost * 100)/100 - } - } - } + cost: costEntry.costs } formattedCostTrend.costTrends.push(trend) diff --git a/server/app/services/resourceService.js b/server/app/services/resourceService.js index 13f3491db..1791d7075 100644 --- a/server/app/services/resourceService.js +++ b/server/app/services/resourceService.js @@ -267,6 +267,14 @@ function aggregateEntityCosts(parentEntity, parentEntityId, parentEntityQuery, e }) } +function aggregateTotalCost() { + +} + +function aggregateAWSServiceCosts() { + +} + function getCostForServices_deprecated(provider,callback) { var cryptoConfig = appConfig.cryptoSettings; var cryptography = new Cryptography(cryptoConfig.algorithm, cryptoConfig.password); From 12da17cc3c36fdeabbc797c5880d6abeefb4f4d9 Mon Sep 17 00:00:00 2001 From: Karthik K N Date: Wed, 28 Sep 2016 14:01:56 +0530 Subject: [PATCH 04/12] Entity cost aggregation code refactored --- .../AWSResourceCostsAggregation.js | 13 ++- server/app/services/analyticsService.js | 84 +++++++------- server/app/services/resourceService.js | 106 ------------------ 3 files changed, 51 insertions(+), 152 deletions(-) diff --git a/server/app/cronjobs/aws-cost-aggregation/AWSResourceCostsAggregation.js b/server/app/cronjobs/aws-cost-aggregation/AWSResourceCostsAggregation.js index 8d9041e8d..cab81a0b6 100644 --- a/server/app/cronjobs/aws-cost-aggregation/AWSResourceCostsAggregation.js +++ b/server/app/cronjobs/aws-cost-aggregation/AWSResourceCostsAggregation.js @@ -88,7 +88,6 @@ function aggregateAWSResourceCosts() { function(next1) { AWSResourceCostsAggregation.aggregateEntityCostsByProvider(providers, next1) } - ], function(err) { if(err) { next(err) @@ -241,10 +240,10 @@ function aggregateEntityCostsByOrg(orgs, callback) { }) }, function(err) { if(err) { - logger.error('Entity cost aggregation failed') + logger.error('Entity cost aggregation by org failed') logger.error(err) } else { - logger.info('Entity cost aggregation complete') + logger.info('Entity cost aggregation by org complete') callback() } }) @@ -268,10 +267,10 @@ function aggregateEntityCostsByProvider(providers, callback) { }) }, function(err) { if(err) { - logger.error('Entity cost aggregation failed') + logger.error('Entity cost aggregation by provider failed') logger.error(err) } else { - logger.info('Entity cost aggregation complete') + logger.info('Entity cost aggregation by provider complete') callback() } }) @@ -305,8 +304,10 @@ function aggregateEntityCostTrendByOrg(orgs, callback) { }) }, function (err) { if (err) { + logger.error('Entity cost trend aggregation by org failed') callback(err) } else { + logger.info('Entity cost trend aggregation by org complete') callback() } }) @@ -338,8 +339,10 @@ function aggregateEntityCostTrendByProvider(providers, callback) { }) }, function (err) { if (err) { + logger.error('Entity cost trend aggregation by provider failed') callback(err) } else { + logger.info('Entity cost trend aggregation by provider complete') callback() } }) diff --git a/server/app/services/analyticsService.js b/server/app/services/analyticsService.js index bec16e5c7..398340b94 100644 --- a/server/app/services/analyticsService.js +++ b/server/app/services/analyticsService.js @@ -83,63 +83,65 @@ analyticsService.aggregateEntityCosts function(err) { if(err) { return next1(err) - } - var aggregatedCosts = {totalCosts: totalCosts} - aggregatedCosts.serviceCosts = serviceCosts + } else { + var aggregatedCosts = {totalCosts: totalCosts} + aggregatedCosts.serviceCosts = serviceCosts - next1(null, aggregatedCosts) + next1(null, aggregatedCosts) + } } ) } ], function(err, aggregateCosts) { - if(err) - return next0(err) - - var entityCosts = {} - for(var i = 0; i < aggregateCosts.totalCosts.length; i++) { - entityCosts[aggregateCosts.totalCosts[i]._id] = { - entity: { - id: aggregateCosts.totalCosts[i]._id, - type: childEntity - }, - parentEntity: { - id: parentEntityId, - type: parentEntity - }, - costs: { - totalCost: Math.round(aggregateCosts.totalCosts[i].totalCost * 100) / 100, - AWS: { + if(err) { + next0(err) + } else { + var entityCosts = {} + for(var i = 0; i < aggregateCosts.totalCosts.length; i++) { + entityCosts[aggregateCosts.totalCosts[i]._id] = { + entity: { + id: aggregateCosts.totalCosts[i]._id, + type: childEntity + }, + parentEntity: { + id: parentEntityId, + type: parentEntity + }, + costs: { totalCost: Math.round(aggregateCosts.totalCosts[i].totalCost * 100) / 100, - serviceCosts: {} - } - }, - startTime: Date.parse(startTime), - endTime: Date.parse(endTime), - period: period, - interval: interval + AWS: { + totalCost: Math.round(aggregateCosts.totalCosts[i].totalCost * 100) / 100, + serviceCosts: {} + } + }, + startTime: Date.parse(startTime), + endTime: Date.parse(endTime), + period: period, + interval: interval + } } - } - for(var i = 0; i < aggregateCosts.serviceCosts.length; i++) { - for(var j = 0; j < aggregateCosts.serviceCosts[i].length; j++) { - if(aggregateCosts.serviceCosts[i][j]._id in entityCosts) { - entityCosts[aggregateCosts.serviceCosts[i][j]._id] - .costs.AWS.serviceCosts[aggregateCosts.serviceCosts[i][j].service] - = Math.round(aggregateCosts.serviceCosts[i][j].totalCost * 100) / 100 + for(var i = 0; i < aggregateCosts.serviceCosts.length; i++) { + for(var j = 0; j < aggregateCosts.serviceCosts[i].length; j++) { + if(aggregateCosts.serviceCosts[i][j]._id in entityCosts) { + entityCosts[aggregateCosts.serviceCosts[i][j]._id] + .costs.AWS.serviceCosts[aggregateCosts.serviceCosts[i][j].service] + = Math.round(aggregateCosts.serviceCosts[i][j].totalCost * 100) / 100 + } } } - } - if(Object.keys(entityCosts).length > 0) - analyticsService.updateEntityCosts(entityCosts, next0) - else - next0() + if(Object.keys(entityCosts).length > 0) + analyticsService.updateEntityCosts(entityCosts, next0) + else + next0() + } }) }, function (err) { if (err) { - return callback(err) + callback(err) } else { callback() } diff --git a/server/app/services/resourceService.js b/server/app/services/resourceService.js index 1791d7075..ae92f8aa0 100644 --- a/server/app/services/resourceService.js +++ b/server/app/services/resourceService.js @@ -169,112 +169,6 @@ function updateAWSResourceCostsFromCSV(provider, resources, downlaodedCSVPath, u }) } -// NOTE: Only monthly costs aggregated. -function aggregateEntityCosts(parentEntity, parentEntityId, parentEntityQuery, endTime, period, callback) { - var mongoConnectionString = 'mongodb://' + appConfig.db.host + ':' + appConfig.db.port + '/' + appConfig.db.dbName - var catalystEntityHierarchy = appConfig.catalystEntityHierarchy - var costAggregationPeriods = appConfig.costAggregationPeriods - - var startTime - var interval - switch (period) { - case 'month': - startTime = dateUtil.getStartOfAMonthInUTC(endTime) - interval = costAggregationPeriods.month.intervalInSeconds - break - case 'day': - startTime = dateUtil.getStartOfADayInUTC(endTime) - interval = costAggregationPeriods.day.intervalInSeconds - break - } - - mongoDbClient.connect(mongoConnectionString, function(err, db) { - if(err) { - return callback(err) - } - - async.forEach(catalystEntityHierarchy[parentEntity].children, function (childEntity, next) { - //@TODO Consider replacing with Mongo aggregate $sum - var map = function() { - emit(this.childEntityKey, {cost: this.cost}) - } - - var reduce = function (key, values) { - var reducedObject = { cost: 0 } - - values.forEach(function(value) { - reducedObject.cost += value.cost - }) - - return reducedObject - } - - var query = parentEntityQuery - query.startTime = {$gte: Date.parse(startTime)} - query.endTime = {$lte: Date.parse(endTime)} - - var command = { - mapreduce: 'resourcecosts', - map: map.toString().replace(/childEntityKey/, catalystEntityHierarchy[childEntity].key), - reduce: reduce.toString(), - query: query, - out: {inline: 1} - } - - db.command(command, function (err, result) { - if(err) { - logger.error(err) - next(err) - } else if(result.ok == 1){ - //@TODO To be handled outside - async.forEach(result.results, function(entry, next) { - var entityCost = { - entity: { - id: entry._id, - type: childEntity - }, - parentEntity: { - id: parentEntityId, - type: parentEntity - }, - costs: { - totalCost: entry.value.cost - }, - startTime: Date.parse(startTime), - endTime: Date.parse(endTime), - period: period, - interval: interval - } - - entityCosts.upsertEntityCost(entityCost, next) - }, - function(err) { - if(err) { - return next(err) - } - - return next() - }) - } - }) - }, function (err) { - if(err) { - callback(err) - } else { - callback() - } - }) - }) -} - -function aggregateTotalCost() { - -} - -function aggregateAWSServiceCosts() { - -} - function getCostForServices_deprecated(provider,callback) { var cryptoConfig = appConfig.cryptoSettings; var cryptography = new Cryptography(cryptoConfig.algorithm, cryptoConfig.password); From 08e0ea502d98229483e063cab6020278f25d234f Mon Sep 17 00:00:00 2001 From: Karthik K N Date: Wed, 28 Sep 2016 14:35:49 +0530 Subject: [PATCH 05/12] resource service refactored --- server/app/services/resourceService.js | 1 - 1 file changed, 1 deletion(-) diff --git a/server/app/services/resourceService.js b/server/app/services/resourceService.js index ae92f8aa0..6c641b673 100644 --- a/server/app/services/resourceService.js +++ b/server/app/services/resourceService.js @@ -46,7 +46,6 @@ resourceService.bulkUpdateAWSResourcesTags=bulkUpdateAWSResourcesTags; resourceService.getEC2InstancesInfo=getEC2InstancesInfo; resourceService.getAllResourcesForProvider = getAllResourcesForProvider; resourceService.updateAWSResourceCostsFromCSV = updateAWSResourceCostsFromCSV -resourceService.aggregateEntityCosts = aggregateEntityCosts resourceService.updateDomainNameForInstance = updateDomainNameForInstance // @TODO To be cached if needed. In memory data will not exceed 200MB for upto 2000 instances. From 6ae40ff4737965a1fa82baa06f042d5d0a4764ee Mon Sep 17 00:00:00 2001 From: hrushikesh07 Date: Wed, 28 Sep 2016 17:39:52 +0530 Subject: [PATCH 06/12] Chinged filter and filter event --- .../dashboard/analytics/analytics.html | 4 +- .../sections/dashboard/analytics/analytics.js | 56 ++--------- .../dashboard/analytics/analytics.scss | 2 +- .../dashboard/analytics/analyticsServices.js | 53 +++++++++- .../analytics/controller/costCtrl.js | 98 +++++++++---------- .../analytics/controller/usageCtrl.js | 46 +++++---- .../dashboard/analytics/view/cost.html | 23 +++-- 7 files changed, 152 insertions(+), 130 deletions(-) diff --git a/client/cat3/src/partials/sections/dashboard/analytics/analytics.html b/client/cat3/src/partials/sections/dashboard/analytics/analytics.html index 599a15e81..ef0330037 100644 --- a/client/cat3/src/partials/sections/dashboard/analytics/analytics.html +++ b/client/cat3/src/partials/sections/dashboard/analytics/analytics.html @@ -93,8 +93,8 @@
- - + +
diff --git a/client/cat3/src/partials/sections/dashboard/analytics/analytics.js b/client/cat3/src/partials/sections/dashboard/analytics/analytics.js index 9c64d1f66..1194d88db 100644 --- a/client/cat3/src/partials/sections/dashboard/analytics/analytics.js +++ b/client/cat3/src/partials/sections/dashboard/analytics/analytics.js @@ -59,7 +59,7 @@ } }) }]) - .controller('analyticsCtrl',['$scope', '$rootScope','$state','genericServices', 'workzoneServices', 'toastr', function ($scope, $rootScope, $state, genericServices, workzoneServices, toastr) { + .controller('analyticsCtrl',['$scope', '$rootScope','$state','genericServices','analyticsServices', 'workzoneServices', 'toastr', function ($scope, $rootScope, $state, genericServices,analyticsServices, workzoneServices, toastr) { var analytic = this; var splitUp=null; analytic.tabShowChat=true; @@ -68,14 +68,10 @@ $rootScope.isOpenSidebar = false; $rootScope.dashboardChild = 'analytics'; $rootScope.stateItems = $state.params; + analyticsServices.initFilter(); var treeNames = ['Analytics']; //$rootScope.$emit('treeNameUpdate', treeNames); $rootScope.$emit('HEADER_NAV_CHANGE', 'ANALYTICS'); - $rootScope.organNewEnt=[]; - $rootScope.filterNewEnt={}; - $rootScope.organNewEnt.org = '0'; - $rootScope.filterNewEnt.period='month'; - $rootScope.splitUpCosts=[]; $scope.selectedResources = []; analytic.viewByFilter='orgView'; $scope.$watch(function() { return analytic.viewByFilter}, function(newVal, oldVal) { @@ -96,48 +92,11 @@ $scope.$broadcast('CHANGE_VIEW',newVal); }, true); analytic.applyCount=0 - analytic.applyFilter = function(filterApp,period){ - $rootScope.filterApply= new Date(); - var obj=$rootScope.organObject, - or=$rootScope.organNewEnt.org, - bu=$rootScope.organNewEnt.buss, - pr=$rootScope.organNewEnt.proj; - if(period) - $rootScope.filterNewEnt.period=period; - if(or){ - $rootScope.filterNewEnt.org={name:obj[or].name,id:obj[or].rowid,title:'Org'}; - $rootScope.filterNewEnt.provider=''; - } - if(filterApp){ - if(bu){ - $rootScope.filterNewEnt.buss = {name:obj[or].businessGroups[bu].name,id:obj[or].businessGroups[bu].rowid,title:'BU'}; - } - if(pr){ - $rootScope.filterNewEnt.proj = {name:obj[or].businessGroups[bu].projects[pr].name,id:obj[or].businessGroups[bu].projects[pr].rowid,title:'Project'}; - } - - if($rootScope.organNewEnt.provider){ - $rootScope.filterNewEnt.provider={name:$scope.providers[$rootScope.organNewEnt.provider].providerName,id:$scope.providers[$rootScope.organNewEnt.provider]._id,title:'Provider'}; - } else{ - $rootScope.filterNewEnt.provider=''; - } - } else{ - $rootScope.organNewEnt={} - $rootScope.organNewEnt.org=or; - analytic.viewByFilter='orgView'; - analytic.splitUp=$rootScope.splitUpCosts[0]; - } - }; //get organisation genericServices.getTreeNew().then(function (orgs) { $rootScope.organObject = orgs; - analytic.applyFilter(true); }); - $rootScope.organNewEnt=[]; - $rootScope.organNewEnt.org = '0'; - //$rootScope.organNewEnt.buss='0'; - //$rootScope.organNewEnt.proj='0'; if (!$rootScope.stateParams.view) { $state.go('dashboard.analytics.cost'); } @@ -151,7 +110,6 @@ analytic.tabShowChat=chat; analytic.tabShowReport=report; }; - analytic.hideTreeOverlay(); $scope.getAllRegionsList = function() { workzoneServices.getAllRegionsList().then(function(response) { @@ -162,6 +120,7 @@ }; $scope.getProviders = function() { workzoneServices.getProviders().then(function(response) { + $rootScope.providers=response.data; $scope.providers = response.data; $scope.filter = []; $scope.filter.providerId = response.data[0]._id; @@ -196,9 +155,7 @@ $scope.providerLoading = false; }); }; - if (!$rootScope.stateItems.view) { - $state.go('dashboard.analytics.cost'); - } + $scope.getAllRegionsList(); $scope.getProviders(); $scope.fnProviderChange = function() { @@ -244,5 +201,8 @@ } } }; + if (!$rootScope.stateParams.view) { + $state.go('dashboard.analytics.cost'); + } }]); -})(angular); \ No newline at end of file +})(angular); diff --git a/client/cat3/src/partials/sections/dashboard/analytics/analytics.scss b/client/cat3/src/partials/sections/dashboard/analytics/analytics.scss index f05b6671a..6eeb3b83a 100644 --- a/client/cat3/src/partials/sections/dashboard/analytics/analytics.scss +++ b/client/cat3/src/partials/sections/dashboard/analytics/analytics.scss @@ -266,6 +266,6 @@ } .selected { - background: #ddd; + background: #E49C25; } } \ No newline at end of file diff --git a/client/cat3/src/partials/sections/dashboard/analytics/analyticsServices.js b/client/cat3/src/partials/sections/dashboard/analytics/analyticsServices.js index 87bc5f53e..bd370c6a8 100644 --- a/client/cat3/src/partials/sections/dashboard/analytics/analyticsServices.js +++ b/client/cat3/src/partials/sections/dashboard/analytics/analyticsServices.js @@ -1,9 +1,60 @@ (function (angular) { "use strict"; angular.module('apis.analytics',[]) - .factory('analyticsServices',[ function () { + .factory('analyticsServices',['$rootScope', function ($rootScope) { return { + initFilter:function(){ + $rootScope.organNewEnt=[]; + $rootScope.filterNewEnt={}; + $rootScope.organNewEnt.org = '0'; + $rootScope.filterNewEnt.period='month'; + $rootScope.splitUpCosts=[]; + }, + applyFilter : function(filterApp,period){ + if($rootScope.organObject) { + var obj = $rootScope.organObject, + or = $rootScope.organNewEnt.org, + bu = $rootScope.organNewEnt.buss, + pr = $rootScope.organNewEnt.proj; + if (period) + $rootScope.filterNewEnt.period = period; + if (or) { + $rootScope.filterNewEnt.org = {name: obj[or].name, id: obj[or].rowid, title: 'Org'}; + $rootScope.filterNewEnt.provider = ''; + } + if (filterApp) { + if (bu) { + $rootScope.filterNewEnt.buss = { + name: obj[or].businessGroups[bu].name, + id: obj[or].businessGroups[bu].rowid, + title: 'BU' + }; + } + if (pr) { + $rootScope.filterNewEnt.proj = { + name: obj[or].businessGroups[bu].projects[pr].name, + id: obj[or].businessGroups[bu].projects[pr].rowid, + title: 'Project' + }; + } + + if ($rootScope.organNewEnt.provider) { + $rootScope.filterNewEnt.provider = { + name: $rootScope.providers[$rootScope.organNewEnt.provider].providerName, + id: $rootScope.providers[$rootScope.organNewEnt.provider]._id, + title: 'Provider' + }; + } else { + $rootScope.filterNewEnt.provider = ''; + } + } else { + $rootScope.organNewEnt = {} + $rootScope.organNewEnt.org = or; + } + } + + } }; }]); })(angular); \ No newline at end of file diff --git a/client/cat3/src/partials/sections/dashboard/analytics/controller/costCtrl.js b/client/cat3/src/partials/sections/dashboard/analytics/controller/costCtrl.js index ec1226b8e..7dd71d673 100644 --- a/client/cat3/src/partials/sections/dashboard/analytics/controller/costCtrl.js +++ b/client/cat3/src/partials/sections/dashboard/analytics/controller/costCtrl.js @@ -3,10 +3,13 @@ angular.module('dashboard.analytics') .controller('costCtrl', ['$scope', '$rootScope', '$state','analyticsServices', 'genericServices', function ($scope,$rootScope,$state,analyticsServices,genSevs){ $rootScope.stateItems = $state.params; + //analyticsServices.initFilter(); // var treeNames = ['Analytics','Cost']; // $rootScope.$emit('treeNameUpdate', treeNames); + analyticsServices.initFilter(); var costObj =this; costObj.chartData=[]; + costObj.splitUp=null; costObj.pieChat={ option:{}, totalCoust:'', @@ -71,8 +74,9 @@ showControls: true, showValues: true, xAxis: { - axisLabel: 'label', - showMaxMin: false + axisLabel: '', + showMaxMin: false, + staggerLabels:false }, yAxis: { tickFormat: function (d) { @@ -123,6 +127,7 @@ $rootScope.splitUpCosts.push({id:key,val:a}); }); $scope.$emit('CHANGE_splitUp', $rootScope.splitUpCosts[0].id); + costObj.splitUp=0; costObj.createLable(result, $rootScope.splitUpCosts[0].id); } else { costObj.createLable(result,'provider'); @@ -137,7 +142,6 @@ {name: 'totalCost', field: 'cost.totalCost'} ]; costObj.pieChat.totalCoust = result.cost.totalCost; - costObj.serviceCosts = result.cost.AWS.serviceCosts; costObj.pieChat.data = []; costObj.barChat.data = []; // create bar @@ -149,50 +153,34 @@ value: value.cost.totalCost }); }); - - angular.forEach(result.cost.AWS.serviceCosts, function (valueChild, keyChild) { - var va = []; - costObj.costGridOptions.columnDefs.push({ - name: keyChild, - field: 'cost.AWS.serviceCosts.' + keyChild - }) - angular.forEach(result.splitUpCosts[viewType], function (valBar) { - va.push( - { - "label": valBar.name, - "value": valBar.cost.AWS.serviceCosts[keyChild] + if(result.cost && result.cost.AWS && result.cost.AWS.serviceCosts) { + costObj.serviceCosts = result.cost.AWS.serviceCosts; + angular.forEach(result.cost.AWS.serviceCosts, function (valueChild, keyChild) { + var va = []; + costObj.costGridOptions.columnDefs.push({ + name: keyChild, + field: 'cost.AWS.serviceCosts.' + keyChild + }) + angular.forEach(result.splitUpCosts[viewType], function (valBar) { + var chVal = ''; + if (valBar.cost.AWS.serviceCosts[keyChild]) { + chVal = valBar.cost.AWS.serviceCosts[keyChild]; + } else { + chVal = 0; } - ); - }); - costObj.barChat.data.push({ - "key": keyChild, - "values": va + va.push( + { + "label": valBar.name, + "value": chVal + } + ); + }); + costObj.barChat.data.push({ + "key": keyChild, + "values": va + }); }); - }); - // } else { - // costObj.costGridOptions.data = result.splitUpCosts.businessUnits; - // angular.forEach(result.splitUpCosts.businessUnits, function (value) { - // costObj.pieChat.data.push({ - // key: value.name, - // value: value.cost.totalCost - // }); - // }); - // angular.forEach(result.cost.AWS.serviceCosts,function(valueChild,keyChild){ - // var va=[]; - // costObj.costGridOptions.columnDefs.push({name: keyChild, field: 'cost.AWS.serviceCosts.'+keyChild}) - // angular.forEach(result.splitUpCosts.businessUnits, function (valBar) { - // va.push( - // { "label": valBar.name, - // "value": valBar.cost.AWS.serviceCosts[keyChild] - // } - // ); - // }); - // costObj.barChat.data.push({ - // "key": keyChild, - // "values": va - // }); - // }); - // } + } } }; costObj.trendsChart=function(fltObj){ @@ -252,6 +240,7 @@ } else { entityId=fltObj.org.id; } + //http://192.168.152.139:3001 param.url='/analytics/cost/trend?parentEntityId='+fltObj.org.id+'&entityId='+fltObj.org.id+'&toTimeStamp='+new Date()+'&period='+fltObj.period+'&interval=86400' } @@ -262,7 +251,13 @@ angular.forEach(result.cost.AWS.serviceCosts, function (valueChild, keyChild) { var va = []; angular.forEach(result.costTrends, function (value) { - va.push([value.fromTime,value.cost.AWS.serviceCosts[keyChild]]); + var chVal=''; + if(value.cost.AWS.serviceCosts[keyChild]){ + chVal=value.cost.AWS.serviceCosts[keyChild]; + } else { + chVal=0; + } + va.push([value.fromTime,chVal]); }); costObj.trendLineChart.data.push({ "key": keyChild, @@ -274,14 +269,19 @@ }; costObj.createChart(); $scope.$on('CHANGE_VIEW', function (event, data) { + costObj.splitUp=data.replace(/([A-Z])/g, ' $1').replace(/^./, function(str) { + return str.toUpperCase(); + }); costObj.createLable(costObj.chartData,data); }); - $rootScope.$watch('filterApply', function () { + $rootScope.applyFilter =function(filterApp,period){ + analyticsServices.applyFilter(filterApp,period); if($state.current.name === "dashboard.analytics.cost") { costObj.getCostData($rootScope.filterNewEnt); - costObj.trendsChart($rootScope.filterNewEnt); } - }); + }; + $rootScope.applyFilter(true,'month'); + costObj.trendsChart($rootScope.filterNewEnt); }]); })(angular); diff --git a/client/cat3/src/partials/sections/dashboard/analytics/controller/usageCtrl.js b/client/cat3/src/partials/sections/dashboard/analytics/controller/usageCtrl.js index 411bb996b..f740ee3d7 100644 --- a/client/cat3/src/partials/sections/dashboard/analytics/controller/usageCtrl.js +++ b/client/cat3/src/partials/sections/dashboard/analytics/controller/usageCtrl.js @@ -63,29 +63,33 @@ $scope.gridApi = gridApi; } }; - - var param = { - url: 'src/partials/sections/dashboard/analytics/data/usage.json' - }; - genSevs.promiseGet(param).then(function (result) { - usage.trendLineChart.data = []; - usage.costGridOptions.columnDefs=[]; - angular.forEach(result,function (valu,keyChild) { - var va = []; - angular.forEach(valu.dataPoints, function (value) { - va.push([value.fromTime,value.average]); - }); - usage.trendLineChart.data.push({ - "key": keyChild, - "values": va - }); - }); - }); - }; - $rootScope.$watch('filterApply', function () { + usage.trendLineChart.data = []; + usage.costGridOptions.columnDefs = []; + var param = { + url: 'http://neocatalyst.rlcatalyst.com/analytics/trend/usage?resource=57da3fecbddbbdf876981be5&fromTimeStamp=2016-09-27T07:07:17&toTimeStamp=2016-09-28T07:07:17&interval=3600' + }; + genSevs.promiseGet(param).then(function (result) { + angular.forEach(result, function (valu, keyChild) { + var va = []; + angular.forEach(valu.dataPoints, function (value) { + va.push([Date.parse(value.fromTime), value.average]); + }); + usage.trendLineChart.data.push({ + "key": keyChild, + "values": va + }); + }); + }); + }; + $rootScope.applyFilter =function(filterApp,period){ + analyticsServices.applyFilter(filterApp,period); if($state.current.name === "dashboard.analytics.usage") { usage.trendsChart($rootScope.filterNewEnt); } - }); + }; + if($state.current.name === "dashboard.analytics.usage") { + usage.trendsChart($rootScope.filterNewEnt); + } + }]); })(angular); diff --git a/client/cat3/src/partials/sections/dashboard/analytics/view/cost.html b/client/cat3/src/partials/sections/dashboard/analytics/view/cost.html index 6091cc5ad..d433e5c11 100644 --- a/client/cat3/src/partials/sections/dashboard/analytics/view/cost.html +++ b/client/cat3/src/partials/sections/dashboard/analytics/view/cost.html @@ -2,22 +2,29 @@
+
+
+
+

Total Cost ${{cost.pieChat.totalCoust}}

+

Services Cost + {{value}} : ${{key}} +

+
+
+
+
-

Aggregate cost

-
- Total Cost - ${{cost.pieChat.totalCoust}} -
+
+

Aggregate cost

-

Distribution of all services across BU's

-
Total - {{value}} - ${{key}} -
+

Distribution of all services across {{cost.splitUp}}

+
From d29a140098f90ee0119c70d37e8fa29195c2e9eb Mon Sep 17 00:00:00 2001 From: hrushikesh07 Date: Wed, 28 Sep 2016 18:01:36 +0530 Subject: [PATCH 07/12] Changed done for split up --- .../sections/dashboard/analytics/controller/costCtrl.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/cat3/src/partials/sections/dashboard/analytics/controller/costCtrl.js b/client/cat3/src/partials/sections/dashboard/analytics/controller/costCtrl.js index 7dd71d673..4a31b6da5 100644 --- a/client/cat3/src/partials/sections/dashboard/analytics/controller/costCtrl.js +++ b/client/cat3/src/partials/sections/dashboard/analytics/controller/costCtrl.js @@ -127,7 +127,7 @@ $rootScope.splitUpCosts.push({id:key,val:a}); }); $scope.$emit('CHANGE_splitUp', $rootScope.splitUpCosts[0].id); - costObj.splitUp=0; + costObj.splitUp= $rootScope.splitUpCosts[0].val; costObj.createLable(result, $rootScope.splitUpCosts[0].id); } else { costObj.createLable(result,'provider'); From 6ce34da74ed366939cb35952edcfedfb864a61a2 Mon Sep 17 00:00:00 2001 From: hrushikesh07 Date: Wed, 28 Sep 2016 18:04:26 +0530 Subject: [PATCH 08/12] Changed done for split up --- .../src/partials/sections/dashboard/analytics/view/cost.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/cat3/src/partials/sections/dashboard/analytics/view/cost.html b/client/cat3/src/partials/sections/dashboard/analytics/view/cost.html index d433e5c11..00b70c483 100644 --- a/client/cat3/src/partials/sections/dashboard/analytics/view/cost.html +++ b/client/cat3/src/partials/sections/dashboard/analytics/view/cost.html @@ -31,7 +31,7 @@

Aggregate cost

-

Daily trends of cost across organization

+

Monthly trends of cost across organization

Total Cost - ${{cost.trendLineChart.totalCost}}
From 10ab38f9fc3455b9d00ac1b145fce97fd3a10262 Mon Sep 17 00:00:00 2001 From: hrushikesh07 Date: Thu, 29 Sep 2016 10:33:19 +0530 Subject: [PATCH 09/12] API changes --- .../sections/dashboard/analytics/analytics.js | 19 +++++++++++++------ .../dashboard/analytics/analyticsServices.js | 4 +++- .../analytics/controller/costCtrl.js | 15 +++++++++------ 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/client/cat3/src/partials/sections/dashboard/analytics/analytics.js b/client/cat3/src/partials/sections/dashboard/analytics/analytics.js index 1194d88db..251beb146 100644 --- a/client/cat3/src/partials/sections/dashboard/analytics/analytics.js +++ b/client/cat3/src/partials/sections/dashboard/analytics/analytics.js @@ -59,7 +59,7 @@ } }) }]) - .controller('analyticsCtrl',['$scope', '$rootScope','$state','genericServices','analyticsServices', 'workzoneServices', 'toastr', function ($scope, $rootScope, $state, genericServices,analyticsServices, workzoneServices, toastr) { + .controller('analyticsCtrl',['$scope', '$rootScope','$state','genericServices','analyticsServices', 'workzoneServices', 'toastr','$timeout', function ($scope, $rootScope, $state, genericServices,analyticsServices, workzoneServices, toastr,$timeout) { var analytic = this; var splitUp=null; analytic.tabShowChat=true; @@ -77,11 +77,15 @@ $scope.$watch(function() { return analytic.viewByFilter}, function(newVal, oldVal) { if(newVal === 'ProviderView'){ $rootScope.viewType='ProviderView'; - $state.params.filterView.provi=true; + if($state.params && $state.params.filterView){ + $state.params.filterView.provi=true; + } } else { $rootScope.organNewEnt.provider='' $rootScope.viewType='orgView'; - $state.params.filterView.provi=false; + if($state.params && $state.params.filterView){ + $state.params.filterView.provi=false; + } } $rootScope.stateItems = $state.params; }, true); @@ -201,8 +205,11 @@ } } }; - if (!$rootScope.stateParams.view) { - $state.go('dashboard.analytics.cost'); - } + $timeout(function(){ + if (!$rootScope.stateParams.view && $rootScope.organObject) { + $state.go('dashboard.analytics.cost'); + } + },200); + }]); })(angular); diff --git a/client/cat3/src/partials/sections/dashboard/analytics/analyticsServices.js b/client/cat3/src/partials/sections/dashboard/analytics/analyticsServices.js index bd370c6a8..1bf8334b8 100644 --- a/client/cat3/src/partials/sections/dashboard/analytics/analyticsServices.js +++ b/client/cat3/src/partials/sections/dashboard/analytics/analyticsServices.js @@ -22,6 +22,8 @@ if (or) { $rootScope.filterNewEnt.org = {name: obj[or].name, id: obj[or].rowid, title: 'Org'}; $rootScope.filterNewEnt.provider = ''; + } else{ + $rootScope.filterNewEnt.org = {id: obj[or].rowid, title: 'Org'}; } if (filterApp) { if (bu) { @@ -53,7 +55,7 @@ $rootScope.organNewEnt.org = or; } } - + return 1; } }; }]); diff --git a/client/cat3/src/partials/sections/dashboard/analytics/controller/costCtrl.js b/client/cat3/src/partials/sections/dashboard/analytics/controller/costCtrl.js index 4a31b6da5..fa6c30cda 100644 --- a/client/cat3/src/partials/sections/dashboard/analytics/controller/costCtrl.js +++ b/client/cat3/src/partials/sections/dashboard/analytics/controller/costCtrl.js @@ -1,12 +1,11 @@ (function (angular) { "use strict"; angular.module('dashboard.analytics') - .controller('costCtrl', ['$scope', '$rootScope', '$state','analyticsServices', 'genericServices', function ($scope,$rootScope,$state,analyticsServices,genSevs){ + .controller('costCtrl', ['$scope', '$rootScope', '$state','analyticsServices', 'genericServices','$timeout', function ($scope,$rootScope,$state,analyticsServices,genSevs,$timeout){ $rootScope.stateItems = $state.params; //analyticsServices.initFilter(); // var treeNames = ['Analytics','Cost']; // $rootScope.$emit('treeNameUpdate', treeNames); - analyticsServices.initFilter(); var costObj =this; costObj.chartData=[]; costObj.splitUp=null; @@ -267,7 +266,6 @@ } }); }; - costObj.createChart(); $scope.$on('CHANGE_VIEW', function (event, data) { costObj.splitUp=data.replace(/([A-Z])/g, ' $1').replace(/^./, function(str) { return str.toUpperCase(); @@ -280,8 +278,13 @@ costObj.getCostData($rootScope.filterNewEnt); } }; - $rootScope.applyFilter(true,'month'); - costObj.trendsChart($rootScope.filterNewEnt); + costObj.init =function(){ + analyticsServices.initFilter(); + costObj.createChart(); + $rootScope.applyFilter(true,'month'); + costObj.trendsChart($rootScope.filterNewEnt); + }; + costObj.init(); - }]); + }]); })(angular); From 526cf64cdf2dd3f02450b318a88d9ddb39a4cf36 Mon Sep 17 00:00:00 2001 From: hrushikesh07 Date: Thu, 29 Sep 2016 11:10:54 +0530 Subject: [PATCH 10/12] API changes with some lable --- .../sections/dashboard/analytics/analytics.html | 7 ++++--- .../sections/dashboard/analytics/analytics.js | 17 +++++++---------- .../dashboard/analytics/analyticsServices.js | 12 +++++++++--- .../dashboard/analytics/controller/costCtrl.js | 6 ++++-- .../sections/dashboard/analytics/view/cost.html | 4 ++-- 5 files changed, 26 insertions(+), 20 deletions(-) diff --git a/client/cat3/src/partials/sections/dashboard/analytics/analytics.html b/client/cat3/src/partials/sections/dashboard/analytics/analytics.html index ef0330037..e5c1dc668 100644 --- a/client/cat3/src/partials/sections/dashboard/analytics/analytics.html +++ b/client/cat3/src/partials/sections/dashboard/analytics/analytics.html @@ -45,7 +45,7 @@
-
+
+ +