matestack-ui-core 1.2.0 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +27 -1
  3. data/app/concepts/matestack/ui/core/cable/cable.haml +1 -1
  4. data/app/concepts/matestack/ui/core/collection/helper.rb +7 -1
  5. data/app/concepts/matestack/ui/core/form/checkbox/base.rb +120 -0
  6. data/app/concepts/matestack/ui/core/form/checkbox/checkbox.js +15 -0
  7. data/app/concepts/matestack/ui/core/form/checkbox/checkbox.rb +7 -70
  8. data/app/concepts/matestack/ui/core/form/checkbox/mixin.js +80 -0
  9. data/app/concepts/matestack/ui/core/form/form.js +15 -46
  10. data/app/concepts/matestack/ui/core/form/input/base.rb +75 -0
  11. data/app/concepts/matestack/ui/core/form/input/input.js +15 -0
  12. data/app/concepts/matestack/ui/core/form/input/input.rb +8 -52
  13. data/app/concepts/matestack/ui/core/form/input/mixin.js +55 -0
  14. data/app/concepts/matestack/ui/core/form/radio/base.rb +90 -0
  15. data/app/concepts/matestack/ui/core/form/radio/mixin.js +62 -0
  16. data/app/concepts/matestack/ui/core/form/radio/radio.js +15 -0
  17. data/app/concepts/matestack/ui/core/form/radio/radio.rb +7 -62
  18. data/app/concepts/matestack/ui/core/form/select/base.rb +98 -0
  19. data/app/concepts/matestack/ui/core/form/select/mixin.js +58 -0
  20. data/app/concepts/matestack/ui/core/form/select/select.js +15 -0
  21. data/app/concepts/matestack/ui/core/form/select/select.rb +11 -60
  22. data/app/concepts/matestack/ui/core/form/submit/base.rb +12 -0
  23. data/app/concepts/matestack/ui/core/form/submit/submit.js +19 -0
  24. data/app/concepts/matestack/ui/core/form/submit/submit.rb +9 -6
  25. data/app/concepts/matestack/ui/core/form/textarea/base.rb +49 -0
  26. data/app/concepts/matestack/ui/core/form/textarea/mixin.js +41 -0
  27. data/app/concepts/matestack/ui/core/form/textarea/textarea.js +15 -0
  28. data/app/concepts/matestack/ui/core/form/textarea/textarea.rb +10 -21
  29. data/app/concepts/matestack/ui/core/js/core.js +11 -0
  30. data/app/concepts/matestack/ui/core/{form/submit/submit.haml → select/select.haml} +1 -1
  31. data/app/concepts/matestack/ui/core/select/select.rb +7 -0
  32. data/app/concepts/matestack/ui/core/view/view.rb +2 -2
  33. data/app/javascript/matestack-ui-core/index.js +12 -2
  34. data/lib/matestack/ui/core/components.rb +2 -0
  35. data/lib/matestack/ui/core/version.rb +1 -1
  36. data/vendor/assets/javascripts/dist/matestack-ui-core.js +611 -55
  37. data/vendor/assets/javascripts/dist/matestack-ui-core.js.map +1 -1
  38. data/vendor/assets/javascripts/dist/matestack-ui-core.min.js +1 -1
  39. data/vendor/assets/javascripts/dist/matestack-ui-core.min.js.LICENSE.txt +5 -12
  40. data/vendor/assets/javascripts/dist/matestack-ui-core.min.js.br +0 -0
  41. data/vendor/assets/javascripts/dist/matestack-ui-core.min.js.gz +0 -0
  42. data/vendor/assets/javascripts/dist/matestack-ui-core.min.js.map +1 -1
  43. data/vendor/assets/javascripts/dist/matestack-ui-core.min.js.map.br +0 -0
  44. data/vendor/assets/javascripts/dist/matestack-ui-core.min.js.map.gz +0 -0
  45. metadata +31 -16
  46. data/app/concepts/matestack/ui/core/form/select/select.haml +0 -9
@@ -0,0 +1,75 @@
1
+ require_relative '../utils'
2
+ require_relative '../has_input_html_attributes'
3
+ require_relative '../has_errors'
4
+ module Matestack::Ui::Core::Form::Input
5
+ class Base < Matestack::Ui::Core::Component::Dynamic
6
+ include Matestack::Ui::Core::Form::Utils
7
+ include Matestack::Ui::Core::Form::HasInputHtmlAttributes
8
+ include Matestack::Ui::Core::Form::HasErrors
9
+
10
+ requires :key, :type
11
+ optional :multiple, :init, for: { as: :input_for }, label: { as: :input_label }
12
+
13
+ def setup
14
+ @component_config[:init_value] = init_value
15
+ end
16
+
17
+ def component_id
18
+ "input-component-for-#{attr_key}"
19
+ end
20
+
21
+ def input_attributes
22
+ html_attributes.merge(attributes: vue_attributes)
23
+ end
24
+
25
+ def input_key
26
+ "$parent.data[\"#{key}\"]"
27
+ end
28
+
29
+ def error_key
30
+ "$parent.errors[\"#{key}\"]"
31
+ end
32
+
33
+ def change_event
34
+ "inputChanged('#{attr_key}'); #{ "filesAdded('#{attr_key}');" if type == :file }".strip
35
+ end
36
+
37
+ def vue_attributes
38
+ (options[:attributes] || {}).merge({
39
+ "@change": change_event,
40
+ ref: "input.#{attr_key}",
41
+ 'init-value': init_value,
42
+ 'v-bind:class': "{ '#{input_error_class}': #{error_key} }"
43
+ }).merge(
44
+ type != :file ? { "#{v_model_type}": input_key } : {}
45
+ ) # file inputs are readonly, no v-model possible
46
+ end
47
+
48
+ def v_model_type
49
+ if type == :number || init_value.is_a?(Integer)
50
+ 'v-model.number'
51
+ else
52
+ 'v-model'
53
+ end
54
+ end
55
+
56
+ def custom_options_validation
57
+ raise "included form config is missing, please add ':include' to parent form component" if @included_config.nil?
58
+ end
59
+
60
+ def attr_key
61
+ super + "#{'[]' if multiple && type == :file}"
62
+ end
63
+
64
+ private
65
+
66
+ def parse_value(value)
67
+ if [true, false].include? value
68
+ value ? 1 : 0
69
+ else
70
+ return value
71
+ end
72
+ end
73
+
74
+ end
75
+ end
@@ -0,0 +1,15 @@
1
+ import Vue from "vue/dist/vue.esm";
2
+
3
+ import formInputMixin from "./mixin";
4
+ import componentMixin from "../../component/component";
5
+
6
+ const componentDef = {
7
+ mixins: [componentMixin, formInputMixin],
8
+ data() {
9
+ return {};
10
+ }
11
+ }
12
+
13
+ let component = Vue.component("matestack-ui-core-form-input", componentDef);
14
+
15
+ export default componentDef;
@@ -1,59 +1,15 @@
1
- require_relative '../utils'
2
- require_relative '../has_input_html_attributes'
3
- require_relative '../has_errors'
1
+ require_relative './base'
2
+
4
3
  module Matestack::Ui::Core::Form::Input
5
- class Input < Matestack::Ui::Core::Component::Static
6
- include Matestack::Ui::Core::Form::Utils
7
- include Matestack::Ui::Core::Form::HasInputHtmlAttributes
8
- include Matestack::Ui::Core::Form::HasErrors
4
+ class Input < Base
9
5
 
10
- requires :key, :type
11
- optional :multiple, :init, for: { as: :input_for }, label: { as: :input_label }
6
+ vue_js_component_name "matestack-ui-core-form-input"
12
7
 
13
8
  def response
14
- label text: input_label if input_label
15
- input html_attributes.merge(attributes: vue_attributes)
16
- render_errors
17
- end
18
-
19
- def vue_attributes
20
- (options[:attributes] || {}).merge({
21
- "@change": change_event,
22
- ref: "input.#{attr_key}",
23
- 'init-value': init_value,
24
- 'v-bind:class': "{ '#{input_error_class}': #{error_key} }"
25
- }).merge(
26
- type != :file ? { "#{v_model_type}": input_key } : {}
27
- ) # file inputs are readonly, no v-model possible
28
- end
29
-
30
- def v_model_type
31
- if type == :number || init_value.is_a?(Integer)
32
- 'v-model.number'
33
- else
34
- 'v-model'
35
- end
36
- end
37
-
38
- def change_event
39
- "inputChanged('#{attr_key}'); #{ "filesAdded('#{attr_key}');" if type == :file }".strip
40
- end
41
-
42
- def custom_options_validation
43
- raise "included form config is missing, please add ':include' to parent form component" if @included_config.nil?
44
- end
45
-
46
- def attr_key
47
- super + "#{'[]' if multiple && type == :file}"
48
- end
49
-
50
- private
51
-
52
- def parse_value(value)
53
- if [true, false].include? value
54
- value ? 1 : 0
55
- else
56
- return value
9
+ div class: "matestack-ui-core-form-input" do
10
+ label text: input_label if input_label
11
+ input input_attributes
12
+ render_errors
57
13
  end
58
14
  end
59
15
 
@@ -0,0 +1,55 @@
1
+ const formInputMixin = {
2
+ methods: {
3
+ initialize: function(){
4
+ const self = this
5
+ let data = {};
6
+
7
+ for (let key in this.$refs) {
8
+ let initValue = this.$refs[key]["attributes"]["init-value"];
9
+
10
+ if (initValue) {
11
+ data[key.replace("input.", "")] = initValue["value"];
12
+ Object.assign(self.$parent.data, data);
13
+ self.afterInitialize(initValue["value"])
14
+ } else {
15
+ data[key.replace("input.", "")] = null;
16
+ Object.assign(self.$parent.data, data);
17
+ self.afterInitialize(null)
18
+ }
19
+ }
20
+
21
+ //without the timeout it's somehow not working
22
+ setTimeout(function () {
23
+ self.$forceUpdate()
24
+ }, 1);
25
+ },
26
+ filesAdded: function (key) {
27
+ const dataTransfer = event.dataTransfer || event.target;
28
+ const files = dataTransfer.files;
29
+ if (event.target.attributes.multiple) {
30
+ this.$parent.data[key] = [];
31
+ for (let index in files) {
32
+ if (files[index] instanceof File) {
33
+ this.$parent.data[key].push(files[index]);
34
+ }
35
+ }
36
+ } else {
37
+ this.$parent.data[key] = files[0];
38
+ }
39
+ },
40
+ inputChanged: function (key) {
41
+ this.$parent.resetErrors(key);
42
+ this.$forceUpdate();
43
+ },
44
+ afterInitialize: function(value){
45
+ // can be used in the main component for further initialization steps
46
+ },
47
+ setValue: function (value){
48
+ this.$parent.data[this.componentConfig["key"]] = value
49
+ this.$forceUpdate();
50
+ }
51
+ }
52
+
53
+ }
54
+
55
+ export default formInputMixin
@@ -0,0 +1,90 @@
1
+ require_relative '../utils'
2
+ require_relative '../has_input_html_attributes'
3
+ require_relative '../has_errors'
4
+ module Matestack::Ui::Core::Form::Radio
5
+ class Base < Matestack::Ui::Core::Component::Dynamic
6
+ include Matestack::Ui::Core::Form::Utils
7
+ include Matestack::Ui::Core::Form::HasInputHtmlAttributes
8
+ include Matestack::Ui::Core::Form::HasErrors
9
+
10
+ requires :key
11
+ optional :multiple, :init, for: { as: :input_for }, label: { as: :input_label }, options: { as: :radio_options }
12
+
13
+ def setup
14
+ @component_config[:init_value] = init_value
15
+ end
16
+
17
+ def component_id
18
+ "radio-component-for-#{attr_key}"
19
+ end
20
+
21
+ def input_key
22
+ "$parent.data[\"#{key}\"]"
23
+ end
24
+
25
+ def error_key
26
+ "$parent.errors[\"#{key}\"]"
27
+ end
28
+
29
+ def change_event
30
+ "inputChanged('#{attr_key}')"
31
+ end
32
+
33
+ def render_options
34
+ radio_options.to_a.each do |item|
35
+ input radio_attributes(item)
36
+ label text: item_label(item), for: id_for_item(item_value(item))
37
+ end
38
+ end
39
+
40
+ def radio_attributes(item)
41
+ html_attributes.merge(
42
+ attributes: vue_attributes,
43
+ type: :radio,
44
+ id: "#{id_for_item(item_value(item))}",
45
+ name: item_name(item),
46
+ value: item_value(item),
47
+ )
48
+ end
49
+
50
+ def vue_attributes
51
+ (options[:attributes] || {}).merge({
52
+ "@change": change_event,
53
+ ref: "select.#{attr_key}",
54
+ 'init-value': init_value,
55
+ 'v-bind:class': "{ '#{input_error_class}': #{error_key} }",
56
+ 'value-type': value_type,
57
+ "#{v_model_type}": input_key,
58
+ })
59
+ end
60
+
61
+ def value_type
62
+ item_value(radio_options.first).is_a?(Integer) ? Integer : nil
63
+ end
64
+
65
+ def item_value(item)
66
+ item.is_a?(Array) ? item.last : item
67
+ end
68
+
69
+ def item_name(item)
70
+ "#{attr_key}_#{item.is_a?(Array) ? item.first : item}"
71
+ end
72
+
73
+ def item_label(item)
74
+ item.is_a?(Array) ? item.first : item
75
+ end
76
+
77
+ def v_model_type
78
+ if radio_options && item_value(radio_options.first).is_a?(Integer)
79
+ 'v-model.number'
80
+ else
81
+ 'v-model'
82
+ end
83
+ end
84
+
85
+ def id_for_item(value)
86
+ "#{html_attributes[:id] || attr_key}_#{value}"
87
+ end
88
+
89
+ end
90
+ end
@@ -0,0 +1,62 @@
1
+ const formRadioMixin = {
2
+ methods: {
3
+ initialize: function(){
4
+ const self = this
5
+ let data = {};
6
+
7
+ for (let key in self.$refs) {
8
+ let initValue = self.$refs[key]["attributes"]["init-value"];
9
+ let valueType = self.$refs[key]["attributes"]["value-type"];
10
+
11
+ if (key.startsWith("select.")) {
12
+ if (key.startsWith("select.multiple.")) {
13
+ if (initValue) {
14
+ data[key.replace("select.multiple.", "")] = JSON.parse(initValue["value"]);
15
+ Object.assign(self.$parent.data, data);
16
+ self.afterInitialize(JSON.parse(initValue["value"]))
17
+ } else {
18
+ data[key.replace("select.multiple.", "")] = [];
19
+ Object.assign(self.$parent.data, data);
20
+ self.afterInitialize([])
21
+ }
22
+ } else {
23
+ if (initValue) {
24
+ if (valueType && valueType["value"] == "Integer") {
25
+ data[key.replace("select.", "")] = parseInt(initValue["value"]);
26
+ Object.assign(self.$parent.data, data);
27
+ self.afterInitialize(parseInt(initValue["value"]))
28
+ } else {
29
+ data[key.replace("select.", "")] = initValue["value"];
30
+ Object.assign(self.$parent.data, data);
31
+ self.afterInitialize(initValue["value"])
32
+ }
33
+ } else {
34
+ data[key.replace("select.", "")] = null;
35
+ Object.assign(self.$parent.data, data);
36
+ self.afterInitialize(null)
37
+ }
38
+ }
39
+ }
40
+ }
41
+
42
+ //without the timeout it's somehow not working
43
+ setTimeout(function () {
44
+ self.$forceUpdate();
45
+ }, 1);
46
+ },
47
+ inputChanged: function (key) {
48
+ this.$parent.resetErrors(key);
49
+ this.$forceUpdate();
50
+ },
51
+ afterInitialize: function(value){
52
+ // can be used in the main component for further initialization steps
53
+ },
54
+ setValue: function (value){
55
+ this.$parent.data[this.componentConfig["key"]] = value
56
+ this.$forceUpdate();
57
+ }
58
+ }
59
+
60
+ }
61
+
62
+ export default formRadioMixin
@@ -0,0 +1,15 @@
1
+ import Vue from "vue/dist/vue.esm";
2
+
3
+ import formRadioMixin from "./mixin";
4
+ import componentMixin from "../../component/component";
5
+
6
+ const componentDef = {
7
+ mixins: [componentMixin, formRadioMixin],
8
+ data() {
9
+ return {};
10
+ }
11
+ }
12
+
13
+ let component = Vue.component("matestack-ui-core-form-radio", componentDef);
14
+
15
+ export default componentDef;
@@ -1,71 +1,16 @@
1
- require_relative '../utils'
2
- require_relative '../has_input_html_attributes'
3
- require_relative '../has_errors'
1
+ require_relative './base'
2
+
4
3
  module Matestack::Ui::Core::Form::Radio
5
- class Radio < Matestack::Ui::Core::Component::Static
6
- include Matestack::Ui::Core::Form::Utils
7
- include Matestack::Ui::Core::Form::HasInputHtmlAttributes
8
- include Matestack::Ui::Core::Form::HasErrors
4
+ class Radio < Base
9
5
 
10
- requires :key
11
- optional :multiple, :init, for: { as: :input_for }, label: { as: :input_label }, options: { as: :radio_options }
6
+ vue_js_component_name "matestack-ui-core-form-radio"
12
7
 
13
8
  def response
14
- radio_options.to_a.each do |item|
15
- input html_attributes.merge(
16
- attributes: vue_attributes,
17
- type: :radio,
18
- id: "#{id_for_item(item_value(item))}",
19
- name: item_name(item),
20
- value: item_value(item),
21
- )
22
- label text: item_label(item), for: id_for_item(item_value(item))
23
- end
24
- render_errors
25
- end
26
-
27
- def vue_attributes
28
- (options[:attributes] || {}).merge({
29
- "@change": change_event,
30
- ref: "select.#{attr_key}",
31
- 'init-value': init_value,
32
- 'v-bind:class': "{ '#{input_error_class}': #{error_key} }",
33
- 'value-type': value_type,
34
- "#{v_model_type}": input_key,
35
- })
36
- end
37
-
38
- def value_type
39
- item_value(radio_options.first).is_a?(Integer) ? Integer : nil
40
- end
41
-
42
- def item_value(item)
43
- item.is_a?(Array) ? item.last : item
44
- end
45
-
46
- def item_name(item)
47
- "#{attr_key}_#{item.is_a?(Array) ? item.first : item}"
48
- end
49
-
50
- def item_label(item)
51
- item.is_a?(Array) ? item.first : item
52
- end
53
-
54
- def v_model_type
55
- if radio_options && item_value(radio_options.first).is_a?(Integer)
56
- 'v-model.number'
57
- else
58
- 'v-model'
9
+ div class: "matestack-ui-core-form-radio" do
10
+ render_options
11
+ render_errors
59
12
  end
60
13
  end
61
14
 
62
- def change_event
63
- "inputChanged('#{attr_key}')"
64
- end
65
-
66
- def id_for_item(value)
67
- "#{html_attributes[:id] || attr_key}_#{value}"
68
- end
69
-
70
15
  end
71
16
  end