Skip to content

Commit

Permalink
CS-5728 - Remove limitation from loaded playlist, load more on scroll…
Browse files Browse the repository at this point in the history
… when no limit
  • Loading branch information
takeit committed Mar 19, 2015
1 parent 59e37d1 commit ee78558
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ angular.module('playlistsApp').controller('FeaturedController', [
* @param {Object} scope Current scope
*/
$scope.updateParentLimit = function (scope) {
console.log($scope.$parent.playlistLimit, scope.limitForm);
$scope.$parent.playlistLimit = scope.limitForm.$valid;
}
}]);
Original file line number Diff line number Diff line change
Expand Up @@ -351,9 +351,12 @@ angular.module('playlistsApp').controller('PlaylistsController', [
// (right box), by default it's set to 2 because we start fetching new
// articles from page 2, since articles on page 1 are loaded
// by default when selecting playlist.
var page = 2,
isRunning = false,
isEmpty = false;
// set in scope so we can reset it when playlist will be saved
// and it can load more articles on scroll, without a need
// to refresh the page
$scope.page = 2;
$scope.isRunning = false;
$scope.isEmpty = false;

/**
* Sets playlist details to the current scope.
Expand All @@ -368,10 +371,40 @@ angular.module('playlistsApp').controller('PlaylistsController', [
$scope.playlistInfo = list;
$scope.playlist.selected.oldLimit = list.maxItems;
$scope.formData = {title: list.title}
page = 2;
isRunning = false;
$scope.page = 2;
$scope.isRunning = false;
};

/**
* Loads more playlist's articles on scroll
*/
$scope.loadArticlesOnScrollDown = function () {
if ($scope.playlist.selected) {
if ($scope.playlist.selected.maxItems === undefined ||
$scope.playlist.selected.maxItems === 0) {
if (!$scope.isEmpty && !$scope.isRunning) {
$scope.isRunning = true;
Playlist.getArticlesByListId($scope.playlist.selected, $scope.page).$promise
.then(function (response) {
if (response.length == 0) {
$scope.isEmpty = true;
} else {
$scope.page++;
$scope.isEmpty = false;
angular.forEach(response, function(value, key) {
if (value.number !== undefined) {
$scope.featuredArticles.push(value);
}
});
}

$scope.isRunning = false;
});
}
}
}
}

/**
* Adds new playlist. Sets default list name to current date.
*/
Expand Down Expand Up @@ -439,7 +472,7 @@ angular.module('playlistsApp').controller('PlaylistsController', [

okText = Translator.trans('OK', {}, 'messages');
cancelText = Translator.trans('Cancel', {}, 'messages');
if ($scope.playlist.selected.title !== $scope.formData.title) {
if ($scope.playlist.selected.title !== $scope.formData.title && $scope.playlist.selected.id !== undefined) {
title = Translator.trans('Info');
text = Translator.trans('articles.playlists.namechanged', {}, 'articles');
modal = modalFactory.confirmLight(title, text, okText, cancelText);
Expand Down Expand Up @@ -483,10 +516,13 @@ angular.module('playlistsApp').controller('PlaylistsController', [
$scope.processing = false;
Playlist.clearLogList();
flashMessage(Translator.trans('List saved'));
$scope.featuredArticles = Playlist.getArticlesByListId({id: Playlist.getListId()});
$scope.featuredArticles = Playlist.getArticlesByListId({id: Playlist.getListId(), maxItems: $scope.playlist.selected.maxItems});
$scope.playlist.selected.id = Playlist.getListId();
$scope.page = 2;
$scope.isRunning = false;
$scope.isEmpty = false;

if (response[0] !== undefined && response[0].object.articlesModificationTime !== undefined) {
if (response && response[0] !== undefined && response[0].object.articlesModificationTime !== undefined) {
$scope.playlist.selected.articlesModificationTime = response[0].object.articlesModificationTime;
}
}, function(response) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ angular.module('playlistsApp').factory('Playlist', [

var params = {id: playlist.id};

if (playlist.maxItems !== null && playlist.maxItems > 0) {
params.items_per_page = 9999;
}

if (page !== undefined) {
params.page = page;
}
Expand Down Expand Up @@ -334,7 +338,7 @@ angular.module('playlistsApp').factory('Playlist', [
};

if (playlist.maxItems !== undefined) {
formData.playlist.maxItems = playlist.maxItems;
formData.playlist.maxItems = playlist.maxItems == null ? 0 : playlist.maxItems;
}

$http({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@
<div class="context-list-results" >
<div style="display: block">
<form>
<div infinite-scroll="loadArticlesOnScrollDown()" infinite-scroll-container="'#context_list'" infinite-scroll-parent infinite-scroll-distance='2'>
<div id="placeholder-wrapper" {% if editorView == false %}ng-class="{'empty-placeholder': $parent.featuredArticles.length == 0}" {% endif %}>
<p>{{ 'Drag here to add to list'|trans }}</p>
<ul id="context_list" ng-sortable="sortableConfig">
Expand Down Expand Up @@ -269,6 +270,7 @@
</li>
</ul>
</div>
</div>
</form>
</div>
<!-- alert message start -->
Expand Down

0 comments on commit ee78558

Please sign in to comment.