-
Notifications
You must be signed in to change notification settings - Fork 59
/
settings.js
195 lines (169 loc) · 7.07 KB
/
settings.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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
'use strict';
angular.module('hyphe.settingsController', [])
.controller('settings', ['$scope', 'api', 'utils', '$location', 'corpus'
,function($scope, api, utils, $location, corpus) {
$scope.currentPage = 'settings'
$scope.corpusName = corpus.getName()
$scope.corpusId = corpus.getId();
$scope.corpusNotEmpty;
$scope.corpusSettingsEditMode = false
$scope.options = {}
$scope.loading = true
$scope.destroying = false
$scope.resetting = false;
$scope.saving = false;
$scope.destroy = function(){
if (confirm('Are you sure you want to PERMANENTLY destroy this corpus?')) {
$scope.destroying = true
$scope.status = {message: 'Destroying corpus'};
api.destroyCorpus({
id:corpus.getId()
}, function(){
$location.path('/project/'+$scope.corpusId+'/');
}, function(){
$scope.status = {message: "Error destroying project", background:'danger'};
})
}
}
$scope.resetCorpus = function(){
if (confirm('Are you sure you want to reset this corpus?')) {
$scope.resetting = true;
$scope.status = {message: 'Resetting corpus'};
api.resetCorpus({
id:corpus.getId()
}, function(){
$location.path('/project/'+$scope.corpusId+'/overview');
}, function(){
$scope.status = {message: "Error resetting project", background:'danger'};
});
}
};
function checkValid(){
if ( $scope.ed_defaultStartpagesMode.length < 1 ){
$scope.status = {message:'You need to select at least one Startpages Mode', background:'danger'}
return false;
}
// if a user enters with the keyboard a non acceptable value, the input sets the variable to undefined
if ($scope.ed_max_depth === undefined) {
$scope.status = {message:'max depth must be comprised between 0 and ' + $scope.maxmax_depth, background:'danger'}
return false;
}
if ($scope.nbOfPages < 0 || $scope.nbOfPages > 50){
$scope.status = {message:'Please enter a valid number of pages as Startpages (between 0 and 9)', background:'danger'}
return false;
}
return true;
}
$scope.toggle = function(item, list, replace){
var toggle = false;
for (var index = 0; index < list.length; index++) {
if ((list[index].startsWith("pages") && item.startsWith("pages")) || list[index] === item) {
console.log(item)
list.splice(index, 1);
toggle = true;
}
}
if (!toggle || replace) {
console.log('iciaussi?')
list.push(item);
}
};
$scope.editSettings = function(save){
if (save) {
$scope.saving = true;
//construction of the array of startpages mode
$scope.ed_defaultStartpagesMode = [];
if ($scope.startpages_homepage) {
console.log($scope.startpages_homepage)
$scope.ed_defaultStartpagesMode.push('homepage');
}
if ($scope.startpages_prefixes) {
$scope.ed_defaultStartpagesMode.push('prefixes');
}
if ($scope.startpages_pages) {
$scope.ed_defaultStartpagesMode.push('pages-' + $scope.nbOfPages);
}
if (checkValid()) {
var modifiedOptions = {
"max_depth": $scope.ed_max_depth,
"defaultStartpagesMode": $scope.ed_defaultStartpagesMode,
"proxy": {
"port": $scope.ed_proxy_port,
"host": $scope.ed_proxy_host
},
"phantom": {
"timeout": $scope.ed_timeout,
"ajax_timeout": $scope.ed_ajax_timeout,
"idle_timeout": $scope.ed_idle_timeout,
"whitelist_domains": $scope.ed_whitelist
},
"follow_redirects": $scope.ed_follow_redirects,
"defaultCreationRule": $scope.ed_defaultCreationRule
};
$scope.status = {message: 'Saving new settings'};
api.setCorpusOptions({
id: $scope.corpusId,
options: modifiedOptions
}, function (options) {
$scope.options = options;
$scope.status = {};
$scope.saving = false;
console.log("Settings successfully updated");
}, function () {
$scope.status = {message: 'Could not save new settings.', background: 'danger'}
$scope.saving = false;
console.error("Settings could not be updated");
});
} else {
$scope.saving = false;
if (save && !checkValid()) return;
}
}
$scope.ed_max_depth = $scope.options.max_depth;
$scope.ed_defaultStartpagesMode = $scope.options.defaultStartpagesMode.slice();
console.log($scope.ed_defaultStartpagesMode);
$scope.ed_proxy_host = $scope.options.proxy.host+"";
$scope.ed_proxy_port = $scope.options.proxy.port+0;
$scope.ed_timeout = $scope.options.phantom.timeout+0;
$scope.ed_ajax_timeout = $scope.options.phantom.ajax_timeout+0;
$scope.ed_idle_timeout = $scope.options.phantom.idle_timeout+0;
$scope.ed_whitelist = $scope.options.phantom.whitelist_domains.slice();
$scope.ed_follow_redirects = $scope.options.follow_redirects.slice();
$scope.ed_defaultCreationRule = $scope.options.defaultCreationRule+"";
$scope.startpages_homepage = $scope.options.defaultStartpagesMode.includes('homepage');
$scope.startpages_prefixes = $scope.options.defaultStartpagesMode.includes('prefixes');
$scope.startpages_pages = $scope.options.defaultStartpagesMode.some(x => x.startsWith('pages'))
$scope.corpusSettingsEditMode = !$scope.corpusSettingsEditMode;
//define the current number of most cited pages as start pages
for (var i=0; i<$scope.options.defaultStartpagesMode.length; i++){
if ($scope.ed_defaultStartpagesMode[i].startsWith('pages')){
$scope.nbOfPages = parseInt($scope.ed_defaultStartpagesMode[i].slice(-1));
console.log($scope.nbOfPages)
return;
}
}
};
// Init
$scope.status = {message: "Loading"}
api.downloadCorpusTLDs(function(){
api.globalStatus({},
function(corpus_status){
$scope.corpus_status=corpus_status;
$scope.corpusNotEmpty = !!$scope.corpus_status.corpus.traph.webentities.total;
$scope.options = corpus_status.corpus.options;
$scope.maxmax_depth = corpus_status.hyphe.max_depth;
$scope.options.follow_redirects.sort();
$scope.creationrules = corpus_status.corpus.creation_rules.map(function(rule){
return {
domain: utils.LRU_to_URL(rule.prefix).replace(/^https?:\/\//, '') || "DEFAULT RULE"
,type: rule.name
,https: rule.prefix.indexOf('s:https') === 0
};
})
$scope.loading = false
$scope.status = {};
},function(data, status, headers, config){
$scope.status = {message: "Error while getting options", background:'danger'};
});
});
}])