matestack-ui-core 2.0.0 → 3.0.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +1 -1
  3. data/README.md +15 -478
  4. data/lib/matestack/ui/core/base.rb +24 -7
  5. data/lib/matestack/ui/core/context.rb +2 -2
  6. data/lib/matestack/ui/core/helper.rb +29 -29
  7. data/lib/matestack/ui/core/{app.rb → layout.rb} +6 -17
  8. data/lib/matestack/ui/core/page.rb +0 -50
  9. data/lib/matestack/ui/core/tag_helper.rb +17 -10
  10. data/lib/matestack/ui/core/version.rb +1 -1
  11. data/lib/matestack/ui/core.rb +2 -45
  12. data/lib/matestack/ui/layout.rb +1 -0
  13. data/lib/matestack/ui/page.rb +1 -1
  14. metadata +7 -68
  15. data/lib/matestack/ui/app.rb +0 -1
  16. data/lib/matestack/ui/core/vue_attributes.rb +0 -13
  17. data/lib/matestack/ui/vue_js/app/app.js +0 -40
  18. data/lib/matestack/ui/vue_js/app/location.js +0 -9
  19. data/lib/matestack/ui/vue_js/app/store.js +0 -103
  20. data/lib/matestack/ui/vue_js/components/action.js +0 -151
  21. data/lib/matestack/ui/vue_js/components/action.rb +0 -46
  22. data/lib/matestack/ui/vue_js/components/async.js +0 -110
  23. data/lib/matestack/ui/vue_js/components/async.rb +0 -84
  24. data/lib/matestack/ui/vue_js/components/cable.js +0 -100
  25. data/lib/matestack/ui/vue_js/components/cable.rb +0 -69
  26. data/lib/matestack/ui/vue_js/components/collection/content.js +0 -97
  27. data/lib/matestack/ui/vue_js/components/collection/content.rb +0 -32
  28. data/lib/matestack/ui/vue_js/components/collection/filter.js +0 -45
  29. data/lib/matestack/ui/vue_js/components/collection/filter.rb +0 -29
  30. data/lib/matestack/ui/vue_js/components/collection/filter_reset.rb +0 -19
  31. data/lib/matestack/ui/vue_js/components/collection/helper.rb +0 -128
  32. data/lib/matestack/ui/vue_js/components/collection/next.rb +0 -19
  33. data/lib/matestack/ui/vue_js/components/collection/order.js +0 -46
  34. data/lib/matestack/ui/vue_js/components/collection/order.rb +0 -28
  35. data/lib/matestack/ui/vue_js/components/collection/order_toggle.rb +0 -21
  36. data/lib/matestack/ui/vue_js/components/collection/order_toggle_indicator.rb +0 -30
  37. data/lib/matestack/ui/vue_js/components/collection/page.rb +0 -21
  38. data/lib/matestack/ui/vue_js/components/collection/previous.rb +0 -19
  39. data/lib/matestack/ui/vue_js/components/form/base.rb +0 -167
  40. data/lib/matestack/ui/vue_js/components/form/checkbox.js +0 -15
  41. data/lib/matestack/ui/vue_js/components/form/checkbox.rb +0 -105
  42. data/lib/matestack/ui/vue_js/components/form/checkbox_mixin.js +0 -83
  43. data/lib/matestack/ui/vue_js/components/form/context.rb +0 -15
  44. data/lib/matestack/ui/vue_js/components/form/form.js +0 -275
  45. data/lib/matestack/ui/vue_js/components/form/form.rb +0 -64
  46. data/lib/matestack/ui/vue_js/components/form/input.js +0 -15
  47. data/lib/matestack/ui/vue_js/components/form/input.rb +0 -37
  48. data/lib/matestack/ui/vue_js/components/form/input_mixin.js +0 -58
  49. data/lib/matestack/ui/vue_js/components/form/radio.js +0 -15
  50. data/lib/matestack/ui/vue_js/components/form/radio.rb +0 -76
  51. data/lib/matestack/ui/vue_js/components/form/radio_mixin.js +0 -65
  52. data/lib/matestack/ui/vue_js/components/form/select.js +0 -15
  53. data/lib/matestack/ui/vue_js/components/form/select.rb +0 -88
  54. data/lib/matestack/ui/vue_js/components/form/select_mixin.js +0 -61
  55. data/lib/matestack/ui/vue_js/components/form/textarea.js +0 -15
  56. data/lib/matestack/ui/vue_js/components/form/textarea.rb +0 -37
  57. data/lib/matestack/ui/vue_js/components/form/textarea_mixin.js +0 -44
  58. data/lib/matestack/ui/vue_js/components/isolated.js +0 -108
  59. data/lib/matestack/ui/vue_js/components/isolated.rb +0 -86
  60. data/lib/matestack/ui/vue_js/components/mixin.js +0 -22
  61. data/lib/matestack/ui/vue_js/components/onclick.js +0 -19
  62. data/lib/matestack/ui/vue_js/components/onclick.rb +0 -37
  63. data/lib/matestack/ui/vue_js/components/toggle.js +0 -71
  64. data/lib/matestack/ui/vue_js/components/toggle.rb +0 -38
  65. data/lib/matestack/ui/vue_js/components/transition.js +0 -42
  66. data/lib/matestack/ui/vue_js/components/transition.rb +0 -40
  67. data/lib/matestack/ui/vue_js/components.rb +0 -94
  68. data/lib/matestack/ui/vue_js/event_hub.js +0 -5
  69. data/lib/matestack/ui/vue_js/helpers/query_params_helper.js +0 -56
  70. data/lib/matestack/ui/vue_js/index.js +0 -52
  71. data/lib/matestack/ui/vue_js/initialize.rb +0 -5
  72. data/lib/matestack/ui/vue_js/page/content.js +0 -23
  73. data/lib/matestack/ui/vue_js/vue.rb +0 -63
  74. data/lib/matestack/ui/vue_js_component.rb +0 -2
@@ -1,45 +0,0 @@
1
- import Vue from 'vue/dist/vue.esm'
2
- import matestackEventHub from '../../event_hub'
3
- import queryParamsHelper from '../../helpers/query_params_helper'
4
-
5
- import formMixin from '../form/form'
6
-
7
- const componentDef = {
8
- mixins: [formMixin],
9
- methods: {
10
- perform: function(){
11
- var url;
12
- var filter = this.data
13
- for (var key in this.data) {
14
- url = queryParamsHelper.updateQueryParams(this.props["id"] + "-filter-" + key, JSON.stringify(this.data[key]), url)
15
- }
16
- url = queryParamsHelper.updateQueryParams(this.props["id"] + "-offset", 0, url)
17
- window.history.pushState({matestackApp: true, url: url}, null, url);
18
- matestackEventHub.$emit(this.props["id"] + "-update")
19
- },
20
- resetFilter: function(){
21
- var url;
22
- for (var key in this.data) {
23
- url = queryParamsHelper.updateQueryParams(this.props["id"] + "-filter-" + key, null, url)
24
- this.data[key] = null;
25
- this.$forceUpdate();
26
- }
27
- this.initValues();
28
- window.history.pushState({matestackApp: true, url: url}, null, url);
29
- matestackEventHub.$emit(this.props["id"] + "-update")
30
- }
31
- },
32
- created: function(){
33
- var self = this;
34
- var queryParamsObject = queryParamsHelper.queryParamsToObject()
35
- Object.keys(queryParamsObject).forEach(function(key){
36
- if (key.startsWith(self.props["id"] + "-filter-")){
37
- self.data[key.replace(self.props["id"] + "-filter-", "")] = queryParamsObject[key]
38
- }
39
- })
40
- }
41
- }
42
-
43
- let component = Vue.component('matestack-ui-core-collection-filter', componentDef)
44
-
45
- export default componentDef
@@ -1,29 +0,0 @@
1
- module Matestack
2
- module Ui
3
- module VueJs
4
- module Components
5
- module Collection
6
-
7
- class Filter < Matestack::Ui::VueJs::Components::Form::Form
8
- vue_name 'matestack-ui-core-collection-filter'
9
-
10
- required :id
11
- required :filter_state
12
-
13
- def vue_props
14
- super.merge({
15
- id: ctx.id
16
- })
17
- end
18
-
19
- def for_option
20
- OpenStruct.new(ctx.filter_state)
21
- end
22
-
23
- end
24
-
25
- end
26
- end
27
- end
28
- end
29
- end
@@ -1,19 +0,0 @@
1
- module Matestack
2
- module Ui
3
- module VueJs
4
- module Components
5
- module Collection
6
- class FilterReset < Matestack::Ui::Component
7
-
8
- def response
9
- a '@click': 'resetFilter()' do
10
- yield
11
- end
12
- end
13
-
14
- end
15
- end
16
- end
17
- end
18
- end
19
- end
@@ -1,128 +0,0 @@
1
- module Matestack::Ui::VueJs::Components::Collection
2
- module Helper
3
-
4
- def get_collection_filter collection_id, key=nil
5
- filter_hash = {}
6
- controller_params.each do |param_key, param_value|
7
- if param_key.start_with?("#{collection_id}-filter-")
8
- param_key.gsub("#{collection_id}-filter-", "")
9
- filter_hash[param_key.gsub("#{collection_id}-filter-", "").to_sym] = JSON.parse(param_value)
10
- end
11
- end
12
- if key.nil?
13
- return filter_hash
14
- else
15
- return filter_hash[key]
16
- end
17
- end
18
-
19
- def get_collection_order collection_id, key=nil
20
- order_hash = {}
21
- controller_params.each do |param_key, param_value|
22
- if param_key.start_with?("#{collection_id}-order-")
23
- param_key.gsub("#{collection_id}-order-", "")
24
- order_hash[param_key.gsub("#{collection_id}-order-", "").to_sym] = param_value
25
- end
26
- end
27
- if key.nil?
28
- return order_hash
29
- else
30
- return order_hash[key]
31
- end
32
- end
33
-
34
- # since ruby 3 changed hash <-> keyword argument transformation, we need to
35
- # adjust this method call in order to stay compatible with ruby 2.x and ruby 3.x
36
- def set_collection options_hash
37
- _set_collection **options_hash
38
- end
39
-
40
- def _set_collection id: nil, init_offset: 0, init_limit: nil, base_count: nil, filtered_count: nil, data: nil
41
- @collections = {} if @collections.nil?
42
-
43
- collection_config = CollectionConfig.new(
44
- id,
45
- init_offset,
46
- init_limit,
47
- filtered_count,
48
- base_count,
49
- data,
50
- controller_params,
51
- get_collection_filter(id)
52
- )
53
-
54
- @collections[id.to_sym] = collection_config
55
-
56
- return collection_config
57
- end
58
-
59
- def controller_params
60
- return params.to_unsafe_h if defined? params
61
- raise 'collection component is missing access to params or context'
62
- end
63
-
64
- end
65
-
66
- CollectionConfig = Struct.new(:id, :init_offset, :init_limit, :filtered_count, :base_count, :data, :params, :filter_state) do
67
-
68
- def paginated_data
69
- resulting_data = data
70
- resulting_data = resulting_data.offset(get_collection_offset) unless get_collection_offset == 0
71
- resulting_data = resulting_data.limit(get_collection_limit) unless get_collection_limit == 0
72
-
73
- return resulting_data
74
- end
75
-
76
- def get_collection_offset
77
- (params["#{id}-offset".to_sym] ||= init_offset).to_i
78
- end
79
-
80
- def get_collection_limit
81
- (params["#{id}-limit".to_sym] ||= init_limit).to_i
82
- end
83
-
84
- def pages
85
- offset = get_collection_offset
86
- limit = get_collection_limit
87
- if filtered_count.present?
88
- count = filtered_count
89
- else
90
- count = base_count
91
- end
92
- page_count = count/limit
93
- page_count += 1 if count%limit > 0
94
- return (1..page_count).to_a
95
- end
96
-
97
- def from
98
- return get_collection_offset + 1 if to > 0
99
- return 0 if to == 0
100
- end
101
-
102
- def to
103
- current_to = get_collection_offset + get_collection_limit
104
- if filtered_count.present?
105
- if current_to > filtered_count
106
- return filtered_count
107
- else
108
- return current_to
109
- end
110
- else
111
- if current_to > base_count
112
- return base_count
113
- else
114
- return current_to
115
- end
116
- end
117
- end
118
-
119
- def filter_state
120
-
121
- end
122
-
123
- def config
124
- self.to_h.except(:context)
125
- end
126
-
127
- end
128
- end
@@ -1,19 +0,0 @@
1
- module Matestack
2
- module Ui
3
- module VueJs
4
- module Components
5
- module Collection
6
- class Next < Matestack::Ui::Component
7
-
8
- def response
9
- a options.merge('@click': 'next()') do
10
- yield
11
- end
12
- end
13
-
14
- end
15
- end
16
- end
17
- end
18
- end
19
- end
@@ -1,46 +0,0 @@
1
- import Vue from 'vue/dist/vue.esm'
2
- import matestackEventHub from '../../event_hub'
3
- import queryParamsHelper from '../../helpers/query_params_helper'
4
- import componentMixin from '../mixin'
5
-
6
- const componentDef = {
7
- mixins: [componentMixin],
8
- data: function(){
9
- return {
10
- ordering: {}
11
- }
12
- },
13
- methods: {
14
- toggleOrder: function(key){
15
- if (this.ordering[key] == undefined) {
16
- this.ordering[key] = "asc"
17
- } else if (this.ordering[key] == "asc") {
18
- this.ordering[key] = "desc"
19
- } else if (this.ordering[key] == "desc") {
20
- this.ordering[key] = undefined
21
- }
22
- var url;
23
- url = queryParamsHelper.updateQueryParams(this.props["id"] + "-order-" + key, this.ordering[key])
24
- url = queryParamsHelper.updateQueryParams(this.props["id"] + "-offset", 0, url)
25
- window.history.pushState({matestackApp: true, url: url}, null, url);
26
- matestackEventHub.$emit(this.props["id"] + "-update")
27
- this.$forceUpdate()
28
- },
29
- orderIndicator(key, indicators){
30
- return indicators[this.ordering[key]]
31
- }
32
- },
33
- created: function(){
34
- var self = this;
35
- var queryParamsObject = queryParamsHelper.queryParamsToObject()
36
- Object.keys(queryParamsObject).forEach(function(key){
37
- if (key.startsWith(self.props["id"] + "-order-")){
38
- self.ordering[key.replace(self.props["id"] + "-order-", "")] = queryParamsObject[key]
39
- }
40
- })
41
- }
42
- }
43
-
44
- let component = Vue.component('matestack-ui-core-collection-order', componentDef)
45
-
46
- export default componentDef
@@ -1,28 +0,0 @@
1
- module Matestack
2
- module Ui
3
- module VueJs
4
- module Components
5
- module Collection
6
- class Order < Matestack::Ui::VueJs::Vue
7
- vue_name 'matestack-ui-core-collection-order'
8
-
9
- required :id
10
-
11
- def response
12
- div do
13
- yield
14
- end
15
- end
16
-
17
- def vue_props
18
- {
19
- id: ctx.id
20
- }
21
- end
22
-
23
- end
24
- end
25
- end
26
- end
27
- end
28
- end
@@ -1,21 +0,0 @@
1
- module Matestack
2
- module Ui
3
- module VueJs
4
- module Components
5
- module Collection
6
- class OrderToggle < Matestack::Ui::Component
7
-
8
- required :key
9
-
10
- def response
11
- a '@click': "toggleOrder(\"#{ctx.key}\")" do
12
- yield
13
- end
14
- end
15
-
16
- end
17
- end
18
- end
19
- end
20
- end
21
- end
@@ -1,30 +0,0 @@
1
- module Matestack
2
- module Ui
3
- module VueJs
4
- module Components
5
- module Collection
6
- class OrderToggleIndicator < Matestack::Ui::Component
7
-
8
- required :key, :asc, :desc
9
- optional :default
10
-
11
- def response
12
- span do
13
- span "v-if": "ordering['#{ctx.key}'] === undefined" do
14
- plain ctx.default
15
- end
16
- unescaped "{{
17
- orderIndicator(
18
- '#{ctx.key}',
19
- { asc: '#{ctx.asc}', desc: '#{ctx.desc}'}
20
- )
21
- }}"
22
- end
23
- end
24
-
25
- end
26
- end
27
- end
28
- end
29
- end
30
- end
@@ -1,21 +0,0 @@
1
- module Matestack
2
- module Ui
3
- module VueJs
4
- module Components
5
- module Collection
6
- class Page < Matestack::Ui::Component
7
-
8
- required :page
9
-
10
- def response
11
- a options.merge('@click': "goToPage(#{ctx.page})") do
12
- yield
13
- end
14
- end
15
-
16
- end
17
- end
18
- end
19
- end
20
- end
21
- end
@@ -1,19 +0,0 @@
1
- module Matestack
2
- module Ui
3
- module VueJs
4
- module Components
5
- module Collection
6
- class Previous < Matestack::Ui::Component
7
-
8
- def response
9
- a options.merge('@click': 'previous()') do
10
- yield
11
- end
12
- end
13
-
14
- end
15
- end
16
- end
17
- end
18
- end
19
- end
@@ -1,167 +0,0 @@
1
- module Matestack
2
- module Ui
3
- module VueJs
4
- module Components
5
- module Form
6
- class Base < Matestack::Ui::VueJs::Vue
7
-
8
- optional :key, :type, :label, :init, :errors, :id, :multiple, :placeholder
9
-
10
- def form_context
11
- Matestack::Ui::VueJs::Components::Form::Context.form_context
12
- end
13
-
14
- # options/settings
15
-
16
- def key
17
- ctx.key
18
- end
19
-
20
- def type
21
- ctx.type
22
- end
23
-
24
- def input_label
25
- ctx.label
26
- end
27
-
28
- def init
29
- ctx.init
30
- end
31
-
32
- def error_config
33
- ctx.errors
34
- end
35
-
36
- def id
37
- ctx.id || key
38
- end
39
-
40
- def multiple
41
- ctx.multiple
42
- end
43
-
44
- def placeholder
45
- ctx.placeholder
46
- end
47
-
48
- # calculated attributes
49
-
50
- def attributes
51
- (options || {}).merge({
52
- ref: "input.#{attribute_key}",
53
- id: id,
54
- type: ctx.type,
55
- multiple: ctx.multiple,
56
- placeholder: ctx.placeholder,
57
- '@change': change_event,
58
- 'init-value': init_value || (ctx.multiple ? [] : nil),
59
- 'v-bind:class': "{ '#{input_error_class}': #{error_key} }",
60
- }).tap do |attrs|
61
- attrs[:"#{v_model_type}"] = input_key unless type == :file
62
- end
63
- end
64
-
65
- def attribute_key
66
- key.to_s + "#{'[]' if ctx.multiple && ctx.type == :file}"
67
- end
68
-
69
- def name
70
- attribute_key
71
- end
72
-
73
- def init_value
74
- return init unless init.nil?
75
- if form_context.for_option.respond_to?(key)
76
- form_context.for_option.send(key)
77
- end
78
- end
79
-
80
- def change_event
81
- input_changed = "inputChanged('#{attribute_key}');"
82
- input_changed << "filesAdded('#{attribute_key}');" if type == :file
83
- input_changed
84
- end
85
-
86
- def input_key
87
- "$parent.data['#{key}']"
88
- end
89
-
90
- # set v-model.number for all numeric init values or options
91
- def v_model_type(item=nil)
92
- if item.nil?
93
- (type == :number || init_value.is_a?(Numeric)) ? 'v-model.number' : 'v-model'
94
- else
95
- item.is_a?(Integer) ? 'v-model.number' : 'v-model'
96
- end
97
- end
98
-
99
- # set value-type "Integer" for all numeric init values or options
100
- def value_type(item=nil)
101
- if item.nil?
102
- (type == :number || init_value.is_a?(Numeric)) ? Integer : nil
103
- else
104
- item.is_a?(Integer)? Integer : nil
105
- end
106
- end
107
-
108
- # error rendering
109
-
110
- def display_errors?
111
- if form_context.ctx.errors == false
112
- error_config ? true : false
113
- else
114
- error_config != false
115
- end
116
- end
117
-
118
- def error_key
119
- "$parent.errors['#{key}']"
120
- end
121
-
122
- def error_class
123
- get_from_error_config(:class) || 'error'
124
- end
125
-
126
- def error_tag
127
- get_from_error_config(:tag) || :div
128
- # error_config.is_a?(Hash) && error_config.dig(:tag) || :div
129
- end
130
-
131
- def input_error_class
132
- get_from_error_config(:input, :class) || 'error'
133
- # error_config.is_a?(Hash) && error_config.dig(:input, :class) || 'error'
134
- end
135
-
136
- def wrapper_tag
137
- get_from_error_config(:wrapper, :tag) || :div
138
- # error_config.is_a?(Hash) && error_config.dig(:wrapper, :tag) || :div
139
- end
140
-
141
- def wrapper_error_class
142
- get_from_error_config(:wrapper, :class) || 'errors'
143
- # error_config.is_a?(Hash) && error_config.dig(:wrapper, :class) || 'errors'
144
- end
145
-
146
- def get_from_error_config(*keys)
147
- comp_error_config = error_config.dig(*keys) if error_config.is_a?(Hash)
148
- form_error_config = form_context.ctx.errors.dig(*keys) if form_context.ctx.errors.is_a?(Hash)
149
- comp_error_config || form_error_config
150
- end
151
-
152
- def render_errors
153
- if display_errors?
154
- Matestack::Ui::Component.new(wrapper_tag, class: wrapper_error_class, 'v-if': error_key) do
155
- Matestack::Ui::Component.new(error_tag, class: error_class, 'v-for': "error in #{error_key}") do
156
- plain vue.error
157
- end
158
- end
159
- end
160
- end
161
-
162
- end
163
- end
164
- end
165
- end
166
- end
167
- end
@@ -1,15 +0,0 @@
1
- import Vue from "vue/dist/vue.esm";
2
-
3
- import formCheckboxMixin from "./checkbox_mixin";
4
- import componentMixin from "../mixin";
5
-
6
- const componentDef = {
7
- mixins: [componentMixin, formCheckboxMixin],
8
- data() {
9
- return {};
10
- }
11
- }
12
-
13
- let component = Vue.component("matestack-ui-core-form-checkbox", componentDef);
14
-
15
- export default componentDef;