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

Commit

Permalink
Merge pull request #87 from turnervink/develop
Browse files Browse the repository at this point in the history
Merge sprint 1 version into master
  • Loading branch information
novanaz authored May 12, 2017
2 parents 56f7412 + c94c226 commit fa96125
Show file tree
Hide file tree
Showing 54 changed files with 1,620 additions and 0 deletions.
85 changes: 85 additions & 0 deletions app/app.js
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();
}]);

7 changes: 7 additions & 0 deletions app/controllers/AffiliatesCtrl.js
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) {

}]);
52 changes: 52 additions & 0 deletions app/controllers/AuthCtrl.js
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");
}
});
}]);
61 changes: 61 additions & 0 deletions app/controllers/HistoryListCtrl.js
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");
}


}]);
11 changes: 11 additions & 0 deletions app/controllers/ModalCtrl.js
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);
};
});
47 changes: 47 additions & 0 deletions app/controllers/PanelCtrl.js
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);
}
});
19 changes: 19 additions & 0 deletions app/controllers/ReportCtrl.js
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';

}]);
72 changes: 72 additions & 0 deletions app/controllers/ShoppingListCtrl.js
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");
}

});

});
}

}]);
9 changes: 9 additions & 0 deletions app/firebaseinfo.js
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);
Loading

0 comments on commit fa96125

Please sign in to comment.