From f503dea287bf4c71bc6f9d3cfc98adb902d56d4d Mon Sep 17 00:00:00 2001 From: fredkingham Date: Mon, 27 Feb 2023 17:38:20 +0000 Subject: [PATCH 1/6] Removes an unused variable from search.js --- opal/core/search/static/js/search/controllers/search.js | 1 - 1 file changed, 1 deletion(-) diff --git a/opal/core/search/static/js/search/controllers/search.js b/opal/core/search/static/js/search/controllers/search.js index 2f960301c..f06587dc7 100644 --- a/opal/core/search/static/js/search/controllers/search.js +++ b/opal/core/search/static/js/search/controllers/search.js @@ -38,7 +38,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 From f9e8b175a7b9d1031dba2a4cb20194f99d97af75 Mon Sep 17 00:00:00 2001 From: fredkingham Date: Mon, 27 Feb 2023 18:03:54 +0000 Subject: [PATCH 2/6] Changes the search button/form to be disabled while waiting for results In the simple search page, while we are querying the server for search results, this disabled the search button and form. The form is reenabled after results are returned of it the user has changed what they want to search for. --- changelog.md | 7 ++++ .../static/js/search/controllers/search.js | 5 +++ .../static/js/test/search.controller.test.js | 34 +++++++++++++++++++ opal/core/search/templates/search.html | 5 +-- 4 files changed, 49 insertions(+), 2 deletions(-) diff --git a/changelog.md b/changelog.md index a1e506283..39f51cebb 100644 --- a/changelog.md +++ b/changelog.md @@ -1,3 +1,10 @@ +### 0.23.1 (Minor Release) + +#### Disable search button while searching + +While waiting for search results the search button and form are now disabled. + + ### 0.23.0 (Major Release) #### Enhanced customisation of search results diff --git a/opal/core/search/static/js/search/controllers/search.js b/opal/core/search/static/js/search/controllers/search.js index f06587dc7..3afe5c351 100644 --- a/opal/core/search/static/js/search/controllers/search.js +++ b/opal/core/search/static/js/search/controllers/search.js @@ -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(){ @@ -52,13 +53,17 @@ angular.module('opal.controllers').controller( ngProgressLite.set(0); ngProgressLite.start(); var queryParams = $location.search(); + $scope.searching = true; queryBackend(queryParams).then( function(response){ + $scope.searching = false; + ngProgressLite.done(); $scope.searched = true; $scope.paginator = new Paginator($scope.search, response.data); }, function(){ + $scope.searching = false; ngProgressLite.done(); } ); diff --git a/opal/core/search/static/js/test/search.controller.test.js b/opal/core/search/static/js/test/search.controller.test.js index ca752faf4..26fb0b048 100644 --- a/opal/core/search/static/js/test/search.controller.test.js +++ b/opal/core/search/static/js/test/search.controller.test.js @@ -132,6 +132,40 @@ describe('SearchCtrl', function (){ 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(false); + }); + + 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"; diff --git a/opal/core/search/templates/search.html b/opal/core/search/templates/search.html index f559ba834..66989d197 100644 --- a/opal/core/search/templates/search.html +++ b/opal/core/search/templates/search.html @@ -10,7 +10,7 @@

-
+
slash-key-focus="!state || state==='normal'" ng-blur="enableShortcuts()" ng-focus="disableShortcuts()" + ng-change="searching=false" placeholder="Name or Hospital Number" ng-model="query.searchTerm" class="form-control" @@ -33,7 +34,7 @@

- + {% trans "Search" %} From b93148c1b20d0eec4333026b77f156718c69d0d1 Mon Sep 17 00:00:00 2001 From: fredkingham Date: Mon, 27 Feb 2023 18:07:09 +0000 Subject: [PATCH 3/6] Makes use of a previously unused variable in the search controller tests This only changes the tests. --- opal/core/search/static/js/test/search.controller.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opal/core/search/static/js/test/search.controller.test.js b/opal/core/search/static/js/test/search.controller.test.js index 26fb0b048..2853319ed 100644 --- a/opal/core/search/static/js/test/search.controller.test.js +++ b/opal/core/search/static/js/test/search.controller.test.js @@ -125,7 +125,7 @@ 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(); From 68c536c393988cb941652067e41fae143dbe3989 Mon Sep 17 00:00:00 2001 From: fredkingham Date: Fri, 3 Mar 2023 17:20:12 +0000 Subject: [PATCH 4/6] Changes the search.searching flag js to not reset In search.js we set a searching flag after they start searching. Once the results have come back, if the search parameter has not been changed then do no reenable the form. --- opal/core/search/static/js/search/controllers/search.js | 2 -- opal/core/search/static/js/test/search.controller.test.js | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/opal/core/search/static/js/search/controllers/search.js b/opal/core/search/static/js/search/controllers/search.js index 3afe5c351..94a45ac45 100644 --- a/opal/core/search/static/js/search/controllers/search.js +++ b/opal/core/search/static/js/search/controllers/search.js @@ -56,8 +56,6 @@ angular.module('opal.controllers').controller( $scope.searching = true; queryBackend(queryParams).then( function(response){ - $scope.searching = false; - ngProgressLite.done(); $scope.searched = true; $scope.paginator = new Paginator($scope.search, response.data); diff --git a/opal/core/search/static/js/test/search.controller.test.js b/opal/core/search/static/js/test/search.controller.test.js index 2853319ed..53a51f6df 100644 --- a/opal/core/search/static/js/test/search.controller.test.js +++ b/opal/core/search/static/js/test/search.controller.test.js @@ -148,7 +148,7 @@ describe('SearchCtrl', function (){ $scope.loadResults(); expect($scope.searching).toBe(true); $httpBackend.flush(); - expect($scope.searching).toBe(false); + expect($scope.searching).toBe(true); }); it('loadResults() should set and reset the searching variable if the server errors', function(){ From 2308719a2dee0f3002ced305a81cb89aa0bf3970 Mon Sep 17 00:00:00 2001 From: David Miller Date: Thu, 18 May 2023 12:26:54 +0100 Subject: [PATCH 5/6] Fixup: explain the change more accurately --- changelog.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index 57b23cdc8..3f78627ff 100644 --- a/changelog.md +++ b/changelog.md @@ -2,7 +2,8 @@ #### Disable search button while searching -While waiting for search results the search button and form are now disabled. +While waiting for search results the search button and form are now disabled unless +the user has changed the search string. ### 0.23.0 (Major Release) From 714cb811d5e5dcf564a6310dbce66ed22c6acf1d Mon Sep 17 00:00:00 2001 From: fredkingham Date: Thu, 18 May 2023 15:03:22 +0100 Subject: [PATCH 6/6] Adds a comment to search.html Adds in a comment to explain what the searching variable does in the ng-change of the search input. --- opal/core/search/templates/search.html | 1 + 1 file changed, 1 insertion(+) diff --git a/opal/core/search/templates/search.html b/opal/core/search/templates/search.html index 66989d197..2cdf93e22 100644 --- a/opal/core/search/templates/search.html +++ b/opal/core/search/templates/search.html @@ -18,6 +18,7 @@

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"