Browse Source

Merge pull request #1532 from abpframework/dashboard-demo-widget-manager-usage

used widget manager for all widgets
pull/1545/head
Halil İbrahim Kalkan 7 years ago
committed by GitHub
parent
commit
1d2dd8c032
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 41
      samples/DashboardDemo/src/DashboardDemo.Web/Pages/Components/CountersWidget/Default.js
  2. 22
      samples/DashboardDemo/src/DashboardDemo.Web/Pages/Components/LicenseStatisticWidget/Default.cshtml
  3. 46
      samples/DashboardDemo/src/DashboardDemo.Web/Pages/Components/LicenseStatisticWidget/Default.js
  4. 25
      samples/DashboardDemo/src/DashboardDemo.Web/Pages/Components/NewUserStatisticWidget/Default.js

41
samples/DashboardDemo/src/DashboardDemo.Web/Pages/Components/CountersWidget/Default.js

@ -1,21 +1,26 @@
(function() {
function refresh(args) {
args.container
.find('.counters-widget')
.each(function () {
var $this = $(this);
dashboardDemo.dashboard
.getCountersWidget({
startDate: args.filters.startDate,
endDate: args.filters.endDate
}).then(function (result) {
$this.find('.new-user-count').text(result.newUsers);
$this.find('.active-user-count').text(result.activeUsers);
$this.find('.total-income').text('$' + result.totalIncome.toFixed(2));
$this.find('.total-profit').text('$' + result.totalProfit.toFixed(2));
});
abp.widgets = abp.widgets || {}; //TODO: Remove later
(function () {
abp.widgets.CountersWidget = function ($wrapper) {
var refresh = function (filters) {
dashboardDemo.dashboard.getCountersWidget({
startDate: filters.startDate,
endDate: filters.endDate
}).then(function (result) {
$wrapper.find('.new-user-count').text(result.newUsers);
$wrapper.find('.active-user-count').text(result.activeUsers);
$wrapper.find('.total-income').text('$' + result.totalIncome.toFixed(2));
$wrapper.find('.total-profit').text('$' + result.totalProfit.toFixed(2));
});
}
};
var init = function (filters) {
// there is no initial process for this widget.
};
abp.event.on('refresh-widgets', refresh);
return {
init: init,
refresh: refresh
};
};
})();

22
samples/DashboardDemo/src/DashboardDemo.Web/Pages/Components/LicenseStatisticWidget/Default.cshtml

@ -1,12 +1,10 @@
<div class="license-statistic-widget">
<abp-card background="Light">
<abp-card-header background="Secondary" class="text-white">
License Statistics
</abp-card-header>
<abp-card-body>
<div class="row">
<canvas class="LicenseStatisticChart"></canvas>
</div>
</abp-card-body>
</abp-card>
</div>
<abp-card background="Light">
<abp-card-header background="Secondary" class="text-white">
License Statistics
</abp-card-header>
<abp-card-body>
<div class="row">
<canvas class="LicenseStatisticChart"></canvas>
</div>
</abp-card-body>
</abp-card>

46
samples/DashboardDemo/src/DashboardDemo.Web/Pages/Components/LicenseStatisticWidget/Default.js

@ -1,11 +1,9 @@
(function () {
var serviceMethod = dashboardDemo.dashboard.getLicenseStatisticWidget;
function ChartManager($wrapper) {
abp.widgets.LicenseStatisticWidget = function($wrapper) {
var _chart;
var createChart = function (statistic) {
var createChart = function(statistic) {
_chart = new Chart($wrapper.find('.LicenseStatisticChart'),
{
type: 'pie',
@ -26,7 +24,7 @@
});
};
var refreshChart = function (statistic) {
var refreshChart = function(statistic) {
_chart.data = {
labels: Object.keys(statistic.data),
datasets: [
@ -44,21 +42,21 @@
_chart.update();
};
var render = function (filters, callback) {
serviceMethod({
startDate: filters.startDate,
endDate: filters.endDate
var render = function(filters, callback) {
dashboardDemo.dashboard.getLicenseStatisticWidget({
startDate: filters.startDate,
endDate: filters.endDate
})
.then(function (result) {
.then(function(result) {
callback(result);
});
};
var init = function (filters) {
var init = function(filters) {
render(filters, createChart);
};
var refresh = function (filters) {
var refresh = function(filters) {
render(filters, refreshChart);
};
@ -66,27 +64,5 @@
init: init,
refresh: refresh
};
}
abp.event.on('init-widgets', function (args) {
args.container
.find('.license-statistic-widget')
.each(function () {
var $this = $(this);
var chartManager = new ChartManager($this);
chartManager.init(args.filters);
$this.data('chart-manager', chartManager);
});
});
abp.event.on('refresh-widgets', function (args) {
args.container
.find('.license-statistic-widget')
.each(function () {
var $this = $(this);
var chartManager = $this.data('chart-manager');
chartManager.refresh(args.filters);
});
});
};
})();

25
samples/DashboardDemo/src/DashboardDemo.Web/Pages/Components/NewUserStatisticWidget/Default.js

@ -1,11 +1,11 @@
abp.widgets = abp.widgets || {}; //TODO: Remove later
(function () {
abp.widgets.NewUserStatisticWidget = function ($wrapper) {
abp.widgets.NewUserStatisticWidget = function($wrapper) {
var _latestFilters;
var _chart;
var refresh = function (filters) {
var refresh = function(filters) {
_latestFilters = filters || _latestFilters;
dashboardDemo.dashboard.getNewUserStatisticWidget({
startDate: _latestFilters.startDate,
@ -26,17 +26,19 @@
});
};
var init = function (filters) {
var init = function(filters) {
_chart = new Chart($wrapper.find('.NewUserStatisticChart'),
{
type: 'bar',
options: {
scales: {
yAxes: [{
ticks: {
beginAtZero: true
yAxes: [
{
ticks: {
beginAtZero: true
}
}
}]
]
}
}
});
@ -45,14 +47,15 @@
$wrapper
.find('.frequency-filter')
.on('change', function () {
refresh();
});
.on('change',
function() {
refresh();
});
};
return {
init: init,
refresh: refresh
};
}
};
})();
Loading…
Cancel
Save