Skip to content

Commit

Permalink
Merge pull request #195 from andela/bug/user-profile
Browse files Browse the repository at this point in the history
Bug/user profile
  • Loading branch information
gottsohn committed Mar 30, 2016
2 parents 2aa0588 + 8527b34 commit 7799c34
Show file tree
Hide file tree
Showing 28 changed files with 480 additions and 335 deletions.
41 changes: 21 additions & 20 deletions app/scripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,12 @@
.state('authSuccess', {
url: '/auth/success/{token}/{id}',
controller: ['$stateParams', 'Auth', '$state',
function($stateParams, Auth, $state) {
Auth.setToken($stateParams.token);
var loc = $state.href('userProfile',
{id : $stateParams.id}, {absolute:true});
window.location.href = loc;
}
function($stateParams, Auth, $state) {
Auth.setToken($stateParams.token);
var loc = $state.href('userProfile',
{id : $stateParams.id}, {absolute:true});
window.location.href = loc;
}
]
})
.state('viewEvent', {
Expand Down Expand Up @@ -203,6 +203,18 @@
}
}
})
.state('userProfile.editItem', {
url: '/items/{id}/edit',
params: {
tabIndex: 0
},
views: {
'inner-view@userProfile': {
controller: 'UserProductsCtrl',
templateUrl: 'views/edit-item.html'
}
}
})
.state('userProfile.events', {
url: '/events',
views: {
Expand All @@ -214,27 +226,16 @@
})
.state('userProfile.editEvent', {
url: '/events/{id}/edit',
params: {
tabIndex: 0
},
views: {
'inner-view@userProfile': {
controller: 'UserEventsCtrl',
templateUrl: 'views/edit-event.html'
}
}
})
.state('addItem', {
url: '/items/create',
controller: 'ItemCtrl',
templateUrl: 'views/add-item.html',
authenticate: true
})
.state('editItem', {
url: '/items/{id}/edit',
params: {
tabIndex: 0
},
controller: 'ItemCtrl',
templateUrl: 'views/edit-item.html'
})
.state('viewItem', {
url: '/items/{id}',
controller: 'ItemCtrl',
Expand Down
1 change: 0 additions & 1 deletion app/scripts/controllers/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
});
};


$scope.close = function() {
$mdSidenav('evcatNav').close();
};
Expand Down
57 changes: 1 addition & 56 deletions app/scripts/controllers/items.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,6 @@
$scope.selectedImage = image;
};

$scope.addItems = function() {
Items.save($scope.item, function(item) {
if (item) {
$state.go('editItem', {
id: item.id
});
} else {
Utils.toast('Item not created');
}
});
};

$scope.addItemReview = function() {
$scope.itemReview.itemId = $stateParams.id;
Reviews.save($scope.itemReview, function(review) {
Expand All @@ -79,36 +67,6 @@
});
};

$scope.getItem = function() {
// get selected item id
$scope.itemId = $stateParams.id;
$scope.uploader = new FileUploader({
url: '/api/image/',
alias: 'photos',
formData: [{
id: $scope.itemId,
userId: $rootScope.currentUser.id
}],
onCompleteItem: function() {
Items.update($scope.item, function() {
$state.go($state.current, {
id: $scope.itemId,
tabIndex: 1
}, {
reload: true
});
});
}
});
//load the item
Items.get({
id: $scope.itemId
}, function(item) {
$scope.images = item.Images;
$scope.item = item;
});
};

$scope.init = function() {
// get all categories
$scope.categories = Categories.query({
Expand All @@ -124,20 +82,6 @@
$scope.tabIndex = $stateParams.tabIndex;
};

$scope.updateItem = function() {
Items.update($scope.item, function(item) {
$scope.getItem();
Utils.toast(item.message);
});
};

$scope.showToast = function() {
Utils.toast('Upload complete');
};

$scope.upload = function() {
$scope.uploader.uploadAll();
};
$scope.deleteImage = function(id) {
Images.delete(id, function() {
$state.go($state.current, {
Expand All @@ -148,6 +92,7 @@
});
});
};

$scope.init();
}
]);
Expand Down
18 changes: 12 additions & 6 deletions app/scripts/controllers/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ angular.module('vvida.controllers')
function($rootScope, $scope, $state, Users, Countries,
FileUploader, Utils) {
$scope.init = function() {

Users.get({
id: $rootScope.currentUser.id
}, function(res) {
$scope.userData = res;
$scope.userData.dob = new Date(res.dob);
});

$scope.uploader = new FileUploader({
url: '/api/users/image-upload',
alias: 'photos',
Expand Down Expand Up @@ -58,15 +66,13 @@ angular.module('vvida.controllers')
};

$scope.editProfile = function() {
$rootScope.currentUser.dob = new Date($rootScope.currentUser.dob);
Users.update($rootScope.currentUser, function() {
$scope.message =
'You have successfully updated your profile. ' +
$scope.userData.dob = new Date($scope.userData.dob);
Users.update($scope.userData, function() {
$scope.message = 'You have successfully updated your profile. ' +
'Click on the home button to get to vvida homepage.';

}, function() {
$scope.message =
'There was a problem updating your profile.';
$scope.message = 'There was a problem updating your profile.';
});
};

Expand Down
23 changes: 18 additions & 5 deletions app/scripts/controllers/user-profile/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ angular.module('vvida.controllers')
'FileUploader',
'Categories',
'$mdDialog',
function($scope, $rootScope,
$state, $stateParams, Users, Utils, Events,
FileUploader, Categories, $mdDialog) {
function($scope, $rootScope, $state, $stateParams,
Users, Utils, Events, FileUploader, Categories, $mdDialog) {

$scope.init = function() {

Expand All @@ -26,12 +25,13 @@ angular.module('vvida.controllers')
}
}
});

// get all categories
$scope.categories = Categories.query({
type: 'Event'
});

};
// $scope.init();

// create event
$scope.addEvent = function() {
Expand All @@ -47,6 +47,7 @@ angular.module('vvida.controllers')
});
};

// get selected event id
$scope.getEvent = function() {
$scope.eventId = $stateParams.id;
$scope.uploader = new FileUploader({
Expand All @@ -68,10 +69,12 @@ angular.module('vvida.controllers')
});
}
});

Events.get({
id: $stateParams.id
}, function(event) {
$scope.event = event;
$scope.event.time = new Date(event.time);
});

$scope.categories = Categories.query({
Expand All @@ -82,6 +85,16 @@ angular.module('vvida.controllers')
$scope.updateEvent = function() {
Events.update($scope.event, function(event) {
Utils.toast(event.message);
$state.go('userProfile.events');
});
};

$scope.deleteEvent = function(id) {
Events.delete({
id: id
}, function(msg) {
Utils.toast(msg.message);
$state.go('userProfile.events', {}, { reload: true });
});
};

Expand All @@ -94,7 +107,7 @@ angular.module('vvida.controllers')
};

$scope.parseDate = function(date) {
return new Date(Date.parse(date)).toUTCString();
return Utils.parseTime(date);
};

$scope.addEventModal = function(ev) {
Expand Down
24 changes: 18 additions & 6 deletions app/scripts/controllers/user-profile/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
angular.module('vvida.controllers')
.controller('UserProfileCtrl', ['$scope', '$rootScope', '$state', 'Users',
function($scope, $rootScope, $state, Users) {
.controller('UserProfileCtrl', ['$scope', '$rootScope', '$state',
'Users', '$mdSidenav',
function($scope, $rootScope, $state, Users, $mdSidenav) {
$scope.init = function() {
$scope.menu = [{
link: 'userProfile.events',
Expand All @@ -18,28 +19,39 @@ angular.module('vvida.controllers')
icon: 'fa fa-pencil'
}];

$scope.close = function() {
$mdSidenav('profileSideNav').close();
};

$scope.toggleSidenav = function() {
$mdSidenav('profileSideNav').toggle();
};

// Route to defualt view
$state.go('userProfile.events');
var stateName = $state.current.name;
if (/^userProfile$/.test(stateName)) {
$state.go('userProfile.events');
}

Users.eventsCount($rootScope.currentUser, function(err, res) {
if (err) {
$scope.eventsCount = 0;
$scope.message = 'Error loading page';
} else {
$scope.eventsCount = res;
}
});

Users.itemsCount($rootScope.currentUser, function(err, res) {
if (err) {
$scope.itemsCount = 0;
$scope.message = 'Error loading page';
} else {
$scope.itemsCount = res;
}
});

Users.reviewsCount($rootScope.currentUser, function(err, res) {
if (err) {
$scope.reviewsCount = 0;
$scope.message = 'Error loading page';
} else {
$scope.reviewsCount = res;
}
Expand Down
Loading

0 comments on commit 7799c34

Please sign in to comment.