dorsale 3.3.0 → 3.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (116) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +9 -0
  3. data/app/assets/stylesheets/dorsale/engines/flyboy.sass +0 -7
  4. data/app/controllers/dorsale/alexandrie/attachments_controller.rb +7 -0
  5. data/app/controllers/dorsale/application_controller.rb +1 -0
  6. data/app/controllers/dorsale/billing_machine/invoices_controller.rb +2 -0
  7. data/app/controllers/dorsale/billing_machine/quotations_controller.rb +2 -0
  8. data/app/controllers/dorsale/customer_vault/application_controller.rb +0 -4
  9. data/app/controllers/dorsale/customer_vault/people_controller.rb +0 -2
  10. data/app/controllers/dorsale/expense_gun/expenses_controller.rb +2 -2
  11. data/app/controllers/dorsale/flyboy/application_controller.rb +0 -3
  12. data/app/controllers/dorsale/flyboy/tasks_controller.rb +2 -8
  13. data/app/helpers/dorsale/all_helpers.rb +1 -0
  14. data/app/helpers/dorsale/flyboy/application_helper.rb +3 -12
  15. data/app/helpers/dorsale/link_helper.rb +10 -0
  16. data/app/helpers/dorsale/sorting_helper.rb +48 -0
  17. data/app/mailers/dorsale/billing_machine/invoice_mailer.rb +1 -1
  18. data/app/models/concerns/dorsale/model_i18n.rb +25 -0
  19. data/app/models/concerns/dorsale/model_to_s.rb +9 -0
  20. data/{lib → app/models/concerns}/dorsale/polymorphic_id.rb +1 -3
  21. data/app/models/concerns/dorsale/search.rb +30 -0
  22. data/app/models/dorsale/alexandrie/attachment.rb +7 -6
  23. data/app/models/dorsale/application_record.rb +6 -0
  24. data/app/models/dorsale/billing_machine/invoice.rb +2 -6
  25. data/app/models/dorsale/billing_machine/quotation.rb +4 -4
  26. data/app/models/dorsale/customer_vault/person.rb +0 -2
  27. data/app/models/dorsale/expense_gun/expense.rb +8 -8
  28. data/app/models/dorsale/flyboy/task.rb +5 -16
  29. data/app/pdfs/concerns/dorsale/alexandrie/prawn/render_with_attachments.rb +13 -0
  30. data/app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb +6 -1
  31. data/app/pdfs/dorsale/billing_machine/quotation_pdf_common_methods.rb +0 -18
  32. data/app/policies/dorsale/expense_gun/expense_policy_helper.rb +1 -1
  33. data/app/policies/dorsale/flyboy/task_policy_helper.rb +0 -10
  34. data/app/policies/dorsale/policy_checker.rb +0 -1
  35. data/app/services/dorsale/billing_machine/pdf_file_generator.rb +37 -0
  36. data/app/services/dorsale/expense_gun/expense/copy.rb +1 -1
  37. data/app/uploaders/dorsale/pdf_uploader.rb +5 -0
  38. data/app/views/dorsale/billing_machine/invoices/_details.html.slim +1 -1
  39. data/app/views/dorsale/billing_machine/invoices/_list.html.slim +1 -2
  40. data/app/views/dorsale/billing_machine/invoices/index.pdf.ruby +2 -2
  41. data/app/views/dorsale/billing_machine/invoices/show.pdf.ruby +1 -1
  42. data/app/views/dorsale/billing_machine/quotations/_list.html.slim +1 -2
  43. data/app/views/dorsale/billing_machine/quotations/show.pdf.ruby +1 -1
  44. data/app/views/dorsale/comments/_comment.html.slim +1 -1
  45. data/app/views/dorsale/customer_vault/links/new.html.slim +1 -1
  46. data/app/views/dorsale/customer_vault/people/_list_item.html.slim +1 -1
  47. data/app/views/dorsale/flyboy/tasks/_form.html.slim +3 -0
  48. data/app/views/dorsale/flyboy/tasks/_index_actions.html.slim +3 -0
  49. data/app/views/dorsale/flyboy/tasks/_list.html.slim +6 -12
  50. data/app/views/dorsale/flyboy/tasks/_summary_list.html.slim +2 -3
  51. data/app/views/dorsale/flyboy/tasks/_taskable_context.html.slim +1 -1
  52. data/app/views/dorsale/flyboy/tasks/index.xlsx.ruby +2 -4
  53. data/config/locales/billing_machine.en.yml +1 -0
  54. data/config/locales/billing_machine.fr.yml +1 -0
  55. data/config/locales/common.en.yml +3 -3
  56. data/config/locales/expense_gun.fr.yml +12 -12
  57. data/config/locales/flyboy.en.yml +1 -28
  58. data/config/locales/flyboy.fr.yml +1 -28
  59. data/config/routes.rb +0 -7
  60. data/db/migrate/20170127131537_delete_folders.rb +10 -0
  61. data/db/migrate/20170127151610_fix_expense_state.rb +6 -0
  62. data/db/migrate/20170127155636_billing_machine_add_pdf_file.rb +16 -0
  63. data/features/expense_gun_expenses.feature +3 -3
  64. data/features/flyboy_task_comments.feature +1 -1
  65. data/features/flyboy_tasks.feature +3 -4
  66. data/features/flyboy_tasks_summary.feature +0 -1
  67. data/features/step_definitions/billing_machine_invoices_steps.rb +1 -0
  68. data/features/step_definitions/expense_gun_expenses_steps.rb +2 -2
  69. data/features/step_definitions/flyboy_tasks_steps.rb +2 -3
  70. data/features/step_definitions/tasks_summary_steps.rb +3 -3
  71. data/lib/dorsale/active_record_comma_type_cast.rb +12 -0
  72. data/lib/dorsale/core_and_rails_ext.rb +3 -0
  73. data/lib/dorsale/engine.rb +6 -10
  74. data/lib/dorsale/form_back_url.rb +3 -1
  75. data/lib/dorsale/version.rb +1 -1
  76. data/spec/controllers/dorsale/billing_machine/invoices_controller_spec.rb +4 -1
  77. data/spec/controllers/dorsale/flyboy/tasks_controller_spec.rb +7 -30
  78. data/spec/factories/flyboy_tasks.rb +0 -2
  79. data/spec/helpers/dorsale/flyboy/application_helper_spec.rb +0 -64
  80. data/spec/helpers/dorsale/sorting_helper_spec.rb +74 -0
  81. data/spec/libs/{active_record_comma_type_cast_spec.rb → dorsale/active_record_comma_type_cast_spec.rb} +1 -1
  82. data/spec/libs/dorsale/polymorphic_id_spec.rb +8 -7
  83. data/spec/models/{dorsale → concerns/dorsale}/model_i18n_spec.rb +0 -0
  84. data/spec/models/dorsale/expense_gun/expense_spec.rb +19 -19
  85. data/spec/models/dorsale/flyboy/task_spec.rb +2 -1
  86. data/spec/pdfs/dorsale/billing_machine/invoice_multiple_vat_pdf_spec.rb +18 -13
  87. data/spec/pdfs/dorsale/billing_machine/invoice_single_vat_pdf_spec.rb +18 -13
  88. data/spec/pdfs/dorsale/billing_machine/quotation_multiple_vat_pdf_spec.rb +18 -13
  89. data/spec/pdfs/dorsale/billing_machine/quotation_single_vat_pdf_spec.rb +25 -19
  90. data/spec/services/dorsale/expense_gun/expense/copy_spec.rb +1 -1
  91. metadata +21 -52
  92. data/app/controllers/dorsale/flyboy/folders_controller.rb +0 -140
  93. data/app/filters/dorsale/flyboy/small_data/filter_for_folders.rb +0 -5
  94. data/app/filters/dorsale/flyboy/small_data/filter_strategy_by_status.rb +0 -9
  95. data/app/models/dorsale/flyboy/folder.rb +0 -72
  96. data/app/policies/dorsale/flyboy/folder_policy_helper.rb +0 -26
  97. data/app/views/dorsale/flyboy/folders/_context.html.slim +0 -18
  98. data/app/views/dorsale/flyboy/folders/_context_actions.html.slim +0 -10
  99. data/app/views/dorsale/flyboy/folders/_form.html.slim +0 -17
  100. data/app/views/dorsale/flyboy/folders/_index_actions.html.slim +0 -2
  101. data/app/views/dorsale/flyboy/folders/_list.html.slim +0 -41
  102. data/app/views/dorsale/flyboy/folders/edit.html.slim +0 -8
  103. data/app/views/dorsale/flyboy/folders/index.html.slim +0 -22
  104. data/app/views/dorsale/flyboy/folders/new.html.slim +0 -2
  105. data/app/views/dorsale/flyboy/folders/show.html.slim +0 -14
  106. data/features/flyboy_folders.feature +0 -109
  107. data/features/step_definitions/flyboy_folders_steps.rb +0 -170
  108. data/lib/active_record_comma_type_cast.rb +0 -12
  109. data/lib/dorsale/alexandrie/prawn.rb +0 -17
  110. data/lib/dorsale/model_i18n.rb +0 -30
  111. data/lib/dorsale/model_to_s.rb +0 -13
  112. data/lib/dorsale/search.rb +0 -34
  113. data/spec/controllers/dorsale/flyboy/folders_controller_spec.rb +0 -113
  114. data/spec/factories/flyboy_folders.rb +0 -7
  115. data/spec/models/dorsale/flyboy/folder_spec.rb +0 -103
  116. data/spec/routing/dorsale/flyboy/folders_routing_spec.rb +0 -44
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d434a4d088da9d112016b8b105a585e3c6ab6d5d
4
- data.tar.gz: 8e168b8193bba3d7ed57847a461feebd36b3e0d8
3
+ metadata.gz: 56df4e99e7f2c43e981701c129cb9f16cd795730
4
+ data.tar.gz: bf0eccdda5b712abbf01deffc58ae3146daa0499
5
5
  SHA512:
6
- metadata.gz: c7ab336441e22590d30bc06da433455fddfed6579cce0ab693f59bb243e073ebfd1ec29afdb631373abcea83b3cd650edb05c0a4f0dbc8e99742a03702d380d5
7
- data.tar.gz: 8d4c15c6f3adf0c3a0375f451e03643f8a0b415ab33195e0dd862a7da9ae89ed8ba961b9c2bdfcfd7f5fb57fdc9c4241270cd93513aac610ece2d7f8ca14b72d
6
+ metadata.gz: 2471402877909fd94ad6bb27d0eba98cc362e6cb225c40e73e55e58a7a30654f36f67b2294919f02d3897aafab5a99742b541b733176ee6d66c4ce11d00cd0e4
7
+ data.tar.gz: 52908cd5f86c3f8b757a6ecc644970e0e727746165cbe1c213d9c9ec5cf91af7f81eb2e7e7f76ef852ce67ad275b8c48f48a0de89a746735c072a84df20fae19
@@ -4,6 +4,15 @@
4
4
 
5
5
  Nothing.
6
6
 
7
+ ## 3.4.0
8
+
9
+ - Delete Flyboy folders
10
+ - Add `link_to_object` helper
11
+ - Change/fix expense states (new -> draft, submited -> submitted)
12
+ - Persist invoice/quotation PDFs after save
13
+ - Add concerns to ApplicationRecord and stop pollute ActiveRecord::Base
14
+ - Replace abandoned gem handles_sortable_columns
15
+
7
16
  ## 3.3.0
8
17
 
9
18
  - Add download of all invoices in pdf
@@ -21,10 +21,6 @@
21
21
  td.actions
22
22
  width: 5em
23
23
 
24
- td.folder-status
25
- width: 5em
26
- white-space: nowrap
27
-
28
24
  td.task-status,
29
25
  td.task-snooze,
30
26
  width: 3em
@@ -40,7 +36,6 @@
40
36
  overflow: hidden
41
37
 
42
38
  td.task-progress,
43
- td.folder-progress,
44
39
  td.taskable-progress,
45
40
  td.task_comment-progress,
46
41
  width: 150px
@@ -53,10 +48,8 @@
53
48
  margin: 0
54
49
  padding: 0
55
50
 
56
- td.folder-status,
57
51
  td.task-status,
58
52
  td.task-snooze,
59
- td.folder-status a,
60
53
  td.task-status a,
61
54
  td.task-snooze a,
62
55
  td.task-term,
@@ -24,6 +24,7 @@ class Dorsale::Alexandrie::AttachmentsController < ::Dorsale::ApplicationControl
24
24
  authorize @attachment, :create?
25
25
 
26
26
  if @attachment.save
27
+ notify_attachable
27
28
  # flash[:notice] = t("messages.attachments.create_ok")
28
29
  else
29
30
  flash[:alert] = t("messages.attachments.create_error")
@@ -44,6 +45,7 @@ class Dorsale::Alexandrie::AttachmentsController < ::Dorsale::ApplicationControl
44
45
  authorize @attachment, :update?
45
46
 
46
47
  if @attachment.update(attachment_params_for_update)
48
+ notify_attachable
47
49
  # flash[:notice] = t("messages.attachments.update_ok")
48
50
  else
49
51
  flash[:alert] = t("messages.attachments.update_error")
@@ -56,6 +58,7 @@ class Dorsale::Alexandrie::AttachmentsController < ::Dorsale::ApplicationControl
56
58
  authorize @attachment, :delete?
57
59
 
58
60
  if @attachment.destroy
61
+ notify_attachable
59
62
  # flash[:notice] = t("messages.attachments.delete_ok")
60
63
  else
61
64
  flash[:alert] = t("messages.attachments.delete_error")
@@ -132,4 +135,8 @@ class Dorsale::Alexandrie::AttachmentsController < ::Dorsale::ApplicationControl
132
135
  end
133
136
  end
134
137
 
138
+ def notify_attachable
139
+ @attachment.attachable.send(:try, :after_attachments_changes)
140
+ end
141
+
135
142
  end
@@ -1,6 +1,7 @@
1
1
  class Dorsale::ApplicationController < ::ApplicationController
2
2
  include Pundit
3
3
  include Dorsale::BackUrlConcern
4
+ include Dorsale::SortingHelper
4
5
 
5
6
  after_action :verify_authorized
6
7
  after_action :verify_policy_scoped
@@ -39,6 +39,7 @@ class Dorsale::BillingMachine::InvoicesController < ::Dorsale::BillingMachine::A
39
39
  authorize model, :create?
40
40
 
41
41
  if @invoice.save
42
+ Dorsale::BillingMachine::PdfFileGenerator.(@invoice)
42
43
  flash[:notice] = t("messages.invoices.create_ok")
43
44
  redirect_to default_back_url
44
45
  else
@@ -78,6 +79,7 @@ class Dorsale::BillingMachine::InvoicesController < ::Dorsale::BillingMachine::A
78
79
  authorize @invoice, :update?
79
80
 
80
81
  if @invoice.update(invoice_params_for_update)
82
+ Dorsale::BillingMachine::PdfFileGenerator.(@invoice)
81
83
  flash[:notice] = t("messages.invoices.update_ok")
82
84
  redirect_to default_back_url
83
85
  else
@@ -39,6 +39,7 @@ class Dorsale::BillingMachine::QuotationsController < ::Dorsale::BillingMachine:
39
39
  authorize @quotation, :create?
40
40
 
41
41
  if @quotation.save
42
+ Dorsale::BillingMachine::PdfFileGenerator.(@quotation)
42
43
  flash[:notice] = t("messages.quotations.create_ok")
43
44
  redirect_to default_back_url
44
45
  else
@@ -67,6 +68,7 @@ class Dorsale::BillingMachine::QuotationsController < ::Dorsale::BillingMachine:
67
68
  authorize @quotation, :update?
68
69
 
69
70
  if @quotation.update(quotation_params_for_update)
71
+ Dorsale::BillingMachine::PdfFileGenerator.(@quotation)
70
72
  flash[:notice] = t("messages.quotations.update_ok")
71
73
  redirect_to default_back_url
72
74
  else
@@ -1,8 +1,4 @@
1
1
  class Dorsale::CustomerVault::ApplicationController < ::Dorsale::ApplicationController
2
- handles_sortable_columns
3
-
4
- helper ::Dorsale::Flyboy::ApplicationHelper
5
-
6
2
  before_action :set_form_variables, only: [
7
3
  :new,
8
4
  :create,
@@ -1,6 +1,4 @@
1
1
  class Dorsale::CustomerVault::PeopleController < ::Dorsale::CustomerVault::ApplicationController
2
- handles_sortable_columns
3
-
4
2
  before_action :set_objects
5
3
 
6
4
  def index
@@ -74,8 +74,8 @@ class Dorsale::ExpenseGun::ExpensesController < Dorsale::ExpenseGun::Application
74
74
  def submit
75
75
  authorize @expense, :submit?
76
76
 
77
- @expense.go_to_submited!
78
- flash[:success] = t("expense_gun.expense.messages.submited")
77
+ @expense.go_to_submitted!
78
+ flash[:success] = t("expense_gun.expense.messages.submitted")
79
79
  redirect_to dorsale.expense_gun_expenses_path
80
80
  end
81
81
 
@@ -1,5 +1,2 @@
1
1
  class Dorsale::Flyboy::ApplicationController < ::Dorsale::ApplicationController
2
- handles_sortable_columns
3
-
4
- helper ::Dorsale::CustomerVault::ApplicationHelper
5
2
  end
@@ -23,9 +23,9 @@ class Dorsale::Flyboy::TasksController < ::Dorsale::Flyboy::ApplicationControlle
23
23
  %(dorsale_flyboy_tasks.#{column} #{direction})
24
24
  when "taskable"
25
25
  if direction == :asc
26
- proc { |a, b| a.taskable.name.downcase <=> b.taskable.name.downcase }
26
+ proc { |a, b| a.taskable.to_s.downcase <=> b.taskable.to_s.downcase }
27
27
  else
28
- proc { |a, b| b.taskable.name.downcase <=> a.taskable.name.downcase }
28
+ proc { |a, b| b.taskable.to_s.downcase <=> a.taskable.to_s.downcase }
29
29
  end
30
30
  else
31
31
  params["sort"] = "term"
@@ -160,12 +160,6 @@ class Dorsale::Flyboy::TasksController < ::Dorsale::Flyboy::ApplicationControlle
160
160
  end
161
161
  end
162
162
 
163
- def back_url
164
- url = super
165
- url << "#tasks" if url.include?("customer_vault")
166
- url
167
- end
168
-
169
163
  def notify_owner(author, task)
170
164
  return if author == task.owner
171
165
  return if task.owner.nil?
@@ -11,6 +11,7 @@ module Dorsale::AllHelpers
11
11
  include ::Dorsale::RoutesHelper
12
12
  include ::Dorsale::TextHelper
13
13
  include ::Dorsale::BootstrapHelper
14
+ include ::Dorsale::SortingHelper
14
15
 
15
16
  include ::Dorsale::Alexandrie::AttachmentsHelper
16
17
  include ::Dorsale::BillingMachine::ApplicationHelper
@@ -1,6 +1,4 @@
1
1
  module Dorsale::Flyboy::ApplicationHelper
2
- include ::Handles::SortableColumns::InstanceMethods
3
-
4
2
  def tasks_for(taskable)
5
3
  @filters = ::Dorsale::Flyboy::SmallData::FilterForTasks.new(cookies)
6
4
 
@@ -34,18 +32,11 @@ module Dorsale::Flyboy::ApplicationHelper
34
32
  return "onwarning"
35
33
  end
36
34
 
37
- def folder_color(folder)
38
- return "onalert" if ::Dorsale::Flyboy::Task.where(taskable: folder).where('done = ? AND term < ?', false, Time.zone.now.to_date).count > 0
39
- return "onwarning" if ::Dorsale::Flyboy::Task.where(taskable: folder).where('done = ? AND term > ? AND reminder < ?', false, Time.zone.now.to_date, Time.zone.now.to_date).count > 0
40
- return "finished" if folder.closed?
41
- return "ontime"
42
- end
43
-
44
35
  def flyboy_status_for_filters_select
45
36
  {
46
- Dorsale::Flyboy::Folder.t("status.all") => "",
47
- Dorsale::Flyboy::Folder.t("status.open") => "open",
48
- Dorsale::Flyboy::Folder.t("status.closed") => "closed",
37
+ Dorsale::Flyboy::Task.t("status.all") => "",
38
+ Dorsale::Flyboy::Task.t("status.open") => "open",
39
+ Dorsale::Flyboy::Task.t("status.closed") => "closed",
49
40
  }
50
41
  end
51
42
 
@@ -1,4 +1,14 @@
1
1
  module Dorsale::LinkHelper
2
+ def link_to_object(obj, options = {})
3
+ return if obj.nil?
4
+
5
+ if policy(obj).read?
6
+ link_to(obj.to_s, engine_polymorphic_path(obj), options)
7
+ else
8
+ obj.to_s
9
+ end
10
+ end
11
+
2
12
  def icon_link_to(icon, name, options = nil, html_options = nil, &block)
3
13
  name = "#{icon(icon)} #{name}".html_safe
4
14
  link_to(name, options, html_options, &block)
@@ -0,0 +1,48 @@
1
+ module Dorsale::SortingHelper
2
+ def sortable_column(name, column)
3
+ unless column.is_a?(Symbol)
4
+ raise ArgumentError, "invalid column, please use symbol"
5
+ end
6
+
7
+ current_column, current_order = sortable_column_order
8
+
9
+ if current_column == column.to_s
10
+ if current_order == :asc
11
+ name = "#{name} ↓"
12
+ new_sort_param = "-#{column}"
13
+ end
14
+
15
+ if current_order == :desc
16
+ name = "#{name} ↑"
17
+ new_sort_param = column
18
+ end
19
+
20
+ klass = "sort #{current_order}"
21
+ else
22
+ new_sort_param = column
23
+ klass = "sort"
24
+ end
25
+
26
+ link_to(name, params.merge(sort: new_sort_param), class: klass)
27
+ end
28
+
29
+ def sortable_column_order
30
+ sort_param = params[:sort].to_s
31
+
32
+ if sort_param.present?
33
+ if sort_param.start_with?("-")
34
+ column = sort_param[1..-1]
35
+ order = :desc
36
+ else
37
+ column = sort_param
38
+ order = :asc
39
+ end
40
+ end
41
+
42
+ if block_given?
43
+ yield(column, order)
44
+ else
45
+ [column, order]
46
+ end
47
+ end
48
+ end
@@ -1,6 +1,6 @@
1
1
  class Dorsale::BillingMachine::InvoiceMailer < ::Dorsale::ApplicationMailer
2
2
  def send_invoice_to_customer(invoice, subject, body, sender = nil)
3
- attachments["#{invoice.t}_#{invoice.tracking_id}.pdf"] = invoice.to_pdf
3
+ attachments["#{invoice.t}_#{invoice.tracking_id}.pdf"] = invoice.pdf_file.read
4
4
 
5
5
  mail(
6
6
  :to => invoice.customer.email,
@@ -0,0 +1,25 @@
1
+ module Dorsale::ModelI18n
2
+ extend ActiveSupport::Concern
3
+
4
+ def t(*args)
5
+ self.class.t(*args)
6
+ end
7
+
8
+ def ts
9
+ self.class.ts
10
+ end
11
+
12
+ class_methods do
13
+ def t(*args)
14
+ if args.any?
15
+ human_attribute_name(*args)
16
+ else
17
+ model_name.human
18
+ end
19
+ end
20
+
21
+ def ts
22
+ model_name.human(count: 2)
23
+ end
24
+ end # class_methods
25
+ end # Dorsale::ModelI18n
@@ -0,0 +1,9 @@
1
+ module Dorsale::ModelToS
2
+ def to_s
3
+ %w(name title label).map do |m|
4
+ return send(m) if respond_to?(m)
5
+ end
6
+
7
+ super
8
+ end
9
+ end
@@ -1,7 +1,7 @@
1
1
  module Dorsale::PolymorphicId
2
2
  extend ActiveSupport::Concern
3
- included do
4
3
 
4
+ included do
5
5
  def self.polymorphic_id_for(relation_name)
6
6
  module_src = File.read(__FILE__).split("__END__").last
7
7
  module_src = module_src.gsub("relation", relation_name.to_s)
@@ -16,8 +16,6 @@ module Dorsale::PolymorphicId
16
16
  end # included
17
17
  end # module
18
18
 
19
- ActiveRecord::Base.send(:include, Dorsale::PolymorphicId)
20
-
21
19
  # __END__
22
20
 
23
21
  Module.new do
@@ -0,0 +1,30 @@
1
+ module Dorsale::Search
2
+ extend ActiveSupport::Concern
3
+
4
+ class_methods do
5
+ def default_search_fields
6
+ fields = columns.map do |column|
7
+ "#{table_name}.#{column.name}"
8
+ end
9
+ end # def default_search_fields
10
+
11
+ def search(q, *fields)
12
+ words = q.to_s.parameterize.split("-")
13
+ fields = default_search_fields if fields.empty?
14
+
15
+ sql_query = words.map.with_index do |word, index|
16
+ fields.map do |field|
17
+ "(LOWER(CAST(#{field} AS TEXT)) LIKE :w#{index})"
18
+ end.join(" OR ")
19
+ end.map{ |e| "(#{e})" }.join(" AND ")
20
+
21
+ sql_params_a = words.map.with_index do |word, index|
22
+ ["w#{index}".to_sym, "%#{word}%"]
23
+ end
24
+
25
+ sql_params_h = Hash[sql_params_a]
26
+
27
+ self.where(sql_query, sql_params_h)
28
+ end # def search
29
+ end # class_methods
30
+ end # class Dorsale::Search
@@ -11,18 +11,12 @@ class Dorsale::Alexandrie::Attachment < ::Dorsale::ApplicationRecord
11
11
 
12
12
  mount_uploader :file, ::Dorsale::Alexandrie::FileUploader
13
13
 
14
- before_save :assign_default_name
15
-
16
14
  default_scope -> {
17
15
  all
18
16
  .order(created_at: :desc, id: :desc)
19
17
  .preload(:attachment_type)
20
18
  }
21
19
 
22
- def assign_default_name
23
- self.name = file_identifier if name.blank?
24
- end
25
-
26
20
  def download_filename
27
21
  if File.extname(file_identifier) == File.extname(name)
28
22
  name
@@ -31,4 +25,11 @@ class Dorsale::Alexandrie::Attachment < ::Dorsale::ApplicationRecord
31
25
  end
32
26
  end
33
27
 
28
+ private
29
+
30
+ before_save :assign_default_name
31
+
32
+ def assign_default_name
33
+ self.name = file_identifier if name.blank?
34
+ end
34
35
  end
@@ -1,8 +1,14 @@
1
+ require "dorsale/search"
2
+
1
3
  class Dorsale::ApplicationRecord < ActiveRecord::Base
2
4
  self.abstract_class = true
3
5
 
4
6
  include Dorsale::ActiveRecordUUIDConcern
5
7
  include Dorsale::DefaultValuesConcern
8
+ include Dorsale::ModelToS
9
+ include Dorsale::ModelI18n
10
+ include Dorsale::PolymorphicId
11
+
6
12
  nilify_blanks
7
13
 
8
14
  def self.last_created
@@ -11,6 +11,8 @@ class Dorsale::BillingMachine::Invoice < ::Dorsale::ApplicationRecord
11
11
 
12
12
  polymorphic_id_for :customer
13
13
 
14
+ mount_uploader :pdf_file, ::Dorsale::PdfUploader
15
+
14
16
  validates :id_card, presence: true
15
17
  validates :date, presence: true
16
18
 
@@ -138,10 +140,4 @@ class Dorsale::BillingMachine::Invoice < ::Dorsale::ApplicationRecord
138
140
  def balance=(*); super; end
139
141
  private :balance=
140
142
 
141
- def to_pdf
142
- ::Dorsale::BillingMachine.invoice_pdf_model.new(self)
143
- .tap(&:build)
144
- .render
145
- end
146
-
147
143
  end