StatisticsChartPanel.js (2774B)
1 Ext.define('PartKeepr.StatisticsChartPanel', { 2 extend: 'Ext.form.Panel', 3 title: i18n("Statistics Chart"), 4 5 layout: 'anchor', 6 bodyStyle: 'background:#DBDBDB;padding: 15px;', 7 8 initComponent: function () 9 { 10 this.chart = Ext.create("PartKeepr.StatisticsChart", {anchor: '100% -60'}); 11 12 this.dateSelector1 = Ext.create("Ext.form.field.Date", { 13 style: 'margin-top: 10px', 14 fieldLabel: i18n("From"), 15 listeners: { 16 change: Ext.bind(this.onDateChanged, this) 17 } 18 }); 19 20 this.dateSelector2 = Ext.create("Ext.form.field.Date", { 21 fieldLabel: i18n("To"), 22 listeners: { 23 change: Ext.bind(this.onDateChanged, this) 24 } 25 }); 26 27 this.items = [this.chart, this.dateSelector1, this.dateSelector2]; 28 29 this.reloadDates(); 30 31 this.callParent(); 32 }, 33 onDateChanged: function () 34 { 35 this.chart.setStart(this.dateSelector1.getValue()); 36 this.chart.setEnd(this.dateSelector2.getValue()); 37 this.chart.store.load(); 38 }, 39 reloadDates: function () 40 { 41 var options = { 42 url: PartKeepr.getBasePath() + "/api/statistics/range", 43 method: "GET", 44 callback: Ext.bind(this.onReloadDates, this) 45 }; 46 47 Ext.Ajax.request(options); 48 }, 49 onReloadDates: function (options, success, response) 50 { 51 var data = Ext.decode(response.responseText); 52 53 if (data.startDate === null || data.endDate === null) { 54 Ext.Msg.alert( 55 i18n("Unable to retrieve the statistic data"), 56 i18n( 57 "The system was unable to retrieve the statistic data. The most probable cause is that the CreateStatisticSnapshot.php cronjob is not running.")); 58 return; 59 } 60 61 var start = Ext.Date.parse(data.startDate, "Y-m-d H:i:s"); 62 var end = Ext.Date.parse(data.endDate, "Y-m-d H:i:s"); 63 64 this.dateSelector1.setMinValue(start); 65 this.dateSelector1.setMaxValue(end); 66 this.dateSelector1.suspendEvents(); 67 68 this.dateSelector1.setValue(start); 69 this.dateSelector1.resumeEvents(); 70 71 72 this.dateSelector2.setMinValue(start); 73 this.dateSelector2.setMaxValue(end); 74 75 this.dateSelector2.suspendEvents(); 76 this.dateSelector2.setValue(end); 77 this.dateSelector2.resumeEvents(); 78 79 this.chart.setStart(start); 80 this.chart.setEnd(end); 81 this.chart.store.load(); 82 }, 83 statics: { 84 iconCls: 'web-icon chart_bar', 85 title: i18n('Chart'), 86 closable: true, 87 menuPath: [{text: i18n("View")}, {text: i18n("Statistics"), iconCls: "web-icon chart_bar"}] 88 } 89 });