effective_classifieds 0.0.2 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +10 -13
  3. data/app/controllers/admin/classified_wizards_controller.rb +19 -0
  4. data/app/controllers/effective/classified_wizards_controller.rb +10 -0
  5. data/app/controllers/effective/classifieds_controller.rb +1 -21
  6. data/app/datatables/admin/{effective_classified_submissions_datatable.rb → effective_classified_wizards_datatable.rb} +2 -2
  7. data/app/datatables/admin/effective_classifieds_datatable.rb +3 -2
  8. data/app/datatables/effective_classified_wizards_datatable.rb +36 -0
  9. data/app/datatables/effective_classifieds_datatable.rb +11 -6
  10. data/app/helpers/effective_classifieds_helper.rb +0 -5
  11. data/app/models/concerns/{effective_classifieds_classified_submission.rb → effective_classifieds_classified_wizard.rb} +8 -16
  12. data/app/models/effective/classified.rb +4 -4
  13. data/app/models/effective/classified_wizard.rb +7 -0
  14. data/app/views/effective/classified_wizards/_classified.html.haml +10 -0
  15. data/app/views/effective/classified_wizards/_classified_wizard.html.haml +3 -0
  16. data/app/views/effective/{classified_submissions → classified_wizards}/_content.html.haml +0 -0
  17. data/app/views/effective/classified_wizards/_dashboard.html.haml +30 -0
  18. data/app/views/effective/{classified_submissions → classified_wizards}/_layout.html.haml +0 -0
  19. data/app/views/effective/{classified_submissions → classified_wizards}/_summary.html.haml +5 -5
  20. data/app/views/effective/{classified_submissions → classified_wizards}/classified.html.haml +1 -1
  21. data/app/views/effective/classified_wizards/start.html.haml +20 -0
  22. data/app/views/effective/classified_wizards/submitted.html.haml +14 -0
  23. data/app/views/effective/classified_wizards/summary.html.haml +8 -0
  24. data/app/views/effective/classifieds/_classified.html.haml +30 -34
  25. data/app/views/effective/classifieds/_dashboard.html.haml +5 -2
  26. data/app/views/effective/classifieds/_fields.html.haml +18 -12
  27. data/app/views/effective/classifieds/edit.html.haml +5 -0
  28. data/app/views/effective/classifieds/index.html.haml +7 -7
  29. data/app/views/effective/classifieds/show.html.haml +7 -7
  30. data/app/views/effective/classifieds_mailer/classified_submitted.html.haml +8 -4
  31. data/config/effective_classifieds.rb +5 -5
  32. data/config/routes.rb +2 -2
  33. data/db/migrate/01_create_effective_classifieds.rb.erb +5 -5
  34. data/lib/effective_classifieds/engine.rb +1 -1
  35. data/lib/effective_classifieds/version.rb +1 -1
  36. data/lib/effective_classifieds.rb +4 -4
  37. data/lib/generators/effective_classifieds/install_generator.rb +1 -1
  38. metadata +19 -20
  39. data/app/controllers/admin/classified_submissions_controller.rb +0 -19
  40. data/app/controllers/effective/classified_submissions_controller.rb +0 -31
  41. data/app/datatables/effective_classified_submissions_datatable.rb +0 -37
  42. data/app/models/effective/classified_submission.rb +0 -7
  43. data/app/views/effective/classified_submissions/_classified.haml +0 -12
  44. data/app/views/effective/classified_submissions/_classified_submission.html.haml +0 -8
  45. data/app/views/effective/classified_submissions/_dashboard.html.haml +0 -28
  46. data/app/views/effective/classified_submissions/start.html.haml +0 -16
  47. data/app/views/effective/classified_submissions/submitted.html.haml +0 -13
  48. data/app/views/effective/classified_submissions/summary.html.haml +0 -8
  49. data/app/views/effective/classifieds/_layout.html.haml +0 -1
  50. data/app/views/effective/classifieds/_spacer.html.haml +0 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4b6ec3f5b89b358551558d22206f8ce57ef5002f199a635c9e004155a12ff246
4
- data.tar.gz: 0c36fa15a0dd1ae22c8cd74fef90e8b28bd6bec2e74efe2950c3bb32ee24e999
3
+ metadata.gz: b86483009f7d9be8e80a451b7b957bbfe1ac9ec2d88d7a11e13f36a97a261a6e
4
+ data.tar.gz: bd9cd48a34bd463f87c12cb3353f9a474f4de95645c4999f9188d10fd2f52d76
5
5
  SHA512:
6
- metadata.gz: 1377dab4d35fc6f2a0c160f006246380cf3af0adabd97100e5b78c61d5c2402c274d747c7eee3ca4126317fe38efc648dc142a549e0be7e31e2f257d4bcbb937
7
- data.tar.gz: 2043dfe2ce40bd423fe50c5c80b2c44be329d28c53504c820bb009188382ccb8cdce2596deaf8d374f97786a8cbf09270c8465cb8067edbdaea1a2a1ae0b440a
6
+ metadata.gz: 820fd500352d1a4b20cc7ed71f0f9569a25d27ca3d2e6a91befc4d8ccfc3244d882e77dcdbb240e73634b419fb90b5b7abfe0ce5abf09d63c11945f90f690f57
7
+ data.tar.gz: 5f2c5ea34d257e972c9f3f2e4e30216537a3f899a8c4778af8c578485653b0d134f6e7c4e44146c456efd2cd7cdde55f85e87f5f96b0c0c972ca37c75d6cb924
data/README.md CHANGED
@@ -39,21 +39,18 @@ Then migrate the database:
39
39
  rake db:migrate
40
40
  ```
41
41
 
42
- Please add the following to your User model:
43
-
44
- ```
45
- effective_classifieds_user
46
-
47
- Use the following datatables to display to your user their applicants dues:
42
+ Please add the following to your user dashboard page:
48
43
 
49
44
  ```haml
50
- %h2 My Classifieds
51
- - datatable = EffectiveClassifiedsDatatable.new(self)
45
+ .card.card-dashboard.mb-4
46
+ .card-body= render 'effective/classifieds/dashboard'
47
+
48
+ .card.card-dashboard.mb-4
49
+ .card-body= render 'effective/classified_wizards/dashboard'
52
50
  ```
53
51
 
54
52
  and
55
53
 
56
- ```
57
54
  Add a link to the admin menu:
58
55
 
59
56
  ```haml
@@ -85,18 +82,18 @@ The permissions you actually want to define are as follows (using CanCan):
85
82
  can([:index, :show], Effective::Classified) { |classified| classified.published? }
86
83
  can([:show, :edit, :update], Effective::Classified) { |classified| classified.owner == user }
87
84
 
88
- can([:show, :index, :destroy], EffectiveClassifieds.ClassifiedSubmission) { |submission| submission.owner == user }
89
- can([:update], EffectiveClassifieds.ClassifiedSubmission) { |submission| submission.owner == user && !submission.was_submitted? }
85
+ can(:new, EffectiveClassifieds.ClassifiedWizard)
86
+ can([:show, :index, :destroy], EffectiveClassifieds.ClassifiedWizard) { |submission| submission.owner == user }
87
+ can([:update], EffectiveClassifieds.ClassifiedWizard) { |submission| submission.owner == user && !submission.was_submitted? }
90
88
 
91
89
  if user.admin?
92
90
  can :admin, :effective_classifieds
93
91
 
94
92
  can(crud - [:destroy], Classified)
95
-
96
93
  can(:approve, Classified) { |classified| classified.was_submitted? && !classified.approved? }
97
94
  can(:destroy, Classified) { |classified| !classified.draft? }
98
95
 
99
- can([:new, :index, :show], EffectiveClassifieds.ClassifiedSubmission)
96
+ can([:index, :show], EffectiveClassifieds.ClassifiedWizard)
100
97
  end
101
98
  ```
102
99
 
@@ -0,0 +1,19 @@
1
+ module Admin
2
+ class ClassifiedWizardsController < ApplicationController
3
+ before_action(:authenticate_user!) if defined?(Devise)
4
+ before_action { EffectiveResources.authorize!(self, :admin, :effective_classifieds) }
5
+
6
+ include Effective::CrudController
7
+
8
+ resource_scope -> { EffectiveEvents.ClassifiedWizard.deep.all }
9
+ datatable -> { Admin::EffectiveClassifiedWizardsDatatable.new }
10
+
11
+ private
12
+
13
+ def permitted_params
14
+ model = (params.key?(:effective_classified_wizard) ? :effective_classified_wizard : :classified_wizard)
15
+ params.require(model).permit!
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,10 @@
1
+ module Effective
2
+ class ClassifiedWizardsController < ApplicationController
3
+ before_action(:authenticate_user!) if defined?(Devise)
4
+
5
+ include Effective::WizardController
6
+
7
+ resource_scope -> { EffectiveClassifieds.ClassifiedWizard.deep.where(owner: current_user) }
8
+
9
+ end
10
+ end
@@ -2,26 +2,6 @@ module Effective
2
2
  class ClassifiedsController < ApplicationController
3
3
  include Effective::CrudController
4
4
 
5
- resource_scope -> {
6
- unpublished = EffectiveResources.authorized?(self, :admin, :effective_classifieds)
7
- Effective::Classified.classifieds(user: current_user, unpublished: unpublished)
8
- }
9
-
10
- def index
11
- @classifieds ||= resource_scope.published
12
-
13
- @classifieds = @classifieds.paginate(page: params[:page])
14
-
15
- # if params[:search].present?
16
- # search = params[:search].permit(EffectiveClassifieds.permitted_params).delete_if { |k, v| v.blank? }
17
- # @classifieds = @classifieds.where(search) if search.present?
18
- # end
19
-
20
- EffectiveResources.authorize!(self, :index, Effective::Classified)
21
-
22
- @page_title ||= ['Classifieds', (" - Page #{params[:page]}" if params[:page])].compact.join
23
- end
24
-
25
5
  def show
26
6
  @classified = resource_scope.find(params[:id])
27
7
 
@@ -46,7 +26,7 @@ module Effective
46
26
  private
47
27
 
48
28
  def permitted_params
49
- params.require(:effective_classified).permit!.except(:status, :status_steps)
29
+ params.require(:effective_classified).except(:status, :status_steps).permit!
50
30
  end
51
31
 
52
32
  end
@@ -1,4 +1,4 @@
1
- class Admin::EffectiveClassifiedSubmissionsDatatable < Effective::Datatable
1
+ class Admin::EffectiveClassifiedWizardsDatatable < Effective::Datatable
2
2
  datatable do
3
3
  order :created_at
4
4
 
@@ -16,7 +16,7 @@ class Admin::EffectiveClassifiedSubmissionsDatatable < Effective::Datatable
16
16
  end
17
17
 
18
18
  collection do
19
- EffectiveSubmissions.ClassifiedSubmission.all.deep.done.joins(:classified)
19
+ EffectiveSubmissions.ClassifiedWizard.all.deep.done.joins(:classified)
20
20
  end
21
21
 
22
22
  end
@@ -18,7 +18,8 @@ module Admin
18
18
 
19
19
  col :id, visible: false
20
20
 
21
- col :classified_submission, visible: false, search: :string
21
+ col :classified_wizard, visible: false, search: :string
22
+ col :owner, visible: false, label: 'Submitted by'
22
23
 
23
24
  col :start_on, as: :date
24
25
  col :end_on, as: :date
@@ -28,7 +29,7 @@ module Admin
28
29
  end
29
30
 
30
31
  col :title
31
- col :body
32
+ col :body, visible: false
32
33
  col :slug, visible: false
33
34
 
34
35
  col :organization
@@ -0,0 +1,36 @@
1
+ # Dashboard Classified Submissions
2
+ class EffectiveClassifiedWizardsDatatable < Effective::Datatable
3
+ datatable do
4
+ order :created_at
5
+
6
+ col :token, visible: false
7
+ col :created_at, visible: false
8
+
9
+ col :submitted_at, label: 'Submitted' do |wizard|
10
+ wizard.submitted_at&.strftime('%F') || 'Incomplete'
11
+ end
12
+
13
+ col :classified, search: :string, label: 'Title'
14
+
15
+ col :owner, visible: false, search: :string
16
+
17
+ col :status, visible: false do |wizard|
18
+ wizard.classified&.status || wizard.status
19
+ end
20
+
21
+ actions_col(actions: []) do |wizard|
22
+ if wizard.draft?
23
+ dropdown_link_to('Continue', effective_classifieds.classified_wizard_build_path(wizard, wizard.next_step), 'data-turbolinks' => false)
24
+ else
25
+ dropdown_link_to('Edit', effective_classifieds.edit_classified_path(wizard.classified))
26
+ end
27
+
28
+ dropdown_link_to('Delete', effective_classifieds.classified_wizard_path(wizard), 'data-confirm': "Really delete #{wizard}?", 'data-method': :delete)
29
+ end
30
+ end
31
+
32
+ collection do
33
+ EffectiveClassifieds.ClassifiedWizard.deep.where(owner: current_user).left_joins(:classified)
34
+ end
35
+
36
+ end
@@ -1,21 +1,26 @@
1
1
  # Dashboard Classifieds
2
2
  class EffectiveClassifiedsDatatable < Effective::Datatable
3
3
  datatable do
4
+ length :all
4
5
  order :start_on
5
6
 
6
- col :start_on, as: :date, label: 'Starts'
7
- col :end_on, as: :date, label: 'Ends'
7
+ col :start_on, as: :date, label: 'Posted'
8
8
 
9
- col :title
10
- col :organization
11
- col :location
9
+ col :title do |classified|
10
+ link_to classified, effective_classifieds.classified_path(classified)
11
+ end
12
+
13
+ col :end_on, as: :date, label: 'Expires', visible: false
14
+
15
+ col :organization, visible: false
16
+ col :location, visible: false
12
17
 
13
18
  col :body, visible: false
14
19
  col :website, visible: false
15
20
  col :email, visible: false
16
21
  col :phone, visible: false
17
22
 
18
- actions_col(edit: false)
23
+ # actions_col(edit: false)
19
24
  end
20
25
 
21
26
  collection do
@@ -1,7 +1,2 @@
1
1
  module EffectiveClassifiedsHelper
2
-
3
- def edit_effective_classified_submissions_wizard?
4
- params[:controller] == 'effective/classified_submissions' && defined?(resource) && resource.draft?
5
- end
6
-
7
2
  end
@@ -1,28 +1,20 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # EffectiveClassifiedsClassifiedSubmission
3
+ # EffectiveClassifiedsClassifiedWizard
4
4
  #
5
- # Mark your owner model with effective_classifieds_classified_submission to get all the includes
5
+ # Mark your owner model with effective_classifieds_classified_wizard to get all the includes
6
6
 
7
- module EffectiveClassifiedsClassifiedSubmission
7
+ module EffectiveClassifiedsClassifiedWizard
8
8
  extend ActiveSupport::Concern
9
9
 
10
10
  module Base
11
- def effective_classifieds_classified_submission
12
- include ::EffectiveClassifiedsClassifiedSubmission
11
+ def effective_classifieds_classified_wizard
12
+ include ::EffectiveClassifiedsClassifiedWizard
13
13
  end
14
14
  end
15
15
 
16
16
  module ClassMethods
17
- def effective_classifieds_classified_submission?; true; end
18
-
19
- def all_wizard_steps
20
- const_get(:WIZARD_STEPS).keys
21
- end
22
-
23
- def required_wizard_steps
24
- [:start, :summary, :submitted]
25
- end
17
+ def effective_classifieds_classified_wizard?; true; end
26
18
  end
27
19
 
28
20
  included do
@@ -47,7 +39,7 @@ module EffectiveClassifiedsClassifiedSubmission
47
39
  accepts_nested_attributes_for :owner
48
40
 
49
41
  # Effective Namespace
50
- has_one :classified, class_name: 'Effective::Classified', inverse_of: :classified_submission, dependent: :destroy
42
+ has_one :classified, class_name: 'Effective::Classified', inverse_of: :classified_wizard, dependent: :destroy
51
43
  accepts_nested_attributes_for :classified, reject_if: :all_blank, allow_destroy: true
52
44
 
53
45
  effective_resource do
@@ -83,7 +75,7 @@ module EffectiveClassifiedsClassifiedSubmission
83
75
 
84
76
  # Instance Methods
85
77
  def to_s
86
- 'classified submission'
78
+ 'classified ad submission'
87
79
  end
88
80
 
89
81
  def in_progress?
@@ -10,18 +10,18 @@ module Effective
10
10
  log_changes if respond_to?(:log_changes)
11
11
  acts_as_role_restricted if respond_to?(:acts_as_role_restricted)
12
12
 
13
- # This will be the owner of the classified submission
13
+ # This will be the owner of the classified ad submission
14
14
  # Or the admin user that created it
15
15
  belongs_to :owner, polymorphic: true
16
16
 
17
17
  # When submitted through the wizard
18
- belongs_to :classified_submission, polymorphic: true, optional: true
18
+ belongs_to :classified_wizard, polymorphic: true, optional: true
19
19
 
20
20
  has_rich_text :body
21
21
 
22
22
  acts_as_statused(
23
23
  :draft, # Initial state
24
- :submitted, # Once submitted by the classified submission.
24
+ :submitted, # Once submitted by the classified ad submission.
25
25
  :approved # Exit state. Classified was approved.
26
26
  )
27
27
 
@@ -102,7 +102,7 @@ module Effective
102
102
  end
103
103
 
104
104
  # Automatically approve submissions created by admins outside the submissions wizard
105
- before_validation(if: -> { new_record? && classified_submission.blank? }) do
105
+ before_validation(if: -> { new_record? && classified_wizard.blank? }) do
106
106
  assign_attributes(status: :approved)
107
107
  end
108
108
 
@@ -0,0 +1,7 @@
1
+ module Effective
2
+ class ClassifiedWizard < ActiveRecord::Base
3
+ self.table_name = EffectiveClassifieds.classified_wizards_table_name.to_s
4
+
5
+ effective_classifieds_classified_wizard
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ .card
2
+ .card-body
3
+ .row
4
+ .col-sm
5
+ %h5.card-title= classified_wizard.wizard_step_title(:classified)
6
+ .col-sm-auto.text-right
7
+ = link_to('Edit', wizard_path(:classified)) if edit_effective_wizard?
8
+
9
+ - classified = classified_wizard.classified
10
+ = render 'effective/classifieds/classified', classified: classified
@@ -0,0 +1,3 @@
1
+ .effective-classified-wizard
2
+ - classified_wizard.render_steps.each do |partial|
3
+ = render "effective/classified_wizards/#{partial}", classified_wizard: classified_wizard, step: partial
@@ -0,0 +1,30 @@
1
+ - if can?(:new, EffectiveClassifieds.ClassifiedWizard)
2
+
3
+ -# In-progress submission
4
+ - submission = EffectiveClassifieds.ClassifiedWizard.in_progress.for(current_user).first
5
+ - datatable = EffectiveResources.best('EffectiveClassifiedWizardsDatatable').new(self, namespace: :effective)
6
+
7
+ - if submission.present?
8
+ %h2 In-progress Classified Ads
9
+
10
+ %p
11
+ Your submission for #{submission.classified.presence || 'a classified'} is incomplete.
12
+
13
+ %p
14
+ Please
15
+ = link_to("Continue submission for #{submission.classified.presence || 'a classified'}", effective_classifieds.classified_wizard_build_path(submission, submission.next_step), 'data-turbolinks' => false, class: 'btn btn-primary')
16
+ or you can
17
+ = link_to('Abandon submission', effective_classifieds.classified_wizard_path(submission), 'data-confirm': "Really delete #{submission}?", 'data-method': :delete, class: 'btn btn-danger')
18
+ to submit another.
19
+
20
+ %hr
21
+
22
+ %h2 Classified Ads
23
+
24
+ - if datatable.present?
25
+ = render_simple_datatable(datatable)
26
+ - else
27
+ %p You don't have any classified ads. When you do, we'll show them here.
28
+
29
+ - if submission.blank?
30
+ %p= link_to 'Submit New Classified Ad', effective_classifieds.new_classified_wizard_path, class: 'btn btn-primary'
@@ -1,5 +1,5 @@
1
- = card('Classified Submission') do
2
- - classified = classified_submission.classified
1
+ = card('Classified Ad') do
2
+ - classified = classified_wizard.classified
3
3
 
4
4
  %table.table.table-sm
5
5
  %tbody
@@ -16,12 +16,12 @@
16
16
  %tr
17
17
  %th Owner
18
18
  %td
19
- - url = (polymorphic_admin_path(classified_submission.owner) rescue "/admin/users/#{classified_submission.owner.to_param}/edit")
20
- = link_to(classified_submission.owner, url)
19
+ - url = (polymorphic_admin_path(classified_wizard.owner) rescue "/admin/users/#{classified_wizard.owner.to_param}/edit")
20
+ = link_to(classified_wizard.owner, url)
21
21
  - else
22
22
  %tr
23
23
  %th Owner
24
- %td= classified_submission.owner
24
+ %td= classified_wizard.owner
25
25
 
26
26
  - if classified&.was_submitted?
27
27
  %tr
@@ -1,5 +1,5 @@
1
1
  = render 'layout' do
2
- = render 'effective/classified_submissions/content', resource: resource
2
+ = render 'effective/classified_wizards/content', resource: resource
3
3
 
4
4
  .card
5
5
  .card-body
@@ -0,0 +1,20 @@
1
+ = render 'layout' do
2
+ = render 'effective/classified_wizards/content', resource: resource
3
+
4
+ .card
5
+ .card-body
6
+ %p
7
+ Welcome #{current_user}!
8
+
9
+ %p
10
+ You can use this wizard to post a new classified ad.
11
+ Your progress will be saved as you move through the wizard.
12
+ Once the ad published you will be able to come back and edit/change the details.
13
+
14
+ = effective_form_with(model: resource, url: wizard_path(step), method: :put) do |f|
15
+ = f.hidden_field :id
16
+
17
+ = f.hidden_field :owner_type
18
+ = f.hidden_field :owner_id
19
+
20
+ = f.save 'Save and Continue'
@@ -0,0 +1,14 @@
1
+ = render 'layout' do
2
+ = render 'effective/classified_wizards/content', resource: resource
3
+
4
+ - raise('expected a submitted classified_wizard') unless resource.was_submitted?
5
+
6
+ .alert.alert-warning.mb-4
7
+ Successfully submitted on #{resource.submitted_at.strftime('%F')}.
8
+
9
+ = link_to "Return to Dashboard", root_path, class: 'btn btn-lg btn-primary mb-4'
10
+
11
+ = render 'effective/classified_wizards/summary', classified_wizard: resource
12
+ = render 'effective/classified_wizards/classified_wizard', classified_wizard: resource
13
+
14
+ = link_to "Return to Dashboard", root_path, class: 'btn btn-lg btn-primary'
@@ -0,0 +1,8 @@
1
+ = render 'layout' do
2
+ = render 'effective/classified_wizards/content', resource: resource
3
+
4
+ = render('effective/classified_wizards/classified_wizard', classified_wizard: resource)
5
+
6
+ = effective_form_with(model: resource, url: wizard_path(step), method: :put) do |f|
7
+ = f.hidden_field :id
8
+ = f.submit 'Submit Classified Ad', class: 'btn btn-primary'
@@ -1,50 +1,46 @@
1
- .card.effective-classified
1
+ .card
2
2
  .card-body
3
- %h5.card-title= classified.title
4
-
5
3
  %table.table.effective-classified-table
6
4
  %tbody
7
5
  %tr
8
- %td Category
6
+ %th Category
9
7
  %td= classified.category
10
8
 
11
9
  %tr
12
- %td Available
13
- %td #{classified.start_on&.strftime('%F')} to #{classified.end_on&.strftime('%F')}
10
+ %th Title
11
+ %td= classified.title
14
12
 
15
13
  %tr
16
- %td Location
17
- %td= classified.location.presence || '-'
14
+ %th Available
15
+ %td
16
+ #{classified.start_on&.strftime('%F')}
17
+ to
18
+ #{classified.end_on&.strftime('%F')}
19
+
20
+ - if classified.website.present?
21
+ %tr
22
+ %th Location
23
+ %td= classified.location
18
24
 
19
25
  %tr
20
- %td Website
21
- %td
22
- - if classified.website.present?
23
- = link_to(classified.website, classified.website, target: '_blank')
24
- - else
25
- = '-'
26
+ %th Description
27
+ %td= classified.body
26
28
 
27
29
  %tr
28
- %td Contact
30
+ %th Company
29
31
  %td= classified.organization
30
32
 
31
- %tr
32
- %td Email
33
- %td
34
- - if classified.email.present?
35
- = mail_to(classified.email)
36
- - else
37
- = '-'
33
+ - if classified.website.present?
34
+ %tr
35
+ %th Website
36
+ %td= link_to(classified.website, classified.website, target: '_blank')
38
37
 
39
- %tr
40
- %td Phone
41
- %td
42
- - if classified.phone.present?
43
- = classified.phone
44
- - else
45
- = '-'
46
-
47
- - if block_given?
48
- = yield
49
- - else
50
- %p= link_to('View Classified', effective_classifieds.classified_path(classified), class: 'btn btn-primary')
38
+ - if classified.email.present?
39
+ %tr
40
+ %th Email
41
+ %td= mail_to(classified.email)
42
+
43
+ - if classified.phone.present?
44
+ %tr
45
+ %th Phone
46
+ %td= classified.phone
@@ -2,7 +2,10 @@
2
2
 
3
3
  - published = Effective::Classified.classifieds(user: current_user).count
4
4
 
5
- - datatable = EffectiveClassifiedsDatatable.new(self, namespace: :effective)
6
- = render_datatable(datatable, simple: true)
5
+ - if published > 0
6
+ - datatable = EffectiveClassifiedsDatatable.new(self, namespace: :effective)
7
+ = render_datatable(datatable, simple: true)
8
+ - else
9
+ %p There are no active classified ads. When there are, we'll show them here.
7
10
 
8
11
  %p= link_to 'View All Classifieds', effective_classifieds.classifieds_path, class: 'btn btn-primary'
@@ -1,5 +1,6 @@
1
- = f.text_field :title
2
1
  = f.select :category, EffectiveClassifieds.categories, required: true
2
+ = f.text_field :title
3
+ = f.text_field :location
3
4
 
4
5
  - if f.object.persisted? || f.object.errors.include?(:slug)
5
6
  - current_url = (effective_classifieds.classified_url(f.object) rescue nil)
@@ -7,22 +8,27 @@
7
8
 
8
9
  - minDate = [Time.zone.now, f.object.created_at].compact.min
9
10
 
10
- = f.date_field :start_on, label: "Classified Start",
11
- hint: 'The classified ad will be displayed starting on this date',
12
- input_js: { minDate: minDate.strftime('%F') }
11
+ .row
12
+ .col-lg-6
13
+ = f.date_field :start_on, label: "Start",
14
+ hint: 'The classified ad will be displayed starting after this date.',
15
+ input_js: { minDate: minDate.strftime('%F') }
13
16
 
14
- = f.date_field :end_on, label: "Classified End",
15
- hint: 'The classified ad will no longer be displayed on this date'
17
+ .col-lg-6
18
+ = f.date_field :end_on, label: "Expire",
19
+ hint: 'The classified ad will no longer be displayed after this date.'
16
20
 
17
21
  - if f.object.persisted? && !f.object.draft?
18
22
  = f.check_box :archived, label: 'Yes, this classified is archived and will not be displayed'
19
23
 
20
- %h2 Classified Content
21
- = f.rich_text_area :body, hint: 'The main body of your classified'
22
- = f.text_field :location
23
- = f.url_field :website
24
+ = f.rich_text_area :body, label: 'Body content', hint: 'The main body content of your classified ad. Be sure to include all relevant information!'
25
+
24
26
 
25
- %h2 Contact Information
26
- = f.text_field :organization
27
+ %h2.mt-5.mb-0 Contact Information
28
+ %p
29
+ %small.text-muted Contact information will be displayed on the classified ad.
30
+
31
+ = f.text_field :organization, label: 'Company or Organization'
32
+ = f.url_field :website
27
33
  = f.email_field :email
28
34
  = f.tel_field :phone
@@ -0,0 +1,5 @@
1
+ .card
2
+ .card-body
3
+ = effective_form_with(model: @classified, engine: true) do |f|
4
+ = render('effective/classifieds/fields', f: f, classified: f.object)
5
+ = effective_submit(f)
@@ -1,8 +1,8 @@
1
- %h1= @page_title
1
+ .resource-buttons
2
+ = link_to 'Submit New Classified Ad', effective_classifieds.new_classified_wizard_path, class: 'btn btn-primary'
2
3
 
3
- = render 'layout' do
4
- .effective-classifieds
5
- = render partial: @classifieds, spacer_template: 'spacer'
6
-
7
- %nav.d-flex.justify-content-center
8
- = bootstrap_paginate(@classifieds, per_page: EffectiveClassifieds.per_page)
4
+ = card do
5
+ - if @datatable.present?(self)
6
+ = render_datatable(@datatable, simple: true)
7
+ - else
8
+ %p There are no active classified ads. When there are, we'll show them here.
@@ -1,8 +1,8 @@
1
- = render 'layout' do
2
- .effective-classified
3
- - unless @classified.published?
4
- .alert.alert-warning This classified is currently unavailable.
1
+ .effective-classified
2
+ - unless @classified.published?
3
+ .alert.alert-warning.mb-4 This classified is currently unavailable.
5
4
 
6
- = render 'effective/classifieds/classified', classified: @classified do
7
- .classified-body.classified-content
8
- = @classified.body
5
+ = render 'effective/classifieds/classified', classified: @classified
6
+
7
+ .resource-buttons.text-left
8
+ = link_to 'View All Classifieds', effective_classifieds.classifieds_path, class: 'btn btn-primary'
@@ -1,16 +1,20 @@
1
1
  %p Hello Admin!
2
2
 
3
3
  - if @classified.published?
4
- %p The following classified has been submitted and is published online:
4
+ %p The following classified ad has been submitted and is published online:
5
5
  - else
6
- %p The following classified has been submitted and is awaiting your approval:
7
- %p= link_to('Approve Classified', effective_classifieds.edit_admin_classified_path(@classified))
6
+ %p The following classified ad has been submitted and is awaiting your approval:
7
+
8
+ %hr
8
9
 
9
10
  = render('effective/classifieds/classified', classified: @classified) do
10
11
  %p= @classified.body
11
12
 
12
13
  %hr
13
14
 
14
- %p= link_to('View Classified', effective_classifieds.classified_path(@classified))
15
+ - if !@classified.published?
16
+ %p= link_to('Approve Classified Ad', effective_classifieds.edit_admin_classified_path(@classified))
17
+
18
+ %p= link_to('View Classified Ad', effective_classifieds.classified_path(@classified))
15
19
 
16
20
  %p Have a great day!
@@ -1,19 +1,19 @@
1
1
  EffectiveClassifieds.setup do |config|
2
2
  config.classifieds_table_name = :classifieds
3
- config.classified_submissions_table_name = :classified_submissions
3
+ config.classified_wizards_table_name = :classified_wizards
4
4
 
5
5
  # Every classified must have a category.
6
- config.categories = ['Job Board', 'Equipment Sales']
6
+ config.categories = ['Job', 'Equipment Sales', 'Other']
7
7
 
8
8
  # Layout Settings
9
9
  # Configure the Layout per controller, or all at once
10
10
  # config.layout = { application: 'application', admin: 'admin' }
11
11
 
12
12
  # Classified Settings
13
- # config.classified_submission_class_name = 'Effective::ClassifiedSubmission'
13
+ # config.classified_wizard_class_name = 'Effective::ClassifiedWizard'
14
14
 
15
15
  # Pagination length on the Classified#index page
16
- config.per_page = 10
16
+ config.per_page = :all
17
17
 
18
18
  # Classified can be restricted by role
19
19
  config.use_effective_roles = true
@@ -21,7 +21,7 @@ EffectiveClassifieds.setup do |config|
21
21
  # Automatically end classifieds after this duration
22
22
  config.max_duration = 3.months
23
23
 
24
- # Automatically approve classified submissions, otherwise require admin approval
24
+ # Automatically approve classified ad submissions, otherwise require admin approval
25
25
  config.auto_approve = false
26
26
 
27
27
  # Mailer Configuration
data/config/routes.rb CHANGED
@@ -9,8 +9,8 @@ EffectiveClassifieds::Engine.routes.draw do
9
9
  scope module: 'effective' do
10
10
  resources :classifieds, only: [:index, :show, :edit, :update]
11
11
 
12
- resources :classified_submissions, only: [:new, :show, :destroy] do
13
- resources :build, controller: :classified_submissions, only: [:show, :update]
12
+ resources :classified_wizards, only: [:new, :show, :destroy] do
13
+ resources :build, controller: :classified_wizards, only: [:show, :update]
14
14
  end
15
15
 
16
16
  end
@@ -1,8 +1,8 @@
1
1
  class CreateEffectiveClassifieds < ActiveRecord::Migration[6.1]
2
2
  def change
3
3
  create_table <%= @classifieds_table_name %> do |t|
4
- t.integer :classified_submission_id
5
- t.string :classified_submission_type
4
+ t.integer :classified_wizard_id
5
+ t.string :classified_wizard_type
6
6
 
7
7
  t.integer :owner_id
8
8
  t.string :owner_type
@@ -36,7 +36,7 @@ class CreateEffectiveClassifieds < ActiveRecord::Migration[6.1]
36
36
  add_index :classifieds, [:owner_id, :owner_type]
37
37
  add_index :classifieds, :slug
38
38
 
39
- create_table <%= @classified_submissions_table_name %> do |t|
39
+ create_table <%= @classified_wizards_table_name %> do |t|
40
40
  t.string :token
41
41
 
42
42
  t.integer :owner_id
@@ -56,7 +56,7 @@ class CreateEffectiveClassifieds < ActiveRecord::Migration[6.1]
56
56
  t.datetime :created_at
57
57
  end
58
58
 
59
- add_index :classified_submissions, [:owner_id, :owner_type]
60
- add_index :classified_submissions, :token
59
+ add_index :classified_wizards, [:owner_id, :owner_type]
60
+ add_index :classified_wizards, :token
61
61
  end
62
62
  end
@@ -10,7 +10,7 @@ module EffectiveClassifieds
10
10
  # Include acts_as_addressable concern and allow any ActiveRecord object to call it
11
11
  initializer 'effective_classifieds.active_record' do |app|
12
12
  ActiveSupport.on_load :active_record do
13
- ActiveRecord::Base.extend(EffectiveClassifiedsClassifiedSubmission::Base)
13
+ ActiveRecord::Base.extend(EffectiveClassifiedsClassifiedWizard::Base)
14
14
  end
15
15
  end
16
16
 
@@ -1,3 +1,3 @@
1
1
  module EffectiveClassifieds
2
- VERSION = '0.0.2'.freeze
2
+ VERSION = '0.2.1'.freeze
3
3
  end
@@ -7,17 +7,17 @@ module EffectiveClassifieds
7
7
 
8
8
  def self.config_keys
9
9
  [
10
- :classifieds_table_name, :classified_submissions_table_name,
10
+ :classifieds_table_name, :classified_wizards_table_name,
11
11
  :layout, :categories, :per_page, :use_effective_roles, :max_duration, :auto_approve,
12
- :classified_submission_class_name,
12
+ :classified_wizard_class_name,
13
13
  :mailer, :parent_mailer, :deliver_method, :mailer_layout, :mailer_sender, :mailer_admin
14
14
  ]
15
15
  end
16
16
 
17
17
  include EffectiveGem
18
18
 
19
- def self.ClassifiedSubmission
20
- classified_submission_class_name&.constantize || Effective::ClassifiedSubmission
19
+ def self.ClassifiedWizard
20
+ classified_wizard_class_name&.constantize || Effective::ClassifiedWizard
21
21
  end
22
22
 
23
23
  def self.mailer_class
@@ -21,7 +21,7 @@ module EffectiveMemberships
21
21
 
22
22
  def create_migration_file
23
23
  @classifieds_table_name = ':' + EffectiveClassifieds.classifieds_table_name.to_s
24
- @classified_submissions_table_name = ':' + EffectiveClassifieds.classified_submissions_table_name.to_s
24
+ @classified_wizards_table_name = ':' + EffectiveClassifieds.classified_wizards_table_name.to_s
25
25
 
26
26
  migration_template ('../' * 3) + 'db/migrate/01_create_effective_classifieds.rb.erb', 'db/migrate/create_effective_classifieds.rb'
27
27
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_classifieds
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-19 00:00:00.000000000 Z
11
+ date: 2022-01-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -179,38 +179,37 @@ files:
179
179
  - app/assets/javascripts/effective_classifieds/base.js
180
180
  - app/assets/stylesheets/effective_classifieds.scss
181
181
  - app/assets/stylesheets/effective_classifieds/base.scss
182
- - app/controllers/admin/classified_submissions_controller.rb
182
+ - app/controllers/admin/classified_wizards_controller.rb
183
183
  - app/controllers/admin/classifieds_controller.rb
184
- - app/controllers/effective/classified_submissions_controller.rb
184
+ - app/controllers/effective/classified_wizards_controller.rb
185
185
  - app/controllers/effective/classifieds_controller.rb
186
- - app/datatables/admin/effective_classified_submissions_datatable.rb
186
+ - app/datatables/admin/effective_classified_wizards_datatable.rb
187
187
  - app/datatables/admin/effective_classifieds_datatable.rb
188
- - app/datatables/effective_classified_submissions_datatable.rb
188
+ - app/datatables/effective_classified_wizards_datatable.rb
189
189
  - app/datatables/effective_classifieds_datatable.rb
190
190
  - app/helpers/effective_classifieds_helper.rb
191
191
  - app/mailers/effective/classifieds_mailer.rb
192
- - app/models/concerns/effective_classifieds_classified_submission.rb
192
+ - app/models/concerns/effective_classifieds_classified_wizard.rb
193
193
  - app/models/effective/classified.rb
194
- - app/models/effective/classified_submission.rb
194
+ - app/models/effective/classified_wizard.rb
195
195
  - app/views/admin/classifieds/_form.html.haml
196
196
  - app/views/admin/classifieds/_form_access.html.haml
197
197
  - app/views/admin/classifieds/_form_classified.html.haml
198
- - app/views/effective/classified_submissions/_classified.haml
199
- - app/views/effective/classified_submissions/_classified_submission.html.haml
200
- - app/views/effective/classified_submissions/_content.html.haml
201
- - app/views/effective/classified_submissions/_dashboard.html.haml
202
- - app/views/effective/classified_submissions/_layout.html.haml
203
- - app/views/effective/classified_submissions/_summary.html.haml
204
- - app/views/effective/classified_submissions/classified.html.haml
205
- - app/views/effective/classified_submissions/start.html.haml
206
- - app/views/effective/classified_submissions/submitted.html.haml
207
- - app/views/effective/classified_submissions/summary.html.haml
198
+ - app/views/effective/classified_wizards/_classified.html.haml
199
+ - app/views/effective/classified_wizards/_classified_wizard.html.haml
200
+ - app/views/effective/classified_wizards/_content.html.haml
201
+ - app/views/effective/classified_wizards/_dashboard.html.haml
202
+ - app/views/effective/classified_wizards/_layout.html.haml
203
+ - app/views/effective/classified_wizards/_summary.html.haml
204
+ - app/views/effective/classified_wizards/classified.html.haml
205
+ - app/views/effective/classified_wizards/start.html.haml
206
+ - app/views/effective/classified_wizards/submitted.html.haml
207
+ - app/views/effective/classified_wizards/summary.html.haml
208
208
  - app/views/effective/classifieds/_classified.html.haml
209
209
  - app/views/effective/classifieds/_dashboard.html.haml
210
210
  - app/views/effective/classifieds/_fields.html.haml
211
211
  - app/views/effective/classifieds/_form.html.haml
212
- - app/views/effective/classifieds/_layout.html.haml
213
- - app/views/effective/classifieds/_spacer.html.haml
212
+ - app/views/effective/classifieds/edit.html.haml
214
213
  - app/views/effective/classifieds/index.html.haml
215
214
  - app/views/effective/classifieds/show.html.haml
216
215
  - app/views/effective/classifieds_mailer/classified_submitted.html.haml
@@ -1,19 +0,0 @@
1
- module Admin
2
- class ClassifiedSubmissionsController < ApplicationController
3
- before_action(:authenticate_user!) if defined?(Devise)
4
- before_action { EffectiveResources.authorize!(self, :admin, :effective_classifieds) }
5
-
6
- include Effective::CrudController
7
-
8
- resource_scope -> { EffectiveEvents.ClassifiedSubmission.deep.all }
9
- datatable -> { Admin::EffectiveClassifiedSubmissionsDatatable.new }
10
-
11
- private
12
-
13
- def permitted_params
14
- model = (params.key?(:effective_classified_submission) ? :effective_classified_submission : :classified_submission)
15
- params.require(model).permit!
16
- end
17
-
18
- end
19
- end
@@ -1,31 +0,0 @@
1
- module Effective
2
- class ClassifiedSubmissionsController < ApplicationController
3
- before_action(:authenticate_user!) if defined?(Devise)
4
-
5
- include Effective::WizardController
6
-
7
- resource_scope -> { EffectiveClassifieds.ClassifiedSubmission.deep.where(owner: current_user) }
8
-
9
- # Allow only 1 in-progress application at a time
10
- before_action(only: [:new, :show], unless: -> { resource&.done? }) do
11
- existing = resource_scope.in_progress.where.not(id: resource).first
12
-
13
- if existing.present?
14
- flash[:success] = "You have been redirected to your existing in progress classified submission"
15
- redirect_to effective_classifieds.classified_submission_build_path(existing, existing.next_step)
16
- end
17
- end
18
-
19
- after_save do
20
- flash.now[:success] = ''
21
- end
22
-
23
- private
24
-
25
- def permitted_params
26
- model = (params.key?(:effective_classified_submission) ? :effective_classified_submission : :classified_submission)
27
- params.require(model).permit!.except(:status, :status_steps, :wizard_steps, :submitted_at)
28
- end
29
-
30
- end
31
- end
@@ -1,37 +0,0 @@
1
- # Dashboard Classified Submissions
2
- class EffectiveClassifiedSubmissionsDatatable < Effective::Datatable
3
- datatable do
4
- order :created_at
5
-
6
- col :token, visible: false
7
- col :created_at, visible: false
8
-
9
- col :submitted_at do |submission|
10
- submission.submitted_at&.strftime('%F') || 'Incomplete'
11
- end
12
-
13
- col :classified, search: :string
14
-
15
- col :owner, visible: false, search: :string
16
-
17
- col :status do |submission|
18
- submission.classified&.status || submission.status
19
- end
20
-
21
- actions_col(actions: []) do |submission|
22
- if submission.draft?
23
- dropdown_link_to('Continue', effective_classifieds.classified_submission_build_path(submission, submission.next_step), 'data-turbolinks' => false)
24
- else
25
- dropdown_link_to('Show', effective_classifieds.classified_submission_path(submission))
26
- dropdown_link_to('Edit', effective_classifieds.edit_classified_path(submission.classified)) if submission.classified
27
- end
28
-
29
- dropdown_link_to('Delete', effective_classifieds.classified_submission_path(submission), 'data-confirm': "Really delete #{submission}?", 'data-method': :delete)
30
- end
31
- end
32
-
33
- collection do
34
- EffectiveClassifieds.ClassifiedSubmission.deep.where(owner: current_user).left_joins(:classified)
35
- end
36
-
37
- end
@@ -1,7 +0,0 @@
1
- module Effective
2
- class ClassifiedSubmission < ActiveRecord::Base
3
- self.table_name = EffectiveClassifieds.classified_submissions_table_name.to_s
4
-
5
- effective_classifieds_classified_submission
6
- end
7
- end
@@ -1,12 +0,0 @@
1
- = card do
2
- .row
3
- .col-sm
4
- %h5.card-title= classified_submission.wizard_step_title(:classified)
5
- .col-sm-auto.text-right
6
- = link_to('Edit', wizard_path(:classified)) if edit_effective_classified_submissions_wizard?
7
-
8
- - classified = classified_submission.classified
9
-
10
- - if classified.present?
11
- = render('effective/classifieds/classified', classified: classified) do
12
- = classified.body
@@ -1,8 +0,0 @@
1
- .effective-classified-submission
2
- - blacklist = EffectiveClassifieds.ClassifiedSubmission.required_wizard_steps
3
- - steps = classified_submission.required_steps - blacklist
4
-
5
- = render "effective/classified_submissions/summary", classified_submission: classified_submission
6
-
7
- - steps.select { |step| classified_submission.has_completed_step?(step) }.each do |partial|
8
- = render "effective/classified_submissions/#{partial}", classified_submission: classified_submission, step: partial
@@ -1,28 +0,0 @@
1
- -# In progress submission
2
- - submission = EffectiveClassifieds.ClassifiedSubmission.in_progress.for(current_user).first
3
- - datatable = EffectiveResources.best('EffectiveClassifiedSubmissionsDatatable').new(self, namespace: :effective)
4
-
5
- - if submission.present?
6
- %h2 In Progress Classified Submissions
7
-
8
- %p
9
- Your submission for #{submission.classified.presence || 'a classified'} is incomplete
10
-
11
- %p
12
- Please
13
- = link_to("Continue submission for #{submission.classified.presence || 'a classified'}", effective_classifieds.classified_submission_build_path(submission, submission.next_step), 'data-turbolinks' => false, class: 'btn btn-primary')
14
- or you can
15
- = link_to('Abandon submission', effective_classifieds.classified_submission_path(submission), 'data-confirm': "Really delete #{submission}?", 'data-method': :delete, class: 'btn btn-danger')
16
- to submit another.
17
-
18
- %hr
19
-
20
- %h2 Classified Submissions
21
-
22
- - if datatable.present?
23
- = render_simple_datatable(datatable)
24
- - else
25
- %p You have no past classified submissions. When you do, we'll show them here.
26
-
27
- - if submission.blank?
28
- %p= link_to 'Submit New Classified', effective_classifieds.new_classified_submission_path, class: 'btn btn-primary'
@@ -1,16 +0,0 @@
1
- = render 'layout' do
2
- = render 'effective/classified_submissions/content', resource: resource
3
-
4
- .card
5
- .card-body
6
- %p Welcome #{current_user}!
7
-
8
- %p You are about to submit a classified
9
-
10
- = effective_form_with(model: resource, url: wizard_path(step), method: :put) do |f|
11
- = f.hidden_field :id
12
-
13
- = f.hidden_field :owner_type
14
- = f.hidden_field :owner_id
15
-
16
- = f.save 'Save and Continue'
@@ -1,13 +0,0 @@
1
- = render 'layout' do
2
- = render 'effective/classified_submissions/content', resource: resource
3
-
4
- - raise('expected a submitted classified_submission') unless resource.was_submitted?
5
-
6
- .alert.alert-warning.mb-4
7
- Successfully submitted on #{resource.submitted_at.strftime('%F')}.
8
-
9
- = link_to "Return to Dashboard", root_path, class: 'btn btn-lg btn-primary mb-4'
10
-
11
- = render 'effective/classified_submissions/classified_submission', classified_submission: resource
12
-
13
- = link_to "Return to Dashboard", root_path, class: 'btn btn-lg btn-primary'
@@ -1,8 +0,0 @@
1
- = render 'layout' do
2
- = render 'effective/classified_submissions/content', resource: resource
3
-
4
- = render('effective/classified_submissions/classified_submission', classified_submission: resource)
5
-
6
- = effective_form_with(model: resource, url: wizard_path(step), method: :put) do |f|
7
- = f.hidden_field :id
8
- = f.submit 'Submit Classified', class: 'btn btn-primary'
@@ -1 +0,0 @@
1
- = yield