From 9ea3bf8a33742feca7433d8aa608083d4623cdbf Mon Sep 17 00:00:00 2001 From: Helana Nosrat Date: Sat, 3 Dec 2016 11:08:45 -0600 Subject: [PATCH] added pin factory, fixed logic --- index.html | 32 ++--- javascripts/AppConfig.js | 2 +- javascripts/controllers/AuthCtrl.js | 24 ++-- javascripts/controllers/BoardEditCtrl.js | 4 +- .../{CreateBoardCtrl.js => BoardNewCtrl.js} | 6 +- javascripts/controllers/BoardViewCtrl.js | 1 - javascripts/controllers/GeneralViewCtrl.js | 12 +- javascripts/controllers/NavCtrl.js | 4 +- javascripts/factories/BoardFactory.js | 8 +- javascripts/factories/PinFactory.js | 86 ++++++++++++ javascripts/factories/UserFactory.js | 1 + lib/Gruntfile.js | 2 +- lib/bower.json | 7 +- lib/package.json | 2 +- partials/auth.html | 3 +- partials/board-new.html | 6 +- partials/board-view.html | 4 +- partials/general-view.html | 9 +- partials/navbar.html | 3 +- pinSeed.json | 128 ++++++++++-------- sass/main.scss | 15 +- 21 files changed, 232 insertions(+), 127 deletions(-) rename javascripts/controllers/{CreateBoardCtrl.js => BoardNewCtrl.js} (60%) create mode 100644 javascripts/factories/PinFactory.js diff --git a/index.html b/index.html index 4731060..5de9c63 100644 --- a/index.html +++ b/index.html @@ -10,7 +10,7 @@ -
+

Pin This!

@@ -18,24 +18,24 @@

Pin This!

- - + + - + - - - - - - - - - - + + + + + + + + + + + + \ No newline at end of file diff --git a/javascripts/AppConfig.js b/javascripts/AppConfig.js index 9d4e57a..d729b6f 100644 --- a/javascripts/AppConfig.js +++ b/javascripts/AppConfig.js @@ -42,7 +42,7 @@ app.config(function($routeProvider){ }) .when('/boards/new', { templateUrl: 'partials/board-new.html', - controller: 'CreateBoardCtrl', + controller: 'BoardNewCtrl', resolve: {isAuth} }) .when('/boards/view/:id', { diff --git a/javascripts/controllers/AuthCtrl.js b/javascripts/controllers/AuthCtrl.js index 5329435..c6ee40f 100644 --- a/javascripts/controllers/AuthCtrl.js +++ b/javascripts/controllers/AuthCtrl.js @@ -1,8 +1,8 @@ "use strict"; -app.controller("AuthCtrl", function($scope, $rootScope, AuthFactory, UserFactory, $location){ - $scope.setLoginContainer = true; - $scope.setRegisterContainer = false; +app.controller("AuthCtrl", function($scope, $rootScope, $location, AuthFactory, UserFactory){ + $scope.loginContainer = true; + $scope.registerContainer = false; if($location.path() === "/logout"){ @@ -11,35 +11,33 @@ app.controller("AuthCtrl", function($scope, $rootScope, AuthFactory, UserFactory $location.url("/auth"); } - let logMeIn = function(loginParams){ - AuthFactory.authenticate(loginParams).then(function(didLogin){ + let logMeIn = function(loginStuff){ + AuthFactory.authenticate(loginStuff).then(function(didLogin){ console.log("didLogin", didLogin); return UserFactory.getUser(didLogin.uid); }).then(function(userCreds){ $rootScope.user = userCreds; $scope.login = {}; $scope.register = {}; - $location.url("/boards/list"); + $location.url('/boards/list'); + console.log("userCreds", userCreds); }); }; - $scope.setRegisterContainer = function(){ - $scope.loginContainer = false; - $scope.registerContainer = true; - - }; - $scope.setLoginContainer = function(){ $scope.loginContainer = true; $scope.registerContainer = false; + }; + $scope.setRegisterContainer = function(){ + $scope.loginContainer = false; + $scope.registerContainer = true; }; $scope.registerUser = function(registerNewUser){ AuthFactory.registerWithEmail(registerNewUser).then(function(didRegister){ registerNewUser.uid = didRegister.uid; - console.log("didRegister", didRegister); return UserFactory.addUser(registerNewUser); }).then(function(registerComplete){ logMeIn(registerNewUser); diff --git a/javascripts/controllers/BoardEditCtrl.js b/javascripts/controllers/BoardEditCtrl.js index e46d852..30668db 100644 --- a/javascripts/controllers/BoardEditCtrl.js +++ b/javascripts/controllers/BoardEditCtrl.js @@ -10,8 +10,8 @@ app.controller("BoardEditCtrl", function($scope, $location, $routeParams, BoardF }); $scope.addNewBoard = function(){ - BoardFactory.editBoard($scope.newBoard).then(function(response){ - $scope.newPins = {}; + BoardFactory.editBoard($scope.newPin).then(function(response){ + $scope.newPin = {}; $location.url("/boards/list"); }); }; diff --git a/javascripts/controllers/CreateBoardCtrl.js b/javascripts/controllers/BoardNewCtrl.js similarity index 60% rename from javascripts/controllers/CreateBoardCtrl.js rename to javascripts/controllers/BoardNewCtrl.js index 0417892..7ff1b5a 100644 --- a/javascripts/controllers/CreateBoardCtrl.js +++ b/javascripts/controllers/BoardNewCtrl.js @@ -1,14 +1,16 @@ "use strict"; -app.controller("CreateBoardCtrl", function($scope, $rootScope, $location, BoardFactory){ +app.controller("BoardNewCtrl", function($scope, $rootScope, $location, BoardFactory){ $scope.newPin = {}; $scope.addNewBoard = function(){ $scope.newPin.isSelected = false; - $scope.newBoard.uid = $rootScope.user.uid; + $scope.newPin.uid = $rootScope.user.uid; BoardFactory.postNewBoard($scope.newPin).then(function(boardId){ $location.url("/boards/list"); $scope.newPin = {}; }); }; }); + +console.log("BoardNewCtrl") \ No newline at end of file diff --git a/javascripts/controllers/BoardViewCtrl.js b/javascripts/controllers/BoardViewCtrl.js index 626a212..8121d9c 100644 --- a/javascripts/controllers/BoardViewCtrl.js +++ b/javascripts/controllers/BoardViewCtrl.js @@ -3,7 +3,6 @@ app.controller("BoardViewCtrl", function($scope, $routeParams, BoardFactory){ $scope.selectedBoard = {}; let boardId = $routeParams.id; - //console.log("$routeParams", BoardId); BoardFactory.getSingleBoard(boardId).then(function(oneBoard){ oneBoard.id=boardId; diff --git a/javascripts/controllers/GeneralViewCtrl.js b/javascripts/controllers/GeneralViewCtrl.js index 809d88f..4f759bb 100644 --- a/javascripts/controllers/GeneralViewCtrl.js +++ b/javascripts/controllers/GeneralViewCtrl.js @@ -4,8 +4,8 @@ app.controller("GeneralViewCtrl", function($scope, $rootScope, BoardFactory){ $scope.boards = []; let getBoards = function(){ - BoardFactory.getBoardList($rootScope.user.uid).then(function(fbItems){ - $scope.boards = fbItems; + BoardFactory.getBoardList($rootScope.user.uid).then(function(fbBoards){ + $scope.boards = fbBoards; }); }; @@ -17,9 +17,11 @@ $scope.deleteBoard = function(boardId){ }); }; - $scope.inputChange = function(change){ - BoardFactory.editBoard(change).then(function(response){ + $scope.inputChange = function(thingy){ + BoardFactory.editBoard(thingy).then(function(response){ getBoards(); }); }; -}); \ No newline at end of file +}); + +console.log("GeneralViewCtrl Loaded"); \ No newline at end of file diff --git a/javascripts/controllers/NavCtrl.js b/javascripts/controllers/NavCtrl.js index a71c6f7..ce14db6 100644 --- a/javascripts/controllers/NavCtrl.js +++ b/javascripts/controllers/NavCtrl.js @@ -7,11 +7,11 @@ app.controller("NavCtrl", function($scope) { url:"#/logout" }, { - name:"All Items", + name:"My Boards", url:"#/boards/list" }, { - name:"New Item", + name:"All Boards", url:"#/boards/new" } ]; diff --git a/javascripts/factories/BoardFactory.js b/javascripts/factories/BoardFactory.js index fe37847..e9df214 100644 --- a/javascripts/factories/BoardFactory.js +++ b/javascripts/factories/BoardFactory.js @@ -3,7 +3,7 @@ app.factory("BoardFactory", function($q, $http, FIREBASE_CONFIG){ var getBoardList = function(userId){ - return $q((resolve, reject) =>{ + return $q((resolve, reject) => { $http.get(`${FIREBASE_CONFIG.databaseURL}/boards.json?orderBy="uid"&equalTo="${userId}"`) .success(function(response){ let boards = []; @@ -24,7 +24,7 @@ app.factory("BoardFactory", function($q, $http, FIREBASE_CONFIG){ JSON.stringify({ assignedTo: newBoard.assignedTo, isSelected: newBoard.isSelected, - board: newBoard.pin, + pin: newBoard.pin, uid: newBoard.uid }) ) @@ -52,8 +52,8 @@ var deleteBoard = function(boardId){ var getSingleBoard = function(boardId){ return $q((resolve, reject) => { $http.get(`${FIREBASE_CONFIG.databaseURL}/boards/${boardId}.json`) - .success(function(getSingleRespose){ - resolve(getSingleRespose); + .success(function(getSingleResponse){ + resolve(getSingleResponse); }) .error(function(getSingleError){ reject(getSingleError); diff --git a/javascripts/factories/PinFactory.js b/javascripts/factories/PinFactory.js new file mode 100644 index 0000000..029a966 --- /dev/null +++ b/javascripts/factories/PinFactory.js @@ -0,0 +1,86 @@ +"use strict"; + +app.factory("PinFactory", function($q, $http, FIREBASE_CONFIG){ + + var getPinList = function(userId){ + return $q((resolve, reject) => { + $http.get(`${FIREBASE_CONFIG.databaseURL}/pins.json?orderBy="uid"&equalTo="${userId}"`) + .success(function(response){ + let pins = []; + Object.keys(response).forEach(function(key){ + response[key].id = key; + boards.push(response[key]); + }); + resolve(pins); + }) + .error(function(errorResponse){ + reject(errorResponse); + }); + }); + }; + var postNewPin = function(newPin){ + return $q((resolve, reject)=>{ + $http.post(`${FIREBASE_CONFIG.databaseURL}/boards.json`, + JSON.stringify({ + assignedTo: newPin.assignedTo, + isSelected: newPin.isSelected, + pin: newPin.board, + uid: newPin.uid + }) + ) + .success(function(postResponse){ + resolve(postResponse); + }) + .error(function(postError){ + reject(postError); + }); + }); + }; + +var deletePin = function(boardId){ + return $q((resolve, reject) => { + $http.delete(`${FIREBASE_CONFIG.databaseURL}/pins/${PinId}.json`) + .success(function(deleteResponse){ + resolve(deleteResponse); + }) + .error(function(deleteError){ + reject(deleteError); + }); + }); +}; + +var getSingleBoard = function(pinId){ + return $q((resolve, reject) => { + $http.get(`${FIREBASE_CONFIG.databaseURL}/pins/${pinId}.json`) + .success(function(getSingleResponse){ + resolve(getSingleResponse); + }) + .error(function(getSingleError){ + reject(getSingleError); + }); + }); +}; + + var editPin = function(editPin){ + return $q((resolve, reject)=>{ + $http.put(`${FIREBASE_CONFIG.databaseURL}/pins/${editPin.id}.json`, + JSON.stringify({ + assignedTo: editPin.assignedTo, + isSelected: editPin.isSelected, + pins: editPin.pin, + uid: editPin.uid + }) + ) + .success(function(editResponse){ + resolve(editResponse); + }) + .error(function(editError){ + reject(editError); + }); + }); + }; + + + return {getPinList:getPinList, postNewPin:postNewPin, deletePin:deletePin, getSinglePin:getSinglePin, editPin:editPin}; +}); + diff --git a/javascripts/factories/UserFactory.js b/javascripts/factories/UserFactory.js index 5b2ca53..b79aaff 100644 --- a/javascripts/factories/UserFactory.js +++ b/javascripts/factories/UserFactory.js @@ -1,5 +1,6 @@ "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({ diff --git a/lib/Gruntfile.js b/lib/Gruntfile.js index 8f141a5..ad99701 100644 --- a/lib/Gruntfile.js +++ b/lib/Gruntfile.js @@ -4,7 +4,7 @@ module.exports = function(grunt) { jshint: { files: ['../javascripts/**/*.js'], options: { - predef: [ "document", "console", "$", "firebase", "FbAPI"], + predef: [ "document", "console", "$", "firebase", "app", "angular"], esnext: true, globalstrict: true, globals: {}, diff --git a/lib/bower.json b/lib/bower.json index 34aef9f..dad7ffb 100644 --- a/lib/bower.json +++ b/lib/bower.json @@ -1,5 +1,5 @@ { - "name": "pin this", + "name": "pin-this", "description": "Pinterest type app", "main": "index.js", "authors": [ @@ -20,9 +20,6 @@ "jquery": "^3.1.1", "bootstrap": "^3.3.7", "angular": "^1.5.8", - "angular-route": "^1.5.9" - }, - "resolutions": { - "angular": "^1.5.8" + "angular-route": "^1.5.8" } } diff --git a/lib/package.json b/lib/package.json index 77bb011..bc1c01c 100644 --- a/lib/package.json +++ b/lib/package.json @@ -1,5 +1,5 @@ { - "name": "angular-todo", + "name": "pin-this", "version": "1.0.0", "description": "", "main": "index.js", diff --git a/partials/auth.html b/partials/auth.html index 201661d..4da29b5 100644 --- a/partials/auth.html +++ b/partials/auth.html @@ -11,7 +11,7 @@
- +
Submit Login @@ -36,6 +36,5 @@ Submit Registration
- \ No newline at end of file diff --git a/partials/board-new.html b/partials/board-new.html index febd545..e2c92ad 100644 --- a/partials/board-new.html +++ b/partials/board-new.html @@ -1,12 +1,12 @@ -

New Todo

+

My Boards

- +
- +
diff --git a/partials/board-view.html b/partials/board-view.html index ba5509e..9447f6a 100644 --- a/partials/board-view.html +++ b/partials/board-view.html @@ -1,4 +1,4 @@

Board: {{selectedBoard.pin}}

- +

Helana's Boards: {{selectedBoard.assignedTo}}

-

My Pins: {{selectedBoard.isSelected}}

+

My Boards: {{selectedBoard.isSelected}}

diff --git a/partials/general-view.html b/partials/general-view.html index baeb4d1..7bcbf46 100644 --- a/partials/general-view.html +++ b/partials/general-view.html @@ -1,5 +1,5 @@
-
+
@@ -13,10 +13,7 @@

Boards

- -
-
{{board.assignedTo}}
@@ -25,10 +22,10 @@

Boards

My Boards

-
+
-
+
{{board.assignedTo}}
diff --git a/partials/navbar.html b/partials/navbar.html index 5af9fcd..40d103a 100644 --- a/partials/navbar.html +++ b/partials/navbar.html @@ -1,6 +1,5 @@