From 7a7f4ee02a01a0cf904322183faab22f72017d05 Mon Sep 17 00:00:00 2001 From: Peter Deltchev Date: Sat, 16 Jan 2016 23:35:43 -0800 Subject: [PATCH] #1: Moved the artists list into its own directive + visual cleanup of search. --- .../Controllers/Api/Web/ArtistsController.php | 13 +-------- .../Controllers/Api/Web/SearchController.php | 4 +-- app/Library/Search.php | 18 ++++++++---- app/Models/User.php | 15 ++++++++++ public/templates/artists/list.html | 20 +------------ public/templates/directives/search.html | 4 +-- public/templates/directives/users-list.html | 19 ++++++++++++ .../scripts/app/directives/search.coffee | 2 +- .../scripts/app/directives/users-list.coffee | 29 +++++++++++++++++++ resources/assets/styles/content.less | 6 ++-- resources/assets/styles/search.less | 2 +- 11 files changed, 85 insertions(+), 47 deletions(-) create mode 100644 public/templates/directives/users-list.html create mode 100644 resources/assets/scripts/app/directives/users-list.coffee diff --git a/app/Http/Controllers/Api/Web/ArtistsController.php b/app/Http/Controllers/Api/Web/ArtistsController.php index 96e38554..5999432e 100644 --- a/app/Http/Controllers/Api/Web/ArtistsController.php +++ b/app/Http/Controllers/Api/Web/ArtistsController.php @@ -195,18 +195,7 @@ class ArtistsController extends ApiControllerBase $users = []; foreach ($query->get() as $user) { - $users[] = [ - 'id' => $user->id, - 'name' => $user->display_name, - 'slug' => $user->slug, - 'url' => $user->url, - 'is_archived' => $user->is_archived, - 'avatars' => [ - 'small' => $user->getAvatarUrl(Image::SMALL), - 'normal' => $user->getAvatarUrl(Image::NORMAL) - ], - 'created_at' => $user->created_at - ]; + $users[] = User::mapPublicUserSummary($user); } return Response::json(["artists" => $users, "current_page" => $page, "total_pages" => ceil($count / $perPage)], diff --git a/app/Http/Controllers/Api/Web/SearchController.php b/app/Http/Controllers/Api/Web/SearchController.php index 367e08a4..f2304bf0 100644 --- a/app/Http/Controllers/Api/Web/SearchController.php +++ b/app/Http/Controllers/Api/Web/SearchController.php @@ -30,9 +30,7 @@ class SearchController extends ApiControllerBase { public function getSearch(Search $search) { - $input = Input::all(); - - $results = $search->searchAllContent($input['query']); + $results = $search->searchAllContent(Input::query('query')); return Response::json([ 'results' => $results, diff --git a/app/Library/Search.php b/app/Library/Search.php index f28e5f9a..6e31a1ab 100644 --- a/app/Library/Search.php +++ b/app/Library/Search.php @@ -117,7 +117,7 @@ class Search { $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']); + $users = $this->transformUsers($results['responses'][3]['hits']['hits']); return [ 'tracks' => $tracks, @@ -137,20 +137,28 @@ class Search { protected function transformAlbums(array $searchHits) { $albums = $this->transformToEloquent(Album::class, $searchHits); - $albums = $albums->map(function (Album $track) { - return Album::mapPublicAlbumSummary($track); + $albums = $albums->map(function (Album $album) { + return Album::mapPublicAlbumSummary($album); }); return $albums; } protected function transformPlaylists(array $searchHits) { $playlists = $this->transformToEloquent(Playlist::class, $searchHits); - $playlists = $playlists->map(function (Playlist $track) { - return Playlist::mapPublicPlaylistSummary($track); + $playlists = $playlists->map(function (Playlist $playlist) { + return Playlist::mapPublicPlaylistSummary($playlist); }); return $playlists; } + protected function transformUsers(array $searchHits) { + $users = $this->transformToEloquent(User::class, $searchHits); + $users = $users->map(function (User $user) { + return User::mapPublicUserSummary($user); + }); + return $users; + } + /** * Transforms the given Elasticsearch results into a collection of corresponding * Eloquent models. diff --git a/app/Models/User.php b/app/Models/User.php index d2f77bfd..0a656b57 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -251,6 +251,21 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon return false; } + public static function mapPublicUserSummary(User $user) { + return [ + 'id' => $user->id, + 'name' => $user->display_name, + 'slug' => $user->slug, + 'url' => $user->url, + 'is_archived' => $user->is_archived, + 'avatars' => [ + 'small' => $user->getAvatarUrl(Image::SMALL), + 'normal' => $user->getAvatarUrl(Image::NORMAL) + ], + 'created_at' => $user->created_at + ]; + } + /** * Returns this model in Elasticsearch-friendly form. The array returned by * this method should match the current mapping for this model's ES type. diff --git a/public/templates/artists/list.html b/public/templates/artists/list.html index b18a502f..48635e61 100644 --- a/public/templates/artists/list.html +++ b/public/templates/artists/list.html @@ -1,21 +1,3 @@
- +
diff --git a/public/templates/directives/search.html b/public/templates/directives/search.html index ec044091..36e9a740 100644 --- a/public/templates/directives/search.html +++ b/public/templates/directives/search.html @@ -16,9 +16,7 @@

Matching users

-
    -
  1. -
+

Matching albums

diff --git a/public/templates/directives/users-list.html b/public/templates/directives/users-list.html new file mode 100644 index 00000000..7fac5a81 --- /dev/null +++ b/public/templates/directives/users-list.html @@ -0,0 +1,19 @@ + diff --git a/resources/assets/scripts/app/directives/search.coffee b/resources/assets/scripts/app/directives/search.coffee index ed0280fb..53d5abde 100644 --- a/resources/assets/scripts/app/directives/search.coffee +++ b/resources/assets/scripts/app/directives/search.coffee @@ -59,5 +59,5 @@ angular.module('ponyfm').directive 'pfmSearch', () -> for user in results.users $scope.users.push(user) - , 200) + , 300) ] diff --git a/resources/assets/scripts/app/directives/users-list.coffee b/resources/assets/scripts/app/directives/users-list.coffee new file mode 100644 index 00000000..82f6e8c0 --- /dev/null +++ b/resources/assets/scripts/app/directives/users-list.coffee @@ -0,0 +1,29 @@ +# 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 'pfmUsersList', () -> + restrict: 'E' + replace: true + templateUrl: '/templates/directives/users-list.html' + scope: + users: '=users', + class: '@class' + + controller: [ + '$scope', 'auth' + ($scope, auth) -> + $scope.auth = auth.data + ] diff --git a/resources/assets/styles/content.less b/resources/assets/styles/content.less index 7423f206..bc9cf0d9 100644 --- a/resources/assets/styles/content.less +++ b/resources/assets/styles/content.less @@ -22,7 +22,7 @@ @media (max-width: 1300px) and (min-width: 720px) { html { - .albums-listing, .playlists-listing, .artist-listing { + .albums-listing, .playlists-listing, .users-listing { &.two-columns li { width: auto; float: none; @@ -37,7 +37,7 @@ @media (max-width: 720px) { html { - .albums-listing, .playlists-listing, .artist-listing { + .albums-listing, .playlists-listing, .users-listing { &.two-columns li { width: auto; float: none; @@ -51,7 +51,7 @@ } } -.albums-listing, .playlists-listing, .artist-listing { +.albums-listing, .playlists-listing, .users-listing { margin: 0px; padding: 0px; list-style: none; diff --git a/resources/assets/styles/search.less b/resources/assets/styles/search.less index c980ab8f..b29d398a 100644 --- a/resources/assets/styles/search.less +++ b/resources/assets/styles/search.less @@ -66,7 +66,7 @@ input.search-input { padding-left: 0; } - .albums-listing, .playlists-listing { + .albums-listing, .playlists-listing, .users-listing { li { width: 100%; }