Skip to content

Commit

Permalink
#1410 Add a name query param to Query API calls for better troublesho…
Browse files Browse the repository at this point in the history
…oting experience
  • Loading branch information
nadouani committed Jul 17, 2020
1 parent 4be16d8 commit 566c103
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

this.load = function() {
this.list = new PaginatedQuerySrv({
name: 'alert-observables',
skipStream: true,
version: 'v1',
sort: self.filtering.context.sort,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

this.load = function() {
this.list = new PaginatedQuerySrv({
name: 'alert-similar-cases',
skipStream: true,
version: 'v1',
loadAll: true,
Expand Down
1 change: 1 addition & 0 deletions frontend/app/scripts/controllers/case/CaseListCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
this.load = function() {

this.list = new PaginatedQuerySrv({
name: 'cases',
root: undefined,
objectType: 'case',
version: 'v1',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@

$scope.load = function() {
$scope.artifacts = new PaginatedQuerySrv({
name: 'observables',
root: $scope.caseId,
objectType: 'case_artifact',
version: 'v1',
Expand Down
1 change: 1 addition & 0 deletions frontend/app/scripts/controllers/case/CaseTasksCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@

$scope.load = function() {
$scope.tasks = new PaginatedQuerySrv({
name: 'case-tasks',
root: $scope.caseId,
objectType: 'case_task',
version: 'v1',
Expand Down
1 change: 1 addition & 0 deletions frontend/app/scripts/controllers/case/CaseTasksItemCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
$scope.initScope = function () {

$scope.logs = new PaginatedQuerySrv({
name: 'case-task-logs',
root: caseId,
objectType: 'case_task_log',
version: 'v1',
Expand Down
20 changes: 4 additions & 16 deletions frontend/app/scripts/services/api/AlertingSrv.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,8 @@
var factory = {

list: function(config, callback) {
// return PSearchSrv(undefined, 'alert', {
// scope: config.scope,
// sort: config.sort || '-date',
// loadAll: config.loadAll || false,
// pageSize: config.pageSize || 10,
// filter: config.filter || '',
// onUpdate: callback || angular.noop
// });

return new PaginatedQuerySrv({
name: 'alerts',
root: undefined,
objectType: 'alert',
version: 'v1',
Expand All @@ -38,15 +30,11 @@
'_name': 'getAlert',
'idOrName': alertId
}
]).then(function(response) {
], {
name: 'get-alert-' + alertId
}).then(function(response) {
return response[0];
});

// return $http.get(baseUrl + '/' + alertId, {
// params: {
// similarity: 1
// }
// });
},

create: function(alertId, data) {
Expand Down
1 change: 1 addition & 0 deletions frontend/app/scripts/services/api/CaseSrv.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
'_name': 'getCase',
'idOrName': id
}], {
name:'get-case-' + id,
page: {
from: 0,
to: 1,
Expand Down
1 change: 1 addition & 0 deletions frontend/app/scripts/services/api/CaseTaskSrv.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
'_name': 'getTask',
'idOrName': id
}], {
name: 'get-task-' + id,
page: {
from: 0,
to: 1
Expand Down
18 changes: 16 additions & 2 deletions frontend/app/scripts/services/common/QuerySrv.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
*/
this.call = function(version, selectorOperation, options) {
var operations = [].concat(selectorOperation);
var config = {};

// Apply filter is defined
if (options && options.filter && !_.isEmpty(options.filter)) {
Expand All @@ -60,7 +61,13 @@
);
}

return self.query(version, operations)
if(options && options.name) {
config.params = {
name: options.name
};
}

return self.query(version, operations, config)
.then(function(response) {
return $q.resolve(response.data);
});
Expand All @@ -77,6 +84,7 @@
*/
this.count = function(version, selectorOperation, options) {
var operations = [].concat(selectorOperation);
var config = {};

// Apply filter is defined
if (options && options.filter && !_.isEmpty(options.filter)) {
Expand All @@ -85,10 +93,16 @@
);
}

if(options && options.name) {
config.params = {
name: options.name + '.count'
};
}

// Add filters
operations.push({'_name': 'count'});

return self.query(version, operations)
return self.query(version, operations, config)
.then(function(response) {
return $q.resolve(response.data);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
this.guard = options.guard || undefined;
this.withStats = options.withStats || undefined;
this.extraData = options.extraData || undefined;
this.name = options.name || undefined;

this.operations = options.operations;

Expand Down Expand Up @@ -130,7 +131,8 @@
sort: self.getSort(),
page: self.getPage(),
config: {},
withParent: false
withParent: false,
name: self.name
}).then(function(data) {
if (self.loadAll) {
self.allValues = data;
Expand All @@ -154,6 +156,7 @@
// Compute the total again
QuerySrv.count('v1', this.operations, {
filter: filters,
name: self.name,
config: {}
}).then(function(total) {
self.total = total;
Expand Down

0 comments on commit 566c103

Please sign in to comment.