|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +module Decidim |
| 4 | + module Content |
| 5 | + class MeetingSerializer < Decidim::Exporters::Serializer |
| 6 | + include Decidim::Content::SerializerTools |
| 7 | + |
| 8 | + def serialize |
| 9 | + { |
| 10 | + uid: uid(resource), |
| 11 | + author: uid(identity(resource)), |
| 12 | + category: uid(resource.try(:category)), |
| 13 | + scope: uid(resource.try(:scope)), |
| 14 | + title: normalize_translated_attribute(resource.try(:title)), |
| 15 | + description: normalize_translated_attribute(resource.try(:description)), |
| 16 | + start_time: resource.try(:start_time), |
| 17 | + end_time: resource.try(:end_time), |
| 18 | + type_of_meeting: resource.try(:type_of_meeting), |
| 19 | + online_meeting_url: resource.try(:online_meeting_url), |
| 20 | + video_url: resource.try(:video_url), |
| 21 | + audio_url: resource.try(:audio_url), |
| 22 | + address: resource.try(:address), |
| 23 | + latitude: resource.try(:latitude), |
| 24 | + longitude: resource.try(:longitude), |
| 25 | + location: resource.try(:location), |
| 26 | + location_hints: resource.try(:location_hints), |
| 27 | + private_meeting: resource.try(:private_meeting), |
| 28 | + transparent: resource.try(:transparent), |
| 29 | + agenda: serialize_agenda, |
| 30 | + services: serialize_services, |
| 31 | + created_at: resource.try(:created_at), |
| 32 | + updated_at: resource.try(:updated_at), |
| 33 | + published_at: resource.try(:published_at), |
| 34 | + withdrawn: resource.withdrawn?, |
| 35 | + withdrawn_at: resource.try(:withdrawn_at), |
| 36 | + registrations_enabled: resource.try(:registrations_enabled), |
| 37 | + available_slots: resource.try(:available_slots), |
| 38 | + reserved_slots: resource.try(:reserved_slots), |
| 39 | + registration_terms: normalize_translated_attribute(resource.try(:registration_terms)), |
| 40 | + registration_type: resource.try(:registration_type), |
| 41 | + # enable_registration_confirmation: resource.try(:enable_registration_confirmation), |
| 42 | + # enable_cancellation: resource.try(:enable_cancellation), |
| 43 | + # disable_account_confirmation: resource.try(:disable_account_confirmation), |
| 44 | + customize_registration_email: resource.try(:customize_registration_email), |
| 45 | + registration_email_custom_content: normalize_translated_attribute(resource.try(:registration_email_custom_content)), |
| 46 | + salt: resource.try(:salt), |
| 47 | + registration_url: resource.try(:registration_url), |
| 48 | + registration_form_enabled: resource.try(:registration_form_enabled), |
| 49 | + registration_form: convert_questionnaire_json_to_uid(serialize_questionnaire(resource.try(:questionnaire))), |
| 50 | + attendees_count: resource.try(:attendees_count), |
| 51 | + contributions_count: resource.try(:contributions_count), |
| 52 | + attending_organizations: resource.try(:attending_organizations), |
| 53 | + poll: convert_questionnaire_json_to_uid(serialize_questionnaire(resource.try(:poll)&.questionnaire), module_prefix: "Decidim::Meetings"), |
| 54 | + comments_enabled: resource.try(:comments_enabled), |
| 55 | + comments_count: resource.try(:comments_count), |
| 56 | + comments_start_time: resource.try(:comments_start_time), |
| 57 | + comments_end_time: resource.try(:comments_end_time), |
| 58 | + followers_count: resource.try(:follows).try(:size), |
| 59 | + related_proposals: resource.linked_resources(:proposals, "proposals_from_meeting").map { |proposal| uid(proposal) }, |
| 60 | + related_results: resource.linked_resources(:results, "meetings_through_proposals").map { |result| uid(result) }, |
| 61 | + closing_visible: resource.try(:closing_visible), |
| 62 | + closing_report: normalize_translated_attribute(resource.try(:closing_report)), |
| 63 | + component: uid(resource.try(:component)), |
| 64 | + url: Decidim::ResourceLocatorPresenter.new(resource).url |
| 65 | + } |
| 66 | + end |
| 67 | + |
| 68 | + def serialize_agenda |
| 69 | + return if (agenda = resource.try(:agenda)).blank? |
| 70 | + |
| 71 | + { |
| 72 | + uid: uid(agenda), |
| 73 | + title: normalize_translated_attribute(agenda.try(:title)), |
| 74 | + description: normalize_translated_attribute(agenda.try(:description)), |
| 75 | + duration: agenda.try(:duration), |
| 76 | + items: agenda.agenda_items.first_class.map do |item| |
| 77 | + { |
| 78 | + uid: uid(item), |
| 79 | + title: normalize_translated_attribute(item.try(:title)), |
| 80 | + description: normalize_translated_attribute(item.try(:description)), |
| 81 | + duration: item.try(:duration), |
| 82 | + items: item.agenda_item_children.map do |child_item| |
| 83 | + { |
| 84 | + uid: uid(child_item), |
| 85 | + title: normalize_translated_attribute(child_item.try(:title)), |
| 86 | + description: normalize_translated_attribute(child_item.try(:description)), |
| 87 | + duration: child_item.try(:duration) |
| 88 | + } |
| 89 | + end |
| 90 | + } |
| 91 | + end |
| 92 | + } |
| 93 | + end |
| 94 | + |
| 95 | + def serialize_services |
| 96 | + return if (services = resource.try(:services)).blank? |
| 97 | + |
| 98 | + services.map do |service| |
| 99 | + { |
| 100 | + uid: uid(service), |
| 101 | + title: normalize_translated_attribute(service.try(:title)), |
| 102 | + description: normalize_translated_attribute(service.try(:description)) |
| 103 | + } |
| 104 | + end |
| 105 | + end |
| 106 | + end |
| 107 | + end |
| 108 | +end |
0 commit comments