app directive pfTable function SubFilterService PrimaryFilterService S

  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
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
app.directive('pfTable', function(SubFilterService,PrimaryFilterService, SortService) {
return {
restrict: 'E',
templateUrl: 'templates/pf-table.html',
scope: {
// filter: "@"
},
link: function(scope, element, attrs) {
scope.primaryFilter = PrimaryFilterService.filter;
scope.aggregate_data = [];
scope.currentPage = {name: "1", value: 1};
scope.selectOptions = [];
scope.isBigTable = true;
scope.isShow = false;
scope.filter = SubFilterService.filter.type;
// Passed on to Child Directives, "volume" or "contract"
scope.field = "volume";
// Scope fields for pagination
scope.start = 0;
scope.end = 10;
scope.total = 0;
// Watch the primary filter value
scope.$watch(
function() {
return scope.primaryFilter.value;
},
function(newVal, oldVal) {
// console.log('scope-prim', scope.primaryFilter);
SubFilterService.getFilterData(scope, element);
}
);
// Watch the sub filter value
scope.$watch(function() {
return SubFilterService.filter.type;
}, function(newVal, oldVal) {
console.log('scope-sub1 Big');
// SubFilterService.getFilterData(scope, element);
SubFilterService.redrawTable(element, scope);
}
);
scope.next = function() {
if ((scope.start + 10) <= scope.length) {
scope.start = scope.start + 10;
scope.end = ((scope.start + 10) <= scope.length) ? scope.start + 10 : scope.start + scope.length - scope.start;
scope.currentPage.value++;
scope.currentPage.name = scope.currentPage.value.toString();
console.log(scope.start, scope.end);
SubFilterService.redrawTable(element,scope);
}
};
scope.first = function() {
scope.start = 0;
scope.end = ((scope.start + 10) <= scope.length) ? scope.start + 10 : scope.start + scope.length - scope.start;
scope.currentPage.value = 1;
scope.currentPage.name = scope.currentPage.value.toString();
SubFilterService.redrawTable(element,scope);
};
scope.last = function() {
scope.start = (scope.countOfPages-1)*10;
scope.end = ((scope.start + 10) <= scope.length) ? scope.start + 10 : scope.start + scope.length - scope.start;
scope.currentPage.value = scope.countOfPages;
scope.currentPage.name = scope.currentPage.value.toString();
SubFilterService.redrawTable(element,scope);
};
scope.previous = function() {
if(scope.currentPage.value - 1 > 0){
scope.currentPage.value--;
scope.currentPage.name = scope.currentPage.value.toString();
scope.start = (scope.currentPage.value - 1)*10;
scope.end = scope.start+10;
console.log(scope.start, scope.end);
SubFilterService.redrawTable(element,scope);
}
};
scope.getPointInfo = function(index){
var currentIndex = (scope.currentPage.value-1)*10+index;
var shipperName = SubFilterService.filter.quarterData.shippers[currentIndex].shipper_name;
var shipperName = SubFilterService.filter.quarterData.shippers[currentIndex].shipper_name;
scope.pointRows = [];
SubFilterService.filter.quarterData.shippers[currentIndex].points.forEach(function(point){
scope.pointRows.push([shipperName, point.point_type, point.point_name, point.point_id_code_qualifier, point.point_id_code_qualifier, point.zone_name, point.point_transport_mdq, point.point_storage_msq])
});
};
// 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');
}
}
}
});