Skip to content

Commit 8a2691d

Browse files
committed
make homepage search work for chu&facilities
1 parent fbd00c5 commit 8a2691d

File tree

8 files changed

+82
-42
lines changed

8 files changed

+82
-42
lines changed

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2015 The Minisry of Health, Republic of Kenya
3+
Copyright (c) 2015 The Republic of Kenya, Ministry of Health
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

libs/typeahead.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,13 @@
2626
* @param tokenize_field
2727
* @param search_url
2828
* @param limit
29+
* @param recreate
2930
* @returns {*}
3031
*/
31-
this.initTT = function (name, tokenize_field, search_url, limit) {
32+
this.initTT = function (name, tokenize_field, search_url, limit, recreate) {
3233
var tt_adapter = tt[name];
3334
var tt_limit = limit || 10;
34-
if (_.isUndefined(tt_adapter)) {
35+
if (_.isUndefined(tt_adapter) || recreate) {
3536
tt_adapter = new Bloodhound({
3637
datumTokenizer: function (d) {
3738
return Bloodhound.tokenizers.whitespace(d[tokenize_field]);

src/app/home/controllers.js

+19-3
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,31 @@
2020
$scope.spinner = false;
2121
});
2222
$scope.isFocused = false;
23+
$scope.chu_mode = false;
24+
2325
$scope.typeaheadFacilities = function () {
26+
$scope.chu_mode = false;
27+
searchService.destroyTT("facilities");
28+
$scope.isFocused = !$scope.isFocused;
29+
_.debounce(searchService.typeaheadFacilities("facilities"), 300);
30+
};
31+
32+
$scope.typeaheadCHUs = function () {
33+
$scope.chu_mode = true;
34+
searchService.destroyTT("facilities");
2435
$scope.isFocused = !$scope.isFocused;
25-
_.debounce(searchService.typeaheadFacilities("facilities"),
26-
300);
36+
_.debounce(searchService.typeaheadCHUs("facilities"), 300);
2737
};
38+
2839
$scope.search = function (query) {
2940
$scope.loader = true;
30-
$state.go("facility_filter.results", {"search" : query});
41+
if ($scope.chu_mode) {
42+
$state.go("chul_filter.results", {"search" : query});
43+
} else {
44+
$state.go("facility_filter.results", {"search" : query});
45+
}
3146
};
47+
3248
}
3349
]);
3450

src/app/home/services.js

+21-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(function (angular) {
1+
(function (angular, jQuery) {
22

33
"use strict";
44

@@ -20,22 +20,32 @@
2020
.service("searchService",["SERVER_URL", "mfl.typeahead",
2121
function (SERVER_URL, typeahead) {
2222
var facilities_url = "api/facilities/facilities/?fields=name&search=%QUERY";
23-
var initFacilities = function () {
24-
return typeahead.initTT(
25-
"facilities",
26-
"name",
27-
SERVER_URL+facilities_url,
28-
15
23+
var chus_url = "api/chul/units/?fields=name&search=%QUERY";
24+
25+
var initTT = function (url_stub, fieldclass, recreate) {
26+
var f = typeahead.initTT(
27+
"facilities", "name", SERVER_URL+url_stub, 15, recreate
2928
);
30-
};
31-
this.typeaheadFacilities = function (fieldclass) {
32-
var f = initFacilities();
3329
var name = fieldclass || "facilities";
3430
typeahead.typeaheadUI(name, {
3531
displayKey: "name",
3632
source: f.ttAdapter()
3733
});
3834
};
35+
36+
this.destroyTT = function (fieldclass) {
37+
// yeah...this is criminal
38+
return jQuery(fieldclass).typeahead("destroy");
39+
};
40+
41+
this.typeaheadFacilities = function (fieldclass) {
42+
initTT(facilities_url, fieldclass, true);
43+
};
44+
45+
this.typeaheadCHUs = function (fieldclass) {
46+
initTT(chus_url, fieldclass, true);
47+
};
3948
}
4049
]);
41-
})(window.angular);
50+
51+
})(window.angular, window.jQuery);

src/app/home/tests/controllers.spec.js

+28-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
expect(scope.spinner).toBe(false);
4949
});
5050

51-
it("should search facilites on `mfl.home.controllers.home`", function(){
51+
it("should launch facility search", function(){
5252
var scope = rootScope.$new();
5353
spyOn(state, "go");
5454
controller("mfl.home.controllers.home", {
@@ -57,9 +57,25 @@
5757
});
5858
scope.search("testing");
5959
expect(scope.loader).toBeTruthy();
60+
expect(state.go.calls[0].args[0]).toEqual("facility_filter.results");
61+
expect(state.go.calls[0].args[1]).toEqual({"search": "testing"});
6062
});
6163

62-
it("should test auto-complete on `mfl.home.controllers.home`", function(){
64+
it("should launch CHU search", function(){
65+
var scope = rootScope.$new();
66+
spyOn(state, "go");
67+
controller("mfl.home.controllers.home", {
68+
"$scope": scope,
69+
"$state": state
70+
});
71+
scope.chu_mode = true;
72+
scope.search("testing");
73+
expect(scope.loader).toBeTruthy();
74+
expect(state.go.calls[0].args[0]).toEqual("chul_filter.results");
75+
expect(state.go.calls[0].args[1]).toEqual({"search": "testing"});
76+
});
77+
78+
it("should test facility typeahead", function(){
6379
var scope = rootScope.$new();
6480
spyOn(_, "debounce");
6581
controller("mfl.home.controllers.home", {
@@ -68,6 +84,16 @@
6884
scope.typeaheadFacilities();
6985
expect(_.debounce).toHaveBeenCalled();
7086
});
87+
88+
it("should test chu typeahead", function(){
89+
var scope = rootScope.$new();
90+
spyOn(_, "debounce");
91+
controller("mfl.home.controllers.home", {
92+
"$scope": scope
93+
});
94+
scope.typeaheadCHUs();
95+
expect(_.debounce).toHaveBeenCalled();
96+
});
7197
});
7298

7399
})(window._);

src/app/home/tpls/main.tpl.html

+7-20
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,20 @@
11
<div class="container-fluid landing-img main-view">
2-
<div class="container-fluid bg-overlay">
2+
<div class="container-fluid">
33
<div class="row margin-h-5">
4-
<div class="col-lg-12 margin-b-20">
5-
<h2 class="welcome-text text-center hidden-sm hidden-xs">
6-
Welcome to the Kenya Health Master Facility List
7-
</h2>
8-
<h3 class="welcome-text text-center hidden-lg hidden-md" style="color: #fff;">
9-
Welcome to the Kenya Health Master Facility List
10-
</h3>
11-
</div>
124
<div class="col-lg-8 col-lg-offset-2 search-card text-center margin-t-20" style="border: 1px solid #FFF;">
135
<form role="form" name="search-form" ng-submit="search(search.query)">
146
<div class="col-md-12 input-group">
157
<div class="search-addon-btn input-group-btn">
16-
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
17-
Facilities <i class="fa fa-caret-down"></i>
18-
</button>
8+
<a class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
9+
{{chu_mode ? 'Community Health Units': 'Facilities'}} <i class="fa fa-caret-down"></i>
10+
</a>
1911
<div class="dropdown-menu">
20-
<a class="dropdown-item fw-500" href="#">Facilities</a>
12+
<a class="dropdown-item fw-500" ng-click="typeaheadFacilities()">Facilities</a>
2113
<div role="separator" class="dropdown-divider"></div>
22-
<a class="dropdown-item fw-500" href="#">Community Units</a>
14+
<a class="dropdown-item fw-500" ng-click="typeaheadCHUs()">Community Units</a>
2315
</div>
2416
</div>
25-
<input type="search" class="facilities" ng-model="search.query" placeholder="Search facilities..." ng-focus="typeaheadFacilities()" sync-focus-with="isFocused" autofocus />
26-
<span class="highlight"></span>
27-
<span class="bar"></span>
17+
<input type="search" class="facilities" ng-model="search.query" placeholder="Search by name or code..." sync-focus-with="isFocused" autofocus />
2818
<span class="search-addon-btn input-group-addon" id="sizing-addon1" ng-click="search(search.query)">
2919
<button type="submit" class="search-btn">
3020
<i class="fa fa-search"></i>
@@ -43,9 +33,6 @@ <h3 class="fw-500 text-black" >
4333
<span class="pull-left margin-t-10 col-md-6 col-xs-12">
4434
About the Master Facility List (MFL)
4535
</span>
46-
<span class="content-right col-md-6 col-xs-12">
47-
<img src="assets/img/ehealth_logo.gif" >
48-
</span>
4936
</h3>
5037
<br>
5138
<hr class="margin-t-20 margin-b-0" style="border: 1px solid #F0F0F0;">

src/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ <h5 class="fs-16 fw-600 text-white">
156156
<p class="text-left margin-t-20">
157157
&copy; Copyright 2015,
158158
<a href="http://health.go.ke/" target="_blank">
159-
Ministry of Health, Republic of Kenya
159+
Republic of Kenya, Ministry of Health
160160
</a>
161161
.Powered by
162162
<a href="http://savannahinformatics.com/" target="_blank">

src/less/normal_inputs.less

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
}
66
input[type=search]{
77
font-size:14px;
8-
padding:10px 10px 10px 5px;
8+
padding:10px 10px 10px 10px;
99
background-color: #fff;
1010
display:block;
1111
width:90%;
@@ -118,7 +118,7 @@ input:-moz-ui-invalid {
118118

119119
input[type=search] {
120120
font-size: 18px;
121-
padding: 10px 10px 10px 5px;
121+
padding: 10px 10px 10px 10px;
122122
background-color: #fff;
123123
display: block;
124124
width: 100%;

0 commit comments

Comments
 (0)