1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-02-19 13:54:25 +01:00

members & invoices lists: display 20 items by default + do not display 'load more' button if all items were initially loaded

This commit is contained in:
Sylvain 2016-05-31 17:01:26 +02:00
parent 65328451ac
commit fae013d973
5 changed files with 30 additions and 13 deletions

View File

@ -10,8 +10,8 @@ Application.Controllers.controller "InvoicesController", ["$scope", "$state", 'I
### PRIVATE STATIC CONSTANTS ###
# 10 invoices loaded each time we click on 'load more...'
INVOICES_PER_PAGE = 10
# number of invoices loaded each time we click on 'load more...'
INVOICES_PER_PAGE = 20
@ -371,6 +371,9 @@ Application.Controllers.controller "InvoicesController", ["$scope", "$state", 'I
# Kind of constructor: these actions will be realized first when the controller is loaded
##
initialize = ->
if (!invoices[0] || invoices[0].maxInvoices <= $scope.invoices.length)
$scope.noMoreResults = true
# retrieve settings from the DB through the API
$scope.invoice.legals.content = settings['invoice_legals']
$scope.invoice.text.content = settings['invoice_text']
@ -447,14 +450,14 @@ Application.Controllers.controller "InvoicesController", ["$scope", "$state", 'I
page: $scope.page
size: INVOICES_PER_PAGE
}, (invoices) ->
if (invoices.length < INVOICES_PER_PAGE)
$scope.noMoreResults = true
if concat
$scope.invoices = $scope.invoices.concat(invoices)
else
$scope.invoices = invoices
if (!invoices[0] || invoices[0].maxInvoices <= $scope.invoices.length)
$scope.noMoreResults = true
## !!! MUST BE CALLED AT THE END of the controller

View File

@ -112,8 +112,8 @@ Application.Controllers.controller "AdminMembersController", ["$scope", 'members
### PRIVATE STATIC CONSTANTS ###
# 10 users loaded each time we click on 'load more...'
USERS_PER_PAGE = 10
# number of users loaded each time we click on 'load more...'
USERS_PER_PAGE = 20
@ -208,6 +208,13 @@ Application.Controllers.controller "AdminMembersController", ["$scope", 'members
### PRIVATE SCOPE ###
##
# Kind of constructor: these actions will be realized first when the controller is loaded
##
initialize = ->
if (!membersPromise[0] || membersPromise[0].maxInvoices <= $scope.members.length)
$scope.member.noMore = true
##
# Iterate through the provided array and return the index of the requested admin
# @param admins {Array} full list of users with role 'admin'
@ -237,13 +244,14 @@ Application.Controllers.controller "AdminMembersController", ["$scope", 'members
##
memberSearch = (concat) ->
Member.list { query: { search: $scope.member.searchText, order_by: $scope.member.order, page: $scope.member.page, size: USERS_PER_PAGE } }, (members) ->
if (members.length < USERS_PER_PAGE)
$scope.member.noMore = true
if concat
$scope.members = $scope.members.concat(members)
else
$scope.members = members;
if (!members[0] || members[0].maxMembers <= $scope.members.length)
$scope.member.noMore = true
]

View File

@ -671,7 +671,7 @@ angular.module('application.router', ['ui.router']).
]
invoices: [ 'Invoice', (Invoice) ->
Invoice.list({
query: { number: '', customer: '', date: null, order_by: '-reference', page: 1, size: 10 }
query: { number: '', customer: '', date: null, order_by: '-reference', page: 1, size: 20 }
}).$promise
]
translations: [ 'Translations', (Translations) ->
@ -697,7 +697,7 @@ angular.module('application.router', ['ui.router']).
controller: 'AuthentificationController'
resolve:
membersPromise: ['Member', (Member)->
Member.list({ query: { search: '', order_by: 'id', page: 1, size: 10 } }).$promise
Member.list({ query: { search: '', order_by: 'id', page: 1, size: 20 } }).$promise
]
adminsPromise: ['Admin', (Admin)->
Admin.query().$promise

View File

@ -1,4 +1,7 @@
maxInvoices = @invoices.except(:offset, :limit, :order).count
json.array!(@invoices) do |invoice|
json.maxInvoices maxInvoices
json.extract! invoice, :id, :created_at, :reference, :invoiced_type, :user_id, :avoir_date
json.total (invoice.total / 100.00)
json.url invoice_url(invoice, format: :json)
@ -9,4 +12,4 @@ json.array!(@invoices) do |invoice|
json.stripe invoice.stp_invoice_id?
json.date invoice.is_a?(Avoir) ? invoice.avoir_date : invoice.created_at
json.prevent_refund invoice.prevent_refund?
end
end

View File

@ -1,4 +1,7 @@
maxMembers = @members.except(:offset, :limit, :order).count
json.array!(@members) do |member|
json.maxMembers maxMembers
json.id member.id
json.email member.email if current_user
json.profile do