shopapp 0.2.70 → 0.2.71
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/app/assets/javascripts/shopapp3.js +10 -4
- data/app/controllers/concerns/remote_request_manager.rb +46 -0
- data/app/helpers/shopapp3_form_helper.rb +193 -0
- data/app/views/shopapp/_display_flag.haml +4 -0
- data/app/views/shopapp/_modal_errors.haml +15 -0
- data/app/views/shopapp/modal_errors.js.erb +5 -0
- data/app/views/shopapp/render_remote_response.js.erb +13 -0
- data/shopapp.gemspec +2 -2
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 874495e5720b2a801792b23fdb4f64397b8c69d5e4ef3f38473f45217857a707
|
4
|
+
data.tar.gz: b22cf4b6d9fa37ef383342ec1662fc41ede7cc5cb2eab2f4439670fb8b17eab9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4abd1682238b019eaf23b615aaf580a28b9f298bdce62288a031a7524139f62a5e95bd50a8afdd8cb57a7fd9421704cdaf541e102601efa82a6fbf8f648e8d0d
|
7
|
+
data.tar.gz: bd72b665b7639efe76b6e4dea240d2a4c425fd7385841cd18f0e11e0f36081b4ea2edf7d0f8e64c8c8adbb23ad9b9960c5151e62bb0e471912f728e5e7d441bf
|
data/README.md
CHANGED
@@ -93,4 +93,4 @@ shopapp to support i18n, add two methods to your ApplicationController:
|
|
93
93
|
|
94
94
|
To build new version of this gem, change the version in shopapp.gemspec and run:
|
95
95
|
|
96
|
-
gem build shopapp.gemspec ; gem push shopapp-0.2.
|
96
|
+
gem build shopapp.gemspec ; gem push shopapp-0.2.71.gem; gem install shopapp
|
@@ -17,11 +17,17 @@ function shopappSnackbar(message, timeout) {
|
|
17
17
|
}
|
18
18
|
|
19
19
|
function shopappAlert(message, type) {
|
20
|
-
if(type === undefined) {
|
20
|
+
if (type === undefined) {
|
21
21
|
type = 'danger';
|
22
22
|
}
|
23
23
|
$('main > div:nth-child(2) > div:first-child').append(
|
24
|
-
|
25
|
-
|
26
|
-
|
24
|
+
'<div class="alert alert-' + type + ' alert-dismissible fade mt-3 show" role="alert">' +
|
25
|
+
message +
|
26
|
+
'<button aria-label="Close" class="close" data-dismiss="alert" type="button"><span aria-hidden="true">×</span></button></div>');
|
27
27
|
}
|
28
|
+
|
29
|
+
// Following makes BS tooltips work. See /views/layouts/application.html.haml
|
30
|
+
$(function() {
|
31
|
+
$('[data-tooltip="tooltip"]').tooltip();
|
32
|
+
$('[data-toggle="tooltip"]').tooltip();
|
33
|
+
});
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module RemoteRequestManager
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
PATH_TO_JS_FILE = "shopapp/modal_errors"
|
5
|
+
|
6
|
+
included do
|
7
|
+
end
|
8
|
+
|
9
|
+
class_methods do
|
10
|
+
end
|
11
|
+
|
12
|
+
def redirect_remote_request(notice, args = {})
|
13
|
+
respond_to do |format|
|
14
|
+
format.html { redirect_to redirect_path(args), success: notice }
|
15
|
+
format.js do
|
16
|
+
flash[:success] = notice
|
17
|
+
render js: "window.location='#{redirect_path(args)}'"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def rescue_remote_request(error)
|
23
|
+
Rails.logger.error error.message
|
24
|
+
Rails.logger.error error.backtrace.join("\n")
|
25
|
+
if error.instance_of?(ActiveRecord::RecordInvalid)
|
26
|
+
respond_to_js(error.record.errors.messages)
|
27
|
+
else
|
28
|
+
respond_to_js(error)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def respond_to_js(error_message)
|
35
|
+
flash.now[:danger] = error_message
|
36
|
+
respond_to do |format|
|
37
|
+
format.js do
|
38
|
+
render PATH_TO_JS_FILE, locals: { flash: flash }
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def redirect_path(args)
|
44
|
+
args[:to].presence || request.referer || root_path
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,193 @@
|
|
1
|
+
module Shopapp3FormHelper
|
2
|
+
def sf_text_field(f, tag, params = {})
|
3
|
+
unless params.key?(:label)
|
4
|
+
params[:label] = tag.to_s.capitalize
|
5
|
+
end
|
6
|
+
label_tag = f.label tag, params[:label] unless params[:label].nil?
|
7
|
+
input_tag = f.text_field tag,
|
8
|
+
value: params[:value],
|
9
|
+
placeholder: params[:placeholder],
|
10
|
+
class: ["form-control", params[:class]].join(' '),
|
11
|
+
required: params[:required],
|
12
|
+
'aria-describedby' => "#{tag}_help",
|
13
|
+
readonly: params[:readonly],
|
14
|
+
onkeyup: params[:onkeyup],
|
15
|
+
pattern: params[:pattern],
|
16
|
+
title: params[:title]
|
17
|
+
|
18
|
+
<<~HTML.html_safe
|
19
|
+
<div class="form-group">
|
20
|
+
#{label_flag(tag, params)}
|
21
|
+
#{label_tag}
|
22
|
+
#{input_tag}
|
23
|
+
#{help_tag(tag, params)}
|
24
|
+
#{invalid_feedback(params)}
|
25
|
+
</div>
|
26
|
+
HTML
|
27
|
+
end
|
28
|
+
|
29
|
+
def label_flag(tag, params)
|
30
|
+
if params[:language].present?
|
31
|
+
render partial: 'shopapp/display_flag', locals: { language: params[:language], html_class: ""}
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def sf_number_field(f, tag, params = {})
|
36
|
+
unless params.key?(:label)
|
37
|
+
params[:label] = tag.to_s.capitalize
|
38
|
+
end
|
39
|
+
label_tag = f.label tag, params[:label]
|
40
|
+
input_tag = f.number_field tag,
|
41
|
+
value: params[:value],
|
42
|
+
min: 0,
|
43
|
+
placeholder: params[:placeholder],
|
44
|
+
class: 'form-control',
|
45
|
+
required: params[:required],
|
46
|
+
'aria-describedby' => "#{tag}_help"
|
47
|
+
|
48
|
+
<<~HTML.html_safe
|
49
|
+
<div class="form-group">
|
50
|
+
#{label_tag}
|
51
|
+
#{input_tag}
|
52
|
+
#{help_tag(tag, params)}
|
53
|
+
#{invalid_feedback(params)}
|
54
|
+
</div>
|
55
|
+
HTML
|
56
|
+
end
|
57
|
+
|
58
|
+
def sf_checkbox(f, tag, params = {})
|
59
|
+
unless params.key?(:label)
|
60
|
+
params[:label] = tag.to_s.capitalize
|
61
|
+
end
|
62
|
+
label_tag = f.label tag,
|
63
|
+
value: params[:label],
|
64
|
+
class: 'form-check-label'
|
65
|
+
input_tag = f.check_box tag,
|
66
|
+
value: params[:value],
|
67
|
+
placeholder: params[:placeholder],
|
68
|
+
class: 'form-check-input',
|
69
|
+
required: params[:required],
|
70
|
+
'aria-describedby' => "#{tag}_help",
|
71
|
+
readonly: params[:readonly]
|
72
|
+
|
73
|
+
<<~HTML.html_safe
|
74
|
+
<div class="form-group form-check pt-2">
|
75
|
+
#{input_tag}
|
76
|
+
#{label_tag}
|
77
|
+
#{help_tag(tag, params)}
|
78
|
+
#{invalid_feedback(params)}
|
79
|
+
</div>
|
80
|
+
HTML
|
81
|
+
end
|
82
|
+
|
83
|
+
def sf_select(f, tag, params = {})
|
84
|
+
unless params.key?(:label)
|
85
|
+
params[:label] = tag.to_s.capitalize
|
86
|
+
end
|
87
|
+
label_tag = f.label tag, params[:label]
|
88
|
+
options_list = if params.key? :enum
|
89
|
+
options_for_select(params[:enum].keys, params[:selected_value])
|
90
|
+
elsif params.key? :list
|
91
|
+
options_for_select(params[:list], params[:selected_value])
|
92
|
+
else
|
93
|
+
# we will impolement them as we go
|
94
|
+
fail NotImplementedError
|
95
|
+
end
|
96
|
+
|
97
|
+
select_tag = f.select tag,
|
98
|
+
options_list,
|
99
|
+
{ include_blank: (params[:blank_option_title] || "Please select...") }.merge(params[:select_params].to_h),
|
100
|
+
{ class: "custom-select", required: params[:required] }.merge(params[:html_params].to_h)
|
101
|
+
help_tag = if params[:help].present?
|
102
|
+
%(<small class="form-text text-muted" id="#{tag}_help">#{params[:help]}</small>)
|
103
|
+
end
|
104
|
+
|
105
|
+
<<~HTML.html_safe
|
106
|
+
<div class="form-group">
|
107
|
+
#{label_tag}
|
108
|
+
#{select_tag}
|
109
|
+
#{help_tag(tag, params)}
|
110
|
+
#{invalid_feedback(params)}
|
111
|
+
</div>
|
112
|
+
HTML
|
113
|
+
end
|
114
|
+
|
115
|
+
def sf_submit(*params_numbered, **params)
|
116
|
+
rails ArgumentError unless params_numbered.count <= 1
|
117
|
+
params_numbered << 'Submit' if params_numbered.count < 1
|
118
|
+
# label = 'Submit'
|
119
|
+
%(<button name="#{params[:name]}" type="submit" class="btn btn-primary float-right ml-2 mt-3 #{params[:class]}">#{params_numbered[0]}</button>).html_safe
|
120
|
+
end
|
121
|
+
|
122
|
+
def sf_cancel(return_path, label = 'Cancel', params = {})
|
123
|
+
%(<a href="#{return_path}" class="btn btn-warning float-right ml-2 mt-3" role="button">#{label}</a>).html_safe
|
124
|
+
end
|
125
|
+
|
126
|
+
def sf_action(url, action_name = nil, text = nil, remote: true, method: :post, additional_classes: nil, form_class: nil, onclick: onclick)
|
127
|
+
action_name ||= :submit
|
128
|
+
button_to((text || action_name.to_s.humanize),
|
129
|
+
url,
|
130
|
+
{
|
131
|
+
form_class: (form_class || 'float-right mr-2'),
|
132
|
+
name: :button_action,
|
133
|
+
method: method,
|
134
|
+
remote: remote,
|
135
|
+
class: ["btn", additional_classes || 'btn-secondary'].join(' '),
|
136
|
+
data: { disable_with: "Please wait..." },
|
137
|
+
onclick: onclick,
|
138
|
+
}
|
139
|
+
)
|
140
|
+
#%button.btn.btn-danger.btn-sm Reject
|
141
|
+
end
|
142
|
+
|
143
|
+
def sf_model_validation(model)
|
144
|
+
if model.errors.any?
|
145
|
+
<<~HTML.html_safe
|
146
|
+
<div class="alert alert-danger">
|
147
|
+
<h5>#{pluralize(@product.errors.count, "error")} appeared in the form:</h5>
|
148
|
+
<ul>
|
149
|
+
#{model.errors.full_messages.map { |msg| "<li>#{msg}</li>" }.join}
|
150
|
+
<ul>
|
151
|
+
</div>
|
152
|
+
HTML
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
def sf_bool_value(value)
|
157
|
+
symbol = value ? 'check-outline' : 'close-outline'
|
158
|
+
mdi_tag "#{symbol} 24px"
|
159
|
+
end
|
160
|
+
|
161
|
+
# private helpers
|
162
|
+
|
163
|
+
def help_tag(tag, params)
|
164
|
+
if params[:help].present?
|
165
|
+
%(<small class="form-text text-muted" id="#{tag}_help">#{params[:help]}</small>)
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
def invalid_feedback(params)
|
170
|
+
if params[:invalid_feedback].present?
|
171
|
+
%(<div class="invalid-feedback">#{params[:invalid_feedback]}</div>)
|
172
|
+
end
|
173
|
+
|
174
|
+
end
|
175
|
+
|
176
|
+
def format_js_render_remote_response(destination_selector, partial, locals = {})
|
177
|
+
respond_to do |format|
|
178
|
+
format.js {
|
179
|
+
render_remote_response(destination_selector, partial, locals)
|
180
|
+
}
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
def render_remote_response(destination_selector, partial, locals = {})
|
185
|
+
status = locals[:status]
|
186
|
+
locals.delete :status
|
187
|
+
render :render_remote_response, status: status, locals: {
|
188
|
+
destination_selector: destination_selector,
|
189
|
+
partial: partial.to_s,
|
190
|
+
locals: locals
|
191
|
+
}
|
192
|
+
end
|
193
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
#alert-container
|
2
|
+
- flash.keys.each do |f|
|
3
|
+
.alert.alert-dismissible.fade.show(class="alert-#{f.gsub('notice', 'info').gsub('alert', 'warning')}" role="alert")
|
4
|
+
-if flash[f].is_a? Hash
|
5
|
+
- flash[f].values.each do |flsh|
|
6
|
+
= "- #{flsh.first}"
|
7
|
+
%br
|
8
|
+
%button.close(type="button" data-dismiss="alert" aria-label="Close")
|
9
|
+
%span(aria-hidden="true")
|
10
|
+
= mdi_tag 'close 12px'
|
11
|
+
-else
|
12
|
+
= flash[f]
|
13
|
+
%button.close(type="button" data-dismiss="alert" aria-label="Close")
|
14
|
+
%span(aria-hidden="true")
|
15
|
+
= mdi_tag 'close 12px'
|
@@ -0,0 +1,13 @@
|
|
1
|
+
$("<%= destination_selector %>").html(
|
2
|
+
"<%= escape_javascript(render partial: partial,
|
3
|
+
locals: locals.except(:snackbar_message, :alert))
|
4
|
+
%>"
|
5
|
+
);
|
6
|
+
|
7
|
+
<% if (locals[:snackbar_message]).present? %>
|
8
|
+
shopappSnackbar("<%=locals[:snackbar_message]%>");
|
9
|
+
<% end %>
|
10
|
+
|
11
|
+
<% if (locals[:alert]).present? %>
|
12
|
+
alert("<%=locals[:alert]%>");
|
13
|
+
<% end %>
|
data/shopapp.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'shopapp'
|
3
|
-
s.version = '0.2.
|
4
|
-
s.date = '2019-
|
3
|
+
s.version = '0.2.71'
|
4
|
+
s.date = '2019-12-14'
|
5
5
|
s.summary = 'Do a shoplift.'
|
6
6
|
s.description = 'Ha! Art thou Bedlam? Dost thou thirst base Trojan, to have me fold up Parca\'s fatal web? Hence!\
|
7
7
|
I am qualmish at the smell of leek.'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shopapp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.71
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zeljko
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-12-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
@@ -411,6 +411,7 @@ files:
|
|
411
411
|
- app/assets/stylesheets/variables.scss
|
412
412
|
- app/controllers/api_controller.rb
|
413
413
|
- app/controllers/auth_controller.rb
|
414
|
+
- app/controllers/concerns/remote_request_manager.rb
|
414
415
|
- app/controllers/concerns/shopapp3.rb
|
415
416
|
- app/controllers/concerns/shoplift_client.rb
|
416
417
|
- app/controllers/concerns/shoplift_search.rb
|
@@ -418,15 +419,20 @@ files:
|
|
418
419
|
- app/controllers/user_authenticated_controller.rb
|
419
420
|
- app/controllers/user_authenticated_or_api_controller.rb
|
420
421
|
- app/helpers/euro_helper.rb
|
422
|
+
- app/helpers/shopapp3_form_helper.rb
|
421
423
|
- app/helpers/shopapp3_helper.rb
|
422
424
|
- app/helpers/shopapp_helper.rb
|
423
425
|
- app/views/layouts/_header_menu.html.haml
|
424
426
|
- app/views/shopapp/403.html.haml
|
427
|
+
- app/views/shopapp/_display_flag.haml
|
428
|
+
- app/views/shopapp/_modal_errors.haml
|
425
429
|
- app/views/shopapp/_shopapp.html.haml
|
426
430
|
- app/views/shopapp/_shopapp2.html.haml
|
427
431
|
- app/views/shopapp/_shopapp3.html.haml
|
428
432
|
- app/views/shopapp/_shopapp_alerts.html.haml
|
429
433
|
- app/views/shopapp/login_message.haml
|
434
|
+
- app/views/shopapp/modal_errors.js.erb
|
435
|
+
- app/views/shopapp/render_remote_response.js.erb
|
430
436
|
- bin/shop
|
431
437
|
- bin/shopitapp
|
432
438
|
- config/initializers/active_settings.rb
|