From 752564aa804e2b432662252da5b3a4cbd5ec4c65 Mon Sep 17 00:00:00 2001 From: Kevin Jump Date: Mon, 10 Jun 2019 16:36:03 +0100 Subject: [PATCH] use relative paths in angular #28 --- .../uSync8/uSyncDashboardController.js | 6 ++--- .../App_Plugins/uSync8/uSyncHub.js | 4 +-- .../App_Plugins/uSync8/uSyncService.js | 2 +- .../uSyncDashboardApiController.cs | 5 ++++ uSync8.BackOffice/uSyncBackofficeComponent.cs | 27 ++++++++++++++++++- .../uSync8/uSyncDashboardController.js | 6 ++--- uSync8.Site/App_Plugins/uSync8/uSyncHub.js | 4 +-- .../App_Plugins/uSync8/uSyncService.js | 2 +- 8 files changed, 43 insertions(+), 13 deletions(-) diff --git a/uSync8.BackOffice/App_Plugins/uSync8/backoffice/uSync8/uSyncDashboardController.js b/uSync8.BackOffice/App_Plugins/uSync8/backoffice/uSync8/uSyncDashboardController.js index ee96777f..b558665e 100644 --- a/uSync8.BackOffice/App_Plugins/uSync8/backoffice/uSync8/uSyncDashboardController.js +++ b/uSync8.BackOffice/App_Plugins/uSync8/backoffice/uSync8/uSyncDashboardController.js @@ -14,20 +14,20 @@ 'name': 'uSync', 'alias': 'uSync', 'icon': 'icon-infinity', - 'view': '/App_plugins/usync8/settings/default.html', + 'view': Umbraco.Sys.ServerVariables.umbracoSettings.appPluginsPath + '/usync8/settings/default.html', 'active': true }, { 'name': 'Settings', 'alias': 'settings', 'icon': 'icon-settings', - 'view': '/App_Plugins/uSync8/settings/settings.html' + 'view': Umbraco.Sys.ServerVariables.umbracoSettings.appPluginsPath + '/uSync8/settings/settings.html' }, { 'name': 'Add ons', 'alias': 'expansion', 'icon': 'icon-box', - 'view': '/App_plugins/usync8/settings/expansion.html' + 'view': Umbraco.Sys.ServerVariables.umbracoSettings.appPluginsPath + '/usync8/settings/expansion.html' } ] }; diff --git a/uSync8.BackOffice/App_Plugins/uSync8/uSyncHub.js b/uSync8.BackOffice/App_Plugins/uSync8/uSyncHub.js index 91601567..25bc6694 100644 --- a/uSync8.BackOffice/App_Plugins/uSync8/uSyncHub.js +++ b/uSync8.BackOffice/App_Plugins/uSync8/uSyncHub.js @@ -4,8 +4,8 @@ function uSyncHub($rootScope, $q, assetsService) { var scripts = [ - '/umbraco/lib/signalr/jquery.signalR.js', - '/umbraco/backoffice/signalr/hubs']; + Umbraco.Sys.ServerVariables.umbracoSettings.umbracoPath + '/lib/signalr/jquery.signalR.js', + Umbraco.Sys.ServerVariables.umbracoSettings.umbracoPath + '/backoffice/signalr/hubs']; var resource = { initHub: initHub diff --git a/uSync8.BackOffice/App_Plugins/uSync8/uSyncService.js b/uSync8.BackOffice/App_Plugins/uSync8/uSyncService.js index 06188ccd..470fafd1 100644 --- a/uSync8.BackOffice/App_Plugins/uSync8/uSyncService.js +++ b/uSync8.BackOffice/App_Plugins/uSync8/uSyncService.js @@ -12,7 +12,7 @@ function uSyncServiceController($http) { - var serviceRoot = 'backoffice/uSync/uSyncDashboardApi/'; + var serviceRoot = Umbraco.Sys.ServerVariables.uSync.uSyncService; var service = { getSettings: getSettings, diff --git a/uSync8.BackOffice/Controllers/uSyncDashboardApiController.cs b/uSync8.BackOffice/Controllers/uSyncDashboardApiController.cs index 10dd34aa..4a2fff00 100644 --- a/uSync8.BackOffice/Controllers/uSyncDashboardApiController.cs +++ b/uSync8.BackOffice/Controllers/uSyncDashboardApiController.cs @@ -48,6 +48,11 @@ public uSyncDashboardApiController( uSyncConfig.Reloaded += BackOfficeConfig_Reloaded; } + public bool GetApi() + { + return true; + } + private void BackOfficeConfig_Reloaded(uSyncSettings settings) { this.settings = settings; diff --git a/uSync8.BackOffice/uSyncBackofficeComponent.cs b/uSync8.BackOffice/uSyncBackofficeComponent.cs index a1f8b740..5d082df5 100644 --- a/uSync8.BackOffice/uSyncBackofficeComponent.cs +++ b/uSync8.BackOffice/uSyncBackofficeComponent.cs @@ -1,8 +1,17 @@ using System; +using System.Collections.Generic; +using System.Web; +using System.Web.Mvc; +using System.Web.Routing; + using Umbraco.Core; using Umbraco.Core.Composing; using Umbraco.Core.Logging; +using Umbraco.Web; +using Umbraco.Web.JavaScript; + using uSync8.BackOffice.Configuration; +using uSync8.BackOffice.Controllers; using uSync8.BackOffice.Services; using uSync8.BackOffice.SyncHandlers; @@ -38,6 +47,8 @@ public uSyncBackofficeComponent( public void Initialize() { + ServerVariablesParser.Parsing += ServerVariablesParser_Parsing; + if (runtimeState.Level <= RuntimeLevel.Run) { logger.Info("Umbraco is not in Run Mode {0} so uSync is not going to run", runtimeState.Level); @@ -54,9 +65,23 @@ public void Initialize() { InitBackOffice(); } + + } + + private void ServerVariablesParser_Parsing(object sender, Dictionary e) + { + if (HttpContext.Current == null) + throw new InvalidOperationException("This method requires that an HttpContext be active"); + + var urlHelper = new UrlHelper(new RequestContext(new HttpContextWrapper(HttpContext.Current), new RouteData())); + + e.Add("uSync", new Dictionary + { + { "uSyncService", urlHelper.GetUmbracoApiServiceBaseUrl(controller => controller.GetApi()) } + }); } - private void InitBackOffice() + private void InitBackOffice() { if (globalSettings.ExportAtStartup || (globalSettings.ExportOnSave && !syncFileService.RootExists(globalSettings.RootFolder))) { diff --git a/uSync8.Site/App_Plugins/uSync8/backoffice/uSync8/uSyncDashboardController.js b/uSync8.Site/App_Plugins/uSync8/backoffice/uSync8/uSyncDashboardController.js index 9ad4d0e1..b271379d 100644 --- a/uSync8.Site/App_Plugins/uSync8/backoffice/uSync8/uSyncDashboardController.js +++ b/uSync8.Site/App_Plugins/uSync8/backoffice/uSync8/uSyncDashboardController.js @@ -14,20 +14,20 @@ 'name': 'uSync', 'alias': 'uSync', 'icon': 'icon-infinity', - 'view': '/App_plugins/usync8/settings/default.html', + 'view': Umbraco.Sys.ServerVariables.umbracoSettings.appPluginsPath + '/usync8/settings/default.html', 'active': true }, { 'name': 'Settings', 'alias': 'settings', 'icon': 'icon-settings', - 'view': '/App_Plugins/uSync8/settings/settings.html' + 'view': Umbraco.Sys.ServerVariables.umbracoSettings.appPluginsPath + '/uSync8/settings/settings.html' }, { 'name': 'Add ons', 'alias': 'expansion', 'icon': 'icon-box', - 'view': '/App_plugins/usync8/settings/expansion.html' + 'view': Umbraco.Sys.ServerVariables.umbracoSettings.appPluginsPath + '/usync8/settings/expansion.html' } ] }; diff --git a/uSync8.Site/App_Plugins/uSync8/uSyncHub.js b/uSync8.Site/App_Plugins/uSync8/uSyncHub.js index b0885a9c..5a6cb909 100644 --- a/uSync8.Site/App_Plugins/uSync8/uSyncHub.js +++ b/uSync8.Site/App_Plugins/uSync8/uSyncHub.js @@ -4,8 +4,8 @@ function uSyncHub($rootScope, $q, assetsService) { var scripts = [ - '/umbraco/lib/signalr/jquery.signalR.js', - '/umbraco/backoffice/signalr/hubs']; + Umbraco.Sys.ServerVariables.umbracoSettings.umbracoPath + '/lib/signalr/jquery.signalR.js', + Umbraco.Sys.ServerVariables.umbracoSettings.umbracoPath + '/backoffice/signalr/hubs']; var resource = { initHub: initHub diff --git a/uSync8.Site/App_Plugins/uSync8/uSyncService.js b/uSync8.Site/App_Plugins/uSync8/uSyncService.js index 7c0f3783..ed27a0ef 100644 --- a/uSync8.Site/App_Plugins/uSync8/uSyncService.js +++ b/uSync8.Site/App_Plugins/uSync8/uSyncService.js @@ -12,7 +12,7 @@ function uSyncServiceController($http) { - var serviceRoot = 'backoffice/uSync/uSyncDashboardApi/'; + var serviceRoot = Umbraco.Sys.ServerVariables.uSync.uSyncService; var service = { getSettings: getSettings,