From 0dac1422231ac9006ff3397901f7a9a138e06385 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Muszy=C5=84ski?= Date: Thu, 10 Sep 2015 14:31:48 +0200 Subject: [PATCH] preload featured article list by providing an extra parameter in url --- .../Controller/PlaylistsController.php | 5 +++-- .../js/playlists/controllers/playlists.js | 18 ++++++++++++++++++ .../Resources/views/Playlists/index.html.twig | 6 ++++-- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/newscoop/src/Newscoop/NewscoopBundle/Controller/PlaylistsController.php b/newscoop/src/Newscoop/NewscoopBundle/Controller/PlaylistsController.php index f3ec7fba46..f7c40bbb28 100644 --- a/newscoop/src/Newscoop/NewscoopBundle/Controller/PlaylistsController.php +++ b/newscoop/src/Newscoop/NewscoopBundle/Controller/PlaylistsController.php @@ -22,12 +22,12 @@ class PlaylistsController extends Controller { /** * @Route("/admin/playlists/") - * @Route("/admin/playlists/{articleNumber}/{language}/editor-view/", + * @Route("/admin/playlists/{articleNumber}/{language}/editor-view/{listId}", * options={"expose"=true}, * name="newscoop_newscoop_playlists_editor" * ) */ - public function indexAction(Request $request, $articleNumber = null, $language = null) + public function indexAction(Request $request, $articleNumber = null, $language = null, $listId = null) { $preferencesService = $this->get('preferences'); $em = $this->get('em'); @@ -55,6 +55,7 @@ public function indexAction(Request $request, $articleNumber = null, $language = 'editorView' => $editorView, 'articleNumber' => $articleNumber, 'language' => $languageCode, + 'selectedListId' => $listId, )); } diff --git a/newscoop/src/Newscoop/NewscoopBundle/Resources/public/js/playlists/controllers/playlists.js b/newscoop/src/Newscoop/NewscoopBundle/Resources/public/js/playlists/controllers/playlists.js index 8cf8667cf9..77a4cb3a18 100644 --- a/newscoop/src/Newscoop/NewscoopBundle/Resources/public/js/playlists/controllers/playlists.js +++ b/newscoop/src/Newscoop/NewscoopBundle/Resources/public/js/playlists/controllers/playlists.js @@ -63,6 +63,24 @@ angular.module('playlistsApp').controller('PlaylistsController', [ } }); + // preload featured article list when selectedListId variable + // is given. + // selectedListId variable is set globally in twig template. Its value + // is filled with the data from the url parameter. + // Preloads all featured article lists when value of selectedListId is + // not found in existing lists, fetched from the server. + // When selectedListId is empty it will do nothing. + if (_.isEmpty($scope.playlists) && selectedListId) { + Playlist.getAll().$promise.then(function (data) { + $scope.playlists = data.items; + var selectedList = _.find(data.items, { 'id': parseInt(selectedListId) }); + if (selectedList !== undefined) { + $scope.playlist.selected = selectedList; + $scope.setPlaylistInfoOnChange(selectedList); + } + }); + } + // stops, starts counter $scope.isCounting = false; diff --git a/newscoop/src/Newscoop/NewscoopBundle/Resources/views/Playlists/index.html.twig b/newscoop/src/Newscoop/NewscoopBundle/Resources/views/Playlists/index.html.twig index ba675536f1..4a97809c54 100644 --- a/newscoop/src/Newscoop/NewscoopBundle/Resources/views/Playlists/index.html.twig +++ b/newscoop/src/Newscoop/NewscoopBundle/Resources/views/Playlists/index.html.twig @@ -330,8 +330,10 @@