matestack-ui-core 1.0.1 → 1.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +782 -16
  3. data/app/concepts/matestack/ui/core/async/async.js +6 -28
  4. data/app/concepts/matestack/ui/core/async/async.rb +7 -10
  5. data/app/concepts/matestack/ui/core/cable/cable.haml +4 -0
  6. data/app/concepts/matestack/ui/core/cable/cable.js +100 -0
  7. data/app/concepts/matestack/ui/core/cable/cable.rb +28 -0
  8. data/app/concepts/matestack/ui/core/cable/children_wrapper.haml +2 -0
  9. data/app/concepts/matestack/ui/core/collection/content/content.js +2 -2
  10. data/app/concepts/matestack/ui/core/collection/content/content.rb +1 -1
  11. data/app/concepts/matestack/ui/core/component/base.rb +10 -4
  12. data/app/concepts/matestack/ui/core/component/component.js +18 -1
  13. data/app/concepts/matestack/ui/core/component/dynamic.rb +1 -1
  14. data/app/concepts/matestack/ui/core/form/checkbox/base.rb +120 -0
  15. data/app/concepts/matestack/ui/core/form/checkbox/checkbox.js +15 -0
  16. data/app/concepts/matestack/ui/core/form/checkbox/checkbox.rb +7 -70
  17. data/app/concepts/matestack/ui/core/form/checkbox/mixin.js +80 -0
  18. data/app/concepts/matestack/ui/core/form/form.js +15 -46
  19. data/app/concepts/matestack/ui/core/form/input/base.rb +75 -0
  20. data/app/concepts/matestack/ui/core/form/input/input.js +15 -0
  21. data/app/concepts/matestack/ui/core/form/input/input.rb +8 -52
  22. data/app/concepts/matestack/ui/core/form/input/mixin.js +55 -0
  23. data/app/concepts/matestack/ui/core/form/radio/base.rb +90 -0
  24. data/app/concepts/matestack/ui/core/form/radio/mixin.js +62 -0
  25. data/app/concepts/matestack/ui/core/form/radio/radio.js +15 -0
  26. data/app/concepts/matestack/ui/core/form/radio/radio.rb +7 -62
  27. data/app/concepts/matestack/ui/core/form/select/base.rb +98 -0
  28. data/app/concepts/matestack/ui/core/form/select/mixin.js +58 -0
  29. data/app/concepts/matestack/ui/core/form/select/select.js +15 -0
  30. data/app/concepts/matestack/ui/core/form/select/select.rb +11 -60
  31. data/app/concepts/matestack/ui/core/form/submit/base.rb +12 -0
  32. data/app/concepts/matestack/ui/core/form/submit/submit.js +19 -0
  33. data/app/concepts/matestack/ui/core/form/submit/submit.rb +9 -6
  34. data/app/concepts/matestack/ui/core/form/textarea/base.rb +49 -0
  35. data/app/concepts/matestack/ui/core/form/textarea/mixin.js +41 -0
  36. data/app/concepts/matestack/ui/core/form/textarea/textarea.js +15 -0
  37. data/app/concepts/matestack/ui/core/form/textarea/textarea.rb +10 -21
  38. data/app/concepts/matestack/ui/core/js/core.js +12 -0
  39. data/app/concepts/matestack/ui/core/{form/submit/submit.haml → select/select.haml} +1 -1
  40. data/app/concepts/matestack/ui/core/select/select.rb +7 -0
  41. data/app/helpers/matestack/ui/core/application_helper.rb +6 -3
  42. data/app/javascript/matestack-ui-core/index.js +12 -2
  43. data/app/lib/matestack/ui/core/has_view_context.rb +4 -2
  44. data/app/lib/matestack/ui/core/rendering/main_renderer.rb +4 -1
  45. data/lib/matestack/ui/core/components.rb +4 -1
  46. data/lib/matestack/ui/core/version.rb +1 -1
  47. data/vendor/assets/javascripts/dist/matestack-ui-core.js +768 -98
  48. data/vendor/assets/javascripts/dist/matestack-ui-core.js.map +1 -1
  49. data/vendor/assets/javascripts/dist/matestack-ui-core.min.js +1 -1
  50. data/vendor/assets/javascripts/dist/matestack-ui-core.min.js.br +0 -0
  51. data/vendor/assets/javascripts/dist/matestack-ui-core.min.js.gz +0 -0
  52. data/vendor/assets/javascripts/dist/matestack-ui-core.min.js.map +1 -1
  53. data/vendor/assets/javascripts/dist/matestack-ui-core.min.js.map.br +0 -0
  54. data/vendor/assets/javascripts/dist/matestack-ui-core.min.js.map.gz +0 -0
  55. metadata +25 -7
  56. data/app/concepts/matestack/ui/core/component/rerender.rb +0 -8
  57. data/app/concepts/matestack/ui/core/form/select/select.haml +0 -9
@@ -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
@@ -0,0 +1,98 @@
1
+ require_relative '../utils'
2
+ require_relative '../has_errors'
3
+ module Matestack::Ui::Core::Form::Select
4
+ class Base < Matestack::Ui::Core::Component::Dynamic
5
+ include Matestack::Ui::Core::Form::Utils
6
+ include Matestack::Ui::Core::Form::HasErrors
7
+
8
+ html_attributes :autofocus, :disabled, :form, :multiple, :name, :required, :size
9
+
10
+ requires :key
11
+ optional :multiple, :init, :placeholder, :disabled_values,
12
+ for: { as: :input_for },
13
+ label: { as: :input_label },
14
+ options: { as: :select_options }
15
+
16
+ def setup
17
+ @component_config[:init_value] = init_value
18
+ end
19
+
20
+
21
+ def component_id
22
+ "select-component-for-#{attr_key}"
23
+ end
24
+
25
+ def select_attributes
26
+ html_attributes.merge(attributes: vue_attributes)
27
+ end
28
+
29
+ def render_options
30
+ if placeholder
31
+ option value: 'null', disabled: true, selected: init_value.nil?, text: placeholder
32
+ end
33
+ select_options.to_a.each do |item|
34
+ option value: item_value(item), disabled: item_disabled(item), text: item_label(item)
35
+ end
36
+ end
37
+
38
+ def input_key
39
+ "$parent.data[\"#{key}\"]"
40
+ end
41
+
42
+ def error_key
43
+ "$parent.errors[\"#{key}\"]"
44
+ end
45
+
46
+ def change_event
47
+ "inputChanged('#{attr_key}')"
48
+ end
49
+
50
+ def vue_attributes
51
+ (options[:attributes] || {}).merge({
52
+ "@change": change_event,
53
+ ref: vue_ref,
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 vue_ref
62
+ "select#{'.multiple' if multiple}.#{attr_key}"
63
+ end
64
+
65
+ def value_type
66
+ item_value(select_options.first).is_a?(Integer) ? Integer : nil
67
+ end
68
+
69
+ def item_value(item)
70
+ item.is_a?(Array) ? item.last : item
71
+ end
72
+
73
+ def item_name(item)
74
+ "#{attr_key}_#{item.is_a?(Array) ? item.first : item}"
75
+ end
76
+
77
+ def item_disabled(item)
78
+ disabled_values.present? && disabled_values.include?(item_value(item))
79
+ end
80
+
81
+ def item_label(item)
82
+ item.is_a?(Array) ? item.first : item
83
+ end
84
+
85
+ def v_model_type
86
+ if select_options && item_value(select_options.first).is_a?(Integer) && !multiple
87
+ 'v-model.number'
88
+ else
89
+ 'v-model'
90
+ end
91
+ end
92
+
93
+ def id_for_item(value)
94
+ "#{html_attributes[:id]}_#{value}"
95
+ end
96
+
97
+ end
98
+ end
@@ -0,0 +1,58 @@
1
+ const formSelectMixin = {
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
+ self.afterInitialize(JSON.parse(initValue["value"]))
16
+ } else {
17
+ data[key.replace("select.multiple.", "")] = [];
18
+ self.afterInitialize([])
19
+ }
20
+ } else {
21
+ if (initValue) {
22
+ if (valueType && valueType["value"] == "Integer") {
23
+ data[key.replace("select.", "")] = parseInt(initValue["value"]);
24
+ self.afterInitialize(parseInt(initValue["value"]))
25
+ } else {
26
+ data[key.replace("select.", "")] = initValue["value"];
27
+ self.afterInitialize(initValue["value"])
28
+ }
29
+ } else {
30
+ data[key.replace("select.", "")] = null;
31
+ self.afterInitialize(null)
32
+ }
33
+ }
34
+ }
35
+ }
36
+
37
+ //without the timeout it's somehow not working
38
+ setTimeout(function () {
39
+ Object.assign(self.$parent.data, data);
40
+ self.$forceUpdate()
41
+ }, 1);
42
+ },
43
+ inputChanged: function (key) {
44
+ this.$parent.resetErrors(key);
45
+ this.$forceUpdate();
46
+ },
47
+ afterInitialize: function(value){
48
+ // can be used in the main component for further initialization steps
49
+ },
50
+ setValue: function (value){
51
+ this.$parent.data[this.componentConfig["key"]] = value
52
+ this.$forceUpdate();
53
+ }
54
+ }
55
+
56
+ }
57
+
58
+ export default formSelectMixin
@@ -0,0 +1,15 @@
1
+ import Vue from "vue/dist/vue.esm";
2
+
3
+ import formSelectMixin from "./mixin";
4
+ import componentMixin from "../../component/component";
5
+
6
+ const componentDef = {
7
+ mixins: [componentMixin, formSelectMixin],
8
+ data() {
9
+ return {};
10
+ }
11
+ }
12
+
13
+ let component = Vue.component("matestack-ui-core-form-select", componentDef);
14
+
15
+ export default componentDef;
@@ -1,68 +1,19 @@
1
- require_relative '../utils'
2
- require_relative '../has_errors'
3
- module Matestack::Ui::Core::Form::Select
4
- class Select < Matestack::Ui::Core::Component::Static
5
- include Matestack::Ui::Core::Form::Utils
6
- include Matestack::Ui::Core::Form::HasErrors
7
-
8
- html_attributes :autofocus, :disabled, :form, :multiple, :name, :required, :size
9
-
10
- requires :key
11
- optional :multiple, :init, :placeholder, :disabled_values,
12
- for: { as: :input_for },
13
- label: { as: :input_label },
14
- options: { as: :select_options }
15
-
16
- def vue_attributes
17
- (options[:attributes] || {}).merge({
18
- "@change": change_event,
19
- ref: vue_ref,
20
- 'init-value': init_value || [],
21
- 'v-bind:class': "{ '#{input_error_class}': #{error_key} }",
22
- 'value-type': value_type,
23
- "#{v_model_type}": input_key,
24
- })
25
- end
26
-
27
- def vue_ref
28
- "select#{'.multiple' if multiple}.#{attr_key}"
29
- end
30
-
31
- def value_type
32
- item_value(select_options.first).is_a?(Integer) ? Integer : nil
33
- end
34
-
35
- def item_value(item)
36
- item.is_a?(Array) ? item.last : item
37
- end
38
-
39
- def item_name(item)
40
- "#{attr_key}_#{item.is_a?(Array) ? item.first : item}"
41
- end
1
+ require_relative './base'
42
2
 
43
- def item_disabled(item)
44
- disabled_values.present? && disabled_values.include?(item_value(item))
45
- end
3
+ module Matestack::Ui::Core::Form::Select
4
+ class Select < Base
46
5
 
47
- def item_label(item)
48
- item.is_a?(Array) ? item.first : item
49
- end
6
+ vue_js_component_name "matestack-ui-core-form-select"
50
7
 
51
- def v_model_type
52
- if select_options && item_value(select_options.first).is_a?(Integer) && !multiple
53
- 'v-model.number'
54
- else
55
- 'v-model'
8
+ def response
9
+ div class: "matestack-ui-core-form-select" do
10
+ label text: input_label if input_label
11
+ select select_attributes do
12
+ render_options
13
+ end
14
+ render_errors
56
15
  end
57
16
  end
58
17
 
59
- def change_event
60
- "inputChanged('#{attr_key}')"
61
- end
62
-
63
- def id_for_item(value)
64
- "#{html_attributes[:id]}_#{value}"
65
- end
66
-
67
18
  end
68
19
  end