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,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
@@ -0,0 +1,12 @@
1
+ module Matestack::Ui::Core::Form::Submit
2
+ class Base < Matestack::Ui::Core::Component::Dynamic
3
+
4
+ def submit_attributes
5
+ html_attributes.merge!({
6
+ "@click.prevent": "$parent.perform",
7
+ "v-bind:class": "{ 'loading': $parent.loading }"
8
+ })
9
+ end
10
+
11
+ end
12
+ end
@@ -0,0 +1,19 @@
1
+ import Vue from "vue/dist/vue.esm";
2
+
3
+ import componentMixin from "../../component/component";
4
+
5
+ const componentDef = {
6
+ mixins: [componentMixin],
7
+ data() {
8
+ return {};
9
+ },
10
+ methods: {
11
+ loading: function(){
12
+ return this.$parent.loading;
13
+ }
14
+ }
15
+ }
16
+
17
+ let component = Vue.component("matestack-ui-core-form-submit", componentDef);
18
+
19
+ export default componentDef;
@@ -1,11 +1,14 @@
1
+ require_relative './base'
2
+
1
3
  module Matestack::Ui::Core::Form::Submit
2
- class Submit < Matestack::Ui::Core::Component::Static
4
+ class Submit < Base
5
+
6
+ vue_js_component_name "matestack-ui-core-form-submit"
3
7
 
4
- def submit_attributes
5
- html_attributes.merge!({
6
- "@click.prevent": "perform",
7
- "v-bind:class": "{ 'loading': loading }"
8
- })
8
+ def response
9
+ span attributes: submit_attributes do
10
+ yield_components
11
+ end
9
12
  end
10
13
 
11
14
  end
@@ -0,0 +1,49 @@
1
+ require_relative '../utils'
2
+ require_relative '../has_errors'
3
+ module Matestack::Ui::Core::Form::Textarea
4
+ class Base < Matestack::Ui::Core::Component::Dynamic
5
+ include Matestack::Ui::Core::Form::Utils
6
+ include Matestack::Ui::Core::Form::HasErrors
7
+
8
+ requires :key
9
+ optional :multiple, :init, for: { as: :input_for }, label: { as: :input_label }
10
+
11
+ html_attributes :autofocus, :cols, :dirname, :disabled, :form, :maxlength,
12
+ :name, :placeholder, :readonly, :required, :rows, :wrap
13
+
14
+ def setup
15
+ @component_config[:init_value] = init_value
16
+ end
17
+
18
+ def component_id
19
+ "textarea-component-for-#{attr_key}"
20
+ end
21
+
22
+ def input_key
23
+ "$parent.data[\"#{key}\"]"
24
+ end
25
+
26
+ def error_key
27
+ "$parent.errors[\"#{key}\"]"
28
+ end
29
+
30
+ def change_event
31
+ "inputChanged('#{attr_key}')"
32
+ end
33
+
34
+ def textarea_attributes
35
+ html_attributes.merge(attributes: vue_attributes)
36
+ end
37
+
38
+ def vue_attributes
39
+ (options[:attributes] || {}).merge({
40
+ 'v-model': input_key,
41
+ '@change': change_event,
42
+ 'v-bind:class': "{ '#{input_error_class}': #{error_key} }",
43
+ "init-value": init_value,
44
+ ref: "input.#{attr_key}",
45
+ })
46
+ end
47
+
48
+ end
49
+ end
@@ -0,0 +1,41 @@
1
+ const formTextareaMixin = {
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
+ inputChanged: function (key) {
27
+ this.$parent.resetErrors(key);
28
+ this.$forceUpdate();
29
+ },
30
+ afterInitialize: function(value){
31
+ // can be used in the main component for further initialization steps
32
+ },
33
+ setValue: function (value){
34
+ this.$parent.data[this.componentConfig["key"]] = value
35
+ this.$forceUpdate();
36
+ }
37
+ }
38
+
39
+ }
40
+
41
+ export default formTextareaMixin
@@ -0,0 +1,15 @@
1
+ import Vue from "vue/dist/vue.esm";
2
+
3
+ import formTextareaMixin from "./mixin";
4
+ import componentMixin from "../../component/component";
5
+
6
+ const componentDef = {
7
+ mixins: [componentMixin, formTextareaMixin],
8
+ data() {
9
+ return {};
10
+ }
11
+ }
12
+
13
+ let component = Vue.component("matestack-ui-core-form-textarea", componentDef);
14
+
15
+ export default componentDef;
@@ -1,28 +1,17 @@
1
- require_relative '../utils'
2
- require_relative '../has_errors'
1
+ require_relative './base'
2
+
3
3
  module Matestack::Ui::Core::Form::Textarea
4
- class Textarea < Matestack::Ui::Core::Textarea::Textarea
5
- include Matestack::Ui::Core::Form::Utils
6
- include Matestack::Ui::Core::Form::HasErrors
4
+ class Textarea < Base
7
5
 
8
- requires :key
9
- optional :multiple, :init, for: { as: :input_for }, label: { as: :input_label }
6
+ vue_js_component_name "matestack-ui-core-form-textarea"
10
7
 
11
8
  def response
12
- label text: input_label if input_label
13
- textarea html_attributes.merge(attributes: vue_attributes)
14
- render_errors
9
+ div class: "matestack-ui-core-form-textarea" do
10
+ label text: input_label if input_label
11
+ textarea textarea_attributes
12
+ render_errors
13
+ end
15
14
  end
16
15
 
17
- def vue_attributes
18
- (options[:attributes] || {}).merge({
19
- 'v-model': input_key,
20
- '@change': "inputChanged('#{attr_key}')",
21
- 'v-bind:class': "{ '#{input_error_class}': #{error_key} }",
22
- "init-value": init_value,
23
- ref: "input.#{attr_key}",
24
- })
25
- end
26
-
27
16
  end
28
- end
17
+ end