sufia 7.0.0.beta4 → 7.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +0 -1
- data/.rubocop_todo.yml +1 -2
- data/.travis.yml +1 -0
- data/Gemfile +18 -9
- data/README.md +23 -3
- data/app/assets/javascripts/sufia.js +4 -1
- data/app/assets/javascripts/sufia/app.js +15 -3
- data/app/assets/javascripts/sufia/autocomplete.es6 +51 -0
- data/app/assets/javascripts/sufia/autocomplete/language.es6 +25 -0
- data/app/assets/javascripts/sufia/autocomplete/location.es6 +24 -0
- data/app/assets/javascripts/sufia/autocomplete/subject.es6 +26 -0
- data/app/assets/javascripts/sufia/batch_edit.js +8 -5
- data/app/assets/javascripts/sufia/permissions/control.es6 +7 -3
- data/app/assets/javascripts/sufia/save_work/required_fields.es6 +10 -4
- data/app/assets/javascripts/sufia/save_work/save_work_control.es6 +14 -4
- data/app/assets/stylesheets/sufia/_fixedsticky.scss +23 -21
- data/app/assets/stylesheets/sufia/_form-progress.scss +16 -7
- data/app/assets/stylesheets/sufia/_header.scss +2 -1
- data/app/assets/stylesheets/sufia/_settings.scss +4 -0
- data/app/controllers/api/items_controller.rb +2 -2
- data/app/controllers/api/zotero_controller.rb +1 -1
- data/app/controllers/citations_controller.rb +0 -2
- data/app/controllers/concerns/sufia/batch_edits_controller_behavior.rb +7 -7
- data/app/controllers/concerns/sufia/batch_uploads_controller_behavior.rb +9 -3
- data/app/controllers/concerns/sufia/singular_subresource_controller.rb +6 -1
- data/app/controllers/concerns/sufia/transfers_controller_behavior.rb +1 -1
- data/app/controllers/concerns/sufia/users_controller_behavior.rb +3 -3
- data/app/controllers/concerns/sufia/works_controller_behavior.rb +11 -4
- data/app/controllers/my/highlights_controller.rb +1 -1
- data/app/forms/sufia/forms/batch_edit_form.rb +10 -6
- data/app/forms/sufia/forms/batch_upload_form.rb +2 -2
- data/app/forms/sufia/forms/collection_form.rb +4 -0
- data/app/forms/sufia/forms/work_form.rb +4 -0
- data/app/helpers/sufia/blacklight_override.rb +0 -20
- data/app/helpers/sufia/collections_helper.rb +12 -0
- data/app/helpers/sufia/sufia_helper_behavior.rb +84 -56
- data/app/jobs/batch_create_job.rb +18 -2
- data/app/jobs/content_depositor_change_event_job.rb +13 -6
- data/app/jobs/create_work_job.rb +6 -2
- data/app/models/batch_upload_item.rb +15 -0
- data/app/models/concerns/sufia/ability.rb +7 -4
- data/app/models/concerns/sufia/user.rb +0 -11
- data/app/models/concerns/sufia/work_behavior.rb +1 -0
- data/app/models/concerns/sufia/works/featured.rb +23 -0
- data/app/models/file_download_stat.rb +9 -12
- data/app/models/file_view_stat.rb +5 -15
- data/app/models/proxy_deposit_request.rb +11 -7
- data/app/models/sufia/statistic.rb +65 -0
- data/app/models/work_view_stat.rb +5 -16
- data/app/presenters/file_usage.rb +3 -4
- data/app/presenters/sufia/file_set_presenter.rb +1 -3
- data/app/presenters/sufia/trophy_presenter.rb +28 -0
- data/app/presenters/sufia/user_profile_presenter.rb +1 -1
- data/app/presenters/work_usage.rb +5 -4
- data/app/search_builders/deposit_search_builder.rb +4 -3
- data/app/search_builders/parent_collection_search_builder.rb +1 -1
- data/app/services/sufia/collection_member_service.rb +1 -1
- data/app/services/sufia/user_stat_importer.rb +11 -6
- data/app/views/_controls.html.erb +11 -9
- data/app/views/batch_edits/edit.html.erb +8 -2
- data/app/views/catalog/_index_list_default.html.erb +2 -1
- data/app/views/curation_concerns/base/_form_metadata.html.erb +1 -1
- data/app/views/curation_concerns/base/_form_progress.html.erb +1 -1
- data/app/views/curation_concerns/base/_form_relationships.html.erb +1 -1
- data/app/views/curation_concerns/base/_guts4form.html.erb +6 -2
- data/app/views/curation_concerns/base/_items.html.erb +1 -1
- data/app/views/curation_concerns/base/edit.html.erb +1 -1
- data/app/views/curation_concerns/base/new.html.erb +1 -1
- data/app/views/curation_concerns/file_sets/_permission.html.erb +5 -1
- data/app/views/curation_concerns/file_sets/media_display/_default.html.erb +1 -1
- data/app/views/curation_concerns/file_sets/show.html.erb +1 -1
- data/app/views/dashboard/_index_partials/_heading_actions.html.erb +1 -1
- data/app/views/{error → errors}/404.html.erb +0 -0
- data/app/views/records/edit_fields/_based_near.html.erb +8 -0
- data/app/views/records/edit_fields/_language.html.erb +8 -0
- data/app/views/records/edit_fields/_subject.html.erb +8 -0
- data/app/views/stats/work.html.erb +1 -1
- data/app/views/sufia/batch_uploads/_form.html.erb +1 -1
- data/app/views/sufia/homepage/_home_header.html.erb +1 -1
- data/app/views/sufia/homepage/_sortable_featured.html.erb +1 -1
- data/app/views/transfers/new.html.erb +3 -1
- data/app/views/users/_contributions.html.erb +1 -1
- data/config/locales/sufia.en.yml +3 -2
- data/config/routes.rb +0 -7
- data/lib/generators/sufia/install_generator.rb +0 -24
- data/lib/generators/sufia/templates/catalog_controller.rb +4 -3
- data/lib/generators/sufia/templates/config/sufia.rb +4 -2
- data/lib/generators/sufia/upgrade700_generator.rb +7 -9
- data/lib/generators/sufia/work_generator.rb +56 -0
- data/lib/sufia.rb +4 -1
- data/lib/sufia/arkivo/actor.rb +1 -1
- data/lib/sufia/configuration.rb +15 -3
- data/lib/sufia/engine.rb +1 -10
- data/lib/sufia/version.rb +1 -1
- data/spec/controllers/api/items_controller_spec.rb +20 -7
- data/spec/controllers/sufia/batch_uploads_controller_spec.rb +4 -3
- data/spec/controllers/transfers_controller_spec.rb +3 -11
- data/spec/controllers/users_controller_spec.rb +2 -1
- data/spec/features/batch_edit_spec.rb +17 -2
- data/spec/forms/sufia/forms/batch_edit_form_spec.rb +2 -0
- data/spec/forms/sufia/forms/batch_upload_form_spec.rb +1 -1
- data/spec/helpers/blacklight_helper_spec.rb +36 -26
- data/spec/helpers/{generic_work_helper_spec.rb → sufia/collections_helper_spec.rb} +1 -1
- data/spec/helpers/sufia_helper_spec.rb +70 -32
- data/spec/javascripts/autocomplete_spec.js.coffee +7 -7
- data/spec/javascripts/save_work_spec.js +20 -20
- data/spec/lib/sufia/configuration_spec.rb +30 -0
- data/spec/lib/sufia/user_stat_importer_spec.rb +21 -36
- data/spec/models/file_download_stat_spec.rb +8 -8
- data/spec/models/file_view_stat_spec.rb +8 -8
- data/spec/models/generic_work_spec.rb +24 -0
- data/spec/models/proxy_deposit_request_spec.rb +2 -4
- data/spec/models/sufia/ability_spec.rb +7 -13
- data/spec/models/user_spec.rb +0 -14
- data/spec/models/work_view_stat_spec.rb +22 -8
- data/spec/presenters/sufia/file_usage_spec.rb +0 -4
- data/spec/presenters/sufia/trophy_presenter_spec.rb +46 -0
- data/spec/presenters/sufia/user_profile_presenter_spec.rb +4 -1
- data/spec/presenters/sufia/work_usage_spec.rb +8 -17
- data/spec/routing/route_spec.rb +0 -6
- data/spec/spec_helper.rb +8 -2
- data/spec/test_app_templates/lib/generators/test_app_generator.rb +4 -0
- data/spec/views/batch_edits/edit.html.erb_spec.rb +8 -2
- data/spec/views/catalog/_index_list_default.html.erb_spec.rb +8 -6
- data/spec/views/curation_concerns/base/_form.html.erb_spec.rb +3 -0
- data/spec/views/curation_concerns/file_sets/_permission.html.erb_spec.rb +16 -0
- data/spec/views/curation_concerns/file_sets/show.html.erb_spec.rb +0 -2
- data/spec/views/records/edit_fields/_based_near.html.erb_spec.rb +20 -0
- data/spec/views/records/edit_fields/_language.html.erb_spec.rb +20 -0
- data/spec/views/records/edit_fields/_subject.html.erb_spec.rb +20 -0
- data/spec/views/{homepage → sufia/homepage}/_announcement.html.erb_spec.rb +0 -0
- data/spec/views/{homepage → sufia/homepage}/_featured_works.html.erb_spec.rb +0 -0
- data/spec/views/{homepage → sufia/homepage}/_home_header.html.erb_spec.rb +0 -0
- data/spec/views/sufia/homepage/_sortable_featured.html.erb_spec.rb +21 -0
- data/spec/views/users/edit.html.erb_spec.rb +5 -5
- data/spec/views/users/show.html.erb_spec.rb +5 -3
- data/sufia.gemspec +4 -3
- data/tasks/noid.rake +2 -2
- data/tasks/sufia-dev.rake +1 -1
- metadata +73 -68
- data/app/assets/javascripts/sufia/edit_metadata.js +0 -87
- data/app/controllers/authorities_controller.rb +0 -19
- data/app/helpers/generic_work_helper.rb +0 -10
- data/app/helpers/sufia_url_helper.rb +0 -14
- data/app/models/concerns/sufia/file_stat_utils.rb +0 -33
- data/app/models/concerns/sufia/work_stat_utils.rb +0 -33
- data/app/models/geo_names_resource.rb +0 -18
- data/app/models/local_authority.rb +0 -101
- data/app/models/local_authority_entry.rb +0 -3
- data/app/models/subject_local_authority_entry.rb +0 -2
- data/app/views/curation_concerns/generic_works/_generic_work.html.erb +0 -3
- data/app/views/error/401.html.erb +0 -18
- data/app/views/error/500.html.erb +0 -9
- data/app/views/error/single_use_error.html.erb +0 -19
- data/lib/generators/sufia/geonames_username_config_generator.rb +0 -20
- data/spec/controllers/authorities_controller_spec.rb +0 -18
- data/spec/fixtures/cities15000.tsv +0 -149
- data/spec/fixtures/genreForms.nt +0 -471
- data/spec/fixtures/lexvo.rdf +0 -3108
- data/spec/helpers/sufia_url_helper_spec.rb +0 -18
- data/spec/models/geo_names_resource_spec.rb +0 -30
- data/spec/models/local_authority_spec.rb +0 -108
- data/vendor/assets/javascripts/almond.js +0 -430
@@ -8,6 +8,12 @@ class BatchCreateJob < ActiveJob::Base
|
|
8
8
|
|
9
9
|
# This copies metadata from the passed in attribute to all of the works that
|
10
10
|
# are members of the given upload set
|
11
|
+
# @param [User] user
|
12
|
+
# @param [Array<String>] titles
|
13
|
+
# @param [Array<String>] resource_types
|
14
|
+
# @param [Array<Sufia::UploadedFile>] uploaded_files
|
15
|
+
# @param [Hash] attributes attributes to apply to all works
|
16
|
+
# @param [BatchCreateOperation] log
|
11
17
|
def perform(user, titles, resource_types, uploaded_files, attributes, log)
|
12
18
|
log.performing!
|
13
19
|
|
@@ -23,11 +29,21 @@ class BatchCreateJob < ActiveJob::Base
|
|
23
29
|
uploaded_files.each do |upload_id|
|
24
30
|
title = [titles[upload_id]] if titles[upload_id]
|
25
31
|
resource_type = [resource_types[upload_id]] if resource_types[upload_id]
|
26
|
-
attributes = attributes.merge(uploaded_files: [upload_id],
|
32
|
+
attributes = attributes.merge(uploaded_files: [upload_id],
|
33
|
+
title: title,
|
34
|
+
resource_type: resource_type)
|
35
|
+
model = model_to_create(attributes)
|
27
36
|
child_log = CurationConcerns::Operation.create!(user: user,
|
28
37
|
operation_type: "Create Work",
|
29
38
|
parent: log)
|
30
|
-
CreateWorkJob.perform_later(user, attributes, child_log)
|
39
|
+
CreateWorkJob.perform_later(user, model, attributes, child_log)
|
31
40
|
end
|
32
41
|
end
|
42
|
+
|
43
|
+
# Override this method if you have a different rubric for choosing the model
|
44
|
+
# @param [Hash] attributes
|
45
|
+
# @return String the model to create
|
46
|
+
def model_to_create(attributes)
|
47
|
+
Sufia.config.model_to_create.call(attributes)
|
48
|
+
end
|
33
49
|
end
|
@@ -2,21 +2,28 @@
|
|
2
2
|
#
|
3
3
|
# @attr [Boolean] reset (false) should the access controls be reset. This means revoking edit access from the depositor
|
4
4
|
class ContentDepositorChangeEventJob < ContentEventJob
|
5
|
+
include Rails.application.routes.url_helpers
|
6
|
+
include ActionDispatch::Routing::PolymorphicRoutes
|
7
|
+
|
5
8
|
attr_accessor :reset
|
6
9
|
|
7
|
-
# @param [
|
8
|
-
# @param [User] user the user the
|
10
|
+
# @param [ActiveFedora::Base] work the work to be transfered
|
11
|
+
# @param [User] user the user the work is being transfered to.
|
9
12
|
# @param [TrueClass,FalseClass] reset (false) if true, reset the access controls. This revokes edit access from the depositor
|
10
|
-
def perform(
|
13
|
+
def perform(work, user, reset = false)
|
11
14
|
@reset = reset
|
12
|
-
super(
|
15
|
+
super(work, user)
|
13
16
|
end
|
14
17
|
|
15
18
|
def action
|
16
|
-
"User #{link_to_profile work.proxy_depositor} has transferred #{
|
19
|
+
"User #{link_to_profile work.proxy_depositor} has transferred #{link_to_work work.title.first} to user #{link_to_profile depositor}"
|
20
|
+
end
|
21
|
+
|
22
|
+
def link_to_work(text)
|
23
|
+
link_to text, polymorphic_path(work)
|
17
24
|
end
|
18
25
|
|
19
|
-
# Log the event to the
|
26
|
+
# Log the event to the work's stream
|
20
27
|
def log_work_event(work)
|
21
28
|
work.log_event(event)
|
22
29
|
end
|
data/app/jobs/create_work_job.rb
CHANGED
@@ -8,9 +8,13 @@ class CreateWorkJob < ActiveJob::Base
|
|
8
8
|
|
9
9
|
# This copies metadata from the passed in attribute to all of the works that
|
10
10
|
# are members of the given upload set
|
11
|
-
|
11
|
+
# @param [User] user
|
12
|
+
# @param [String] model
|
13
|
+
# @param [Hash] attributes
|
14
|
+
# @param [BatchCreateOperation] log
|
15
|
+
def perform(user, model, attributes, log)
|
12
16
|
log.performing!
|
13
|
-
work =
|
17
|
+
work = model.constantize.new
|
14
18
|
actor = work_actor(work, user)
|
15
19
|
status = actor.create(attributes)
|
16
20
|
return log.success! if status
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# This stands in for an object to be created from the BatchUploadForm.
|
2
|
+
# It should never actually be persisted in the repository.
|
3
|
+
# The properties on this form should be copied to a real work type.
|
4
|
+
class BatchUploadItem < ActiveFedora::Base
|
5
|
+
include CurationConcerns::BasicMetadata
|
6
|
+
|
7
|
+
# This mocks out the behavior of Hydra::PCDM::PcdmBehavior
|
8
|
+
def in_collection_ids
|
9
|
+
[]
|
10
|
+
end
|
11
|
+
|
12
|
+
def create_or_update
|
13
|
+
raise "This is a read only record"
|
14
|
+
end
|
15
|
+
end
|
@@ -14,13 +14,13 @@ module Sufia
|
|
14
14
|
|
15
15
|
def uploaded_file_abilities
|
16
16
|
return unless registered_user?
|
17
|
-
can :create, UploadedFile
|
17
|
+
can :create, [UploadedFile, BatchUploadItem]
|
18
18
|
can :destroy, UploadedFile, user: current_user
|
19
19
|
end
|
20
20
|
|
21
21
|
def proxy_deposit_abilities
|
22
22
|
can :transfer, String do |id|
|
23
|
-
|
23
|
+
user_is_depositor?(id)
|
24
24
|
end
|
25
25
|
can :create, ProxyDepositRequest if registered_user?
|
26
26
|
can :accept, ProxyDepositRequest, receiving_user_id: current_user.id, status: 'pending'
|
@@ -57,8 +57,11 @@ module Sufia
|
|
57
57
|
|
58
58
|
private
|
59
59
|
|
60
|
-
def
|
61
|
-
::
|
60
|
+
def user_is_depositor?(document_id)
|
61
|
+
CurationConcerns::WorkRelation.new.search_with_conditions(
|
62
|
+
id: document_id,
|
63
|
+
DepositSearchBuilder.depositor_field => current_user.user_key
|
64
|
+
).any?
|
62
65
|
end
|
63
66
|
end
|
64
67
|
end
|
@@ -110,17 +110,6 @@ module Sufia::User
|
|
110
110
|
user_key.gsub(/\./, '-dot-')
|
111
111
|
end
|
112
112
|
|
113
|
-
def trophy_works
|
114
|
-
trophies.map do |t|
|
115
|
-
begin
|
116
|
-
::GenericWork.load_instance_from_solr(t.work_id)
|
117
|
-
rescue ActiveFedora::ObjectNotFoundError
|
118
|
-
logger.error("Invalid trophy for user #{user_key} (work id #{t.work_id})")
|
119
|
-
nil
|
120
|
-
end
|
121
|
-
end.compact
|
122
|
-
end
|
123
|
-
|
124
113
|
# method needed for messaging
|
125
114
|
def mailboxer_email(_obj = nil)
|
126
115
|
nil
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Sufia::Works
|
2
|
+
module Featured
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
included do
|
5
|
+
before_destroy :cleanup_featured_works
|
6
|
+
after_save :check_featureability
|
7
|
+
end
|
8
|
+
|
9
|
+
def cleanup_featured_works
|
10
|
+
FeaturedWork.destroy_all(work_id: id)
|
11
|
+
end
|
12
|
+
|
13
|
+
def check_featureability
|
14
|
+
return unless private?
|
15
|
+
cleanup_featured_works if featured?
|
16
|
+
end
|
17
|
+
|
18
|
+
def featured?
|
19
|
+
return true if FeaturedWork.find_by_work_id(id)
|
20
|
+
false
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -1,17 +1,14 @@
|
|
1
|
-
class FileDownloadStat <
|
2
|
-
|
3
|
-
|
4
|
-
def to_flot
|
5
|
-
[self.class.convert_date(date), downloads]
|
6
|
-
end
|
7
|
-
|
8
|
-
def self.statistics(file_id, start_date, user_id = nil)
|
9
|
-
combined_stats file_id, start_date, :downloads, :totalEvents, user_id
|
10
|
-
end
|
1
|
+
class FileDownloadStat < Sufia::Statistic
|
2
|
+
self.cache_column = :downloads
|
3
|
+
self.event_type = :totalEvents
|
11
4
|
|
12
5
|
# Sufia::Download is sent to Sufia::Analytics.profile as #sufia__download
|
13
6
|
# see Legato::ProfileMethods.method_name_from_klass
|
14
|
-
def self.ga_statistics(start_date,
|
15
|
-
Sufia::Analytics.profile.sufia__download(sort: 'date', start_date: start_date, end_date: Date.yesterday).for_file(
|
7
|
+
def self.ga_statistics(start_date, file)
|
8
|
+
Sufia::Analytics.profile.sufia__download(sort: 'date', start_date: start_date, end_date: Date.yesterday).for_file(file.id)
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.filter(file)
|
12
|
+
{ file_id: file.id }
|
16
13
|
end
|
17
14
|
end
|
@@ -1,18 +1,8 @@
|
|
1
|
-
class FileViewStat <
|
2
|
-
|
1
|
+
class FileViewStat < Sufia::Statistic
|
2
|
+
self.cache_column = :views
|
3
|
+
self.event_type = :pageviews
|
3
4
|
|
4
|
-
def
|
5
|
-
|
6
|
-
end
|
7
|
-
|
8
|
-
def self.statistics(file_id, start_date, user_id = nil)
|
9
|
-
combined_stats file_id, start_date, :views, :pageviews, user_id
|
10
|
-
end
|
11
|
-
|
12
|
-
# Sufia::Download is sent to Sufia::Analytics.profile as #sufia__download
|
13
|
-
# see Legato::ProfileMethods.method_name_from_klass
|
14
|
-
def self.ga_statistics(start_date, file_id)
|
15
|
-
path = Rails.application.routes.url_helpers.curation_concerns_file_set_path(file_id)
|
16
|
-
Sufia::Analytics.profile.sufia__pageview(sort: 'date', start_date: start_date).for_path(path)
|
5
|
+
def self.filter(file)
|
6
|
+
{ file_id: file.id }
|
17
7
|
end
|
18
8
|
end
|
@@ -56,7 +56,7 @@ class ProxyDepositRequest < ActiveRecord::Base
|
|
56
56
|
|
57
57
|
# @param [TrueClass,FalseClass] reset (false) if true, reset the access controls. This revokes edit access from the depositor
|
58
58
|
def transfer!(reset = false)
|
59
|
-
ContentDepositorChangeEventJob.perform_later(
|
59
|
+
ContentDepositorChangeEventJob.perform_later(work, receiving_user, reset)
|
60
60
|
self.status = 'accepted'
|
61
61
|
self.fulfillment_date = Time.current
|
62
62
|
save!
|
@@ -80,21 +80,21 @@ class ProxyDepositRequest < ActiveRecord::Base
|
|
80
80
|
end
|
81
81
|
|
82
82
|
def deleted_work?
|
83
|
-
!
|
83
|
+
!work_relation.exists?(work_id)
|
84
84
|
end
|
85
85
|
|
86
|
-
def
|
87
|
-
@
|
86
|
+
def work
|
87
|
+
@work ||= work_relation.find(work_id)
|
88
88
|
end
|
89
89
|
|
90
90
|
# Delegate to the SolrDocument of the work
|
91
|
-
delegate :to_s, to: :
|
91
|
+
delegate :to_s, to: :solr_doc
|
92
92
|
|
93
93
|
private
|
94
94
|
|
95
|
-
def
|
95
|
+
def solr_doc
|
96
96
|
return 'work not found' if deleted_work?
|
97
|
-
@
|
97
|
+
@solr_doc ||= SolrDocument.new(solr_response['response']['docs'].first, solr_response)
|
98
98
|
end
|
99
99
|
|
100
100
|
def solr_response
|
@@ -104,4 +104,8 @@ class ProxyDepositRequest < ActiveRecord::Base
|
|
104
104
|
def query
|
105
105
|
ActiveFedora::SolrQueryBuilder.construct_query_for_ids([work_id])
|
106
106
|
end
|
107
|
+
|
108
|
+
def work_relation
|
109
|
+
CurationConcerns::WorkRelation.new
|
110
|
+
end
|
107
111
|
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module Sufia
|
2
|
+
class Statistic < ActiveRecord::Base
|
3
|
+
self.abstract_class = true
|
4
|
+
|
5
|
+
class_attribute :cache_column, :event_type
|
6
|
+
|
7
|
+
class << self
|
8
|
+
include ActionDispatch::Routing::PolymorphicRoutes
|
9
|
+
include Rails.application.routes.url_helpers
|
10
|
+
|
11
|
+
def statistics_for(object)
|
12
|
+
where(filter(object))
|
13
|
+
end
|
14
|
+
|
15
|
+
def build_for(object, attrs)
|
16
|
+
new attrs.merge(filter(object))
|
17
|
+
end
|
18
|
+
|
19
|
+
def to_flots(stats)
|
20
|
+
stats.map(&:to_flot)
|
21
|
+
end
|
22
|
+
|
23
|
+
def convert_date(date_time)
|
24
|
+
date_time.to_datetime.to_i * 1000
|
25
|
+
end
|
26
|
+
|
27
|
+
def statistics(object, start_date, user_id = nil)
|
28
|
+
combined_stats object, start_date, cache_column, event_type, user_id
|
29
|
+
end
|
30
|
+
|
31
|
+
# Sufia::Download is sent to Sufia::Analytics.profile as #sufia__download
|
32
|
+
# see Legato::ProfileMethods.method_name_from_klass
|
33
|
+
def ga_statistics(start_date, object)
|
34
|
+
path = polymorphic_path(object)
|
35
|
+
Sufia::Analytics.profile.sufia__pageview(sort: 'date', start_date: start_date).for_path(path)
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def cached_stats(object, start_date, _method)
|
41
|
+
stats = statistics_for(object).order(date: :asc)
|
42
|
+
ga_start_date = stats.any? ? stats[stats.size - 1].date + 1.day : start_date.to_date
|
43
|
+
{ ga_start_date: ga_start_date, cached_stats: stats.to_a }
|
44
|
+
end
|
45
|
+
|
46
|
+
def combined_stats(object, start_date, object_method, ga_key, user_id = nil)
|
47
|
+
stat_cache_info = cached_stats(object, start_date, object_method)
|
48
|
+
stats = stat_cache_info[:cached_stats]
|
49
|
+
if stat_cache_info[:ga_start_date] < Time.zone.today
|
50
|
+
ga_stats = ga_statistics(stat_cache_info[:ga_start_date], object)
|
51
|
+
ga_stats.each do |stat|
|
52
|
+
lstat = build_for(object, date: stat[:date], object_method => stat[ga_key], user_id: user_id)
|
53
|
+
lstat.save unless Date.parse(stat[:date]) == Time.zone.today
|
54
|
+
stats << lstat
|
55
|
+
end
|
56
|
+
end
|
57
|
+
stats
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def to_flot
|
62
|
+
[self.class.convert_date(date), send(cache_column)]
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -1,19 +1,8 @@
|
|
1
|
-
class WorkViewStat <
|
2
|
-
|
1
|
+
class WorkViewStat < Sufia::Statistic
|
2
|
+
self.cache_column = :work_views
|
3
|
+
self.event_type = :pageviews
|
3
4
|
|
4
|
-
def
|
5
|
-
|
6
|
-
end
|
7
|
-
|
8
|
-
def self.statistics(work_id, start_date, user_id = nil)
|
9
|
-
combined_stats work_id, start_date, :work_views, :pageviews, user_id
|
10
|
-
end
|
11
|
-
|
12
|
-
# Sufia::Download is sent to Sufia::Analytics.profile as #sufia__download
|
13
|
-
# see Legato::ProfileMethods.method_name_from_klass
|
14
|
-
def self.ga_statistics(start_date, work_id)
|
15
|
-
path = Rails.application.routes.url_helpers.curation_concerns_generic_work_path(work_id)
|
16
|
-
|
17
|
-
Sufia::Analytics.profile.sufia__pageview(sort: 'date', start_date: start_date).for_path(path)
|
5
|
+
def self.filter(work)
|
6
|
+
{ work_id: work.id }
|
18
7
|
end
|
19
8
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
class FileUsage
|
2
|
-
attr_accessor :id, :created, :
|
2
|
+
attr_accessor :id, :created, :downloads, :pageviews
|
3
3
|
|
4
4
|
def initialize(id)
|
5
5
|
file = ::FileSet.find(id)
|
@@ -7,10 +7,9 @@ class FileUsage
|
|
7
7
|
user_id = user ? user.id : nil
|
8
8
|
|
9
9
|
self.id = id
|
10
|
-
self.path = Rails.application.routes.url_helpers.curation_concerns_file_set_path(id)
|
11
10
|
self.created = date_for_analytics(file)
|
12
|
-
self.downloads = FileDownloadStat.to_flots FileDownloadStat.statistics(
|
13
|
-
self.pageviews = FileViewStat.to_flots FileViewStat.statistics(
|
11
|
+
self.downloads = FileDownloadStat.to_flots FileDownloadStat.statistics(file, created, user_id)
|
12
|
+
self.pageviews = FileViewStat.to_flots FileViewStat.statistics(file, created, user_id)
|
14
13
|
end
|
15
14
|
|
16
15
|
# file.date_uploaded reflects the date the file was uploaded by the user
|
@@ -45,9 +45,7 @@ module Sufia
|
|
45
45
|
end
|
46
46
|
|
47
47
|
def audit_service
|
48
|
-
|
49
|
-
model = FileSet.find(id)
|
50
|
-
@audit_service ||= CurationConcerns::FileSetAuditService.new(model)
|
48
|
+
@audit_service ||= CurationConcerns::FileSetAuditService.new(id)
|
51
49
|
end
|
52
50
|
end
|
53
51
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Sufia
|
2
|
+
class TrophyPresenter
|
3
|
+
include CurationConcerns::ModelProxy
|
4
|
+
def initialize(solr_document)
|
5
|
+
@solr_document = solr_document
|
6
|
+
end
|
7
|
+
|
8
|
+
attr_reader :solr_document
|
9
|
+
|
10
|
+
delegate :to_s, to: :solr_document
|
11
|
+
|
12
|
+
def self.find_by_user(user)
|
13
|
+
work_ids = user.trophies.pluck(:work_id)
|
14
|
+
query = ActiveFedora::SolrQueryBuilder.construct_query_for_ids(work_ids)
|
15
|
+
results = CurationConcerns::WorkRelation.new.search_with_conditions(query)
|
16
|
+
results.map { |result| TrophyPresenter.new(document_model.new(result)) }
|
17
|
+
end
|
18
|
+
|
19
|
+
def thumbnail_path
|
20
|
+
solr_document[CatalogController.blacklight_config.index.thumbnail_field]
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.document_model
|
24
|
+
CatalogController.blacklight_config.document_model
|
25
|
+
end
|
26
|
+
private_class_method :document_model
|
27
|
+
end
|
28
|
+
end
|