This repository has been archived by the owner on Dec 21, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #87 from turnervink/develop
Merge sprint 1 version into master
- Loading branch information
Showing
54 changed files
with
1,620 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
var greenlistApp = angular.module("greenlistApp", ["ngRoute", "firebase", "ui.bootstrap", 'ngAside']); | ||
|
||
greenlistApp.run(["$rootScope", "$location", function($rootScope, $location) { | ||
$rootScope.$on("$routeChangeError", function(event, next, previous, error) { | ||
// We can catch the error thrown when the $requireSignIn promise is rejected | ||
// and redirect the user back to the home page | ||
if (error === "AUTH_REQUIRED") { | ||
$location.path("/login"); | ||
} | ||
|
||
}); | ||
}]); | ||
|
||
//Slide menu code | ||
|
||
greenlistApp.config(["$routeProvider", function($routeProvider) { | ||
$routeProvider | ||
.when("/login", { | ||
templateUrl: "views/html/login.html" | ||
}) | ||
.when("/list", { | ||
templateUrl: "views/html/shopping.html", | ||
controller: "ShoppingListCtrl", | ||
resolve: { | ||
"CurrentAuth": ["Auth", function(Auth) { | ||
return Auth.$requireSignIn(); | ||
}] | ||
} | ||
}) | ||
.when("/history", { | ||
templateUrl: "views/html/history.html", | ||
controller: "HistoryListCtrl", | ||
resolve: { | ||
"CurrentAuth": ["Auth", function(Auth) { | ||
return Auth.$requireSignIn(); | ||
}] | ||
} | ||
}) | ||
|
||
.when('/ctrl', { | ||
templateUrl: "views/partials/modal.html", | ||
controller: 'ModalCtrl' | ||
|
||
}) | ||
|
||
.when("/reports", { | ||
templateUrl: "views/html/report.html", | ||
controller: "ReportCtrl", | ||
resolve: { | ||
"CurrentAuth": ["Auth", function(Auth) { | ||
return Auth.$requireSignIn(); | ||
}] | ||
} | ||
}) | ||
|
||
.when("/affiliates", { | ||
templateUrl: "views/html/affiliates.html", | ||
controller: "AffiliatesCtrl" | ||
}) | ||
.when("/loading", { | ||
templateUrl: "views/html/loading.html" | ||
}) | ||
|
||
.otherwise({ | ||
redirectTo: "/list" | ||
}); | ||
|
||
}]); | ||
|
||
/* | ||
This controller listens for route changes and assigns a class to the body in order to | ||
have a different background colour for each view. A value of "undefined-page" is used for | ||
the login view as there is not controller associated with it. | ||
*/ | ||
greenlistApp.controller("GlobalCtrl", ["$scope", "$rootScope", function($scope, $rootScope) { | ||
$rootScope.$on("$routeChangeStart", function(event, toState, toParams) { | ||
$scope.bodyClass = toState.$$route.controller + "-page"; | ||
}); | ||
}]); | ||
|
||
greenlistApp.factory("Auth", ["$firebaseAuth", | ||
function($firebaseAuth) { | ||
return $firebaseAuth(); | ||
}]); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/** | ||
* Currently dummy service to allow dynamic styling | ||
* based on the loaded view. | ||
*/ | ||
greenlistApp.controller("AffiliatesCtrl", ["$scope", "UserInfo", function($scope, UserInfo) { | ||
|
||
}]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/** | ||
* Handles user authorization with Firebase through Google accounts. | ||
*/ | ||
greenlistApp.controller("AuthCtrl", ["$scope", "$route", "$location", "UserInfo", "$firebaseAuth", function($scope, $route, $location, UserInfo, $firebaseAuth) { | ||
// AngularFire auth object | ||
var auth = $firebaseAuth(); | ||
|
||
/** | ||
* Called when clicking the "sign in" button. Directs | ||
* users to the Google auth flow and sets user info | ||
* in the UserInfo service before redirecting back to | ||
* the previous page. | ||
*/ | ||
$scope.signIn = function() { | ||
auth.$signInWithRedirect("google").then(function(firebaseUser) { | ||
console.log("Signed in as " + firebaseUser.user.displayName); | ||
UserInfo.initUser(firebaseUser.user.displayName, firebaseUser.user.uid, firebaseUser.user.photoURL); | ||
}).catch(function(error) { | ||
console.error("Auth failed:", error); | ||
}); | ||
$location.url("/list"); // TODO this only works after the user has signed in at least once | ||
} | ||
|
||
/** | ||
* Called when clicking the "sign out" button. Clears user info | ||
* in the UserInfo service and un-auths with Firebase. | ||
*/ | ||
$scope.signOut = function() { | ||
auth.$signOut().then(function() { | ||
console.log("Goodbye!"); | ||
UserInfo.clearUser(); | ||
$location.url("/login"); | ||
}).catch(function(error) { | ||
console.error("Error signing out: " + error); | ||
}); | ||
} | ||
|
||
/** | ||
* Fires whenever the auth state changes. Sets up user info | ||
* in the UserInfo service if the user is signed it, otherwise | ||
* does not do anything. | ||
*/ | ||
auth.$onAuthStateChanged( | ||
function(firebaseUser) { | ||
if (firebaseUser) { | ||
console.log("User is auth'd as " + firebaseUser.displayName); | ||
UserInfo.initUser(firebaseUser.displayName, firebaseUser.uid, firebaseUser.photoURL); | ||
} else { | ||
console.error("Could not auth user"); | ||
} | ||
}); | ||
}]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/** | ||
* Controller for the history view. | ||
*/ | ||
greenlistApp.controller("HistoryListCtrl", | ||
["CurrentAuth", "$scope", "UserInfo", "DatabaseRef", "$firebaseObject", "DatabaseQuery", | ||
function(CurrentAuth, $scope, UserInfo, DatabaseRef, $firebaseObject, DatabaseQuery) { | ||
|
||
// Set up user info with the UserInfo service | ||
UserInfo.initUser(CurrentAuth.displayName, CurrentAuth.uid, CurrentAuth.photoURL); | ||
|
||
// Define style values for the header and nav bar | ||
$scope.heading = 'History'; | ||
$scope.listBtnColor = 'white'; | ||
$scope.histBtnColor = 'green'; | ||
$scope.reptBtnColor = 'white'; | ||
$scope.listColor = 'black'; | ||
$scope.histColor = 'white'; | ||
$scope.reptColor = 'black'; | ||
$scope.listBgImg = 'images/list-icon-off.png'; | ||
$scope.histBgImg = 'images/hist-icon-on.png'; | ||
$scope.reptBgImg = 'images/rept-icon-off.png'; | ||
|
||
// Create a database reference to items in the history list | ||
var historyFood = $firebaseObject(DatabaseRef.getRefToSpecificList('history')); | ||
|
||
$scope.historyItem = historyFood; | ||
|
||
/** | ||
* Called when the log waste button is tapped on an item. | ||
* Calls the updateWasteScore function of the DatabaseQuery | ||
* service if the item needs a data update. | ||
* | ||
* @param food The item to log waste for | ||
*/ | ||
$scope.logWaste = function(food) { | ||
|
||
if (!food.dataUpdated) { | ||
DatabaseQuery.updateWasteScore(food); | ||
} | ||
|
||
} | ||
|
||
/** | ||
* Called when the add to list button is tapped on an | ||
* item. Calls the updateWasteScore function of the DatabaseQuery | ||
* service if the item needs a data update. Moves the item to | ||
* the shopping list. | ||
* | ||
* @param food | ||
*/ | ||
$scope.addToList = function(food) { | ||
|
||
if (!food.dataUpdated) { | ||
DatabaseQuery.updateWasteScore(food); | ||
} | ||
|
||
DatabaseQuery.setItemList(food, "shopping"); | ||
} | ||
|
||
|
||
}]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/** | ||
* Close modal when the back is clicked. | ||
*/ | ||
greenlistApp.controller('ModalCtrl', function($scope, $modalInstance) { | ||
/** | ||
* Close the modal. | ||
*/ | ||
$scope.back = function() { | ||
$modalInstance.close($scope.test.input); | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/** | ||
* Brings out side nav by injecting new view with modal. | ||
*/ | ||
greenlistApp.controller('PanelCtrl', function($scope, $aside, UserInfo) { | ||
|
||
$scope.userPic = UserInfo.getCurrentUser().photoUrl; | ||
|
||
$scope.asideState = { | ||
open: false | ||
}; | ||
|
||
/** | ||
* Change state of the side nav to true and set position | ||
* | ||
* @param position set position | ||
* @param backdrop set the backdrop | ||
*/ | ||
$scope.openAside = function(position, backdrop) { | ||
$scope.asideState = { | ||
open: true, | ||
position: position | ||
}; | ||
/** | ||
* close the side nav | ||
*/ | ||
function postClose() { | ||
$scope.asideState.open = false; | ||
} | ||
|
||
$aside.open({ | ||
templateUrl: 'views/html/aside.html', | ||
placement: position, | ||
size: 'sm', | ||
backdrop: backdrop, | ||
controller: function($scope, $uibModalInstance) { | ||
$scope.ok = function(e) { | ||
$uibModalInstance.close(); | ||
e.stopPropagation(); | ||
}; | ||
$scope.cancel = function(e) { | ||
$uibModalInstance.dismiss(); | ||
e.stopPropagation(); | ||
}; | ||
} | ||
}).result.then(postClose, postClose); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
greenlistApp.controller("ReportCtrl", | ||
["CurrentAuth", "$scope", "UserInfo", "DatabaseRef", "$firebaseObject", | ||
function(CurrentAuth, $scope, UserInfo, DatabaseRef, $firebaseObject) { | ||
|
||
UserInfo.initUser(CurrentAuth.displayName, CurrentAuth.uid, CurrentAuth.photoURL); | ||
|
||
// Setting report page heading content and nav bar button style | ||
$scope.heading = 'Report'; | ||
$scope.listBtnColor = 'white'; | ||
$scope.histBtnColor = 'white'; | ||
$scope.reptBtnColor = 'green'; | ||
$scope.listColor = 'black'; | ||
$scope.histColor = 'black'; | ||
$scope.reptColor = 'white'; | ||
$scope.listBgImg = 'images/list-icon-off.png'; | ||
$scope.histBgImg = 'images/hist-icon-off.png'; | ||
$scope.reptBgImg = 'images/rept-icon-on.png'; | ||
|
||
}]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
greenlistApp.controller("ShoppingListCtrl", | ||
["CurrentAuth", "$scope", "UserInfo", "DatabaseRef", "$firebaseObject", "$modal", "$window","DatabaseQuery", | ||
function(CurrentAuth, $scope, UserInfo, DatabaseRef, $firebaseObject, $modal, $window,DatabaseQuery) { | ||
|
||
UserInfo.initUser(CurrentAuth.displayName, CurrentAuth.uid, CurrentAuth.photoURL); | ||
|
||
// Setting shopping list page heading content and nav bar button style | ||
$scope.heading = 'Shopping List'; | ||
$scope.listBtnColor = 'green'; | ||
$scope.histBtnColor = 'white'; | ||
$scope.reptBtnColor = 'white'; | ||
$scope.listColor = 'white'; | ||
$scope.histColor = 'black'; | ||
$scope.reptColor = 'black'; | ||
$scope.listBgImg = 'images/list-icon-on.png'; | ||
$scope.histBgImg = 'images/hist-icon-off.png'; | ||
$scope.reptBgImg = 'images/rept-icon-off.png'; | ||
|
||
|
||
var uncheckedItems = $firebaseObject(DatabaseRef.getUncheckedItems()); | ||
uncheckedItems.$bindTo($scope, "uncheckedItems"); | ||
|
||
var checkedItems = $firebaseObject(DatabaseRef.getCheckedItems()); | ||
checkedItems.$bindTo($scope, "checkedItems"); | ||
|
||
$scope.toggleCheck = function(item, status) { | ||
DatabaseQuery.updateCheckedStatus(item, status); | ||
} | ||
|
||
$scope.addItem = function(item) { | ||
DatabaseQuery.addItem(item); | ||
$scope.newItemName = ""; | ||
} | ||
|
||
$scope.deleteItem = function(item) { | ||
if (item.dataUpdated == undefined) { | ||
DatabaseQuery.deleteItem(item); | ||
} else { | ||
DatabaseQuery.setItemList(item, "history"); | ||
} | ||
} | ||
|
||
$scope.archive = function() { | ||
DatabaseRef.getCheckedItems() | ||
.once("value") | ||
.then(function(data) { | ||
|
||
data.forEach(function(item) { | ||
DatabaseQuery.updateWasteDataStatus(item.val(), false); | ||
DatabaseQuery.setItemList(item.val(), "history"); | ||
}); | ||
|
||
}); | ||
|
||
DatabaseRef.getUncheckedItems() | ||
.once("value") | ||
.then(function(data) { | ||
|
||
data.forEach(function(item) { | ||
|
||
if (item.val().dataUpdated == undefined) { | ||
DatabaseQuery.deleteItem(item.val()); | ||
} else { | ||
DatabaseQuery.setItemList(item.val(), "history"); | ||
} | ||
|
||
}); | ||
|
||
}); | ||
} | ||
|
||
}]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
var config = { | ||
apiKey: "AIzaSyAnOvIFGZ9IiYbcEdJvA8AZtIf4_FZa8yk", | ||
authDomain: "greenlist-bb6f7.firebaseapp.com", | ||
databaseURL: "https://greenlist-bb6f7.firebaseio.com", | ||
projectId: "greenlist-bb6f7", | ||
storageBucket: "greenlist-bb6f7.appspot.com", | ||
messagingSenderId: "647042734711" | ||
}; | ||
firebase.initializeApp(config); |
Oops, something went wrong.