Skip to content

Commit 3aa9905

Browse files
committed
fixes: data source + download for older aggregations + removed console.log
1 parent 9321750 commit 3aa9905

File tree

2 files changed

+25
-34
lines changed

2 files changed

+25
-34
lines changed

api/utils/requestProcessor.js

+17-28
Original file line numberDiff line numberDiff line change
@@ -1620,12 +1620,14 @@ const processRequest = (params) => {
16201620
else {
16211621
params.qstring.query.$and.push({"$or": [{"global": {"$ne": false}}, {"creator": params.member._id + ""}]});
16221622
}
1623-
if (params.qstring.app_id && params.qstring.app_id !== "") {
1624-
params.qstring.query.$and.push({"app_id": params.qstring.app_id});
1625-
}
1626-
else if (params.qstring.app_independent === true) {
1627-
console.log(params.qstring.app_independent);
1628-
params.qstring.query.$and.push({"app_id": "undefined"});
1623+
1624+
if (params.qstring.data_source !== "all" && params.qstring.app_id) {
1625+
if (params.qstring.data_source === "independent") {
1626+
params.qstring.query.$and.push({"app_id": "undefined"});
1627+
}
1628+
else {
1629+
params.qstring.query.$and.push({"app_id": params.qstring.app_id});
1630+
}
16291631
}
16301632

16311633
if (params.qstring.query.$or) {
@@ -1938,6 +1940,7 @@ const processRequest = (params) => {
19381940
var type = filename.split(".");
19391941
type = type[type.length - 1];
19401942
var myfile = paths[4];
1943+
var headers = {};
19411944

19421945
countlyFs.gridfs.getSize("task_results", myfile, {id: paths[4]}, function(err2, size) {
19431946
if (err2) {
@@ -1947,30 +1950,16 @@ const processRequest = (params) => {
19471950
if (data.type !== "dbviewer") {
19481951
common.returnMessage(params, 400, "Export size is 0");
19491952
}
1950-
//handling older aggregations aren't saved in countly_fs
1953+
//handling older aggregations that aren't saved in countly_fs
19511954
else if (!data.gridfs && data.data) {
1952-
console.log("here");
19531955
type = "json";
19541956
filename = data.name + "." + type;
1955-
countlyFs.gridfs.saveData("task_results", myfile, data.data, {id: myfile}, function(err3) {
1956-
if (err3) {
1957-
console.log(err3);
1958-
}
1959-
else {
1960-
countlyFs.gridfs.getStream("task_results", myfile, {id: myfile}, function(err4, stream) {
1961-
if (err4) {
1962-
common.returnMessage(params, 400, "Export stream does not exist");
1963-
}
1964-
else {
1965-
var headers = {};
1966-
headers["Content-Type"] = countlyApi.data.exports.getType(type);
1967-
headers["Content-Disposition"] = "attachment;filename=" + encodeURIComponent(filename);
1968-
params.res.writeHead(200, headers);
1969-
stream.pipe(params.res);
1970-
}
1971-
});
1972-
}
1973-
});
1957+
headers = {};
1958+
headers["Content-Type"] = countlyApi.data.exports.getType(type);
1959+
headers["Content-Disposition"] = "attachment;filename=" + encodeURIComponent(filename);
1960+
params.res.writeHead(200, headers);
1961+
params.res.write(data.data);
1962+
params.res.end();
19741963
}
19751964
}
19761965
else {
@@ -1979,7 +1968,7 @@ const processRequest = (params) => {
19791968
common.returnMessage(params, 400, "Export stream does not exist");
19801969
}
19811970
else {
1982-
var headers = {};
1971+
headers = {};
19831972
headers["Content-Type"] = countlyApi.data.exports.getType(type);
19841973
headers["Content-Disposition"] = "attachment;filename=" + encodeURIComponent(filename);
19851974
params.res.writeHead(200, headers);

frontend/express/public/core/report-manager/javascripts/countly.views.js

+8-6
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,14 @@
174174
return obj;
175175
},
176176
selectedAppId: function() {
177-
return (this.currentFilter.selectedDataSource && !["all", "independent"].includes(this.currentFilter.selectedDataSource))
178-
? this.currentFilter.selectedDataSource
179-
: null;
177+
return (this.currentFilter.selectedDataSource && ["all", "independent"].includes(this.currentFilter.selectedDataSource))
178+
? countlyCommon.ACTIVE_APP_ID
179+
: this.currentFilter.selectedDataSource;
180180
},
181-
isAppIndependent: function() {
182-
return this.currentFilter.selectedDataSource && this.currentFilter.selectedDataSource === "independent";
181+
dataSource: function() {
182+
if (this.currentFilter.selectedDataSource && ["all", "independent"].includes(this.currentFilter.selectedDataSource)) {
183+
return this.currentFilter.selectedDataSource;
184+
}
183185
}
184186
},
185187
watch: {
@@ -208,7 +210,7 @@
208210
url: countlyCommon.API_PARTS.data.r + "/tasks/list",
209211
data: {
210212
app_id: self.selectedAppId,
211-
app_independent: self.isAppIndependent,
213+
data_source: self.dataSource,
212214
query: JSON.stringify(queryObject),
213215
}
214216
};

0 commit comments

Comments
 (0)