#1: IT'S ALIVE!

This commit is contained in:
Peter Deltchev 2016-01-16 19:22:04 -08:00
parent 6b5d3f67a3
commit 8960d11869
4 changed files with 30 additions and 22 deletions

View file

@ -1,7 +1,7 @@
<div class="search" ng-blur="searchInProgress = false"> <div class="search" ng-blur="searchInProgress = false">
<input class="search-input" type="text" placeholder="Search&hellip;" ng-model="searchQuery" ng-keyup="quickSearch()" pfm-popup="search-results" /> <input class="search-input" type="text" placeholder="Search&hellip;" ng-model="searchQuery" pfm-popup="search-results" />
<div class="search-results pfm-popup" id="search-results" ng-show="searchInProgress"> <div class="search-results pfm-popup" id="search-results">
<h3 class="-section-header">Matching tracks</h3> <h3 class="-section-header">Matching tracks</h3>
<pfm-tracks-list tracks="tracks"></pfm-tracks-list> <pfm-tracks-list tracks="tracks"></pfm-tracks-list>

View file

@ -29,10 +29,11 @@ angular.module('ponyfm').directive 'pfmPopup', () ->
open = false open = false
documentClickHandler = () -> documentClickHandler = (event) ->
return if !open return if !open
$popup.removeClass 'open' $popup.removeClass 'open'
open = false open = false
return true
calculatePosition = -> calculatePosition = ->
$popup.parents().each () -> $popup.parents().each () ->
@ -79,7 +80,7 @@ angular.module('ponyfm').directive 'pfmPopup', () ->
e.preventDefault() e.preventDefault()
e.stopPropagation() e.stopPropagation()
if open if open and not $element.is(':focus')
open = false open = false
$popup.removeClass 'open' $popup.removeClass 'open'
return return

View file

@ -24,7 +24,7 @@ angular.module('ponyfm').directive 'pfmSearch', () ->
controller: [ controller: [
'$scope', 'search' '$scope', 'search'
($scope, search) -> ($scope, search) ->
$scope.searchQuery = null $scope.searchQuery = ''
$scope.searchInProgress = false $scope.searchInProgress = false
$scope.tracks = [] $scope.tracks = []
@ -33,27 +33,31 @@ angular.module('ponyfm').directive 'pfmSearch', () ->
$scope.users = [] $scope.users = []
clearResults = ()-> clearResults = ()->
$scope.tracks = [] $scope.tracks.length = 0
$scope.albums = [] $scope.albums.length = 0
$scope.playlists = [] $scope.playlists.length = 0
$scope.users = [] $scope.users.length = 0
$scope.quickSearch = ()->
clearResults()
$scope.searchInProgress = true
search.searchAllContent($scope.searchQuery) $scope.$watch 'searchQuery', _.debounce((searchQuery)->
.done (results)-> $scope.$apply ()->
for track in results.tracks clearResults()
$scope.tracks.push(track) return if searchQuery.length <3
for album in results.albums $scope.searchInProgress = true
$scope.albums.push(album)
for playlist in results.playlists search.searchAllContent(searchQuery)
$scope.playlists.push(playlist) .then (results)->
for track in results.tracks
$scope.tracks.push(track)
for user in results.users for album in results.albums
$scope.users.push(user) $scope.albums.push(album)
for playlist in results.playlists
$scope.playlists.push(playlist)
for user in results.users
$scope.users.push(user)
, 500)
] ]

View file

@ -26,6 +26,9 @@ angular.module('ponyfm').factory('search', [
.success (results)-> .success (results)->
searchDef.resolve(results.results) searchDef.resolve(results.results)
.error (response)->
searchDef.reject(response)
searchDef.promise() searchDef.promise()
self self