admin_it 1.0.6 → 1.0.7

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d3a63565c2793d51ed2992d7d4e01deeecc68543
4
- data.tar.gz: 2fe03cded06fe4a4fedc76b2244f727a9dfaa876
3
+ metadata.gz: c69b40dfe779b858729883eea07b1077f74216b4
4
+ data.tar.gz: 7ba60b0a798165f512348b509411fffad8f1d17f
5
5
  SHA512:
6
- metadata.gz: 1cc3714caf30a63432ca69c6bed8ab1e6b01947918b6f7024daeb9a8951fbd026c1ec7ede09037b61386f0622e2971f0d1b2ae25a9c5532125bebb5169bc647b
7
- data.tar.gz: ed25582af138eca0e80f23b1e2205880b4a74bc6ad830c74adf027ebfcf6eed05407e0180b14e2f15b074df284ba1362bf16b75f9c5f79d3f33ce8516431f4b9
6
+ metadata.gz: 7a55e137e2e089570a4a00faeeee9eeb1cc38657b5055b3153d304e785a1b6109cf1a1281b9e525ab9185d4c04c3906105711678f573bee09d5fe43d2b1a7452
7
+ data.tar.gz: 7bbfd6ff962a80ac79adeb880730693c072d5b003828f5d6c27d9b2dbd9da95e6154752d63689557de88f908760f2834032052c1a1e0cd587aa07d15597b33d6
data/README.md CHANGED
@@ -38,6 +38,12 @@ bundle install
38
38
 
39
39
  # Changes
40
40
 
41
+ `1.0.7`
42
+
43
+ * destoy entity fixed
44
+ * delete confirmation added
45
+ * simple record editing and creating fixed
46
+
41
47
  `1.0.6`
42
48
 
43
49
  * fixed: [#1](/../../issues/1)
data/README_RU.md CHANGED
@@ -37,6 +37,24 @@ bundle install
37
37
 
38
38
  # Изменения
39
39
 
40
+ `1.0.7`
41
+
42
+ * исправлено удаление записей
43
+ * добавлено подтверждение удаления
44
+ * налажено редактирование и создание простых записей
45
+
46
+ `1.0.6`
47
+
48
+ * исправлено: [#1](/../../issues/1)
49
+
50
+ `1.0.5`
51
+
52
+ * исправлено: font-awesome asset path
53
+
54
+ `1.0.4`
55
+
56
+ * исправлено: font-awesome
57
+
40
58
  `1.0.3`
41
59
 
42
60
  * исправлено: assets
@@ -70,20 +70,12 @@ var initLinks = function() {
70
70
  });
71
71
  }
72
72
 
73
- var initFilters = function() {
74
- $('[data-filter-values]').each(function(idx, container) {
75
- $.each($(container).data().filterValues, function(i, v) {
76
- var html = "<a class='label label-success' href='#'>" + v.value + ' ' + "<span class='badge'>" + v.count + "</span></a>";
77
- $(container).append(html);
78
- });
79
- });
80
- }
81
-
82
73
  $(document).on('ready page:load', function() {
83
74
  initPartials();
84
75
  initTiles();
85
76
  initTabs();
86
77
  initPopups();
87
78
  initLinks();
88
- // initFilters();
79
+ // allow dialog content reloading
80
+ $('.modal').on('hidden.bs.modal', function() { $(this).removeData(); })
89
81
  });
@@ -0,0 +1,38 @@
1
+ - for_context ||= context
2
+
3
+ - content_for :title do
4
+ - if for_context.confirm?
5
+ - if for_context.confirm == :destroy
6
+ span class="text-danger"
7
+ i class="fa fa-exclamation-triangle"
8
+ = ' ' + t('admin_it.destroying')
9
+ - else
10
+ = t('admin_it.details')
11
+
12
+ - if for_context.layout.empty?
13
+ h4 = yield :title
14
+
15
+ - if for_context.confirm?
16
+ - if for_context.confirm == :destroy
17
+ p = t('admin_it.confirm.destroy.header')
18
+
19
+ dl class="dl-horizontal"
20
+ - for_context.fields.each do |f|
21
+ - next if f.type == :relation
22
+ dt = f.display_name
23
+ = field f, tag: 'dl'
24
+ div class="clearfix"
25
+
26
+ - if for_context.confirm?
27
+ - if for_context.confirm == :destroy
28
+ p = t('admin_it.confirm.destroy.text')
29
+
30
+ - content_for :buttons do
31
+ - if for_context.confirm?
32
+ - if for_context.confirm == :destroy
33
+ = link_to( \
34
+ '<i class="fa fa-trash-o"></i> '.html_safe + t('admin_it.action.destroy'),
35
+ for_context.path, \
36
+ method: :delete, \
37
+ class: 'btn btn-danger' \
38
+ )
@@ -36,3 +36,7 @@
36
36
 
37
37
  = render partial: File.join(%w(admin_it shared pagination)), \
38
38
  locals: { for_context: for_context }
39
+
40
+ div class="modal fade" id="confirm_modal"
41
+ div class="modal-dialog"
42
+ div class="modal-content"
@@ -44,7 +44,7 @@ form(
44
44
  - content_for :buttons do
45
45
  button class="btn btn-primary" = t('admin_it.action.save')
46
46
 
47
- - if context.layout == ''
47
+ - if for_context.layout.empty?
48
48
  div class="form-group"
49
49
  div class="col-sm-10 col-sm-offset-2"
50
50
  = yield :buttons
@@ -1,6 +1,2 @@
1
1
  - context.begin_render(self)
2
- dl class="dl-horizontal"
3
- - context.fields.each do |f|
4
- - next if f.type == :relation
5
- dt = f.display_name
6
- = field f.read(context.entity), f, tag: 'dl'
2
+ = render File.join %w(admin_it context show)
@@ -1,5 +1,5 @@
1
1
  div class="modal-header"
2
- h4.modal-title title
2
+ h4.modal-title = yield :title
3
3
  div class="modal-body"
4
4
  = yield
5
5
  div class="modal-footer"
@@ -23,6 +23,7 @@ module AdminIt
23
23
  value.nil? ? default_icon : value.to_s
24
24
  end
25
25
  dsl_use_hash :fields
26
+ dsl_boolean :confirm_destroy
26
27
  end
27
28
 
28
29
  inherited_class_reader :resource, :entity_class
@@ -35,6 +36,7 @@ module AdminIt
35
36
  @resource = _resource
36
37
  @context_name = context_name
37
38
  @entity_class = @resource.entity_class
39
+ @confirm_destroy = @resource.confirm_destroy?
38
40
 
39
41
  import_data_module(base)
40
42
 
@@ -91,7 +93,7 @@ module AdminIt
91
93
  end
92
94
 
93
95
  class_attr_reader :collection?, :single?, :entity_class, :resource, :icon,
94
- :entity_path?
96
+ :entity_path?, :confirm_destroy?
95
97
  attr_reader :top_menu, :toolbar, :parent, :template, :controller
96
98
 
97
99
  CONTEXT_REGEXP = /\A
@@ -2,6 +2,8 @@ module AdminIt
2
2
  class ShowContext < SingleContext
3
3
  include Identifiable
4
4
 
5
+ CONFIRMS = %i(destroy update)
6
+
5
7
  class << self
6
8
  include Renderable
7
9
 
@@ -24,6 +26,22 @@ module AdminIt
24
26
  end
25
27
  end
26
28
 
29
+ attr_reader :confirm
30
+
31
+ after_load do |store: {}, params: {}|
32
+ self.confirm = params[:confirm]
33
+ end
34
+
35
+ def confirm=(value)
36
+ value = value.downcase.to_sym if value.is_a?(String)
37
+ return unless value.is_a?(Symbol) && CONFIRMS.include?(value)
38
+ @confirm = value
39
+ end
40
+
41
+ def confirm?
42
+ !@confirm.nil?
43
+ end
44
+
27
45
  def destroy_entity
28
46
  if entity_destroyer.nil?
29
47
  if controller.respond_to?("#{resource.name}_destroy")
@@ -31,7 +49,7 @@ module AdminIt
31
49
  elsif controller.respond_to?(:destroy_entity)
32
50
  controller.destroy_entity(entity_class)
33
51
  else
34
- destroy
52
+ do_destroy_entity
35
53
  end
36
54
  else
37
55
  entity_destroyer.call(controller)
@@ -40,6 +58,6 @@ module AdminIt
40
58
 
41
59
  protected
42
60
 
43
- def destroy; end
61
+ def do_destroy_entity; end
44
62
  end
45
63
  end
@@ -147,7 +147,7 @@ module AdminIt
147
147
  elsif controller.respond_to?(:save)
148
148
  controller.save(entity_class, name)
149
149
  else
150
- save_entity
150
+ do_save_entity
151
151
  end
152
152
  else
153
153
  entity_saver.call(controller, name)
@@ -158,7 +158,7 @@ module AdminIt
158
158
 
159
159
  protected
160
160
 
161
- def save_entity; end
161
+ def do_save_entity; end
162
162
  end
163
163
 
164
164
  class EditContext < SavableSingleContext
@@ -105,7 +105,7 @@ module AdminIt
105
105
  module SavableSingleContext
106
106
  protected
107
107
 
108
- def save_entity
108
+ def do_save_entity
109
109
  if AdminIt::Env.pundit?
110
110
  controller.authorize(entity, "#{self.class.save_action}?")
111
111
  end
@@ -165,7 +165,7 @@ module AdminIt
165
165
 
166
166
  protected
167
167
 
168
- def destroy
168
+ def do_destroy_entity
169
169
  if AdminIt::Env.pundit?
170
170
  controller.authorize(entity, :destroy?)
171
171
  end
@@ -214,7 +214,11 @@ module AdminIt
214
214
  def read_value(entity)
215
215
  value = entity.send(name)
216
216
  if type == :relation
217
- assoc.collection? ? value.map(&:id).to_json : value.id
217
+ if assoc.collection?
218
+ value.nil? || value.empty? ? [] : value.map(&:id).to_json
219
+ else
220
+ value.nil? ? nil : value.id
221
+ end
218
222
  else
219
223
  value
220
224
  end
@@ -20,25 +20,47 @@ module AdminIt
20
20
  default_tag 'td'
21
21
 
22
22
  before_capture do
23
- single = parent.parent.resource.singles.select { |c| !(c <= NewContext) }
24
- buttons = single.map do |context|
25
- cl = context <= ShowContext ? 'info' : 'default'
26
- href = context.path(parent.parent.context.entity)
23
+ context = parent.parent.context
24
+ entity = context.entity
25
+ resource = parent.parent.resource
26
+ single = resource.singles.select { |c| !(c <= NewContext) }
27
+ buttons = single.map do |_context|
28
+ cl = _context <= ShowContext ? 'info' : 'default'
29
+ href = _context.path(entity)
27
30
  "<a class=\"btn btn-xs btn-#{cl}\" href=\"#{href}\">" \
28
- "<i class=\"fa fa-#{context.icon}\"></i></a>"
31
+ "<i class=\"fa fa-#{_context.icon}\"></i></a>"
32
+ end
33
+ if resource.destroyable?
34
+ if context.confirm_destroy?
35
+ confirm = single.find { |c| c.context_name == :confirm } ||
36
+ single.first { |c| c <= ShowContext }
37
+ buttons << if confirm.nil?
38
+ @template.link_to(
39
+ html_safe('<i class="fa fa-trash-o"></i>'),
40
+ show.path(entity),
41
+ method: :delete,
42
+ confirm: I18n.t('admin_it.confirm.destroy.text'),
43
+ class: 'btn btn-xs btn-danger'
44
+ )
45
+ else
46
+ '<a class="btn btn-xs btn-danger" ' +
47
+ %Q{data-toggle="modal" data-target="#confirm_modal" } +
48
+ %Q{href="#{confirm.path(entity)}} +
49
+ '?layout=dialog&confirm=destroy">' +
50
+ '<i class="fa fa-trash-o"></i></a>'
51
+ end
52
+ else
53
+ buttons << @template.link_to(
54
+ html_safe('<i class="fa fa-trash-o"></i>'),
55
+ show.path(entity),
56
+ method: :delete,
57
+ class: 'btn btn-xs btn-danger'
58
+ )
29
59
  end
30
- show = single.first { |c| c <= ShowContext }
31
- unless show.nil?
32
- buttons << @template.link_to(
33
- html_safe('<i class="fa fa-trash-o"></i>'),
34
- show.path(parent.parent.context.entity),
35
- method: :delete,
36
- class: 'btn btn-xs btn-danger'
37
- )
38
60
  end
39
61
 
40
62
  html = buttons.join
41
- html = "<div class=\"btn-group\">#{html}</dic>" if buttons.size > 1
63
+ html = "<div class=\"btn-group\">#{html}</div>" if buttons.size > 1
42
64
 
43
65
  self[:content] = html_safe(html)
44
66
  end
@@ -11,4 +11,11 @@ en:
11
11
  create: 'Create'
12
12
  save: 'Save'
13
13
  close: 'Close'
14
- filters: 'FIlters'
14
+ destroy: 'Delete'
15
+ filters: 'Filters'
16
+ details: 'Details'
17
+ destroying: 'Deletion'
18
+ confirm:
19
+ destroy:
20
+ header: 'You are going to delete following record:'
21
+ text: 'Please, confirm deletion'
@@ -11,4 +11,11 @@ ru:
11
11
  create: 'Создать'
12
12
  save: 'Сохранить'
13
13
  close: 'Закрыть'
14
+ destroy: 'Удалить'
14
15
  filters: 'Фильтры'
16
+ details: 'Подробная информация'
17
+ destroying: 'Удаление'
18
+ confirm:
19
+ destroy:
20
+ header: 'Вы собираетесь удалить следующую запись:'
21
+ text: 'Подтвердите удаление'
@@ -55,6 +55,7 @@ module AdminIt
55
55
 
56
56
  dsl_accessor :icon
57
57
  dsl_use_hash :fields
58
+ dsl_boolean :confirm_destroy
58
59
 
59
60
  define_callbacks :initialize
60
61
 
@@ -202,7 +203,7 @@ module AdminIt
202
203
  end
203
204
 
204
205
  def define_controller
205
- c_name = "#{name.to_s.camelize}Controller" # !POTABLE
206
+ c_name = "#{name.to_s.camelize}Controller" # !PORTABLE
206
207
  resource = self
207
208
  c_class = Class.new(AdminIt.config.controller) do
208
209
  @resource = resource
@@ -213,14 +214,14 @@ module AdminIt
213
214
 
214
215
  if _context < SavableSingleContext
215
216
  define_method _context.save_action do
216
- load_context(_context) { context.save_entity(self) }
217
+ load_context(_context) { context.save_entity }
217
218
  end
218
219
  end
219
220
  end
220
221
 
221
222
  if resource.destroyable?
222
223
  define_method :destroy do
223
- load_context(resource[:show]) { context.destroy_entity(self) }
224
+ load_context(resource[:show]) { context.destroy_entity }
224
225
  end
225
226
  end
226
227
  end
@@ -1,5 +1,5 @@
1
1
  #
2
2
  module AdminIt
3
3
  # Current gem version
4
- VERSION = '1.0.6'
4
+ VERSION = '1.0.7'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: admin_it
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.6
4
+ version: 1.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexey Ovchinnikov
@@ -209,6 +209,7 @@ files:
209
209
  - app/assets/stylesheets/admin_it/bootstrap-theme.min.css
210
210
  - app/assets/stylesheets/admin_it/bootstrap.min.css
211
211
  - app/assets/stylesheets/admin_it/font-awesome.min.css.erb
212
+ - app/views/admin_it/context/_show.html.slim
212
213
  - app/views/admin_it/context/_table.html.slim
213
214
  - app/views/admin_it/context/_tiles.html.slim
214
215
  - app/views/admin_it/edit.html.slim