Skip to content

Commit

Permalink
#76 add cases listing page
Browse files Browse the repository at this point in the history
  • Loading branch information
nadouani committed Jan 6, 2017
1 parent cbbb86c commit 0bbccb5
Show file tree
Hide file tree
Showing 30 changed files with 882 additions and 91 deletions.
10 changes: 7 additions & 3 deletions ui/app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<!-- endbower -->
<link rel="stylesheet" href="bower_components/smalot-bootstrap-datetimepicker/css/bootstrap-datetimepicker.css" />
<link rel="stylesheet" href="bower_components/ng-tags-input/ng-tags-input.bootstrap.min.css"/>
<link rel="stylesheet" type="text/css" href="bower_components/codemirror/lib/codemirror.css">
<link rel="stylesheet" type="text/css" href="bower_components/codemirror/lib/codemirror.css">
<!-- endbuild -->

<!-- build:css(.tmp) styles/app.css -->
Expand All @@ -38,6 +38,7 @@
<link rel="stylesheet" href="styles/search.css"/>
<link rel="stylesheet" href="styles/filters.css"/>
<link rel="stylesheet" href="styles/directives/page-sizer.css"/>
<link rel="stylesheet" href="styles/directives/user.css"/>
<!-- endbuild -->
</head>
<body ng-cloak>
Expand Down Expand Up @@ -90,8 +91,8 @@
<script src="bower_components/angular-images-resizer/angular-images-resizer.js"></script>
<script src="bower_components/angular-base64-upload/src/angular-base64-upload.js"></script>
<!-- endbower -->
<script type="text/javascript" src="bower_components/ace-builds/src-min-noconflict/ace.js"></script>

<script type="text/javascript" src="bower_components/ace-builds/src-min-noconflict/ace.js"></script>
<script type="text/javascript" src="bower_components/angular-ui-ace/ui-ace.js"></script>

<script src="bower_components/codemirror/lib/codemirror.js"></script>
Expand Down Expand Up @@ -123,6 +124,7 @@
<script src="scripts/controllers/case/CaseCreationCtrl.js"></script>
<script src="scripts/controllers/case/CaseDetailsCtrl.js"></script>
<script src="scripts/controllers/case/CaseLinksCtrl.js"></script>
<script src="scripts/controllers/case/CaseListCtrl.js"></script>
<script src="scripts/controllers/case/CaseMainCtrl.js"></script>
<script src="scripts/controllers/case/CaseMergeModalCtrl.js"></script>
<script src="scripts/controllers/case/CaseObservablesCtrl.js"></script>
Expand Down Expand Up @@ -188,6 +190,7 @@
<script src="scripts/services/CaseSrv.js"></script>
<script src="scripts/services/CaseTabsSrv.js"></script>
<script src="scripts/services/CaseTaskSrv.js"></script>
<script src="scripts/services/CasesUISrv.js"></script>
<script src="scripts/services/ChartSrv.js"></script>
<script src="scripts/services/Constants.js"></script>
<script src="scripts/services/CortexSrv.js"></script>
Expand All @@ -205,6 +208,7 @@
<script src="scripts/services/StatisticSrv.js"></script>
<script src="scripts/services/StreamSrv.js"></script>
<script src="scripts/services/StreamStatSrv.js"></script>
<script src="scripts/services/TagSrv.js"></script>
<script src="scripts/services/TaskLogSrv.js"></script>
<script src="scripts/services/TemplateSrv.js"></script>
<script src="scripts/services/UserInfoSrv.js"></script>
Expand Down
13 changes: 9 additions & 4 deletions ui/app/scripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ angular.module('thehive', ['ngAnimate', 'ngMessages', 'ui.bootstrap', 'ui.router
.config(function($stateProvider, $urlRouterProvider) {
'use strict';

$urlRouterProvider.otherwise('/main/');
$urlRouterProvider.otherwise('/cases');

$stateProvider
.state('login', {
Expand Down Expand Up @@ -61,6 +61,13 @@ angular.module('thehive', ['ngAnimate', 'ngMessages', 'ui.bootstrap', 'ui.router
templateUrl: 'views/app.main.html',
controller: 'MainPageCtrl'
})
.state('app.cases', {
url: 'cases',
templateUrl: 'views/partials/case/case.list.html',
controller: 'CaseListCtrl',
controllerAs: '$vm',
title: 'Cases'
})
.state('app.search', {
url: 'search?q',
templateUrl: 'views/partials/search/list.html',
Expand Down Expand Up @@ -125,9 +132,7 @@ angular.module('thehive', ['ngAnimate', 'ngMessages', 'ui.bootstrap', 'ui.router
controller: 'AdminObservablesCtrl',
title: 'Observable administration'
})


.state('app.case', {
.state('app.case', {
abstract: true,
url: 'case/{caseId}',
templateUrl: 'views/app.case.html',
Expand Down
2 changes: 1 addition & 1 deletion ui/app/scripts/controllers/AuthenticationCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
$scope.login = function() {
$scope.params.username = angular.lowercase($scope.params.username);
AuthenticationSrv.login($scope.params.username, $scope.params.password, function() {
$state.go('app.main');
$state.go('app.cases');
}, function(data, status) {
if (status === 520) {
AlertSrv.error('AuthenticationCtrl', data, status);
Expand Down
6 changes: 3 additions & 3 deletions ui/app/scripts/controllers/MigrationCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
if (users.length === 0) {
$scope.showUserForm = true;
} else {
$state.go('app.main');
$state.go('app.cases');
}
}, function() {
$state.go('app.main');
$state.go('app.cases');
});
}
var current = 0;
Expand Down Expand Up @@ -58,7 +58,7 @@
'password': $scope.newUser.password,
'roles': ['read', 'write', 'admin']
}, function() {
$state.go('app.main');
$state.go('app.cases');
});
};
}
Expand Down
4 changes: 2 additions & 2 deletions ui/app/scripts/controllers/SettingsCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
AlertSrv.error('SettingsCtrl', response.data, response.status);
});
} else {
$state.go('app.main');
$state.go('app.cases');
}
};

Expand All @@ -82,7 +82,7 @@
};

$scope.cancel = function() {
$state.go('app.main');
$state.go('app.cases');
};

$scope.clearAvatar = function(form) {
Expand Down
151 changes: 151 additions & 0 deletions ui/app/scripts/controllers/case/CaseListCtrl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
(function() {
'use strict';
angular.module('theHiveControllers')
.controller('CaseListCtrl', CaseListCtrl);

function CaseListCtrl($scope, $q, CasesUISrv, StreamStatSrv, PSearchSrv, EntitySrv, UserInfoSrv, TagSrv) {
var self = this;

this.showFlow = true;
this.openEntity = EntitySrv.open;
this.getUserInfo = UserInfoSrv;

this.uiSrv = CasesUISrv;
this.uiSrv.initContext('list');
this.searchForm = {
searchQuery: this.uiSrv.buildQuery() || ''
};

this.list = PSearchSrv(undefined, 'case', {
filter: self.searchForm.searchQuery !== '' ? {
_string: self.searchForm.searchQuery
} : '',
loadAll: false,
sort: self.uiSrv.context.sort,
pageSize: self.uiSrv.context.pageSize,
nstats: true
});

this.caseStats = StreamStatSrv({
rootId: 'any',
query: {},
result: {},
objectType: 'case',
field: 'status'
});


$scope.$watch('$vm.list.pageSize', function (newValue) {
self.uiSrv.setPageSize(newValue);
});

this.toggleStats = function () {
this.uiSrv.toggleStats();
};

this.toggleFilters = function () {
this.uiSrv.toggleFilters();
};

this.filter = function () {
this.uiSrv.filter().then(this.applyFilters);
};

this.applyFilters = function () {
self.searchForm.searchQuery = self.uiSrv.buildQuery();
self.search();
};

this.clearFilters = function () {
this.uiSrv.clearFilters().then(this.applyFilters);
};

this.addFilter = function (field, value) {
this.uiSrv.addFilter(field, value).then(this.applyFilters);
};

this.removeFilter = function (field) {
this.uiSrv.removeFilter(field).then(this.applyFilters);
};

this.search = function () {
this.list.filter = {
_string: this.searchForm.searchQuery
};

this.list.update();
};
this.addFilterValue = function (field, value) {
var filterDef = this.uiSrv.filterDefs[field];
var filter = this.uiSrv.activeFilters[field];
var date;

if (filter && filter.value) {
if (filterDef.type === 'list') {
if (_.pluck(filter.value, 'text').indexOf(value) === -1) {
filter.value.push({
text: value
});
}
} else if (filterDef.type === 'date') {
date = moment(value, ['YYYYMMDDTHHmmZZ', 'DD-MM-YYYY HH:mm']);
this.uiSrv.activeFilters[field] = {
value: {
from: date.hour(0).minutes(0).seconds(0).toDate(),
to: date.hour(23).minutes(59).seconds(59).toDate()
}
};
} else {
filter.value = value;
}
} else {
if (filterDef.type === 'list') {
this.uiSrv.activeFilters[field] = {
value: [{
text: value
}]
};
} else if (filterDef.type === 'date') {
date = moment(value, ['YYYYMMDDTHHmmZZ', 'DD-MM-YYYY HH:mm']);
this.uiSrv.activeFilters[field] = {
value: {
from: date.hour(0).minutes(0).seconds(0).toDate(),
to: date.hour(23).minutes(59).seconds(59).toDate()
}
};
} else {
this.uiSrv.activeFilters[field] = {
value: value
};
}
}

this.filter();
};

this.getStatuses = function() {
return $q.resolve([
{text: 'Open'},
{text: 'Resolved'}
]);
};

this.getTags = function(query) {
return TagSrv.fromCases(query);
};

this.filterByStatus = function(status) {
this.uiSrv.clearFilters()
.then(function(){
self.addFilterValue('status', status);
});
};

this.sortBy = function(sort) {
this.list.sort = sort;
this.list.update();
this.uiSrv.setSort(sort);
};

}
})();
4 changes: 2 additions & 2 deletions ui/app/scripts/controllers/case/CaseMainCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@

if(switchToDetails) {
$scope.openTab('details');
}
}
};

$scope.switchFlag = function() {
Expand Down Expand Up @@ -168,7 +168,7 @@
});

modalInstance.result.then(function() {
$state.go('app.main', {viewId: 'currentcases'});
$state.go('app.cases');
});
};

Expand Down
21 changes: 18 additions & 3 deletions ui/app/scripts/directives/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,31 @@
return {
scope: {
user: '=userId',
iconOnly: '@',
iconOnly: '=',
iconSize: '@'
},
templateUrl: 'views/directives/user.html',
link: function(scope) {
link: function(scope) {
scope.userInfo = UserInfoSrv;
scope.userData = {};
scope.initials = '';

scope.$watch('userData.name', function(value) {
if(!value) {
return;
}

scope.initials = value.split(' ')
.map(function(item) {
return item[0];
})
.join('')
.substr(0, 3)
.toUpperCase();
});

scope.$watch('user', function(value) {
scope.userData = scope.userInfo.get(value);

});
}
};
Expand Down
Loading

0 comments on commit 0bbccb5

Please sign in to comment.