Skip to content
This repository was archived by the owner on Dec 21, 2020. It is now read-only.

Commit fa96125

Browse files
authored
Merge pull request #87 from turnervink/develop
Merge sprint 1 version into master
2 parents 56f7412 + c94c226 commit fa96125

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1620
-0
lines changed

app/app.js

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
var greenlistApp = angular.module("greenlistApp", ["ngRoute", "firebase", "ui.bootstrap", 'ngAside']);
2+
3+
greenlistApp.run(["$rootScope", "$location", function($rootScope, $location) {
4+
$rootScope.$on("$routeChangeError", function(event, next, previous, error) {
5+
// We can catch the error thrown when the $requireSignIn promise is rejected
6+
// and redirect the user back to the home page
7+
if (error === "AUTH_REQUIRED") {
8+
$location.path("/login");
9+
}
10+
11+
});
12+
}]);
13+
14+
//Slide menu code
15+
16+
greenlistApp.config(["$routeProvider", function($routeProvider) {
17+
$routeProvider
18+
.when("/login", {
19+
templateUrl: "views/html/login.html"
20+
})
21+
.when("/list", {
22+
templateUrl: "views/html/shopping.html",
23+
controller: "ShoppingListCtrl",
24+
resolve: {
25+
"CurrentAuth": ["Auth", function(Auth) {
26+
return Auth.$requireSignIn();
27+
}]
28+
}
29+
})
30+
.when("/history", {
31+
templateUrl: "views/html/history.html",
32+
controller: "HistoryListCtrl",
33+
resolve: {
34+
"CurrentAuth": ["Auth", function(Auth) {
35+
return Auth.$requireSignIn();
36+
}]
37+
}
38+
})
39+
40+
.when('/ctrl', {
41+
templateUrl: "views/partials/modal.html",
42+
controller: 'ModalCtrl'
43+
44+
})
45+
46+
.when("/reports", {
47+
templateUrl: "views/html/report.html",
48+
controller: "ReportCtrl",
49+
resolve: {
50+
"CurrentAuth": ["Auth", function(Auth) {
51+
return Auth.$requireSignIn();
52+
}]
53+
}
54+
})
55+
56+
.when("/affiliates", {
57+
templateUrl: "views/html/affiliates.html",
58+
controller: "AffiliatesCtrl"
59+
})
60+
.when("/loading", {
61+
templateUrl: "views/html/loading.html"
62+
})
63+
64+
.otherwise({
65+
redirectTo: "/list"
66+
});
67+
68+
}]);
69+
70+
/*
71+
This controller listens for route changes and assigns a class to the body in order to
72+
have a different background colour for each view. A value of "undefined-page" is used for
73+
the login view as there is not controller associated with it.
74+
*/
75+
greenlistApp.controller("GlobalCtrl", ["$scope", "$rootScope", function($scope, $rootScope) {
76+
$rootScope.$on("$routeChangeStart", function(event, toState, toParams) {
77+
$scope.bodyClass = toState.$$route.controller + "-page";
78+
});
79+
}]);
80+
81+
greenlistApp.factory("Auth", ["$firebaseAuth",
82+
function($firebaseAuth) {
83+
return $firebaseAuth();
84+
}]);
85+

app/controllers/AffiliatesCtrl.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/**
2+
* Currently dummy service to allow dynamic styling
3+
* based on the loaded view.
4+
*/
5+
greenlistApp.controller("AffiliatesCtrl", ["$scope", "UserInfo", function($scope, UserInfo) {
6+
7+
}]);

app/controllers/AuthCtrl.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/**
2+
* Handles user authorization with Firebase through Google accounts.
3+
*/
4+
greenlistApp.controller("AuthCtrl", ["$scope", "$route", "$location", "UserInfo", "$firebaseAuth", function($scope, $route, $location, UserInfo, $firebaseAuth) {
5+
// AngularFire auth object
6+
var auth = $firebaseAuth();
7+
8+
/**
9+
* Called when clicking the "sign in" button. Directs
10+
* users to the Google auth flow and sets user info
11+
* in the UserInfo service before redirecting back to
12+
* the previous page.
13+
*/
14+
$scope.signIn = function() {
15+
auth.$signInWithRedirect("google").then(function(firebaseUser) {
16+
console.log("Signed in as " + firebaseUser.user.displayName);
17+
UserInfo.initUser(firebaseUser.user.displayName, firebaseUser.user.uid, firebaseUser.user.photoURL);
18+
}).catch(function(error) {
19+
console.error("Auth failed:", error);
20+
});
21+
$location.url("/list"); // TODO this only works after the user has signed in at least once
22+
}
23+
24+
/**
25+
* Called when clicking the "sign out" button. Clears user info
26+
* in the UserInfo service and un-auths with Firebase.
27+
*/
28+
$scope.signOut = function() {
29+
auth.$signOut().then(function() {
30+
console.log("Goodbye!");
31+
UserInfo.clearUser();
32+
$location.url("/login");
33+
}).catch(function(error) {
34+
console.error("Error signing out: " + error);
35+
});
36+
}
37+
38+
/**
39+
* Fires whenever the auth state changes. Sets up user info
40+
* in the UserInfo service if the user is signed it, otherwise
41+
* does not do anything.
42+
*/
43+
auth.$onAuthStateChanged(
44+
function(firebaseUser) {
45+
if (firebaseUser) {
46+
console.log("User is auth'd as " + firebaseUser.displayName);
47+
UserInfo.initUser(firebaseUser.displayName, firebaseUser.uid, firebaseUser.photoURL);
48+
} else {
49+
console.error("Could not auth user");
50+
}
51+
});
52+
}]);

app/controllers/HistoryListCtrl.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/**
2+
* Controller for the history view.
3+
*/
4+
greenlistApp.controller("HistoryListCtrl",
5+
["CurrentAuth", "$scope", "UserInfo", "DatabaseRef", "$firebaseObject", "DatabaseQuery",
6+
function(CurrentAuth, $scope, UserInfo, DatabaseRef, $firebaseObject, DatabaseQuery) {
7+
8+
// Set up user info with the UserInfo service
9+
UserInfo.initUser(CurrentAuth.displayName, CurrentAuth.uid, CurrentAuth.photoURL);
10+
11+
// Define style values for the header and nav bar
12+
$scope.heading = 'History';
13+
$scope.listBtnColor = 'white';
14+
$scope.histBtnColor = 'green';
15+
$scope.reptBtnColor = 'white';
16+
$scope.listColor = 'black';
17+
$scope.histColor = 'white';
18+
$scope.reptColor = 'black';
19+
$scope.listBgImg = 'images/list-icon-off.png';
20+
$scope.histBgImg = 'images/hist-icon-on.png';
21+
$scope.reptBgImg = 'images/rept-icon-off.png';
22+
23+
// Create a database reference to items in the history list
24+
var historyFood = $firebaseObject(DatabaseRef.getRefToSpecificList('history'));
25+
26+
$scope.historyItem = historyFood;
27+
28+
/**
29+
* Called when the log waste button is tapped on an item.
30+
* Calls the updateWasteScore function of the DatabaseQuery
31+
* service if the item needs a data update.
32+
*
33+
* @param food The item to log waste for
34+
*/
35+
$scope.logWaste = function(food) {
36+
37+
if (!food.dataUpdated) {
38+
DatabaseQuery.updateWasteScore(food);
39+
}
40+
41+
}
42+
43+
/**
44+
* Called when the add to list button is tapped on an
45+
* item. Calls the updateWasteScore function of the DatabaseQuery
46+
* service if the item needs a data update. Moves the item to
47+
* the shopping list.
48+
*
49+
* @param food
50+
*/
51+
$scope.addToList = function(food) {
52+
53+
if (!food.dataUpdated) {
54+
DatabaseQuery.updateWasteScore(food);
55+
}
56+
57+
DatabaseQuery.setItemList(food, "shopping");
58+
}
59+
60+
61+
}]);

app/controllers/ModalCtrl.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
* Close modal when the back is clicked.
3+
*/
4+
greenlistApp.controller('ModalCtrl', function($scope, $modalInstance) {
5+
/**
6+
* Close the modal.
7+
*/
8+
$scope.back = function() {
9+
$modalInstance.close($scope.test.input);
10+
};
11+
});

app/controllers/PanelCtrl.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/**
2+
* Brings out side nav by injecting new view with modal.
3+
*/
4+
greenlistApp.controller('PanelCtrl', function($scope, $aside, UserInfo) {
5+
6+
$scope.userPic = UserInfo.getCurrentUser().photoUrl;
7+
8+
$scope.asideState = {
9+
open: false
10+
};
11+
12+
/**
13+
* Change state of the side nav to true and set position
14+
*
15+
* @param position set position
16+
* @param backdrop set the backdrop
17+
*/
18+
$scope.openAside = function(position, backdrop) {
19+
$scope.asideState = {
20+
open: true,
21+
position: position
22+
};
23+
/**
24+
* close the side nav
25+
*/
26+
function postClose() {
27+
$scope.asideState.open = false;
28+
}
29+
30+
$aside.open({
31+
templateUrl: 'views/html/aside.html',
32+
placement: position,
33+
size: 'sm',
34+
backdrop: backdrop,
35+
controller: function($scope, $uibModalInstance) {
36+
$scope.ok = function(e) {
37+
$uibModalInstance.close();
38+
e.stopPropagation();
39+
};
40+
$scope.cancel = function(e) {
41+
$uibModalInstance.dismiss();
42+
e.stopPropagation();
43+
};
44+
}
45+
}).result.then(postClose, postClose);
46+
}
47+
});

app/controllers/ReportCtrl.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
greenlistApp.controller("ReportCtrl",
2+
["CurrentAuth", "$scope", "UserInfo", "DatabaseRef", "$firebaseObject",
3+
function(CurrentAuth, $scope, UserInfo, DatabaseRef, $firebaseObject) {
4+
5+
UserInfo.initUser(CurrentAuth.displayName, CurrentAuth.uid, CurrentAuth.photoURL);
6+
7+
// Setting report page heading content and nav bar button style
8+
$scope.heading = 'Report';
9+
$scope.listBtnColor = 'white';
10+
$scope.histBtnColor = 'white';
11+
$scope.reptBtnColor = 'green';
12+
$scope.listColor = 'black';
13+
$scope.histColor = 'black';
14+
$scope.reptColor = 'white';
15+
$scope.listBgImg = 'images/list-icon-off.png';
16+
$scope.histBgImg = 'images/hist-icon-off.png';
17+
$scope.reptBgImg = 'images/rept-icon-on.png';
18+
19+
}]);
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
greenlistApp.controller("ShoppingListCtrl",
2+
["CurrentAuth", "$scope", "UserInfo", "DatabaseRef", "$firebaseObject", "$modal", "$window","DatabaseQuery",
3+
function(CurrentAuth, $scope, UserInfo, DatabaseRef, $firebaseObject, $modal, $window,DatabaseQuery) {
4+
5+
UserInfo.initUser(CurrentAuth.displayName, CurrentAuth.uid, CurrentAuth.photoURL);
6+
7+
// Setting shopping list page heading content and nav bar button style
8+
$scope.heading = 'Shopping List';
9+
$scope.listBtnColor = 'green';
10+
$scope.histBtnColor = 'white';
11+
$scope.reptBtnColor = 'white';
12+
$scope.listColor = 'white';
13+
$scope.histColor = 'black';
14+
$scope.reptColor = 'black';
15+
$scope.listBgImg = 'images/list-icon-on.png';
16+
$scope.histBgImg = 'images/hist-icon-off.png';
17+
$scope.reptBgImg = 'images/rept-icon-off.png';
18+
19+
20+
var uncheckedItems = $firebaseObject(DatabaseRef.getUncheckedItems());
21+
uncheckedItems.$bindTo($scope, "uncheckedItems");
22+
23+
var checkedItems = $firebaseObject(DatabaseRef.getCheckedItems());
24+
checkedItems.$bindTo($scope, "checkedItems");
25+
26+
$scope.toggleCheck = function(item, status) {
27+
DatabaseQuery.updateCheckedStatus(item, status);
28+
}
29+
30+
$scope.addItem = function(item) {
31+
DatabaseQuery.addItem(item);
32+
$scope.newItemName = "";
33+
}
34+
35+
$scope.deleteItem = function(item) {
36+
if (item.dataUpdated == undefined) {
37+
DatabaseQuery.deleteItem(item);
38+
} else {
39+
DatabaseQuery.setItemList(item, "history");
40+
}
41+
}
42+
43+
$scope.archive = function() {
44+
DatabaseRef.getCheckedItems()
45+
.once("value")
46+
.then(function(data) {
47+
48+
data.forEach(function(item) {
49+
DatabaseQuery.updateWasteDataStatus(item.val(), false);
50+
DatabaseQuery.setItemList(item.val(), "history");
51+
});
52+
53+
});
54+
55+
DatabaseRef.getUncheckedItems()
56+
.once("value")
57+
.then(function(data) {
58+
59+
data.forEach(function(item) {
60+
61+
if (item.val().dataUpdated == undefined) {
62+
DatabaseQuery.deleteItem(item.val());
63+
} else {
64+
DatabaseQuery.setItemList(item.val(), "history");
65+
}
66+
67+
});
68+
69+
});
70+
}
71+
72+
}]);

app/firebaseinfo.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
var config = {
2+
apiKey: "AIzaSyAnOvIFGZ9IiYbcEdJvA8AZtIf4_FZa8yk",
3+
authDomain: "greenlist-bb6f7.firebaseapp.com",
4+
databaseURL: "https://greenlist-bb6f7.firebaseio.com",
5+
projectId: "greenlist-bb6f7",
6+
storageBucket: "greenlist-bb6f7.appspot.com",
7+
messagingSenderId: "647042734711"
8+
};
9+
firebase.initializeApp(config);

0 commit comments

Comments
 (0)