Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
module = angular.module('impac.components.widgets.sales-average-spend-per-customer', [])
module.controller('WidgetSalesAverageSpendPerCustomerCtrl', ($scope, $q, $filter, HighchartsFactory) ->

w = $scope.widget
$scope.isChartDisplayed = true

# Define settings
# --------------------------------------
$scope.orgDeferred = $q.defer();
settingsPromises = [$scope.orgDeferred.promise]

# Unique identifier for the chart object in the DOM
$scope.chartId = ->
"averageSpendPerCustomerChart-#{w.id}"

# # == Sub-Components =============================================================
$scope.chartDeferred = $q.defer()

# Widget specific methods
# --------------------------------------
w.initContext = ->
$scope.isDataFound = w.content?

w.format = ->
# Instantiate and render chart
options =
chartType: 'line'
chartOnClickCallbacks: []
currency: w.metadata.currency
showToday: true
showLegend: true

$scope.chart = new HighchartsFactory($scope.chartId(), w.content.chart, options)

$scope.chart.formatters = ->
Copy link
Contributor

@xaun xaun Mar 19, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To save some lines, you can assign the result to a variable, and then mutate the object and return that.

defaultFormatters = $scope.chart.formatters()
$scope.chart.formatters = -> 
   defaultFormatters.xAxis = { new: 'opts' }
   ...
   defaultFormatters

currency = @options.currency
xAxisLabels =
labels:
formatter: ->
moment.utc(this.value).format('MMM YYYY')
yAxisLabels =
labels:
formatter: ->
$filter('mnoCurrency')(this.value, currency, false)
xAxis: angular.merge([w.content.chart.xAxis[0]], [xAxisLabels])
yAxis: angular.merge([w.content.chart.yAxis[0]], [yAxisLabels])
rangeSelector:
selected: 5

$scope.chart.render(w.content.chart, options)

# Notifies parent element that the chart is ready to be displayed
$scope.chartDeferred.notify($scope.chart)

$scope.widgetDeferred.resolve(settingsPromises)
)
module.directive('widgetSalesAverageSpendPerCustomer', ->
return {
restrict: 'A',
controller: 'WidgetSalesAverageSpendPerCustomerCtrl'
}
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.analytics .widget-item .content.sales-average-spend-per-customer {
.tall-widget();

.average-spend-per-customer-chart {
height: ~"calc(@{impac-big-widget-size} - 50px)";
}

.highcharts-y-primary {
fill: 'rgb(68, 208, 218)'
}

.highcharts-y-secondary {
fill: 'rgb(208, 68, 218)'
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<div widget-sales-average-spend-per-customer>
<!-- Settings Panel -->
<div ng-show="widget.isEditMode" class="edit">
<h4>Widget settings</h4>

<div setting-organizations parent-widget="widget" class="part" deferred="::orgDeferred" />

<!-- Buttons displayed on the lower -->
<div class="bottom-buttons" align="right">
<button class="btn btn-default" ng-click="initSettings()">Cancel</button>
<button class="btn btn-warning" ng-click="updateSettings()">Save</button>
</div>
</div>

<!-- Content Panel -->
<div ng-hide="widget.isEditMode">
<!-- Data found -->
<div ng-show="(isDataFound==true)" class="">
<div id="{{chartId()}}" class="average-spend-per-customer-chart"></div>
</div>

<!-- No data found -->
<div ng-if="(isDataFound==false)" common-data-not-found on-display-alerts="onDisplayAlerts()" endpoint="::widget.category" width="::widget.width" />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the old implementation of the data-not-found directive. I know the generator created it, but its out of date. I updated this in the generator in v1.6.9 but the lmi feature branch is behind.

The data-not-found is now a modal, so no need to show/hide content on $scope.isDataFound. Replace this directive with: <div ng-show="widget.demoData" common-data-not-found />.

Take a look at cash projection template for example, test with a bolt widget for org with no bolt data.

</div>
</div>
3 changes: 2 additions & 1 deletion src/impac-angular.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ angular.module('impac.components.widgets',
'impac.components.widgets.sales-summary',
'impac.components.widgets.sales-top-opportunities',
'impac.components.widgets.sales-top-customers',
'impac.components.widgets.sales-new-vs-existing-customers'
'impac.components.widgets.sales-new-vs-existing-customers',
'impac.components.widgets.sales-average-spend-per-customer'
]
);
angular.module('impac.components.widgets-settings',
Expand Down