basemate-ui-core 0.5.1 → 0.6.0.pre.1
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/concepts/app/cell/app.rb +1 -1
- data/app/concepts/app/js/store.js +1 -0
- data/app/concepts/component/cell/dynamic.rb +19 -4
- data/app/concepts/component/utils/component_node.rb +16 -4
- data/app/concepts/footer/cell/footer.rb +5 -0
- data/app/concepts/footer/view/footer.haml +3 -0
- data/app/concepts/form/cell/form.rb +53 -9
- data/app/concepts/{input → form}/cell/inline.rb +2 -2
- data/app/concepts/form/cell/input.rb +42 -0
- data/app/concepts/form/cell/select.rb +48 -0
- data/app/concepts/{submit → form}/cell/submit.rb +1 -1
- data/app/concepts/form/js/form.js +58 -2
- data/app/concepts/{input → form}/view/inline.haml +0 -0
- data/app/concepts/form/view/input.haml +29 -0
- data/app/concepts/form/view/select.haml +68 -0
- data/app/concepts/{submit → form}/view/submit.haml +0 -0
- data/app/concepts/page/cell/page.rb +8 -5
- data/app/concepts/page/utils/page_node.rb +20 -5
- data/app/concepts/page/view/content.haml +5 -6
- data/app/concepts/partial/view/partial.haml +2 -2
- data/app/concepts/progress/cell/progress.rb +5 -0
- data/app/concepts/progress/view/progress.haml +3 -0
- data/app/concepts/shared/utils/to_cell.rb +19 -5
- data/lib/basemate/ui/core/version.rb +1 -1
- data/vendor/assets/javascripts/basemate-ui-core.js +56 -2
- data/vendor/assets/javascripts/basemate-ui-core.js.map +1 -1
- metadata +16 -10
- data/app/concepts/input/cell/input.rb +0 -9
- data/app/concepts/input/view/input.haml +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 443aa974568221356740ed44ad37a7e91e650f4271e4ab18027e202f381e2bdf
|
4
|
+
data.tar.gz: 8b00a348e1e3203f926a91447b0402a813c49cd2bfe32a1dc58f389d7a0aa5cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7bfa85451abd984134064b7046aee02e13dbbb0cf202bfcdad0e2214a2bd647ab51abc43283cd5ddeb2433cadaa5c889e4e97dd7e0100d16215ace169b50bcba
|
7
|
+
data.tar.gz: fa107b2572b1b526c67ce97bf384fee4b274da810dd5d351c2b75483174b1d6b3bc5cf6027469567425a678f5e2852200a550a7a24a2ef34223d8ef2632979bf
|
data/README.md
CHANGED
@@ -64,7 +64,7 @@ module App::Cell
|
|
64
64
|
@nodes = ::App::Utils::AppNode.build(self, &block)
|
65
65
|
|
66
66
|
@nodes.each do |key, node|
|
67
|
-
@cells[key] = to_cell(key, node["component_name"], node["config"], node["argument"], node["components"])
|
67
|
+
@cells[key] = to_cell(key, node["component_name"], node["config"], node["argument"], node["components"], nil)
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
@@ -44,12 +44,27 @@ module Component::Cell
|
|
44
44
|
@static = false
|
45
45
|
@nodes = {}
|
46
46
|
@cells = {}
|
47
|
+
@included_config = options[:included_config]
|
47
48
|
generate_component_name
|
48
49
|
generate_children_cells
|
49
50
|
set_tag_attributes
|
51
|
+
validate_options
|
50
52
|
setup
|
51
53
|
end
|
52
54
|
|
55
|
+
def validate_options
|
56
|
+
if defined? self.class::REQUIRED_KEYS
|
57
|
+
self.class::REQUIRED_KEYS.each do |key|
|
58
|
+
raise "required key '#{key}' is missing" if options[key].nil?
|
59
|
+
end
|
60
|
+
end
|
61
|
+
custom_options_validation
|
62
|
+
end
|
63
|
+
|
64
|
+
def custom_options_validation
|
65
|
+
true
|
66
|
+
end
|
67
|
+
|
53
68
|
def setup
|
54
69
|
true
|
55
70
|
end
|
@@ -107,15 +122,15 @@ module Component::Cell
|
|
107
122
|
end
|
108
123
|
|
109
124
|
def components(&block)
|
110
|
-
@nodes = ::Component::Utils::ComponentNode.build(self, &block)
|
125
|
+
@nodes = ::Component::Utils::ComponentNode.build(self, nil, &block)
|
111
126
|
|
112
127
|
@nodes.each do |key, node|
|
113
|
-
@cells[key] = to_cell(key, node["component_name"], node["config"], node["argument"], node["components"])
|
128
|
+
@cells[key] = to_cell(key, node["component_name"], node["config"], node["argument"], node["components"], node["included_config"])
|
114
129
|
end
|
115
130
|
end
|
116
131
|
|
117
132
|
def partial(&block)
|
118
|
-
::Component::Utils::ComponentNode.build(self, &block)
|
133
|
+
::Component::Utils::ComponentNode.build(self, nil, &block)
|
119
134
|
end
|
120
135
|
|
121
136
|
private
|
@@ -123,7 +138,7 @@ module Component::Cell
|
|
123
138
|
def generate_children_cells
|
124
139
|
unless options[:children].nil?
|
125
140
|
options[:children].each do |key, node|
|
126
|
-
@children_cells[key] = to_cell("#{@component_key}__#{key}", node["component_name"], node["config"], node["argument"], node["components"])
|
141
|
+
@children_cells[key] = to_cell("#{@component_key}__#{key}", node["component_name"], node["config"], node["argument"], node["components"], node["included_config"])
|
127
142
|
end
|
128
143
|
end
|
129
144
|
end
|
@@ -1,18 +1,19 @@
|
|
1
1
|
module Component::Utils
|
2
2
|
class ComponentNode
|
3
3
|
|
4
|
-
def self.build(component_instance, &block)
|
5
|
-
node = ComponentNode.new(component_instance)
|
4
|
+
def self.build(component_instance, included_config, &block)
|
5
|
+
node = ComponentNode.new(component_instance, included_config)
|
6
6
|
node.instance_eval(&block)
|
7
7
|
node.hash
|
8
8
|
end
|
9
9
|
|
10
10
|
attr_reader :hash
|
11
11
|
|
12
|
-
def initialize(component_instance)
|
12
|
+
def initialize(component_instance, included_config)
|
13
13
|
@hash = {}
|
14
14
|
@node_start_id = 0
|
15
15
|
@component_instance = component_instance
|
16
|
+
@included_config = included_config
|
16
17
|
component_instance.instance_variables.each do |component_instance_var_key|
|
17
18
|
self.instance_variable_set(component_instance_var_key, component_instance.instance_variable_get(component_instance_var_key))
|
18
19
|
end
|
@@ -29,6 +30,7 @@ module Component::Utils
|
|
29
30
|
@hash[current_node]["component_name"] = meth.to_s
|
30
31
|
@hash[current_node]["config"] = {}
|
31
32
|
@hash[current_node]["argument"] = nil
|
33
|
+
@hash[current_node]["included_config"] = @included_config
|
32
34
|
|
33
35
|
if meth == :partial
|
34
36
|
@hash[current_node]["components"] = @component_instance.send(args.first, *args.drop(1))
|
@@ -39,8 +41,18 @@ module Component::Utils
|
|
39
41
|
@hash[current_node]["argument"] = args.first
|
40
42
|
end
|
41
43
|
|
44
|
+
if args.second == :include
|
45
|
+
included = args.first
|
46
|
+
else
|
47
|
+
unless @included_config .nil?
|
48
|
+
included = @included_config
|
49
|
+
else
|
50
|
+
included = nil
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
42
54
|
if block_given?
|
43
|
-
@hash[current_node]["components"] = ComponentNode.build(@component_instance, &block)
|
55
|
+
@hash[current_node]["components"] = ComponentNode.build(@component_instance, included, &block)
|
44
56
|
end
|
45
57
|
end
|
46
58
|
end
|
@@ -1,22 +1,66 @@
|
|
1
1
|
module Form::Cell
|
2
2
|
class Form < Component::Cell::Dynamic
|
3
3
|
|
4
|
+
REQUIRED_KEYS = [:for, :path, :method]
|
5
|
+
|
4
6
|
def setup
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
@component_config[:
|
10
|
-
|
7
|
+
begin
|
8
|
+
@component_config[:for] = form_wrapper
|
9
|
+
@component_config[:submit_path] = submit_path
|
10
|
+
@component_config[:method] = options[:method]
|
11
|
+
@component_config[:success] = options[:success]
|
12
|
+
unless options[:success].nil?
|
13
|
+
unless options[:success][:transition].nil?
|
14
|
+
@component_config[:success][:transition][:path] = transition_path
|
15
|
+
end
|
16
|
+
end
|
17
|
+
if options[:notify].nil?
|
18
|
+
@component_config[:notify] = true
|
19
|
+
end
|
11
20
|
|
12
|
-
|
21
|
+
@tag_attributes.merge!({"@submit.prevent": true})
|
22
|
+
rescue => e
|
23
|
+
raise "Form component could not be setted up. Reason: #{e}"
|
24
|
+
end
|
13
25
|
end
|
14
26
|
|
15
27
|
def submit_path
|
16
28
|
begin
|
17
|
-
|
29
|
+
if options[:path].is_a?(Symbol)
|
30
|
+
return ::Rails.application.routes.url_helpers.send(options[:path], options[:params])
|
31
|
+
else
|
32
|
+
return options[:path]
|
33
|
+
end
|
34
|
+
rescue
|
35
|
+
raise "Submit path not found"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def transition_path
|
40
|
+
begin
|
41
|
+
if options[:success][:transition][:path].is_a?(Symbol)
|
42
|
+
return ::Rails.application.routes.url_helpers.send(
|
43
|
+
options[:success][:transition][:path],
|
44
|
+
options[:success][:transition][:params]
|
45
|
+
)
|
46
|
+
else
|
47
|
+
return options[:success][:transition][:path]
|
48
|
+
end
|
18
49
|
rescue
|
19
|
-
"
|
50
|
+
raise "Transition path not found"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def form_wrapper
|
55
|
+
case options[:for]
|
56
|
+
when Symbol
|
57
|
+
return options[:for]
|
58
|
+
when String
|
59
|
+
return options[:for]
|
60
|
+
end
|
61
|
+
|
62
|
+
if options[:for].respond_to?(:model_name)
|
63
|
+
return options[:for].model_name.singular
|
20
64
|
end
|
21
65
|
end
|
22
66
|
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Form::Cell
|
2
|
+
class Input < Component::Cell::Static
|
3
|
+
|
4
|
+
REQUIRED_KEYS = [:key, :type]
|
5
|
+
|
6
|
+
def custom_options_validation
|
7
|
+
raise "included form config is missing, please add ':include' to parent form component" if @included_config.nil?
|
8
|
+
end
|
9
|
+
|
10
|
+
def input_key
|
11
|
+
'data["' + options[:key].to_s + '"]'
|
12
|
+
end
|
13
|
+
|
14
|
+
def error_key
|
15
|
+
'errors["' + options[:key].to_s + '"]'
|
16
|
+
end
|
17
|
+
|
18
|
+
def attr_key
|
19
|
+
options[:key].to_s
|
20
|
+
end
|
21
|
+
|
22
|
+
def init_value
|
23
|
+
unless options[:init].nil?
|
24
|
+
return options[:init]
|
25
|
+
end
|
26
|
+
|
27
|
+
unless @included_config.nil? && @included_config[:for].nil?
|
28
|
+
if @included_config[:for].respond_to?(options[:key])
|
29
|
+
return @included_config[:for].send(options[:key])
|
30
|
+
else
|
31
|
+
if @included_config[:for].is_a?(Symbol) || @included_config[:for].is_a?(String)
|
32
|
+
return nil
|
33
|
+
end
|
34
|
+
if @included_config[:for].is_a?(Hash)
|
35
|
+
return @included_config[:for][options[:key]]
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module Form::Cell
|
2
|
+
class Select < Component::Cell::Static
|
3
|
+
|
4
|
+
def input_key
|
5
|
+
'data["' + options[:key].to_s + '"]'
|
6
|
+
end
|
7
|
+
|
8
|
+
def error_key
|
9
|
+
'errors["' + options[:key].to_s + '"]'
|
10
|
+
end
|
11
|
+
|
12
|
+
def attr_key
|
13
|
+
options[:key].to_s
|
14
|
+
end
|
15
|
+
|
16
|
+
def option_values
|
17
|
+
values = options[:options] if options[:options].is_a?(Array)
|
18
|
+
values = options[:options].values if options[:options].is_a?(Hash)
|
19
|
+
return values
|
20
|
+
end
|
21
|
+
|
22
|
+
def options_type
|
23
|
+
return Integer if option_values.first.is_a?(Integer)
|
24
|
+
return String if option_values.first.is_a?(String)
|
25
|
+
end
|
26
|
+
|
27
|
+
def model_binding
|
28
|
+
|
29
|
+
if option_values.first.is_a?(Integer)
|
30
|
+
return "v-model.number"
|
31
|
+
else
|
32
|
+
return "v-model"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def init_value
|
37
|
+
unless options[:init].nil?
|
38
|
+
return options[:init]
|
39
|
+
end
|
40
|
+
|
41
|
+
unless @included_config.nil? && @included_config[:for].nil?
|
42
|
+
return @included_config[:for].send(options[:key])
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
@@ -11,10 +11,22 @@ const componentDef = {
|
|
11
11
|
data: function(){
|
12
12
|
return {
|
13
13
|
data: {},
|
14
|
-
showInlineForm: false
|
14
|
+
showInlineForm: false,
|
15
|
+
errors: {}
|
15
16
|
}
|
16
17
|
},
|
17
18
|
methods: {
|
19
|
+
initDataKey: function(key, initValue){
|
20
|
+
this.data[key] = initValue;
|
21
|
+
},
|
22
|
+
inputChanged: function(key){
|
23
|
+
this.resetErrors(key)
|
24
|
+
},
|
25
|
+
resetErrors: function(key){
|
26
|
+
if (this.errors[key]){
|
27
|
+
this.errors[key] = null;
|
28
|
+
}
|
29
|
+
},
|
18
30
|
launchInlineForm: function(key, value){
|
19
31
|
this.showInlineForm = true;
|
20
32
|
this.data[key] = value;
|
@@ -50,7 +62,14 @@ const componentDef = {
|
|
50
62
|
})
|
51
63
|
.then(function(response){
|
52
64
|
for (let key in self.componentConfig["success"]) {
|
53
|
-
|
65
|
+
switch(key){
|
66
|
+
case "transition":
|
67
|
+
let path = self.componentConfig["success"]["transition"]["path"]
|
68
|
+
self.$store.dispatch('navigateTo', {url: path, backwards: false})
|
69
|
+
break;
|
70
|
+
default:
|
71
|
+
basemateEventHub.$emit(self.componentConfig["success"][key], key);
|
72
|
+
}
|
54
73
|
}
|
55
74
|
if (self.componentConfig["notify"] === true) {
|
56
75
|
if (typeof basemateUiCoreActionSuccess !== 'undefined') {
|
@@ -61,6 +80,9 @@ const componentDef = {
|
|
61
80
|
self.showInlineForm = false;
|
62
81
|
})
|
63
82
|
.catch(function(error){
|
83
|
+
if(error.response && error.response.data && error.response.data.errors){
|
84
|
+
self.errors = error.response.data.errors;
|
85
|
+
}
|
64
86
|
if (self.componentConfig["notify"] === true) {
|
65
87
|
if (typeof basemateUiCoreActionError !== 'undefined') {
|
66
88
|
basemateUiCoreActionError(error);
|
@@ -68,6 +90,40 @@ const componentDef = {
|
|
68
90
|
}
|
69
91
|
})
|
70
92
|
}
|
93
|
+
},
|
94
|
+
mounted: function(){
|
95
|
+
let self = this;
|
96
|
+
let data = {}
|
97
|
+
for (let key in self.$refs) {
|
98
|
+
if (key.startsWith("input.")){
|
99
|
+
if(self.$refs[key]["attributes"]["init-value"]){
|
100
|
+
data[key.replace('input.', '')] = self.$refs[key]["attributes"]["init-value"]["value"]
|
101
|
+
}else{
|
102
|
+
data[key.replace('input.', '')] = null
|
103
|
+
}
|
104
|
+
}
|
105
|
+
if (key.startsWith("select.")){
|
106
|
+
if (key.startsWith("select.multiple.")){
|
107
|
+
if(self.$refs[key]["attributes"]["init-value"]){
|
108
|
+
data[key.replace('select.multiple.', '')] = JSON.parse(self.$refs[key]["attributes"]["init-value"]["value"])
|
109
|
+
}else{
|
110
|
+
data[key.replace('select.multiple.', '')] = []
|
111
|
+
}
|
112
|
+
}else{
|
113
|
+
if(self.$refs[key]["attributes"]["init-value"]){
|
114
|
+
if(self.$refs[key]["attributes"]["value-type"]["value"] == "Integer")
|
115
|
+
data[key.replace('select.', '')] = parseInt(self.$refs[key]["attributes"]["init-value"]["value"])
|
116
|
+
else{
|
117
|
+
data[key.replace('select.', '')] = self.$refs[key]["attributes"]["init-value"]["value"]
|
118
|
+
}
|
119
|
+
}else{
|
120
|
+
data[key.replace('select.', '')] = null
|
121
|
+
}
|
122
|
+
}
|
123
|
+
|
124
|
+
}
|
125
|
+
}
|
126
|
+
self.data = data;
|
71
127
|
}
|
72
128
|
}
|
73
129
|
|
File without changes
|
@@ -0,0 +1,29 @@
|
|
1
|
+
- if options[:label]
|
2
|
+
%label=options[:label]
|
3
|
+
|
4
|
+
- if [:text, :number, :date, :password].include?(options[:type])
|
5
|
+
%input{"v-model#{'.number' if options[:type] == :number}": input_key,
|
6
|
+
type: options[:type],
|
7
|
+
class: options[:class],
|
8
|
+
id: component_id,
|
9
|
+
"@change": "inputChanged(\"#{attr_key}\")",
|
10
|
+
ref: "input.#{attr_key}",
|
11
|
+
placeholder: options[:placeholder],
|
12
|
+
"init-value": init_value}
|
13
|
+
%span{"v-if": error_key }
|
14
|
+
%span{"v-for": "error in #{error_key}"}
|
15
|
+
{{ error }}
|
16
|
+
|
17
|
+
- if options[:type] == :textarea
|
18
|
+
%textarea{"v-model": input_key,
|
19
|
+
class: options[:class],
|
20
|
+
id: component_id,
|
21
|
+
"@change": "inputChanged(\"#{attr_key}\")",
|
22
|
+
ref: "input.#{attr_key}",
|
23
|
+
placeholder: options[:placeholder],
|
24
|
+
"init-value": init_value,
|
25
|
+
rows: options[:rows],
|
26
|
+
cols: options[:cols]}
|
27
|
+
%span{"v-if": error_key }
|
28
|
+
%span{"v-for": "error in #{error_key}"}
|
29
|
+
{{ error }}
|