enju_biblio 0.0.9 → 0.1.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) hide show
  1. data/app/controllers/accepts_controller.rb +83 -0
  2. data/app/controllers/items_controller.rb +2 -2
  3. data/app/controllers/manifestations_controller.rb +8 -8
  4. data/app/controllers/patrons_controller.rb +18 -4
  5. data/app/controllers/series_has_manifestations_controller.rb +1 -1
  6. data/app/controllers/series_statements_controller.rb +2 -5
  7. data/app/models/accept.rb +36 -0
  8. data/app/models/create.rb +0 -4
  9. data/app/models/donate.rb +0 -4
  10. data/app/models/exemplify.rb +0 -4
  11. data/app/models/import_request.rb +0 -4
  12. data/app/models/item.rb +2 -4
  13. data/app/models/manifestation.rb +5 -8
  14. data/app/models/own.rb +0 -3
  15. data/app/models/patron.rb +2 -4
  16. data/app/models/picture_file.rb +0 -4
  17. data/app/models/produce.rb +0 -4
  18. data/app/models/realize.rb +0 -4
  19. data/app/models/series_has_manifestation.rb +1 -3
  20. data/app/models/series_statement.rb +2 -4
  21. data/app/views/accepts/_form.html.erb +11 -0
  22. data/app/views/accepts/_list.html.erb +31 -0
  23. data/app/views/accepts/edit.html.erb +13 -0
  24. data/app/views/accepts/index.csv.erb +4 -0
  25. data/app/views/accepts/index.html.erb +49 -0
  26. data/app/views/accepts/index.js.erb +1 -0
  27. data/app/views/accepts/new.html.erb +14 -0
  28. data/app/views/accepts/show.html.erb +31 -0
  29. data/app/views/countries/index.html.erb +1 -1
  30. data/app/views/creates/_index.html.erb +1 -1
  31. data/app/views/creates/_index_patron.html.erb +1 -1
  32. data/app/views/creates/_index_work.html.erb +1 -1
  33. data/app/views/donates/index.html.erb +1 -1
  34. data/app/views/exemplifies/index.html.erb +1 -1
  35. data/app/views/extents/index.html.erb +1 -1
  36. data/app/views/import_requests/index.html.erb +1 -1
  37. data/app/views/items/index.html.erb +1 -1
  38. data/app/views/items/index.mobile.erb +1 -1
  39. data/app/views/languages/index.html.erb +1 -1
  40. data/app/views/licenses/index.html.erb +1 -1
  41. data/app/views/manifestations/_list.html.erb +2 -2
  42. data/app/views/manifestations/_manifestation.html.erb +1 -1
  43. data/app/views/manifestations/_question_list.html.erb +2 -2
  44. data/app/views/manifestations/_tab_list.html.erb +1 -1
  45. data/app/views/manifestations/index.html.erb +2 -2
  46. data/app/views/manifestations/index.mobile.erb +1 -1
  47. data/app/views/medium_of_performances/index.html.erb +1 -1
  48. data/app/views/owns/index.html.erb +1 -1
  49. data/app/views/patron_import_files/index.html.erb +1 -1
  50. data/app/views/patron_import_results/index.html.erb +1 -1
  51. data/app/views/patrons/_expression_list.html.erb +2 -2
  52. data/app/views/patrons/_index.html.erb +1 -1
  53. data/app/views/patrons/_index_expression.html.erb +1 -1
  54. data/app/views/patrons/_index_manifestation.html.erb +1 -1
  55. data/app/views/patrons/_index_patron.html.erb +1 -1
  56. data/app/views/patrons/_index_patron_merge_list.html.erb +1 -1
  57. data/app/views/patrons/_index_work.html.erb +1 -1
  58. data/app/views/patrons/_manifestation_list.html.erb +2 -2
  59. data/app/views/patrons/_work_list.html.erb +2 -2
  60. data/app/views/patrons/index.mobile.erb +1 -1
  61. data/app/views/picture_files/_index.html.erb +1 -1
  62. data/app/views/picture_files/_index_event.html.erb +1 -1
  63. data/app/views/picture_files/_index_manifestation.html.erb +1 -1
  64. data/app/views/picture_files/_index_patron.html.erb +1 -1
  65. data/app/views/picture_files/_index_shelf.html.erb +1 -1
  66. data/app/views/produces/_index.html.erb +1 -1
  67. data/app/views/produces/_index_manifestation.html.erb +1 -1
  68. data/app/views/produces/_index_patron.html.erb +1 -1
  69. data/app/views/realizes/_index.html.erb +1 -1
  70. data/app/views/realizes/_index_expression.html.erb +1 -1
  71. data/app/views/realizes/_index_patron.html.erb +1 -1
  72. data/app/views/resource_import_files/index.html.erb +1 -1
  73. data/app/views/resource_import_results/index.html.erb +1 -1
  74. data/app/views/series_has_manifestations/index.html.erb +1 -1
  75. data/app/views/series_statements/_index.html.erb +1 -1
  76. data/app/views/series_statements/_index_manifestation.html.erb +1 -1
  77. data/app/views/series_statements/_index_series_statement_merge_list.html.erb +1 -1
  78. data/app/views/series_statements/_manifestation_list.html.erb +2 -2
  79. data/{spec/dummy/db → db}/migrate/120_create_baskets.rb +0 -0
  80. data/{spec/dummy/db → db}/migrate/20120319173203_create_accepts.rb +0 -0
  81. data/lib/enju_biblio.rb +4 -0
  82. data/lib/enju_biblio/engine.rb +0 -3
  83. data/lib/enju_biblio/version.rb +1 -1
  84. data/lib/generators/enju_biblio/views_generator.rb +51 -0
  85. data/spec/controllers/accepts_controller_spec.rb +304 -0
  86. data/spec/dummy/app/models/ability.rb +2 -0
  87. data/spec/dummy/config/application.rb +9 -1
  88. data/spec/dummy/config/initializers/kaminari_config.rb +9 -0
  89. data/spec/dummy/db/test.sqlite3 +0 -0
  90. data/spec/dummy/lib/plugins/ext.rb +0 -2
  91. data/spec/dummy/tmp/cache/4F7/F90/default_role +0 -0
  92. data/spec/dummy/tmp/cache/6E4/420/search_engine_all +0 -0
  93. data/spec/factories/accepts.rb +9 -0
  94. data/spec/factories/basket.rb +5 -0
  95. data/spec/models/accept_spec.rb +22 -0
  96. data/spec/requests/accepts_spec.rb +11 -0
  97. data/spec/routing/accepts_routing_spec.rb +27 -0
  98. data/spec/views/accepts/edit.html.erb_spec.rb +18 -0
  99. data/spec/views/accepts/index.html.erb_spec.rb +25 -0
  100. data/spec/views/accepts/new.html.erb_spec.rb +29 -0
  101. data/spec/views/accepts/show.html.erb_spec.rb +17 -0
  102. data/spec/views/creates/index.html.erb_spec.rb +2 -2
  103. data/spec/views/exemplifies/index.html.erb_spec.rb +2 -2
  104. data/spec/views/owns/index.html.erb_spec.rb +2 -2
  105. data/spec/views/produces/index.html.erb_spec.rb +2 -2
  106. data/spec/views/realizes/index.html.erb_spec.rb +2 -2
  107. data/spec/views/series_has_manifestations/index.html.erb_spec.rb +2 -2
  108. metadata +50 -42
  109. data/app/views/resource_import_files/_show_object_list.html.erb +0 -26
  110. data/spec/dummy/lib/enju_leaf.rb +0 -9
  111. data/spec/dummy/lib/enju_leaf/calculate_stat.rb +0 -30
  112. data/spec/dummy/lib/plugins/ext/will_paginate.rb +0 -64
@@ -0,0 +1,83 @@
1
+ class AcceptsController < InheritedResources::Base
2
+ load_and_authorize_resource :except => :index
3
+ authorize_resource :only => :index
4
+ respond_to :html, :json
5
+ before_filter :get_basket, :only => [:index, :create]
6
+
7
+ # GET /accepts
8
+ # GET /accepts.json
9
+ def index
10
+ if params[:format] == 'csv'
11
+ @accepts = Accept.order('accepts.created_at DESC').page(params[:page]).per(65534)
12
+ else
13
+ if params[:accept]
14
+ @query = params[:accept][:item_identifier].to_s.strip
15
+ item = Item.where(:item_identifier => @query).first if @query.present?
16
+ end
17
+
18
+ if item
19
+ @accepts = Accept.order('accepts.created_at DESC').where(:item_id => item.id).page(params[:page])
20
+ else
21
+ if @basket
22
+ @accepts = @basket.accepts.page(params[:page])
23
+ else
24
+ @accepts = Accept.page(params[:page])
25
+ end
26
+ end
27
+ end
28
+
29
+ respond_to do |format|
30
+ format.html # index.html.erb
31
+ format.json { render :json => @accepts }
32
+ format.js { @accept = Accept.new }
33
+ format.csv
34
+ end
35
+ end
36
+
37
+ # GET /new
38
+ # GET /new.json
39
+ def new
40
+ @basket = Basket.new
41
+ @basket.user = current_user
42
+ @basket.save!
43
+ @accept = Accept.new
44
+ @accepts = []
45
+
46
+ respond_to do |format|
47
+ format.html # new.html.erb
48
+ format.json { render :json => @patron }
49
+ end
50
+ end
51
+
52
+ # POST /accepts
53
+ # POST /accepts.json
54
+ def create
55
+ unless @basket
56
+ access_denied; return
57
+ end
58
+ @accept.basket = @basket
59
+ @accept.librarian = current_user
60
+
61
+ flash[:message] = ''
62
+ if @accept.item_identifier.blank?
63
+ flash[:message] << t('accept.enter_item_identifier') if @accept.item_identifier.blank?
64
+ else
65
+ item = Item.where(:item_identifier => @accept.item_identifier.to_s.strip).first
66
+ end
67
+ @accept.item = item
68
+
69
+ respond_to do |format|
70
+ if @accept.save
71
+ flash[:message] << t('accept.successfully_accepted', :model => t('activerecord.models.accept'))
72
+ format.html { redirect_to basket_accepts_url(@basket) }
73
+ format.json { render :json => @accept, :status => :created, :location => @accept }
74
+ format.js { redirect_to basket_accepts_url(@basket, :format => :js) }
75
+ else
76
+ @accepts = @basket.accepts.page(params[:page])
77
+ format.html { render :action => "index" }
78
+ format.json { render :json => @accept.errors, :status => :unprocessable_entity }
79
+ format.js { render :action => "index" }
80
+ end
81
+ end
82
+ end
83
+ end
@@ -17,7 +17,7 @@ class ItemsController < ApplicationController
17
17
  # GET /items.json
18
18
  def index
19
19
  query = params[:query].to_s.strip
20
- per_page = Item.per_page
20
+ per_page = Item.default_per_page
21
21
  @count = {}
22
22
  if user_signed_in?
23
23
  if current_user.has_role?('Librarian')
@@ -40,7 +40,7 @@ class ItemsController < ApplicationController
40
40
  mode = 'not_on_shelf'
41
41
  end
42
42
  order = 'items.id'
43
- @items = Item.inventory_items(@inventory_file, mode).order(order).page(params[:page]).per_page(per_page)
43
+ @items = Item.inventory_items(@inventory_file, mode).order(order).page(params[:page]).per(per_page)
44
44
  else
45
45
  access_denied
46
46
  return
@@ -223,7 +223,7 @@ class ManifestationsController < ApplicationController
223
223
  end
224
224
 
225
225
  page ||= params[:page] || 1
226
- per_page ||= Manifestation.per_page
226
+ per_page ||= Manifestation.default_per_page
227
227
  if params[:format] == 'sru'
228
228
  search.query.start_record(params[:startRecord] || 1, params[:maximumRecords] || 200)
229
229
  else
@@ -242,9 +242,9 @@ class ManifestationsController < ApplicationController
242
242
  else
243
243
  max_count = @count[:query_result]
244
244
  end
245
- @manifestations = WillPaginate::Collection.create(page, per_page, max_count) do |pager|
246
- pager.replace(search_result.results)
247
- end
245
+ @manifestations = Kaminari.paginate_array(
246
+ search_result.results, :total_count => max_count
247
+ ).page(page)
248
248
 
249
249
  if params[:format].blank? or params[:format] == 'html'
250
250
  @carrier_type_facet = search_result.facet(:carrier_type).rows
@@ -264,7 +264,7 @@ class ManifestationsController < ApplicationController
264
264
  end
265
265
 
266
266
  if defined?(EnjuSearchLog)
267
- save_search_history(query, @manifestations.offset, @count[:query_result], current_user)
267
+ save_search_history(query, @manifestations.limit_value, @count[:query_result], current_user)
268
268
  end
269
269
 
270
270
  if defined?(EnjuOai)
@@ -274,7 +274,7 @@ class ManifestationsController < ApplicationController
274
274
  params[:resumptionToken],
275
275
  @from_time || Manifestation.last.updated_at,
276
276
  @until_time || Manifestation.first.updated_at,
277
- @manifestations.per_page
277
+ @manifestations.limit_value
278
278
  )
279
279
  else
280
280
  @oai[:errors] << 'noRecordsMatch'
@@ -361,8 +361,8 @@ class ManifestationsController < ApplicationController
361
361
  @reserve = current_user.reserves.where(:manifestation_id => @manifestation.id).first if user_signed_in?
362
362
  end
363
363
 
364
- if @manifestation.root_of_series?
365
- @manifestations = @manifestation.series_statement.manifestations.periodical_children.page(params[:manifestation_page]).per_page(Manifestation.per_page)
364
+ if defined?(EnjuQuestion)
365
+ @questions = @manifestation.questions(:user => current_user, :page => params[:question_page])
366
366
  end
367
367
 
368
368
  if @manifestation.attachment.path
@@ -78,7 +78,7 @@ class PatronsController < ApplicationController
78
78
  end
79
79
 
80
80
  page = params[:page] || 1
81
- search.query.paginate(page.to_i, Patron.per_page)
81
+ search.query.paginate(page.to_i, Patron.default_per_page)
82
82
  @patrons = search.execute!.results
83
83
 
84
84
  flash[:page_info] = {:page => page, :query => query}
@@ -109,9 +109,23 @@ class PatronsController < ApplicationController
109
109
  end
110
110
  end
111
111
 
112
- @works = @patron.works.page(params[:work_list_page]).per_page(Manifestation.per_page)
113
- @expressions = @patron.expressions.page(params[:expression_list_page]).per_page(Manifestation.per_page)
114
- @manifestations = @patron.manifestations.order('date_of_publication DESC').page(params[:manifestation_list_page]).per_page(Manifestation.per_page)
112
+ patron = @patron
113
+ role = current_user.try(:role) || Role.default_role
114
+ @works = Manifestation.search do
115
+ with(:creator_ids).equal_to patron.id
116
+ with(:required_role_id).less_than_or_equal_to role.id
117
+ paginate :page => params[:work_list_page], :per_page => Manifestation.default_per_page
118
+ end.results
119
+ @expressions = Manifestation.search do
120
+ with(:contributor_ids).equal_to patron.id
121
+ with(:required_role_id).less_than_or_equal_to role.id
122
+ paginate :page => params[:expression_list_page], :per_page => Manifestation.default_per_page
123
+ end.results
124
+ @manifestations = Manifestation.search do
125
+ with(:publisher_ids).equal_to patron.id
126
+ with(:required_role_id).less_than_or_equal_to role.id
127
+ paginate :page => params[:manifestation_list_page], :per_page => Manifestation.default_per_page
128
+ end.results
115
129
 
116
130
  respond_to do |format|
117
131
  format.html # show.html.erb
@@ -9,7 +9,7 @@ class SeriesHasManifestationsController < ApplicationController
9
9
  # GET /series_has_manifestations
10
10
  # GET /series_has_manifestations.json
11
11
  def index
12
- @series_has_manifestations = SeriesHasManifestation.paginate(:page => params[:page])
12
+ @series_has_manifestations = SeriesHasManifestation.page(params[:page])
13
13
 
14
14
  respond_to do |format|
15
15
  format.html # index.html.erb
@@ -20,7 +20,7 @@ class SeriesStatementsController < ApplicationController
20
20
  end
21
21
  search.build do
22
22
  fulltext query if query.present?
23
- paginate :page => page.to_i, :per_page => SeriesStatement.per_page
23
+ paginate :page => page.to_i, :per_page => SeriesStatement.default_per_page
24
24
  order_by :position, :asc
25
25
  end
26
26
  #work = @work
@@ -34,7 +34,7 @@ class SeriesStatementsController < ApplicationController
34
34
  end
35
35
  end
36
36
  page = params[:page] || 1
37
- search.query.paginate(page.to_i, SeriesStatement.per_page)
37
+ search.query.paginate(page.to_i, SeriesStatement.default_per_page)
38
38
  @series_statements = search.execute!.results
39
39
 
40
40
  respond_to do |format|
@@ -46,9 +46,6 @@ class SeriesStatementsController < ApplicationController
46
46
  # GET /series_statements/1
47
47
  # GET /series_statements/1.json
48
48
  def show
49
- #@manifestations = @series_statement.manifestations.order('date_of_publication DESC').page(params[:manifestation_page]).per_page(Manifestation.per_page)
50
- #store_location
51
-
52
49
  respond_to do |format|
53
50
  format.html { # show.html.erb
54
51
  redirect_to series_statement_manifestations_url(@series_statement)
@@ -0,0 +1,36 @@
1
+ class Accept < ActiveRecord::Base
2
+ attr_accessible :item_identifier, :librarian_id, :item_id
3
+ default_scope :order => 'accepts.id DESC'
4
+ belongs_to :basket
5
+ belongs_to :item
6
+ belongs_to :librarian, :class_name => 'User'
7
+
8
+ validates_uniqueness_of :item_id, :message => I18n.t('accept.already_accepted')
9
+ validates_presence_of :item_id, :message => I18n.t('accept.item_not_found')
10
+ validates_presence_of :basket_id
11
+
12
+ before_save :accept!, :on => :create
13
+
14
+ attr_accessor :item_identifier
15
+
16
+ paginates_per 10
17
+
18
+ def accept!
19
+ if defined?(EnjuCirculation)
20
+ item.circulation_status = CirculationStatus.where(:name => 'Available On Shelf').first
21
+ end
22
+ item.save(:validate => false)
23
+ end
24
+ end
25
+ # == Schema Information
26
+ #
27
+ # Table name: accepts
28
+ #
29
+ # id :integer not null, primary key
30
+ # basket_id :integer
31
+ # item_id :integer
32
+ # librarian_id :integer
33
+ # created_at :datetime not null
34
+ # updated_at :datetime not null
35
+ #
36
+
@@ -12,10 +12,6 @@ class Create < ActiveRecord::Base
12
12
 
13
13
  acts_as_list :scope => :work
14
14
 
15
- def self.per_page
16
- 10
17
- end
18
-
19
15
  def reindex
20
16
  patron.try(:index)
21
17
  work.try(:index)
@@ -4,10 +4,6 @@ class Donate < ActiveRecord::Base
4
4
  belongs_to :item, :validate => true
5
5
  validates_associated :patron, :item
6
6
  validates_presence_of :patron, :item
7
-
8
- def self.per_page
9
- 10
10
- end
11
7
  end
12
8
 
13
9
  # == Schema Information
@@ -12,10 +12,6 @@ class Exemplify < ActiveRecord::Base
12
12
 
13
13
  acts_as_list :scope => :manifestation_id
14
14
 
15
- def self.per_page
16
- 10
17
- end
18
-
19
15
  def reindex
20
16
  manifestation.try(:index)
21
17
  item.try(:index)
@@ -19,10 +19,6 @@ class ImportRequest < ActiveRecord::Base
19
19
  end
20
20
  end
21
21
 
22
- def self.per_page
23
- 10
24
- end
25
-
26
22
  def check_isbn
27
23
  if isbn.present?
28
24
  errors.add(:isbn) unless StdNum::ISBN.valid?(isbn)
@@ -32,7 +32,7 @@ class Item < ActiveRecord::Base
32
32
  has_paper_trail
33
33
  normalize_attributes :item_identifier
34
34
 
35
- enju_export
35
+ #enju_export
36
36
 
37
37
  searchable do
38
38
  text :item_identifier, :note, :title, :creator, :contributor, :publisher
@@ -84,9 +84,7 @@ class Item < ActiveRecord::Base
84
84
  end
85
85
  end
86
86
 
87
- def self.per_page
88
- 10
89
- end
87
+ paginates_per 10
90
88
 
91
89
  def title
92
90
  manifestation.try(:original_title)
@@ -176,9 +176,8 @@ class Manifestation < ActiveRecord::Base
176
176
  enju_ndl_search
177
177
  #enju_amazon
178
178
  enju_oai
179
- #enju_calil_check
180
- #enju_cinii
181
- enju_export
179
+ #enju_nii
180
+ #enju_export
182
181
 
183
182
  has_paper_trail
184
183
  if configatron.uploaded_file.storage == :s3
@@ -210,11 +209,9 @@ class Manifestation < ActiveRecord::Base
210
209
  after_save :index_series_statement
211
210
  after_destroy :index_series_statement
212
211
  normalize_attributes :manifestation_identifier, :pub_date, :isbn, :issn, :nbn, :lccn, :original_title
213
- attr_accessor :during_import
212
+ paginates_per 10
214
213
 
215
- def self.per_page
216
- 10
217
- end
214
+ attr_accessor :during_import
218
215
 
219
216
  def check_isbn
220
217
  if isbn.present?
@@ -510,7 +507,7 @@ class Manifestation < ActiveRecord::Base
510
507
  if defined?(EnjuQuestion)
511
508
  def questions(options = {})
512
509
  id = self.id
513
- options = {:page => 1, :per_page => Question.per_page}.merge(options)
510
+ options = {:page => 1, :per_page => Question.default_per_page}.merge(options)
514
511
  page = options[:page]
515
512
  per_page = options[:per_page]
516
513
  user = options[:user]
@@ -11,9 +11,6 @@ class Own < ActiveRecord::Base
11
11
 
12
12
  acts_as_list :scope => :item
13
13
 
14
- def self.per_page
15
- 10
16
- end
17
14
  attr_accessor :item_identifier
18
15
 
19
16
  def reindex
@@ -78,11 +78,9 @@ class Patron < ActiveRecord::Base
78
78
  integer :patron_type_id
79
79
  end
80
80
 
81
- enju_export
81
+ #enju_export
82
82
 
83
- def self.per_page
84
- 10
85
- end
83
+ paginates_per 10
86
84
 
87
85
  def set_role_and_name
88
86
  self.required_role = Role.where(:name => 'Librarian').first if self.required_role_id.nil?
@@ -21,10 +21,6 @@ class PictureFile < ActiveRecord::Base
21
21
  # http://railsforum.com/viewtopic.php?id=11615
22
22
  acts_as_list :scope => 'picture_attachable_type=\'#{picture_attachable_type}\''
23
23
  normalize_attributes :picture_attachable_type
24
-
25
- def self.per_page
26
- 10
27
- end
28
24
  end
29
25
 
30
26
  # == Schema Information
@@ -13,10 +13,6 @@ class Produce < ActiveRecord::Base
13
13
 
14
14
  acts_as_list :scope => :manifestation
15
15
 
16
- def self.per_page
17
- 10
18
- end
19
-
20
16
  def reindex
21
17
  patron.try(:index)
22
18
  manifestation.try(:index)
@@ -12,10 +12,6 @@ class Realize < ActiveRecord::Base
12
12
 
13
13
  acts_as_list :scope => :expression
14
14
 
15
- def self.per_page
16
- 10
17
- end
18
-
19
15
  def reindex
20
16
  patron.try(:index)
21
17
  expression.try(:index)
@@ -13,9 +13,7 @@ class SeriesHasManifestation < ActiveRecord::Base
13
13
 
14
14
  acts_as_list :scope => :series_statement_id
15
15
 
16
- def self.per_page
17
- 10
18
- end
16
+ paginates_per 10
19
17
 
20
18
  def reindex
21
19
  series_statement.reload; series_statement.try(:index)
@@ -25,12 +25,10 @@ class SeriesStatement < ActiveRecord::Base
25
25
  integer :series_statement_merge_list_ids, :multiple => true if defined?(EnjuResourceMerge)
26
26
  end
27
27
 
28
- attr_accessor :selected
29
28
  normalize_attributes :original_title, :issn
29
+ paginates_per 10
30
30
 
31
- def self.per_page
32
- 10
33
- end
31
+ attr_accessor :selected
34
32
 
35
33
  def last_issue
36
34
  manifestations.where('date_of_publication IS NOT NULL').order('date_of_publication DESC').first || manifestations.order(:id).last