Skip to content

Commit

Permalink
fix(core): fix lag in spinner, loading page title
Browse files Browse the repository at this point in the history
  • Loading branch information
anotherchrisberry committed May 12, 2017
1 parent eadcb81 commit 8f1de45
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion app/index.deck
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!doctype html>
<html class="no-js" ng-app="netflix.spinnaker">
<head>
<title ng-bind="pageTitle">Spinnaker</title>
<title>Spinnaker</title>
<meta charset="utf-8">
<meta name="description" content="">
<meta name="viewport" content="width=device-width">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('Service: pageTitleService', function() {
var scope = this.$rootScope;

expect(scope.routing).toBeFalsy();
expect(document.title).toBe('');
document.title = 'Spinnaker!';

this.pageTitleService.handleRoutingStart();
expect(scope.routing).toBeTruthy();
Expand Down
17 changes: 11 additions & 6 deletions app/scripts/modules/core/pageTitle/pageTitle.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,12 @@ interface IPageDataParts {
}

export class PageTitleService {
public static $inject = [ '$rootScope', '$stateParams', '$transitions' ];

private previousPageTitle = 'Spinnaker';
private routeCount = 0;

constructor(private $rootScope: IScope, private $stateParams: StateParams, $transitions: TransitionService) {
$rootScope.routing = 0;

'ngInject';
document.title = 'Spinnaker: Loading...';
$transitions.onStart({}, transition => {
this.handleRoutingStart();
const onSuccess = () => this.handleRoutingSuccess(transition.to().data);
Expand All @@ -46,13 +45,15 @@ export class PageTitleService {
}

public handleRoutingStart(): void {
this.$rootScope.routing++;
this.routeCount++;
this.previousPageTitle = document.title;
this.setRoutingFlag();
document.title = 'Spinnaker: Loading...';
}

public handleRoutingError(rejection: Rejection): void {
this.$rootScope.routing--;
this.routeCount--;
this.setRoutingFlag();
const cancelled = rejection.type === RejectType.ABORTED;
document.title = cancelled ? this.previousPageTitle : 'Spinnaker: Error';
}
Expand Down Expand Up @@ -127,6 +128,10 @@ export class PageTitleService {
details: this.configureDetails(data.pageTitleDetails)
};
}

private setRoutingFlag() {
this.$rootScope.routing = this.routeCount > 0;
}
}

export const CORE_PAGETITLE_SERVICE = 'spinnaker.core.pageTitle.service';
Expand Down

0 comments on commit 8f1de45

Please sign in to comment.