Skip to content
Permalink
e66b9c50bc
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
238 lines (217 sloc) 7.83 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: 'TrackId', displayName: ' ', cellTemplate: '<center><button data-ng-click="addToCart(12)" class="btn btn-success btn-xs">Purchase</button></center></td>' },
{ field: 'TrackName', displayName: ' Track Name' },
{ field: 'AlbumTitle', displayName: ' Album Title ' },
{ field: 'MediaType', displayName: ' Media Type ' },
{ field: 'Genre', displayName: ' Genre ' },
{ field: 'Clip', displayName: ' Sound Clip ' },
{ field: 'UnitPrice', displayName: ' Unit Price ' }
];
$scope.gridOptions = {
data: null,
enableSorting: true,
columnDefs: $scope.columns,
onRegisterApi: function (gridApi) {
$scope.gridApi = gridApi;
var cellTemplate = 'ui-grid/selectionRowHeader';
$scope.gridApi.core.addRowHeaderColumn({ name: 'rowHeaderCol', displayName: '', width: 30, cellTemplate: cellTemplate });
}
};
// Search Function
$scope.search = function (token) {
console.log(token);
$http.get("http://localhost:50031/api/Search?search=" + token)
.success(function (response) {
$scope.data = angular.copy(response);
$scope.gridOptions.data = $scope.data.Track;
});
}
/* 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);
}
// 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;
}
}
});
}
// Initialize Order Informations
$scope.initOrders = function () {
$scope.getPlaylists();
$scope.getMyPlaylists();
}
$scope.myData = [
{
"firstName": "Cox",
"lastName": "Carney",
"company": "Enormo",
"employed": true
},
{
"firstName": "Lorraine",
"lastName": "Wise",
"company": "Comveyer",
"employed": false
},
{
"firstName": "Nancy",
"lastName": "Waters",
"company": "Fuelton",
"employed": false
}
];
/* End Function Definitions */
/* Begin Logic */
});