Skip to content

Commit a72e85a

Browse files
committed
Merge branch 'add_loading_state_to_page_and_app' into next-release
2 parents 4462d91 + d5b9fb1 commit a72e85a

File tree

33 files changed

+335
-123
lines changed

33 files changed

+335
-123
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
%component{"is": "matestack-ui-core-app", "inline-template": true}
2-
%div{class: "matestack_app"}
2+
%div{class: "matestack-app-wrapper"}
33
= render_content

app/concepts/matestack/ui/core/app/app.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import Vue from 'vue/dist/vue.esm'
22
import VRuntimeTemplate from "v-runtime-template"
33
import Vuex from 'vuex'
44
import isNavigatingToAnotherPage from "./location"
5+
import matestackEventHub from '../js/event-hub'
56

67
const componentDef = {
78
props: ['appConfig', 'params'],
@@ -22,7 +23,11 @@ const componentDef = {
2223
pathName: self.currentPathName,
2324
search: self.currentSearch
2425
}, document.location)){
25-
self.$store.dispatch("navigateTo", { url: document.location.pathname + document.location.search, backwards: true } );
26+
matestackEventHub.$emit("page_loading_triggered", document.location.pathname + document.location.search);
27+
this.$store.commit('setPageLoading', true);
28+
this.$store.commit('setPageLoadingStart', true);
29+
this.$store.commit('setPageLoadingEnd', false)
30+
self.$store.dispatch("navigateTo", { url: document.location.pathname + document.location.search, backwards: true } );
2631
}
2732
})
2833
},

app/concepts/matestack/ui/core/app/app.rb

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,29 @@ def response
2323
page_content
2424
end
2525

26-
def page_content
27-
# TODO: Content probably needs/would benefit from a better name - like "DynamicWrapper" ?
28-
add_child Matestack::Ui::Core::Page::Content do
26+
# new alternative method name to be used in app defentions
27+
# slots may contain a loading state element will be rendered during form start to finish of a transition
28+
def yield_page slots: {}
29+
page_content_wrapper slots: slots do
2930
add_child @page_class,
3031
controller_instance: @controller_instance,
3132
context: context
3233
end
3334
end
35+
36+
def page_content slots: {}
37+
yield_page slots: slots
38+
end
39+
40+
41+
# def page_content loading_state_element_slot: nil
42+
# # TODO: Content probably needs/would benefit from a better name - like "DynamicWrapper" ?
43+
# context[:loading_state_element_slot] = loading_state_element_slot
44+
# add_child Matestack::Ui::Core::Page::Content, context: context do
45+
# add_child @page_class,
46+
# controller_instance: @controller_instance,
47+
# context: context
48+
# end
49+
# end
3450
end
3551
end

app/concepts/matestack/ui/core/app/store.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Vue.use(Vuex)
88
const store = new Vuex.Store({
99
state: {
1010
pageTemplate: null,
11+
pageLoading: false,
1112
currentPathName: document.location.pathname,
1213
currentSearch: document.location.search,
1314
currentOrigin: document.location.origin
@@ -16,6 +17,9 @@ const store = new Vuex.Store({
1617
setPageTemplate (state, serverResponse){
1718
state.pageTemplate = serverResponse
1819
},
20+
setPageLoading (state, boolean){
21+
state.pageLoading = boolean
22+
},
1923
setCurrentLocation (state, current){
2024
state.currentPathName = current.path
2125
state.currentSearch = current.search
@@ -27,6 +31,8 @@ const store = new Vuex.Store({
2731
},
2832
actions: {
2933
navigateTo ({ commit, state }, { url, backwards }) {
34+
const self = this
35+
commit('setPageLoading', true)
3036
matestackEventHub.$emit("page_loading", url);
3137
if (typeof matestackUiCoreTransitionStart !== 'undefined') {
3238
matestackUiCoreTransitionStart(url);
@@ -54,6 +60,7 @@ const store = new Vuex.Store({
5460
resolve(response["data"]);
5561
commit('setPageTemplate', response["data"])
5662
commit('setCurrentLocation', { path: url.split("?")[0], search: document.location.search, origin: document.location.origin })
63+
commit('setPageLoading', false)
5764
matestackEventHub.$emit("page_loaded", url);
5865
if (typeof matestackUiCoreTransitionSuccess !== 'undefined') {
5966
matestackUiCoreTransitionSuccess(url);

app/concepts/matestack/ui/core/async/async.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@ const componentDef = {
5656
headers: {
5757
'X-CSRF-Token': document.getElementsByName("csrf-token")[0].getAttribute('content')
5858
},
59-
params: {"component_key": self.componentConfig["component_key"]}
59+
params: {
60+
"component_key": self.componentConfig["component_key"],
61+
"component_class": self.componentConfig["parent_class"]
62+
}
6063
})
6164
.then(function(response){
6265
var tmp_dom_element = document.createElement('div');

app/concepts/matestack/ui/core/component/base.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def initialize(model = nil, options = {})
6363
# it inbetween the super calls in the Dynamic super class.
6464
#
6565
# This is the configuration for the VueJS component
66-
@component_config = @options.except(:context, :children, :url_params, :included_config, :matestack_context)
66+
@component_config = @options.except(:context, :children, :url_params, :included_config, :matestack_context, :slots)
6767

6868
# TODO: no idea why this is called `url_params` it contains
6969
# much more than this e.g. almost all params so maybe rename it?
@@ -159,7 +159,11 @@ def prepare
159159

160160
# access params like you would do on rails views and controllers
161161
def params
162-
context[:params]
162+
if @matestack_context.present? && @matestack_context[:controller].present?
163+
@matestack_context[:controller].params
164+
else
165+
context[:params]
166+
end
163167
end
164168

165169
## ------------------ Rendering ----------------

app/concepts/matestack/ui/core/component/dynamic.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def show
1313

1414
def dynamic_tag_attributes
1515
attrs = {
16-
"is": self.class.vue_js_name,
16+
"is": get_vue_js_name,
1717
"ref": component_id,
1818
":params": params.except(:controller, :action).to_json,
1919
":component-config": @component_config.to_json,
@@ -23,6 +23,14 @@ def dynamic_tag_attributes
2323
attrs
2424
end
2525

26+
def get_vue_js_name
27+
if @vue_js_component_name.present?
28+
@vue_js_component_name
29+
else
30+
self.class.vue_js_name
31+
end
32+
end
33+
2634
class << self
2735
def vue_js_component_name(name)
2836
@vue_js_name = name.to_s

app/concepts/matestack/ui/core/isolate/isolate.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
module Matestack::Ui::Core::Isolate
22
class Isolate < Matestack::Ui::Core::Component::Dynamic
33

4-
def vuejs_component_name
5-
"matestack-ui-core-isolate"
6-
end
4+
vue_js_component_name "matestack-ui-core-isolate"
75

86
def initialize(*args)
97
super
108
@public_options = args.map { |hash| hash[:public_options] }[0]
9+
# using this instance var here as users inherit from this class and would need
10+
# to use `vue_js_component_name "matestack-ui-core-isolate"` in their components
11+
# which is not convinient
12+
@vue_js_component_name = "matestack-ui-core-isolate"
1113
end
1214

1315
def public_options

app/concepts/matestack/ui/core/js/core.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import { turbolinksAdapterMixin } from 'vue-turbolinks';
44
// Import from app/concepts/matestack/ui/core:
55
import app from '../app/app'
66
import async from '../async/async'
7+
import pageContent from '../page/content/content'
78
import toggle from '../toggle/toggle'
8-
import pageContent from '../page/content'
99
import store from '../app/store'
1010
import component from '../component/component'
1111
import anonymDynamicComponent from '../component/anonym-dynamic-component'
@@ -28,7 +28,7 @@ document.addEventListener('DOMContentLoaded', () => {
2828
// if they were present on the first page, which was loaded and activated turbolinks
2929
// the mixin does not impact the app when turbolinks is disabled
3030
matestackUiApp = new Vue({
31-
el: "#matestack_ui",
31+
el: "#matestack-ui",
3232
mixins: [turbolinksAdapterMixin],
3333
store: store
3434
})
@@ -45,7 +45,7 @@ document.addEventListener('turbolinks:load', () => {
4545
matestackUiApp.$destroy();
4646
// and recreate it right afterwards in order to work when used with turbolinks
4747
matestackUiApp = new Vue({
48-
el: "#matestack_ui",
48+
el: "#matestack-ui",
4949
mixins: [turbolinksAdapterMixin],
5050
store: store
5151
})

app/concepts/matestack/ui/core/page/content.haml

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)