Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
TeamDbAwesome/TeamDBAwesome/TeamDBAwesome/js/userController.js
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
359 lines (328 sloc)
12.8 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The user controller will deal with | |
angular.module('routerApp').controller('userController', function ($q, $window, $scope, $state, $stateParams, $location, $http, $cookies, urlService, $rootScope, HolderService, $uibModal) { | |
/* Retrieve Url */ | |
var url = urlService.web; | |
$location.hash("top"); | |
$scope.COOKIE = $cookies.getAll(); | |
// Logging out | |
$scope.logout = function () { | |
$cookies.remove('userid'); | |
$state.go('home'); | |
console.log("Happening"); | |
} | |
// Customer Information Editing | |
// Retrieve Data | |
$scope.getUserInfo = function () { | |
var customerid = $cookies.get('userid'); | |
console.log(customerid); | |
$scope.user = {}; | |
$http.get("http://localhost:50031/api/GetCustomer?PersonID=" + customerid) | |
.success(function (response) { | |
$scope.user = angular.copy(response); | |
console.log(response); | |
}) | |
} | |
// Update User Information | |
$scope.updateUser = function () { | |
var promise = $http({ | |
method: "post", | |
url: "http://localhost:50031/api/UpdateCustomer", | |
headers: { | |
contentType: "application/json" | |
}, | |
data: $scope.user | |
}). | |
success(function (data, status, headers, config) { | |
$scope.messages = 'You have successfully updated your information. '; | |
}). | |
error(function (error, status, headers, config) { | |
$scope.messages = 'There was a network error. Try again later.'; | |
}); | |
} | |
// Add Payment | |
$scope.addPayment = function (data) { | |
var pay = HolderService.getBlankPayment(); | |
console.log(data); | |
pay.Type = data.type; | |
pay.is_default = 0; | |
pay.CustomerId = $cookies.get('userid'); | |
if (data.token != undefined) pay.token = data.token; | |
if (data.email != undefined) pay.email = data.email; | |
if (data.num != undefined) pay.cardnum = data.num | |
if (data.date != undefined) pay.expr_date = data.date; | |
if (data.default != undefined) pay.is_default = data.default; | |
console.log("below is pay"); | |
console.log(pay); | |
var promise = $http({ | |
method: "post", | |
url: "http://localhost:50031/api/AddPayment", | |
headers: { | |
contentType: "application/json" | |
}, | |
data: pay | |
}). | |
success(function (data, status, headers, config) { | |
$scope.messages = 'You have successfully updated your information. '; | |
}). | |
error(function (error, status, headers, config) { | |
$scope.messages = 'There was a network error. Try again later.'; | |
}); | |
console.log(pay); | |
} | |
// Dealing with Search | |
$scope.columns = [ | |
{ field: 'TrackName', displayName: ' Track Name', width: "20%" }, | |
{ field: 'artist', displayName: ' Artist Name', width: "20%" }, | |
{ field: 'AlbumTitle', displayName: ' Album ', width: "15%" }, | |
{ field: 'MediaType', displayName: ' Media ', width: "10%" }, | |
{ field: 'Genre', displayName: ' Genre ', width: "10%" }, | |
{ field: 'Clip', displayName: ' Clip ', width: "10%" }, | |
{ field: 'UnitPrice', displayName: ' Price ', width: "10%" } | |
]; | |
$scope.orderColumns = [ | |
{ field: 'TrackId', displayName: ' ', width: "30%", cellTemplate: '<center><button data-ng-click="grid.appScope.addToCart({{row.entity.TrackId}})" class="btn btn-success btn-xs"> + </button></center></td>' }, | |
{ field: 'TrackName', displayName: ' Track Name', width: "20%" }, | |
{ field: 'artist', displayName: ' Artist Name', width: "20%" }, | |
{ field: 'AlbumTitle', displayName: ' Album ', width: "15%" }, | |
{ field: 'MediaType', displayName: ' Media ', width: "10%" }, | |
{ field: 'Genre', displayName: ' Genre ', width: "10%" }, | |
{ field: 'Clip', displayName: ' Clip ', width: "10%" }, | |
{ field: 'UnitPrice', displayName: ' Price ', width: "10%" } | |
]; | |
$scope.gridOptions = { | |
data: null, | |
enableSorting: true, | |
columnDefs: $scope.columns, | |
onRegisterApi: function (gridApi) { | |
$scope.gridApi = gridApi; | |
var cellTemplate = 'ui-grid/selectionRowHeader'; | |
} | |
}; | |
$scope.orderOptions = { | |
data: null, | |
enableSorting: true, | |
columnDefs: $scope.orderColumns, | |
onRegisterApi: function (gridApi) { | |
$scope.gridApi = gridApi; | |
var cellTemplate = 'ui-grid/selectionRowHeader'; | |
} | |
}; | |
// Search Function | |
$scope.search = function (token, category) { | |
console.log(token); | |
console.log(category); | |
$http.get("http://localhost:50031/api/Search?search=" + token) | |
.success(function (response) { | |
$scope.data = angular.copy(response); | |
console.log(response); | |
if (category == "Track") { | |
$scope.gridOptions.data = $scope.data.Track; | |
$scope.orderOptions.data = $scope.data.Track; | |
} | |
else if (category == "Artist") { | |
$scope.gridOptions.data = $scope.data.Artist; | |
$scope.orderOptions.data = $scope.data.Artist; | |
} | |
else if (category == "Composer") { | |
$scope.gridOptions.data = $scope.data.Composer; | |
$scope.orderOptions.data = $scope.data.Composer; | |
} | |
else if (category == "Genre") { | |
$scope.gridOptions.data = $scope.data.Genre; | |
$scope.orderOptions.data = $scope.data.Genre; | |
} | |
else if (category == "Media") { | |
$scope.gridOptions.data = $scope.data.Media; | |
$scope.orderOptions.data = $scope.data.Media; | |
} | |
}); | |
} | |
/* Begin Function Definitions */ | |
$scope.authenticateUser = function (id, pass) { | |
return $q(function (resolve, reject) { | |
var param = id + " " + pass; | |
var promise = $http.post(url + "/authenticateUser", param) | |
.success(function (data, status) { | |
console.log(data); | |
if (data.STATUS == 555) { | |
$scope.authenticated = false; | |
resolve('We did it'); | |
} else { | |
$scope.authenticated = true; | |
resolve('We did it'); | |
} | |
}) | |
.error(function (data, status, headers, config) { | |
$scope.messages = 'There was a network error. Try again later.'; | |
reject('We did not do it'); | |
}); | |
}) | |
} | |
$scope.addToCart = function (trackid) { | |
console.log(trackid + "the track id"); | |
var promise = $http({ | |
method: "get", | |
url: "http://localhost:50031/api/AddTrackOrder?trackId=" + trackid + "&orderId=" + $scope.currOrderID, | |
}). | |
success(function (response) { | |
console.log(response); | |
}); | |
promise.then(function () { | |
console.log($scope.currOrderID); | |
$http.get("http://localhost:50031/api/GetOrderTracks?orderId=" + $scope.currOrderID) | |
.success(function (response) { | |
$scope.currOrder = angular.copy(response); | |
console.log($scope.currOrder); | |
}) | |
}); | |
} | |
// functions for adding playlists to cart | |
$scope.addPLToCart = function (plid) { | |
console.log("cats"); | |
console.log(plid); | |
var promise = $http.get("http://localhost:50031/api/GetPlaylist?PlaylistID=" + plid) | |
.success(function (response) { | |
$scope.currplaylist = angular.copy(response); | |
console.log($scope.currplaylist); | |
}); | |
promise.then(function () { | |
console.log($scope.currplaylist); | |
var end = $scope.currplaylist.length; | |
for (var i = 0; i < end; i++) { | |
$scope.addToCart($scope.currplaylist[i].TrackId); | |
} | |
}); | |
} | |
$scope.addMPLToCart = function (plid) { | |
console.log("cats"); | |
console.log(plid); | |
var promise = $http.get("http://localhost:50031/api/GetPlaylist?PlaylistID=" + plid) | |
.success(function (response) { | |
$scope.currplaylist = angular.copy(response); | |
console.log($scope.currplaylist); | |
}); | |
promise.then(function () { | |
console.log($scope.currplaylist); | |
var end = $scope.currplaylist.length; | |
for (var i = 0; i < end; i++) { | |
$scope.addToCart($scope.currplaylist[i].TrackId); | |
} | |
}); | |
} | |
// Order Functions | |
// Get Playlists | |
$scope.getPlaylists = function () { | |
$http.get("http://localhost:50031/api/GetPlaylistList") | |
.success(function (response) { | |
$scope.playlists = angular.copy(response); | |
console.log($scope.playlists); | |
}) | |
}; | |
// Get Custom Playlists | |
$scope.getMyPlaylists = function () { | |
$http.get("http://localhost:50031/api/GetCustomPlaylists?CustomerID=" + $cookies.get('userid')) | |
.success(function (response) { | |
$scope.myPlaylists = angular.copy(response); | |
console.log($scope.myPlaylists); | |
}) | |
}; | |
// Get Playlist Tracks | |
$scope.getPlaylistTracks = function (id) { | |
$http.get("http://localhost:50031/api/GetPlaylist?PlaylistID=" + id) | |
.success(function (response) { | |
$scope.currplaylist = angular.copy(response); | |
console.log($scope.currplaylist); | |
}) | |
}; | |
// Get CustomPlaylist Tracks | |
$scope.getMyPlaylistTracks = function (id) { | |
$http.get("http://localhost:50031/api/GetPlaylist?PlaylistID=" + id) | |
.success(function (response) { | |
$scope.currplaylist = angular.copy(response); | |
console.log($scope.currplaylist); | |
}) | |
}; | |
// Open window for playlist | |
$scope.open = function (playlist) { | |
$scope.getPlaylistTracks(playlist.PlaylistID); | |
$scope.currname = playlist.Name; | |
var modalInstance = $uibModal.open({ | |
animation: $scope.animationsEnabled, | |
templateUrl: 'pages/user-modal.html', | |
scope: $scope, | |
controller: 'userController', | |
resolve: { | |
items: function () { | |
return $scope.items; | |
} | |
} | |
}); | |
} | |
// Open window for custom playlist | |
$scope.openCustom = function (size, playlist) { | |
$scope.getMyPlaylistTracks(playlist.PlaylistID); | |
$scope.currname = playlist.Name; | |
var modalInstance = $uibModal.open({ | |
animation: $scope.animationsEnabled, | |
templateUrl: 'pages/user-modal.html', | |
scope: $scope, | |
controller: 'userController', | |
resolve: { | |
items: function () { | |
return $scope.items; | |
} | |
} | |
}); | |
} | |
// Get the current order for the customer | |
$scope.getMyOrder = function () { | |
var promise = $http({ | |
method: "get", | |
url: "http://localhost:50031/api/GetCustomerOrders?CustomerId=" + $cookies.get('userid'), | |
}). | |
success(function (response) { | |
if (response.length == 0) { | |
$http.get("http://localhost:50031/api/CreateOrder?CustomerID=" + $cookies.get('userid')) | |
.success(function (response) { | |
$scope.currOrderID = angular.copy(response); | |
}) | |
} | |
else { | |
$scope.currOrderID = angular.copy(response); | |
} | |
}); | |
promise.then(function () { | |
console.log($scope.currOrderID); | |
$http.get("http://localhost:50031/api/GetOrderTracks?orderId=" + $scope.currOrderID) | |
.success(function (response) { | |
$scope.currOrder = angular.copy(response); | |
console.log($scope.currOrder); | |
}) | |
}); | |
}; | |
// get Payment info for the current user | |
$scope.getPayments = function () { | |
$http.get("http://localhost:50031/api/GetPayment?CustomerID=" + $cookies.get('userid')) | |
.success(function (response) { | |
$scope.currpayments = angular.copy(response); | |
console.log($scope.currpayments); | |
}) | |
}; | |
// From shopping cart to invoice | |
$scope.buy = function (payid) { | |
$http.get("http://localhost:50031/api/GenerateInvoice?custId=" + $cookies.get('userid') + "&payId=" + payid + "&orderId=" + $scope.currOrderID) | |
.success(function (response) { | |
$state.go('user-orders'); | |
$scope.messages = "Your order has been submitted."; | |
}) | |
} | |
// Initialize Order Informations | |
$scope.initOrders = function () { | |
$scope.getPlaylists(); | |
$scope.getMyPlaylists(); | |
$scope.getMyOrder(); | |
$scope.getPayments(); | |
} | |
/* End Function Definitions */ | |
/* Begin Logic */ | |
}); |