From f0c4881bf4ccb5b3497332da7f1243910da64296 Mon Sep 17 00:00:00 2001 From: Tomasz Rondio Date: Mon, 4 Jun 2018 13:48:14 +0200 Subject: [PATCH] fix: SWP-1167 content lists --- .../WebPublisherContentListsController.js | 38 ++++++++++++++-- .../listArticles/list-articles-detail.html | 25 ++++++++--- client/styles/helperElements.scss | 4 ++ .../content-lists/content-list-manual.html | 44 ++++++++++++------- 4 files changed, 83 insertions(+), 28 deletions(-) diff --git a/client/controllers/WebPublisherContentListsController.js b/client/controllers/WebPublisherContentListsController.js index 9f17a78b..e477fa5c 100644 --- a/client/controllers/WebPublisherContentListsController.js +++ b/client/controllers/WebPublisherContentListsController.js @@ -355,7 +355,6 @@ export function WebPublisherContentListsController($scope, publisher, modal, $ti } else { $scope.newList.updatedItems.splice($scope.newList.updatedItems.indexOf(updatedItem), 1); } - console.log($scope.newList.updatedItems); this._markDuplicates($scope.newList.items); this.listChangeFlag = true; }; @@ -366,7 +365,7 @@ export function WebPublisherContentListsController($scope, publisher, modal, $ti * @param {Object} list - list of article items * @param {Array} item - dropped items * @param {Int} index - index of list where items were dropped - * @returns {Boolean} + * @returns {Object} * @description Handles drop event */ onDrop(list, item, index) { @@ -379,15 +378,43 @@ export function WebPublisherContentListsController($scope, publisher, modal, $ti let selectedItemId = item.content ? item.content.id : item.id; let itemAction = _.find(list.items, item => (item.id === selectedItemId && !item.content) || (item.content && item.content.id === selectedItemId)) ? 'move' : 'add'; - list.updatedItems.push({content_id: selectedItemId, action: itemAction}); + list.updatedItems.push({content_id: selectedItemId, action: itemAction, position: index}); + + if (itemAction === 'add') { + $timeout(() => { + this.updatePositions(list); + }, 500); + } + + return item; + }; + + /** + * @ngdoc method + * @name WebPublisherContentListsController#onMoved + * @param {Object} list - list object + * @param {Int} index - index of list where items were dropped + * @description Handles move event + */ + onMoved(list, index) { + list.items.splice(index, 1); + this.updatePositions(list); + }; + + /** + * @ngdoc method + * @name WebPublisherContentListsController#updatePositions + * @param {Object} list - list object + * @description updates position of articles in array of changes + */ + updatePositions(list) { for (let i = 0; i < list.updatedItems.length; i++) { let itemInList = _.find(list.items, {content: {id: list.updatedItems[i].content_id}}) || _.find(list.items, {id: list.updatedItems[i].content_id}); list.updatedItems[i].position = list.items.indexOf(itemInList); } - return item; }; /** @@ -441,6 +468,9 @@ export function WebPublisherContentListsController($scope, publisher, modal, $ti _queryArticles() { this.tenantArticles.loading = true; this.tenantArticles.params.limit = 20; + this.tenantArticles.params['sorting[updatedAt]'] = 'desc'; + this.tenantArticles.params.status = 'published'; + publisher.queryTenantArticles(this.tenantArticles.params).then((response) => { response._embedded._items.forEach(el => { el.type = 'tenant'; diff --git a/client/directives/listArticles/list-articles-detail.html b/client/directives/listArticles/list-articles-detail.html index 1a133c52..e0510bbc 100644 --- a/client/directives/listArticles/list-articles-detail.html +++ b/client/directives/listArticles/list-articles-detail.html @@ -9,16 +9,27 @@

The list is empty

@@ -171,7 +177,7 @@

The list is empty

Please update filter criteria to add articles to the list.

-