basemate-ui-core 0.5.1 → 0.6.0.pre.1

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
  SHA256:
3
- metadata.gz: 7d703c2c29c9c5a23e01ca806b1e878187bfeea98f6322c298178bdc52528c95
4
- data.tar.gz: ec7e15c93e97e703f3a61d4a2255909edbbf18d58cbca97facf031aee681d959
3
+ metadata.gz: 443aa974568221356740ed44ad37a7e91e650f4271e4ab18027e202f381e2bdf
4
+ data.tar.gz: 8b00a348e1e3203f926a91447b0402a813c49cd2bfe32a1dc58f389d7a0aa5cd
5
5
  SHA512:
6
- metadata.gz: 879e8616eb7fd1bcbb58e4ca84839b0c6d021e0a5ce07577eb8cf644570f86b5878073e95e41ec37427882c123514c1bc213adecf022e73b9a41fb96b8f577d7
7
- data.tar.gz: f7e1ec7734a2d35b2772c77ddb3e8a1651c9dcce80a5e1bf3e13297a2430346140b7bd283bbf2234297a25969dda8750eeb97d51ca7949a42934cc857cf7a6ab
6
+ metadata.gz: 7bfa85451abd984134064b7046aee02e13dbbb0cf202bfcdad0e2214a2bd647ab51abc43283cd5ddeb2433cadaa5c889e4e97dd7e0100d16215ace169b50bcba
7
+ data.tar.gz: fa107b2572b1b526c67ce97bf384fee4b274da810dd5d351c2b75483174b1d6b3bc5cf6027469567425a678f5e2852200a550a7a24a2ef34223d8ef2632979bf
data/README.md CHANGED
@@ -41,7 +41,7 @@ Execute them with:
41
41
 
42
42
  ```shell
43
43
 
44
- bundle exec rspec
44
+ bundle exec rspec spec/concepts
45
45
 
46
46
  ```
47
47
 
@@ -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
 
@@ -19,6 +19,7 @@ const store = new Vuex.Store({
19
19
  },
20
20
  actions: {
21
21
  navigateTo ({ commit, state }, { url, backwards }) {
22
+ console.log("navigate")
22
23
  if (typeof basemateUiCoreTransitionStart !== 'undefined') {
23
24
  basemateUiCoreTransitionStart(url);
24
25
  }
@@ -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
@@ -0,0 +1,5 @@
1
+ module Footer::Cell
2
+ class Footer < Component::Cell::Static
3
+
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ %footer{@tag_attributes}
2
+ - if block_given?
3
+ = yield
@@ -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
- @component_config[:submit_path] = submit_path
6
- @component_config[:method] = options[:method]
7
- @component_config[:success] = options[:success]
8
- if options[:notify].nil?
9
- @component_config[:notify] = true
10
- end
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
- @tag_attributes.merge!({"@submit.prevent": true})
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
- return ::Rails.application.routes.url_helpers.send(options[:path], options[:params])
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
- "path_not_found"
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
 
@@ -1,9 +1,9 @@
1
- module Input::Cell
1
+ module Form::Cell
2
2
  class Inline < Component::Cell::Static
3
3
 
4
-
5
4
  def input_key
6
5
  'data["' + options[:key].to_s + '"]'
7
6
  end
7
+
8
8
  end
9
9
  end
@@ -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
@@ -1,4 +1,4 @@
1
- module Submit::Cell
1
+ module Form::Cell
2
2
  class Submit < Component::Cell::Static
3
3
 
4
4
  def setup
@@ -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
- basemateEventHub.$emit(self.componentConfig["success"][key], key);
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
 
@@ -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 }}