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,151 +0,0 @@
1
- import Vue from 'vue/dist/vue.esm'
2
- import Vuex from 'vuex'
3
- import axios from 'axios'
4
- import matestackEventHub from '../event_hub'
5
- import componentMixin from './mixin'
6
-
7
- const componentDef = {
8
- mixins: [componentMixin],
9
- data: function(){
10
- return {}
11
- },
12
- methods: {
13
- perform: function(){
14
- const self = this
15
- if (
16
- (self.props["confirm"] == undefined) || confirm(self.props["confirm_text"])
17
- )
18
- {
19
- if (self.props["emit"] != undefined) {
20
- matestackEventHub.$emit(self.props["emit"]);
21
- }
22
- if (self.props["delay"] != undefined) {
23
- setTimeout(function () {
24
- self.sendRequest()
25
- }, parseInt(self.props["delay"]));
26
- } else {
27
- this.sendRequest()
28
- }
29
- }
30
- },
31
- sendRequest: function(){
32
- const self = this
33
- axios({
34
- method: self.props["method"],
35
- url: self.props["action_path"],
36
- data: self.props["data"],
37
- headers: {
38
- 'X-CSRF-Token': document.getElementsByName("csrf-token")[0].getAttribute('content')
39
- }
40
- }
41
- )
42
- .then(function(response){
43
- if (self.props["success"] != undefined && self.props["success"]["emit"] != undefined) {
44
- matestackEventHub.$emit(self.props["success"]["emit"], response.data);
45
- }
46
-
47
- // transition handling
48
- if (self.props["success"] != undefined
49
- && self.props["success"]["transition"] != undefined
50
- && (
51
- self.props["success"]["transition"]["follow_response"] == undefined
52
- ||
53
- self.props["success"]["transition"]["follow_response"] === false
54
- )
55
- && self.$store != undefined
56
- ) {
57
- let path = self.props["success"]["transition"]["path"]
58
- self.$store.dispatch('navigateTo', {url: path, backwards: false})
59
- return;
60
- }
61
- if (self.props["success"] != undefined
62
- && self.props["success"]["transition"] != undefined
63
- && self.props["success"]["transition"]["follow_response"] === true
64
- && self.$store != undefined
65
- ) {
66
- let path = response.data["transition_to"] || response.request.responseURL
67
- self.$store.dispatch('navigateTo', {url: path, backwards: false})
68
- return;
69
- }
70
- // redirect handling
71
- if (self.props["success"] != undefined
72
- && self.props["success"]["redirect"] != undefined
73
- && (
74
- self.props["success"]["redirect"]["follow_response"] == undefined
75
- ||
76
- self.props["success"]["redirect"]["follow_response"] === false
77
- )
78
- && self.$store != undefined
79
- ) {
80
- let path = self.props["success"]["redirect"]["path"]
81
- window.location.href = path
82
- return;
83
- }
84
- if (self.props["success"] != undefined
85
- && self.props["success"]["redirect"] != undefined
86
- && self.props["success"]["redirect"]["follow_response"] === true
87
- && self.$store != undefined
88
- ) {
89
- let path = response.data["redirect_to"] || response.request.responseURL
90
- window.location.href = path
91
- return;
92
- }
93
- })
94
- .catch(function(error){
95
- if (self.props["failure"] != undefined && self.props["failure"]["emit"] != undefined) {
96
- matestackEventHub.$emit(self.props["failure"]["emit"], error.response.data);
97
- }
98
- // transition handling
99
- if (self.props["failure"] != undefined
100
- && self.props["failure"]["transition"] != undefined
101
- && (
102
- self.props["failure"]["transition"]["follow_response"] == undefined
103
- ||
104
- self.props["failure"]["transition"]["follow_response"] === false
105
- )
106
- && self.$store != undefined
107
- ) {
108
- let path = self.props["failure"]["transition"]["path"]
109
- self.$store.dispatch('navigateTo', {url: path, backwards: false})
110
- return;
111
- }
112
- if (self.props["failure"] != undefined
113
- && self.props["failure"]["transition"] != undefined
114
- && self.props["failure"]["transition"]["follow_response"] === true
115
- && self.$store != undefined
116
- ) {
117
- let path = error.response.data["transition_to"] || response.request.responseURL
118
- self.$store.dispatch('navigateTo', {url: path, backwards: false})
119
- return;
120
- }
121
- // redirect handling
122
- if (self.props["failure"] != undefined
123
- && self.props["failure"]["redirect"] != undefined
124
- && (
125
- self.props["failure"]["redirect"]["follow_response"] == undefined
126
- ||
127
- self.props["failure"]["redirect"]["follow_response"] === false
128
- )
129
- && self.$store != undefined
130
- ) {
131
- let path = self.props["failure"]["redirect"]["path"]
132
- window.location.href = path
133
- return;
134
- }
135
- if (self.props["failure"] != undefined
136
- && self.props["failure"]["redirect"] != undefined
137
- && self.props["failure"]["redirect"]["follow_response"] === true
138
- && self.$store != undefined
139
- ) {
140
- let path = error.response.data["redirect_to"] || response.request.responseURL
141
- window.location.href = path
142
- return;
143
- }
144
- })
145
- }
146
- }
147
- }
148
-
149
- let component = Vue.component('matestack-ui-core-action', componentDef)
150
-
151
- export default componentDef
@@ -1,46 +0,0 @@
1
- module Matestack
2
- module Ui
3
- module VueJs
4
- module Components
5
- class Action < Matestack::Ui::VueJs::Vue
6
- vue_name 'matestack-ui-core-action'
7
-
8
- optional :path, :success, :failure, :notify, :confirm, :confirm_text, :data, :delay, :emit
9
-
10
- def response
11
- a attributes do
12
- yield
13
- end
14
- end
15
-
16
- def attributes
17
- {
18
- href: ctx.path,
19
- '@click.prevent': 'perform',
20
- }.merge(options)
21
- end
22
-
23
- def vue_props
24
- {}.tap do |conf|
25
- conf[:action_path] = ctx.path
26
- conf[:method] = action_method
27
- conf[:success] = ctx.success
28
- conf[:failure] = ctx.failure
29
- conf[:notify] = true if ctx.notify.nil?
30
- conf[:confirm] = ctx.confirm
31
- conf[:confirm_text] = ctx.confirm.try(:[], :text) || 'Are you sure?'
32
- conf[:data] = ctx.data
33
- conf[:delay] = ctx.delay
34
- conf[:emit] = ctx.emit
35
- end
36
- end
37
-
38
- def action_method
39
- @action_method ||= options.delete(:method)
40
- end
41
-
42
- end
43
- end
44
- end
45
- end
46
- end
@@ -1,110 +0,0 @@
1
- import Vue from 'vue/dist/vue.esm'
2
- import axios from 'axios'
3
- import VRuntimeTemplate from "v-runtime-template"
4
- import matestackEventHub from '../event_hub'
5
- import componentMixin from './mixin'
6
-
7
- const componentDef = {
8
- mixins: [componentMixin],
9
- data: function(){
10
- return {
11
- asyncTemplate: null,
12
- showing: true,
13
- loading: false,
14
- hideAfterTimeout: null,
15
- event: {
16
- data: {}
17
- }
18
- }
19
- },
20
- methods: {
21
- show: function(event_data){
22
- const self = this
23
- if (this.showing === true){
24
- return
25
- }
26
- this.showing = true
27
- this.event.data = event_data
28
- if(this.props["defer"] != undefined){
29
- if(!isNaN(this.props["defer"])){
30
- this.startDefer()
31
- }
32
- }
33
- if(this.props["hide_after"] != undefined){
34
- self.hideAfterTimeout = setTimeout(function () {
35
- self.hide()
36
- }, parseInt(this.props["hide_after"]));
37
- }
38
- },
39
- hide: function(){
40
- this.showing = false
41
- this.event.data = {}
42
- },
43
- startDefer: function(){
44
- const self = this
45
- self.loading = true;
46
- setTimeout(function () {
47
- self.rerender()
48
- }, parseInt(this.props["defer"]));
49
- },
50
- rerender: function(){
51
- var self = this;
52
- self.loading = true;
53
- axios({
54
- method: "get",
55
- url: location.pathname + location.search,
56
- headers: {
57
- 'X-CSRF-Token': document.getElementsByName("csrf-token")[0].getAttribute('content')
58
- },
59
- params: {
60
- "component_key": self.props["component_key"],
61
- "component_class": self.props["parent_class"]
62
- }
63
- })
64
- .then(function(response){
65
- var tmp_dom_element = document.createElement('div');
66
- tmp_dom_element.innerHTML = response['data'];
67
- var template = tmp_dom_element.querySelector('#' + self.props["component_key"]).outerHTML;
68
- self.loading = false;
69
- self.asyncTemplate = template;
70
- })
71
- .catch(function(error){
72
- console.log(error)
73
- matestackEventHub.$emit('async_rerender_error', { id: self.props["component_key"] })
74
- })
75
- }
76
- },
77
- created: function () {
78
- const self = this
79
- self.registerEvents(this.props['show_on'], self.show)
80
- self.registerEvents(this.props['hide_on'], self.hide)
81
- self.registerEvents(this.props['rerender_on'], self.rerender)
82
- if(this.props["show_on"] != undefined){
83
- this.showing = false
84
- }
85
- if(this.props["defer"] != undefined){
86
- if(!isNaN(this.props["defer"])){
87
- if (this.props["show_on"] == undefined){
88
- this.startDefer()
89
- }
90
- }
91
- }
92
- if(this.props["init_show"] == true){
93
- this.showing = true
94
- }
95
- },
96
- beforeDestroy: function() {
97
- const self = this
98
- clearTimeout(self.hideAfterTimeout)
99
- self.removeEvents(this.props["show_on"], self.show)
100
- self.removeEvents(this.props["hide_on"], self.hide)
101
- self.removeEvents(this.props["rerender_on"], self.rerender)
102
- },
103
- components: {
104
- VRuntimeTemplate: VRuntimeTemplate
105
- }
106
- }
107
-
108
- let component = Vue.component('matestack-ui-core-async', componentDef)
109
-
110
- export default componentDef
@@ -1,84 +0,0 @@
1
- module Matestack
2
- module Ui
3
- module VueJs
4
- module Components
5
- class Async < Matestack::Ui::VueJs::Vue
6
- vue_name 'matestack-ui-core-async'
7
-
8
- required :id
9
- optional :show_on, :hide_on, :rerender_on, :defer
10
-
11
- # register itself as an async component in the context
12
- def initialize(html_tag = nil, text = nil, options = {}, &block)
13
- super(html_tag, text, options, &block)
14
- Matestack::Ui::Core::Context.async_components = {} if Matestack::Ui::Core::Context.async_components.nil?
15
- Matestack::Ui::Core::Context.async_components[self.ctx.id] = self
16
- end
17
-
18
- def create_children(&block)
19
- self.response &block
20
- end
21
-
22
- def response
23
- if params[:component_key] && !is_not_requested?
24
- div async_attributes do
25
- yield
26
- end
27
- else
28
- vue_component do
29
- div class: 'matestack-async-component-container', 'v-bind:class': '{ "loading": loading === true }' do
30
- div class: 'matestack-async-component-wrapper', 'v-if': 'asyncTemplate == null', 'v-bind:class': '{ "loading": loading === true }' do
31
- div async_attributes do
32
- if params[:component_key]
33
- # we need to yield if a request is looking for a async component, indicated through present params[:component_key]
34
- # the requested component could be hidden within this deferred async!
35
- yield
36
- else
37
- yield unless is_deferred?
38
- end
39
- end
40
- end
41
- div class: 'matestack-async-component-wrapper', 'v-if': 'asyncTemplate != null', 'v-bind:class': '{ "loading": loading === true }' do
42
- Matestack::Ui::Core::Base.new('v-runtime-template', ':template': 'asyncTemplate')
43
- end
44
- end
45
- end
46
- end
47
- end
48
-
49
- def async_attributes
50
- options.merge({
51
- id: ctx.id,
52
- class: 'matestack-async-component-root',
53
- 'v-if': 'showing'
54
- })
55
- end
56
-
57
- def vue_props
58
- {
59
- component_key: ctx.id,
60
- show_on: ctx.show_on,
61
- hide_on: ctx.hide_on,
62
- rerender_on: ctx.rerender_on,
63
- defer: ctx.defer,
64
- parent_class: isolated_parent ? isolated_parent.class.to_s : nil,
65
- }
66
- end
67
-
68
- def is_deferred?
69
- ctx.defer
70
- end
71
-
72
- def is_not_requested?
73
- params[:component_key].present? && params[:component_key] != ctx.id
74
- end
75
-
76
- def isolated_parent
77
- Matestack::Ui::Core::Context.isolated_parent
78
- end
79
-
80
- end
81
- end
82
- end
83
- end
84
- end
@@ -1,100 +0,0 @@
1
- import Vue from 'vue/dist/vue.esm'
2
- import VRuntimeTemplate from "v-runtime-template"
3
- import matestackEventHub from '../event_hub'
4
- import componentMixin from './mixin'
5
-
6
- const componentDef = {
7
- mixins: [componentMixin],
8
- props: {
9
- initialTemplate: String,
10
- },
11
- data: function(){
12
- return {
13
- cableTemplate: null,
14
- cableTemplateDomElement: null,
15
- loading: false,
16
- event: {
17
- data: {}
18
- }
19
- }
20
- },
21
- methods: {
22
- append: function(payload){
23
- var html = this.formatPayload(payload)
24
- this.cableTemplateDomElement.insertAdjacentHTML(
25
- 'beforeend',
26
- html.join('')
27
- )
28
- this.updateCableTemplate()
29
- },
30
- prepend: function(payload){
31
- var html = this.formatPayload(payload)
32
- this.cableTemplateDomElement.insertAdjacentHTML(
33
- 'afterbegin',
34
- html.join('')
35
- )
36
- this.updateCableTemplate()
37
- },
38
- delete: function(payload){
39
- var ids = this.formatPayload(payload)
40
- ids.forEach(id =>
41
- this.cableTemplateDomElement.querySelector('#' + id).remove()
42
- )
43
- this.updateCableTemplate()
44
- },
45
- update: function(payload){
46
- const self = this
47
- var html = this.formatPayload(payload)
48
- html.forEach(function(elem){
49
- var dom_elem = document.createElement('div')
50
- dom_elem.innerHTML = elem.replace(/^\s+|\s+$/g, '')
51
- var id = dom_elem.firstChild.id
52
- var old_elem = self.cableTemplateDomElement.querySelector('#' + id)
53
- old_elem.parentNode.replaceChild(dom_elem.firstChild, old_elem)
54
- })
55
- this.updateCableTemplate()
56
- },
57
- replace: function(payload){
58
- var html = this.formatPayload(payload)
59
- this.cableTemplateDomElement.innerHTML = html.join('')
60
- this.updateCableTemplate()
61
- },
62
- updateCableTemplate: function(){
63
- this.cableTemplate = this.cableTemplateDomElement.outerHTML
64
- },
65
- formatPayload: function(payload){
66
- if(!Array.isArray(payload.data)){
67
- return [payload.data]
68
- }
69
- return payload.data
70
- },
71
- },
72
- mounted: function() {
73
- const self = this
74
- var dom_elem = document.createElement('div')
75
- dom_elem.innerHTML = this.initialTemplate
76
- this.cableTemplateDomElement = dom_elem.querySelector("#" + this.props["id"])
77
- this.cableTemplate = this.cableTemplateDomElement.outerHTML
78
- this.registerEvents(this.props['append_on'], self.append)
79
- this.registerEvents(this.props['prepend_on'], self.prepend)
80
- this.registerEvents(this.props['delete_on'], self.delete)
81
- this.registerEvents(this.props['update_on'], self.update)
82
- this.registerEvents(this.props['replace_on'], self.replace)
83
- },
84
- beforeDestroy: function() {
85
- const self = this
86
- this.cableTemplate = null
87
- this.removeEvents(this.props['append_on'], self.append)
88
- this.removeEvents(this.props['prepend_on'], self.prepend)
89
- this.removeEvents(this.props['delete_on'], self.delete)
90
- this.removeEvents(this.props['update_on'], self.update)
91
- this.removeEvents(this.props['replace_on'], self.replace)
92
- },
93
- components: {
94
- VRuntimeTemplate: VRuntimeTemplate
95
- }
96
- }
97
-
98
- let component = Vue.component('matestack-ui-core-cable', componentDef)
99
-
100
- export default componentDef
@@ -1,69 +0,0 @@
1
- module Matestack
2
- module Ui
3
- module VueJs
4
- module Components
5
- class Cable < Matestack::Ui::VueJs::Vue
6
- vue_name 'matestack-ui-core-cable'
7
-
8
- attr_accessor :block_content
9
-
10
- required :id
11
- optional :append_on, :prepend_on, :delete_on, :update_on, :replace_on
12
-
13
- def create_children(&block)
14
- # first render block content
15
- self.block_content = content(&block).render_content if block_given?
16
- super
17
- end
18
-
19
- def content(&block)
20
- Matestack::Ui::Core::Base.new(:without_parent, nil, nil) do
21
- div(class: 'matestack-cable-component-root', id: ctx.id, &block)
22
- end
23
- end
24
-
25
- def component_attributes
26
- super.merge('v-bind:initial-template': "#{self.block_content.to_json}")
27
- end
28
-
29
- def response
30
- div container_attributes do
31
- div wrapper_attributes do
32
- Matestack::Ui::Core::Base.new('v-runtime-template', ':template': 'cableTemplate')
33
- end
34
- end
35
- end
36
-
37
- def container_attributes
38
- {
39
- class: 'matestack-cable-component-container',
40
- 'v-bind:class': '{ loading: loading === true }'
41
- }
42
- end
43
-
44
- def wrapper_attributes
45
- {
46
- class: 'matestack-cable-component-wrapper',
47
- 'v-if': 'cableTemplate != null',
48
- 'v-bind:class': '{ loading: loading === true }'
49
- }
50
- end
51
-
52
- def vue_props
53
- {
54
- id: ctx.id,
55
- component_key: ctx.id,
56
- # events
57
- append_on: ctx.append_on,
58
- prepend_on: ctx.prepend_on,
59
- delete_on: ctx.delete_on,
60
- update_on: ctx.update_on,
61
- replace_on: ctx.replace_on,
62
- }
63
- end
64
-
65
- end
66
- end
67
- end
68
- end
69
- end
@@ -1,97 +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
- currentLimit: null,
11
- currentOffset: null,
12
- currentFilteredCount: null,
13
- currentBaseCount: null
14
- }
15
- },
16
- methods: {
17
- next: function(){
18
- if (this.currentTo() < this.currentCount()){
19
- this.currentOffset += this.currentLimit
20
- var url = queryParamsHelper.updateQueryParams(this.props["id"] + "-offset", this.currentOffset)
21
- window.history.pushState({matestackApp: true, url: url}, null, url);
22
- matestackEventHub.$emit(this.props["id"] + "-update")
23
- }
24
- },
25
- previous: function(){
26
- if ((this.currentOffset - this.currentLimit)*-1 != this.currentLimit){
27
- if((this.currentOffset - this.currentLimit) < 0){
28
- this.currentOffset = 0
29
- } else {
30
- this.currentOffset -= this.currentLimit
31
- }
32
- var url = queryParamsHelper.updateQueryParams(this.props["id"] + "-offset", this.currentOffset)
33
- window.history.pushState({matestackApp: true, url: url}, null, url);
34
- matestackEventHub.$emit(this.props["id"] + "-update")
35
- }
36
- },
37
- currentTo: function(){
38
- var to = parseInt(this.currentOffset) + parseInt(this.currentLimit)
39
- if (to > parseInt(this.currentCount())){
40
- return this.currentCount();
41
- } else {
42
- return to;
43
- }
44
- },
45
- currentCount: function(){
46
- if (this.currentFilteredCount != null || this.currentFilteredCount != undefined){
47
- return this.currentFilteredCount;
48
- } else {
49
- return this.currentBaseCount;
50
- }
51
- },
52
- goToPage: function(page){
53
- this.currentOffset = parseInt(this.currentLimit) * (parseInt(page)-1)
54
- var url = queryParamsHelper.updateQueryParams(this.props["id"] + "-offset", this.currentOffset)
55
- window.history.pushState({matestackApp: true, url: url}, null, url);
56
- matestackEventHub.$emit(this.props["id"] + "-update")
57
- }
58
- },
59
- mounted: function(){
60
- if(queryParamsHelper.getQueryParam(this.props["id"] + "-offset") != null){
61
- this.currentOffset = parseInt(queryParamsHelper.getQueryParam(this.props["id"] + "-offset"))
62
- } else {
63
- if(this.props["init_offset"] != undefined){
64
- this.currentOffset = this.props["init_offset"]
65
- } else {
66
- this.currentOffset = 0
67
- }
68
- }
69
-
70
- if(queryParamsHelper.getQueryParam(this.props["id"] + "-limit") != null){
71
- this.currentOffset = parseInt(queryParamsHelper.getQueryParam(this.props["id"] + "-limit"))
72
- } else {
73
- if(this.props["init_limit"] != undefined){
74
- this.currentLimit = this.props["init_limit"]
75
- } else {
76
- this.currentLimit = 10
77
- }
78
- }
79
-
80
- if(this.props["filtered_count"] != undefined){
81
- this.currentFilteredCount = this.props["filtered_count"]
82
- if(this.currentOffset >= this.currentFilteredCount){
83
- this.previous()
84
- }
85
- }
86
- if(this.props["base_count"] != undefined){
87
- this.currentBaseCount = this.props["base_count"]
88
- if(this.currentOffset >= this.currentBaseCount){
89
- this.previous()
90
- }
91
- }
92
- }
93
- }
94
-
95
- let component = Vue.component('matestack-ui-core-collection-content', componentDef)
96
-
97
- export default componentDef
@@ -1,32 +0,0 @@
1
- module Matestack
2
- module Ui
3
- module VueJs
4
- module Components
5
- module Collection
6
- class Content < Matestack::Ui::VueJs::Vue
7
- vue_name 'matestack-ui-core-collection-content'
8
-
9
- required :id
10
- optional :init_limit, :filtered_count, :base_count
11
-
12
- def response
13
- div class: "matestack-ui-core-collection-content" do
14
- yield
15
- end
16
- end
17
-
18
- def vue_props
19
- {
20
- id: ctx.id,
21
- init_limit: ctx.init_limit,
22
- filtered_count: ctx.filtered_count,
23
- base_count: ctx.base_count
24
- }
25
- end
26
-
27
- end
28
- end
29
- end
30
- end
31
- end
32
- end