Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IMPAC-738] Widget days between visits #492

Open
wants to merge 1 commit into
base: lmi-insights
Choose a base branch
from
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,60 @@
module = angular.module('impac.components.widgets.sales-days-between-visits', [])
module.controller('WidgetSalesDaysBetweenVisitsCtrl', ($scope, $q, $filter, ChartFormatterSvc) ->

w = $scope.widget

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

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

$scope.getColorByIndex = (index) ->
ChartFormatterSvc.getColor(index)

# Chart formating function
# --------------------------------------
$scope.drawTrigger = $q.defer()
w.format = ->
if $scope.isDataFound
dates = _.map w.content.small_chart.dates, (date) ->
$filter('date')(date, 'MMM yy')

lineOptions = {
scaleBeginAtZero: true,
showXLabels: false,
currency: 'hide'
}

lineData = [
{title: 'Merchant', labels: dates, values: w.content.small_chart.merchant_values},
{title: 'Competitive Set', labels: dates, values: w.content.small_chart.competitive_values},
{title: 'Industry', labels: dates, values: w.content.small_chart.industry_values}
]

# init chartData after transletion chages
chartData = ChartFormatterSvc.lineChart(lineData,lineOptions)

# calls chart.draw()
$scope.drawTrigger.notify(chartData)

# Widget is ready: can trigger the "wait for settings to be ready"
# --------------------------------------
$scope.widgetDeferred.resolve(settingsPromises)
)
module.directive('widgetSalesDaysBetweenVisits', ->
return {
restrict: 'A',
controller: 'WidgetSalesDaysBetweenVisitsCtrl'
}
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.analytics .widget-item .content.sales-days-between-visits {
h6 {
text-align: center;
.font(11px, 300, @impac-widget-text-color);
margin-top: 2px;
}

::-webkit-scrollbar {
width: 0px;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<div widget-sales-days-between-visits>
<!-- 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="">
<h6>Average number of days between visits for the same customers</h6>

<div setting-hist-mode parent-widget="widget" deferred="::histModeDeferred" end-date="'not-displayed'"/>

<div ng-hide="widget.isHistoryMode">
<impac-figure-layout content="widget.content.figure"/>
</div>

<div ng-show="widget.isHistoryMode">
<div impac-chart draw-trigger="drawTrigger.promise" deferred="chartDeferred"></div>
<div class="legend">
<span ng-style="{ 'color': getColorByIndex(0) }">Merchant</span> -
<span ng-style="{ 'color': getColorByIndex(1) }">Competitive Set</span> -
<span ng-style="{ 'color': getColorByIndex(2) }">Industry</span>
</div>
</div>
</div>

<!-- No data found -->
<div ng-if="(isDataFound==false)" common-data-not-found on-display-alerts="onDisplayAlerts()" endpoint="::widget.category" width="::widget.width" />
</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-days-between-visits'
]
);
angular.module('impac.components.widgets-settings',
Expand Down