subFilterTableDir

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
app.directive('sfTable', function(SubFilterService,PrimaryFilterService, SortService) {
return {
restrict: 'E',
templateUrl: 'templates/sf-table.html',
scope: {
// filter: "@"
},
link: function(scope, element, attrs) {
scope.primaryFilter = PrimaryFilterService.filter;
scope.aggregate_data = [];
scope.filter = SubFilterService.filter.type;
scope.toggleOptions = [];
// Passed on to Child Directives
scope.field = "volume";
// Scope fields for pagination
scope.start = 0;
scope.end = 10;
scope.total = 0;
scope.radioValues = {
'set1':[{value:'transport/storage', name:'Transport/Storage'},
{value:'rate_schedule', name:'Rate Schedules'}],
'set2':[{value:'volume', name:'Volume'},
{value:'contract', name: 'Contracts count'}]
}
// Watch the primary filter value
scope.$watch(
function() {
return scope.primaryFilter.value;
},
function(newVal, oldVal) {
SubFilterService.getFilterData(scope, element);
}
);
// Watch the sub filter value
scope.$watch(function() {
return SubFilterService.filter.type;
}, function(newVal, oldVal) {
switch(newVal){
case 'contract':
scope.toggleOptions = [{value: "set1", name:"Set 1"}];
break;
default:
scope.toggleOptions = [{value: "set1", name:"Set 1"}, {value: "set2", name:"Set 2"}];
}
SubFilterService.getFilterData(scope, element);
SubFilterService.redrawTable(element, scope);
}
);
// Watch the sub filter value
scope.$watch( "toggleCharts", function(newVal, oldVal) {
//console.log("toggleCharts");
}
);
scope.$watch( "field", function(newVal, oldVal) {
//console.log("field asd", newVal);
}
);
// Sort function, takes in the key to sort aggregate data by and reverse indicator
scope.sort = function(key,reverse) {
// Set all header bacgrounds to normal
element.find('.sort-header').css('background-color','#f9f9f9');
// Set relevant headers background to indicate sort key selection
element.find('.header-' + key).css('background-color', '#E6E6E6');
// Call to sorting service function
scope.aggregate_data = SortService.sort(key,scope.aggregate_data,scope.reverse);
// Broadcast message to child scopes
scope.$broadcast('SORTING-CHANGED');
}
}
}
});