Advertisement
Guest User

Untitled

a guest
Jul 24th, 2017
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. require 'will_paginate/array'
  2. module Documents
  3. class IndexPresenter < Documents::BasePresenter
  4. def initialize(controller, client, direction = :incoming)
  5. @controller = controller
  6. @client = client
  7. @direction = direction
  8. end
  9.  
  10. def title
  11. @title ||= outgoing? ? 'Nosūtītās vēstules' : 'Saņemtās vēstules'
  12. end
  13.  
  14. def date_title
  15. @date_title ||= outgoing? ? 'Nosūtīšanas datums' : 'Saņemšanas datums'
  16. end
  17.  
  18. def documents
  19. # @documents = Enumerator.new do |yielder|
  20. documents ||= outgoing? ? @client.documents.outgoing : @client.documents.incoming
  21. documents = documents.map do |document|
  22. Index::DocumentPresenter.new(@controller, @client, document) unless document.empty_block_correnction?
  23. end.compact
  24. # end
  25. documents = documents.paginate(per_page: 1, page: @controller.params[:page])
  26. end
  27.  
  28. def outgoing?
  29. @direction == :outgoing
  30. end
  31.  
  32. def incoming?
  33. @direction == :incoming
  34. end
  35. end
  36. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement