Skip to content

Commit

Permalink
Merge branch 'FEAT-translations-posts' of github.com:ushahidi/platfor…
Browse files Browse the repository at this point in the history
…m-client into v5
  • Loading branch information
rowasc committed Aug 13, 2020
2 parents 7893631 + 2a5cb50 commit a3277e3
Show file tree
Hide file tree
Showing 13 changed files with 36 additions and 28 deletions.
3 changes: 2 additions & 1 deletion app/common/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,8 @@
"edit_savedsearch" : "Edit Search",
"set_settings" : "Collection Settings",
"add_notification" : "Add Notification",
"remove" : "remove"
"remove" : "remove",
"save_apply": "Save Search and Apply"
},
"category": {
"add_tag" : "Add Category",
Expand Down
1 change: 1 addition & 0 deletions app/main/posts/savedsearches/editor-directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ function (
$scope.cpySavedSearch.description = $filter('translate')($scope.cpySavedSearch.description);
$scope.cpySavedSearch.name = $filter('translate')($scope.cpySavedSearch.name);
$scope.save = function (savedSearch) {
PostFilters.reactToFilters = true;
$scope.isSaving = true;
var persist = savedSearch.id ? SavedSearchEndpoint.update : SavedSearchEndpoint.save;
persist(savedSearch)
Expand Down
2 changes: 1 addition & 1 deletion app/main/posts/savedsearches/savedsearch-editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<div class="modal-actions">
<div class="form-field">
<button type="button" class="button-link modal-trigger" ng-click="cancel()" translate>app.cancel</button>
<button type="button" class="button-alpha modal-trigger" ng-show="!isSaving" ng-click="save(cpySavedSearch)" translate>app.save_and_close</button>
<button type="button" class="button-alpha modal-trigger" ng-show="!isSaving" ng-click="save(cpySavedSearch)" translate>set.save_apply</button>
<button ng-click="saveSearch()" ng-show="isSaving" disabled class="button-beta" type="button">
<div class="loading">
<div class="line"></div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function ActiveSearchFilters($translate, $filter, PostFilters, _, FilterTransfor

FilterTransformers.requestsFiltersData().then(function (all) {
$scope.$watch(function () {
return PostFilters.getActiveFilters(PostFilters.getFilters());
return PostFilters.getActiveFilters($scope.filters);
}, handleFiltersUpdate, true);
});
}
Expand Down Expand Up @@ -158,7 +158,7 @@ function ActiveSearchFilters($translate, $filter, PostFilters, _, FilterTransfor
PostFilters.clearFilter(filterKey, value);
$scope.savedSearch = savedSearch;
} else {
PostFilters.clearFilter(filterKey, value);
$scope.filters = PostFilters.clearFilterFromArray(filterKey, value, $scope.filters);
}
}

Expand Down
16 changes: 13 additions & 3 deletions app/main/posts/views/filters/filter-posts.directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ function FilterPostsDirective() {
};
}

FilterPostsController.$inject = ['$scope', 'PostFilters', '$state', '$document', '$element'];
function FilterPostsController($scope, PostFilters, $state, $document, $element) {
FilterPostsController.$inject = ['$rootScope', '$scope', 'PostFilters', '$state', '$document', '$element'];
function FilterPostsController($rootScope, $scope, PostFilters, $state, $document, $element) {
$scope.searchSavedToggle = false;
$scope.status = { isopen: false };
$scope.hideDropdown = hideDropdown;
Expand All @@ -26,10 +26,15 @@ function FilterPostsController($scope, PostFilters, $state, $document, $element)
PostFilters.reactToFilters = false;
activate();

$rootScope.$on('event:filters:modeContext', function () {
$scope.filters = PostFilters.getFilters();
activateViewFilters();
});

function activate() {
// Watch all click events on the page
$document.on('click', handleDocumentClick);

activateViewFilters();
$scope.$on('$destroy', () => {
$document.off('click', handleDocumentClick);
});
Expand All @@ -43,8 +48,13 @@ function FilterPostsController($scope, PostFilters, $state, $document, $element)
});
}

function activateViewFilters () {
$scope.filtersInView = angular.copy($scope.filters);
}

function applyFilters() {
PostFilters.reactToFilters = true;
PostFilters.setFilters($scope.filtersInView);
$scope.status.isopen = false;
}

Expand Down
4 changes: 2 additions & 2 deletions app/main/posts/views/filters/filter-posts.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
<!-- Toggle Filters show/hide -->
<div uib-dropdown-toggle class="searchbar-options">
<a type="button" class="searchbar-options-filter button">
<sort-and-filter-counter></sort-and-filter-counter>
<sort-and-filter-counter filters="filtersInView"></sort-and-filter-counter>
</a>
</div>

<filters-dropdown uib-dropdown-menu class="dropdown-menu" dropdown-status="status" filters="filters"></filters-dropdown>
<filters-dropdown uib-dropdown-menu class="dropdown-menu" dropdown-status="status" filters="filtersInView"></filters-dropdown>
</form>
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,20 @@ SortAndFilterCounterDirective.$inject = ['PostFilters'];
function SortAndFilterCounterDirective(PostFilters) {
return {
restrict: 'E',
scope: {},
scope: {
filters: '='
},
link: SortAndFilterCounterDirectiveLink,
template: require('./sort-and-filter-counter.html')
};

function SortAndFilterCounterDirectiveLink($scope, $element, $attrs, ngModel) {
$scope.$watch(function () {
return PostFilters.countFilters();
return PostFilters.countFilters($scope.filters);
}, handleFiltersUpdate, true);

function handleFiltersUpdate() {
$scope.filtersCount = PostFilters.countFilters();
$scope.filtersCount = PostFilters.countFilters($scope.filters);
}
}

Expand Down
2 changes: 2 additions & 0 deletions app/main/posts/views/mode-context-form-filter.directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ function ModeContextFormFilter($scope, PostEndpoint, $q, _, $rootScope, PostSurv

if (diffLength > 0) {
getPostStats(PostFilters.getFilters()).$promise.then(updateCounts);
PostFilters.reactToFilters = true;
$rootScope.$broadcast('event:filters:modeContext');
}
}, true);

Expand Down
5 changes: 3 additions & 2 deletions app/main/posts/views/post-filters.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,9 @@ function PostFiltersService(_, FormEndpoint, TagEndpoint, $q) {
}
return null;
}
function countFilters() {
let count = _.keys(this.getActiveFilters(this.getFilters())).length;
function countFilters(filters) {
let filtersToCount = filters ? filters : this.getFilters();
let count = _.keys(this.getActiveFilters(filtersToCount)).length;

// Hacky workaround to make sure set is counted in filter counter
// Can probably be refactored to just include set in the filterState
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,15 @@ describe('post active search filters directive', function () {


it('should remove a given filter from the PostFilters object', function () {
spyOn(PostFilters, 'clearFilter');
spyOn(PostFilters, 'clearFilterFromArray');
var mockEvent = {
type: 'click',
stopPropagation: function () {},
preventDefault: function () {}
};
directiveScope.removeFilter('test', 'test', false, mockEvent);

expect(PostFilters.clearFilter).toHaveBeenCalled();
expect(PostFilters.clearFilterFromArray).toHaveBeenCalled();
});
});
describe('test clean filters', function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,6 @@ describe('post filters-dropdown directive', function () {
isolateScope.saveSavedSearchModal();
expect(ModalService.openTemplate).toHaveBeenCalledTimes(1);
});
it('should return false when calling disableApplyButton if in data-view', function () {
expect(isolateScope.disableApplyButton()).toEqual(false);
});
it('should return true when calling disableApplyButton if in map-view', function () {
mockState.$current.includes = {
'posts': true,
'posts.map': true
};
expect(isolateScope.disableApplyButton()).toEqual(true);
});
});
describe('test children', function () {
it('should have a filter-post-order-asc-desc directive child', function () {
Expand Down
3 changes: 2 additions & 1 deletion test/unit/main/post/views/post-view-map.directive.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,11 @@ describe('post view map directive', function () {
isolateScope.filters = {
status : 'published'
};
PostFilters.reactToFilters = true;
});

expect(L.geoJson).toHaveBeenCalled();
expect(L.geoJson.calls.count()).toEqual(3);
expect(L.geoJson.calls.count()).toEqual(2);
expect(geojson.addTo).toHaveBeenCalledWith(map);
});

Expand Down
Loading

0 comments on commit a3277e3

Please sign in to comment.