From 6b5d3f67a3ee2aaecfa16049c2358e615df63ca3 Mon Sep 17 00:00:00 2001 From: Peter Deltchev Date: Sat, 16 Jan 2016 01:10:07 -0800 Subject: [PATCH] #1: Beginning of the search front-end. --- app/Library/Search.php | 30 +++++++++- public/templates/directives/search.html | 19 ++++++ .../scripts/app/directives/search.coffee | 59 +++++++++++++++++++ .../assets/scripts/app/services/search.coffee | 32 ++++++++++ resources/assets/styles/app.less | 1 + resources/assets/styles/search.less | 58 ++++++++++++++++++ resources/views/shared/_app_layout.blade.php | 1 + 7 files changed, 197 insertions(+), 3 deletions(-) create mode 100644 public/templates/directives/search.html create mode 100644 resources/assets/scripts/app/directives/search.coffee create mode 100644 resources/assets/scripts/app/services/search.coffee create mode 100644 resources/assets/styles/search.less diff --git a/app/Library/Search.php b/app/Library/Search.php index d7259807..f28e5f9a 100644 --- a/app/Library/Search.php +++ b/app/Library/Search.php @@ -114,9 +114,9 @@ class Search { ] ]); - $tracks = $this->transformToEloquent(Track::class, $results['responses'][0]['hits']['hits']); - $albums = $this->transformToEloquent(Album::class, $results['responses'][1]['hits']['hits']); - $playlists = $this->transformToEloquent(Playlist::class, $results['responses'][2]['hits']['hits']); + $tracks = $this->transformTracks($results['responses'][0]['hits']['hits']); + $albums = $this->transformAlbums($results['responses'][1]['hits']['hits']); + $playlists = $this->transformPlaylists($results['responses'][2]['hits']['hits']); $users = $this->transformToEloquent(User::class, $results['responses'][3]['hits']['hits']); return [ @@ -127,6 +127,30 @@ class Search { ]; } + protected function transformTracks(array $searchHits) { + $tracks = $this->transformToEloquent(Track::class, $searchHits); + $tracks = $tracks->map(function (Track $track) { + return Track::mapPublicTrackSummary($track); + }); + return $tracks; + } + + protected function transformAlbums(array $searchHits) { + $albums = $this->transformToEloquent(Album::class, $searchHits); + $albums = $albums->map(function (Album $track) { + return Album::mapPublicAlbumSummary($track); + }); + return $albums; + } + + protected function transformPlaylists(array $searchHits) { + $playlists = $this->transformToEloquent(Playlist::class, $searchHits); + $playlists = $playlists->map(function (Playlist $track) { + return Playlist::mapPublicPlaylistSummary($track); + }); + return $playlists; + } + /** * Transforms the given Elasticsearch results into a collection of corresponding * Eloquent models. diff --git a/public/templates/directives/search.html b/public/templates/directives/search.html new file mode 100644 index 00000000..f86ce766 --- /dev/null +++ b/public/templates/directives/search.html @@ -0,0 +1,19 @@ + diff --git a/resources/assets/scripts/app/directives/search.coffee b/resources/assets/scripts/app/directives/search.coffee new file mode 100644 index 00000000..62ca04df --- /dev/null +++ b/resources/assets/scripts/app/directives/search.coffee @@ -0,0 +1,59 @@ +# Pony.fm - A community for pony fan music. +# Copyright (C) 2016 Peter Deltchev +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +angular.module('ponyfm').directive 'pfmSearch', () -> + restrict: 'E' + templateUrl: '/templates/directives/search.html' + scope: + resource: '=resource', + type: '@type' + + controller: [ + '$scope', 'search' + ($scope, search) -> + $scope.searchQuery = null + $scope.searchInProgress = false + + $scope.tracks = [] + $scope.albums = [] + $scope.playlists = [] + $scope.users = [] + + clearResults = ()-> + $scope.tracks = [] + $scope.albums = [] + $scope.playlists = [] + $scope.users = [] + + $scope.quickSearch = ()-> + clearResults() + $scope.searchInProgress = true + + search.searchAllContent($scope.searchQuery) + .done (results)-> + for track in results.tracks + $scope.tracks.push(track) + + for album in results.albums + $scope.albums.push(album) + + for playlist in results.playlists + $scope.playlists.push(playlist) + + for user in results.users + $scope.users.push(user) + + ] diff --git a/resources/assets/scripts/app/services/search.coffee b/resources/assets/scripts/app/services/search.coffee new file mode 100644 index 00000000..acc3fd37 --- /dev/null +++ b/resources/assets/scripts/app/services/search.coffee @@ -0,0 +1,32 @@ +# Pony.fm - A community for pony fan music. +# Copyright (C) 2016 Peter Deltchev +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +angular.module('ponyfm').factory('search', [ + '$http' + ($http) -> + + self = + searchAllContent: (query) -> + searchDef = new $.Deferred() + + $http.get('/api/web/search?query=' + encodeURIComponent(query)) + .success (results)-> + searchDef.resolve(results.results) + + searchDef.promise() + + self +]) diff --git a/resources/assets/styles/app.less b/resources/assets/styles/app.less index 73a7deae..33c7095c 100644 --- a/resources/assets/styles/app.less +++ b/resources/assets/styles/app.less @@ -32,3 +32,4 @@ @import 'content'; @import 'dashboard'; @import 'uploader'; +@import 'search'; diff --git a/resources/assets/styles/search.less b/resources/assets/styles/search.less new file mode 100644 index 00000000..612873ac --- /dev/null +++ b/resources/assets/styles/search.less @@ -0,0 +1,58 @@ +/** + * Pony.fm - A community for pony fan music. + * Copyright (C) 2016 Peter Deltchev + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +@import 'base/bootstrap/bootstrap'; +@import 'mixins'; +@import 'variables'; + + +.search-input { + +} + +.search-results { + position: absolute; + width: 500px; + padding: 10px; + + background: #fff; + + ol li { + list-style: disc; + } + + li a { + padding: 0; + padding-right: 0; + overflow: hidden; + color: @pfm-light-grey; + } + + .-section-header { + background: transparent; + color: @pfm-purple; + + padding-left: 0; + } + + .albums-listing, .playlists-listing { + li { + width: 100%; + } + } +} diff --git a/resources/views/shared/_app_layout.blade.php b/resources/views/shared/_app_layout.blade.php index 9970e97a..0ad04930 100644 --- a/resources/views/shared/_app_layout.blade.php +++ b/resources/views/shared/_app_layout.blade.php @@ -66,6 +66,7 @@