dynamic_scaffold 1.9.0 → 1.10.0

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
  SHA256:
3
- metadata.gz: 7d0ca43e5c5f7d3eac65d3ecb58f9c8db1c5fc56c16afa34ecd09dd5d04ee4e4
4
- data.tar.gz: ef7f572241d232e3579d991d501e49da461baac0297598014b1f145cca959c83
3
+ metadata.gz: d2878d75af1c0e57b392261a63012a7e8adaf8b527cc6da8bb7c8ea5f84011a5
4
+ data.tar.gz: 5a0037e29736c6863901d7f7fdbec3aaeefd0a1ebb746d21f49c3356838cfcf5
5
5
  SHA512:
6
- metadata.gz: f5df70910ffc6358f63638bd48748910176a889a89ca0ec9667c01aa37a4e3bd97a2981e3915b4efc2a6542a134bb12b7892271a7e438ebd3eb8078bb9d8cf59
7
- data.tar.gz: bcf91e27f537462fe3f9417f0230c21d95c76fb1e13db923121951f6001437d3b328aaf303c2b60c6d1ca0b86c8f96e418851ad7994f5addba7fbdfc3b301169
6
+ metadata.gz: 9ef5af49b21cd93f46e1e13138eff64823fe3e5379882bdf0910e8082ecba8d7f9b65dd8c8b6cde8c22fb0fbb7fe5f92ffc1c31e61bfd7fd18a22fbdd8756022
7
+ data.tar.gz: bb3b7662d02ebda9658ada08ce216e63ac24f4c63d2434757cc924c6e56ae8ab4b3156809b062824b7251d14037791fa00189eeace66498f53117b7fb8d8b44c
data/README.md CHANGED
@@ -157,6 +157,34 @@ You can customize the list through the `DynamicScaffold::Config#list` property.
157
157
  class ShopController < ApplicationController
158
158
  include DynamicScaffold::Controller
159
159
  dynamic_scaffold Shop do |config|
160
+ # Add button and new action to disabled, You can still post to create action.
161
+ config.list.add_button = false
162
+ # or
163
+ config.list.add_button do
164
+ # This block is called in view scope
165
+ false if params[:foo] == 1
166
+ end
167
+
168
+ # Edit button and edit action to disabled, You can still post to update action.
169
+ config.list.edit_buttons = false
170
+ # or
171
+ config.list.edit_buttons do |record|
172
+ # This block is called in view scope
173
+ # You can disable only specific record's button.
174
+ false if record.id != 1
175
+ end
176
+
177
+ # Destroy button to disabled, You can still post to destroy action.
178
+ config.list.destroy_buttons = false
179
+ # or
180
+ config.list.destroy_buttons do |record|
181
+ # This block is called in view scope
182
+ # You can disable only specific record's button.
183
+ false if record.id != 1
184
+ end
185
+
186
+
187
+
160
188
  # If you want filtering that can not be handled by `config.scope`, you can use the filter method.
161
189
  # Please note that returning nil will be ignored.
162
190
  config.list.filter do |query|
@@ -5,16 +5,18 @@
5
5
  <%end%>
6
6
  <input type="hidden" class="authenticity_param_name" value="<%= request_forgery_protection_token %>">
7
7
  <%= form_with method: :patch, url: dynamic_scaffold_path(:sort, request_queries(dynamic_scaffold.list.page_param_name)), local: true do%>
8
- <div class="ds-row">
9
- <%= link_to dynamic_scaffold_path(:new, request_queries), class: class_names('btn btn-outline-primary btn-primary btn-sm spec-ds-add', 'disabled': dynamic_scaffold.max_count?(@count)) do%>
10
- <%= dynamic_scaffold_icon(:add) %> <%= t('dynamic_scaffold.button.add') %>
11
- <%- unless dynamic_scaffold.max_count.nil? -%>
12
- &nbsp;<span class="badge badge-light">
13
- <%= @count %>&nbsp;/&nbsp;<%= dynamic_scaffold.max_count%>
14
- </span>
15
- <% end %>
16
- <%end%>
17
- </div>
8
+ <%- if dynamic_scaffold.list.add_button -%>
9
+ <div class="ds-row">
10
+ <%= link_to dynamic_scaffold_path(:new, request_queries), class: class_names('btn btn-outline-primary btn-primary btn-sm spec-ds-add', 'disabled': dynamic_scaffold.max_count?(@count)) do%>
11
+ <%= dynamic_scaffold_icon(:add) %> <%= t('dynamic_scaffold.button.add') %>
12
+ <%- unless dynamic_scaffold.max_count.nil? -%>
13
+ &nbsp;<span class="badge badge-light">
14
+ <%= @count %>&nbsp;/&nbsp;<%= dynamic_scaffold.max_count%>
15
+ </span>
16
+ <% end %>
17
+ <%end%>
18
+ </div>
19
+ <%- end -%>
18
20
  <%= render 'dynamic_scaffold/bootstrap/pagination' %>
19
21
  <div class="ds-row">
20
22
  <%= render 'dynamic_scaffold/bootstrap/save_order'%>
@@ -47,11 +49,13 @@
47
49
  </div>
48
50
  <div class="ds-list-footer clearfix">
49
51
  <div class="float-right pull-right">
50
- <div class="btn-group">
51
- <%= link_to dynamic_scaffold_path(:edit, request_queries.merge(id: record[record.class.primary_key])), class: 'btn btn-primary btn-outline-primary btn-sm spec-ds-edit' do %>
52
- <%= dynamic_scaffold_icon(:edit) %> <%= t('dynamic_scaffold.button.edit') %>
53
- <%end%>
54
- </div>
52
+ <%- if dynamic_scaffold.list.edit_buttons(record) -%>
53
+ <div class="btn-group">
54
+ <%= link_to dynamic_scaffold_path(:edit, request_queries.merge(id: record[record.class.primary_key])), class: 'btn btn-primary btn-outline-primary btn-sm spec-ds-edit' do %>
55
+ <%= dynamic_scaffold_icon(:edit) %> <%= t('dynamic_scaffold.button.edit') %>
56
+ <%end%>
57
+ </div>
58
+ <%- end -%>
55
59
  <% if dynamic_scaffold.list.sorter %>
56
60
  <%[*dynamic_scaffold.model.primary_key].each do |pkey|%>
57
61
  <input type="hidden" name="pkeys[][<%=pkey%>]" value="<%= record[pkey] %>">
@@ -71,15 +75,17 @@
71
75
  </button>
72
76
  </div>
73
77
  <% end %>
74
- <div class="btn-group">
75
- <button
76
- data-action="<%= dynamic_scaffold_path(:update, request_queries(dynamic_scaffold.list.page_param_name).merge(id: record[record.class.primary_key])) %>"
77
- data-confirm-message="<%= t('dynamic_scaffold.message.destroy_confirm') %>"
78
- class="btn btn-danger btn-sm js-ds-destory"
79
- >
80
- <%= dynamic_scaffold_icon(:delete) %>
81
- </button>
82
- </div>
78
+ <%- if dynamic_scaffold.list.destroy_buttons(record) -%>
79
+ <div class="btn-group">
80
+ <button
81
+ data-action="<%= dynamic_scaffold_path(:update, request_queries(dynamic_scaffold.list.page_param_name).merge(id: record[record.class.primary_key])) %>"
82
+ data-confirm-message="<%= t('dynamic_scaffold.message.destroy_confirm') %>"
83
+ class="btn btn-danger btn-sm js-ds-destory spec-ds-destroy"
84
+ >
85
+ <%= dynamic_scaffold_icon(:delete) %>
86
+ </button>
87
+ </div>
88
+ <%- end -%>
83
89
  </div>
84
90
  </div>
85
91
  </li>
@@ -44,6 +44,8 @@ module DynamicScaffold
44
44
  end
45
45
 
46
46
  def new # rubocop:disable Metrics/AbcSize
47
+ raise ActionController::RoutingError, '`Add Button` is disabled.' unless dynamic_scaffold.list.add_button
48
+
47
49
  unless dynamic_scaffold.max_count.nil?
48
50
  count = dynamic_scaffold.list.build_sql(scope_params).count
49
51
  raise Error::InvalidOperation, 'You can not add any more.' if dynamic_scaffold.max_count?(count)
@@ -60,6 +62,8 @@ module DynamicScaffold
60
62
 
61
63
  def edit
62
64
  @record = find_record(edit_params)
65
+
66
+ raise ActionController::RoutingError, '`Edit Button` is disabled.' unless dynamic_scaffold.list.edit_buttons(@record)
63
67
  end
64
68
 
65
69
  def create
@@ -1,5 +1,7 @@
1
1
  module DynamicScaffold
2
2
  class ListBuilder
3
+ attr_writer :add_button, :edit_buttons, :destroy_buttons
4
+
3
5
  def initialize(config)
4
6
  @config = config
5
7
  @items = []
@@ -8,6 +10,9 @@ module DynamicScaffold
8
10
  @title = nil
9
11
  @filter = nil
10
12
  @row_class_block = nil
13
+ @add_button = true
14
+ @edit_buttons = true
15
+ @destroy_buttons = true
11
16
  end
12
17
 
13
18
  def pagination(options = nil)
@@ -97,5 +102,35 @@ module DynamicScaffold
97
102
  @config.controller.view_context.instance_exec(record, &@row_class_block)
98
103
  end
99
104
  end
105
+
106
+ def add_button(&block)
107
+ if block_given?
108
+ @add_button_block = block
109
+ elsif @add_button_block
110
+ @config.controller.view_context.instance_exec(&@add_button_block)
111
+ else
112
+ @add_button
113
+ end
114
+ end
115
+
116
+ def edit_buttons(record = nil, &block)
117
+ if block_given?
118
+ @edit_buttons_block = block
119
+ elsif record.present? && @edit_buttons_block
120
+ @config.controller.view_context.instance_exec(record, &@edit_buttons_block)
121
+ else
122
+ @edit_buttons
123
+ end
124
+ end
125
+
126
+ def destroy_buttons(record = nil, &block)
127
+ if block_given?
128
+ @destroy_buttons_block = block
129
+ elsif record.present? && @destroy_buttons_block
130
+ @config.controller.view_context.instance_exec(record, &@destroy_buttons_block)
131
+ else
132
+ @destroy_buttons
133
+ end
134
+ end
100
135
  end
101
136
  end
@@ -1,3 +1,3 @@
1
1
  module DynamicScaffold
2
- VERSION = '1.9.0'.freeze
2
+ VERSION = '1.10.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dynamic_scaffold
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.0
4
+ version: 1.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masamoto Miyata