Skip to content

Commit 4b8ba0a

Browse files
committed
Refactored layout
1 parent 92d243a commit 4b8ba0a

File tree

4 files changed

+55
-50
lines changed

4 files changed

+55
-50
lines changed
Lines changed: 41 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
(function () {
22
'use strict';
33

4+
var localize = abp.localization.getSource('SimpleTaskSystem');
5+
46
var app = angular.module('app', [
57
'ngAnimate',
68
'ngRoute',
@@ -12,42 +14,46 @@
1214
'abp'
1315
]);
1416

15-
app.constant('routes', getRoutes());
16-
17-
function getRoutes() {
18-
return [
19-
{
20-
url: '/', //default: /task/list
21-
config: {
22-
templateUrl: '/App/Main/views/task/list.cshtml',
23-
menuItem: 'TaskList'
24-
}
25-
},
26-
{
27-
url: '/task/new',
28-
config: {
29-
templateUrl: '/App/Main/views/task/new.cshtml',
30-
menuItem: 'NewTask'
31-
}
17+
app.constant('routes', [
18+
{
19+
url: '/', //default: /task/list
20+
config: {
21+
templateUrl: '/App/Main/views/task/list.cshtml',
22+
menuText: localize('TaskList'),
23+
menuItem: 'TaskList'
3224
}
33-
];
34-
}
35-
36-
app.config(['$routeProvider', 'routes', routeConfigurator]);
37-
function routeConfigurator($routeProvider, routes) {
38-
39-
routes.forEach(function (r) {
40-
$routeProvider.when(r.url, r.config);
41-
});
25+
},
26+
{
27+
url: '/about',
28+
config: {
29+
templateUrl: '/App/Main/views/task/new.cshtml',
30+
menuText: localize('NewTask'),
31+
menuItem: 'NewTask'
32+
}
33+
}
34+
]);
4235

43-
$routeProvider.otherwise({ redirectTo: abp.appPath });
44-
}
36+
app.config([
37+
'$routeProvider', 'routes',
38+
function ($routeProvider, routes) {
39+
routes.forEach(function (route) {
40+
$routeProvider.when(route.url, route.config);
41+
});
42+
43+
$routeProvider.otherwise({
44+
redirectTo: '/'
45+
});
46+
}
47+
]);
4548

46-
app.run(['$rootScope', '$location', '$routeParams', '$route', function ($rootScope, $location, $routeParams, $route) {
47-
$rootScope.$on('$routeChangeSuccess', function (event, next, current) {
48-
if (next && next.$$route) {
49-
$rootScope.activeMenu = next.$$route.menuItem;
50-
}
51-
});
52-
}]);
49+
app.run([
50+
'$rootScope',
51+
function ($rootScope) {
52+
$rootScope.$on('$routeChangeSuccess', function (event, next, current) {
53+
if (next && next.$$route) {
54+
$rootScope.activeMenu = next.$$route.menuItem; //Used in layout.cshtml to make selected menu 'active'.
55+
}
56+
});
57+
}
58+
]);
5359
})();

SimpleTaskSystemSPA_AngularJs_EntityFramework/SimpleTaskSystem.Web/App/Main/views/layout/layout.cshtml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,8 @@
1111
</div>
1212
<div class="collapse navbar-collapse">
1313
<ul class="nav navbar-nav">
14-
<li ng-class="{active: activeMenu == 'TaskList'}">
15-
<a href="#/">@L("TaskList")</a>
16-
</li>
17-
<li ng-class="{active: activeMenu == 'NewTask'}">
18-
<a href="#/task/new">@L("NewTask")</a>
14+
<li ng-class="{active: activeMenu == route.config.menuItem}" ng-repeat="route in vm.routes">
15+
<a ng-href="#{{route.url}}">{{route.config.menuText}}</a>
1916
</li>
2017
</ul>
2118
<ul class="nav navbar-nav navbar-right">

SimpleTaskSystemSPA_AngularJs_EntityFramework/SimpleTaskSystem.Web/App/Main/views/layout/layout.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
(function () {
2+
var app = angular.module('app');
23

34
var languages = [
45
{
@@ -13,11 +14,12 @@
1314
}
1415
];
1516

16-
var app = angular.module('app');
1717
var controllerId = 'sts.controllers.views.layout';
18-
app.controller(controllerId, ['$scope', function ($scope) {
18+
app.controller(controllerId, ['routes', '$scope', function (routes, $scope) {
1919
var that = this;
20-
20+
21+
that.routes = routes;
22+
2123
that.getLanguageFlagClass = function () {
2224
var lang = abp.localization.currentCulture.name;
2325
for (var i = 0; i < languages.length; i++) {

SimpleTaskSystemSPA_AngularJs_EntityFramework/SimpleTaskSystem.Web/Views/Shared/_Layout.cshtml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<link rel="shortcut icon" href="~/favicon.ico">
1414

1515
<!-- Site title -->
16-
<title>My ASP.NET Boilerplate Project!</title>
16+
<title>Simple Task System!</title>
1717

1818
<!-- Style for jQueryUI -->
1919
<link href="~/Content/themes/base/minified/jquery-ui.min.css" rel="stylesheet" />
@@ -49,12 +49,6 @@
4949
<!-- Modernizr: for feature detection (All other scripts are included at the end of file for faster page load) -->
5050
<script src="~/Scripts/modernizr-2.7.2.js"></script>
5151

52-
</head>
53-
54-
<body>
55-
56-
@RenderBody()
57-
5852
<!-- jQuery and plugins -->
5953
<script src="~/Scripts/json2.min.js"></script>
6054
<script src="~/Scripts/jquery-2.1.1.min.js"></script>
@@ -83,5 +77,11 @@
8377
<!-- Custom scripts for views -->
8478
@RenderSection("scripts", required: false)
8579

80+
</head>
81+
82+
<body>
83+
84+
@RenderBody()
85+
8686
</body>
8787
</html>

0 commit comments

Comments
 (0)