Skip to content

Commit

Permalink
fix period selector custom detection + apply it to single crawls (#372)
Browse files Browse the repository at this point in the history
  • Loading branch information
boogheta committed Jul 6, 2021
1 parent b5071c0 commit ada2d16
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 27 deletions.
2 changes: 1 addition & 1 deletion config/config.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"webarchives": {
"options": ["web.archive.org"],
"date": "2012-07-01",
"days_range": 365
"days_range": 28
},
"ADMIN_PASSWORD": null,
"OPEN_CORS_API": false,
Expand Down
21 changes: 14 additions & 7 deletions hyphe_frontend/app/partials/webentitystartpagesmodal.html
Original file line number Diff line number Diff line change
Expand Up @@ -203,18 +203,25 @@ <h3 class="md-title" md-colors="{'color':'default-warn'}">
<md-radio-button value="{{option.id}}" class="md-primary">{{option.label}}</md-radio-button>
</div>
</md-radio-group>
<div layout="column" ng-style="{'opacity': webentity.webarchives.option ? 1 : 0}">
<!-- TODO: DATE SELECTOR -->
<div layout="column" ng-style="{'opacity': webentity.webarchives.option ? 1 : 0, 'width': '257px'}">
<!-- TODO: DATE PICKER -->
<label><small>Date to try to approach:</small></label>
<md-input-container style="width: 95%; margin: 0px; height: 28px">
<input ng-model="webentity.webarchives.date" ng-change="setArchivesMinMaxDate()">
</md-input-container>

<!-- TODO: use DATE SELECTOR to define the days range-->
<label><small>Days to consider around the date:</small></label>
<md-input-container style="width: 95%; margin: 0px; height: 28px">
<input type="number" min="1" ng-model="webentity.webarchives.days_range" ng-change="setArchivesMinMaxDate()">
</md-input-container>
<label><small>Delay to consider before and after the date</small></label>
<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; margin-top: 20px;">
<small><em>{{ webarchives_mindate }} &#x2794; {{ webarchives_maxdate }}</em></small>
Expand Down
51 changes: 43 additions & 8 deletions hyphe_frontend/app/views/prepareCrawls.js
Original file line number Diff line number Diff line change
Expand Up @@ -664,18 +664,53 @@ angular.module('hyphe.preparecrawlsController', [])
$scope.depthRange = depthRange
$scope.cookiesError = ""
$scope.webarchives_options = webarchives_options

$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.webentity.webarchives.option) {
try {
var dat = new Date($scope.webentity.webarchives.date)
dat.setDate(dat.getDate() - $scope.webentity.webarchives.days_range/2)
$scope.webarchives_mindate = dat.toISOString().slice(0, 10)
dat.setDate(dat.getDate() + $scope.webentity.webarchives.days_range)
$scope.webarchives_maxdate = dat.toISOString().slice(0, 10)
} catch(e) {}
if (!$scope.webentity.webarchives.option) {
return
}

if ($scope.ed_webarchive_daysrange_custom === undefined || $scope.ed_webarchive_daysrange_choice === undefined) {
$scope.ed_webarchive_daysrange_custom = Math.trunc($scope.webentity.webarchives.days_range / 2);
if (Object.keys($scope.webarchives_periods).map(x => 2*x).indexOf($scope.webentity.webarchives.days_range) == -1) {
$scope.ed_webarchive_daysrange_choice = 'custom'
} else {
$scope.ed_webarchive_daysrange_choice = $scope.webentity.webarchives.days_range / 2
}
}

if ($scope.ed_webarchive_daysrange_choice === 'custom') {
$scope.webentity.webarchives.days_range = 2 * $scope.ed_webarchive_daysrange_custom
$scope.webarchives_days_range_display = $scope.webentity.webarchives.days_range + " days"
} else {
$scope.webentity.webarchives.days_range = 2 * parseInt($scope.ed_webarchive_daysrange_choice)
$scope.webarchives_days_range_display = $scope.webarchives_periods[$scope.webentity.webarchives.days_range]
}

try {
var dat = new Date($scope.webentity.webarchives.date)
dat.setDate(dat.getDate() - $scope.webentity.webarchives.days_range / 2)
$scope.webarchives_mindate = dat.toISOString().slice(0, 10)
dat.setDate(dat.getDate() + $scope.webentity.webarchives.days_range)
$scope.webarchives_maxdate = dat.toISOString().slice(0, 10)
} catch(e) {
console.log(e)
}
}
$scope.setArchivesMinMaxDate()

$scope.startpagesSummary = {
stage: 'loading'
, percent: 0
Expand Down
3 changes: 1 addition & 2 deletions hyphe_frontend/app/views/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,12 @@ <h3 style="margin:0px">CRAWL WEB ARCHIVES (experimental)</h3>
</md-radio-group>

<div ng-hide="ed_webarchive_option === ''">
<!-- TODO: DATE SELECTOR -->
<!-- TODO: DATE PICKER -->
<dt>Date to try to approach</dt>
<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>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">
Expand Down
18 changes: 9 additions & 9 deletions hyphe_frontend/app/views/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,19 @@ angular.module('hyphe.settingsController', [])
}

$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",
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) {
if ($scope.ed_webarchive_daysrange_custom === undefined || $scope.ed_webarchive_daysrange_choice === undefined) {
$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'
Expand Down

0 comments on commit ada2d16

Please sign in to comment.