matestack-ui-core 1.1.0 → 1.4.0

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.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +801 -13
  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/component/base.rb +1 -1
  6. data/app/concepts/matestack/ui/core/form/checkbox/base.rb +120 -0
  7. data/app/concepts/matestack/ui/core/form/checkbox/checkbox.js +15 -0
  8. data/app/concepts/matestack/ui/core/form/checkbox/checkbox.rb +7 -70
  9. data/app/concepts/matestack/ui/core/form/checkbox/mixin.js +80 -0
  10. data/app/concepts/matestack/ui/core/form/form.js +15 -46
  11. data/app/concepts/matestack/ui/core/form/input/base.rb +75 -0
  12. data/app/concepts/matestack/ui/core/form/input/input.js +15 -0
  13. data/app/concepts/matestack/ui/core/form/input/input.rb +8 -52
  14. data/app/concepts/matestack/ui/core/form/input/mixin.js +55 -0
  15. data/app/concepts/matestack/ui/core/form/radio/base.rb +90 -0
  16. data/app/concepts/matestack/ui/core/form/radio/mixin.js +62 -0
  17. data/app/concepts/matestack/ui/core/form/radio/radio.js +15 -0
  18. data/app/concepts/matestack/ui/core/form/radio/radio.rb +7 -62
  19. data/app/concepts/matestack/ui/core/form/select/base.rb +98 -0
  20. data/app/concepts/matestack/ui/core/form/select/mixin.js +58 -0
  21. data/app/concepts/matestack/ui/core/form/select/select.js +15 -0
  22. data/app/concepts/matestack/ui/core/form/select/select.rb +11 -60
  23. data/app/concepts/matestack/ui/core/form/submit/base.rb +12 -0
  24. data/app/concepts/matestack/ui/core/form/submit/submit.js +19 -0
  25. data/app/concepts/matestack/ui/core/form/submit/submit.rb +9 -6
  26. data/app/concepts/matestack/ui/core/form/textarea/base.rb +49 -0
  27. data/app/concepts/matestack/ui/core/form/textarea/mixin.js +41 -0
  28. data/app/concepts/matestack/ui/core/form/textarea/textarea.js +15 -0
  29. data/app/concepts/matestack/ui/core/form/textarea/textarea.rb +10 -21
  30. data/app/concepts/matestack/ui/core/js/core.js +11 -0
  31. data/app/concepts/matestack/ui/core/{form/submit/submit.haml → select/select.haml} +1 -1
  32. data/app/concepts/matestack/ui/core/select/select.rb +7 -0
  33. data/app/concepts/matestack/ui/core/view/view.rb +2 -2
  34. data/app/helpers/matestack/ui/core/application_helper.rb +2 -2
  35. data/app/javascript/matestack-ui-core/index.js +12 -2
  36. data/app/lib/matestack/ui/core/has_view_context.rb +4 -2
  37. data/app/lib/matestack/ui/core/rendering/main_renderer.rb +4 -1
  38. data/lib/matestack/ui/core/components.rb +2 -0
  39. data/lib/matestack/ui/core/version.rb +1 -1
  40. data/vendor/assets/javascripts/dist/matestack-ui-core.js +611 -55
  41. data/vendor/assets/javascripts/dist/matestack-ui-core.js.map +1 -1
  42. data/vendor/assets/javascripts/dist/matestack-ui-core.min.js +1 -1
  43. data/vendor/assets/javascripts/dist/matestack-ui-core.min.js.LICENSE.txt +5 -12
  44. data/vendor/assets/javascripts/dist/matestack-ui-core.min.js.br +0 -0
  45. data/vendor/assets/javascripts/dist/matestack-ui-core.min.js.gz +0 -0
  46. data/vendor/assets/javascripts/dist/matestack-ui-core.min.js.map +1 -1
  47. data/vendor/assets/javascripts/dist/matestack-ui-core.min.js.map.br +0 -0
  48. data/vendor/assets/javascripts/dist/matestack-ui-core.min.js.map.gz +0 -0
  49. metadata +31 -16
  50. data/app/concepts/matestack/ui/core/form/select/select.haml +0 -9
@@ -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
@@ -13,6 +13,17 @@ import anonymDynamicComponent from '../component/anonym-dynamic-component'
13
13
  import transition from '../transition/transition'
14
14
  import action from '../action/action'
15
15
  import form from '../form/form'
16
+ import formInput from '../form/input/input'
17
+ import formInputMixin from '../form/input/mixin'
18
+ import formSelect from '../form/select/select'
19
+ import formSelectMixin from '../form/select/mixin'
20
+ import formRadio from '../form/radio/radio'
21
+ import formRadioMixin from '../form/radio/mixin'
22
+ import formCheckbox from '../form/checkbox/checkbox'
23
+ import formCheckboxMixin from '../form/checkbox/mixin'
24
+ import formTextarea from '../form/textarea/textarea'
25
+ import formTextareaMixin from '../form/textarea/mixin'
26
+ import formSubmit from '../form/submit/submit'
16
27
  import onclick from '../onclick/onclick'
17
28
  import collectionContent from '../collection/content/content'
18
29
  import collectionFilter from '../collection/filter/filter'
@@ -1,3 +1,3 @@
1
- %span{ submit_attributes }
1
+ %select{ html_attributes }
2
2
  - if block_given?
3
3
  = yield
@@ -0,0 +1,7 @@
1
+ module Matestack::Ui::Core::Select
2
+ class Select < Matestack::Ui::Core::Component::Static
3
+
4
+ html_attributes :autofocus, :disabled, :form, :multiple, :name, :required, :size
5
+
6
+ end
7
+ end
@@ -1,4 +1,4 @@
1
- require_dependency "cell/partial"
1
+ require "cell/partial"
2
2
 
3
3
  module Matestack::Ui::Core::View
4
4
  class View < Matestack::Ui::Core::Component::Static
@@ -15,7 +15,7 @@ module Matestack::Ui::Core::View
15
15
  controller.render_to_string view_path, layout: false, locals: locals
16
16
  elsif partial_path
17
17
  controller.render_to_string partial: partial_path, layout: false, locals: locals
18
- else
18
+ else
19
19
  raise 'view or partial param missing for RailsView Component'
20
20
  end
21
21
  end
@@ -102,8 +102,8 @@ module Matestack
102
102
  controller = (self.class <= ActionController::Base) ? self : @_controller
103
103
  context = (options[:matestack_context] ||= {}).merge(controller: controller)
104
104
  Matestack::Ui::Core::Component::Base
105
- .new(options.merge(matestack_context: context))
106
- .send(component, options.merge(matestack_context: context), &block).to_s
105
+ .new(options.merge(context: context, matestack_context: context))
106
+ .send(component, options.merge(context: context, matestack_context: context), &block).to_s
107
107
  end
108
108
  end
109
109
  end
@@ -5,6 +5,11 @@ import axios from 'axios'
5
5
  // Import from app/concepts/matestack/ui/core:
6
6
  import matestackEventHub from '../../../app/concepts/matestack/ui/core/js/event-hub'
7
7
  import componentMixin from '../../../app/concepts/matestack/ui/core/component/component'
8
+ import formInputMixin from '../../../app/concepts/matestack/ui/core/form/input/mixin'
9
+ import formSelectMixin from '../../../app/concepts/matestack/ui/core/form/select/mixin'
10
+ import formRadioMixin from '../../../app/concepts/matestack/ui/core/form/radio/mixin'
11
+ import formCheckboxMixin from '../../../app/concepts/matestack/ui/core/form/checkbox/mixin'
12
+ import formTextareaMixin from '../../../app/concepts/matestack/ui/core/form/textarea/mixin'
8
13
  import matestackUiCore from '../../../app/concepts/matestack/ui/core/js/core'
9
14
 
10
15
  import styles from './styles/index.scss'
@@ -14,9 +19,14 @@ const MatestackUiCore = {
14
19
  Vuex,
15
20
  axios,
16
21
  matestackEventHub,
17
- componentMixin
22
+ componentMixin,
23
+ formInputMixin,
24
+ formSelectMixin,
25
+ formCheckboxMixin,
26
+ formTextareaMixin,
27
+ formRadioMixin
18
28
  }
19
29
 
20
30
  window.MatestackUiCore = MatestackUiCore
21
31
 
22
- export default MatestackUiCore
32
+ export default MatestackUiCore