Skip to content
Permalink
d28a1d40f1
Switch branches/tags

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?
Go to file
 
 
Cannot retrieve contributors at this time
305 lines (278 sloc) 10.8 KB
// 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: "5%", 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);
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);
})
});
}
// 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);
})
});
};
// Initialize Order Informations
$scope.initOrders = function () {
$scope.getPlaylists();
$scope.getMyPlaylists();
$scope.getMyOrder();
}
/* End Function Definitions */
/* Begin Logic */
});