Skip to content

Commit d6b6e7e

Browse files
committed
Fixed issue #80
The simple query build was only showing the current page's worth of data when in edit mode (display mode was ok). I've change this to load the full data set when a Chart has been added, and update the paging to use that data set so multiple round trips are not required.
1 parent 4256909 commit d6b6e7e

File tree

1 file changed

+64
-24
lines changed

1 file changed

+64
-24
lines changed

Web/Scripts/simple.js

Lines changed: 64 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -90,25 +90,39 @@ var SimpleQueryBuilderViewModel = function () {
9090
return x1 + x2;
9191
};
9292

93-
self.currentData = ko.observable();
93+
self.currentDataFull = ko.observable();
94+
self.HasChart = ko.observable(false);
95+
96+
self.currentData = ko.computed(function() {
97+
if (self.HasChart() && self.currentDataFull()) {
98+
return self.currentDataFull().slice(self.currentRowStart(), self.currentRowStart() + self.dataPageSize())
99+
} else {
100+
return self.currentDataFull();
101+
}
102+
})
103+
94104
self.currentDataColumns = ko.observable();
95105
self.currentRowStart = ko.observable();
96106
self.currentRowStartFormatted = ko.computed(function () {
97107
return formatNumber(self.currentRowStart());
98108
});
99109

100-
self.currentRowEnd = ko.observable();
101-
self.currentRowEndFormatted = ko.computed(function () {
102-
return formatNumber(self.currentRowEnd());
103-
});
104-
105110
self.currentRowsTotal = ko.observable();
106111
self.currentRowsTotalFormatted = ko.computed(function () {
107112
return formatNumber(self.currentRowsTotal());
108113
});
109114

110115
self.dataPageSize = ko.observable(10);
111116

117+
self.currentRowEnd = ko.computed(function() {
118+
return Math.min(self.currentRowsTotal(), self.currentRowStart() + self.dataPageSize() - 1)
119+
});
120+
self.currentRowEndFormatted = ko.computed(function () {
121+
return formatNumber(self.currentRowEnd());
122+
});
123+
124+
125+
112126
self.isPreviousVisible = ko.computed(function () {
113127
if (self.currentRowStart() != null) {
114128
return self.currentRowStart() > 1;
@@ -129,8 +143,12 @@ var SimpleQueryBuilderViewModel = function () {
129143

130144
self.navigateStart = function () {
131145
if (self.selectedNode()) {
132-
//events.FetchSelectedNodeData(0, models.DataPageSize());
133-
self.refresh(0);
146+
// If HasChart() == true, we will already have the data, no need to reload from the server
147+
if (self.HasChart()) {
148+
self.currentRowStart(1);
149+
} else {
150+
self.refresh(0);
151+
}
134152
}
135153
}
136154

@@ -141,22 +159,34 @@ var SimpleQueryBuilderViewModel = function () {
141159
start -= self.dataPageSize();
142160
}
143161
var count = self.currentRowsTotal() - start;
144-
//events.FetchSelectedNodeData(start, count);
145-
self.refresh(start);
162+
// If HasChart() == true, we will already have the data, no need to reload from the server
163+
if (self.HasChart()) {
164+
self.currentRowStart(start + 1);
165+
} else {
166+
self.refresh(start);
167+
}
146168
}
147169
}
148170

149171
self.navigateNext = function () {
150172
if (self.selectedNode()) {
151-
//events.FetchSelectedNodeData(self.CurrentRowStart() - 1 + self.DataPageSize(), self.DataPageSize());
152-
self.refresh(self.currentRowStart() - 1 + self.dataPageSize());
173+
// If HasChart() == true, we will already have the data, no need to reload from the server
174+
if (self.HasChart()) {
175+
self.currentRowStart(self.currentRowStart() + self.dataPageSize());
176+
} else {
177+
self.refresh(self.currentRowStart() - 1 + self.dataPageSize());
178+
}
153179
}
154180
}
155181

156182
self.navigatePrev = function () {
157183
if (self.selectedNode()) {
158-
//events.FetchSelectedNodeData(self.CurrentRowStart() - 1 - self.DataPageSize(), self.DataPageSize());
159-
self.refresh(self.currentRowStart() - 1 - self.dataPageSize());
184+
// If HasChart() == true, we will already have the data, no need to reload from the server
185+
if (self.HasChart()) {
186+
self.currentRowStart(self.currentRowStart() - self.dataPageSize());
187+
} else {
188+
self.refresh(self.currentRowStart() - 1 - self.dataPageSize());
189+
}
160190
}
161191
}
162192

@@ -925,7 +955,16 @@ var SimpleQueryBuilderViewModel = function () {
925955
populateNodeSettings(node);
926956

927957
backend.SaveQuery(self.serverQueryKey, nodeSettings, function () {
928-
backend.LoadData(self.serverQueryKey, nodeSettings, node.Id, start, self.dataPageSize(), "JSON", null, function (data) {
958+
fetchStart = start;
959+
fetchCount = self.dataPageSize();
960+
961+
// If a chart is being shown, fetch all the data
962+
if (self.HasChart()) {
963+
fetchStart = null;
964+
fetchCount = null;
965+
}
966+
967+
backend.LoadData(self.serverQueryKey, nodeSettings, node.Id, fetchStart, fetchCount, "JSON", null, function (data) {
929968
if (data.status) {
930969

931970
node.SetColumns(data.columns, data.columnTypes);
@@ -937,9 +976,8 @@ var SimpleQueryBuilderViewModel = function () {
937976

938977
if (node.Id == self.selectedNode().Id) {
939978
self.currentDataColumns(data.columns);
940-
self.currentData(data.rows);
979+
self.currentDataFull(data.rows);
941980
self.currentRowStart(start + 1);
942-
self.currentRowEnd(start + data.rows.length);
943981
self.currentRowsTotal(data.rowCount);
944982

945983
var headerCategories = self.dataTables()
@@ -996,9 +1034,8 @@ var SimpleQueryBuilderViewModel = function () {
9961034

9971035
self.loading(true);
9981036
self.currentDataColumns([]);
999-
self.currentData([]);
1037+
self.currentDataFull([]);
10001038
self.currentRowStart(0);
1001-
self.currentRowEnd(0);
10021039
self.currentRowsTotal(0);
10031040

10041041
self.headerCategories([]);
@@ -1256,12 +1293,10 @@ var SimpleQueryBuilderViewModel = function () {
12561293
}
12571294
}
12581295

1259-
self.HasChart = ko.observable(false);
1260-
12611296
self.RenderChart = function (graphType, xAxis, yAxis) {
1262-
if (self.HasChart() && self.currentData() && self.currentData().length > 0) {
1297+
if (self.HasChart() && self.currentDataFull() && self.currentDataFull().length > 0) {
12631298
var columnTypes = self.selectedNode().ColumnTypes();
1264-
utils.RenderChart('#chart', self.currentData(), graphType, xAxis, columnTypes[xAxis], yAxis, columnTypes[yAxis]);
1299+
utils.RenderChart('#chart', self.currentDataFull(), graphType, xAxis, columnTypes[xAxis], yAxis, columnTypes[yAxis]);
12651300
} else {
12661301
$('#chart').empty();
12671302
}
@@ -1283,11 +1318,16 @@ var SimpleQueryBuilderViewModel = function () {
12831318
self.ShowChart = function () {
12841319
self.ChartGuid(utils.CreateGuid());
12851320
self.HasChart(true);
1286-
self.RenderChart(self.GraphType(), self.XAxis(), self.YAxis());
1321+
self.refresh(self.currentRowStart() - 1, function() {
1322+
self.RenderChart(self.GraphType(), self.XAxis(), self.YAxis());
1323+
});
12871324
}
12881325

12891326
self.HideChart = function () {
1327+
// save the current page of data, as removing the chart will change how the paging works
1328+
var data = self.currentData().slice(0);
12901329
self.HasChart(false);
1330+
self.currentDataFull(data);
12911331
self.RenderChart(self.GraphType(), self.XAxis(), self.YAxis());
12921332
}
12931333

0 commit comments

Comments
 (0)