Skip to content

Commit

Permalink
added pin factory, fixed logic
Browse files Browse the repository at this point in the history
  • Loading branch information
helanan committed Dec 3, 2016
1 parent 4cc8823 commit 9ea3bf8
Show file tree
Hide file tree
Showing 21 changed files with 232 additions and 127 deletions.
32 changes: 16 additions & 16 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,32 @@

<body>
<body ng-app="PinThisApp">
<div ng-include='./partials/navbar.html'></div>
<div ng-include="'./partials/navbar.html'"></div>

<div class="row">
<h1>Pin This!</h1>
<div class="col-xs-offset-2 col-xs-8" ng-view></div>
</div>

<script src="https://www.gstatic.com/firebasejs/3.6.2/firebase.js"></script>
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="/lib/bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
<script type="text/javascript" src="/lib/bower_components/jquery/dist/jquery.min.js"></script>
<script type="text/javascript" src="/lib/bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
<script type="text/javascript" src="/lib/bower_components/angular/angular.min.js"></script>
<script src="/lib/bower_components/angular-route/angular-route.min.js"></script>
<script type="text/javascript" src="/lib/bower_components/angular-route/angular-route.min.js"></script>



<script src="/javascripts/app.js"></script>
<script src="/javascripts/AppConstants.js"></script>
<script src="/javascripts/AppConfig.js"></script>
<script src="/javascripts/factories/AuthFactory.js"></script>
<script src="/javascripts/factories/BoardFactory.js">
<script src="/javascripts/factories/UserFactory.js"></script>
<script src="/javascripts/controllers/AuthCtrl.js"></script>
<script src="/javascripts/controllers/NavCtrl.js"></script>
<script src="/javascripts/controllers/GeneralViewCtrl.js"></script>
<script src="/javascripts/controllers/CreateBoardCtrl.js">
<script src="/javascripts/controllers/BoardViewCtrl.js"></script>
<script src="/javascripts/controllers/BoardEditCtrl.js"></script>
<script type="text/javascript" src="/javascripts/app.js"></script>
<script type="text/javascript" src="/javascripts/AppConstants.js"></script>
<script type="text/javascript" src="/javascripts/factories/AuthFactory.js"></script>
<script type="text/javascript" src="/javascripts/AppConfig.js"></script>
<script type="text/javascript" src="/javascripts/factories/BoardFactory.js"></script>
<script type="text/javascript" src="/javascripts/factories/UserFactory.js"></script>
<script type="text/javascript" src="/javascripts/controllers/AuthCtrl.js"></script>
<script type="text/javascript" src="/javascripts/controllers/NavCtrl.js"></script>
<script type="text/javascript" src="/javascripts/controllers/GeneralViewCtrl.js"></script>
<script type="text/javascript" src="/javascripts/controllers/BoardNewCtrl.js"></script>
<script type="text/javascript" src="/javascripts/controllers/BoardViewCtrl.js"></script>
<script type="text/javascript" src="/javascripts/controllers/BoardEditCtrl.js"></script>
</body>
</html>
2 changes: 1 addition & 1 deletion javascripts/AppConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', {
Expand Down
24 changes: 11 additions & 13 deletions javascripts/controllers/AuthCtrl.js
Original file line number Diff line number Diff line change
@@ -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"){
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions javascripts/controllers/BoardEditCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});
};
Expand Down
Original file line number Diff line number Diff line change
@@ -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")
1 change: 0 additions & 1 deletion javascripts/controllers/BoardViewCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 7 additions & 5 deletions javascripts/controllers/GeneralViewCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
};

Expand All @@ -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();
});
};
});
});

console.log("GeneralViewCtrl Loaded");
4 changes: 2 additions & 2 deletions javascripts/controllers/NavCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
];
Expand Down
8 changes: 4 additions & 4 deletions javascripts/factories/BoardFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand All @@ -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
})
)
Expand Down Expand Up @@ -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);
Expand Down
86 changes: 86 additions & 0 deletions javascripts/factories/PinFactory.js
Original file line number Diff line number Diff line change
@@ -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};
});

1 change: 1 addition & 0 deletions javascripts/factories/UserFactory.js
Original file line number Diff line number Diff line change
@@ -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({
Expand Down
2 changes: 1 addition & 1 deletion lib/Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {},
Expand Down
7 changes: 2 additions & 5 deletions lib/bower.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "pin this",
"name": "pin-this",
"description": "Pinterest type app",
"main": "index.js",
"authors": [
Expand All @@ -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"
}
}
2 changes: 1 addition & 1 deletion lib/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "angular-todo",
"name": "pin-this",
"version": "1.0.0",
"description": "",
"main": "index.js",
Expand Down
3 changes: 1 addition & 2 deletions partials/auth.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</div>
<div class="form-group">
<label>Password</label>
<input type="password" class="col-xs-offset-1 col-xs-10" placeholder="" ng-model="login.password" required>
<input type="password" class="col-xs-offset-1 col-xs-10" placeholder="Password" ng-model="login.password" required>
</div>
<div class="form-group">
<a class="btn btn-lg btn-info col-xs-offset-1 col-xs-10" ng-click="loginUser(login)">Submit Login</a>
Expand All @@ -36,6 +36,5 @@
<a class="btn btn-lg btn-success col-xs-offset-1 col-xs-10" ng-click="registerUser(register)">Submit Registration</a>
</div>
</form>
<!-- end of login form -->
</div>
</div>
6 changes: 3 additions & 3 deletions partials/board-new.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<h3>New Todo</h3>
<h3>My Boards</h3>
<form>
<div class="form-group">
<label>Pins</label>
<label>Board Title</label>
<input type="text" class="form-control" placeholder="New Pin" ng-model="newPin.pin">
</div>

<div class="form-group">
<label>Assigned To</label>
<label>My Boards</label>
<input type="text" class="form-control" placeholder="My Pins" ng-model="newPin.assignedTo">
</div>

Expand Down
4 changes: 2 additions & 2 deletions partials/board-view.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<h1>Board: {{selectedBoard.pin}}</h1>
<button type="btn btn-info"><a ng-href="#/boards/edit/{{selectedBoard.id}}">Edit</a></button>
<button class="btn btn-info"><a ng-href="#/boards/edit/{{selectedBoard.id}}">Edit</a></button>
<h2>Helana's Boards: {{selectedBoard.assignedTo}}</h2>
<h2>My Pins: {{selectedBoard.isSelected}}</h2>
<h2>My Boards: {{selectedBoard.isSelected}}</h2>
Loading

0 comments on commit 9ea3bf8

Please sign in to comment.