-
-
Notifications
You must be signed in to change notification settings - Fork 82
/
Copy pathdownload-history-controller.js
160 lines (143 loc) · 5.78 KB
/
download-history-controller.js
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
angular
.module('nzbhydraApp')
.controller('DownloadHistoryController', DownloadHistoryController);
function DownloadHistoryController($scope, StatsService, downloads, ConfigService, $timeout, $sce) {
$scope.limit = 100;
$scope.pagination = {
current: 1
};
var sortModel = {
column: "time",
sortMode: 2
};
$timeout(function () {
$scope.$broadcast("newSortColumn", sortModel.column, sortModel.sortMode);
}, 10);
$scope.filterModel = {};
//Filter options
$scope.indexersForFiltering = [];
_.forEach(ConfigService.getSafe().indexers, function (indexer) {
$scope.indexersForFiltering.push({label: indexer.name, id: indexer.name})
});
$scope.preselectedTimeInterval = {beforeDate: null, afterDate: null};
$scope.statusesForFiltering = [
{label: "None", id: 'NONE'},
{label: "Requested", id: 'REQUESTED'},
{label: "Internal error", id: 'INTERNAL_ERROR'},
{label: "NZB downloaded successful", id: 'NZB_DOWNLOAD_SUCCESSFUL'},
{label: "NZB download error", id: 'NZB_DOWNLOAD_ERROR'},
{label: "NZB added", id: 'NZB_ADDED'},
{label: "NZB not added", id: 'NZB_NOT_ADDED'},
{label: "NZB add error", id: 'NZB_ADD_ERROR'},
{label: "NZB add rejected", id: 'NZB_ADD_REJECTED'},
{label: "Content download successful", id: 'CONTENT_DOWNLOAD_SUCCESSFUL'},
{label: "Content download warning", id: 'CONTENT_DOWNLOAD_WARNING'},
{label: "Content download error", id: 'CONTENT_DOWNLOAD_ERROR'}
];
$scope.accessOptionsForFiltering = [{label: "All", value: "all"}, {label: "API", value: 'API'}, {
label: "Internal",
value: 'INTERNAL'
}];
//Preloaded data
$scope.nzbDownloads = downloads.nzbDownloads;
$scope.totalDownloads = downloads.totalDownloads;
$scope.columnSizes = {
time: 10,
indexer: 10,
title: 37,
result: 9,
source: 8,
age: 6,
username: 10,
ip: 10
};
var anyUsername = false;
var anyIp = false;
for (var download of $scope.nzbDownloads) {
if (download.username) {
anyUsername = true;
}
if (download.ip) {
anyIp = true;
}
if (anyIp && anyUsername) {
break;
}
}
if (ConfigService.getSafe().logging.historyUserInfoType === "NONE" || (!anyUsername && !anyIp)) {
$scope.columnSizes.username = 0;
$scope.columnSizes.ip = 0;
$scope.columnSizes.title += 20;
} else if (ConfigService.getSafe().logging.historyUserInfoType === "IP") {
$scope.columnSizes.username = 0;
$scope.columnSizes.title += 10;
} else if (ConfigService.getSafe().logging.historyUserInfoType === "USERNAME") {
$scope.columnSizes.ip = 0;
$scope.columnSizes.title += 10;
}
$scope.update = function () {
StatsService.getDownloadHistory($scope.pagination.current, $scope.limit, $scope.filterModel, sortModel).then(function (downloads) {
$scope.nzbDownloads = downloads.nzbDownloads;
$scope.totalDownloads = downloads.totalDownloads;
});
};
$scope.$on("sort", function (event, column, sortMode) {
if (sortMode === 0) {
column = "time";
sortMode = 2;
}
sortModel = {
column: column,
sortMode: sortMode
};
$scope.$broadcast("newSortColumn", sortModel.column, sortModel.sortMode);
$scope.update();
});
$scope.getStatusIcon = function (result) {
var spans;
if (result === "NONE" || result === "REQUESTED") {
spans = '<span class="glyphicon glyphicon-question-sign"></span>'
}
if (result === "INTERNAL_ERROR") {
spans = '<span class="glyphicon glyphicon-remove"></span>'
}
if (result === "INTERNAL_ERROR") {
spans = '<span class="glyphicon glyphicon-remove"></span>'
}
if (result === 'NZB_DOWNLOAD_SUCCESSFUL') {
spans = '<span class="glyphicon glyphicon-ok"></span>';
}
if (result === 'NZB_DOWNLOAD_ERROR') {
spans = '<span class="glyphicon glyphicon-remove"></span>';
}
if (result === 'NZB_ADDED') {
spans = '<span class="glyphicon glyphicon-ok" style="margin-right: 3px"></span><span class="glyphicon glyphicon-question-sign"></span>';
}
if (result === 'NZB_NOT_ADDED' || result === 'NZB_ADD_ERROR' || result === 'NZB_ADD_REJECTED') {
spans = '<span class="glyphicon glyphicon-ok" style="margin-right: 3px"></span><span class="glyphicon glyphicon-remove"></span>';
}
if (result === 'CONTENT_DOWNLOAD_SUCCESSFUL') {
spans = '<span class="glyphicon glyphicon-ok" style="margin-right: 3px"><span class="glyphicon glyphicon-ok"></span><span class="glyphicon glyphicon-ok"></span>';
}
if (result === 'CONTENT_DOWNLOAD_ERROR' || result === 'CONTENT_DOWNLOAD_WARNING') {
spans = '<span class="glyphicon glyphicon-ok" style="margin-right: 3px"><span class="glyphicon glyphicon-ok"></span><span class="glyphicon glyphicon-remove"></span>';
}
return $sce.trustAsHtml('<span tooltip-placement="auto top" uib-tooltip="' + result + '">' + spans + '</span>');
};
$scope.$on("filter", function (event, column, filterModel, isActive) {
if (filterModel.filterValue) {
$scope.filterModel[column] = filterModel;
} else {
delete $scope.filterModel[column];
}
$scope.update();
})
}
angular
.module('nzbhydraApp')
.filter('reformatDateEpoch', reformatDateEpoch);
function reformatDateEpoch() {
return function (date) {
return moment.unix(date).local().format("YYYY-MM-DD HH:mm");
}
}