From 795ec4c00819763139641e9219888967a52afdf5 Mon Sep 17 00:00:00 2001 From: Helana Nosrat Date: Thu, 1 Dec 2016 23:00:52 -0600 Subject: [PATCH] went through all of code, completed authorization, login, registering and creating and editing boards --- index.html | 10 ++-- javascripts/AppConfig.js | 50 ++++++++++---------- javascripts/controllers/AuthCtrl.js | 2 +- javascripts/controllers/BoardEditCtrl.js | 12 ++--- javascripts/controllers/CreateBoardCtrl.js | 8 ++-- javascripts/factories/BoardFactory.js | 8 ++-- javascripts/factories/PinsFactory.js | 0 javascripts/factories/UserFactory.js | 37 +++++++++++++++ partials/auth.html | 55 ++++++++++++++++++++++ partials/loginview.html | 17 ------- 10 files changed, 137 insertions(+), 62 deletions(-) create mode 100644 javascripts/factories/PinsFactory.js delete mode 100644 partials/loginview.html diff --git a/index.html b/index.html index d89cc1f..4c836e8 100644 --- a/index.html +++ b/index.html @@ -17,19 +17,19 @@

Pin This!

- + - + - - + + \ No newline at end of file diff --git a/javascripts/AppConfig.js b/javascripts/AppConfig.js index 0df8d77..8b3bc61 100644 --- a/javascripts/AppConfig.js +++ b/javascripts/AppConfig.js @@ -35,30 +35,30 @@ app.config(function($routeProvider){ templateUrl: 'partials/auth.html', controller:'AuthCtrl' }) - .when('/boards/list', { - templateUrl: 'partials/general-view.html', - controller: 'GeneralViewCtrl', - resolve: {isAuth} - }) - .when('/boards/new', { - templateUrl: 'partials/create-board.html', - controller: 'CreateBoardCtrl', - resolve: {isAuth} - }) - .when('/boards/view/:id', { - templateUrl: 'partials/board-view.html', - controller: 'BoardViewCtrl', - resolve: {isAuth} - }) - .when('/boards/edit/:id', { - templateUrl: 'partials/create-board.html', - controller:'BoardEditCtrl', - resolve: {isAuth} - }) - .when('/logout', { - templateUrl: 'partials/auth.html', - controller: 'AuthCtrl', - resolve: {isAuth} - }) + // .when('/boards/list', { + // templateUrl: 'partials/general-view.html', + // controller: 'GeneralViewCtrl', + // resolve: {isAuth} + // }) + // .when('/boards/new', { + // templateUrl: 'partials/create-board.html', + // controller: 'CreateBoardCtrl', + // resolve: {isAuth} + // }) + // .when('/boards/view/:id', { + // templateUrl: 'partials/board-view.html', + // controller: 'BoardViewCtrl', + // resolve: {isAuth} + // }) + // .when('/boards/edit/:id', { + // templateUrl: 'partials/create-board.html', + // controller:'BoardEditCtrl', + // resolve: {isAuth} + // }) + // .when('/logout', { + // templateUrl: 'partials/auth.html', + // controller: 'AuthCtrl', + // resolve: {isAuth} + // }) .otherwise('/auth'); }); \ No newline at end of file diff --git a/javascripts/controllers/AuthCtrl.js b/javascripts/controllers/AuthCtrl.js index e66b01d..770d0bf 100644 --- a/javascripts/controllers/AuthCtrl.js +++ b/javascripts/controllers/AuthCtrl.js @@ -3,7 +3,7 @@ app.controller("AuthCtrl", function($scope, $rootScope, AuthFactory, UserFactory, $location){ $scope.setLoginContainer = true; $scope.setRegisterContainer = false; - }); + if($location.path() == "/logout"){ AuthFactory.logout(); diff --git a/javascripts/controllers/BoardEditCtrl.js b/javascripts/controllers/BoardEditCtrl.js index 09fcd66..764462a 100644 --- a/javascripts/controllers/BoardEditCtrl.js +++ b/javascripts/controllers/BoardEditCtrl.js @@ -1,15 +1,15 @@ "use strict"; app.controller("BoardEditCtrl", function($scope, $location, $routeParams, BoardFactory){ - $scope.newBoard = {}; - let BoardId = $routeParams.id; + $scope.newPin = {}; + let boardId = $routeParams.id; - ItemFactory.getSingleBoard(BoardId).then(function(oneBoard){ - oneBoard.id = BoardId; - $scope.newBoard = oneBoard; + BoardFactory.getSingleBoard(boardId).then(function(oneBoard){ + oneBoard.id = boardId; + $scope.newPin = oneBoard; }); - $scope.addBoard = function(){ + $scope.addNewBoard = function(){ BoardFactory.editBoard($scope.newBoard).then(function(response){ $scope.newBoard = {}; $location.url("/boards/list"); diff --git a/javascripts/controllers/CreateBoardCtrl.js b/javascripts/controllers/CreateBoardCtrl.js index 4ce6531..0417892 100644 --- a/javascripts/controllers/CreateBoardCtrl.js +++ b/javascripts/controllers/CreateBoardCtrl.js @@ -1,14 +1,14 @@ "use strict"; app.controller("CreateBoardCtrl", function($scope, $rootScope, $location, BoardFactory){ - $scope.newBoard = {}; + $scope.newPin = {}; $scope.addNewBoard = function(){ - $scope.newBoard.isClicked = true; + $scope.newPin.isSelected = false; $scope.newBoard.uid = $rootScope.user.uid; - BoardFactory.postNewBoard($scope.newBoard).then(function(BoardId){ + BoardFactory.postNewBoard($scope.newPin).then(function(boardId){ $location.url("/boards/list"); - $scope.newBoard = {}; + $scope.newPin = {}; }); }; }); diff --git a/javascripts/factories/BoardFactory.js b/javascripts/factories/BoardFactory.js index 76d06e2..5e6034d 100644 --- a/javascripts/factories/BoardFactory.js +++ b/javascripts/factories/BoardFactory.js @@ -23,8 +23,8 @@ app.factory("BoardFactory", function($q, $http, FIREBASE_CONFIG){ $http.post(`${FIREBASE_CONFIG.databaseURL}/boards.json`, JSON.stringify({ assignedTo: newBoard.assignedTo, - isClicked: newBoard.isClicked, - board: newBoard.board, + isSelected: newBoard.isSelected, + board: newBoard.pin, uid: newBoard.uid }) ) @@ -67,8 +67,8 @@ var getSingleBoard = function(boardId){ $http.put(`${FIREBASE_CONFIG.databaseURL}/boards/${editBoard.id}.json`, JSON.stringify({ assignedTo: editBoard.assignedTo, - isCompleted: editBoard.isClicked, - task: editBoard.board, + isSelected: editBoard.isSelected, + pins: editBoard.pin, uid: editBoard.uid }) ) diff --git a/javascripts/factories/PinsFactory.js b/javascripts/factories/PinsFactory.js new file mode 100644 index 0000000..e69de29 diff --git a/javascripts/factories/UserFactory.js b/javascripts/factories/UserFactory.js index e69de29..5b2ca53 100644 --- a/javascripts/factories/UserFactory.js +++ b/javascripts/factories/UserFactory.js @@ -0,0 +1,37 @@ +"use strict"; +app.factory("UserFactory", function($q, $http, FIREBASE_CONFIG){ + let addUser = (authData) => { + return $q((resolve, reject) => { + $http.post(`${FIREBASE_CONFIG.databaseURL}/users.json`, JSON.stringify({ + uid: authData.uid, + username: authData.username + }) + ) + .success(function(storeUserSuccess){ + resolve(storeUserSuccess); + }) + .error(function(storeUserError){ + reject(storeUserError); + }); + }); + }; + + let getUser = (userId) =>{ + return $q((resolve, reject) => { + $http.get(`${FIREBASE_CONFIG.databaseURL}/users.json?orderBy="uid"&equalTo="${userId}"`) + .success(function(userObject){ + let users = []; + Object.keys(userObject).forEach(function(key){ + users.push(userObject[key]); + }); + resolve(users[0]); + }) + .error(function(error){ + reject(error); + }); + }); + + }; + + return {addUser:addUser, getUser:getUser}; +}); \ No newline at end of file diff --git a/partials/auth.html b/partials/auth.html index e69de29..f537e90 100644 --- a/partials/auth.html +++ b/partials/auth.html @@ -0,0 +1,55 @@ +
+
+ + + +
+
+ + +
+ +
+ + +
+ +
+ + +
+ + + +
+ + + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ + + +
+ + +
+
\ No newline at end of file diff --git a/partials/loginview.html b/partials/loginview.html deleted file mode 100644 index dee6cfc..0000000 --- a/partials/loginview.html +++ /dev/null @@ -1,17 +0,0 @@ -
-
\ No newline at end of file