Skip to content

Commit 11a458f

Browse files
committed
Add Controllers and templates for sitewite items, menus and pages.
1 parent d0ce716 commit 11a458f

File tree

9 files changed

+109
-19
lines changed

9 files changed

+109
-19
lines changed

angular/app/_partials/404.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<h1>Not found <span>:(</span></h1>
2+
<p>Sorry, but the page you were trying to view does not exist.</p>
3+
<p>It looks like this was the result of either:</p>
4+
<ul>
5+
<li>a mistyped address</li>
6+
<li>an out-of-date link</li>
7+
</ul>
8+
<script>
9+
var GOOG_FIXURL_LANG = (navigator.language || '').slice(0,2),GOOG_FIXURL_SITE = location.host;
10+
</script>
11+
<script src="//linkhelp.clients.google.com/tbproxy/lh/wm/fixurl.js"></script>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<nav class="navbar" role="navigation">
2+
<ul class="nav navbar-nav">
3+
<li data-ng-repeat="item in mainMenu"><a data-ng-href="{{item.path}}" data-ng-bind="item.title"></a></li>
4+
</ul>
5+
</nav>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
this is a node
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
this is a specific page type template

angular/app/_partials/page.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<div data-ng-include="templateUrl"></div>
2+
page

angular/app/index-async.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
// load all of the dependencies asynchronously.
3232
$script([
3333
'lib/angular/angular.js',
34+
'lib/angular/angular-resource.js',
3435
'js/app.js',
3536
'js/services.js',
3637
'js/controllers.js',
@@ -41,7 +42,7 @@
4142
angular.bootstrap(document, ['myApp']);
4243
});
4344
</script>
44-
<title>My AngularJS App</title>
45+
<title data-ng-bind="site.name"></title>
4546
<link rel="stylesheet" href="css/app.css">
4647
</head>
4748
<body ng-cloak>

angular/app/index.html

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,21 @@
11
<!doctype html>
2-
<html lang="en" ng-app="myApp">
2+
<html lang="en" data-ng-app="myApp" data-ng-controller="SiteCtrl">
33
<head>
44
<meta charset="utf-8">
5-
<title>My AngularJS App</title>
6-
<link rel="stylesheet" href="css/app.css"/>
5+
<title data-ng-bind="site.name"></title>
6+
<link rel="stylesheet" href="/css/app.css"/>
77
</head>
88
<body>
9-
<ul class="menu">
10-
<li><a href="#/view1">view1</a></li>
11-
<li><a href="#/view2">view2</a></li>
12-
</ul>
139

10+
<div data-ng-include="site.templates.mainMenu" data-ng-controller="MainMenuCtrl"></div>
1411
<div ng-view></div>
1512

16-
<div>Angular seed app: v<span app-version></span></div>
17-
18-
<!-- In production use:
19-
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script>
20-
-->
21-
<script src="lib/angular/angular.js"></script>
22-
<script src="js/app.js"></script>
23-
<script src="js/services.js"></script>
24-
<script src="js/controllers.js"></script>
25-
<script src="js/filters.js"></script>
26-
<script src="js/directives.js"></script>
13+
<script src="/lib/angular/angular.js"></script>
14+
<script src="/lib/angular/angular-resource.js"></script>
15+
<script src="/js/app.js"></script>
16+
<script src="/js/services.js"></script>
17+
<script src="/js/controllers.js"></script>
18+
<script src="/js/filters.js"></script>
19+
<script src="/js/directives.js"></script>
2720
</body>
2821
</html>

angular/app/js/app.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
angular.module('myApp', ['myApp.filters', 'myApp.services', 'myApp.directives', 'myApp.controllers'])
44

5+
.config(function($routeProvider) {
6+
$routeProvider
7+
.when('/404', {templateUrl: '/_partials/404.html', controller: '404Ctrl', caseInsensitiveMatch: true})
8+
.otherwise({templateUrl: '/_partials/page.html', controller: 'PageCtrl'})
9+
;
10+
})
11+
512
.run(function() {
613
if (!Array.prototype.indexOf) {
714
Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) {

angular/app/js/controllers.js

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,73 @@
11
'use strict';
22

33
angular.module('myApp.controllers', [])
4+
.controller('SiteCtrl', ['$scope', 'cmsSiteSettings', function($scope, cmsSiteSettings) {
5+
$scope.site = {
6+
templates: {
7+
mainMenu: '/_partials/mainMenu.html'
8+
}
9+
};
10+
var siteSettings = cmsSiteSettings.get({}, function (settings) {
11+
if (settings.variables) {
12+
for (var key in settings.variables) {
13+
if (settings.variables.hasOwnProperty(key) && key.substr(0, 5) === 'site_') {
14+
$scope.site[key.substr(5)] = settings.variables[key];
15+
}
16+
}
17+
}
18+
});
19+
}])
20+
21+
.controller('MainMenuCtrl', ['$scope', 'cmsMainMenu', function($scope, cmsMainMenu) {
22+
$scope.mainMenu = [];
23+
var mainMenu = cmsMainMenu.get({}, function(data) {
24+
if (data.links.length) {
25+
for (var i = 0; i < data.links.length; i++) {
26+
var link = data.links[i].link;
27+
if (link.internal_path === '<front>') {
28+
link.path = '/';
29+
}
30+
else {
31+
link.path = '/' + link.alias;
32+
}
33+
$scope.mainMenu.push(data.links[i].link);
34+
}
35+
}
36+
});
37+
}])
38+
39+
.controller('PageCtrl', ['$scope', 'cmsNode', 'cmsSiteSettings', '$location', 'cmsTemplate', function($scope, cmsNode, cmsSiteSettings, $location, cmsTemplate) {
40+
$scope.node = {};
41+
$scope.front = false;
42+
var node = cmsNode.get({path: 'node/1'}, function(data) {
43+
if (data.nodes && data.nodes[0] && data.nodes[0].node) {
44+
$scope.node = data.nodes[0].node;
45+
var siteSettings = cmsSiteSettings.get({}, function (settings) {
46+
if (settings.variables) {
47+
if (settings.variables.site_frontpage) {
48+
if ($scope.node.path && $scope.node.path == settings.variables.site_frontpage || 'node/' + $scope.node.id == settings.variables.site_frontpage) {
49+
$scope.front = true;
50+
}
51+
}
52+
53+
if ($scope.node.type && settings.variables.allowed_content_types && settings.variables.allowed_content_types.indexOf($scope.node.type) !== -1) {
54+
if ($scope.path !== $scope.node.path) {
55+
$location.path($scope.node.path).replace();
56+
}
57+
58+
cmsTemplate.getPartial($scope.node).then(function(partialUrl) {
59+
$scope.templateUrl = partialUrl;
60+
}, function () {
61+
$location.path('/404');
62+
});
63+
}
64+
else {
65+
$location.path('/404');
66+
}
67+
}
68+
});
69+
}
70+
});
71+
}]);
72+
473
;

0 commit comments

Comments
 (0)