|
|
@@ -1,15 +1,16 @@
|
|
|
-import coreModule from 'app/core/core_module';
|
|
|
+import coreModule from 'app/core/core_module';
|
|
|
import config from 'app/core/config';
|
|
|
import appEvents from 'app/core/app_events';
|
|
|
+import { store } from 'app/stores/store';
|
|
|
+import { reaction } from 'mobx';
|
|
|
|
|
|
-// This service is for registering global events.
|
|
|
-// Good for communication react > angular and vice verse
|
|
|
-export class GlobalEventSrv {
|
|
|
+// Services that handles angular -> mobx store sync & other react <-> angular sync
|
|
|
+export class BridgeSrv {
|
|
|
private appSubUrl;
|
|
|
private fullPageReloadRoutes;
|
|
|
|
|
|
/** @ngInject */
|
|
|
- constructor(private $location, private $timeout, private $window) {
|
|
|
+ constructor(private $location, private $timeout, private $window, private $rootScope) {
|
|
|
this.appSubUrl = config.appSubUrl;
|
|
|
this.fullPageReloadRoutes = ['/logout'];
|
|
|
}
|
|
|
@@ -25,6 +26,31 @@ export class GlobalEventSrv {
|
|
|
}
|
|
|
|
|
|
init() {
|
|
|
+ this.$rootScope.$on('$routeUpdate', (evt, data) => {
|
|
|
+ let angularUrl = this.$location.url();
|
|
|
+ if (store.view.currentUrl !== angularUrl) {
|
|
|
+ store.view.updatePathAndQuery(this.$location.path(), this.$location.search());
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ this.$rootScope.$on('$routeChangeSuccess', (evt, data) => {
|
|
|
+ let angularUrl = this.$location.url();
|
|
|
+ if (store.view.currentUrl !== angularUrl) {
|
|
|
+ store.view.updatePathAndQuery(this.$location.path(), this.$location.search());
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ reaction(
|
|
|
+ () => store.view.currentUrl,
|
|
|
+ currentUrl => {
|
|
|
+ let angularUrl = this.$location.url();
|
|
|
+ if (angularUrl !== currentUrl) {
|
|
|
+ this.$location.url(currentUrl);
|
|
|
+ console.log('store updating angular $location.url', currentUrl);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ );
|
|
|
+
|
|
|
appEvents.on('location-change', payload => {
|
|
|
const urlWithoutBase = this.stripBaseFromUrl(payload.href);
|
|
|
if (this.fullPageReloadRoutes.indexOf(urlWithoutBase) > -1) {
|
|
|
@@ -40,4 +66,4 @@ export class GlobalEventSrv {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-coreModule.service('globalEventSrv', GlobalEventSrv);
|
|
|
+coreModule.service('bridgeSrv', BridgeSrv);
|