Skip to content

Commit

Permalink
Merge pull request #2025 from openhealthcare/163-disable-search-while…
Browse files Browse the repository at this point in the history
…-searching

163 disable search while searching
  • Loading branch information
davidmiller committed May 24, 2023
2 parents 4dfd551 + ec917a9 commit f50a203
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 4 deletions.
5 changes: 5 additions & 0 deletions changelog.md
@@ -1,5 +1,10 @@
### 0.24.0 (Major Release)

#### Disable search button while searching

While waiting for search results the search button and form are now disabled unless
the user has changed the search string.

#### Fixes a sporadic failure in create_random_data
Fixes a bug where in an edge case create_random.data.date_generator would raise "ValueError: empty range for randrange()".

Expand Down
4 changes: 3 additions & 1 deletion opal/core/search/static/js/search/controllers/search.js
Expand Up @@ -11,6 +11,7 @@ angular.module('opal.controllers').controller(
$scope.limit = 10;
$scope.results = [];
$scope.searched = false;
$scope.searching = false;
$scope.paginator = new Paginator($scope.search);

$scope.getQueryParam = function(){
Expand Down Expand Up @@ -38,7 +39,6 @@ angular.module('opal.controllers').controller(
};

$scope.loadResults = function(){
var queryString;
var urlParams = $location.search();

// this view only allows a couple a couple of search columns
Expand All @@ -53,13 +53,15 @@ angular.module('opal.controllers').controller(
ngProgressLite.set(0);
ngProgressLite.start();
var queryParams = $location.search();
$scope.searching = true;
queryBackend(queryParams).then(
function(response){
ngProgressLite.done();
$scope.searched = true;
$scope.paginator = new Paginator($scope.search, response.data);
},
function(){
$scope.searching = false;
ngProgressLite.done();
}
);
Expand Down
36 changes: 35 additions & 1 deletion opal/core/search/static/js/test/search.controller.test.js
Expand Up @@ -125,13 +125,47 @@ describe('SearchCtrl', function (){
});

var expectedUrl = "/search/simple/?query=Bond&page_number=1";
$httpBackend.expectGET().respond(500);
$httpBackend.expectGET(expectedUrl).respond(500);
spyOn(ngProgressLite, 'done');
$scope.loadResults();
$httpBackend.flush();
expect(ngProgressLite.done).toHaveBeenCalledWith();
});

it('loadResults() should set and reset the searching variable', function(){
location.search({
query: "Bond",
page_number: 1
});

var expectedUrl = "/search/simple/?query=Bond&page_number=1";
$httpBackend.expectGET(expectedUrl).respond({
page_number: 1,
object_list: [],
total_pages: 1
});
expect($scope.searching).toBe(false);
$scope.loadResults();
expect($scope.searching).toBe(true);
$httpBackend.flush();
expect($scope.searching).toBe(true);
});

it('loadResults() should set and reset the searching variable if the server errors', function(){
location.search({
query: "Bond",
page_number: 1
});

var expectedUrl = "/search/simple/?query=Bond&page_number=1";
$httpBackend.expectGET(expectedUrl).respond(500);
expect($scope.searching).toBe(false);
$scope.loadResults();
expect($scope.searching).toBe(true);
$httpBackend.flush();
expect($scope.searching).toBe(false);
});

it("should redirect to the search page", function(){
locationDetails.href = "";
locationDetails.pathname = "/somewhere";
Expand Down
6 changes: 4 additions & 2 deletions opal/core/search/templates/search.html
Expand Up @@ -10,14 +10,16 @@ <h2>
</h2>
</div>
<div class="panel-body">
<form ng-submit="search()" class="form form-horizontal">
<form ng-submit="!searching && search()" class="form form-horizontal">
<div class="row content-offset">
<div class="col-sm-4 col-sm-push-4">
<input type="text" autofocus
name="name"
slash-key-focus="!state || state==='normal'"
ng-blur="enableShortcuts()"
ng-focus="disableShortcuts()"
{# Reenables the search button/form after the input box is changed #}
ng-change="searching=false"
placeholder="Name or Hospital Number"
ng-model="query.searchTerm"
class="form-control"
Expand All @@ -33,7 +35,7 @@ <h2>
</div>
<div class="row">
<div class="col-sm-4 col-sm-push-4 text-center">
<a ng-click="search()" class="btn btn-lg btn-primary content-offset-25">
<a ng-disabled="searching" ng-click="search()" class="btn btn-lg btn-primary content-offset-25">
<i class="glyphicon glyphicon-search"></i>
{% trans "Search" %}
</a>
Expand Down

0 comments on commit f50a203

Please sign in to comment.