btemplater 1.2.0 → 1.3.3

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: 4f08fd8f55db6d6bc515ffffffa7a0d2a67a9cc4cbc44c5a32cf8848ace16654
4
- data.tar.gz: 1911356e285d12e06e3584e9b3e1e1b3ab04c3a12decc8523b9df8a18d390dd5
3
+ metadata.gz: 3597e1e51e82afc3fa4bd1b2c83724dde7d398b22647474dcda460a8bce6d8ce
4
+ data.tar.gz: 762b901aee0ff349e537bc937ef484550be0963c3b0e39a29e955845636a6496
5
5
  SHA512:
6
- metadata.gz: d0a4d0fe2cd061735b9196665f43d37f99c2144c1b2bc1ea7d7a7f0e5d17d18a8b78b92b059c2ec3c529fa24e6da5ee16465f70ede528715d43281de266a54e9
7
- data.tar.gz: b09723d73753834ceb27b7db92d1a7a09dc53cfd90f467f65ad7fe9ecbf619caca048215571ee8df2242cad623c5e9ea4c5eb6d306bdfea99207c904313b9925
6
+ metadata.gz: 6e7ab6927dd7ae07168d760301b06e6fc2fb8442791392018f830ee26fbfe9324a1915eb01b3fd9f0420c52f13b80161500799dc1c9276671cbeba5ad9b1c019
7
+ data.tar.gz: 4c7b5775a72a4987aa2df0151ecba0c4e9d114aeefba732e6c5e82d4005b73c7e5a280102910e40be20416677d9697f084a66bcd42fc0cf8cf13a40348bfcc0e
@@ -4,6 +4,7 @@ module Btemplater
4
4
  include ActionView::Helpers::TagHelper
5
5
  include ActionView::Helpers::UrlHelper
6
6
  include Btemplater::IndexSubHelper
7
+ include Btemplater::IndexSearchHelper
7
8
  include ActionView::Helpers::TagHelper
8
9
  include Pundit
9
10
 
@@ -35,11 +36,13 @@ module Btemplater
35
36
  columns: [],
36
37
  items: [],
37
38
  model: nil,
38
- actions: []
39
+ actions: [],
40
+ search: {}
39
41
  )
40
42
  capture do
41
43
  concat(render(args[:form_pre])) if args[:form_pre]
42
44
  concat do_title(args[:title], args[:titleactions], args[:title_small], self, args)
45
+ concat(search args[:search], current_user_entity, self)
43
46
  concat(paginate args[:items])
44
47
  concat(IndexSubHelper.custom_table_for(args, current_user_entity, self) do
45
48
  args[:columns].each do |c|
@@ -0,0 +1,180 @@
1
+ module Btemplater
2
+ module IndexSearchHelper
3
+ def search(args, current_user_entity, env)
4
+ # yield
5
+
6
+ # model_name = args[:model].to_s
7
+ # model_name = args[:model].try(:first).to_s if args[:model].is_a?(Array)
8
+
9
+ #cont = env.content_tag :table, class: "table table-hover table-striped #{model_name.underscore.gsub('/', '_')}" do
10
+ # thead(args, env) + tbody(args, current_user_entity, env)
11
+ #end
12
+
13
+ search_args = args.try('[]', :args).try('[]', 0)
14
+ search_fields = args.try('[]', :fields)
15
+ return '' unless search_fields
16
+
17
+ search_dialog = render 'btemplater/shared/search_dialog', env: env, fields: search_fields, args: search_args
18
+
19
+ search_str = search_dialog
20
+ search_str += "<button id=\"search_button\" onclick=\"$('#searchmodal').modal('show');\" class=\"btn btn-info\">Keresés megjelenítése...</button>".html_safe
21
+ search_str += "&nbsp;#{search_active(env.params)}".html_safe
22
+
23
+ return search_str.html_safe
24
+ end
25
+
26
+ def search_active(params)
27
+ search_params = params[:search]
28
+ if search_params
29
+ i = 0
30
+ search_params.each do |prm|
31
+ i = search_params_helper(prm[0].to_sym, search_params, i)
32
+ end
33
+ return '' if i == 0
34
+ str = '<span class="badge badge-warning">' + i.to_s + ' keresési feltétel aktív</span>'
35
+ return str.html_safe
36
+ else
37
+ return ''
38
+ end
39
+ end
40
+
41
+ def search_params_helper(field, search_params, i, truevalue = nil)
42
+ if truevalue.nil?
43
+ if !search_params[field].blank?
44
+ i += 1
45
+ end
46
+ else
47
+ if search_params[field] == truevalue
48
+ i += 1
49
+ end
50
+ end
51
+ return i
52
+ end
53
+
54
+ # def column(name, value = nil, &block)
55
+ # value = name unless value
56
+ # @columns << { name: name, value: value, block: block }
57
+ # end
58
+
59
+ # def show_action(args, item, right = true, env = nil)
60
+ # env.link_to env.polymorphic_url(args[:class].map{|m| m.to_s.demodulize.tableize.singularize}, id: item.id), class: 'btn btn-secondary', title: I18n.t('actions.show', scope: :btemplater) do
61
+ # env.content_tag(:span, '', class: 'fa fa-file')
62
+ # end.html_safe if right
63
+ # end
64
+
65
+ # def edit_action(args, item, right = true, env = nil)
66
+ # po = args[:parentobj] ? args[:parentobj].dup : []
67
+ # env.link_to env.polymorphic_url((po << item).flatten, {action: :edit}.merge(args[:options] || {})), class: 'btn btn-warning', title: I18n.t('actions.edit_short', scope: :btemplater) do
68
+ # env.content_tag(:span, '', class: 'fa fa-pencil-square-o')
69
+ # end.html_safe if right
70
+ # end
71
+
72
+ # def destroy_action(args, item, right = true, env = nil, confirm_message = I18n.t('actions.are_you_sure', scope: :btemplater))
73
+ # po = args[:parentobj] ? args[:parentobj].dup : []
74
+ # env.link_to env.polymorphic_url((po << item).flatten, {}.merge(args[:options] || {})), class: 'btn btn-danger', title: I18n.t('actions.destroy', scope: :btemplater), method: :delete, data: { confirm: confirm_message } do
75
+ # env.content_tag(:span, args[:text].blank? ? '' : " #{args[:text]}", class: 'fa fa-trash')
76
+ # end.html_safe if right
77
+ # end
78
+
79
+ # def action_decorator(ad, item, policy = true, env = nil, clazz = nil)
80
+ # env.link_to ad.path.call(item), class: (ad.clazz.blank? ? 'btn btn-secondary' : ad.clazz), title: ad.title, method: ad.method, data: ad.data do
81
+ # if ad.icon.class == Proc
82
+ # env.content_tag(:span, '', class: "fa fa-#{ad.icon.call(item)}")
83
+ # else
84
+ # env.content_tag(:span, '', class: "fa fa-#{ad.icon}")
85
+ # end
86
+ # end.html_safe
87
+ # end
88
+
89
+ # def thead(args, env = nil)
90
+ # env.content_tag :thead do
91
+ # env.content_tag :tr do
92
+ # @columns.each do |c|
93
+ # env.concat(env.content_tag(:th, c[:value], class: c[:name]))
94
+ # end
95
+ # env.concat(env.content_tag(:th, '')) unless args[:actions].empty?
96
+ # end
97
+ # end
98
+ # end
99
+
100
+ # def tbody(args, current_user_entity, env = nil)
101
+ # items = args[:items]
102
+ # if items.count == 0
103
+ # env.content_tag :tbody do
104
+ # if args[:empty_partial]
105
+ # env.render args[:empty_partial]
106
+ # elsif args[:empty_text]
107
+ # ('<tr><td colspan="999">' + args[:empty_text] + '</td></tr>').html_safe
108
+ # else
109
+ # ('<tr><td colspan="999">' + I18n.t('helpers.index.table_empty') + '</td></tr>').html_safe
110
+ # end
111
+ # end
112
+ # else
113
+ # model_name = args[:model].is_a?(Array) ? args[:model].last.to_s : args[:model].to_s
114
+ # env.content_tag :tbody do
115
+ # items.each do |item|
116
+ # env.concat(
117
+ # env.content_tag(:tr, class: (args[:rowclass].nil? ? '' : args[:rowclass].call(item))) do
118
+ # @columns.each do |column|
119
+ # css_classes = ''
120
+ # args[:css_classes].each do |css_class|
121
+ # css_classes += " #{css_class.decorator.call(item)}"
122
+ # end unless args[:css_classes].nil?
123
+ # if column[:name].is_a? Hash
124
+ # if column[:name].has_key? :date
125
+ # value = item.send(column[:name][:date])
126
+ # env.concat(env.content_tag(:td, value.nil? ? '' : I18n.l(value, format: :long), class: css_classes))
127
+ # elsif column[:name].has_key? :date_short
128
+ # value = item.send(column[:name][:date_short])
129
+ # env.concat(env.content_tag(:td, value.nil? ? '' : I18n.l(value, format: :short), class: css_classes))
130
+ # end
131
+ # elsif column[:block]
132
+ # env.concat(env.content_tag(:td, column[:block].call(item.send(column[:name]), item, env), class: css_classes))
133
+ # else
134
+ # env.concat(env.content_tag(:td, item.send(column[:name]), class: css_classes))
135
+ # end
136
+ # end
137
+ # env.concat(env.content_tag(:td) do
138
+ # args[:actions].each do |action|
139
+ # policy_name = nil
140
+ # if args[:policy_class]
141
+ # policy_name = "#{args[:policy_class]}Policy".constantize
142
+ # else
143
+ # policy_name = "#{model_name}Policy".constantize
144
+ # end
145
+ # if action.instance_of? Btemplater::ActionDecorator
146
+ # # env.concat(env.content_tag(:div, action_decorator(action, item, authorize(security_items), "#{action.name}?", env), style: 'display: inline;'))
147
+ # env.concat(env.content_tag(:div, action_decorator(action, item, policy_name.new(Current, item).send("#{action.name}?"), env), style: 'display: inline;'))
148
+ # else
149
+ # # env.concat(env.content_tag(:div, send("#{action}_action", args, item, authorize(security_items), "#{action}?".to_sym, env), style: 'display: inline;'))
150
+ # env.concat(env.content_tag(:div, send("#{action}_action", args, item, policy_name.new(Current, item).send("#{action}?"), env), style: 'display: inline;'))
151
+ # end
152
+ # end
153
+ # end)
154
+ # end
155
+ # )
156
+ # end
157
+ # end
158
+ # end
159
+ # end
160
+
161
+ # def do_new_button(args, current_user_entity, params = {})
162
+ # model_name = args[:model].is_a?(Array) ? args[:model].last.class : args[:model].class
163
+ # content_tag :div do
164
+ # link_to t('helpers.submit.create', model: t("activerecord.models.#{model_name.model_name.to_s.tableize.singularize}")),
165
+ # polymorphic_url(args[:model], action: :new, params: params),
166
+ # class: 'btn btn-primary'
167
+ # end if "#{model_name}Policy".constantize.new(current_user_entity, args[:model]).new?
168
+ # end
169
+
170
+ # module_function :show_action
171
+ # module_function :edit_action
172
+ # module_function :destroy_action
173
+ # module_function :do_new_button
174
+ # module_function :custom_table_for
175
+ # module_function :column
176
+ # module_function :thead
177
+ # module_function :tbody
178
+ # module_function :action_decorator
179
+ end
180
+ end
@@ -62,12 +62,16 @@ module Btemplater
62
62
  items = args[:items]
63
63
  if items.count == 0
64
64
  env.content_tag :tbody do
65
- if args[:empty_partial]
66
- env.render args[:empty_partial]
67
- elsif args[:empty_text]
68
- ('<tr><td colspan="999">' + args[:empty_text] + '</td></tr>').html_safe
65
+ if env.params[:search]
66
+ ('<tr><td colspan="999">' + I18n.t('helpers.index.no_search_result') + '</td></tr>').html_safe
69
67
  else
70
- ('<tr><td colspan="999">' + I18n.t('helpers.index.table_empty') + '</td></tr>').html_safe
68
+ if args[:empty_partial]
69
+ env.render args[:empty_partial]
70
+ elsif args[:empty_text]
71
+ ('<tr><td colspan="999">' + args[:empty_text] + '</td></tr>').html_safe
72
+ else
73
+ ('<tr><td colspan="999">' + I18n.t('helpers.index.table_empty') + '</td></tr>').html_safe
74
+ end
71
75
  end
72
76
  end
73
77
  else
@@ -98,15 +98,17 @@ module Btemplateable
98
98
  define_method :destroy do
99
99
  obj = self.class.name.split('Controller').first.singularize.constantize
100
100
  path = self.class.name.split('Controller').first.downcase.gsub('::', '.') + '_path'
101
-
101
+ puts obj.inspect
102
+ puts path.inspect
102
103
  skip_policy_scope
103
- @object = self.class.name.split('Controller').first.singularize.constantize.find(params[:id])
104
- authorize @object
104
+ do_destroy(params, obj, send(path.split('.').first).send(path.split('.').last))
105
+ # @object = self.class.name.split('Controller').first.singularize.constantize.find(params[:id])
106
+ # authorize @object
105
107
  # obj = self.class.name.split('Controller').first.singularize.constantize
106
- path = self.class.name.split('Controller').first.downcase.gsub('::', '.') + '_path'
108
+ # path = self.class.name.split('Controller').first.downcase.gsub('::', '.') + '_path'
107
109
  # LastVisitedProject.where(company_id: current_user.current_company?.id, project_id: @project.id).try(:destroy_all)
108
- @object.destroy
109
- redirect_to send(path.split('.').first).send(path.split('.').last)
110
+ # @object.destroy
111
+ # redirect_to send(path.split('.').first).send(path.split('.').last)
110
112
  end
111
113
  else
112
114
  define_method name do
@@ -110,9 +110,10 @@ module Btemplater
110
110
  policy_name = "#{model.to_s}Policy".constantize
111
111
  # end
112
112
  authorize (@object), :destroy?
113
- raise Pundit::NotAuthorizedError unless(policy_name.new(Btemplater::Engine.config.current_user_entity.call(self), @object).destroy?)
113
+ raise Pundit::NotAuthorizedError unless(policy_name.new(Current, @object).destroy?)
114
114
  @object.destroy
115
115
  if @object.destroyed?
116
+ send(:after_destroy, @object) if respond_to?(:after_destroy, true)
116
117
  flash['notice'] = t('btemplater.controllers.destroy_success')
117
118
  end
118
119
  if redirect_root.nil?
@@ -0,0 +1,170 @@
1
+ <!-- Search modal -->
2
+ <div class="modal fade" id="searchmodal" tabindex="-1" role="dialog" aria-labelledby="searchmodalTitle" aria-hidden="true">
3
+ <div class="modal-dialog" role="document">
4
+ <div class="modal-content">
5
+ <%= simple_form_for :search, action: args[:action], method: args[:method] do |f| %>
6
+ <div class="modal-header">
7
+ <h5 class="modal-title" id="searchmodalTitle">Keresés...</h5>
8
+ <button type="button" class="close" data-dismiss="modal" aria-label="Close">
9
+ <span aria-hidden="true">&times;</span>
10
+ </button>
11
+ </div>
12
+ <script type="text/javascript">
13
+ function clear_search_fields() {
14
+ console.log('clearing...');
15
+ var oldValue = $('#search_templates_select').val();
16
+ $('#searchmodal form').find("input[type=text], textarea, select").val('');
17
+ $('#searchmodal form').find("input[type=checkbox]").val('');
18
+ $('#searchmodal form').find("input[type=checkbox]").prop('checked', false)
19
+ $('#search_templates_select').val(oldValue);
20
+ }
21
+
22
+ <% if args[:templates] %>
23
+ function getSearchtemplates() {
24
+ $.get("<%= finances.searchtemplates_path %>", function(data) {
25
+ console.log(data);
26
+ var search_templates_select = $("#search_templates_select");
27
+ var oldValue = search_templates_select.val();
28
+ search_templates_select.find('option').remove();
29
+ search_templates_select.append($("<option></option>"));
30
+ $.each(data, function(i, obj) {
31
+ search_templates_select.append($("<option></option>")
32
+ .attr("value", obj.id)
33
+ .text(obj.name));
34
+ });
35
+ console.log('selectind ' + oldValue);
36
+ search_templates_select.val(oldValue);
37
+ search_templates_select.val('<%= params[:search_template] %>');
38
+ // searchTemplateChanged();
39
+ });
40
+ }
41
+
42
+ function saveSearch() {
43
+ var searchTemplateName = prompt("Search template name:", "");
44
+ var data = $('#searchmodal form').serializeArray();
45
+ var alldata = {
46
+ "searchtemplate": {
47
+ "name": searchTemplateName,
48
+ "data": data
49
+ }
50
+ }
51
+ $.ajax({
52
+ type: "POST",
53
+ url: "<%= finances.searchtemplates_path %>",
54
+ data: alldata,
55
+ headers: {
56
+ 'X-CSRF-Token': $('meta[name="csrf-token"]').attr('content')
57
+ },
58
+ success: function(res, data) {
59
+ console.log("success");
60
+ console.log(data);
61
+ },
62
+ error: function(res, data) {
63
+ console.log("error");
64
+ console.log(data);
65
+ },
66
+ dataType: "application/json"
67
+ });
68
+ }
69
+
70
+ function deleteSearch() {
71
+ var search_templates_select = $("#search_templates_select");
72
+ var value = search_templates_select.val();
73
+
74
+ if(confirm("Biztos benne, hogy törli?") && value != "") {
75
+ var value = $('#search_templates_select').val();
76
+
77
+ var url = "<%= finances.searchtemplate_path(:changeme) %>".replace('changeme', value);
78
+ $.ajax({
79
+ type: "POST",
80
+ url: url,
81
+ dataType: "json",
82
+ data: {"_method":"delete"},
83
+ headers: {
84
+ 'X-CSRF-Token': $('meta[name="csrf-token"]').attr('content')
85
+ },
86
+ success: function(res, data) {
87
+ console.log("successdel");
88
+ console.log(data);
89
+ getSearchtemplates();
90
+ },
91
+ error: function(res, data) {
92
+ console.log("errordel");
93
+ console.log(data);
94
+ getSearchtemplates();
95
+ },
96
+ });
97
+ }
98
+ }
99
+
100
+ function searchTemplateChanged() {
101
+ // clear_search_fields();
102
+ var search_templates_select = $("#search_templates_select");
103
+ var selected_template = search_templates_select.val();
104
+ if(selected_template == "") {
105
+ clear_search_fields();
106
+ $('#search_templates_select').val('');
107
+ } else {
108
+ loadTemplate(selected_template);
109
+ }
110
+ }
111
+
112
+ function loadTemplate(template_id) {
113
+ var url = "<%= finances.searchtemplate_path(:change_this, format: :json) %>".replace('change_this', template_id);
114
+ console.log(url);
115
+ $.ajax({
116
+ type: "GET",
117
+ url: url,
118
+ // data: alldata,
119
+ // headers: {
120
+ // 'X-CSRF-Token': $('meta[name="csrf-token"]').attr('content')
121
+ // },
122
+ success: function(res, data) {
123
+ clear_search_fields();
124
+ var form = $('#searchmodal form');
125
+ // clear_search_fields();
126
+ $.each(res.data, function(i, obj) {
127
+ var dat = res.data[i];
128
+ var key = Object.keys(dat)[0];
129
+ var value = dat[key];
130
+ console.log("key: " + key);
131
+ console.log("value: " + value);
132
+ // form.find('#search_' + key).val(value);
133
+ console.log("[name='search[" + key + "]'] => " + value);
134
+ form.find("[name='search[" + key + "]']").val(value);
135
+ // var value = $("[name='nameofobject']");
136
+ });
137
+ },
138
+ error: function(res, data) {
139
+ console.log("error");
140
+ console.log(res);
141
+ }//,
142
+ // dataType: "application/json"
143
+ });
144
+ }
145
+ $(document).on("turbolinks:load", function() {
146
+ getSearchtemplates();
147
+ });
148
+ <% end %>
149
+ </script>
150
+ <div class="modal-body">
151
+ <% if args[:templates] %>
152
+ <select class="form-control" id="search_templates_select" onchange="searchTemplateChanged();return(false);" name="search_template"></select>
153
+ <div>
154
+ <a href="" class="btn btn-mini btn-warning" onclick="saveSearch(); return(false);">Keresés mentése</a>
155
+ <a href="" class="btn btn-mini btn-danger" onclick="deleteSearch(); return(false);">Keresés törlése</a>
156
+ </div>
157
+ <% end %>
158
+ <% fields.each do |field| %>
159
+ <%= field.decorator.call(f, field) %>
160
+ <% end %>
161
+ </div>
162
+ <div class="modal-footer">
163
+ <button type="button" class="btn btn-secondary" data-dismiss="modal">Bezárás</button>
164
+ <button type="button" class="btn btn-secondary" onclick="clear_search_fields();$('#search_templates_select').val('');">Alaphelyzetbe</button>
165
+ <%= f.submit 'Keresés', class: 'btn btn-warning' %>
166
+ </div>
167
+ <% end %>
168
+ </div>
169
+ </div>
170
+ </div>
@@ -1,4 +1,8 @@
1
1
  hu:
2
+ helpers:
3
+ index:
4
+ table_empty: 'Nem található még adat...'
5
+ no_search_result: 'Nincs találat!'
2
6
  btemplater:
3
7
  cancel: 'Mégsem'
4
8
  actions:
@@ -1,3 +1,3 @@
1
1
  module Btemplater
2
- VERSION = "1.2.0"
2
+ VERSION = "1.3.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: btemplater
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Muskovics Gabor
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-08-20 00:00:00.000000000 Z
11
+ date: 2019-03-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -248,6 +248,7 @@ files:
248
248
  - app/helpers/btemplater/application_helper.rb
249
249
  - app/helpers/btemplater/edit_helper.rb
250
250
  - app/helpers/btemplater/index_helper.rb
251
+ - app/helpers/btemplater/index_search_helper.rb
251
252
  - app/helpers/btemplater/index_sub_helper.rb
252
253
  - app/helpers/btemplater/new_helper.rb
253
254
  - app/helpers/btemplater/show_helper.rb
@@ -295,6 +296,7 @@ files:
295
296
  - app/views/authentication/invitation_mailer/right_added_to_user.hu.text.erb
296
297
  - app/views/btemplater/shared/_flash_messages.html.erb
297
298
  - app/views/btemplater/shared/_google_analytics.html.erb
299
+ - app/views/btemplater/shared/_search_dialog.html.erb
298
300
  - app/views/btemplater/shared/showtable.html.erb
299
301
  - app/views/devise/confirmations/new.html.erb
300
302
  - app/views/devise/mailer/confirmation_instructions.html.erb