decidim-core 0.14.4 → 0.15.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of decidim-core might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/README.md +20 -0
- data/app/assets/images/decidim/cc-badge.png +0 -0
- data/app/assets/images/decidim/gamification/badges/continuity.svg +73 -0
- data/app/assets/images/decidim/gamification/badges/followers.svg +115 -0
- data/app/assets/images/decidim/icons.svg +1 -0
- data/app/assets/javascripts/decidim/vizzs/areachart.js.es6 +186 -208
- data/app/assets/javascripts/decidim/vizzs/linechart.js.es6 +263 -0
- data/app/assets/javascripts/decidim/vizzs/metrics.js.es6 +36 -26
- data/app/assets/javascripts/decidim/vizzs/orgchart.js.es6 +3 -2
- data/app/assets/javascripts/decidim/vizzs/rowchart.js.es6 +324 -0
- data/app/assets/stylesheets/decidim/_decidim.scss +1 -0
- data/app/assets/stylesheets/decidim/modules/_cards.scss +1 -0
- data/app/assets/stylesheets/decidim/modules/_conference-diploma.scss +75 -0
- data/app/assets/stylesheets/decidim/modules/_conference-media.scss +44 -0
- data/app/assets/stylesheets/decidim/modules/_conference-programme.scss +5 -1
- data/app/assets/stylesheets/decidim/modules/_conference-registration.scss +34 -0
- data/app/assets/stylesheets/decidim/modules/_list-request.scss +16 -0
- data/app/assets/stylesheets/decidim/modules/_modules.scss +4 -4
- data/app/assets/stylesheets/decidim/modules/_process-phase.scss +1 -0
- data/app/assets/stylesheets/decidim/modules/_reveal.scss +6 -1
- data/app/assets/stylesheets/decidim/utils/_helpers.scss +1 -1
- data/app/assets/stylesheets/decidim/{modules → vizzs}/_areachart.scss +8 -11
- data/app/assets/stylesheets/decidim/{modules → vizzs}/_chart-tooltip.scss +0 -0
- data/app/assets/stylesheets/decidim/vizzs/_linechart.scss +115 -0
- data/app/assets/stylesheets/decidim/vizzs/_rowchart.scss +77 -0
- data/app/cells/decidim/activities/show.erb +3 -0
- data/app/cells/decidim/activities_cell.rb +38 -0
- data/app/cells/decidim/activity/show.erb +21 -0
- data/app/cells/decidim/activity_cell.rb +85 -0
- data/app/cells/decidim/address/details.erb +7 -0
- data/app/cells/decidim/address/show.erb +14 -0
- data/app/cells/decidim/address_cell.rb +19 -0
- data/app/cells/decidim/author/contact.erb +1 -1
- data/app/cells/decidim/author_cell.rb +1 -0
- data/app/cells/decidim/badge/show.erb +2 -2
- data/app/cells/decidim/badge/small.erb +5 -0
- data/app/cells/decidim/badge_cell.rb +36 -14
- data/app/cells/decidim/badges/show.erb +6 -3
- data/app/cells/decidim/badges_cell.rb +4 -4
- data/app/cells/decidim/coauthorships_cell.rb +8 -2
- data/app/cells/decidim/collapsible_authors/show.erb +9 -7
- data/app/cells/decidim/content_blocks/html/show.erb +3 -0
- data/app/cells/decidim/content_blocks/html_cell.rb +11 -0
- data/app/cells/decidim/content_blocks/html_settings_form/show.erb +3 -0
- data/app/cells/decidim/content_blocks/html_settings_form_cell.rb +17 -0
- data/app/cells/decidim/content_blocks/last_activity/show.erb +17 -0
- data/app/cells/decidim/content_blocks/last_activity_cell.rb +60 -0
- data/app/cells/decidim/content_blocks/metrics/show.erb +13 -0
- data/app/cells/decidim/content_blocks/metrics_cell.rb +18 -0
- data/app/cells/decidim/content_blocks/stats/show.erb +2 -1
- data/app/cells/decidim/groups/show.erb +10 -0
- data/app/cells/decidim/groups_cell.rb +19 -0
- data/app/cells/decidim/members/show.erb +9 -0
- data/app/cells/decidim/members_cell.rb +32 -0
- data/app/cells/decidim/profile/show.erb +3 -11
- data/app/cells/decidim/profile/user_group_tabs.erb +5 -0
- data/app/cells/decidim/profile/user_tabs.erb +12 -0
- data/app/cells/decidim/profile_cell.rb +7 -2
- data/app/cells/decidim/profile_sidebar/show.erb +108 -23
- data/app/cells/decidim/profile_sidebar_cell.rb +36 -2
- data/app/cells/decidim/user_group_admin_membership_profile/footer.erb +29 -0
- data/app/cells/decidim/user_group_admin_membership_profile_cell.rb +14 -0
- data/app/cells/decidim/user_group_membership_profile/tags.erb +1 -0
- data/app/cells/decidim/user_group_membership_profile_cell.rb +8 -0
- data/app/cells/decidim/user_group_pending_invitations_list/show.erb +23 -0
- data/app/cells/decidim/user_group_pending_invitations_list_cell.rb +26 -0
- data/app/cells/decidim/user_group_pending_requests_list/show.erb +23 -0
- data/app/cells/decidim/user_group_pending_requests_list_cell.rb +26 -0
- data/app/cells/decidim/user_profile/header.erb +1 -1
- data/app/cells/decidim/user_profile_cell.rb +15 -9
- data/app/commands/decidim/accept_group_invitation.rb +43 -0
- data/app/commands/decidim/accept_user_group_join_request.rb +53 -0
- data/app/commands/decidim/create_follow.rb +6 -0
- data/app/commands/decidim/create_registration.rb +13 -23
- data/app/commands/decidim/create_user_group.rb +57 -0
- data/app/commands/decidim/delete_follow.rb +7 -0
- data/app/commands/decidim/demote_membership.rb +57 -0
- data/app/commands/decidim/destroy_account.rb +6 -0
- data/app/commands/decidim/invite_user.rb +1 -3
- data/app/commands/decidim/invite_user_to_group.rb +62 -0
- data/app/commands/decidim/join_user_group.rb +63 -0
- data/app/commands/decidim/leave_user_group.rb +41 -0
- data/app/commands/decidim/promote_membership.rb +55 -0
- data/app/commands/decidim/reject_group_invitation.rb +42 -0
- data/app/commands/decidim/reject_user_group_join_request.rb +53 -0
- data/app/commands/decidim/remove_user_from_group.rb +53 -0
- data/app/commands/decidim/update_user_group.rb +53 -0
- data/app/controllers/concerns/decidim/locale_switcher.rb +3 -3
- data/app/controllers/concerns/decidim/paginable.rb +1 -0
- data/app/controllers/decidim/application_controller.rb +7 -0
- data/app/controllers/decidim/devise/omniauth_registrations_controller.rb +1 -1
- data/app/controllers/decidim/devise/sessions_controller.rb +1 -1
- data/app/controllers/decidim/gamification/badges_controller.rb +11 -0
- data/app/controllers/decidim/group_admins_controller.rb +41 -0
- data/app/controllers/decidim/group_invites_controller.rb +74 -0
- data/app/controllers/decidim/group_members_controller.rb +59 -0
- data/app/controllers/decidim/groups_controller.rb +85 -0
- data/app/controllers/decidim/last_activities_controller.rb +46 -0
- data/app/controllers/decidim/pages_controller.rb +9 -1
- data/app/controllers/decidim/profiles_controller.rb +35 -5
- data/app/controllers/decidim/user_group_join_requests_controller.rb +69 -0
- data/app/events/decidim/demoted_membership_event.rb +28 -0
- data/app/events/decidim/invited_to_group_event.rb +33 -0
- data/app/events/decidim/join_request_accepted_event.rb +28 -0
- data/app/events/decidim/join_request_created_event.rb +28 -0
- data/app/events/decidim/join_request_rejected_event.rb +28 -0
- data/app/events/decidim/promoted_to_admin_event.rb +28 -0
- data/app/events/decidim/removed_from_group_event.rb +28 -0
- data/app/forms/decidim/account_form.rb +1 -1
- data/app/forms/decidim/invite_user_to_group_form.rb +29 -0
- data/app/forms/decidim/notifications_settings_form.rb +4 -0
- data/app/forms/decidim/registration_form.rb +0 -27
- data/app/forms/decidim/user_group_form.rb +81 -0
- data/app/helpers/decidim/component_path_helper.rb +10 -0
- data/app/helpers/decidim/filters_helper.rb +3 -2
- data/app/helpers/decidim/icon_helper.rb +3 -1
- data/app/helpers/decidim/map_helper.rb +1 -1
- data/app/jobs/decidim/metric_job.rb +14 -0
- data/app/mailers/decidim/newsletter_mailer.rb +2 -0
- data/app/mailers/decidim/notification_mailer.rb +1 -1
- data/app/models/decidim/action_log.rb +66 -0
- data/app/models/decidim/coauthorship.rb +9 -0
- data/app/models/decidim/component.rb +5 -0
- data/app/models/decidim/continuity_badge_status.rb +9 -0
- data/app/models/decidim/gamification/badge_score.rb +1 -1
- data/app/models/decidim/messaging/message.rb +1 -0
- data/app/models/decidim/metric.rb +13 -0
- data/app/models/decidim/participatory_space_private_user.rb +4 -0
- data/app/models/decidim/user.rb +14 -38
- data/app/models/decidim/user_base_entity.rb +52 -0
- data/app/models/decidim/user_group.rb +48 -9
- data/app/models/decidim/user_group_membership.rb +8 -0
- data/app/permissions/decidim/permissions.rb +21 -0
- data/app/presenters/decidim/admin_log/organization_presenter.rb +0 -2
- data/app/presenters/decidim/admin_log/participatory_space_private_user_presenter.rb +38 -0
- data/app/presenters/decidim/metric_charts_presenter.rb +53 -0
- data/app/presenters/decidim/metric_object_presenter.rb +28 -0
- data/app/presenters/decidim/user_group_presenter.rb +16 -8
- data/app/presenters/decidim/user_presenter.rb +14 -0
- data/app/queries/decidim/metric_manage.rb +59 -0
- data/app/queries/decidim/metrics/users_metric_manage.rb +26 -0
- data/app/queries/decidim/user_groups/accepted_memberships.rb +36 -0
- data/app/queries/decidim/user_groups/accepted_user_groups.rb +38 -0
- data/app/queries/decidim/user_groups/accepted_users.rb +36 -0
- data/app/queries/decidim/user_groups/admin_memberships.rb +37 -0
- data/app/queries/decidim/user_groups/invited_memberships.rb +36 -0
- data/app/queries/decidim/user_groups/manageable_user_groups.rb +39 -0
- data/app/queries/decidim/user_groups/member_memberships.rb +37 -0
- data/app/resolvers/decidim/core/metric_resolver.rb +38 -0
- data/app/services/decidim/action_logger.rb +4 -2
- data/app/services/decidim/activity_search.rb +76 -0
- data/app/services/decidim/continuity_badge_tracker.rb +64 -0
- data/app/services/decidim/resource_search.rb +0 -1
- data/app/types/decidim/core/metric_history_type.rb +17 -0
- data/app/types/decidim/core/metric_type.rb +14 -0
- data/app/types/decidim/core/session_type.rb +1 -1
- data/app/types/decidim/core/user_group_type.rb +2 -2
- data/app/views/decidim/authorization_modals/show.html.erb +40 -27
- data/app/views/decidim/devise/registrations/new.html.erb +0 -19
- data/app/views/decidim/gamification/badges/index.html.erb +42 -0
- data/app/views/decidim/group_admins/index.html.erb +18 -0
- data/app/views/decidim/group_invites/index.html.erb +27 -0
- data/app/views/decidim/group_members/index.html.erb +19 -0
- data/app/views/decidim/groups/_form.html.erb +23 -0
- data/app/views/decidim/groups/edit.html.erb +26 -0
- data/app/views/decidim/groups/new.html.erb +26 -0
- data/app/views/decidim/last_activities/_activities.html.erb +13 -0
- data/app/views/decidim/last_activities/index.html.erb +18 -0
- data/app/views/decidim/last_activities/index.js.erb +6 -0
- data/app/views/decidim/profiles/show.html.erb +1 -1
- data/app/views/layouts/decidim/_user_menu.html.erb +0 -1
- data/app/views/layouts/decidim/_wrapper.html.erb +1 -1
- data/config/initializers/devise.rb +1 -1
- data/config/initializers/foundation_rails_helper.rb +1 -0
- data/config/locales/ca.yml +325 -32
- data/config/locales/de.yml +325 -32
- data/config/locales/en.yml +325 -32
- data/config/locales/es-PY.yml +325 -32
- data/config/locales/es.yml +325 -32
- data/config/locales/eu.yml +325 -32
- data/config/locales/fi.yml +330 -37
- data/config/locales/fr.yml +325 -32
- data/config/locales/gl.yml +325 -32
- data/config/locales/hu.yml +327 -34
- data/config/locales/it.yml +325 -32
- data/config/locales/nl.yml +325 -32
- data/config/locales/pl.yml +329 -32
- data/config/locales/pt-BR.yml +326 -33
- data/config/locales/pt.yml +325 -32
- data/config/locales/ru.yml +4 -33
- data/config/locales/sv.yml +346 -53
- data/config/locales/uk.yml +4 -33
- data/config/routes.rb +27 -1
- data/db/migrate/20170128112958_change_user_groups_verified_to_timestamp.rb +11 -0
- data/db/migrate/20180705134647_create_decidim_metrics.rb +16 -0
- data/db/migrate/20180730071851_add_core_content_blocks.rb +3 -3
- data/db/migrate/20180810092428_move_organization_fields_to_hero_content_block.rb +4 -2
- data/db/migrate/20180918072506_add_visibility_to_action_logs.rb +8 -0
- data/db/migrate/20181001124950_move_users_groups_to_users_table.rb +84 -0
- data/db/migrate/20181008102144_add_badge_switch_to_organizations.rb +8 -0
- data/db/migrate/20181010044613_create_decidim_continuity_badge_statuses.rb +11 -0
- data/db/migrate/20181011080252_add_roles_to_memberships.rb +24 -0
- data/db/migrate/20181016091601_make_authors_polymorphic.rb +31 -0
- data/db/migrate/20181029112820_fix_user_follows.rb +18 -0
- data/db/migrate/20181030090144_destroy_deleted_users_follows.rb +16 -0
- data/db/seeds.rb +18 -4
- data/lib/decidim/attributes.rb +1 -0
- data/lib/decidim/attributes/localized_date.rb +16 -0
- data/lib/decidim/attributes/time_with_zone.rb +3 -1
- data/lib/decidim/authorable.rb +5 -4
- data/lib/decidim/authorization_form_builder.rb +2 -2
- data/lib/decidim/coauthorable.rb +68 -18
- data/lib/decidim/content_block_manifest.rb +7 -0
- data/lib/decidim/content_processor.rb +17 -7
- data/lib/decidim/core.rb +12 -0
- data/lib/decidim/core/engine.rb +54 -6
- data/lib/decidim/core/test/factories.rb +63 -17
- data/lib/decidim/core/test/shared_examples/coauthorable.rb +27 -9
- data/lib/decidim/core/test/shared_examples/coauthorable_interface_examples.rb +2 -2
- data/lib/decidim/core/version.rb +1 -1
- data/lib/decidim/data_portability.rb +3 -1
- data/lib/decidim/data_portability_file_reader.rb +1 -1
- data/lib/decidim/events/author_event.rb +4 -1
- data/lib/decidim/events/coauthor_event.rb +4 -1
- data/lib/decidim/faker/localized.rb +5 -4
- data/lib/decidim/form_builder.rb +18 -17
- data/lib/decidim/gamification.rb +8 -2
- data/lib/decidim/gamification/badge.rb +34 -0
- data/lib/decidim/gamification/badge_scorer.rb +29 -14
- data/lib/decidim/gamification/badge_status.rb +2 -0
- data/lib/decidim/hashtaggable.rb +1 -1
- data/lib/decidim/manifest_registry.rb +5 -3
- data/lib/decidim/metric_manifest.rb +20 -0
- data/lib/decidim/metric_registry.rb +71 -0
- data/lib/decidim/participable.rb +1 -1
- data/lib/decidim/participatory_space_resourceable.rb +0 -1
- data/lib/decidim/query_extensions.rb +19 -0
- data/lib/decidim/resourceable.rb +1 -0
- data/lib/decidim/searchable.rb +2 -1
- data/lib/tasks/decidim_metrics_tasks.rake +41 -0
- data/lib/tasks/decidim_tasks.rake +1 -0
- data/vendor/assets/javascripts/datepicker-locales/foundation-datepicker.ca.js +1 -2
- data/vendor/assets/javascripts/datepicker-locales/foundation-datepicker.es.js +1 -2
- data/vendor/assets/javascripts/datepicker-locales/foundation-datepicker.fr.js +1 -2
- data/vendor/assets/javascripts/datepicker-locales/foundation-datepicker.gl.js +1 -2
- data/vendor/assets/javascripts/datepicker-locales/foundation-datepicker.pt.js +1 -2
- data/vendor/assets/javascripts/datepicker-locales/foundation-datepicker.ru.js +1 -2
- data/vendor/assets/javascripts/datepicker-locales/foundation-datepicker.uk.js +1 -2
- data/vendor/assets/javascripts/form_datepicker.js.es6 +1 -11
- metadata +144 -23
- data/app/cells/decidim/invitations_toggle/content.erb +0 -1
- data/app/cells/decidim/invitations_toggle/label.erb +0 -1
- data/app/cells/decidim/invitations_toggle_cell.rb +0 -27
- data/app/cells/decidim/toggle/show.erb +0 -8
- data/app/cells/decidim/toggle_cell.rb +0 -42
- data/app/commands/decidim/invite_friends.rb +0 -48
- data/app/controllers/decidim/invitations_controller.rb +0 -32
- data/app/forms/decidim/invitations_form.rb +0 -37
- data/app/views/decidim/invitations/index.html.erb +0 -48
- data/app/views/devise/mailer/invite_friend.html.erb +0 -27
- data/app/views/devise/mailer/invite_friend.text.erb +0 -19
- data/lib/decidim/rectify_ext.rb +0 -32
@@ -16,6 +16,9 @@ module Decidim
|
|
16
16
|
# 10 points to get to level 3.
|
17
17
|
attribute :levels, Array, default: []
|
18
18
|
|
19
|
+
# An array of types for which this badge is valid for.
|
20
|
+
attribute :valid_for, Array[Symbol], default: [:user]
|
21
|
+
|
19
22
|
# (Optional) you can set a lambda in order to be able to reset the score of a
|
20
23
|
# badge if the progress gets lost somehow. The lambda receives a user as an
|
21
24
|
# argument.
|
@@ -43,12 +46,43 @@ module Decidim
|
|
43
46
|
levels.length
|
44
47
|
end
|
45
48
|
|
49
|
+
def translated_name
|
50
|
+
I18n.t "name", scope: translation_scope
|
51
|
+
end
|
52
|
+
|
53
|
+
def description(organization_name = nil)
|
54
|
+
I18n.t("description", organization_name: organization_name, scope: translation_scope)
|
55
|
+
end
|
56
|
+
|
57
|
+
def conditions
|
58
|
+
I18n.t("conditions", scope: translation_scope)
|
59
|
+
end
|
60
|
+
|
61
|
+
def score_descriptions(score)
|
62
|
+
{
|
63
|
+
unearned_own: I18n.t("unearned_own", scope: translation_scope),
|
64
|
+
description_own: I18n.t("description_own", score: score, scope: translation_scope),
|
65
|
+
unearned_another: I18n.t("unearned_another", scope: translation_scope),
|
66
|
+
description_another: I18n.t("description_another", score: score, scope: translation_scope)
|
67
|
+
}
|
68
|
+
end
|
69
|
+
|
46
70
|
# Public: Returns an image for this badge.
|
47
71
|
#
|
48
72
|
# Returns a String with the image.
|
49
73
|
def image
|
50
74
|
ActionController::Base.helpers.asset_path("decidim/gamification/badges/#{name}.svg")
|
51
75
|
end
|
76
|
+
|
77
|
+
def valid_for?(model)
|
78
|
+
valid_for.include?(model.class.name.demodulize.underscore.to_sym)
|
79
|
+
end
|
80
|
+
|
81
|
+
private
|
82
|
+
|
83
|
+
def translation_scope
|
84
|
+
"decidim.gamification.badges.#{name}"
|
85
|
+
end
|
52
86
|
end
|
53
87
|
end
|
54
88
|
end
|
@@ -2,20 +2,22 @@
|
|
2
2
|
|
3
3
|
module Decidim
|
4
4
|
module Gamification
|
5
|
-
# This class is responsible of updating scores given a
|
5
|
+
# This class is responsible of updating scores given a model and a badge. Will
|
6
6
|
# also trigger any side-effects such as notifications.
|
7
7
|
class BadgeScorer
|
8
8
|
# Public: Initializes the class.
|
9
9
|
#
|
10
|
-
#
|
10
|
+
# model - The model for which to update scores.
|
11
11
|
# badge - The `Badge` to update.
|
12
12
|
#
|
13
|
-
def initialize(
|
14
|
-
|
13
|
+
def initialize(model, badge)
|
14
|
+
raise "Invalid badge for this UserBase type" unless badge.valid_for?(model)
|
15
|
+
|
16
|
+
@model = model
|
15
17
|
@badge = badge
|
16
18
|
end
|
17
19
|
|
18
|
-
# Public: Increments the score for the
|
20
|
+
# Public: Increments the score for the model and badge.
|
19
21
|
#
|
20
22
|
# amount - Amount to increment. Defaults to 1.
|
21
23
|
#
|
@@ -25,13 +27,13 @@ module Decidim
|
|
25
27
|
|
26
28
|
with_level_tracking do
|
27
29
|
BadgeScore.find_or_create_by(
|
28
|
-
user: @
|
30
|
+
user: @model,
|
29
31
|
badge_name: @badge.name
|
30
32
|
).increment(:value, amount).save!
|
31
33
|
end
|
32
34
|
end
|
33
35
|
|
34
|
-
# Public: Decrements the score for the
|
36
|
+
# Public: Decrements the score for the model and badge.
|
35
37
|
#
|
36
38
|
# amount - Amount to decrement. Defaults to 1.
|
37
39
|
#
|
@@ -41,7 +43,7 @@ module Decidim
|
|
41
43
|
|
42
44
|
with_level_tracking do
|
43
45
|
badge_score = BadgeScore.find_by(
|
44
|
-
user: @
|
46
|
+
user: @model,
|
45
47
|
badge_name: @badge.name
|
46
48
|
)
|
47
49
|
|
@@ -53,7 +55,7 @@ module Decidim
|
|
53
55
|
end
|
54
56
|
end
|
55
57
|
|
56
|
-
# Public: Sets the score for the
|
58
|
+
# Public: Sets the score for the model and badge.
|
57
59
|
#
|
58
60
|
# score - Score to set.
|
59
61
|
#
|
@@ -63,7 +65,7 @@ module Decidim
|
|
63
65
|
|
64
66
|
with_level_tracking do
|
65
67
|
BadgeScore.find_or_create_by(
|
66
|
-
user_id: @
|
68
|
+
user_id: @model.id,
|
67
69
|
badge_name: @badge.name
|
68
70
|
).update!(value: score)
|
69
71
|
end
|
@@ -75,17 +77,18 @@ module Decidim
|
|
75
77
|
class InvalidAmountException < StandardError; end
|
76
78
|
|
77
79
|
def with_level_tracking
|
78
|
-
previous_level = BadgeStatus.new(@
|
80
|
+
previous_level = BadgeStatus.new(@model, @badge).level
|
79
81
|
|
80
82
|
yield
|
81
83
|
|
82
|
-
current_status = BadgeStatus.new(@
|
84
|
+
current_status = BadgeStatus.new(@model, @badge)
|
83
85
|
send_notification(previous_level, current_status.level)
|
84
86
|
current_status
|
85
87
|
end
|
86
88
|
|
87
89
|
def send_notification(previous_level, current_level)
|
88
90
|
return unless current_level > previous_level
|
91
|
+
return unless badges_enabled?
|
89
92
|
|
90
93
|
if previous_level.zero?
|
91
94
|
publish_event(name: "decidim.events.gamification.badge_earned",
|
@@ -104,8 +107,8 @@ module Decidim
|
|
104
107
|
Decidim::EventsManager.publish(
|
105
108
|
event: name,
|
106
109
|
event_class: klass,
|
107
|
-
resource: @
|
108
|
-
recipient_ids:
|
110
|
+
resource: @model,
|
111
|
+
recipient_ids: recipients,
|
109
112
|
extra: {
|
110
113
|
badge_name: @badge.name.to_s,
|
111
114
|
previous_level: previous_level,
|
@@ -113,6 +116,18 @@ module Decidim
|
|
113
116
|
}
|
114
117
|
)
|
115
118
|
end
|
119
|
+
|
120
|
+
def badges_enabled?
|
121
|
+
@model.organization.badges_enabled?
|
122
|
+
end
|
123
|
+
|
124
|
+
def recipients
|
125
|
+
if @model.is_a?(User)
|
126
|
+
[@model.id]
|
127
|
+
elsif @model.is_a?(UserGroup)
|
128
|
+
@model.users.pluck(:id)
|
129
|
+
end
|
130
|
+
end
|
116
131
|
end
|
117
132
|
end
|
118
133
|
end
|
data/lib/decidim/hashtaggable.rb
CHANGED
@@ -21,10 +21,12 @@ module Decidim
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def find(name)
|
24
|
+
name = name.to_s
|
24
25
|
manifests.find do |manifest|
|
25
|
-
manifest.
|
26
|
-
|
27
|
-
manifest.
|
26
|
+
manifest_name = manifest.name.to_s
|
27
|
+
manifest_name == name ||
|
28
|
+
manifest.try(:model_class_name) == name ||
|
29
|
+
manifest_name.pluralize == name
|
28
30
|
end
|
29
31
|
end
|
30
32
|
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
# This class acts as a manifest for metrics.
|
5
|
+
#
|
6
|
+
# This manifest is a simple object that holds and stores currently available
|
7
|
+
# metrics and his managers, for calculations purpose
|
8
|
+
#
|
9
|
+
class MetricManifest
|
10
|
+
include ActiveModel::Model
|
11
|
+
include Virtus.model
|
12
|
+
|
13
|
+
attribute :metric_name, String
|
14
|
+
attribute :manager_class, String
|
15
|
+
attribute :highlighted, String
|
16
|
+
attribute :position, Integer
|
17
|
+
|
18
|
+
validates :metric_name, :manager_class, presence: true
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
# This class acts as a registry for metrics. Each metric needs a name
|
5
|
+
# and a manager class, that will be used for calculations
|
6
|
+
#
|
7
|
+
# In order to register a metric, you can follow this example:
|
8
|
+
#
|
9
|
+
# Decidim.metrics_registry.register(
|
10
|
+
# :users_metric,
|
11
|
+
# "Decidim::Metrics::UsersMetricManage"
|
12
|
+
# )
|
13
|
+
#
|
14
|
+
# Metrics need to be registered in the `engine.rb` file of each module
|
15
|
+
class MetricRegistry
|
16
|
+
HIGHLIGHTED = "highlighted"
|
17
|
+
NOT_HIGHLIGHTED = "not-highlighted"
|
18
|
+
# Public: Registers a metric for calculations
|
19
|
+
#
|
20
|
+
# metric_name - a symbol representing the name of the metric
|
21
|
+
#
|
22
|
+
# manager_class - Manager class for specific metric calculation
|
23
|
+
#
|
24
|
+
# highlighted - value referencing if it's a highluithgted metric, or not
|
25
|
+
#
|
26
|
+
# Returns nothing. Raises an error if there's already a metric
|
27
|
+
# registered with that metric name.
|
28
|
+
def register(metric_name, manager_class, highlighted = NOT_HIGHLIGHTED, position = nil)
|
29
|
+
metric_name = metric_name.to_s
|
30
|
+
metric_exists = self.for(metric_name).present?
|
31
|
+
position ||= all.size + 1
|
32
|
+
|
33
|
+
if metric_exists
|
34
|
+
raise(
|
35
|
+
MetricAlreadyRegistered,
|
36
|
+
"There's a metric already registered with the name `:#{metric_name}`, must be unique"
|
37
|
+
)
|
38
|
+
end
|
39
|
+
|
40
|
+
metric_manifest = MetricManifest.new(metric_name: metric_name, manager_class: manager_class, highlighted: highlighted, position: position)
|
41
|
+
|
42
|
+
metric_manifest.validate!
|
43
|
+
|
44
|
+
metrics_manifests << metric_manifest
|
45
|
+
end
|
46
|
+
|
47
|
+
def for(metric_name)
|
48
|
+
all.find { |manifest| manifest.metric_name == metric_name }
|
49
|
+
end
|
50
|
+
|
51
|
+
def all
|
52
|
+
metrics_manifests
|
53
|
+
end
|
54
|
+
|
55
|
+
def highlighted
|
56
|
+
all.find_all { |manifest| manifest.highlighted == HIGHLIGHTED }.sort_by(&:position)
|
57
|
+
end
|
58
|
+
|
59
|
+
def not_highlighted
|
60
|
+
all.find_all { |manifest| manifest.highlighted == NOT_HIGHLIGHTED }.sort_by(&:position)
|
61
|
+
end
|
62
|
+
|
63
|
+
class MetricAlreadyRegistered < StandardError; end
|
64
|
+
|
65
|
+
private
|
66
|
+
|
67
|
+
def metrics_manifests
|
68
|
+
@metrics_manifests ||= []
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
data/lib/decidim/participable.rb
CHANGED
@@ -51,7 +51,6 @@ module Decidim
|
|
51
51
|
def participatory_space_sibling_scope(participatory_space_name)
|
52
52
|
manifest = Decidim.find_participatory_space_manifest(participatory_space_name)
|
53
53
|
return self.class.none unless manifest
|
54
|
-
|
55
54
|
scope = manifest.participatory_spaces.call(organization)
|
56
55
|
|
57
56
|
scope
|
@@ -75,6 +75,25 @@ module Decidim
|
|
75
75
|
Decidim::HashtagsResolver.new(ctx[:current_organization], args[:name]).hashtags
|
76
76
|
}
|
77
77
|
end
|
78
|
+
|
79
|
+
type.field :metrics do
|
80
|
+
type types[Decidim::Core::MetricType]
|
81
|
+
argument :names, types[types.String], "The names of the metrics you want to retrieve"
|
82
|
+
|
83
|
+
resolve lambda { |_, args, ctx|
|
84
|
+
manifests = if args[:names].blank?
|
85
|
+
Decidim.metrics_registry.all
|
86
|
+
else
|
87
|
+
Decidim.metrics_registry.all.select do |manifest|
|
88
|
+
args[:names].include?(manifest.metric_name.to_s)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
manifests.map do |manifest|
|
93
|
+
Decidim::Core::MetricResolver.new(manifest.metric_name, ctx[:current_organization])
|
94
|
+
end
|
95
|
+
}
|
96
|
+
end
|
78
97
|
end
|
79
98
|
end
|
80
99
|
end
|
data/lib/decidim/resourceable.rb
CHANGED
data/lib/decidim/searchable.rb
CHANGED
@@ -94,7 +94,8 @@ module Decidim
|
|
94
94
|
decidim_participatory_space_id: fields[:decidim_participatory_space_id],
|
95
95
|
decidim_participatory_space_type: fields[:decidim_participatory_space_type],
|
96
96
|
decidim_organization_id: fields[:decidim_organization_id],
|
97
|
-
|
97
|
+
resource_id: id,
|
98
|
+
resource_type: self.class.name
|
98
99
|
}
|
99
100
|
end
|
100
101
|
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
namespace :decidim do
|
4
|
+
namespace :metrics do
|
5
|
+
# All ------
|
6
|
+
#
|
7
|
+
# Get all metrics entities and execute his own rake task.
|
8
|
+
# It admits a date-string parameter, in a 'YYYY-MM-DD' format from
|
9
|
+
# today to all past dates
|
10
|
+
desc "Execute all metrics calculation methods"
|
11
|
+
task :all, [:day] => :environment do |_task, args|
|
12
|
+
Decidim::Organization.find_each do |organization|
|
13
|
+
Decidim.metrics_registry.all.each do |metric_manifest|
|
14
|
+
call_metric_job(metric_manifest, organization, args.day)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# One ------
|
20
|
+
#
|
21
|
+
# Execute metric calculations for just one metric
|
22
|
+
# It need a metric name and permits a date-string parameter, in a 'YYYY-MM-DD' format from
|
23
|
+
# today to all past dates
|
24
|
+
desc "Execute one metric calculation method"
|
25
|
+
task :one, [:metric, :day] => :environment do |_task, args|
|
26
|
+
next if args.metric.blank?
|
27
|
+
Decidim::Organization.find_each do |organization|
|
28
|
+
metric_manifest = Decidim.metrics_registry.for(args.metric)
|
29
|
+
call_metric_job(metric_manifest, organization, args.day)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def call_metric_job(metric_manifest, organization, day = nil)
|
34
|
+
Decidim::MetricJob.perform_later(
|
35
|
+
metric_manifest.manager_class,
|
36
|
+
organization.id,
|
37
|
+
day
|
38
|
+
)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -10,7 +10,6 @@
|
|
10
10
|
months: ["Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre"],
|
11
11
|
monthsShort: ["Ene", "Feb", "Mar", "Abr", "May", "Jun", "Jul", "Ago", "Sep", "Oct", "Nov", "Dic"],
|
12
12
|
today: "Hoy",
|
13
|
-
weekStart: 1
|
14
|
-
format: "dd/mm/yyyy"
|
13
|
+
weekStart: 1
|
15
14
|
};
|
16
15
|
}(jQuery));
|