mirror of https://github.com/abpframework/abp.git
2 changed files with 90 additions and 74 deletions
@ -1,93 +1,109 @@ |
|||
(function () { |
|||
var chart; |
|||
var serviceMethod = dashboardDemo.dashboard.getNewUserStatisticWidget; |
|||
var latestEndDate; |
|||
var latestStartDate; |
|||
|
|||
var getFrequencyVal = function() { |
|||
return $("#FrequencyFilter option:selected").val(); |
|||
}; |
|||
function ChartManager($wrapper) { |
|||
|
|||
var createChart = function (statistic) { |
|||
chart = new Chart($('#NewUserStatisticChart'), |
|||
{ |
|||
type: 'bar', |
|||
data: { |
|||
labels: statistic.labels, |
|||
datasets: [ |
|||
{ |
|||
label: 'User count', |
|||
data: statistic.data, |
|||
backgroundColor: 'rgba(255, 132, 132, 1)' |
|||
} |
|||
] |
|||
}, |
|||
options: { |
|||
scales: { |
|||
yAxes: [{ |
|||
ticks: { |
|||
beginAtZero: true |
|||
var _filters; |
|||
var _chart; |
|||
|
|||
var getFrequencyVal = function () { |
|||
return $wrapper.find('.frequency-filter option:selected').val(); |
|||
}; |
|||
|
|||
var createChart = function (statistic) { |
|||
_chart = new Chart($wrapper.find('.NewUserStatisticChart'), |
|||
{ |
|||
type: 'bar', |
|||
data: { |
|||
labels: statistic.labels, |
|||
datasets: [ |
|||
{ |
|||
label: 'User count', |
|||
data: statistic.data, |
|||
backgroundColor: 'rgba(255, 132, 132, 1)' |
|||
} |
|||
}] |
|||
] |
|||
}, |
|||
options: { |
|||
scales: { |
|||
yAxes: [{ |
|||
ticks: { |
|||
beginAtZero: true |
|||
} |
|||
}] |
|||
} |
|||
} |
|||
} |
|||
}); |
|||
}; |
|||
|
|||
var refreshChart = function (statistic) { |
|||
_chart.data = { |
|||
labels: statistic.labels, |
|||
datasets: [ |
|||
{ |
|||
label: 'User count', |
|||
data: statistic.data, |
|||
backgroundColor: 'rgba(255, 132, 132, 1)' |
|||
} |
|||
] |
|||
}; |
|||
_chart.update(); |
|||
}; |
|||
|
|||
var render = function (args, callback) { |
|||
serviceMethod({ |
|||
startDate: _filters.startDate, |
|||
endDate: _filters.endDate, |
|||
frequency: getFrequencyVal() |
|||
}) |
|||
.then(function (result) { |
|||
callback(result); |
|||
}); |
|||
}; |
|||
|
|||
var init = function (filters) { |
|||
_filters = filters; |
|||
render(filters, createChart); |
|||
}; |
|||
|
|||
var refresh = function (filters) { |
|||
_filters = filters; |
|||
render(filters, refreshChart); |
|||
}; |
|||
|
|||
$wrapper.find('.frequency-filter').on('change', |
|||
function () { |
|||
refresh(_filters); |
|||
}); |
|||
}; |
|||
|
|||
var refreshChart = function (statistic) { |
|||
chart.data = { |
|||
labels: statistic.labels, |
|||
datasets: [ |
|||
{ |
|||
label: 'User count', |
|||
data: statistic.data, |
|||
backgroundColor: 'rgba(255, 132, 132, 1)' |
|||
} |
|||
] |
|||
return { |
|||
init: init, |
|||
refresh: refresh |
|||
}; |
|||
chart.update(); |
|||
}; |
|||
} |
|||
|
|||
var init = function (args) { |
|||
serviceMethod({ |
|||
startDate: args.filters.startDate, |
|||
endDate: args.filters.endDate, |
|||
frequency: getFrequencyVal() |
|||
}) |
|||
.then(function (result) { |
|||
createChart(result); |
|||
args.container |
|||
.find('.newUserStatistic-widget') |
|||
.each(function() { |
|||
var $this = $(this); |
|||
var chartManager = new ChartManager($this); |
|||
chartManager.init(args.filters); |
|||
$this.data('chart-manager', chartManager); |
|||
}); |
|||
|
|||
latestStartDate = args.filters.startDate; |
|||
latestEndDate = args.filters.endDate; |
|||
}; |
|||
|
|||
var refresh = function (args) { |
|||
|
|||
serviceMethod({ |
|||
startDate: args.filters.startDate, |
|||
endDate: args.filters.endDate, |
|||
frequency: getFrequencyVal() |
|||
}) |
|||
.then(function (result) { |
|||
refreshChart(result); |
|||
args.container |
|||
.find('.newUserStatistic-widget') |
|||
.each(function () { |
|||
var $this = $(this); |
|||
var chartManager = $this.data('chart-manager'); |
|||
chartManager.refresh(args.filters); |
|||
}); |
|||
|
|||
latestStartDate = args.filters.startDate; |
|||
latestEndDate = args.filters.endDate; |
|||
}; |
|||
|
|||
$('#FrequencyFilter').on('change', |
|||
function () { |
|||
refresh({ |
|||
filters: { |
|||
startDate: latestStartDate, |
|||
endDate: latestEndDate |
|||
} |
|||
}); |
|||
}); |
|||
|
|||
abp.event.on('refresh-widgets', refresh); |
|||
|
|||
abp.event.on('init-widgets', init); |
|||
abp.event.on('refresh-widgets', refresh); |
|||
})(); |
|||
Loading…
Reference in new issue