Commit fcbe595c by muhammad-ammar Committed by muzaffaryousaf

Bookmarks List Pagination

TNL-2490
parent 4304c66c
<nav class="pagination pagination-full bottom" aria-label="Teams Pagination"> <nav class="pagination pagination-full bottom" aria-label="Pagination">
<div class="nav-item previous"><button class="nav-link previous-page-link"><i class="icon fa fa-angle-left" aria-hidden="true"></i> <span class="nav-label"><%= gettext("Previous") %></span></button></div> <div class="nav-item previous"><button class="nav-link previous-page-link"><i class="icon fa fa-angle-left" aria-hidden="true"></i> <span class="nav-label"><%= gettext("Previous") %></span></button></div>
<div class="nav-item page"> <div class="nav-item page">
<div class="pagination-form"> <div class="pagination-form">
......
...@@ -15,6 +15,7 @@ class PaginatedUIMixin(object): ...@@ -15,6 +15,7 @@ class PaginatedUIMixin(object):
PREVIOUS_PAGE_BUTTON_CSS = 'button.previous-page-link' PREVIOUS_PAGE_BUTTON_CSS = 'button.previous-page-link'
PAGINATION_HEADER_TEXT_CSS = 'div.search-tools' PAGINATION_HEADER_TEXT_CSS = 'div.search-tools'
CURRENT_PAGE_NUMBER_CSS = 'span.current-page' CURRENT_PAGE_NUMBER_CSS = 'span.current-page'
TOTAL_PAGES_CSS = 'span.total-pages'
def get_pagination_header_text(self): def get_pagination_header_text(self):
"""Return the text showing which items the user is currently viewing.""" """Return the text showing which items the user is currently viewing."""
...@@ -31,6 +32,11 @@ class PaginatedUIMixin(object): ...@@ -31,6 +32,11 @@ class PaginatedUIMixin(object):
"""Return the the current page number.""" """Return the the current page number."""
return int(self.q(css=self.CURRENT_PAGE_NUMBER_CSS).text[0]) return int(self.q(css=self.CURRENT_PAGE_NUMBER_CSS).text[0])
@property
def get_total_pages(self):
"""Returns the total page value"""
return int(self.q(css=self.TOTAL_PAGES_CSS).text[0])
def go_to_page(self, page_number): def go_to_page(self, page_number):
"""Go to the given page_number in the paginated list results.""" """Go to the given page_number in the paginated list results."""
self.q(css=self.PAGE_NUMBER_INPUT_CSS).results[0].send_keys(unicode(page_number), Keys.ENTER) self.q(css=self.PAGE_NUMBER_INPUT_CSS).results[0].send_keys(unicode(page_number), Keys.ENTER)
......
...@@ -3,9 +3,10 @@ Courseware Boomarks ...@@ -3,9 +3,10 @@ Courseware Boomarks
""" """
from bok_choy.promise import EmptyPromise from bok_choy.promise import EmptyPromise
from .course_page import CoursePage from .course_page import CoursePage
from ..common.paging import PaginatedUIMixin
class BookmarksPage(CoursePage): class BookmarksPage(CoursePage, PaginatedUIMixin):
""" """
Courseware Bookmarks Page. Courseware Bookmarks Page.
""" """
......
;(function (define) { ;(function (define) {
'use strict'; 'use strict';
define(['backbone', 'js/bookmarks/models/bookmark'], define(['backbone', 'common/js/components/collections/paging_collection', 'js/bookmarks/models/bookmark'],
function (Backbone, BookmarkModel) { function (Backbone, PagingCollection, BookmarkModel) {
return PagingCollection.extend({
initialize: function(options) {
PagingCollection.prototype.initialize.call(this);
return Backbone.Collection.extend({ this.url = options.url;
model: BookmarkModel, this.server_api.course_id = function () { return encodeURIComponent(options.course_id); };
this.server_api.fields = function () { return encodeURIComponent('display_name,path'); };
delete this.server_api.sort_order; // Sort order is not specified for the Bookmark API
},
url: function() { model: BookmarkModel,
return $(".courseware-bookmarks-button").data('bookmarksApiUrl');
},
parse: function(response) { url: function() {
return response.results; return this.url;
} }
}); });
}); });
})(define || RequireJS.define); })(define || RequireJS.define);
\ No newline at end of file
;(function (define, undefined) { ;(function (define, undefined) {
'use strict'; 'use strict';
define(['gettext', 'jquery', 'underscore', 'backbone', 'logger', 'moment'], define(['gettext', 'jquery', 'underscore', 'backbone', 'logger', 'moment',
function (gettext, $, _, Backbone, Logger, _moment) { 'common/js/components/views/paging_header', 'common/js/components/views/paging_footer'],
function (gettext, $, _, Backbone, Logger, _moment, PagingHeaderView, PagingFooterView) {
var moment = _moment || window.moment; var moment = _moment || window.moment;
...@@ -16,27 +17,31 @@ ...@@ -16,27 +17,31 @@
errorMessage: gettext('An error has occurred. Please try again.'), errorMessage: gettext('An error has occurred. Please try again.'),
loadingMessage: gettext('Loading'), loadingMessage: gettext('Loading'),
PAGE_SIZE: 500, defaultPage: 1,
events : { events : {
'click .bookmarks-results-list-item': 'visitBookmark' 'click .bookmarks-results-list-item': 'visitBookmark'
}, },
initialize: function (options) { initialize: function (options) {
this.template = _.template($('#bookmarks_list-tpl').text()); this.template = _.template($('#bookmarks-list-tpl').text());
this.loadingMessageView = options.loadingMessageView; this.loadingMessageView = options.loadingMessageView;
this.errorMessageView = options.errorMessageView; this.errorMessageView = options.errorMessageView;
this.courseId = $(this.el).data('courseId');
this.langCode = $(this.el).data('langCode'); this.langCode = $(this.el).data('langCode');
this.pagingHeaderView = new PagingHeaderView({collection: this.collection});
this.pagingFooterView = new PagingFooterView({collection: this.collection});
this.listenTo(this.collection, 'page_changed', this.render);
_.bindAll(this, 'render', 'humanFriendlyDate'); _.bindAll(this, 'render', 'humanFriendlyDate');
}, },
render: function () { render: function () {
var data = { var data = {
bookmarks: this.collection.models, bookmarksCollection: this.collection,
humanFriendlyDate: this.humanFriendlyDate humanFriendlyDate: this.humanFriendlyDate
}; };
this.$el.html(this.template(data)); this.$el.html(this.template(data));
this.pagingHeaderView.setElement(this.$('.paging-header')).render();
this.pagingFooterView.setElement(this.$('.paging-footer')).render();
this.delegateEvents(); this.delegateEvents();
return this; return this;
}, },
...@@ -48,10 +53,7 @@ ...@@ -48,10 +53,7 @@
this.showBookmarksContainer(); this.showBookmarksContainer();
this.showLoadingMessage(); this.showLoadingMessage();
this.collection.fetch({ this.collection.goTo(this.defaultPage).done(function () {
reset: true,
data: {course_id: this.courseId, page_size: this.PAGE_SIZE, fields: 'display_name,path'}
}).done(function () {
view.hideLoadingMessage(); view.hideLoadingMessage();
view.render(); view.render();
view.focusBookmarksElement(); view.focusBookmarksElement();
......
...@@ -16,11 +16,20 @@ ...@@ -16,11 +16,20 @@
}, },
initialize: function () { initialize: function () {
this.bookmarksListView = new BookmarksListView({ var bookmarksCollection = new BookmarksCollection(
collection: new BookmarksCollection(), {
loadingMessageView: new MessageView({el: $(this.loadingMessageElement)}), course_id: $('.courseware-results').data('courseId'),
errorMessageView: new MessageView({el: $(this.errorMessageElement)}) url: $(".courseware-bookmarks-button").data('bookmarksApiUrl')
}); }
);
bookmarksCollection.bootstrap();
this.bookmarksListView = new BookmarksListView(
{
collection: bookmarksCollection,
loadingMessageView: new MessageView({el: $(this.loadingMessageElement)}),
errorMessageView: new MessageView({el: $(this.errorMessageElement)})
}
);
}, },
toggleBookmarksListView: function () { toggleBookmarksListView: function () {
......
define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'js/common_helpers/template_helpers', define(['backbone', 'jquery', 'underscore', 'common/js/spec_helpers/ajax_helpers',
'js/bookmarks/views/bookmark_button' 'common/js/spec_helpers/template_helpers', 'js/bookmarks/views/bookmark_button'
], ],
function (Backbone, $, _, AjaxHelpers, TemplateHelpers, BookmarkButtonView) { function (Backbone, $, _, AjaxHelpers, TemplateHelpers, BookmarkButtonView) {
'use strict'; 'use strict';
......
...@@ -57,7 +57,7 @@ ...@@ -57,7 +57,7 @@
// Rules for Bookmarks Results // Rules for Bookmarks Results
.bookmarks-results-list { .bookmarks-results-list {
padding-top: $baseline; padding-top: ($baseline/2);
.bookmarks-results-list-item { .bookmarks-results-list-item {
@include padding(($baseline/4), $baseline, ($baseline/2), $baseline); @include padding(($baseline/4), $baseline, ($baseline/2), $baseline);
...@@ -181,3 +181,9 @@ i.bookmarked { ...@@ -181,3 +181,9 @@ i.bookmarked {
@include icon-style("\f097", $black); @include icon-style("\f097", $black);
@include hover-style($m-blue, $m-blue, "\f02e"); @include hover-style($m-blue, $m-blue, "\f02e");
} }
.paging-header {
.search-tools {
margin: 0;
}
}
\ No newline at end of file
<div id="my-bookmarks" class="sr-is-focusable" tabindex="-1"></div> <div id="my-bookmarks" class="sr-is-focusable" tabindex="-1"></div>
<h2 class="bookmarks-results-header"><%= gettext("My Bookmarks") %></h2> <h2 class="bookmarks-results-header"><%= gettext("My Bookmarks") %></h2>
<% if (bookmarks.length) { %> <% if (bookmarksCollection.length) { %>
<div class="paging-header"></div>
<div class='bookmarks-results-list'> <div class='bookmarks-results-list'>
<% _.each(bookmarks, function(bookmark, index) { %> <% bookmarksCollection.each(function(bookmark, index) { %>
<a class="bookmarks-results-list-item" href="<%= bookmark.blockUrl() %>" aria-labelledby="bookmark-link-<%= index %>" data-bookmark-id="<%= bookmark.get('id') %>" data-component-type="<%= bookmark.get('block_type') %>" data-usage-id="<%= bookmark.get('usage_id') %>" aria-describedby="bookmark-type-<%= index %> bookmark-date-<%= index %>"> <a class="bookmarks-results-list-item" href="<%= bookmark.blockUrl() %>" aria-labelledby="bookmark-link-<%= index %>" data-bookmark-id="<%= bookmark.get('id') %>" data-component-type="<%= bookmark.get('block_type') %>" data-usage-id="<%= bookmark.get('usage_id') %>" aria-describedby="bookmark-type-<%= index %> bookmark-date-<%= index %>">
<div class="list-item-content"> <div class="list-item-content">
<div class="list-item-left-section"> <div class="list-item-left-section">
...@@ -21,6 +23,8 @@ ...@@ -21,6 +23,8 @@
<% }); %> <% }); %>
</div> </div>
<div class="paging-footer"></div>
<% } else {%> <% } else {%>
<div class="bookmarks-empty" tabindex="0"> <div class="bookmarks-empty" tabindex="0">
......
...@@ -53,7 +53,7 @@ ${page_title_breadcrumbs(course_name())} ...@@ -53,7 +53,7 @@ ${page_title_breadcrumbs(course_name())}
% endfor % endfor
% endif % endif
% for template_name in ["bookmarks_list"]: % for template_name in ["bookmarks-list"]:
<script type="text/template" id="${template_name}-tpl"> <script type="text/template" id="${template_name}-tpl">
<%static:include path="bookmarks/${template_name}.underscore" /> <%static:include path="bookmarks/${template_name}.underscore" />
</script> </script>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment