Skip to content

Commit

Permalink
#138 Refactor the Stream events management and rely on angular events…
Browse files Browse the repository at this point in the history
… instead of callbacks
  • Loading branch information
nadouani committed Mar 2, 2017
1 parent 13935ee commit 07d9df6
Show file tree
Hide file tree
Showing 23 changed files with 153 additions and 186 deletions.
42 changes: 8 additions & 34 deletions ui/app/scripts/controllers/MainPageCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,54 +12,28 @@
$rootScope.title = 'My tasks';
$scope.view.data = 'mytasks';
$scope.list = PSearchSrv(undefined, 'case_task', {
'baseFilter': {
scope: $scope,
baseFilter: {
'_and': [{
'status': 'InProgress'
}, {
'owner': $scope.currentUser.id
}]
},
'sort': ['-flag', '-startDate'],
'nparent': 1
sort: ['-flag', '-startDate'],
nparent: 1
});

} else if ($stateParams.viewId === 'waitingtasks') {
$rootScope.title = 'Waiting tasks';
$scope.view.data = 'waitingtasks';
$scope.list = PSearchSrv(undefined, 'case_task', {
'baseFilter': {
scope: $scope,
baseFilter: {
'status': 'Waiting'
},
'sort': '-startDate',
'nparent': 1
});
} else if ($stateParams.viewId === 'closedcases') {
$rootScope.title = 'Closed cases';
$scope.view.data = 'closedcases';
$scope.list = PSearchSrv(undefined, 'case', {
'baseFilter': {
'_and': [{
'status': 'Resolved'
}, {
'_between': {
'_field': 'endDate',
'_from': 'now-14d',
'_to': 'now'
}
}]
},
'sort': '-startDate',
'nstats': true
});
} else {
$rootScope.title = 'Current cases';
$scope.view.data = 'currentcases';
$scope.list = PSearchSrv(undefined, 'case', {
'baseFilter': {
'status': 'Open'
},
'sort': ['-flag', '-startDate'],
'nstats': true
sort: '-startDate',
nparent: 1
});
}

Expand Down
50 changes: 28 additions & 22 deletions ui/app/scripts/controllers/MigrationCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,36 @@
$scope.newUser = {};

StreamSrv.init();
StreamSrv.listen('any', 'migration', function(events) {
angular.forEach(events, function(event) {
var tableName = event.base.tableName;

if (tableName === 'end') {
// check if there is at least one user registered
var users = UserSrv.query(function() {
if (users.length === 0) {
$scope.showUserForm = true;
} else {
StreamSrv.addListener({
scope: $scope,
rootId: 'any',
objectType: 'migration',
callback: function(events) {
angular.forEach(events, function(event) {
var tableName = event.base.tableName;

if (tableName === 'end') {
// check if there is at least one user registered
var users = UserSrv.query(function() {
if (users.length === 0) {
$scope.showUserForm = true;
} else {
$state.go('app.cases');
}
}, function() {
$state.go('app.cases');
}
}, function() {
$state.go('app.cases');
});
}
var current = 0;
if (angular.isDefined($scope.migrationStatus[tableName])) {
current = $scope.migrationStatus[tableName].current;
}
if (event.base.current > current) {
$scope.migrationStatus[tableName] = event.base;
}
});
});
}
var current = 0;
if (angular.isDefined($scope.migrationStatus[tableName])) {
current = $scope.migrationStatus[tableName].current;
}
if (event.base.current > current) {
$scope.migrationStatus[tableName] = event.base;
}
});
}
});

$scope.migrate = function() {
Expand Down
6 changes: 4 additions & 2 deletions ui/app/scripts/controllers/RootCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ angular.module('theHiveControllers').controller('RootCtrl',
$scope.templates = TemplateSrv.query();

$scope.myCurrentTasks = StreamStatSrv({
scope: $scope,
rootId: 'any',
query: {
'_and': [{
Expand All @@ -32,6 +33,7 @@ angular.module('theHiveControllers').controller('RootCtrl',
});

$scope.waitingTasks = StreamStatSrv({
scope: $scope,
rootId: 'any',
query: {
'status': 'Waiting'
Expand All @@ -47,7 +49,7 @@ angular.module('theHiveControllers').controller('RootCtrl',
});

// Get MISP counts
$scope.mispEvents = MispSrv.stats();
$scope.mispEvents = MispSrv.stats($scope);
}, function(data, status) {
AlertSrv.error('RootCtrl', data, status);
});
Expand All @@ -64,7 +66,7 @@ angular.module('theHiveControllers').controller('RootCtrl',
});

$scope.$on('misp:event-imported', function() {
$scope.mispEvents = MispSrv.stats();
$scope.mispEvents = MispSrv.stats($scope);
});

$scope.$on('misp:status-updated', function(event, enabled) {
Expand Down
2 changes: 1 addition & 1 deletion ui/app/scripts/controllers/admin/AdminUsersCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* users management page
*/
$scope.userlist = PSearchSrv(undefined, 'user', {
//'filter': {}
scope: $scope
});
$scope.initNewUser = function() {
$scope.apiKey = false;
Expand Down
7 changes: 4 additions & 3 deletions ui/app/scripts/controllers/case/CaseDetailsCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
};

$scope.attachments = PSearchSrv($scope.caseId, 'case_task_log', {
'filter': {
scope: $scope,
filter: {
'_and': [{
'_not': {
'status': 'Deleted'
Expand All @@ -34,8 +35,8 @@
}
}]
},
'pageSize': 100,
'nparent': 1
pageSize: 100,
nparent: 1
});

$scope.hasNoMetrics = function(caze) {
Expand Down
2 changes: 2 additions & 0 deletions ui/app/scripts/controllers/case/CaseListCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
};

this.list = PSearchSrv(undefined, 'case', {
scope: $scope,
filter: self.searchForm.searchQuery !== '' ? {
_string: self.searchForm.searchQuery
} : '',
Expand All @@ -28,6 +29,7 @@
});

this.caseStats = StreamStatSrv({
scope: $scope,
rootId: 'any',
query: {},
result: {},
Expand Down
2 changes: 2 additions & 0 deletions ui/app/scripts/controllers/case/CaseMainCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
});

$scope.tasks = StreamStatSrv({
scope: $scope,
rootId: caseId,
query: {
'_and': [{
Expand All @@ -79,6 +80,7 @@
});

$scope.artifactStats = StreamStatSrv({
scope: $scope,
rootId: caseId,
query: {
'_and': [{
Expand Down
15 changes: 8 additions & 7 deletions ui/app/scripts/controllers/case/CaseObservablesCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
$scope.selection = {};

$scope.artifacts = PSearchSrv($scope.caseId, 'case_artifact', {
'baseFilter': {
scope: $scope,
baseFilter: {
'_and': [{
'_parent': {
"_type": "case",
Expand All @@ -29,16 +30,16 @@
'status': 'Ok'
}]
},
'filter': $scope.searchForm.searchQuery !== '' ? {
filter: $scope.searchForm.searchQuery !== '' ? {
_string: $scope.searchForm.searchQuery
} : '',
'loadAll': true,
'sort': '-startDate',
'pageSize': $scope.uiSrv.context.pageSize,
'onUpdate': function () {
loadAll: true,
sort: '-startDate',
pageSize: $scope.uiSrv.context.pageSize,
onUpdate: function () {
$scope.updateSelection();
},
'nstats': true
nstats: true
});

$scope.$watchCollection('artifacts.pageSize', function (newValue) {
Expand Down
2 changes: 1 addition & 1 deletion ui/app/scripts/controllers/case/CaseObservablesItemCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
$scope.analyzers = [];
})
.finally(function () {
$scope.jobs = CortexSrv.list($scope.caseId, observableId, $scope.onJobsChange);
$scope.jobs = CortexSrv.list($scope, $scope.caseId, observableId, $scope.onJobsChange);
});

};
Expand Down
5 changes: 4 additions & 1 deletion ui/app/scripts/controllers/case/CaseStatsCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
'use strict';

angular.module('theHiveControllers').controller('CaseStatsCtrl',
function($rootScope, $stateParams, $timeout, StatSrv, StreamStatSrv, CasesUISrv) {
function($rootScope, $scope, $stateParams, $timeout, StatSrv, StreamStatSrv, CasesUISrv) {
var self = this;

this.uiSrv = CasesUISrv;
Expand All @@ -16,6 +16,7 @@

// Get stats by tags
StreamStatSrv({
scope: $scope,
rootId: 'any',
query: {},
objectType: 'case',
Expand All @@ -30,6 +31,7 @@

// Get stats by type
StreamStatSrv({
scope: $scope,
rootId: 'any',
query: {},
objectType: 'case',
Expand All @@ -42,6 +44,7 @@

// Get stats by ioc
StreamStatSrv({
scope: $scope,
rootId: 'any',
query: {},
objectType: 'case',
Expand Down
5 changes: 3 additions & 2 deletions ui/app/scripts/controllers/case/CaseTasksCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
};

$scope.tasks = PSearchSrv($scope.caseId, 'case_task', {
'baseFilter': {
scope: $scope,
baseFilter: {
'_and': [{
'_parent': {
'_type': 'case',
Expand All @@ -31,7 +32,7 @@
}
}]
},
'sort': ['-flag', '+startDate', '+title']
sort: ['-flag', '+startDate', '+title']
});

$scope.showTask = function(task) {
Expand Down
1 change: 1 addition & 0 deletions ui/app/scripts/controllers/case/CaseTasksItemCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
$scope.initScope = function () {

$scope.logs = PSearchSrv(caseId, 'case_task_log', {
scope: $scope,
'filter': {
'_and': [{
'_parent': {
Expand Down
Loading

0 comments on commit 07d9df6

Please sign in to comment.