dorsale 3.9.6 → 3.9.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c35bf78225914a8dfc322164de561790f97b6e49
4
- data.tar.gz: 9fd0de39cdcbb701862e92777891924ad6669123
3
+ metadata.gz: 19154c764ac2dbbf08f847870a9e25551c745ea0
4
+ data.tar.gz: 401461784af4a331967feb30e8769623584ec539
5
5
  SHA512:
6
- metadata.gz: 84dd08892c8727c90daa2b55f452b334a75e78a3e434dc2cc955fb3055efd83485850a4dc0908b463fa51b2ec2c8a277308db8a489c6bc2002c562f82819e1f9
7
- data.tar.gz: ae773eb9c50e3a42460e7c59a0298e6f5db3ab515fc3c7ae1a7eda3e7ff5148f5009631a6e2cb8c2aa564240357cd77759f0337891e2a9b16179124083c23752
6
+ metadata.gz: cd9a9eba500e6e8d9941029c64cffca4b7165bad1f63b922e4a6297243df75e26759a305cd3799d31252cd869b5d430624142fef1461dcc4af7de162c7ce9caa
7
+ data.tar.gz: ece4ad04640bfeddd6b406a00233752b9c58c539952dcb74152346beb41976ea3b2fcd0dbcae21b21984d061063cb4a90724b1bde9c7579998bd30e2f1151103
data/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## Next version
4
4
 
5
+ ## 3.9.7
6
+
7
+ - Attachments : refactor + sorting
8
+
5
9
  ## 3.9.6
6
10
 
7
11
  - Tasks : add :on_warning_or_alert scope/filter
@@ -8,8 +8,6 @@ window.setupUploadInputs = (scope = document) ->
8
8
  submit = form.find("[type=submit]")
9
9
  progress = form.find(".progress")
10
10
 
11
- progress.hide() if not xhr2_available()
12
-
13
11
  label.map ->
14
12
  this.dataset.defaultValue = $(this).html()
15
13
 
@@ -1,59 +1,24 @@
1
- window.xhr2_available = ->
2
- !!window.ProgressEvent && !!window.FormData
3
-
4
1
  window.alexandrie =
5
- enable_xhr_upload: true
6
-
7
- load: ->
2
+ loadList: ->
8
3
  $("#dorsale-attachments").map ->
9
- container = $(this)
10
- url = this.dataset.url
11
-
12
4
  $.ajax
13
- url: url
5
+ url: this.dataset.url
14
6
  success: (data) ->
15
- container.html(data)
16
- setupUploadInputs(container)
17
- alexandrie.setup()
7
+ alexandrie.replaceHTML(data)
18
8
 
19
- reload: ->
20
- alexandrie.load()
9
+ replaceHTML: (html) ->
10
+ $container = $("#dorsale-attachments")
11
+ $container.html(html)
12
+ setupUploadInputs($container)
21
13
 
22
14
  setup: ->
23
- alexandrie.setupForms()
24
- alexandrie.setupFormsProgress()
25
- alexandrie.setupEditButtons()
26
- alexandrie.setupDeleteButtons()
27
-
28
- setupForms: ->
29
- $("#dorsale-attachments form").on("ajax:success", alexandrie.reload)
15
+ $(document).on "ajax:success", "#dorsale-attachments *", (e, data) ->
16
+ alexandrie.replaceHTML(data)
30
17
 
31
- setupEditButtons: ->
32
- $("#dorsale-attachments [href$=edit]").click ->
33
- container = $("#dorsale-attachments")
34
- url = this.href
35
-
36
- $.ajax
37
- url: url
38
- success: (data) ->
39
- container.html(data)
40
- setupUploadInputs(container)
41
- alexandrie.setup()
18
+ $(document).on "submit", "#dorsale-attachments form", ->
19
+ # Ignore progress if no file input
20
+ return unless $(this).find("input[type=file]").length
42
21
 
43
- return false
44
-
45
- setupDeleteButtons: ->
46
- $("#dorsale-attachments [data-method=delete]").map ->
47
- $(this).on("ajax:success", alexandrie.reload)
48
-
49
- setupFormsProgress: ->
50
- return unless xhr2_available()
51
- return unless alexandrie.enable_xhr_upload
52
-
53
- # Ignore progress if no file input
54
- return unless $("#dorsale-attachments form input[type=file]").length
55
-
56
- $("#dorsale-attachments form").submit ->
57
22
  form = $(this)
58
23
  xhr = new XMLHttpRequest()
59
24
  data = new FormData(this)
@@ -73,10 +38,12 @@ window.alexandrie =
73
38
  bar.attr "aria-valuenow": percentComplete
74
39
 
75
40
  xhr.addEventListener "load", (e) ->
76
- alexandrie.reload()
41
+ alexandrie.replaceHTML(e.target.responseText)
77
42
 
78
43
  xhr.open("POST", this.action, true)
79
44
  xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest")
80
45
  xhr.send(data)
81
46
 
82
47
  return false
48
+
49
+ alexandrie.setup()
@@ -1,7 +1,7 @@
1
1
  class Dorsale::Alexandrie::AttachmentsController < ::Dorsale::ApplicationController
2
2
  layout false
3
3
 
4
- before_action :set_objects, only: [
4
+ before_action :set_attachment, only: [
5
5
  :edit,
6
6
  :update,
7
7
  :destroy,
@@ -10,12 +10,11 @@ class Dorsale::Alexandrie::AttachmentsController < ::Dorsale::ApplicationControl
10
10
  before_action :set_attachment_types
11
11
 
12
12
  def index
13
- @attachable = find_attachable
14
- skip_policy_scope
13
+ @attachable = find_attachable_from_params
15
14
 
16
15
  authorize @attachable, :read?
17
16
 
18
- @attachment = scope.new(attachment_params_for_create)
17
+ render_list
19
18
  end
20
19
 
21
20
  def create
@@ -25,20 +24,17 @@ class Dorsale::Alexandrie::AttachmentsController < ::Dorsale::ApplicationControl
25
24
 
26
25
  if @attachment.save
27
26
  notify_attachable
28
- # flash[:notice] = t("messages.attachments.create_ok")
29
27
  else
30
- flash[:alert] = t("messages.attachments.create_error")
28
+ flash.now[:alert] = t("messages.attachments.create_error")
31
29
  end
32
30
 
33
- render_or_redirect
31
+ render_list
34
32
  end
35
33
 
36
34
  def edit
37
35
  authorize @attachment, :update?
38
36
 
39
- @attachable = @attachment.attachable
40
-
41
- render :index
37
+ render_list
42
38
  end
43
39
 
44
40
  def update
@@ -46,12 +42,11 @@ class Dorsale::Alexandrie::AttachmentsController < ::Dorsale::ApplicationControl
46
42
 
47
43
  if @attachment.update(attachment_params_for_update)
48
44
  notify_attachable
49
- # flash[:notice] = t("messages.attachments.update_ok")
50
45
  else
51
- flash[:alert] = t("messages.attachments.update_error")
46
+ flash.now[:alert] = t("messages.attachments.update_error")
52
47
  end
53
48
 
54
- render_or_redirect
49
+ render_list
55
50
  end
56
51
 
57
52
  def destroy
@@ -59,12 +54,11 @@ class Dorsale::Alexandrie::AttachmentsController < ::Dorsale::ApplicationControl
59
54
 
60
55
  if @attachment.destroy
61
56
  notify_attachable
62
- # flash[:notice] = t("messages.attachments.delete_ok")
63
57
  else
64
- flash[:alert] = t("messages.attachments.delete_error")
58
+ flash.now[:alert] = t("messages.attachments.delete_error")
65
59
  end
66
60
 
67
- render_or_redirect
61
+ render_list
68
62
  end
69
63
 
70
64
  private
@@ -73,7 +67,7 @@ class Dorsale::Alexandrie::AttachmentsController < ::Dorsale::ApplicationControl
73
67
  ::Dorsale::Alexandrie::Attachment
74
68
  end
75
69
 
76
- def set_objects
70
+ def set_attachment
77
71
  @attachment = scope.find(params[:id])
78
72
  end
79
73
 
@@ -81,16 +75,8 @@ class Dorsale::Alexandrie::AttachmentsController < ::Dorsale::ApplicationControl
81
75
  @attachment_types = policy_scope(::Dorsale::Alexandrie::AttachmentType).all
82
76
  end
83
77
 
84
- def attachable_type
85
- params[:attachable_type] || @attachment.attachable_type
86
- end
87
-
88
- def attachable_id
89
- params[:attachable_id] || @attachment.attachable_id
90
- end
91
-
92
- def find_attachable
93
- attachable_type.to_s.constantize.find(attachable_id)
78
+ def find_attachable_from_params
79
+ params[:attachable_type].to_s.constantize.find(params[:attachable_id])
94
80
  rescue NameError
95
81
  raise ActiveRecord::RecordNotFound
96
82
  end
@@ -99,6 +85,7 @@ class Dorsale::Alexandrie::AttachmentsController < ::Dorsale::ApplicationControl
99
85
  [
100
86
  :name,
101
87
  :attachment_type_id,
88
+ :file,
102
89
  ]
103
90
  end
104
91
 
@@ -106,14 +93,11 @@ class Dorsale::Alexandrie::AttachmentsController < ::Dorsale::ApplicationControl
106
93
  common_permitted_params + [
107
94
  :attachable_id,
108
95
  :attachable_type,
109
- :file,
110
96
  ]
111
97
  end
112
98
 
113
99
  def attachment_params_for_create
114
- params
115
- .fetch(:attachment, {})
116
- .permit(permitted_params_for_create)
100
+ params.fetch(:attachment, {}).permit(permitted_params_for_create)
117
101
  .merge(sender: current_user)
118
102
  end
119
103
 
@@ -122,17 +106,15 @@ class Dorsale::Alexandrie::AttachmentsController < ::Dorsale::ApplicationControl
122
106
  end
123
107
 
124
108
  def attachment_params_for_update
125
- params
126
- .fetch(:attachment, {})
127
- .permit(permitted_params_for_update)
109
+ params.fetch(:attachment, {}).permit(permitted_params_for_update)
128
110
  end
129
111
 
130
- def render_or_redirect
131
- if request.xhr?
132
- head :ok
133
- else
134
- redirect_to back_url
135
- end
112
+ def render_list
113
+ @new_attachment = scope.new
114
+ @attachable = @attachment.attachable if @attachable.nil?
115
+ @attachments = scope.where(attachable: @attachable).preload(:attachment_type)
116
+ @attachments = Dorsale::Alexandrie::AttachmentsSorter.call(@attachments, params["sort"])
117
+ render :index
136
118
  end
137
119
 
138
120
  def notify_attachable
@@ -11,12 +11,6 @@ class Dorsale::Alexandrie::Attachment < ::Dorsale::ApplicationRecord
11
11
 
12
12
  mount_uploader :file, ::Dorsale::Alexandrie::FileUploader
13
13
 
14
- default_scope -> {
15
- all
16
- .order(created_at: :desc, id: :desc)
17
- .preload(:attachment_type)
18
- }
19
-
20
14
  def download_filename
21
15
  if File.extname(file_identifier) == File.extname(name)
22
16
  name
@@ -0,0 +1,22 @@
1
+ class Dorsale::Alexandrie::AttachmentsSorter < Agilibox::Sorter
2
+ def sort
3
+ case column
4
+ when :created_at, :updated_at
5
+ {column => direction}
6
+ when :name
7
+ %(LOWER(#{model.table_name}.#{column}) #{direction})
8
+ when :attachment_type_name
9
+ @collection = @collection.joins(:attachment_type)
10
+ table = Dorsale::Alexandrie::AttachmentType.table_name
11
+ %(LOWER(#{table}.name) #{direction})
12
+ else
13
+ {created_at: :desc, id: :desc}
14
+ end
15
+ end
16
+
17
+ private
18
+
19
+ def model
20
+ Dorsale::Alexandrie::Attachment
21
+ end
22
+ end
@@ -8,7 +8,7 @@ tr.attachment
8
8
 
9
9
  td.attachment-actions
10
10
  - if policy(attachment).update?
11
- = update_button dorsale.edit_alexandrie_attachment_path(attachment)
11
+ = update_button dorsale.edit_alexandrie_attachment_path(attachment), remote: true
12
12
 
13
13
  - if policy(attachment).delete?
14
14
  = delete_button dorsale.alexandrie_attachment_path(attachment), remote: true
@@ -1,5 +1,4 @@
1
1
  div#dorsale-attachments data-url=dorsale.alexandrie_attachments_path(attachable_type: attachable.class, attachable_id: attachable.id)
2
2
 
3
- coffee:
4
- $ ->
5
- alexandrie.load()
3
+ javascript:
4
+ alexandrie.loadList()
@@ -3,7 +3,8 @@
3
3
  .panel.panel-default
4
4
  .panel-heading: .panel-title = ::Dorsale::Alexandrie::Attachment.ts
5
5
 
6
- = form_for(@attachment, as: :attachment, remote: true) do |f|
6
+ - url = params[:action] == "edit" ? @attachment : @new_attachment
7
+ = form_for(url, as: :attachment, remote: true) do |f|
7
8
  = hidden_field_tag :authenticity_token, form_authenticity_token
8
9
 
9
10
  table
@@ -12,13 +13,13 @@
12
13
  tbody
13
14
  - if policy(::Dorsale::Alexandrie::Attachment).create?
14
15
  / Create only on index
15
- - if params[:action] == "index"
16
- = render "dorsale/alexandrie/attachments/new", attachable: @attachable
17
- - else
16
+ - if params[:action] == "edit"
18
17
  = render "dorsale/alexandrie/attachments/new_disabled"
18
+ - else
19
+ = render "dorsale/alexandrie/attachments/new", attachable: @attachable
19
20
 
20
- - ::Dorsale::Alexandrie::Attachment.where(attachable: @attachable).each do |attachment|
21
- - if request.path == url_for(action: :edit, id: attachment)
21
+ - @attachments.each do |attachment|
22
+ - if params[:action] == "edit" && attachment == @attachment
22
23
  = render "dorsale/alexandrie/attachments/edit", attachment: attachment
23
24
  - else
24
25
  = render "dorsale/alexandrie/attachments/attachment", attachment: attachment
@@ -1,8 +1,11 @@
1
1
  = filters_form do |f|
2
- = f.input :fb_state, collection: flyboy_status_for_filters_select, include_blank: Dorsale::Flyboy::Task.t("state.all")
2
+ = f.input :fb_state,
3
+ :collection => flyboy_status_for_filters_select,
4
+ :include_blank => Dorsale::Flyboy::Task.t("state.all")
3
5
 
4
- - if @filters.class::STRATEGIES.include?("fb_owner")
5
- = f.input :fb_owner, collection: flyboy_tasks_owners_for_filters_select, include_blank: t("filters.all_owners")
6
+ = f.input :fb_owner,
7
+ :collection => flyboy_tasks_owners_for_filters_select,
8
+ :include_blank => t("filters.all_owners")
6
9
 
7
10
  = f.input :fb_tags,
8
11
  :collection => flyboy_tasks_tags_for_filters_select,
@@ -1,3 +1,3 @@
1
1
  module Dorsale
2
- VERSION = "3.9.6"
2
+ VERSION = "3.9.7"
3
3
  end
@@ -22,30 +22,124 @@ describe Dorsale::Alexandrie::AttachmentsController, type: :controller do
22
22
 
23
23
  before(:each) { sign_in(user) }
24
24
 
25
+ let(:attachment) { create(:alexandrie_attachment) }
26
+
27
+ describe "sorting" do
28
+ let!(:attachable) { create(:billing_machine_quotation) }
29
+
30
+ let!(:attachment1) {
31
+ create(:alexandrie_attachment,
32
+ :attachable => attachable,
33
+ :name => "AAA",
34
+ :created_at => "2010-01-01",
35
+ :updated_at => "2010-01-01",
36
+ :attachment_type => create(:alexandrie_attachment_type, name: "AAA"),
37
+ )
38
+ }
39
+
40
+ let!(:attachment2) {
41
+ create(:alexandrie_attachment,
42
+ :attachable => attachable,
43
+ :name => "ZZZ",
44
+ :created_at => "2020-01-01",
45
+ :updated_at => "2020-01-01",
46
+ :attachment_type => create(:alexandrie_attachment_type, name: "ZZZ"),
47
+ )
48
+ }
49
+
50
+ before do
51
+ allow_any_instance_of(described_class).to \
52
+ receive(:find_attachable_from_params).and_return(attachable)
53
+ end
54
+
55
+ it "should sort by name" do
56
+ get :index, params: {sort: "name"}
57
+ expect(assigns :attachments).to eq [attachment1, attachment2]
58
+ end
59
+
60
+ it "should sort by -name" do
61
+ get :index, params: {sort: "-name"}
62
+ expect(assigns :attachments).to eq [attachment2, attachment1]
63
+ end
64
+
65
+ it "should sort by created_at" do
66
+ get :index, params: {sort: "created_at"}
67
+ expect(assigns :attachments).to eq [attachment1, attachment2]
68
+ end
69
+
70
+ it "should sort by -created_at" do
71
+ get :index, params: {sort: "-created_at"}
72
+ expect(assigns :attachments).to eq [attachment2, attachment1]
73
+ end
74
+
75
+ it "should sort by updated_at" do
76
+ get :index, params: {sort: "updated_at"}
77
+ expect(assigns :attachments).to eq [attachment1, attachment2]
78
+ end
79
+
80
+ it "should sort by -updated_at" do
81
+ get :index, params: {sort: "-updated_at"}
82
+ expect(assigns :attachments).to eq [attachment2, attachment1]
83
+ end
84
+
85
+ it "should sort by attachment_type_name" do
86
+ get :index, params: {sort: "attachment_type_name"}
87
+ expect(assigns :attachments).to eq [attachment1, attachment2]
88
+ end
89
+
90
+ it "should sort by -attachment_type_name" do
91
+ get :index, params: {sort: "-attachment_type_name"}
92
+ expect(assigns :attachments).to eq [attachment2, attachment1]
93
+ end
94
+ end # describe "sorting"
95
+
25
96
  describe "create" do
26
97
  it "should create attachment" do
27
- post :create, params: {attachment: valid_attributes, back_url: "/"}
98
+ post :create, params: {attachment: valid_attributes}
28
99
  expect(assigns(:attachment)).to be_persisted
29
100
  end
30
101
 
31
- it "should redirect to back_url" do
32
- post :create, params: {attachment: valid_attributes, back_url: "/"}
33
- expect(response).to redirect_to("/")
102
+ it "should render list" do
103
+ post :create, params: {attachment: valid_attributes}
104
+ expect(response).to be_ok
105
+ expect(response).to render_template :index
106
+ end
107
+ end
108
+
109
+ describe "edit" do
110
+ it "should render list" do
111
+ get :edit, params: {id: attachment}
112
+ expect(response).to be_ok
113
+ expect(response).to render_template :index
114
+ end
115
+ end
116
+
117
+ describe "update" do
118
+ it "should update attachment" do
119
+ patch :update, params: {id: attachment, attachment: {name: "new_name"}}
120
+ expect(attachment.reload.name).to eq "new_name"
121
+ end
122
+
123
+ it "should render list" do
124
+ patch :update, params: {id: attachment}
125
+ expect(response).to be_ok
126
+ expect(response).to render_template :index
34
127
  end
35
128
  end
36
129
 
37
130
  describe "destroy" do
131
+ let!(:attachment) { create(:alexandrie_attachment) }
132
+
38
133
  it "should delete attachment" do
39
- attachment = create(:alexandrie_attachment)
40
134
  expect {
41
- delete :destroy, params: {id: attachment, back_url: "/"}
135
+ delete :destroy, params: {id: attachment}
42
136
  }.to change(::Dorsale::Alexandrie::Attachment, :count).by(-1)
43
137
  end
44
138
 
45
- it "should redirect to back_url" do
46
- attachment = create(:alexandrie_attachment)
47
- delete :destroy, params: {id: attachment, back_url: "/"}
48
- expect(response).to redirect_to("/")
139
+ it "should render list" do
140
+ delete :destroy, params: {id: attachment}
141
+ expect(response).to be_ok
142
+ expect(response).to render_template :index
49
143
  end
50
144
  end
51
145
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dorsale
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.9.6
4
+ version: 3.9.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - agilidée
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-10 00:00:00.000000000 Z
11
+ date: 2018-03-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -643,6 +643,7 @@ files:
643
643
  - app/services/dorsale/flyboy/task/snoozer.rb
644
644
  - app/services/dorsale/service.rb
645
645
  - app/services/dorsale/tag_list_for_model.rb
646
+ - app/sorters/dorsale/alexandrie/attachments_sorter.rb
646
647
  - app/sorters/dorsale/flyboy/task_comments_sorter.rb
647
648
  - app/sorters/dorsale/flyboy/tasks_sorter.rb
648
649
  - app/uploaders/dorsale/alexandrie/file_uploader.rb
@@ -774,7 +775,6 @@ files:
774
775
  - app/views/dorsale/expense_gun/expenses/index.html.slim
775
776
  - app/views/dorsale/expense_gun/expenses/new.html.slim
776
777
  - app/views/dorsale/expense_gun/expenses/show.html.slim
777
- - app/views/dorsale/flyboy/_filters.html.slim
778
778
  - app/views/dorsale/flyboy/task_comments/_form.html.slim
779
779
  - app/views/dorsale/flyboy/task_comments/_list.html.slim
780
780
  - app/views/dorsale/flyboy/task_comments/_task_comment.html.slim
@@ -1,13 +0,0 @@
1
- = filters_form do |f|
2
- = f.input :fb_state,
3
- :collection => flyboy_status_for_filters_select,
4
- :include_blank => Dorsale::Flyboy::Task.t("state.all")
5
-
6
- = f.input :fb_owner,
7
- :collection => flyboy_tasks_owners_for_filters_select,
8
- :include_blank => t("filters.all_owners")
9
-
10
- = f.input :fb_tags,
11
- :collection => flyboy_tasks_tags_for_filters_select,
12
- :input_html => {multiple: true},
13
- :placeholder => ::Dorsale::Flyboy::Task.t(:all_tags)