-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmainController.js
123 lines (111 loc) · 3.72 KB
/
mainController.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
'use strict';
var cs142App = angular.module('cs142App', ['ngRoute', 'ngMaterial', 'firebase', 'ngSanitize']);
cs142App.factory("Auth", ["$firebaseAuth",
function($firebaseAuth) {
var ref = new Firebase("https://nooz.firebaseio.com");
return $firebaseAuth(ref);
}
]);
cs142App.config(['$routeProvider',
function($routeProvider) {
$routeProvider.
when('/users', {
templateUrl: 'components/profile-list/profile-listTemplate.html',
controller: 'ProfileListController'
}).
when('/addArticle', {
templateUrl: 'components/article-post/article-postTemplate.html',
controller: 'ArticlePostController'
}).
when('/login-register', {
templateUrl: 'components/login-register/login-registerTemplate.html',
controller: 'LoginRegisterController'
}).
when('/viewArticle/:userId/:articleId', {
templateUrl: 'components/article-view/article-viewTemplate.html',
controller: 'ArticleViewController'
}).
when('/followPeople', {
templateUrl: 'components/follow-people/follow-peopleTemplate.html',
controller: 'FollowPeopleController'
}).
when('/userPosts', {
templateUrl: 'components/user-posts/user-postsTemplate.html',
controller: 'UserPostsController'
}).
when('/userLikes', {
templateUrl: 'components/user-likes/user-likesTemplate.html',
controller: 'UserLikesController'
}).
otherwise({
redirectTo: '/login-register'
});
}
]);
cs142App.controller('MainController', ['$scope', '$location', 'Auth',
function($scope, $location, Auth) {
$scope.main = {};
var list = [];
for (var i = 0; i < 100; i++) {
list.push({
name: 'List Item ' + i,
idx: i
});
}
$scope.list = list;
//store any shared variables between controllers
$scope.shared = {};
//store the logged in user
$scope.shared.currentUser = window.noozModels.loggedInUserModel();
$scope.shared.follow = true;
$scope.shared.sidePaneReadingView = true;
$scope.main.switchSidePane = function(val){
$scope.shared.sidePaneReadingView = val;
if(val){ //reading mode
$scope.shared.testFunction();
} else {
$location.path("/followPeople");
}
};
$scope.shared.auth = Auth;
// any time auth status updates, add the user data to scope
$scope.shared.auth.$onAuth(function(authData) {
$scope.shared.authData = authData;
// $scope.shared.uid = authData.uid;
// if(authData){
// $scope.shared.loggedIn = true;
// } else {
// $scope.shared.loggedIn = false;
// }
});
$scope.main.logout = function() {
$scope.shared.auth.$unauth();
$location.path('login-register');
};
/*
* FetchModel - Fetch a model from the web server.
* url - string - The URL to issue the GET request.
* doneCallback - function - called with argument (model) when the
* the GET request is done. The argument model is the object
* containing the model. model is undefined in the error case.
*/
$scope.FetchModel = function(url, doneCallback) {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function(){
if (this.readyState === 4){
doneCallback(this.responseText);
}
};
xhr.open("GET", url);
xhr.send();
};
$scope.main.callBack = function(model){
var parsedJson = JSON.parse(model);
console.log(parsedJson.version);
$scope.$apply(function(){
$scope.main.versionNumber = 'v' + parsedJson.version;
});
};
$scope.FetchModel("http://localhost:3000/test/info", $scope.main.callBack);
}
]);