diff --git a/.env b/.env deleted file mode 100644 index 7893556..0000000 --- a/.env +++ /dev/null @@ -1,29 +0,0 @@ -# INTERNAL CONFIGURATION - -# postgres -DB_PORT_5432_TCP_ADDR=localhost -DB_ENV_POSTGRESQL_USER=postgres -DB_ENV_POSTGRESQL_DB=church_resources_development -DB_ENV_POSTGRESQL_PASS= - -# redis -REDIS_URL=redis://localhost:6379 - -# local app configuration -SECRET_KEY_BASE=secret_key_base - -# EXTERNAL SERVICE CONFIGURATION - -# name: Amazon Web Services SES -# desc: Simple Email Service -# url: https://aws.amazon.com/ -SES_ACCESS_KEY=SES_ACCESS_KEY -SES_SECRET_KEY=SES_SECRET_KEY - -# name: Amazon Web Services S3 -# desc: Simple Storage Service -# url: https://aws.amazon.com/ -AWS_BUCKET=AWS_BUCKET -AWS_ACCESS_KEY_ID=AWS_S3_ACCESS_KEY_ID -AWS_SECRET_ACCESS_KEY=AWS_S3_SECRET_ACCESS_KEY -AWS_REGION=AWS_REGION diff --git a/.gitignore b/.gitignore index 880204d..30a087a 100644 --- a/.gitignore +++ b/.gitignore @@ -37,3 +37,5 @@ yarn-debug.log* /.env*.local /config/credentials/production.key + +/config/credentials/development.key diff --git a/Procfile b/Procfile deleted file mode 100644 index f42dc75..0000000 --- a/Procfile +++ /dev/null @@ -1,2 +0,0 @@ -web: bundle exec puma -C config/puma.rb -release: rails db:migrate diff --git a/app/admin/location_connection_steps.rb b/app/admin/location_connection_steps.rb deleted file mode 100644 index 65f6ef6..0000000 --- a/app/admin/location_connection_steps.rb +++ /dev/null @@ -1,26 +0,0 @@ -# frozen_string_literal: true - -ActiveAdmin.register Location::Connection::Step do - menu parent: 'Locations', label: 'Steps' - permit_params :content, - :elvanto_form_id, - :mail_chimp_user_id, - :mail_chimp_audience_id, - :location_id, - :step_id, - :fluro_form_url - - form do |f| - f.semantic_errors - inputs do - f.input :location - f.input :step - f.input :content, as: :text - f.input :elvanto_form_id - f.input :mail_chimp_user_id - f.input :mail_chimp_audience_id - f.input :fluro_form_url - end - f.actions - end -end diff --git a/app/admin/location_events.rb b/app/admin/location_events.rb deleted file mode 100644 index 7ab1ddd..0000000 --- a/app/admin/location_events.rb +++ /dev/null @@ -1,53 +0,0 @@ -# frozen_string_literal: true - -ActiveAdmin.register Location::Event do - menu parent: 'Locations', label: 'Events' - permit_params :banner, :name, :content, :start_at, :end_at, :address, :elvanto_form_id, :facebook_url, :location_id, - :registration_url - - scope :upcoming, default: true - scope :featured - scope :all - - batch_action :feature do |ids| - batch_action_collection.find(ids).each do |event| - event.update(featured_at: Time.zone.now) - end - redirect_to collection_path, success: 'The event(s) have been featured' - end - - batch_action :unfeature do |ids| - batch_action_collection.find(ids).each do |event| - event.update(featured_at: nil) - end - redirect_to collection_path, warning: 'The event(s) have been unfeatured' - end - - index do - selectable_column - column :name - column :location - column :address - column :start_at - column :end_at - column :featured_at - actions - end - - form do |f| - f.semantic_errors - inputs do - f.input :name - f.input :banner, as: :file - f.input :content, as: :trix - f.input :location - f.input :start_at, as: :date_time_picker - f.input :end_at, as: :date_time_picker - f.input :address - f.input :elvanto_form_id - f.input :registration_url - f.input :facebook_url - end - f.actions - end -end diff --git a/app/admin/location_prayers.rb b/app/admin/location_prayers.rb deleted file mode 100644 index 16fcceb..0000000 --- a/app/admin/location_prayers.rb +++ /dev/null @@ -1,18 +0,0 @@ -# frozen_string_literal: true - -ActiveAdmin.register Location::Prayer do - menu parent: 'Locations', label: 'Prayers' - permit_params :banner, :name, :snippet, :content, :location_id - - form do |f| - f.semantic_errors - inputs do - f.input :name - f.input :banner, as: :file - f.input :snippet - f.input :content, as: :text - f.input :location - end - f.actions - end -end diff --git a/app/admin/location_services.rb b/app/admin/location_services.rb deleted file mode 100644 index 28f0a60..0000000 --- a/app/admin/location_services.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true - -ActiveAdmin.register Location::Service do - menu parent: 'Locations', label: 'Services' - permit_params :start_at, :end_at, :location_id, :elvanto_form_id - - form do |f| - f.semantic_errors - inputs do - f.input :start_at, as: :date_time_picker - f.input :end_at, as: :date_time_picker - f.input :location - f.input :elvanto_form_id - end - f.actions - end -end diff --git a/app/admin/locations.rb b/app/admin/locations.rb deleted file mode 100644 index 995838d..0000000 --- a/app/admin/locations.rb +++ /dev/null @@ -1,22 +0,0 @@ -# frozen_string_literal: true - -ActiveAdmin.register Location do - permit_params :name, :snippet, :content, :address, :banner - - filter :name - filter :snippet - filter :content - filter :address - - form do |f| - f.semantic_errors - inputs do - f.input :name - f.input :banner, as: :file - f.input :snippet - f.input :content, as: :text - f.input :address - end - f.actions - end -end diff --git a/app/admin/resource_articles.rb b/app/admin/resource_articles.rb deleted file mode 100644 index 81e3c35..0000000 --- a/app/admin/resource_articles.rb +++ /dev/null @@ -1,44 +0,0 @@ -# frozen_string_literal: true - -ActiveAdmin.register Resource::Article do - menu parent: 'Resources', label: 'Articles' - config.sort_order = 'published_at_desc' - - permit_params :name, :snippet, :content, :banner, :published_at, :featured_at, - topic_ids: [], author_ids: [], scripture_ids: [], series_ids: [] - - filter :name - filter :snippet - filter :content - filter :published_at - filter :featured_at - filter :author - filter :scripture - filter :series - filter :topic - - index do - id_column - column :name - column :published_at - column :featured_at - actions - end - - form do |f| - f.semantic_errors - inputs do - f.input :name - f.input :published_at, as: :date_time_picker - f.input :featured_at, as: :date_time_picker - f.input :snippet - f.input :content, as: :text - f.input :banner, as: :file - f.input :topics, collection: Category::Topic.all, multiple: true, input_html: { class: 'chosen-select' } - f.input :authors, collection: Author.all, multiple: true, input_html: { class: 'chosen-select' } - f.input :scriptures, collection: Scripture.all, multiple: true - f.input :series, collection: Series.all, multiple: true, input_html: { class: 'chosen-select' } - end - f.actions - end -end diff --git a/app/admin/resource_sermons.rb b/app/admin/sermons.rb similarity index 82% rename from app/admin/resource_sermons.rb rename to app/admin/sermons.rb index 33c602a..45a85a5 100644 --- a/app/admin/resource_sermons.rb +++ b/app/admin/sermons.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true # rubocop:disable Metrics/BlockLength -ActiveAdmin.register Resource::Sermon do - menu parent: 'Resources', label: 'Sermons' +ActiveAdmin.register Sermon do + menu label: 'Sermons' config.sort_order = 'published_at_desc' order_by :published_at do |order_clause| @@ -12,7 +12,7 @@ permit_params :name, :snippet, :content, :video, :audio, :youtube_url, :audio_url, :published_at, :featured_at, :sermon_notes, :connect_group_notes, topic_ids: [], author_ids: [], scripture_ids: [], series_ids: [], - connection_scriptures_attributes: %i[id resource_id scripture_id range _destroy] + sermon_scriptures_attributes: %i[id sermon_id scripture_id range _destroy] filter :name filter :snippet @@ -22,12 +22,12 @@ filter :series, collection: proc { Series.order(:name).all } batch_action :publish do |ids| - Resource::Sermon.batch_publish(ids) + Sermon.batch_publish(ids) redirect_to collection_path, notice: "#{ids.size} sermon(s) published" end batch_action :unpublish do |ids| - Resource::Sermon.batch_unpublish(ids) + Sermon.batch_unpublish(ids) redirect_to collection_path, notice: "#{ids.size} sermon(s) unpublished" end @@ -54,7 +54,7 @@ f.input :audio, as: :file f.input :topics, collection: Category::Topic.all, multiple: true f.input :authors, collection: Author.all, multiple: true - f.has_many :connection_scriptures, heading: 'Bible Passage', new_record: 'Add Passage Range' do |a| + f.has_many :sermon_scriptures, heading: 'Bible Passage', new_record: 'Add Passage Range' do |a| a.input :scripture, collection: Scripture.all, label: 'Book' a.input :range end diff --git a/app/admin/steps.rb b/app/admin/steps.rb deleted file mode 100644 index 2044c4c..0000000 --- a/app/admin/steps.rb +++ /dev/null @@ -1,63 +0,0 @@ -# frozen_string_literal: true - -ActiveAdmin.register Step do - permit_params :name, :content, :banner - config.sort_order = 'position_asc' - - scope :featured - scope :all, default: true - - filter :name - filter :created_at - filter :updated_at - - batch_action :feature do |ids| - batch_action_collection.find(ids).each do |step| - step.update(featured_at: Time.zone.now) - end - redirect_to collection_path, alert: 'The step(s) have been featured' - end - - batch_action :unfeature do |ids| - batch_action_collection.find(ids).each do |event| - event.update(featured_at: nil) - end - redirect_to collection_path, warning: 'The step(s) have been unfeatured' - end - - index do - selectable_column - column do |post| - [ - link_to(icon('chevron-up', 'font-awesome'), move_higher_admin_step_path(post)), - link_to(icon('chevron-down', 'font-awesome'), move_lower_admin_step_path(post)) - ].join(' ').html_safe - end - column :position - column :name - column :featured_at - actions - end - - member_action :move_higher, method: :get do - flash[:notice] = "#{resource.name} moved higher" - resource.move_higher - redirect_to action: :index - end - - member_action :move_lower, method: :get do - flash[:notice] = "#{resource.name} moved lower" - resource.move_lower - redirect_to action: :index - end - - form do |f| - f.semantic_errors - inputs do - f.input :name - f.input :banner, as: :file - f.input :content, as: :text - end - f.actions - end -end diff --git a/app/constraints/resource_type_constraint.rb b/app/constraints/resource_type_constraint.rb deleted file mode 100644 index 84b7aea..0000000 --- a/app/constraints/resource_type_constraint.rb +++ /dev/null @@ -1,7 +0,0 @@ -# frozen_string_literal: true - -class ResourceTypeConstraint - def matches?(request) - request.params[:resource_type].blank? || Resource::TYPES.keys.include?(request.params[:resource_type].to_sym) - end -end diff --git a/app/controllers/resources/authors_controller.rb b/app/controllers/resources/authors_controller.rb index 8bac777..2db590c 100644 --- a/app/controllers/resources/authors_controller.rb +++ b/app/controllers/resources/authors_controller.rb @@ -17,10 +17,7 @@ def show def load_resources return @resources if @resources - @resources = Resource.order(published_at: :desc).joins(:authors).where(authors: { id: [@author.id] }) - if params[:resource_type].present? - @resources = @resources.where(type: Resource::TYPES[params[:resource_type].to_sym]) - end + @resources = Sermon.order(published_at: :desc).joins(:authors).where(authors: { id: [@author.id] }) @resources = @resources.published.page params[:page] end @@ -43,8 +40,6 @@ def alphabetized_authors end def scope - return ::Author unless params[:resource_type] - - ::Author.joins(:resources).where(resources: { type: Resource::TYPES[params[:resource_type].to_sym] }).distinct + ::Author end end diff --git a/app/controllers/resources/scriptures_controller.rb b/app/controllers/resources/scriptures_controller.rb index 58879e6..a67c4ca 100644 --- a/app/controllers/resources/scriptures_controller.rb +++ b/app/controllers/resources/scriptures_controller.rb @@ -17,10 +17,7 @@ def show def load_resources return @resources if @resources - @resources = Resource.order(published_at: :desc).joins(:scriptures).where(scriptures: { id: [@scripture.id] }) - if params[:resource_type].present? - @resources = @resources.where(type: Resource::TYPES[params[:resource_type].to_sym]) - end + @resources = Sermon.order(published_at: :desc).joins(:scriptures).where(scriptures: { id: [@scripture.id] }) @resources = @resources.published.page params[:page] end @@ -43,8 +40,6 @@ def alphabetized_scripture end def scope - return ::Scripture unless params[:resource_type] - - ::Scripture.joins(:resources).where(resources: { type: Resource::TYPES[params[:resource_type].to_sym] }).distinct + ::Scripture end end diff --git a/app/controllers/resources/series_controller.rb b/app/controllers/resources/series_controller.rb index c25d4e6..ae95f24 100644 --- a/app/controllers/resources/series_controller.rb +++ b/app/controllers/resources/series_controller.rb @@ -17,10 +17,7 @@ def show def load_resources return @resources if @resources - @resources = Resource.order(published_at: :desc).joins(:series).where(series: { id: [@series.id] }) - if params[:resource_type].present? - @resources = @resources.where(type: Resource::TYPES[params[:resource_type].to_sym]) - end + @resources = Sermon.order(published_at: :desc).joins(:series).where(series: { id: [@series.id] }) @resources = @resources.published.page params[:page] end @@ -43,8 +40,6 @@ def alphabetized_series end def scope - return ::Series unless params[:resource_type] - - ::Series.joins(:resources).where(resources: { type: Resource::TYPES[params[:resource_type].to_sym] }).distinct + ::Series end end diff --git a/app/controllers/resources/topics_controller.rb b/app/controllers/resources/topics_controller.rb index 22cb289..e2625f8 100644 --- a/app/controllers/resources/topics_controller.rb +++ b/app/controllers/resources/topics_controller.rb @@ -17,10 +17,7 @@ def show def load_resources return @resources if @resources - @resources = Resource.order(published_at: :desc).joins(:topics).where(category_topics: { id: [@topic.id] }) - if params[:resource_type].present? - @resources = @resources.where(type: Resource::TYPES[params[:resource_type].to_sym]) - end + @resources = Sermon.order(published_at: :desc).joins(:topics).where(category_topics: { id: [@topic.id] }) @resources = @resources.published.page params[:page] end @@ -33,18 +30,10 @@ def load_topic end def category_scope - return ::Category.joins(topics: :resources).distinct unless params[:resource_type] - - ::Category.joins(topics: :resources).where( - resources: { type: Resource::TYPES[params[:resource_type].to_sym] } - ).distinct + ::Category.joins(topics: :sermons).distinct end def scope - return ::Category::Topic unless params[:resource_type] - - ::Category::Topic.joins(:resources).where( - resources: { type: Resource::TYPES[params[:resource_type].to_sym] } - ).distinct + ::Category::Topic end end diff --git a/app/controllers/resources_controller.rb b/app/controllers/resources_controller.rb index f277594..d2c5d3c 100644 --- a/app/controllers/resources_controller.rb +++ b/app/controllers/resources_controller.rb @@ -20,9 +20,6 @@ def load_resources return @resources if @resources @resources = scope.order(published_at: :desc).published - if params[:resource_type].present? - @resources = @resources.where(type: Resource::TYPES[params[:resource_type].to_sym]) - end @resources = @resources.page params[:page] end @@ -31,7 +28,7 @@ def load_resource end def scope - ::Resource + ::Sermon end def render_rss_feed @@ -39,15 +36,12 @@ def render_rss_feed latest_update = resource_scope.maximum(:updated_at) cache_key_parts = %w[v1 rss resources] - if params[:resource_type].present? && Resource::TYPES.key?(params[:resource_type].to_sym) - cache_key_parts << params[:resource_type] - end cache_key_parts << latest_update.utc.to_fs(:number) if latest_update response.headers['Content-Type'] = 'application/rss+xml; charset=utf-8' cached_rss_content = Rails.cache.fetch(cache_key_parts.compact.join('/'), expires_in: 1.day) do - @resources = resource_scope.includes(:authors, :connection_scriptures) + @resources = resource_scope.includes(:authors, :sermon_scriptures) render_to_string template: 'resources/index', formats: [:rss] end @@ -55,10 +49,6 @@ def render_rss_feed end def rss_resources_scope - resources = scope.order(published_at: :desc).published - if params[:resource_type].present? && Resource::TYPES.key?(params[:resource_type].to_sym) - resources = resources.where(type: Resource::TYPES[params[:resource_type].to_sym]) - end - resources + scope.order(published_at: :desc).published end end diff --git a/app/decorators/resource/article_decorator.rb b/app/decorators/resource/article_decorator.rb deleted file mode 100644 index 0e3265d..0000000 --- a/app/decorators/resource/article_decorator.rb +++ /dev/null @@ -1,7 +0,0 @@ -# frozen_string_literal: true - -class Resource::ArticleDecorator < ResourceDecorator - def action - 'read' - end -end diff --git a/app/decorators/resource/sermon_decorator.rb b/app/decorators/resource/sermon_decorator.rb deleted file mode 100644 index d25e629..0000000 --- a/app/decorators/resource/sermon_decorator.rb +++ /dev/null @@ -1,15 +0,0 @@ -# frozen_string_literal: true - -class Resource::SermonDecorator < ResourceDecorator - def banner - object.banner.presence || object.series.first&.banner - end - - def foreground - object.foreground.presence || object.series.first&.foreground - end - - def background - object.background.presence || object.series.first&.background - end -end diff --git a/app/decorators/resource_decorator.rb b/app/decorators/resource_decorator.rb deleted file mode 100644 index a4a57d3..0000000 --- a/app/decorators/resource_decorator.rb +++ /dev/null @@ -1,49 +0,0 @@ -# frozen_string_literal: true - -class ResourceDecorator < ApplicationDecorator - decorates_association :connection_scriptures - decorates_association :authors - - def action - 'view' - end - - def type_title - type_param.titleize - end - - def type_param - type.demodulize.downcase - end - - def related - resources = related_resource_scope - resources = resources.where(series: { id: resource.series.pluck(:id) }) - resources = resources.or(resources.where(category_topics: { id: resource.topics.pluck(:id) })) - resources = resources.or(resources.where(authors: { id: resource.authors.pluck(:id) })) - resources = resources.or(resources.where(scriptures: { id: resource.scriptures.pluck(:id) })) - resources.decorate - end - - def description - return snippet if snippet.present? - - author_names = authors.map(&:name).join(', ') - scripture_names = connection_scriptures.map(&:name).join(', ') - display_published_at = published_at.strftime('%b %d, %Y') - - [author_names, scripture_names, display_published_at].compact_blank.join(' | ') - end - - def author_names - resource.authors.map(&:name).join(', ') - end - - def related_resource_scope - Resource.published - .order('RANDOM()') - .limit(3) - .left_outer_joins(:series, :authors, :topics, :scriptures) - .where.not(id: id) - end -end diff --git a/app/decorators/sermon_decorator.rb b/app/decorators/sermon_decorator.rb new file mode 100644 index 0000000..f611785 --- /dev/null +++ b/app/decorators/sermon_decorator.rb @@ -0,0 +1,61 @@ +# frozen_string_literal: true + +class SermonDecorator < ApplicationDecorator + decorates_association :sermon_scriptures + decorates_association :authors + + def action + 'view' + end + + def type_title + 'Sermon' + end + + def type_param + 'sermon' + end + + def banner + object.banner.presence || object.series.first&.banner + end + + def foreground + object.foreground.presence || object.series.first&.foreground + end + + def background + object.background.presence || object.series.first&.background + end + + def related + sermons = related_sermon_scope + sermons = sermons.where(series: { id: object.series.pluck(:id) }) + sermons = sermons.or(sermons.where(category_topics: { id: object.topics.pluck(:id) })) + sermons = sermons.or(sermons.where(authors: { id: object.authors.pluck(:id) })) + sermons = sermons.or(sermons.where(scriptures: { id: object.scriptures.pluck(:id) })) + sermons.decorate + end + + def description + return snippet if snippet.present? + + author_names = authors.map(&:name).join(', ') + scripture_names = sermon_scriptures.map(&:name).join(', ') + display_published_at = published_at.strftime('%b %d, %Y') + + [author_names, scripture_names, display_published_at].compact_blank.join(' | ') + end + + def author_names + object.authors.map(&:name).join(', ') + end + + def related_sermon_scope + Sermon.published + .order('RANDOM()') + .limit(3) + .left_outer_joins(:series, :authors, :topics, :scriptures) + .where.not(id: id) + end +end diff --git a/app/decorators/resource/connection/scripture_decorator.rb b/app/decorators/sermon_scripture_decorator.rb similarity index 54% rename from app/decorators/resource/connection/scripture_decorator.rb rename to app/decorators/sermon_scripture_decorator.rb index e088ab0..ba8ed10 100644 --- a/app/decorators/resource/connection/scripture_decorator.rb +++ b/app/decorators/sermon_scripture_decorator.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class Resource::Connection::ScriptureDecorator < ApplicationDecorator +class SermonScriptureDecorator < ApplicationDecorator def name "#{scripture.name} #{range}" end diff --git a/app/graphql/queries/authors_query.rb b/app/graphql/queries/authors_query.rb index 4da73ad..0f63336 100644 --- a/app/graphql/queries/authors_query.rb +++ b/app/graphql/queries/authors_query.rb @@ -2,17 +2,8 @@ class Queries::AuthorsQuery < Queries::BaseQuery type Types::AuthorType.connection_type, null: false - argument :resource_type, String, required: false - def resolve(resource_type: nil) - scope(resource_type).all - end - - protected - - def scope(resource_type) - return ::Author if resource_type.blank? - - ::Author.joins(:resources).where(resources: { type: Resource::TYPES[resource_type.to_sym] }).distinct + def resolve + ::Author.joins(:sermons).distinct end end diff --git a/app/graphql/queries/categories_query.rb b/app/graphql/queries/categories_query.rb index 7329b34..7be9e86 100644 --- a/app/graphql/queries/categories_query.rb +++ b/app/graphql/queries/categories_query.rb @@ -2,17 +2,8 @@ class Queries::CategoriesQuery < Queries::BaseQuery type Types::CategoryType.connection_type, null: false - argument :resource_type, String, required: false - def resolve(resource_type: nil) - scope(resource_type).all - end - - protected - - def scope(resource_type) - return ::Category if resource_type.blank? - - ::Category.joins(:resources).where(resources: { type: Resource::TYPES[resource_type.to_sym] }).distinct + def resolve + ::Category.joins(topics: :sermons).distinct end end diff --git a/app/graphql/queries/events_query.rb b/app/graphql/queries/events_query.rb deleted file mode 100644 index fdf83bb..0000000 --- a/app/graphql/queries/events_query.rb +++ /dev/null @@ -1,30 +0,0 @@ -# frozen_string_literal: true - -class Queries::EventsQuery < Queries::BaseQuery - type Types::Location::EventType.connection_type, null: false - argument :featured, Boolean, required: false - argument :ids, [ID], required: false - argument :location_ids, [ID], required: false - - def resolve(ids: nil, location_ids: nil, featured: false) - scope(ids, location_ids, featured).all - end - - protected - - def scope(ids, location_ids, featured) - scope = ::Location::Event.upcoming - scope = filter_by_ids(scope, ids) - scope = filter_by_locations(scope, location_ids) - - featured ? scope.featured : scope - end - - def filter_by_ids(scope, ids) - ids.present? ? scope.where(id: ids) : scope - end - - def filter_by_locations(scope, ids) - ids.present? ? scope.where(location_id: ids) : scope - end -end diff --git a/app/graphql/queries/locations_query.rb b/app/graphql/queries/locations_query.rb deleted file mode 100644 index 3cde40e..0000000 --- a/app/graphql/queries/locations_query.rb +++ /dev/null @@ -1,21 +0,0 @@ -# frozen_string_literal: true - -class Queries::LocationsQuery < Queries::BaseQuery - type Types::LocationType.connection_type, null: false - argument :ids, [ID], required: false - - def resolve(ids: nil) - scope(ids).all - end - - protected - - def scope(ids) - scope = ::Location - filter_by_ids(scope, ids) - end - - def filter_by_ids(scope, ids) - ids.present? ? scope.where(id: ids) : scope - end -end diff --git a/app/graphql/queries/prayers_query.rb b/app/graphql/queries/prayers_query.rb deleted file mode 100644 index 043fc7b..0000000 --- a/app/graphql/queries/prayers_query.rb +++ /dev/null @@ -1,27 +0,0 @@ -# frozen_string_literal: true - -class Queries::PrayersQuery < Queries::BaseQuery - type Types::Location::PrayerType.connection_type, null: false - argument :ids, [ID], required: false - argument :location_ids, [ID], required: false - - def resolve(ids: nil, location_ids: nil) - scope(ids, location_ids).all - end - - protected - - def scope(ids, location_ids) - scope = ::Location::Prayer - scope = filter_by_ids(scope, ids) - filter_by_locations(scope, location_ids) - end - - def filter_by_ids(scope, ids) - ids.present? ? scope.where(id: ids) : scope - end - - def filter_by_locations(scope, ids) - ids.present? ? scope.where(location_id: ids) : scope - end -end diff --git a/app/graphql/queries/scriptures_query.rb b/app/graphql/queries/scriptures_query.rb index 7a5cd69..5385b86 100644 --- a/app/graphql/queries/scriptures_query.rb +++ b/app/graphql/queries/scriptures_query.rb @@ -2,17 +2,8 @@ class Queries::ScripturesQuery < Queries::BaseQuery type Types::ScriptureType.connection_type, null: false - argument :resource_type, String, required: false - def resolve(resource_type: nil) - scope(resource_type).all - end - - protected - - def scope(resource_type) - return ::Scripture if resource_type.blank? - - ::Scripture.joins(:resources).where(resources: { type: Resource::TYPES[resource_type.to_sym] }).distinct + def resolve + ::Scripture.joins(:sermons).distinct end end diff --git a/app/graphql/queries/series_query.rb b/app/graphql/queries/series_query.rb index 9acdcbd..867ee81 100644 --- a/app/graphql/queries/series_query.rb +++ b/app/graphql/queries/series_query.rb @@ -3,24 +3,15 @@ class Queries::SeriesQuery < Queries::BaseQuery type Types::SeriesType.connection_type, null: false argument :ids, [ID], required: false, default_value: nil - argument :resource_type, String, required: false, default_value: nil - def resolve(ids:, resource_type:) - scope(ids, resource_type).all.uniq + def resolve(ids:) + scope(ids).all.uniq end protected - def scope(ids, resource_type) - scope = ::Series.joins(:resources).where.not(resources: { published_at: nil }).order('resources.published_at desc') - - scope = filter_by_ids(scope, ids) - scope.where(resources: { type: Resource::TYPES[resource_type.to_sym] }) if resource_type.present? - - scope - end - - def filter_by_ids(scope, ids) + def scope(ids) + scope = ::Series.joins(:sermons).merge(Sermon.published).order('sermons.published_at desc') ids.present? ? scope.where(id: ids) : scope end end diff --git a/app/graphql/queries/resources_query.rb b/app/graphql/queries/sermons_query.rb similarity index 76% rename from app/graphql/queries/resources_query.rb rename to app/graphql/queries/sermons_query.rb index a5de4be..5dd5fce 100644 --- a/app/graphql/queries/resources_query.rb +++ b/app/graphql/queries/sermons_query.rb @@ -1,33 +1,29 @@ # frozen_string_literal: true -class Queries::ResourcesQuery < Queries::BaseQuery - type Types::ResourceType.connection_type, null: false +class Queries::SermonsQuery < Queries::BaseQuery + type Types::SermonType.connection_type, null: false argument :author_ids, [ID], required: false, default_value: nil argument :category_ids, [ID], required: false, default_value: nil argument :ids, [ID], required: false, default_value: nil - argument :resource_type, String, required: false, default_value: nil argument :scripture_ids, [ID], required: false, default_value: nil argument :series_ids, [ID], required: false, default_value: nil argument :topic_ids, [ID], required: false, default_value: nil - def resolve(ids:, author_ids:, category_ids:, scripture_ids:, series_ids:, topic_ids:, resource_type:) - scope(ids, author_ids, category_ids, scripture_ids, series_ids, topic_ids, resource_type).all + def resolve(ids:, author_ids:, category_ids:, scripture_ids:, series_ids:, topic_ids:) + scope(ids, author_ids, category_ids, scripture_ids, series_ids, topic_ids).all end protected - def scope(ids, author_ids, category_ids, scripture_ids, series_ids, topic_ids, resource_type) - scope = ::Resource.published.order(published_at: :desc) + def scope(ids, author_ids, category_ids, scripture_ids, series_ids, topic_ids) + scope = ::Sermon.published.order(published_at: :desc) scope = filter_by_ids(scope, ids) scope = filter_by_authors(scope, author_ids) scope = filter_by_categories(scope, category_ids) scope = filter_by_scriptures(scope, scripture_ids) scope = filter_by_series(scope, series_ids) - scope = filter_by_topics(scope, topic_ids) - scope = scope.where(type: Resource::TYPES[resource_type.to_sym]) if resource_type.present? - - scope + filter_by_topics(scope, topic_ids) end def filter_by_ids(scope, ids) diff --git a/app/graphql/queries/steps_query.rb b/app/graphql/queries/steps_query.rb deleted file mode 100644 index ffdb6f4..0000000 --- a/app/graphql/queries/steps_query.rb +++ /dev/null @@ -1,34 +0,0 @@ -# frozen_string_literal: true - -class Queries::StepsQuery < Queries::BaseQuery - type Types::StepType.connection_type, null: false - argument :featured, Boolean, required: false - argument :ids, [ID], required: false - argument :location_ids, [ID], required: false - - def resolve(ids: nil, location_ids: nil, featured: false) - scope(ids, location_ids, featured).all - end - - protected - - def scope(ids, location_ids, featured) - scope = ::Step.order(position: :asc) - scope = filter_by_ids(scope, ids) - scope = filter_by_locations(scope, location_ids) - - featured ? scope.featured : scope - end - - def filter_by_ids(scope, ids) - ids.present? ? scope.where(id: ids) : scope - end - - def filter_by_locations(scope, ids) - if ids.present? - scope.joins(:location_connection_steps).where(location_connection_steps: { location_id: ids }) - else - scope - end - end -end diff --git a/app/graphql/queries/topic_query.rb b/app/graphql/queries/topic_query.rb index d51ac2e..7d0f119 100644 --- a/app/graphql/queries/topic_query.rb +++ b/app/graphql/queries/topic_query.rb @@ -2,17 +2,8 @@ class Queries::TopicQuery < Queries::BaseQuery type Types::TopicType.connection_type, null: false - argument :resource_type, String, required: false - def resolve(resource_type: nil) - scope(resource_type).all - end - - protected - - def scope(resource_type) - return ::Category::Topic if resource_type.blank? - - ::Category::Topic.joins(:resources).where(resources: { type: Resource::TYPES[resource_type.to_sym] }).distinct + def resolve + ::Category::Topic.joins(:sermons).distinct end end diff --git a/app/graphql/types/author_type.rb b/app/graphql/types/author_type.rb index f1d7743..8592ebe 100644 --- a/app/graphql/types/author_type.rb +++ b/app/graphql/types/author_type.rb @@ -3,5 +3,5 @@ class Types::AuthorType < Types::BaseObject field :id, ID, null: false field :name, String, null: false - field :resources, Types::ResourceType.connection_type, null: false + field :sermons, Types::SermonType.connection_type, null: false end diff --git a/app/graphql/types/category_type.rb b/app/graphql/types/category_type.rb index 41174ad..90ee2a6 100644 --- a/app/graphql/types/category_type.rb +++ b/app/graphql/types/category_type.rb @@ -3,6 +3,6 @@ class Types::CategoryType < Types::BaseObject field :id, ID, null: false field :name, String, null: false - field :resources, Types::ResourceType.connection_type, null: false + field :sermons, Types::SermonType.connection_type, null: false field :topics, Types::TopicType.connection_type, null: false end diff --git a/app/graphql/types/location/connection/step_type.rb b/app/graphql/types/location/connection/step_type.rb deleted file mode 100644 index 8414759..0000000 --- a/app/graphql/types/location/connection/step_type.rb +++ /dev/null @@ -1,14 +0,0 @@ -# frozen_string_literal: true - -class Types::Location::Connection::StepType < Types::BaseObject - graphql_name 'LocationConnectionStepType' - - field :content, String, null: true - field :elvanto_form_id, String, null: true - field :fluro_form_url, String, null: true - field :id, ID, null: false - field :location, Types::LocationType, null: false - field :mail_chimp_audience_id, String, null: true - field :mail_chimp_user_id, String, null: true - field :step, Types::StepType, null: false -end diff --git a/app/graphql/types/location/event_type.rb b/app/graphql/types/location/event_type.rb deleted file mode 100644 index 4a31f0c..0000000 --- a/app/graphql/types/location/event_type.rb +++ /dev/null @@ -1,25 +0,0 @@ -# frozen_string_literal: true - -class Types::Location::EventType < Types::BaseObject - include Rails.application.routes.url_helpers - - field :address, String, null: false - field :banner_url, String, null: false - field :content, String, null: false - field :elvanto_form_id, String, null: true - field :end_at, GraphQL::Types::ISO8601DateTime, null: false - field :facebook_url, String, null: true - field :id, ID, null: false - field :location, Types::LocationType, null: false - field :name, String, null: false - field :registration_url, String, null: true - field :start_at, GraphQL::Types::ISO8601DateTime, null: false - - def banner_url - polymorphic_url( - object.banner.variant( - convert: 'jpg', saver: { quality: 80 }, strip: true, resize_to_limit: [1920, 1080] - ) - ) - end -end diff --git a/app/graphql/types/location/prayer_type.rb b/app/graphql/types/location/prayer_type.rb deleted file mode 100644 index ea82f07..0000000 --- a/app/graphql/types/location/prayer_type.rb +++ /dev/null @@ -1,20 +0,0 @@ -# frozen_string_literal: true - -class Types::Location::PrayerType < Types::BaseObject - include Rails.application.routes.url_helpers - - field :banner_url, String, null: false - field :content, String, null: true - field :id, ID, null: false - field :location, Types::LocationType, null: false - field :name, String, null: false - field :snippet, String, null: false - - def banner_url - polymorphic_url( - object.banner.variant( - convert: 'jpg', saver: { quality: 80 }, strip: true, resize_to_limit: [1920, 1080] - ) - ) - end -end diff --git a/app/graphql/types/location/service_type.rb b/app/graphql/types/location/service_type.rb deleted file mode 100644 index 2bcec77..0000000 --- a/app/graphql/types/location/service_type.rb +++ /dev/null @@ -1,9 +0,0 @@ -# frozen_string_literal: true - -class Types::Location::ServiceType < Types::BaseObject - field :elvanto_form_id, String, null: true - field :end_at, String, null: false - field :id, ID, null: false - field :location, Types::LocationType, null: false - field :start_at, String, null: false -end diff --git a/app/graphql/types/location_type.rb b/app/graphql/types/location_type.rb deleted file mode 100644 index 69ab837..0000000 --- a/app/graphql/types/location_type.rb +++ /dev/null @@ -1,24 +0,0 @@ -# frozen_string_literal: true - -class Types::LocationType < Types::BaseObject - include Rails.application.routes.url_helpers - - field :address, String, null: false - field :banner_url, String, null: false - field :content, String, null: true - field :events, Types::Location::EventType.connection_type, null: false - field :id, ID, null: false - field :location_connection_steps, Types::Location::Connection::StepType.connection_type, null: false - field :name, String, null: false - field :prayers, Types::Location::PrayerType.connection_type, null: false - field :services, Types::Location::ServiceType.connection_type, null: false - field :snippet, String, null: false - - def banner_url - polymorphic_url( - object.banner.variant( - convert: 'jpg', saver: { quality: 80 }, strip: true, resize_to_limit: [1920, 1080] - ) - ) - end -end diff --git a/app/graphql/types/query_type.rb b/app/graphql/types/query_type.rb index 34b8861..be986dd 100644 --- a/app/graphql/types/query_type.rb +++ b/app/graphql/types/query_type.rb @@ -3,12 +3,8 @@ class Types::QueryType < Types::BaseObject field :authors, resolver: Queries::AuthorsQuery field :categories, resolver: Queries::CategoriesQuery - field :events, resolver: Queries::EventsQuery - field :locations, resolver: Queries::LocationsQuery - field :prayers, resolver: Queries::PrayersQuery - field :resources, resolver: Queries::ResourcesQuery field :scriptures, resolver: Queries::ScripturesQuery field :series, resolver: Queries::SeriesQuery - field :steps, resolver: Queries::StepsQuery + field :sermons, resolver: Queries::SermonsQuery field :topics, resolver: Queries::TopicQuery end diff --git a/app/graphql/types/scripture_type.rb b/app/graphql/types/scripture_type.rb index 1ba9ba7..ae04a8a 100644 --- a/app/graphql/types/scripture_type.rb +++ b/app/graphql/types/scripture_type.rb @@ -3,5 +3,5 @@ class Types::ScriptureType < Types::BaseObject field :id, ID, null: false field :name, String, null: false - field :resources, Types::ResourceType.connection_type, null: false + field :sermons, Types::SermonType.connection_type, null: false end diff --git a/app/graphql/types/series_type.rb b/app/graphql/types/series_type.rb index 221d0e1..a41d1a9 100644 --- a/app/graphql/types/series_type.rb +++ b/app/graphql/types/series_type.rb @@ -8,7 +8,7 @@ class Types::SeriesType < Types::BaseObject field :foreground_url, String, null: true field :id, ID, null: false field :name, String, null: false - field :resources, Types::ResourceType.connection_type, null: false + field :sermons, Types::SermonType.connection_type, null: false def banner_url object.banner.presence && polymorphic_url( diff --git a/app/graphql/types/resource/connection/scripture_type.rb b/app/graphql/types/sermon_scripture_type.rb similarity index 52% rename from app/graphql/types/resource/connection/scripture_type.rb rename to app/graphql/types/sermon_scripture_type.rb index 04d87ef..5082166 100644 --- a/app/graphql/types/resource/connection/scripture_type.rb +++ b/app/graphql/types/sermon_scripture_type.rb @@ -1,11 +1,9 @@ # frozen_string_literal: true -class Types::Resource::Connection::ScriptureType < Types::BaseObject - graphql_name 'ResourceConnectionScriptureType' - +class Types::SermonScriptureType < Types::BaseObject field :content, String, null: false field :id, ID, null: false field :range, String, null: true - field :resource, Types::ResourceType, null: false field :scripture, Types::ScriptureType, null: false + field :sermon, Types::SermonType, null: false end diff --git a/app/graphql/types/resource_type.rb b/app/graphql/types/sermon_type.rb similarity index 91% rename from app/graphql/types/resource_type.rb rename to app/graphql/types/sermon_type.rb index 0e87f49..2e18f26 100644 --- a/app/graphql/types/resource_type.rb +++ b/app/graphql/types/sermon_type.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class Types::ResourceType < Types::BaseObject +class Types::SermonType < Types::BaseObject include Rails.application.routes.url_helpers field :audio_url, String, null: true @@ -8,7 +8,7 @@ class Types::ResourceType < Types::BaseObject field :background_url, String, null: true field :banner_url, String, null: true field :connect_group_notes, String, null: true - field :connection_scriptures, [Types::Resource::Connection::ScriptureType], null: false + field :connection_scriptures, [Types::SermonScriptureType], null: false field :content, String, null: true field :foreground_url, String, null: true field :id, ID, null: false diff --git a/app/graphql/types/step_type.rb b/app/graphql/types/step_type.rb deleted file mode 100644 index 77fd86d..0000000 --- a/app/graphql/types/step_type.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true - -class Types::StepType < Types::BaseObject - include Rails.application.routes.url_helpers - - field :banner_url, String, null: false - field :content, String, null: true - field :id, ID, null: false - field :location_connection_steps, Types::Location::Connection::StepType.connection_type, null: false - field :name, String, null: false - - def banner_url - polymorphic_url( - object.banner.variant(convert: 'jpg', saver: { quality: 80 }, strip: true, resize_to_limit: [1920, 1080]) - ) - end -end diff --git a/app/graphql/types/topic_type.rb b/app/graphql/types/topic_type.rb index 9926c81..5a1cf0c 100644 --- a/app/graphql/types/topic_type.rb +++ b/app/graphql/types/topic_type.rb @@ -4,5 +4,5 @@ class Types::TopicType < Types::BaseObject field :category, Types::CategoryType, null: false field :id, ID, null: false field :name, String, null: false - field :resources, Types::ResourceType.connection_type, null: false + field :sermons, Types::SermonType.connection_type, null: false end diff --git a/app/models/author.rb b/app/models/author.rb index 78931df..ecf3957 100644 --- a/app/models/author.rb +++ b/app/models/author.rb @@ -4,14 +4,14 @@ class Author < ApplicationRecord extend FriendlyId friendly_id :name, use: :slugged - has_many :connection_authors, class_name: 'Resource::Connection::Author', dependent: :destroy - has_many :resources, through: :connection_authors + has_many :sermon_authors, dependent: :destroy + has_many :sermons, through: :sermon_authors validates :name, presence: true, uniqueness: true # Only allow these associations to be searchable by Ransack (used in ActiveAdmin filters) def self.ransackable_associations(_auth_object = nil) - %w[resources connection_authors] + %w[sermons sermon_authors] end def self.ransackable_attributes(_auth_object = nil) diff --git a/app/models/category/topic.rb b/app/models/category/topic.rb index dc2e402..a6533b6 100644 --- a/app/models/category/topic.rb +++ b/app/models/category/topic.rb @@ -4,15 +4,15 @@ class Category::Topic < ApplicationRecord extend FriendlyId friendly_id :name, use: :slugged - has_many :connection_topics, class_name: 'Resource::Connection::Topic', dependent: :destroy - has_many :resources, through: :connection_topics + has_many :sermon_topics, dependent: :destroy + has_many :sermons, through: :sermon_topics belongs_to :category validates :name, presence: true, uniqueness: true # Only allow these associations to be searchable by Ransack (used in ActiveAdmin filters) def self.ransackable_associations(_auth_object = nil) - %w[resources connection_topics] + %w[sermons sermon_topics] end def self.ransackable_attributes(_auth_object = nil) diff --git a/app/models/location.rb b/app/models/location.rb deleted file mode 100644 index 135c9ad..0000000 --- a/app/models/location.rb +++ /dev/null @@ -1,29 +0,0 @@ -# frozen_string_literal: true - -class Location < ApplicationRecord - has_many :events, dependent: :destroy - has_many :prayers, dependent: :destroy - has_many :services, dependent: :destroy - has_many :location_connection_steps, dependent: :destroy, class_name: 'Location::Connection::Step' - has_one_attached :banner - validates :name, :snippet, :content, :address, presence: true - validates :banner, - attached: true, - aspect_ratio: :is_16_9, - content_type: %r{\Aimage/.*\z}, - dimension: { - width: { in: 0..1920 }, - height: { in: 0..1080 }, - message: '1920x1080 max resolution' - }, - size: { less_than: 500.kilobytes, message: '500KB max size' } - - # No association filters in ActiveAdmin, so none are ransackable - def self.ransackable_associations(_auth_object = nil) - [] - end - - def self.ransackable_attributes(_auth_object = nil) - %w[address content created_at id name snippet updated_at] - end -end diff --git a/app/models/location/connection.rb b/app/models/location/connection.rb deleted file mode 100644 index d3b06a9..0000000 --- a/app/models/location/connection.rb +++ /dev/null @@ -1,7 +0,0 @@ -# frozen_string_literal: true - -module Location::Connection - def self.table_name_prefix - 'location_connection_' - end -end diff --git a/app/models/location/connection/step.rb b/app/models/location/connection/step.rb deleted file mode 100644 index bd4ee06..0000000 --- a/app/models/location/connection/step.rb +++ /dev/null @@ -1,15 +0,0 @@ -# frozen_string_literal: true - -class Location::Connection::Step < ApplicationRecord - belongs_to :step, class_name: '::Step' - belongs_to :location, class_name: '::Location' - - def self.ransackable_attributes(_auth_object = nil) - %w[created_at id location_id step_id updated_at elvanto_form_id content mail_chimp_user_id mail_chimp_audience_id - fluro_form_url] - end - - def self.ransackable_associations(_auth_object = nil) - %w[location step] - end -end diff --git a/app/models/location/event.rb b/app/models/location/event.rb deleted file mode 100644 index 2500d9f..0000000 --- a/app/models/location/event.rb +++ /dev/null @@ -1,29 +0,0 @@ -# frozen_string_literal: true - -class Location::Event < ApplicationRecord - belongs_to :location - has_one_attached :banner - validates :start_at, :end_at, :name, :content, :address, presence: true - validates :banner, - attached: true, - aspect_ratio: :is_16_9, - content_type: %r{\Aimage/.*\z}, - dimension: { - width: { in: 0..1920 }, - height: { in: 0..1080 }, - message: '1920x1080 max resolution' - }, - size: { less_than: 500.kilobytes, message: '500KB max size' } - validates :registration_url, :facebook_url, url: { allow_blank: true } - scope :upcoming, -> { where(end_at: Time.zone.today..).order(:start_at) } - scope :featured, -> { upcoming.where.not(featured_at: nil) } - - def self.ransackable_attributes(_auth_object = nil) - %w[created_at id location_id updated_at elvanto_form_id name content address start_at end_at featured_at - facebook_url registration_url] - end - - def self.ransackable_associations(_auth_object = nil) - %w[location banner_attachment banner_blob] - end -end diff --git a/app/models/location/prayer.rb b/app/models/location/prayer.rb deleted file mode 100644 index df2f36a..0000000 --- a/app/models/location/prayer.rb +++ /dev/null @@ -1,25 +0,0 @@ -# frozen_string_literal: true - -class Location::Prayer < ApplicationRecord - belongs_to :location - has_one_attached :banner - validates :name, :snippet, :content, presence: true - validates :banner, - attached: true, - aspect_ratio: :is_16_9, - content_type: %r{\Aimage/.*\z}, - dimension: { - width: { in: 0..1920 }, - height: { in: 0..1080 }, - message: '1920x1080 max resolution' - }, - size: { less_than: 500.kilobytes, message: '500KB max size' } - - def self.ransackable_attributes(_auth_object = nil) - %w[content created_at id location_id name snippet updated_at] - end - - def self.ransackable_associations(_auth_object = nil) - %w[location banner_attachment banner_blob] - end -end diff --git a/app/models/location/service.rb b/app/models/location/service.rb deleted file mode 100644 index 436d012..0000000 --- a/app/models/location/service.rb +++ /dev/null @@ -1,14 +0,0 @@ -# frozen_string_literal: true - -class Location::Service < ApplicationRecord - belongs_to :location - validates :start_at, :end_at, presence: true - - def self.ransackable_attributes(_auth_object = nil) - %w[created_at id location_id updated_at elvanto_form_id start_at end_at] - end - - def self.ransackable_associations(_auth_object = nil) - %w[location] - end -end diff --git a/app/models/resource.rb b/app/models/resource.rb deleted file mode 100644 index aff081e..0000000 --- a/app/models/resource.rb +++ /dev/null @@ -1,51 +0,0 @@ -# frozen_string_literal: true - -class Resource < ApplicationRecord - TYPES = { article: 'Resource::Article', sermon: 'Resource::Sermon' }.freeze - - TYPES.each do |key, value| - scope key.to_s.pluralize, -> { where(type: value) } - end - - extend FriendlyId - friendly_id :name, use: :slugged - - has_one_attached :banner - has_one_attached :foreground - has_one_attached :background - has_one_attached :audio - has_one_attached :video - - has_many :connection_authors, class_name: 'Resource::Connection::Author', dependent: :destroy - has_many :authors, through: :connection_authors - has_many :connection_scriptures, class_name: 'Resource::Connection::Scripture', dependent: :destroy - has_many :scriptures, through: :connection_scriptures - has_many :connection_series, class_name: 'Resource::Connection::Series', dependent: :destroy - has_many :series, through: :connection_series - has_many :connection_topics, class_name: 'Resource::Connection::Topic', dependent: :destroy - has_many :topics, through: :connection_topics - - accepts_nested_attributes_for :connection_scriptures - - validates :name, presence: true - - scope :published, -> { where.not(published_at: nil) } - scope :featured, -> { where.not(featured_at: nil) } - - def self.batch_publish(ids) - where(id: ids).find_each { |r| r.update(published_at: Time.zone.now) } - end - - def self.batch_unpublish(ids) - where(id: ids).find_each { |r| r.update(published_at: nil) } - end - - # Only allow these associations to be searchable by Ransack (used in ActiveAdmin filters) - def self.ransackable_associations(_auth_object = nil) - %w[authors scriptures series topics connection_authors connection_scriptures connection_series connection_topics] - end - - def self.ransackable_attributes(_auth_object = nil) - %w[created_at featured_at id name published_at slug type updated_at snippet content] - end -end diff --git a/app/models/resource/article.rb b/app/models/resource/article.rb deleted file mode 100644 index 355906b..0000000 --- a/app/models/resource/article.rb +++ /dev/null @@ -1,4 +0,0 @@ -# frozen_string_literal: true - -class Resource::Article < Resource -end diff --git a/app/models/resource/connection.rb b/app/models/resource/connection.rb deleted file mode 100644 index 2a686f8..0000000 --- a/app/models/resource/connection.rb +++ /dev/null @@ -1,7 +0,0 @@ -# frozen_string_literal: true - -module Resource::Connection - def self.table_name_prefix - 'resource_connection_' - end -end diff --git a/app/models/resource/connection/series.rb b/app/models/resource/connection/series.rb deleted file mode 100644 index 158fba1..0000000 --- a/app/models/resource/connection/series.rb +++ /dev/null @@ -1,14 +0,0 @@ -# frozen_string_literal: true - -class Resource::Connection::Series < ApplicationRecord - belongs_to :resource - belongs_to :series - - def self.ransackable_attributes(_auth_object = nil) - %w[created_at id resource_id series_id updated_at] - end - - def self.ransackable_associations(_auth_object = nil) - %w[resource series] # Added common associations, can be emptied if not needed for search - end -end diff --git a/app/models/resource/sermon.rb b/app/models/resource/sermon.rb deleted file mode 100644 index 9213d99..0000000 --- a/app/models/resource/sermon.rb +++ /dev/null @@ -1,4 +0,0 @@ -# frozen_string_literal: true - -class Resource::Sermon < Resource -end diff --git a/app/models/scripture.rb b/app/models/scripture.rb index c93751b..4dba1d0 100644 --- a/app/models/scripture.rb +++ b/app/models/scripture.rb @@ -4,14 +4,14 @@ class Scripture < ApplicationRecord extend FriendlyId friendly_id :name, use: :slugged - has_many :connection_scriptures, class_name: 'Resource::Connection::Scripture', dependent: :destroy - has_many :resources, through: :connection_scriptures + has_many :sermon_scriptures, dependent: :destroy + has_many :sermons, through: :sermon_scriptures validates :name, presence: true, uniqueness: true # Only allow these associations to be searchable by Ransack (used in ActiveAdmin filters) def self.ransackable_associations(_auth_object = nil) - %w[resources connection_scriptures] + %w[sermons sermon_scriptures] end def self.ransackable_attributes(_auth_object = nil) diff --git a/app/models/series.rb b/app/models/series.rb index 9761059..c0ceee5 100644 --- a/app/models/series.rb +++ b/app/models/series.rb @@ -4,8 +4,8 @@ class Series < ApplicationRecord extend FriendlyId friendly_id :name, use: :slugged - has_many :connection_series, class_name: 'Resource::Connection::Series', dependent: :destroy - has_many :resources, through: :connection_series + has_many :sermon_series, dependent: :destroy + has_many :sermons, through: :sermon_series validates :name, presence: true, uniqueness: true @@ -15,7 +15,7 @@ class Series < ApplicationRecord # Only allow these associations to be searchable by Ransack (used in ActiveAdmin filters) def self.ransackable_associations(_auth_object = nil) - %w[resources connection_series banner_attachment banner_blob foreground_attachment foreground_blob + %w[sermons sermon_series banner_attachment banner_blob foreground_attachment foreground_blob background_attachment background_blob] end diff --git a/app/models/sermon.rb b/app/models/sermon.rb new file mode 100644 index 0000000..a301755 --- /dev/null +++ b/app/models/sermon.rb @@ -0,0 +1,45 @@ +# frozen_string_literal: true + +class Sermon < ApplicationRecord + extend FriendlyId + friendly_id :name, use: :slugged + + has_one_attached :banner + has_one_attached :foreground + has_one_attached :background + has_one_attached :audio + has_one_attached :video + + has_many :sermon_authors, dependent: :destroy + has_many :authors, through: :sermon_authors + has_many :sermon_scriptures, dependent: :destroy + has_many :scriptures, through: :sermon_scriptures + has_many :sermon_series, dependent: :destroy + has_many :series, through: :sermon_series + has_many :sermon_topics, dependent: :destroy + has_many :topics, through: :sermon_topics + + accepts_nested_attributes_for :sermon_scriptures + + validates :name, presence: true + + scope :published, -> { where.not(published_at: nil) } + scope :featured, -> { where.not(featured_at: nil) } + + def self.batch_publish(ids) + where(id: ids).find_each { |r| r.update(published_at: Time.zone.now) } + end + + def self.batch_unpublish(ids) + where(id: ids).find_each { |r| r.update(published_at: nil) } + end + + # Only allow these associations to be searchable by Ransack (used in ActiveAdmin filters) + def self.ransackable_associations(_auth_object = nil) + %w[authors scriptures series topics sermon_authors sermon_scriptures sermon_series sermon_topics] + end + + def self.ransackable_attributes(_auth_object = nil) + %w[created_at featured_at id name published_at slug updated_at snippet content] + end +end diff --git a/app/models/resource/connection/author.rb b/app/models/sermon_author.rb similarity index 53% rename from app/models/resource/connection/author.rb rename to app/models/sermon_author.rb index 0a5bea1..52adc93 100644 --- a/app/models/resource/connection/author.rb +++ b/app/models/sermon_author.rb @@ -1,14 +1,14 @@ # frozen_string_literal: true -class Resource::Connection::Author < ApplicationRecord - belongs_to :resource +class SermonAuthor < ApplicationRecord + belongs_to :sermon belongs_to :author def self.ransackable_attributes(_auth_object = nil) - %w[author_id created_at id resource_id updated_at] + %w[author_id created_at id sermon_id updated_at] end def self.ransackable_associations(_auth_object = nil) - %w[author resource] + %w[author sermon] end end diff --git a/app/models/resource/connection/scripture.rb b/app/models/sermon_scripture.rb similarity index 75% rename from app/models/resource/connection/scripture.rb rename to app/models/sermon_scripture.rb index f9f8a1c..364dd77 100644 --- a/app/models/resource/connection/scripture.rb +++ b/app/models/sermon_scripture.rb @@ -1,17 +1,17 @@ # frozen_string_literal: true -class Resource::Connection::Scripture < ApplicationRecord - belongs_to :resource +class SermonScripture < ApplicationRecord + belongs_to :sermon belongs_to :scripture, class_name: '::Scripture' before_save :fetch_content, if: :range_changed? def self.ransackable_attributes(_auth_object = nil) - %w[content created_at id range resource_id scripture_id updated_at] + %w[content created_at id range sermon_id scripture_id updated_at] end def self.ransackable_associations(_auth_object = nil) - %w[resource scripture] + %w[sermon scripture] end protected diff --git a/app/models/sermon_series.rb b/app/models/sermon_series.rb new file mode 100644 index 0000000..5ff7288 --- /dev/null +++ b/app/models/sermon_series.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +class SermonSeries < ApplicationRecord + belongs_to :sermon + belongs_to :series + + def self.ransackable_attributes(_auth_object = nil) + %w[created_at id sermon_id series_id updated_at] + end + + def self.ransackable_associations(_auth_object = nil) + %w[sermon series] + end +end diff --git a/app/models/resource/connection/topic.rb b/app/models/sermon_topic.rb similarity index 57% rename from app/models/resource/connection/topic.rb rename to app/models/sermon_topic.rb index 0210d05..dbc246d 100644 --- a/app/models/resource/connection/topic.rb +++ b/app/models/sermon_topic.rb @@ -1,14 +1,14 @@ # frozen_string_literal: true -class Resource::Connection::Topic < ApplicationRecord - belongs_to :resource +class SermonTopic < ApplicationRecord + belongs_to :sermon belongs_to :topic, class_name: 'Category::Topic' def self.ransackable_attributes(_auth_object = nil) - %w[created_at id resource_id topic_id updated_at] + %w[created_at id sermon_id topic_id updated_at] end def self.ransackable_associations(_auth_object = nil) - %w[resource topic] + %w[sermon topic] end end diff --git a/app/models/step.rb b/app/models/step.rb deleted file mode 100644 index 648df84..0000000 --- a/app/models/step.rb +++ /dev/null @@ -1,28 +0,0 @@ -# frozen_string_literal: true - -class Step < ApplicationRecord - acts_as_list - has_many :location_connection_steps, dependent: :destroy, class_name: 'Location::Connection::Step' - has_one_attached :banner - validates :name, :content, presence: true - validates :banner, - attached: true, - aspect_ratio: :is_16_9, - content_type: %r{\Aimage/.*\z}, - dimension: { - width: { in: 0..1920 }, - height: { in: 0..1080 }, - message: '1920x1080 max resolution' - }, - size: { less_than: 500.kilobytes, message: '500KB max size' } - scope :featured, -> { where.not(featured_at: nil) } - - # No association filters in ActiveAdmin, so none are ransackable - def self.ransackable_associations(_auth_object = nil) - [] - end - - def self.ransackable_attributes(_auth_object = nil) - %w[content created_at featured_at id name position updated_at] - end -end diff --git a/app/services/import/wpfc_service.rb b/app/services/import/wpfc_service.rb index be8a777..43922f4 100644 --- a/app/services/import/wpfc_service.rb +++ b/app/services/import/wpfc_service.rb @@ -37,10 +37,10 @@ def import_authors def import_sermons items('wpfc_sermon').each do |remote_sermon| - sermon = Resource::Sermon.find_or_initialize_by(remote_id: remote_sermon['id']) + sermon = Sermon.find_or_initialize_by(remote_id: remote_sermon['id']) sermon.name = CGI.unescapeHTML(remote_sermon['title']['rendered']) sermon.slug = remote_sermon['slug'] - sermon.connection_scriptures = connection_scriptures(remote_sermon['bible_passage']) + sermon.sermon_scriptures = sermon_scriptures(remote_sermon['bible_passage']) sermon.authors = Author.where(remote_id: remote_sermon['wpfc_preacher']) sermon.series = Series.where(remote_id: remote_sermon['wpfc_sermon_series']) sermon.audio_url = remote_sermon['sermon_audio'] @@ -49,12 +49,12 @@ def import_sermons end end - def connection_scriptures(bible_passage) + def sermon_scriptures(bible_passage) matches = bible_passage.match(/(?[\dA-Za-z ]*) (?[\d:-]*)/) return [] if matches.blank? Scripture.where(name: matches[:name]).map do |scripture| - Resource::Connection::Scripture.new(scripture: scripture, range: matches[:range]) + SermonScripture.new(scripture: scripture, range: matches[:range]) end end diff --git a/app/views/application/_links.html.erb b/app/views/application/_links.html.erb index 648e0ca..ef47fec 100644 --- a/app/views/application/_links.html.erb +++ b/app/views/application/_links.html.erb @@ -1,16 +1,9 @@