Skip to content
This repository has been archived by the owner on Jul 14, 2021. It is now read-only.

Commit

Permalink
Remove whitespace & refactor search
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Closner committed Apr 10, 2014
1 parent 39d6211 commit cb43940
Show file tree
Hide file tree
Showing 24 changed files with 405 additions and 253 deletions.
6 changes: 3 additions & 3 deletions platforms/ios/CordovaLib/cordova.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
Expand Down Expand Up @@ -1629,4 +1629,4 @@ window.cordova = require('cordova');

require('cordova/init');

})();
})();
6 changes: 3 additions & 3 deletions platforms/ios/platform_www/cordova.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
Expand Down Expand Up @@ -1629,4 +1629,4 @@ window.cordova = require('cordova');

require('cordova/init');

})();
})();
6 changes: 3 additions & 3 deletions platforms/ios/www/cordova.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
Expand Down Expand Up @@ -1629,4 +1629,4 @@ window.cordova = require('cordova');

require('cordova/init');

})();
})();
27 changes: 17 additions & 10 deletions platforms/ios/www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ <h4 class="notification-headline">Notification Headlines Can Be Quite Long</h4>
<div class="trail-data">
<div class="trail-attributes">
<h3 class="trail-title">{{ selectedTrail.get('name') }}</h3>
<h5 class="trail-attribute-distance">{{ distance(selectedTrailHead).toFixed(2) }} mi away</h5>
<h5 class="trail-attribute-distance">
<distance-from-trailhead trailhead="selectedTrailHead" position="geoposition"/>
</h5>
<h5 class="trail-attribute-length">{{ selectedTrail.getLength().toFixed(2) }} mi long</h5>
<div class="trail-attribute-icons">
<div class="attribute-icon-box">
Expand Down Expand Up @@ -155,7 +157,9 @@ <h5 class="trail-attribute-length">{{ selectedTrail.getLength().toFixed(2) }} mi
</div>
<div class="trailhead-attributes">
<div class="trailhead-location-attributes">
<p class="trailhead-distance">{{ distance(selectedTrailHead).toFixed(2) }} mi away</p>
<p class="trailhead-distance">
<distance-from-trailhead trailhead="selectedTrailHead" position="geoposition"/>
</p>
<a class="trailhead-address" href="">{{ selectedTrailHead.get('address') }}</a>
</div>
<div class="amenities">
Expand All @@ -180,33 +184,35 @@ <h5 class="trail-attribute-length">{{ selectedTrail.getLength().toFixed(2) }} mi
<div class="search-input-container">
<span class="search-input-icon">&nbsp;</span>
<input class="search-input" type="search" ng-model="searchKeywords" value="{{searchKeywords}}" placeholder="Search">
<a href="#" ng-click="searchKeywords = ''">Clear</a>
<a href="#" ng-click="clearSearch()">Clear</a>
</div>
</form>
</div>


<div id="content">

<div class="search-info" ng-if="searchKeywords.length > 0">
<span>Found {{ searchResults.length }} Results For '{{searchKeywords}}'</span>
<div class="search-info" ng-if="lastSearch.length > 0">
<span>Found {{ searchResults.length }} Results For '{{ lastSearch }}'</span>
</div>

<div class="search-info" ng-if="!searchKeywords || searchKeywords.length === 0">
<div class="search-info" ng-if="!lastSearch || lastSearch.length === 0">
<span>Found {{ searchResults.length }} Trails Near You</span>
</div>

<div class="search-results">
<div class="search-result" ng-repeat="result in searchResults">
<div class="search-result-header-outer">
<div class="search-result-header-inner">
<p class="name">{{ result.record.get('name') }}</p>
<p class="distance">{{ result.distance.toFixed(2) }} miles away</p>
<p class="name">{{ result.trailhead.get('name') }}</p>
<p class="distance">
<distance-from-trailhead trailhead="result.trailhead" position="geoposition"/>
</p>
</div>
</div>
<div class="search-subresults">
<a href="#" ng-click="selectTrailHead(result.record, subrecord)" ng-repeat="subrecord in result.subrecords">
<h3>{{ subrecord.get('name') }}</h3>
<a href="#" ng-click="selectTrailHead(result.trailhead, trail)" ng-repeat="trail in result.trails">
<h3>{{ trail.get('name') }}</h3>
</a>
</div>
</div>
Expand Down Expand Up @@ -254,6 +260,7 @@ <h3>{{ subrecord.get('name') }}</h3>
<script type="text/javascript" src="js/application/controllers.js"></script>
<script type="text/javascript" src="js/application/routes.js"></script>
<script type="text/javascript" src="js/application/services.js"></script>
<script type="text/javascript" src="js/application/directives.js"></script>
<script type="text/javascript" src="js/application.js"></script>

</body>
Expand Down
2 changes: 1 addition & 1 deletion platforms/ios/www/js/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
'trails.routes',
'trails.controllers',
'trails.services',
'trails.directives',
'angular-gestures'
]);

Expand All @@ -20,4 +21,3 @@
}, false);

})(angular, FastClick);

69 changes: 20 additions & 49 deletions platforms/ios/www/js/application/controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
'MapTrailLayer',
'MapTrailHeadMarker',
'MapMarkerClusterGroup',
'TrailSearch',

function ($scope, Map, Models, GeoPosition, GeoPositionMarker, MapTileLayer, MapTrailLayer, MapTrailHeadMarker, MapMarkerClusterGroup) {
function ($scope, Map, Models, GeoPosition, GeoPositionMarker, MapTileLayer, MapTrailLayer, MapTrailHeadMarker, MapMarkerClusterGroup, TrailSearch) {

//
// CONSTANTS
Expand All @@ -31,12 +32,12 @@

function toggleView (id) {
$scope.view === id ? showView(DEFAULT_VIEW) : showView(id);
}
}

$scope.toggleView = toggleView;

function showView (id) {
$scope.view = id;
$scope.view = id;
}

$scope.showView = showView;
Expand Down Expand Up @@ -70,6 +71,8 @@
onGeoPositionError
);

$scope.geoposition = GeoPosition;

function recenter () {
Map.setView( positionMarker.getPosition(), Map.DEFAULT_ZOOM );
}
Expand Down Expand Up @@ -110,52 +113,20 @@
$scope.searchResults = [];
$scope.searchKeywords = '';

function search (searchKeywords) {

var query = {
key: 'name',
evaluator: 'contains',
value: searchKeywords
}

var searchResults = Models.TrailHead.query.map(
function (record) {
var subrecords = record.trails.where(query).all();

if ( subrecords.length > 0 ) {

var dist;
if (record) {
dist = distance(record);
}

return {
record: record,
subrecords: subrecords,
distance: dist
};

}
}
);

$scope.searchResults = utils.compact(searchResults).sort(
function (a,b) {
return a.distance > b.distance;
}
);

function search (keywords) {
$scope.lastSearch = keywords;
$scope.searchResults = TrailSearch.perform({ keywords: keywords });
}

$scope.search = search;

$scope.$watch('searchKeywords', function (searchKeywords) {
if (searchKeywords) {
$scope.search(searchKeywords);
} else {
search('');
}
});
function clearSearch () {
$scope.lastSearch = null;
$scope.searchKeywords = null;
$scope.search();
}

$scope.clearSearch = clearSearch;

//
// TRAIL LAYERS LOGIC
Expand Down Expand Up @@ -197,7 +168,7 @@
marker.select();
if (marker.selected) {
$scope.$apply(function() {
$scope.selected = marker;
$scope.selected = marker;
});
}
}
Expand All @@ -214,13 +185,13 @@

function selectTrailLayer (layer) {
if (layer) {
layer.select();
layer.select();
}
}

function deselectTrailLayer (layer) {
if (layer) {
layer.deselect();
layer.deselect();
}
}

Expand Down Expand Up @@ -261,7 +232,7 @@

function selectTrail (t) {
if (!t || ng.isUndefined(t)) return false;
$scope.selectedTrail = t;
$scope.selectedTrail = t;
}

$scope.selectTrail = selectTrail;
Expand Down
Loading

0 comments on commit cb43940

Please sign in to comment.