Skip to content

Commit

Permalink
[enh] Allow to exclude old ad, in search
Browse files Browse the repository at this point in the history
  • Loading branch information
blavenie committed Jan 31, 2020
1 parent 7299274 commit 516a5de
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 4 deletions.
1 change: 1 addition & 0 deletions www/plugins/market/i18n/locale-en-GB.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
"BTN_OFFERS": "Offers",
"BTN_NEEDS": "Needs",
"SHOW_CLOSED_RECORD": "Display closed ads?",
"SHOW_OLD_RECORD": "Display old ads?",
"RECORD_STOCK": "Stock:"
},
"GALLERY": {
Expand Down
1 change: 1 addition & 0 deletions www/plugins/market/i18n/locale-en.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
"BTN_OFFERS": "Offers",
"BTN_NEEDS": "Needs",
"SHOW_CLOSED_RECORD": "Display closed ads?",
"SHOW_OLD_RECORD": "Display old ads?",
"RECORD_STOCK": "Stock:"
},
"GALLERY": {
Expand Down
1 change: 1 addition & 0 deletions www/plugins/market/i18n/locale-fr-FR.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
"BTN_OFFERS": "Offres",
"BTN_NEEDS": "Demandes",
"SHOW_CLOSED_RECORD": "Afficher les annonces closes ?",
"SHOW_OLD_RECORD": "Afficher les anciennes annonces ?",
"RECORD_STOCK": "Stock :"
},
"GALLERY": {
Expand Down
36 changes: 32 additions & 4 deletions www/plugins/market/js/controllers/search-controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ angular.module('cesium.market.search.controllers', ['cesium.market.record.servic
$stateProvider

.state('app.market_lookup', {
url: "/market?q&category&location&reload&type&hash&lat&lon&last",
url: "/market?q&category&location&reload&type&hash&lat&lon&last&old",
views: {
'menuContent': {
templateUrl: "plugins/market/templates/search/lookup.html",
Expand All @@ -20,7 +20,7 @@ angular.module('cesium.market.search.controllers', ['cesium.market.record.servic
})

.state('app.market_lookup_lg', {
url: "/market/lg?q&category&location&reload&type&hash&closed&lat&lon&last",
url: "/market/lg?q&category&location&reload&type&hash&closed&lat&lon&last&old",
views: {
'menuContent': {
templateUrl: "plugins/market/templates/search/lookup_lg.html",
Expand Down Expand Up @@ -73,6 +73,7 @@ function MkLookupAbstractController($scope, $state, $filter, $q, $location, $tra
options: null,
loadingMore: false,
showClosed: false,
showOld: false,
geoDistance: !isNaN(csSettings.data.plugins.es.geoDistance) ? csSettings.data.plugins.es.geoDistance : 20,
sortAttribute: null,
sortDirection: 'desc'
Expand Down Expand Up @@ -101,6 +102,9 @@ function MkLookupAbstractController($scope, $state, $filter, $q, $location, $tra
$scope.$watch('search.showClosed', function() {
$scope.options.showClosed = $scope.search.showClosed;
}, true);
$scope.$watch('search.showOld', function() {
$scope.options.showOld = $scope.search.showOld;
}, true);

$scope.init = function() {
return $q.all([
Expand Down Expand Up @@ -273,6 +277,14 @@ function MkLookupAbstractController($scope, $state, $filter, $q, $location, $tra
filters.push({range: {stock: {gt: 0}}});
}

if ($scope.search.showOld) {
stateParams.old = true;
}
else {
var minTime = (Date.now() / 1000) - 60 * 60 * 24 * 365;
filters.push({range: {time: {gt: minTime}}});
}

if ($scope.search.type) {
filters.push({term: {type: $scope.search.type}});
stateParams.type = $scope.search.type;
Expand Down Expand Up @@ -323,9 +335,17 @@ function MkLookupAbstractController($scope, $state, $filter, $q, $location, $tra

var filters = [];
var matches = [];

// Filter on NOT closed
if (!$scope.search.showClosed) {
filters.push({range: {stock: {gt: 0}}});
}

// Filter on NOT too old
if (!$scope.search.showOld) {
var minTime = (Date.now() / 1000) - 60 * 60 * 24 * 365;
filters.push({range: {time: {gt: minTime}}});
}
// filter on type
if ($scope.search.type) {
filters.push({term: {type: $scope.search.type}});
Expand Down Expand Up @@ -392,6 +412,8 @@ function MkLookupAbstractController($scope, $state, $filter, $q, $location, $tra
}});
}
}


if (matches.length) {
options.query = {bool: {}};
options.query.bool.should = matches;
Expand Down Expand Up @@ -611,11 +633,17 @@ function MkLookupController($scope, $rootScope, $controller, $focus, $timeout, $
}
}

// Show closed ad
if (state.stateParams.closed == true) {
// Show closed ads
if (angular.isDefined(state.stateParams.closed)) {
$scope.search.showClosed = true;
showAdvanced = true;
}

// Show old ads
if (angular.isDefined(state.stateParams.old)) {
$scope.search.showOld = true;
showAdvanced = true;
}
}

// Search on category
Expand Down
15 changes: 15 additions & 0 deletions www/plugins/market/templates/search/lookup_options.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,18 @@
</label>
</div>

<!-- Show OLD ad ? -->
<div ng-if="search.advanced"
class="item item-icon-left item-input item-toggle stable-bg" >
<i class="icon ion-clock gray"></i>
<b class="icon-secondary ion-close-circled assertive" style="top:7px; left: 34px;"></b>
<span class="input-label item-icon-left-padding" ng-click="search.showOld=!search.showOld">
{{'MARKET.SEARCH.SHOW_OLD_RECORD' | translate}}
</span>
<label class="toggle toggle-royal">
<input type="checkbox" ng-model="search.showOld">
<div class="track">
<div class="handle"></div>
</div>
</label>
</div>

0 comments on commit 516a5de

Please sign in to comment.