Skip to content

Commit fb8f3ab

Browse files
author
Per Ploug Krogslund
committed
Cleaned up WIP
Things now actually run
1 parent 53bb043 commit fb8f3ab

File tree

6 files changed

+163
-154
lines changed

6 files changed

+163
-154
lines changed

src/Umbraco.Web.UI.Client/src/common/services/navigation.service.js

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
* @ngdoc service
33
* @name umbraco.services.navigationService
44
*
5-
* @requires $rootScope
5+
* @requires $rootScope
66
* @requires $routeParams
77
* @requires $log
88
* @requires $location
99
* @requires dialogService
1010
* @requires treeService
1111
* @requires sectionResource
12-
*
12+
*
1313
* @description
1414
* Service to handle the main application navigation. Responsible for invoking the tree
1515
* Section navigation and search, and maintain their state for the entire application lifetime
@@ -41,8 +41,8 @@ function navigationService($rootScope, $routeParams, $log, $location, $q, $timeo
4141
appState.setMenuState("showMenuDialog", false);
4242
appState.setGlobalState("stickyNavigation", false);
4343
appState.setGlobalState("showTray", false);
44-
45-
//$("#search-form input").focus();
44+
45+
//$("#search-form input").focus();
4646
break;
4747
case 'menu':
4848
appState.setGlobalState("navMode", "menu");
@@ -94,8 +94,8 @@ function navigationService($rootScope, $routeParams, $log, $location, $q, $timeo
9494
init: function() {
9595

9696
setTreeMode();
97-
98-
//keep track of the current section - initially this will always be undefined so
97+
98+
//keep track of the current section - initially this will always be undefined so
9999
// no point in setting it now until it changes.
100100
$rootScope.$watch(function () {
101101
return $routeParams.section;
@@ -118,7 +118,7 @@ function navigationService($rootScope, $routeParams, $log, $location, $q, $timeo
118118
* Shows the legacy iframe and loads in the content based on the source url
119119
* @param {String} source The URL to load into the iframe
120120
*/
121-
loadLegacyIFrame: function (source) {
121+
loadLegacyIFrame: function (source) {
122122
$location.path("/" + appState.getSectionState("currentSection") + "/framed/" + encodeURIComponent(source));
123123
},
124124

@@ -160,7 +160,7 @@ function navigationService($rootScope, $routeParams, $log, $location, $q, $timeo
160160
showTree: function (sectionAlias, syncArgs) {
161161
if (sectionAlias !== appState.getSectionState("currentSection")) {
162162
appState.setSectionState("currentSection", sectionAlias);
163-
163+
164164
if (syncArgs) {
165165
this.syncTree(syncArgs);
166166
}
@@ -176,7 +176,7 @@ function navigationService($rootScope, $routeParams, $log, $location, $q, $timeo
176176
appState.setGlobalState("showTray", false);
177177
},
178178

179-
/**
179+
/**
180180
Called to assign the main tree event handler - this is called by the navigation controller.
181181
TODO: Potentially another dev could call this which would kind of mung the whole app so potentially there's a better way.
182182
*/
@@ -190,7 +190,7 @@ function navigationService($rootScope, $routeParams, $log, $location, $q, $timeo
190190

191191
//when a tree node is synced this event will fire, this allows us to set the currentNode
192192
mainTreeEventHandler.bind("treeSynced", function (ev, args) {
193-
193+
194194
if (args.activate === undefined || args.activate === true) {
195195
//set the current selected node
196196
appState.setTreeState("selectedNode", args.node);
@@ -207,7 +207,7 @@ function navigationService($rootScope, $routeParams, $log, $location, $q, $timeo
207207

208208
//Set the current action node (this is not the same as the current selected node!)
209209
appState.setMenuState("currentNode", args.node);
210-
210+
211211
if (args.event && args.event.altKey) {
212212
args.skipDefault = true;
213213
}
@@ -231,7 +231,7 @@ function navigationService($rootScope, $routeParams, $log, $location, $q, $timeo
231231
ev.preventDefault();
232232

233233
if (n.metaData && n.metaData["jsClickCallback"] && angular.isString(n.metaData["jsClickCallback"]) && n.metaData["jsClickCallback"] !== "") {
234-
//this is a legacy tree node!
234+
//this is a legacy tree node!
235235
var jsPrefix = "javascript:";
236236
var js;
237237
if (n.metaData["jsClickCallback"].startsWith(jsPrefix)) {
@@ -254,7 +254,7 @@ function navigationService($rootScope, $routeParams, $log, $location, $q, $timeo
254254
else if (n.routePath) {
255255
//add action to the history service
256256
historyService.add({ name: n.name, link: n.routePath, icon: n.icon });
257-
257+
258258
//put this node into the tree state
259259
appState.setTreeState("selectedNode", args.node);
260260
//when a node is clicked we also need to set the active menu node to this node
@@ -280,7 +280,7 @@ function navigationService($rootScope, $routeParams, $log, $location, $q, $timeo
280280
* The path format is: ["itemId","itemId"], and so on
281281
* so to sync to a specific document type node do:
282282
* <pre>
283-
* navigationService.syncTree({tree: 'content', path: ["-1","123d"], forceReload: true});
283+
* navigationService.syncTree({tree: 'content', path: ["-1","123d"], forceReload: true});
284284
* </pre>
285285
* @param {Object} args arguments passed to the function
286286
* @param {String} args.tree the tree alias to sync to
@@ -298,7 +298,7 @@ function navigationService($rootScope, $routeParams, $log, $location, $q, $timeo
298298
if (!args.tree) {
299299
throw "args.tree cannot be null";
300300
}
301-
301+
302302
if (mainTreeEventHandler) {
303303
//returns a promise
304304
return mainTreeEventHandler.syncTree(args);
@@ -308,8 +308,8 @@ function navigationService($rootScope, $routeParams, $log, $location, $q, $timeo
308308
return angularHelper.rejectedPromise();
309309
},
310310

311-
/**
312-
Internal method that should ONLY be used by the legacy API wrapper, the legacy API used to
311+
/**
312+
Internal method that should ONLY be used by the legacy API wrapper, the legacy API used to
313313
have to set an active tree and then sync, the new API does this in one method by using syncTree
314314
*/
315315
_syncPath: function(path, forceReload) {
@@ -333,16 +333,16 @@ function navigationService($rootScope, $routeParams, $log, $location, $q, $timeo
333333
}
334334
},
335335

336-
/**
337-
Internal method that should ONLY be used by the legacy API wrapper, the legacy API used to
336+
/**
337+
Internal method that should ONLY be used by the legacy API wrapper, the legacy API used to
338338
have to set an active tree and then sync, the new API does this in one method by using syncTreePath
339339
*/
340340
_setActiveTreeType: function (treeAlias, loadChildren) {
341341
if (mainTreeEventHandler) {
342342
mainTreeEventHandler._setActiveTreeType(treeAlias, loadChildren);
343343
}
344344
},
345-
345+
346346
/**
347347
* @ngdoc method
348348
* @name umbraco.services.navigationService#hideTree
@@ -367,7 +367,7 @@ function navigationService($rootScope, $routeParams, $log, $location, $q, $timeo
367367
* @methodOf umbraco.services.navigationService
368368
*
369369
* @description
370-
* Hides the tree by hiding the containing dom element.
370+
* Hides the tree by hiding the containing dom element.
371371
* This always returns a promise!
372372
*
373373
* @param {Event} event the click event triggering the method, passed from the DOM element
@@ -393,7 +393,7 @@ function navigationService($rootScope, $routeParams, $log, $location, $q, $timeo
393393

394394
//NOTE: This is assigning the current action node - this is not the same as the currently selected node!
395395
appState.setMenuState("currentNode", args.node);
396-
396+
397397
//ensure the current dialog is cleared before creating another!
398398
if (currentDialog) {
399399
dialogService.close(currentDialog);
@@ -411,13 +411,13 @@ function navigationService($rootScope, $routeParams, $log, $location, $q, $timeo
411411
}
412412
}
413413

414-
//there is no default or we couldn't find one so just continue showing the menu
414+
//there is no default or we couldn't find one so just continue showing the menu
415415

416416
setMode("menu");
417417

418418
appState.setMenuState("currentNode", args.node);
419419
appState.setMenuState("menuActions", data.menuItems);
420-
appState.setMenuState("dialogTitle", args.node.name);
420+
appState.setMenuState("dialogTitle", args.node.name);
421421

422422
//we're not opening a dialog, return null.
423423
deferred.resolve(null);
@@ -448,7 +448,7 @@ function navigationService($rootScope, $routeParams, $log, $location, $q, $timeo
448448
throw "action cannot be null";
449449
}
450450
if (!node) {
451-
throw "node cannot be null";
451+
throw "node cannot be null";
452452
}
453453
if (!section) {
454454
throw "section cannot be null";
@@ -467,9 +467,9 @@ function navigationService($rootScope, $routeParams, $log, $location, $q, $timeo
467467
var menuAction = action.metaData["jsAction"].split('.');
468468
if (menuAction.length !== 2) {
469469

470-
//if it is not two parts long then this most likely means that it's a legacy action
470+
//if it is not two parts long then this most likely means that it's a legacy action
471471
var js = action.metaData["jsAction"].replace("javascript:", "");
472-
//there's not really a different way to acheive this except for eval
472+
//there's not really a different way to acheive this except for eval
473473
eval(js);
474474
}
475475
else {
@@ -526,8 +526,8 @@ function navigationService($rootScope, $routeParams, $log, $location, $q, $timeo
526526
modalClass: "umb-modal-left",
527527
show: true
528528
});
529-
530-
529+
530+
531531

532532
return userDialog;
533533
},
@@ -553,7 +553,7 @@ function navigationService($rootScope, $routeParams, $log, $location, $q, $timeo
553553
modalClass: "umb-modal-left",
554554
show: true
555555
});
556-
556+
557557
return service.helpDialog;
558558
},
559559

@@ -566,13 +566,13 @@ function navigationService($rootScope, $routeParams, $log, $location, $q, $timeo
566566
* Opens a dialog, for a given action on a given tree node
567567
* uses the dialogService to inject the selected action dialog
568568
* into #dialog div.umb-panel-body
569-
* the path to the dialog view is determined by:
569+
* the path to the dialog view is determined by:
570570
* "views/" + current tree + "/" + action alias + ".html"
571571
* The dialog controller will get passed a scope object that is created here with the properties:
572572
* scope.currentNode = the selected tree node
573573
* scope.currentAction = the selected menu item
574574
* so that the dialog controllers can use these properties
575-
*
575+
*
576576
* @param {Object} args arguments passed to the function
577577
* @param {Scope} args.scope current scope passed to the dialog
578578
* @param {Object} args.action the clicked action containing `name` and `alias`
@@ -651,14 +651,14 @@ function navigationService($rootScope, $routeParams, $log, $location, $q, $timeo
651651
}
652652

653653
//TODO: some action's want to launch a new window like live editing, we support this in the menu item's metadata with
654-
// a key called: "actionUrlMethod" which can be set to either: Dialog, BlankWindow. Normally this is always set to Dialog
655-
// if a URL is specified in the "actionUrl" metadata. For now I'm not going to implement launching in a blank window,
654+
// a key called: "actionUrlMethod" which can be set to either: Dialog, BlankWindow. Normally this is always set to Dialog
655+
// if a URL is specified in the "actionUrl" metadata. For now I'm not going to implement launching in a blank window,
656656
// though would be v-easy, just not sure we want to ever support that?
657657

658658
var dialog = dialogService.open(
659659
{
660660
container: $(".app-navigation-dialog .umb-modalcolumn-body"),
661-
//The ONLY reason we're passing in scope to the dialogService (which is legacy functionality) is
661+
//The ONLY reason we're passing in scope to the dialogService (which is legacy functionality) is
662662
// for backwards compatibility since many dialogs require $scope.currentNode or $scope.currentAction
663663
// to exist
664664
scope: dialogScope,
@@ -687,9 +687,9 @@ function navigationService($rootScope, $routeParams, $log, $location, $q, $timeo
687687
* hides the currently open dialog
688688
*/
689689
hideDialog: function (showMenu) {
690-
690+
691691
setMode("default");
692-
692+
693693
if(showMenu){
694694
this.showMenu(undefined, { skipDefault: true, node: appState.getMenuState("currentNode") });
695695
}

src/Umbraco.Web.UI.Client/src/common/services/user.service.js

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,25 @@ angular.module('umbraco.services')
88
// this is used so that we know when to go and get the user's remaining seconds directly.
99
var lastServerTimeoutSet = null;
1010

11-
/**
12-
This methods will set the current user when it is resolved and
13-
will then start the counter to count in-memory how many seconds they have
11+
/**
12+
This methods will set the current user when it is resolved and
13+
will then start the counter to count in-memory how many seconds they have
1414
remaining on the auth session
1515
*/
16-
function setCurrentUser(usr) {
17-
if (!usr.remainingAuthSeconds) {
16+
function setCurrentUser(data) {
17+
if (!data.remainingAuthSeconds) {
1818
throw "The user object is invalid, the remainingAuthSeconds is required.";
1919
}
20-
currentUser = usr;
20+
21+
currentUser = data;
2122
lastServerTimeoutSet = new Date();
23+
2224
//start the timer
2325
countdownUserTimeout();
2426
}
2527

26-
/**
27-
Method to count down the current user's timeout seconds,
28+
/**
29+
Method to count down the current user's timeout seconds,
2830
this will continually count down their current remaining seconds every 2 seconds until
2931
there are no more seconds remaining.
3032
*/
@@ -39,16 +41,16 @@ angular.module('umbraco.services')
3941
//if there are more than 30 remaining seconds, recurse!
4042
if (currentUser.remainingAuthSeconds > 30) {
4143

42-
//we need to check when the last time the timeout was set from the server, if
43-
// it has been more than 30 seconds then we'll manually go and retrieve it from the
44+
//we need to check when the last time the timeout was set from the server, if
45+
// it has been more than 30 seconds then we'll manually go and retrieve it from the
4446
// server - this helps to keep our local countdown in check with the true timeout.
4547
if (lastServerTimeoutSet != null) {
4648
var now = new Date();
4749
var seconds = (now.getTime() - lastServerTimeoutSet.getTime()) / 1000;
4850

4951
if (seconds > 30) {
5052

51-
//first we'll set the lastServerTimeoutSet to null - this is so we don't get back in to this loop while we
53+
//first we'll set the lastServerTimeoutSet to null - this is so we don't get back in to this loop while we
5254
// wait for a response from the server otherwise we'll be making double/triple/etc... calls while we wait.
5355
lastServerTimeoutSet = null;
5456

@@ -67,7 +69,7 @@ angular.module('umbraco.services')
6769
}
6870
else {
6971

70-
//we are either timed out or very close to timing out so we need to show the login dialog.
72+
//we are either timed out or very close to timing out so we need to show the login dialog.
7173
if (Umbraco.Sys.ServerVariables.umbracoSettings.keepUserLoggedIn !== true) {
7274
//NOTE: the safeApply because our timeout is set to not run digests (performance reasons)
7375
angularHelper.safeApply($rootScope, function () {
@@ -78,7 +80,7 @@ angular.module('umbraco.services')
7880
//we've got less than 30 seconds remaining so let's check the server
7981

8082
if (lastServerTimeoutSet != null) {
81-
//first we'll set the lastServerTimeoutSet to null - this is so we don't get back in to this loop while we
83+
//first we'll set the lastServerTimeoutSet to null - this is so we don't get back in to this loop while we
8284
// wait for a response from the server otherwise we'll be making double/triple/etc... calls while we wait.
8385
lastServerTimeoutSet = null;
8486

@@ -158,7 +160,7 @@ angular.module('umbraco.services')
158160
});
159161
},
160162

161-
/** Logs the user out
163+
/** Logs the user out
162164
*/
163165
logout: function () {
164166

@@ -177,7 +179,11 @@ angular.module('umbraco.services')
177179
if (!currentUser) {
178180
authResource.getCurrentUser()
179181
.then(function (data) {
180-
var result = { user: data, authenticated: true, lastUserId: lastUserId };
182+
183+
var result = data;
184+
result.authenticated = true;
185+
result.lastUserId = lastUserId;
186+
181187
setCurrentUser(result);
182188
deferred.resolve(currentUser);
183189
});
@@ -195,4 +201,4 @@ angular.module('umbraco.services')
195201
}
196202
};
197203

198-
});
204+
});

0 commit comments

Comments
 (0)