Skip to content

Commit 1f38fd6

Browse files
committed
Replace JavaScript application code with TypeScript
1 parent 18b5697 commit 1f38fd6

26 files changed

+3460
-111
lines changed

src/Web/Scripts/_references.js

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

src/Web/Scripts/_references.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/// <reference path="typings/angularjs/angular.d.ts" />

src/Web/Scripts/app.js renamed to src/Web/Scripts/app.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1-
'use strict';
1+
'use strict';
2+
3+
interface IAppRootScopeService extends ng.IRootScopeService {
4+
$state: any;
5+
$stateParams: any;
6+
layout: string;
7+
}
28

39
// Declares how the application should be bootstrapped. See: http://docs.angularjs.org/guide/module
410
angular.module('app', ['ui.router', 'app.filters', 'app.services', 'app.directives', 'app.controllers'])
511

612
// Gets executed during the provider registrations and configuration phase. Only providers and constants can be
713
// injected here. This is to prevent accidental instantiation of services before they have been fully configured.
8-
.config(['$stateProvider', '$locationProvider', function ($stateProvider, $locationProvider) {
14+
.config(['$stateProvider', '$locationProvider', function ($stateProvider, $locationProvider : ng.ILocationProvider) {
915

1016
// UI States, URL Routing & Mapping. For more info see: https://github.com/angular-ui/ui-router
1117
// ------------------------------------------------------------------------------------------------------------
@@ -40,7 +46,7 @@ angular.module('app', ['ui.router', 'app.filters', 'app.services', 'app.directiv
4046

4147
// Gets executed after the injector is created and are used to kickstart the application. Only instances and constants
4248
// can be injected here. This is to prevent further system configuration during application run time.
43-
.run(['$templateCache', '$rootScope', '$state', '$stateParams', function ($templateCache, $rootScope, $state, $stateParams) {
49+
.run(['$templateCache', '$rootScope', '$state', '$stateParams', function ($templateCache: ng.ITemplateCacheService, $rootScope: IAppRootScopeService, $state, $stateParams) {
4450

4551
// <ui-view> contains a pre-rendered template for the current view
4652
// caching it will prevent a round-trip to a server at the first page load
@@ -50,8 +56,7 @@ angular.module('app', ['ui.router', 'app.filters', 'app.services', 'app.directiv
5056
// Allows to retrieve UI Router state information from inside templates
5157
$rootScope.$state = $state;
5258
$rootScope.$stateParams = $stateParams;
53-
54-
$rootScope.$on('$stateChangeSuccess', function (event, toState) {
59+
$rootScope.$on('$stateChangeSuccess', (event, toState?): any => {
5560

5661
// Sets the layout name, which can be used to display different layouts (header, footer etc.)
5762
// based on which page the user is located
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,43 @@
1-
'use strict';
1+
'use strict';
22

33
// Google Analytics Collection APIs Reference:
44
// https://developers.google.com/analytics/devguides/collection/analyticsjs/
55

66
angular.module('app.controllers', [])
77

88
// Path: /
9-
.controller('HomeCtrl', ['$scope', '$location', '$window', function ($scope, $location, $window) {
9+
.controller('HomeCtrl', ['$scope', '$location', '$window', ($scope, $location, $window) => {
1010
$scope.$root.title = 'AngularJS SPA Template for Visual Studio';
11-
$scope.$on('$viewContentLoaded', function () {
11+
$scope.$on('$viewContentLoaded', () => {
1212
$window.ga('send', 'pageview', { 'page': $location.path(), 'title': $scope.$root.title });
1313
});
1414
}])
1515

1616
// Path: /about
17-
.controller('AboutCtrl', ['$scope', '$location', '$window', function ($scope, $location, $window) {
17+
.controller('AboutCtrl', ['$scope', '$location', '$window', ($scope, $location, $window) => {
1818
$scope.$root.title = 'AngularJS SPA | About';
19-
$scope.$on('$viewContentLoaded', function () {
19+
$scope.$on('$viewContentLoaded', () => {
2020
$window.ga('send', 'pageview', { 'page': $location.path(), 'title': $scope.$root.title });
2121
});
2222
}])
2323

2424
// Path: /login
25-
.controller('LoginCtrl', ['$scope', '$location', '$window', function ($scope, $location, $window) {
25+
.controller('LoginCtrl', ['$scope', '$location', '$window', ($scope, $location, $window) => {
2626
$scope.$root.title = 'AngularJS SPA | Sign In';
2727
// TODO: Authorize a user
2828
$scope.login = function () {
2929
$location.path('/');
3030
return false;
3131
};
32-
$scope.$on('$viewContentLoaded', function () {
32+
$scope.$on('$viewContentLoaded', () => {
3333
$window.ga('send', 'pageview', { 'page': $location.path(), 'title': $scope.$root.title });
3434
});
3535
}])
3636

3737
// Path: /error/404
38-
.controller('Error404Ctrl', ['$scope', '$location', '$window', function ($scope, $location, $window) {
38+
.controller('Error404Ctrl', ['$scope', '$location', '$window', ($scope, $location, $window) => {
3939
$scope.$root.title = 'Error 404: Page Not Found';
40-
$scope.$on('$viewContentLoaded', function () {
40+
$scope.$on('$viewContentLoaded', () => {
4141
$window.ga('send', 'pageview', { 'page': $location.path(), 'title': $scope.$root.title });
4242
});
4343
}]);

src/Web/Scripts/controllers.spec.js renamed to src/Web/Scripts/controllersSpec.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
/// <reference path="_references.js" />
2-
/// <reference path="controllers.js" />
1+
/// <chutzpah_reference path="vendor/angular.js" />
2+
/// <chutzpah_reference path="vendor/angular-mocks.js" />
3+
/// <reference path="typings/jasmine/jasmine.d.ts" />
4+
/// <reference path="typings/angularjs/angular-mocks.d.ts" />
5+
/// <reference path="typings/jasmine/jasmine.d.ts" />
6+
/// <reference path="controllers.ts" />
37

48
'use strict';
59

src/Web/Scripts/directives.js

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

src/Web/Scripts/directives.spec.js

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

src/Web/Scripts/directives.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
'use strict';
2+
3+
angular.module('app.directives', [])
4+
5+
.directive('appVersion', ['version', (version) => {
6+
return (scope, elm, attrs) => {
7+
elm.text(version);
8+
};
9+
}]);

src/Web/Scripts/directivesSpec.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/// <chutzpah_reference path="vendor/angular.js" />
2+
/// <chutzpah_reference path="vendor/angular-mocks.js" />
3+
/// <reference path="typings/jasmine/jasmine.d.ts" />
4+
/// <reference path="typings/angularjs/angular-mocks.d.ts" />
5+
/// <reference path="typings/jasmine/jasmine.d.ts" />
6+
/// <reference path="directives.ts" />
7+
8+
'use strict';
9+
10+
describe('Directives', () => {
11+
beforeEach(module('app.directives'));
12+
13+
describe('app-version', () => {
14+
it('should print current version', () => {
15+
module(($provide) => {
16+
$provide.value('version', 'TEST_VER');
17+
});
18+
inject(($compile, $rootScope) => {
19+
var element = $compile('<span app-version></span>')($rootScope);
20+
expect(element.text()).toEqual('TEST_VER');
21+
});
22+
});
23+
});
24+
});

src/Web/Scripts/filters.spec.js

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

0 commit comments

Comments
 (0)