Skip to content

Commit

Permalink
#76 Set case listing default filter
Browse files Browse the repository at this point in the history
  • Loading branch information
nadouani authored and To-om committed Feb 1, 2017
1 parent 2040527 commit 4599e38
Showing 1 changed file with 24 additions and 25 deletions.
49 changes: 24 additions & 25 deletions ui/app/scripts/services/CasesUISrv.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@
'use strict';
angular.module('theHiveServices')
.factory('CasesUISrv', function($q, localStorageService) {
var defaultFilter = {
status: {
field: 'status',
value: [{
text: 'Open'
}],
filter: '(status:"Open")'
}
};

var factory = {
filterDefs: {
Expand Down Expand Up @@ -61,24 +70,20 @@
state: null,
showFilters: false,
showStats: false,
pageSize: 15
pageSize: 15,
sort: ['-flag', '-startDate']
},
currentState: null,
currentPageSize: null,

initContext: function(state) {
if (!factory.context.state) {
var storedContext = localStorageService.get('cases-section');

if (storedContext && storedContext.state && storedContext.state === state) {
factory.context = storedContext;
factory.filters = storedContext.filters || {};
factory.activeFilters = storedContext.activeFilters || {};
return;
}
}

if (state !== factory.context.state) {
var storedContext = localStorageService.get('cases-section');
if (storedContext) {
factory.context = storedContext;
factory.filters = storedContext.filters || {};
factory.activeFilters = storedContext.activeFilters || {};
return;
} else {
factory.context = {
state: state,
showFilters: false,
Expand All @@ -87,8 +92,13 @@
sort: ['-flag', '-startDate']
};

factory.filters = {};
factory.filters = defaultFilter;
factory.activeFilters = {};
factory.activeFilters.status = {
value: [{
text: 'Open'
}]
};

factory.storeContext();
}
Expand Down Expand Up @@ -140,17 +150,6 @@
filterDef = factory.filterDefs[field];

// Prepare the filter value
/*
if(factory.hasFilter(field)) {
var oldValue = factory.getFilterValue(field);
console.log('Filter ['+field+'] already exists = ' + oldValue);
if(factory.filterDefs[field].type === 'list') {
value = angular.isArray(oldValue) ? oldValue.push({text: value}) : [{text: oldValue}, {text: value}];
}
}
*/

if (field === 'keyword') {
query = value;
} else if (angular.isArray(value) && value.length > 0) {
Expand Down

0 comments on commit 4599e38

Please sign in to comment.