Skip to content

Commit

Permalink
make archives period a dropdown selection for days before and after (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
boogheta committed Jul 5, 2021
1 parent e87d5f3 commit b5071c0
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 21 deletions.
26 changes: 17 additions & 9 deletions hyphe_frontend/app/views/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -199,17 +199,25 @@ <h3 style="margin:0px">CRAWL WEB ARCHIVES (experimental)</h3>
<div ng-hide="ed_webarchive_option === ''">
<!-- TODO: DATE SELECTOR -->
<dt>Date to try to approach</dt>
<md-input-container style="width: 95%; margin: 0px; height: 28px">
<input ng-model="ed_webarchive_date" ng-change="setArchivesMinMaxDate(ed_webarchive_date, ed_webarchive_daysrange)">
<md-input-container style="width: 95%; margin: 0px; height: 28px; width: 33%">
<input ng-model="ed_webarchive_date" ng-change="setArchivesMinMaxDate()" style="text-align: center">
</md-input-container>

<!-- TODO: use DATE SELECTOR to define the days range-->
<dt>Days to consider around the date</dt>
<md-input-container style="width: 95%; margin: 0px; height: 28px">
<input type="number" min="1" ng-model="ed_webarchive_daysrange" ng-change="setArchivesMinMaxDate(ed_webarchive_date, ed_webarchive_daysrange)">
</md-input-container>
<dt>Delay to consider before and after the date</dt>
<div layout="row" style="display: flex; justify-content: flex-start">
<md-input-container style="margin: 0px; height: 28px; width: 33%; text-align: center">
<md-select ng-model="ed_webarchive_daysrange_choice" ng-change="setArchivesMinMaxDate()">
<md-option ng-repeat="(key, value) in webarchives_periods" value="{{ key }}">{{ value }}</md-option>
</md-select>
</md-input-container>
<md-input-container ng-show="ed_webarchive_daysrange_choice === 'custom'" style="margin: 0px; height: 28px; width: 33%">
<input type="number" min="1" ng-model="ed_webarchive_daysrange_custom" ng-change="setArchivesMinMaxDate()" style="text-align: right">
</md-input-container>
<span ng-show="ed_webarchive_daysrange_choice === 'custom'" style="padding-top: 5px">days</span>
</div>

<div style="text-align:center">
<div style="text-align:center; margin-top: 10px">
<small><em>{{ webarchives_mindate }} &#x2794; {{ webarchives_maxdate }}</em></small>
</div>
</div>
Expand Down Expand Up @@ -349,8 +357,8 @@ <h3 style="margin:0px">CRAWL WEB ARCHIVES</h3>
<dt>Date to try to approach</dt>
<dd style="min-height: 22px">{{ options.webarchives_date }}</dd>

<dt>Days to consider around the date</dt>
<dd style="min-height: 22px">{{ options.webarchives_days_range }}</dd>
<dt>Delay to consider before and after the date</dt>
<dd style="min-height: 22px">{{ webarchives_days_range_display }}</dd>
<div style="text-align:center">
<small><em>{{ webarchives_mindate }} &#x2794; {{ webarchives_maxdate }}</em></small>
</div>
Expand Down
56 changes: 44 additions & 12 deletions hyphe_frontend/app/views/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,45 @@ angular.module('hyphe.settingsController', [])
return true;
}

$scope.setArchivesMinMaxDate = function(date, days){
try {
var dat = new Date(date)
dat.setDate(dat.getDate() - days/2)
$scope.webarchives_mindate = dat.toISOString().slice(0, 10)
dat.setDate(dat.getDate() + days)
$scope.webarchives_maxdate = dat.toISOString().slice(0, 10)
} catch(e) {}
$scope.webarchives_periods = {
"0": "None",
"1": "a day",
"3": "3 days",
"7": "a week",
"14": "2 weeks",
"30": "a month",
"91": "3 months",
"182": "6 months",
"custom": "Custom"
}

$scope.setArchivesMinMaxDate = function() {
if (!$scope.ed_webarchive_daysrange_custom || !$scope.ed_webarchive_daysrange_choice) {
$scope.ed_webarchive_daysrange_custom = Math.trunc($scope.options.webarchives_days_range / 2);
if (Object.keys($scope.webarchives_periods).map(x => 2*x).indexOf($scope.options.webarchives_days_range) == -1) {
$scope.ed_webarchive_daysrange_choice = 'custom'
} else {
$scope.ed_webarchive_daysrange_choice = $scope.options.webarchives_days_range / 2
}
}

if ($scope.ed_webarchive_daysrange_choice === 'custom') {
$scope.ed_webarchive_daysrange = $scope.ed_webarchive_daysrange_custom + 0
$scope.webarchives_days_range_display = $scope.ed_webarchive_daysrange + " days"
} else {
$scope.ed_webarchive_daysrange = parseInt($scope.ed_webarchive_daysrange_choice)
$scope.webarchives_days_range_display = $scope.webarchives_periods[$scope.ed_webarchive_daysrange]
}

try {
var dat = new Date($scope.ed_webarchive_date)
dat.setDate(dat.getDate() - $scope.ed_webarchive_daysrange)
$scope.webarchives_mindate = dat.toISOString().slice(0, 10)
dat.setDate(dat.getDate() + 2 * $scope.ed_webarchive_daysrange)
$scope.webarchives_maxdate = dat.toISOString().slice(0, 10)
} catch(e) {
console.log(e)
}
}

$scope.editSettings = function(save){
Expand Down Expand Up @@ -110,12 +141,12 @@ angular.module('hyphe.settingsController', [])
},
"webarchives_option": $scope.ed_webarchive_option,
"webarchives_date": $scope.ed_webarchive_date,
"webarchives_days_range": $scope.ed_webarchive_daysrange,
"webarchives_days_range": 2 * $scope.ed_webarchive_daysrange,
"follow_redirects": $scope.ed_follow_redirects,
"defaultCreationRule": $scope.ed_defaultCreationRule
};

$scope.setArchivesMinMaxDate($scope.ed_webarchive_date, $scope.ed_webarchive_daysrange)
$scope.setArchivesMinMaxDate()

$scope.webarchives_chosen_option = $scope.webarchives_options.filter(function(o) { return o.id === $scope.ed_webarchive_option})[0]

Expand All @@ -142,7 +173,7 @@ angular.module('hyphe.settingsController', [])
$scope.ed_webarchive_option = $scope.options.webarchives_option;
// TODO VALIDATE DATE AND RANGE
$scope.ed_webarchive_date = $scope.options.webarchives_date;
$scope.ed_webarchive_daysrange = $scope.options.webarchives_days_range + 0;
$scope.setArchivesMinMaxDate()
$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;
Expand Down Expand Up @@ -181,9 +212,10 @@ angular.module('hyphe.settingsController', [])
,https: rule.prefix.indexOf('s:https') === 0
};
})
$scope.setArchivesMinMaxDate($scope.options.webarchives_date, $scope.options.webarchives_days_range)
$scope.webarchives_options = corpus_status.hyphe.available_archives
$scope.webarchives_chosen_option = $scope.webarchives_options.filter(function(o) { return o.id === corpus_status.corpus.options.webarchives_option})[0]
$scope.ed_webarchive_date = $scope.options.webarchives_date;
$scope.setArchivesMinMaxDate()
$scope.loading = false
$scope.status = {}

Expand Down

0 comments on commit b5071c0

Please sign in to comment.