redde 0.3.22 → 0.3.23

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: 154c245f54bb6a65a6be504bd7426c1c0ccab5f9
4
- data.tar.gz: 5ed9a3bda4d25539d23eceece3113a309787f2f4
3
+ metadata.gz: d0efa702172d1b777179f2041fdab06a083f4f01
4
+ data.tar.gz: eb958f7bc8cc84e9524ea3f586bfa05d8d58480c
5
5
  SHA512:
6
- metadata.gz: f179259536bd2ea94f6576095d5a267fb48a50dbbc6998085b2e10fbcb1b379ecc1de07cea81f1d77852770ba6228a56e7c9705a23b27d63d8688ef8e78924cf
7
- data.tar.gz: 774f205d1f7882f94a14e8a23cb8cf3a50e5c0e5a9264503a4e9e4a67ab5c49564349aa5ffad32b36b09315908457c7196769feda96ca9ae76627ae84ef90931
6
+ metadata.gz: 458cdf655e6ee8990d5aafe0e48bc231112cce07c35dff89d13a01bf894182fca5842aef1c8bc9a67aeada5091537b076845c097b5c5b81d2de602ff27cd2c8c
7
+ data.tar.gz: cede951278c32817510c45fe5e2d73c72cfb875a05c2876f43f9a2ea0e188eaf302fdb21a0a74d81d37a68e1c13307ab5fec8aad31b777df0b91bbee9879b83c
@@ -31,6 +31,7 @@
31
31
  background: #d7e4ef
32
32
  padding-right: 0
33
33
  min-width: 10px
34
+ width: 0.01%
34
35
 
35
36
  &._img
36
37
  padding-left: 20px
@@ -62,7 +63,8 @@
62
63
  &:first-child,
63
64
  &:last-child
64
65
  padding-right: 0
65
- width: 10px
66
+ min-width: 10px
67
+ width: 0.01%
66
68
  border-bottom: 0 none
67
69
 
68
70
  &._handle
@@ -4,9 +4,6 @@ class Admin::BaseController < ActionController::Base
4
4
  include Redde::AdminHelper
5
5
  include Redde::IndexHelper
6
6
 
7
- def welcome
8
- end
9
-
10
7
  def index
11
8
  instance_variable_set("@#{collection}", scope)
12
9
  return render 'tree' if column_names.include?('ancestry')
@@ -11,36 +11,111 @@ module Redde::IndexHelper
11
11
  model_name.columns.select { |i| i.type == :string }.first
12
12
  end
13
13
 
14
- def list_table(res_collection, &block)
15
- render layout: 'admin/redde/list', locals: { res_collection: res_collection } do
16
- res_collection.each do |item|
17
- concat list_table_row( item, &block )
14
+ class IndexBuilder
15
+ include ActionView::Helpers::TagHelper
16
+ include ActionView::Context
17
+
18
+ attr_accessor :list, :params
19
+
20
+ def initialize(list, params)
21
+ @list = list
22
+ @params = params
23
+ end
24
+
25
+ def empty( options = {} )
26
+ content_tag(:th, "", class: ['list__head', options[:class]])
27
+ end
28
+
29
+ def thead insert
30
+ content_tag :thead do
31
+ content_tag(:tr, empty + visible + insert + empty(class: 'list__head_del') + empty)
18
32
  end
19
33
  end
20
- end
21
34
 
22
- def list_table_row(item, &block)
23
- render layout: 'admin/redde/row', locals: { item: item } do
24
- index_columns.each do |column|
25
- concat list_table_cell(item, column, &block)
35
+ def visible
36
+ empty(class: '_eye') if list.column_names.include?('visible')
37
+ end
38
+
39
+ class IndexHeadCellBuilder
40
+ include ActionView::Helpers::TagHelper
41
+ include ActionView::Context
42
+
43
+ attr_accessor :list
44
+
45
+ def initialize(list)
46
+ @list = list
47
+ end
48
+
49
+ def cell field = nil, options = {}, &block
50
+ content_tag :th, list.human_attribute_name(field), class: ['list__head', options[:class]]
26
51
  end
27
52
  end
28
- end
29
53
 
30
- def list_table_cell(item, column, &block)
31
- case column
32
- when 'position'
33
- content_tag(:td, "", class: 'list__cell _handle', 'data-sortable-handle' => "")
34
- when 'visible'
35
- content_tag(:td, link_to('', url_for(id: item, action: :update, record => { visible: !item.visible} ), class: ['list__eye', ('_disactive' if !item.visible)], data: { method: 'put' }), class: 'list__cell _eye')
36
- when 'title', 'name'
37
- content_tag(:td, link_to(item.send(column), url_for(id: item, action: :edit)), class: 'list__cell')
38
- else
39
- if block_given?
40
- capture(item, column, &block)
41
- else
42
- content_tag :td, item.send(column), class: 'list__cell'
54
+ class IndexCellBuilder
55
+ include ActionView::Helpers
56
+ include ActionView::Context
57
+ include ActionView::Helpers::UrlHelper
58
+ include Rails.application.routes.url_helpers
59
+ include Haml::Helpers
60
+
61
+ attr_accessor :item, :builder
62
+
63
+ def initialize(item, builder)
64
+ @item = item
65
+ @builder = builder
66
+ init_haml_helpers
43
67
  end
68
+
69
+ def self.content value
70
+ case value.class.name
71
+ when 'Time' then I18n.l(value, format: '%d %b %Y, %H:%M')
72
+ when 'Date' then I18n.l(value, format: '%d %b %Y')
73
+ else
74
+ value
75
+ end
76
+ end
77
+
78
+ def cell(field, options = {}, &block)
79
+ # через content_tag ... do не работает
80
+ content_tag :td, if block_given? then capture(&block) else IndexCellBuilder.content(item.send(field)) end, class: ['list__cell', options[:class]]
81
+ end
82
+
83
+ def empty(options = {})
84
+ content_tag(:td, "", class: ['list__cell', options[:class]])
85
+ end
86
+
87
+ def handle
88
+ return content_tag(:td, "", class: ['list__cell', '_handle'], 'data-sortable-handle' => "") if item.class.column_names.include?('position')
89
+ empty
90
+ end
91
+
92
+ def visible
93
+ content_tag :td, class: 'list__cell _eye' do
94
+ link_to('', url_for(id: item, controller: builder.params[:controller], action: :update, item.class.model_name.param_key => { visible: !item.visible} ), class: ['list__eye', ('_disactive' if !item.visible)], data: { method: 'put' })
95
+ end if item.class.column_names.include?('visible')
96
+ end
97
+
98
+ def del
99
+ content_tag :td, class: 'list__cell list__cell_del' do
100
+ link_to('', url_for(id: item, action: :destroy, controller: builder.params[:controller]), method: :delete, data: { confirm: 'Точно удалить?' }, class: 'list__del')
101
+ end
102
+ end
103
+ end
104
+ end
105
+
106
+ def list_table(list, options = {}, &block)
107
+ raise ArgumentError, "Missing block" unless block_given?
108
+ builder = IndexBuilder.new(list, params)
109
+
110
+ html = list.map do |item|
111
+ cb = IndexBuilder::IndexCellBuilder.new(item, builder)
112
+ content_tag(:tr, cb.handle + cb.visible + capture(cb, &block) + cb.del + cb.empty, 'data-href' => url_for(id: item, action: :edit), 'data-sortable-item' => "", id: "pos_#{item.id}")
113
+ end.join.html_safe
114
+
115
+ hb = IndexBuilder::IndexHeadCellBuilder.new(list)
116
+ content_tag :table, class: ['list', options[:class]], style: options[:style], "data-sortable" => { handle: "[data-sortable-handle]" }.to_json do
117
+ concat builder.thead( capture(hb, &block) )
118
+ concat html
44
119
  end
45
120
  end
46
121
 
@@ -1,8 +1,9 @@
1
1
  = redde_page do |f|
2
2
  - form_column_names.each do |column|
3
- = f.redde_field column.to_sym
4
- - if column_names.include?('ancestry')
5
- = f.redde_select :parent_id, ancestry_tree(model_name.roots.order(:position), title_symbol_for(instance_variable_get("@#{record}"))), include_blank: 'Корневая'
3
+ - if column == 'ancestry'
4
+ = f.redde_select :parent_id, ancestry_tree(model_name.roots.order(:position), title_symbol_for(instance_variable_get("@#{record}"))), include_blank: 'Корневая'
5
+ - else
6
+ = f.redde_field column.to_sym
6
7
 
7
8
  -# %div= render 'redditor/admin/page', { f: f } if @article.methods.include?(:page)
8
9
 
@@ -1,6 +1,5 @@
1
1
  = page_header
2
2
 
3
- - res_collection = instance_variable_get("@#{collection}")
4
-
5
- = list_table res_collection do |item, column|
6
- %td.list__cell= render_item_column(item, column)
3
+ = list_table instance_variable_get("@#{collection}") do |t|
4
+ - (index_columns - ['position', 'visible']).each do |column|
5
+ = t.cell column
data/lib/redde/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Redde
2
- VERSION = '0.3.22'.freeze
2
+ VERSION = '0.3.23'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redde
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.22
4
+ version: 0.3.23
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oleg Bovykin
@@ -522,7 +522,6 @@ files:
522
522
  - app/views/admin/base/edit.html.haml
523
523
  - app/views/admin/base/index.html.haml
524
524
  - app/views/admin/base/tree.html.haml
525
- - app/views/admin/base/welcome.haml
526
525
  - app/views/admin/managers/edit.html.haml
527
526
  - app/views/admin/redde/_header.html.haml
528
527
  - app/views/admin/redde/_list.html.haml
@@ -1,2 +0,0 @@
1
- = content_for :page_header do
2
- %h1 Welcome