Skip to content

Commit

Permalink
Merge branch 'develop' into v5
Browse files Browse the repository at this point in the history
  • Loading branch information
tuxpiper committed Aug 27, 2020
2 parents d45bd9c + ac2357f commit fbe9c8d
Show file tree
Hide file tree
Showing 17 changed files with 214 additions and 99 deletions.
5 changes: 5 additions & 0 deletions app/common/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
"filter_by" :"Filter by...",
"sort_filter": "Sort & filter",
"apply_filters" : "Apply",
"close_and_view": "Close and view results",
"show_more_less" : "Show more/less",
"filters" : "Filters",
"filter_by_survey" : "Filter by survey",
Expand Down Expand Up @@ -651,6 +652,8 @@
"there_are_no_posts" : "There are no posts",
"in_this_deployment" : " in this deployment, yet.",
"posts_total": " {{posts}} of {{total_nb}} posts",
"posts_total_map": "Displaying {{posts}} of {{total_nb}} posts with location information on the map.",
"search_results": "Results:",
"by" : "by",
"task_completed" : "Task completed",
"everyone" : "Everyone",
Expand All @@ -665,7 +668,9 @@
"message_thread" : "Message Thread",
"all_posts" : "All Posts",
"no_search_results" : "Your search didn't match any posts",
"no_search_results_location" : "Your search didn't match any posts with location information",
"no_posts_yet" : "There are no posts yet!",
"no_posts_yet_location": "There are no posts with location information yet!",
"add_first_post": "Add the first post",
"create_post" : "Create Post",
"create" : "Create",
Expand Down
138 changes: 69 additions & 69 deletions app/common/locales/es.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/main/posts/modify/location.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
/>
</div>
<div id="searchbar-results" class="searchbar-results dropdown-menu init">
<div class="form-field">
<div class="form-field" embed-only=false>
<button class="button-beta button-plain" ng-click="chooseCurrentLocation()" ng-if="showCurrentPositionControl" >
<svg class="iconic">
<use
Expand Down
18 changes: 16 additions & 2 deletions app/main/posts/views/filters/filter-posts.directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ function FilterPostsDirective() {
scope: {
filters: '=',
onOpen: '&',
onClose: '&'
onClose: '&',
stats: '='
},
replace: true,
controller: FilterPostsController,
Expand All @@ -21,6 +22,7 @@ function FilterPostsController($scope, PostFilters, $state, $document, $element)
$scope.status = { isopen: false };
$scope.hideDropdown = hideDropdown;
$scope.showDropdown = showDropdown;
$scope.toggleDropdown = toggleDropdown;
$scope.removeQueryFilter = removeQueryFilter;
$scope.applyFilters = applyFilters;
PostFilters.reactiveFilters = false;
Expand All @@ -44,7 +46,9 @@ function FilterPostsController($scope, PostFilters, $state, $document, $element)
}

function applyFilters() {
PostFilters.reactiveFilters = true;
if ($state.$current.includes['posts.data']) {
PostFilters.reactiveFilters = true;
}
$scope.status.isopen = false;
}

Expand All @@ -71,4 +75,14 @@ function FilterPostsController($scope, PostFilters, $state, $document, $element)
// Otherwise close the dropdown
$scope.$apply(hideDropdown);
}
function toggleDropdown(event) {
switch (event.keyCode) {
case 27: $scope.hideDropdown();
break;
case 13: $scope.hideDropdown();
break;
default:
$scope.showDropdown();
}
}
}
16 changes: 12 additions & 4 deletions app/main/posts/views/filters/filter-posts.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,17 @@
<div class="form-field">
<label class="hidden" translate="toolbar.searchbar.search_entity">Search</label>
<div class="input-with-icon">
<input name="q" type="search" autocomplete="off"
placeholder="{{ 'toolbar.searchbar.search_entity' | translate }}"
ng-model="filters.q" ng-model-options="{ debounce: 300 }" ng-click = "showDropdown()" ng-keyup="($event.keyCode === 27) ? hideDropdown(): showDropdown()" ng-keypress="($event.keyCode === 27) ? hideDropdown(): showDropdown()">
<input
name="q"
type="search"
autocomplete="off"
placeholder="{{ 'toolbar.searchbar.search_entity' | translate }}"
ng-model="filters.q"
ng-model-options="{debounce: 300}"
ng-click = "toggleDropdown($event)"
ng-keyup="toggleDropdown($event)"
ng-keypress="toggleDropdown($event)"
>
<svg class="iconic" ng-show="!postFiltersFormOpen.q.$viewValue.length">
<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="/img/iconic-sprite.svg#magnifying-glass"></use>
</svg>
Expand All @@ -36,5 +44,5 @@
</a>
</div>

<filters-dropdown uib-dropdown-menu class="dropdown-menu" dropdown-status="status" filters="filters"></filters-dropdown>
<filters-dropdown stats="stats" uib-dropdown-menu class="dropdown-menu" dropdown-status="status" filters="filters"></filters-dropdown>
</form>
15 changes: 12 additions & 3 deletions app/main/posts/views/filters/filters-dropdown.directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ function FiltersDropdown() {
restrict: 'E',
scope: {
dropdownStatus: '=',
filters: '='
filters: '=',
stats: '='
},
controller: FiltersDropdownController,
template: require('./filters-dropdown.html')
Expand Down Expand Up @@ -64,8 +65,16 @@ function FiltersDropdownController($scope, $state, PostFilters, ModalService, $r
$scope.savedSearch.user_id = $rootScope.currentUser ? $rootScope.currentUser.userId : null;
ModalService.openTemplate('<saved-search-editor saved-search="savedSearch"></saved-search-editor>', modalHeaderText, 'star', $scope, false, false);
};
$scope.disableApplyButton = function () {
return $state.$current.includes['posts.map'] ? true : false;

$scope.getButtonText = function () {
if ($state.$current.includes['posts.map']) {
return 'app.close_and_view';
}
return 'app.apply_filters';
};

$scope.displayStats = function () {
return $state.$current.includes['posts.map'];
};
}

15 changes: 13 additions & 2 deletions app/main/posts/views/filters/filters-dropdown.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@
<post-active-search-filters ng-model="filters" filters-var="filters"></post-active-search-filters>
</div>
<div class="divider"></div>
<div ng-if="displayStats()">
<h4 class="dropdown-menu-title" translate="post.search_results">Results...</h4>
<div class="form-field">
<strong class="form-field" translate="post.posts_total_map" translate-values="{'posts': stats.filteredPosts, 'total_nb': stats.totalItems, 'unmapped': stats.unmapped }"></strong>
</div>
<div class="form-field" ng-if="stats.totalItems === 0 || stats.filteredPosts === 0">
<strong class="form-field" ng-if="stats.totalItems === 0" translate="post.no_posts_yet_location"></strong>
<strong class="form-field" ng-if="stats.filteredPosts === 0 && stats.totalItems > 0" translate="post.no_search_results_location"></strong>
</div>
</div>
<div class="divider" ng-if="displayStats()"></div>

<!-- sorting options -->
<h4 class="dropdown-menu-title" translate="app.sort_by"></h4>

Expand All @@ -26,5 +38,4 @@ <h4 class="dropdown-menu-title" translate="app.filter_by"></h4>
</div>
<div class="form-field filter-actions">
<button type="button" class="button-beta" ng-click="clearFilters()" translate>global_filter.restore_defaults</button>
<button type="submit" class="button-alpha" ng-disabled="disableApplyButton()" translate>app.apply_filters</button>
</div>
<button type="submit" class="button-alpha" translate>{{getButtonText()}}</button></div>
3 changes: 2 additions & 1 deletion app/main/posts/views/post-toolbar.directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ function PostToolbarDirective() {
restrict: 'E',
scope: {
filters: '=',
selectedPost: '='
selectedPost: '=',
stats: '='
},
controller: PostToolbarController,
template: require('./post-toolbar.html')
Expand Down
4 changes: 2 additions & 2 deletions app/main/posts/views/post-toolbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<!-- floating action button -->
<add-post-button></add-post-button>

<filter-posts filters="filters" embed-only="false" on-open="hideOtherActions()" on-close="showOtherActions()"></filter-posts>
<filter-posts filters="filters" stats="stats" embed-only="false" on-open="hideOtherActions()" on-close="showOtherActions()"></filter-posts>

<div class="button-group" embed-only="false" ng-hide="filtersActive">
<div ng-if="!editMode()">
Expand All @@ -20,7 +20,7 @@
</div>

<div embed-only="true" class="hide-until-medium">
<filter-posts filters="filters" on-open="hideOtherActions()" on-close="showOtherActions()"></filter-posts>
<filter-posts filters="filters" stats="stats" on-open="hideOtherActions()" on-close="showOtherActions()"></filter-posts>
<div class="button-group">
<div ng-hide="filtersActive">
<div ng-if="!editMode()">
Expand Down
10 changes: 10 additions & 0 deletions app/main/posts/views/post-view-map.directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ function PostViewMap(PostEndpoint, Maps, _, PostFilters, L, $q, $rootScope, $com
var requestBlockSize = 5;
var numberOfChunks = 0;
var currentGeoJsonRequests = [];
$scope.stats = {totalItems: 0, filteredPosts:0, unmapped: 0};

activate();

Expand Down Expand Up @@ -151,6 +152,13 @@ function PostViewMap(PostEndpoint, Maps, _, PostFilters, L, $q, $rootScope, $com
}

function loadPosts(query, offset, currentBlock) {
// Getting stats for filter-dropdown
let def = PostFilters.getQueryParams(PostFilters.getDefaults());
PostEndpoint.geojson(def).$promise.then(res => {
$scope.stats.totalItems = res.features.length;
$scope.stats.unmapped = res.total - res.features.length;
});

offset = offset || 0;
currentBlock = currentBlock || 1;

Expand All @@ -166,6 +174,8 @@ function PostViewMap(PostEndpoint, Maps, _, PostFilters, L, $q, $rootScope, $com
currentGeoJsonRequests.push(request);

return request.$promise.then(function (posts) {
// Set number of posts for filter-dropdown
$scope.stats.filteredPosts = posts.total;

// Set number of chunks
if (offset === 0 && posts.total > limit) {
Expand Down
2 changes: 1 addition & 1 deletion app/main/posts/views/post-view-map.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<layout-class layout="a"></layout-class>
<div ui-view="mode-context" noanimation="true" filters="filters"></div>
<main role="main">
<post-toolbar is-loading="isLoading" filters="filters" edit-mode="{ editing: false }"></post-toolbar>
<post-toolbar is-loading="isLoading" stats="stats" filters="filters" edit-mode="{ editing: false }"></post-toolbar>
<div class="map-view">
<div id="map-full-size" class="map full-size" ng-show="!noui"></div>
<div id="map-noui" class="map map-only" ng-show="noui"></div>
Expand Down
10 changes: 10 additions & 0 deletions app/settings/users/filter-users.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@
<!-- Filters menu -->
<div class="dropdown-menu init" data-toggle-target="search-filters" dropdown-menu>
<div class="dropdown-menu-body">
<fieldset>
<label translate>app.users</label>
<div class="form-field checkbox">
<label><input type="radio" name="order" ng-model="filters.order" value="asc">Ascending</label>
</div>
<div class="form-field checkbox">
<label><input type="radio" name="order" ng-model="filters.order" value="desc">Descending</label>
</div>
</fieldset>

<filter-role model="filters.role"></filter-role>
</div>

Expand Down
1 change: 1 addition & 0 deletions app/settings/users/users.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ function (
});

$scope.filters = {
order: 'asc',
role: [],
q: ''
};
Expand Down
2 changes: 1 addition & 1 deletion app/settings/users/users.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ <h1 class="mode-context-title" translate>app.users</h1>
<p ng-hide="users.length"><em translate>empty.user</em></p>
</div>

<div id="user-{{user.id}}" class="listing-item" ng-repeat="user in users | orderBy:'realname'" ng-class="{ 'warning': isToggled(user) }" ng-click="toggleUser(user)">
<div id="user-{{user.id}}" class="listing-item" ng-repeat="user in users | orderBy:'sortalph'" ng-class="{ 'warning': isToggled(user) }" ng-click="toggleUser(user)">
<div class="listing-item-select">
<input type="checkbox" value="{{user.id}}" ng-checked="isToggled(user)">
</div>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
"socket.io-client": "2.0.3",
"sortablejs": "1.10.0",
"underscore": "^1.7.0",
"ushahidi-platform-pattern-library": "^4.4.2-pre.2",
"ushahidi-platform-pattern-library": "^4.4.3",
"ushahidi-platform-sdk": "^0.3.0"
},
"engines": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,33 @@ 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 correct button text', function () {
mockState.$current.includes = {
'posts': true,
'posts.map': true
};
expect(isolateScope.getButtonText()).toEqual('app.close_and_view');
mockState.$current.includes = {
'posts': true,
'posts.data': true,
'posts.map': false
};
expect(isolateScope.getButtonText()).toEqual('app.apply_filters');
});
it('should return true when calling disableApplyButton if in map-view', function () {
it('should return true if user is in map-view', function () {
mockState.$current.includes = {
'posts': true,
'posts.map': true
};
expect(isolateScope.disableApplyButton()).toEqual(true);
'posts': true,
'posts.map': true
};
expect(isolateScope.displayStats()).toEqual(true);
});
it('should return false if user is not in map-view', function () {
mockState.$current.includes = {
'posts': true,
'posts.map': false
};
expect(isolateScope.displayStats()).toEqual(false);
})
});
describe('test children', function () {
it('should have a filter-post-order-asc-desc directive child', function () {
Expand Down
39 changes: 34 additions & 5 deletions test/unit/main/post/views/filters/filters-posts.directive.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,25 @@ describe('filters-posts directive', function () {
PostFilters,
element,
isolateScope,
$compile;
$compile,
mockState = {
'$current': {
name: 'posts.data',
includes: {
'posts': true,
'posts.data': true
}
}
};
;
beforeEach(function () {
fixture.setBase('mocked_backend/api/v3');
var testApp = makeTestApp();
testApp
.directive('filterPosts', require('app/main/posts/views/filters/filter-posts.directive'))
.service('PostFilters', require('app/main/posts/views/post-filters.service.js'))
.service('$state', () => {
return {
go : () => {}
};
.service('$state', function () {
return mockState;
})
;
angular.mock.module('testApp');
Expand Down Expand Up @@ -70,5 +78,26 @@ describe('filters-posts directive', function () {
isolateScope.removeQueryFilter();
expect(isolateScope.filters.q).toEqual('');
});
it('should close dropdown when pressing escape', function () {
spyOn(isolateScope, 'hideDropdown').and.callThrough();
let event = {keyCode: 13};
isolateScope.toggleDropdown(event);
expect(isolateScope.hideDropdown).toHaveBeenCalled();
expect(isolateScope.status.isopen).toEqual(false);
});
it('should close dropdown when pressing enter', function () {
spyOn(isolateScope, 'hideDropdown').and.callThrough();
let event = {keyCode: 27};
isolateScope.toggleDropdown(event);
expect(isolateScope.hideDropdown).toHaveBeenCalled();
expect(isolateScope.status.isopen).toEqual(false);
});
it('should open dropdown when pressing any key except enter and escape', function () {
spyOn(isolateScope, 'showDropdown').and.callThrough();
let event = {keyCode: 22};
isolateScope.toggleDropdown(event);
expect(isolateScope.showDropdown).toHaveBeenCalled();
expect(isolateScope.status.isopen).toEqual(true);
});
});
});

0 comments on commit fbe9c8d

Please sign in to comment.