Skip to content

Commit 6752b33

Browse files
committed
working version of the chart that can display in a graph the data that is returned by the db query
1 parent 8aba2c0 commit 6752b33

2 files changed

Lines changed: 150 additions & 24 deletions

File tree

learning_web_proj/angularLearning/app/controllers/reportConfigController.js

Lines changed: 149 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
var cntrlFunction = function ($scope, $routeParams, $location, runReportFactory, productConfig) {
33
$scope.a = 5;
44
$scope.b = 6; //reportConfigController
5+
firstChart = true;
56

67
var getDateObj = function() {
78
var dateObj = {};
@@ -105,6 +106,107 @@ var cntrlFunction = function ($scope, $routeParams, $location, runReportFactory,
105106
$location.path( path );
106107
};
107108

109+
function requestReportData(product) {
110+
console.log("product in the requestReportData is " + product);
111+
// now request the report data for that product.
112+
var startDate, endDate, reportResolution, utcStart, utcEnd;
113+
console.log("running the report");
114+
startDate = $scope.startDate.getStringDate();
115+
endDate = $scope.endDate.getStringDate();
116+
reportResolution = $scope.reportResolution.selected;
117+
console.log("start date is: " + startDate);
118+
console.log("end date is:" + endDate);
119+
120+
utcStart = $scope.startDate.getUTCDate();
121+
utcEnd = $scope.endDate.getUTCDate();
122+
console.log('utcStart' + utcStart);
123+
console.log('utcEnd' + utcEnd);
124+
$scope.showprogress = true;
125+
//$scope.progressMessage = 'Getting data... (can take a few minutes)'
126+
//$scope.progressbarState = 5;
127+
$scope.chartObject = {};
128+
firstChart = true;
129+
130+
chartDataObject = runReportFactory.query( {'startDate': utcStart,
131+
'endDate': utcEnd,
132+
'reportResolution': reportResolution,
133+
'product': product} );
134+
135+
chartDataObject.$promise.then(function(chartDataObject) {
136+
if (firstChart === true) {
137+
console.log("Have the data for the first chart now!:");
138+
firstChart = false;
139+
$scope.chartObject = chartDataObject;
140+
console.log("chart data is: " + JSON.stringify(chartDataObject));
141+
} else {
142+
// adding data to the chart.
143+
console.log("need to update the chart data with the data that has been returned");
144+
console.log('data to be appended is', JSON.stringify(chartDataObject));
145+
//$scope.chartObject.data = chartDataObject.data;
146+
updateDataTable(chartDataObject);
147+
}
148+
});
149+
chartDataObject.$promise['finally']( function(data) {
150+
$scope.showprogress = false;
151+
});
152+
153+
}
154+
155+
function updateDataTable(updateData) {
156+
// need to rip through the update data and add a row to the
157+
// data that exists in the struct $scope.chartObject
158+
//cols":[{"type":"string","id":"sample_time","label":"Sample Time"},{"type":"number","id":"EDITOR_used","label":"EDITOR"}]}
159+
// dealing with the columns!
160+
var i, j;
161+
console.log("updating the column info...")
162+
for (i=0; i<updateData.data.cols.length; i+=1) {
163+
curColLabel = updateData.data.cols[i].label;
164+
if (curColLabel !== 'Sample Time') {
165+
newCol = updateData.data.cols[i]
166+
$scope.chartObject.data.cols.push(newCol);
167+
}
168+
}
169+
sampleTimeDict = {};
170+
// dealing with the rows:
171+
// start by creating a dictionary that allows me to the corresponding
172+
// position in the rows data struct of a specific sample time.
173+
// it also allows us to test to see if a sample time exists or not.
174+
for (j=0; j<$scope.chartObject.data.rows.length; j+=1) {
175+
sampleTime = $scope.chartObject.data.rows[j].c[0].v;
176+
$scope.chartObject.data.rows[j].c.push({"v":0});
177+
sampleTimeDict[sampleTime] = j;
178+
}
179+
// get the column position the new data should be inserted into
180+
thisRowPosition = $scope.chartObject.data.rows[0].c.length - 1;
181+
console.log("postion is: " + thisRowPosition);
182+
183+
184+
for (i=0; i<updateData.data.rows.length; i+=1) {
185+
sampleTime1 = updateData.data.rows[i].c[0].v;
186+
licenseUsed = updateData.data.rows[i].c[1];
187+
// if the date has an entry in the current data struct enter it here.
188+
if (sampleTimeDict.hasOwnProperty(sampleTime1)) {
189+
rowCnt = sampleTimeDict[sampleTime1]
190+
//console.log('row: ' + $scope.chartObject.data.rows[rowCnt] + ' j: ' + rowCnt);
191+
$scope.chartObject.data.rows[rowCnt].c[thisRowPosition] = licenseUsed;
192+
}
193+
// new row needs to be inserted for the specific date
194+
for (j=0; j<$scope.chartObject.data.rows.length; j+=1) {
195+
curSampleTime = $scope.chartObject.data.rows[j].c[0];
196+
if (curSampleTime > sampleTime1) {
197+
// insert a row in here, add that logic!
198+
// TODO: add logic to insert row here
199+
200+
}
201+
202+
}
203+
204+
};
205+
206+
console.log("appended data is:" + JSON.stringify($scope.chartObject));
207+
208+
}
209+
108210
$scope.runReport = function () {
109211
var startDate, endDate, reportResolution, utcStart, utcEnd;
110212
console.log("running the report");
@@ -121,28 +223,52 @@ var cntrlFunction = function ($scope, $routeParams, $location, runReportFactory,
121223
$scope.showprogress = true;
122224
$scope.progressMessage = 'Getting data... (can take a few minutes)'
123225
$scope.progressbarState = 100;
124-
$scope.products = productConfig.query(function() {
125-
console.log('got the products!');
126-
for (var i=0; i<$scope.products.length; i+=1) {
127-
console.log(" product:" + $scope.products[i]['data']);
128-
//console.log(" keys: " + Object.keys($scope.products[i]));
129-
130-
$scope.chartObject = runReportFactory.query(
131-
{'startDate': utcStart,
132-
'endDate': utcEnd,
133-
'reportResolution': reportResolution,
134-
'product': $scope.products[i]['data']}, function() {
135-
var i, j, row, chartData;
136-
//chartData = restructData($scope.reportData);
137-
//$scope.chartObject = $scope.reportData;
138-
console.log('chartObject');
139-
console.log(JSON.stringify($scope.chartObject));
140-
$scope.showprogress = false;
141-
});
142-
}
143-
226+
227+
// First request the products from the database
228+
$scope.products = productConfig.query();
229+
230+
// once the products have been resolved execute this function
231+
$scope.products.$promise.then(function(data) {
232+
for (var i=0; i<data.length; i+=1) {
233+
$scope.progressMessage = 'Getting license data for ( ' + $scope.products[i]['data'] + ' ) ';
234+
progress = Math.round(((i + 1) * 100 ) / data.length);
235+
$scope.progressbarState = progress;
236+
console.log('progress is:' + progress);
237+
console.log('product: '+ data[i]['data'] + ' ' + $scope.products[i]['data']);
238+
// now request the report data for the current product
239+
requestReportData($scope.products[i]['data']);
240+
}
144241

145-
});
242+
});
243+
console.log("here now");
244+
245+
246+
// This stuff works, but need to fix it up so that the async update
247+
// of the chart works!
248+
// $scope.products = productConfig.query(function() {
249+
// console.log('got the products!');
250+
// for (var i=0; i<$scope.products.length; i+=1) {
251+
// console.log(" product:" + $scope.products[i]['data']);
252+
// $scope.chartObject = runReportFactory.query(
253+
// {'startDate': utcStart,
254+
// 'endDate': utcEnd,
255+
// 'reportResolution': reportResolution,
256+
// 'product': $scope.products[i]['data']}, function() {
257+
// var i, j, row, chartData;
258+
// //chartData = restructData($scope.reportData);
259+
// //$scope.chartObject = $scope.reportData;
260+
// console.log('chartObject');
261+
// console.log(JSON.stringify($scope.chartObject));
262+
// $scope.showprogress = false;
263+
// });
264+
// }
265+
//
266+
//
267+
// });
268+
269+
270+
271+
146272
// TODO: modify this query to run a separate query per product
147273
// $scope.products = productConfig.query( function() {
148274
// console.log("products:" + $scope.products );
@@ -260,8 +386,8 @@ var cntrlFunction = function ($scope, $routeParams, $location, runReportFactory,
260386
$scope.progressbarState = 0;
261387
$scope.progressMessage = '';
262388

263-
264-
389+
// the chart data table
390+
$scope.chartObject = undefined;
265391

266392
};
267393

learning_web_proj/angularLearning/app/partials/reportConfig.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ <h5>
7272
<div id='report'>
7373
<div class='row'>
7474
<div class='col-xs-10' align='center'>
75-
<progressbar animate='true' class="progress-striped active" value="progressbarState" ng-show='showprogress' type="progressBarType">{{progressMessage}} </progressbar>
75+
<progressbar animate='true' class="progress-striped active" max="100" value="progressbarState" ng-show='showprogress' type="progressBarType">{{progressMessage}} </progressbar>
7676
</div>
7777
</div>
7878
<div class='row'>

0 commit comments

Comments
 (0)