Skip to content
Permalink
56a17a02ad
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
579 lines (506 sloc) 18.3 KB
// This controller will hold logic for the employee Portal homepage (Order List, Logout), Customer Info, Media Center, and Reports
angular.module('routerApp').controller('adminController', function ($scope, $http, $log, $timeout, $cookies, urlService, $anchorScroll, $location, $q, $state, $rootScope, HolderService, $uibModal,uiGridConstants) {
/* Retrieve Url */
var url = urlService.web;
$scope.name = $cookies.get('name');
/* Functions Defined */
// Logging out
$scope.logout = function () {
$cookies.remove('userid');
$cookies.remove('isAdmin');
$cookies.remove('name');
$state.go('home');
}
/* Dealing with Order Processing */
// Initialize Employee Portal
$scope.initPortal = function () {
$scope.getAllInvoices();
}
// Return all invoices
$scope.getAllInvoices = function () {
/* $http.get("http://localhost:50031/api/GetAllInvoices")
.success(function (response) {
$scope.currInvoices = angular.copy(response);
})*/
//Currently not working
$http.get("http://localhost:50031/api/GetCustomerInvoice?custId=" + 1)
.success(function (response) {
$scope.currInvoices = angular.copy(response);
console.log($scope.currorders);
})
}
// Open window for orders
$scope.openOrder = function (orderid) {
console.log(orderid);
$scope.catcats = orderid;
$scope.getCustomerInfo(orderid.customerId);
//$scope.getOrderTracks(orderid.invoiceId);
var modalInstance = $uibModal.open({
animation: $scope.animationsEnabled,
templateUrl: 'pages/user-ordermodal.html',
scope: $scope,
controller: 'userController',
resolve: {
items: function () {
return $scope.items;
}
}
});
}
// Get information on the customer
$scope.getCustomerInfo = function(customerId){
$http.get("http://localhost:50031/api/GetCustomer?PersonID=" + customerId)
.success(function (response) {
$scope.currOrderCustomer = angular.copy(response);
})
}
/* BEGIN LOGIC */
//New Media
$scope.showMediaOptions = true;
$scope.showTrackFields = false;
$scope.showAlbumFields = false;
$scope.showArtistFields = false;
$scope.showGenreFields = false;
$scope.showMediaTypeFields = false;
$scope.back = function () {
$scope.showMediaOptions = true;
$scope.showTrackFields = false;
$scope.showAlbumFields = false;
$scope.showArtistFields = false;
$scope.showGenreFields = false;
$scope.showMediaTypeFields = false;
}
$scope.toCreateTrack = function () {
$scope.showMediaOptions = false;
$scope.showTrackFields = true;
window.alert("CAUTION: Make sure that the Artist, Album, and Genre fields already exist in the database before creating the track")
};
$scope.toCreateAlbum = function () {
$scope.showMediaOptions = false;
$scope.showAlbumFields = true;
};
$scope.toCreateArtist = function () {
$scope.showMediaOptions = false;
$scope.showArtistFields = true;
};
$scope.toCreateGenre = function () {
$scope.showMediaOptions = false;
$scope.showGenreFields = true;
};
$scope.toCreateMediaType = function () {
$scope.showMediaOptions = false;
$scope.showMediaTypeFields = true;
};
$scope.createTrack = function (newTrack) {
var sub = HolderService.getBlankTrack();
if (newTrack.company == null) {
newTrack.company = null;
}
sub.TrackName = newTrack.trackName;
sub.artist = newTrack.artist;
sub.AlbumTitle = newTrack.albumTitle;
sub.MediaType = newTrack.mediaType;
sub.Genre = newTrack.genre;
sub.Composer = newTrack.composer;
sub.Milliseconds = parseInt(newTrack.milliseconds);
sub.Bytes = parseInt(newTrack.bytes);
sub.UnitPrice = parseFloat(newTrack.unitPrice);
console.log(sub);
var promise = $http({
method: "post",
url: "http://localhost:50031/api/AddTrack",
headers: {
contentType: "application/json"
},
data: sub
}).
success(function (data, status, headers, config) {
$scope.messages = 'You created a track!';
alert($scope.messages);
}).
error(function (error, status, headers, config) {
$scope.messages = 'There was a network error. Try again later.';
alert($scope.messages);
console.log(error);
console.log(error.ExceptionMessage);
console.log(error.ExeceptionType);
console.log(error.StackTrace);
});
}
$scope.createArtist = function (newArtist) {
var sub = {
ArtistID: null,
Name: null
}
sub.Name = newArtist.artistName;
console.log(sub);
var promise = $http({
method: "post",
url: "http://localhost:50031/api/AddArtist",
headers: {
contentType: "application/json"
},
data: sub
}).
success(function (data, status, headers, config) {
$scope.messages = 'You created an artist!';
alert($scope.messages);
}).
error(function (error, status, headers, config) {
$scope.messages = 'There was a network error. Try again later.';
alert($scope.messages);
});
}
$scope.createAlbum = function (newAlbum) {
var sub = {
AlbumID: null,
Title: null,
Artist: null
}
sub.Title = newAlbum.albumName;
sub.Artist = newAlbum.artistName;
console.log(sub);
var promise = $http({
method: "post",
url: "http://localhost:50031/api/AddAlbum",
headers: {
contentType: "application/json"
},
data: sub
}).
success(function (data, status, headers, config, response) {
$scope.messages = 'You created an album!';
alert($scope.messages);
}).
error(function (error, status, headers, config, response) {
$scope.messages = 'There was a network error. Try again later.';
alert($scope.messages);
console.log(error);
console.log(error.ExceptionMessage);
console.log(error.ExeceptionType);
console.log(error.StackTrace);
});
}
$scope.createGenre = function (genreName) {
$http.get("http://localhost:50031/api/AddGenre?GenreName=" + genreName)
.success(function (response) {
$scope.messages = 'You created a genre!';
console.log(response);
alert($scope.messages);
})
}
$scope.createMediaType = function (mediaTypeName) {
$http.get("http://localhost:50031/api/AddMediaType?TypeName=" + mediaTypeName)
.success(function (response) {
$scope.messages = 'You created a media type!';
console.log(response);
alert($scope.messages);
})
}
//End New Media
//CustomerDemographics
$scope.custInfoGridOptions = {
enableFiltering: true,
columnDefs: [
{field: 'FName', displayName: 'First Name'},
{field: 'LName', displayName: 'Last Name'},
{field: 'Address'},
{field: 'City'},
{field: 'State'},
{field: 'Post'},
{field: 'Country'},
{field: 'Phone'},
{field: 'Fax'},
{field: 'Email'},
{field: 'Company'}
]
}
$scope.custInfoGridOptions.data = [
{ FName: "TEST" ,
LName: "TEST" ,
Address: "TEST" ,
City: "TEST" ,
State: "TEST" ,
Post: "TEST" ,
Country: "TEST" ,
Phone: "TEST" ,
Fax : "TEST" ,
Email: "TEST" ,
Company: "TEST"
}
]
$scope.getDemographics = function () {
$scope.custInfoGridOptions.data = [];
console.log($scope.custInfoGridOptions.data);
$http.get("http://localhost:50031/api/GetDemographic")
.success(function (response) {
$scope.custInfoGridOptions.data = angular.copy(response);
$scope.custInfoGridOptions.data.splice(0, 1);
console.log(response);
})
}
//End Customer Demographics
//Playlist Editor
$scope.editing = false;
$scope.currentPlaylist = 0;
$scope.addingTrack = false;
$scope.playlistGridOptions = {
columnDefs: [
{ field: 'PlaylistID', displayName: 'Playlist Id'},
{ field: 'Name', displayName: 'Playlist Name' },
{ field: 'Edit', cellTemplate: '<center><button ng-click="grid.addScope.debug();">Edit</button></center>' },
{ field: 'Delete', cellTemplate: '<center><button ng-click="grid.addScope.deletePlaylist(row.entity.PlaylistID);">Delete</button></center>' }
]
}
$scope.addPlaylist = function () {
var name = prompt("Enter the name of the playlist");
if (name != null) {
$http.get("http://localhost:50031/api/AddPlaylist?playlistname=" + name)
.success(function (response) {
console.log(response);
})
}
window.setTimeout($scope.getPlaylists(),1000);
}
$scope.toEdit = function (playlistID) {
alert("edit");
$scope.editing = true;
$scope.currentPlaylist = playlistID;
$scope.getPlaylistTracks(playlistID);
}
$scope.getPlaylists = function () {
$scope.playlists = [];
$http.get("http://localhost:50031/api/GetPlaylistList")
.success(function (response) {
$scope.playlists = angular.copy(response);
$scope.playlistGridOptions.data = angular.copy(response);
console.log(response);
})
}
$scope.deletePlaylist = function (playlistID) {
alert("delete");
if (confirm("Are you sure you want to delete this playlist? \nPress OK to confirm") == true) {
$scope.dropPlaylist(playlistID);
}
window.setTimeout($scope.getPlaylists(),1000);
}
$scope.dropPlaylist = function (playlistID) {
$http.get("http://localhost:50031/api/DropPlaylist?PlaylistID="+ playlistID)
.success(function (response) {
console.log(response);
})
}
$scope.getPlaylistTracks = function (playlistID) {
$scope.playlistTracks = [];
$http.get("http://localhost:50031/api/GetPlaylist?PlaylistID="+ playlistID)
.success(function (response) {
$scope.playlistTracks = angular.copy(response);
console.log(response);
})
}
$scope.addToPlaylist = function (trackID) {
console.log(trackID);
$http.get("http://localhost:50031/api/AddTrackPlaylist?PlaylistID=" + $scope.currentPlaylist + "&TrackID=" + trackID)
.success(function (response) {
console.log(response);
})
window.setTimeout($scope.getPlaylistTracks($scope.currentPlaylist),1000);
}
$scope.deleteTrack = function (trackID) {
if (confirm("Are you sure you want to delete this track from this playlist? \nPress OK to confirm") == true) {
$scope.dropTrack(trackID);
}
window.setTimeout($scope.getPlaylistTracks($scope.currentPlaylist), 1000);
}
$scope.dropTrack = function (trackID)
{
$http.get("http://localhost:50031/api/RemoveTrack?PlaylistID=" + $scope.currentPlaylist + "&TrackID=" + trackID)
.success(function (response) {
console.log(response);
})
}
$scope.searchGridOptions = {
enableSorting: true,
columnDefs: [
{ field: 'TrackId', displayName: ' ', width: "5%", cellTemplate: '<center><button ng-click="grid.appScope.addToPlaylist(row.entity.TrackId);" class="btn btn-success btn-xs"> + </button></center>' },
{ 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.search = function (token, category) {
console.log(token);
console.log(category);
console.log($scope.data);
$http.get("http://localhost:50031/api/Search?search=" + token)
.success(function (response) {
$scope.data = angular.copy(response);
console.log(response);
if (category == "Track") {
$scope.searchGridOptions.data = $scope.data.Track;
}
else if (category == "Artist") {
$scope.searchGridOptions.data = $scope.data.Artist;
}
else if (category == "Composer") {
$scope.searchGridOptions.data = $scope.data.Composer;
}
else if (category == "Genre") {
$scope.searchGridOptions.data = $scope.data.Genre;
}
else if (category == "Media") {
$scope.searchGridOptions.data = $scope.data.Media;
}
});
}
//End Playlist Editor
//Reports
$scope.showInventory = false;
$scope.showSales = false;
$scope.inReport = false;
$scope.toInventory = function () {
$scope.showInventory = true;
$scope.inReport = true;
}
$scope.toSales = function () {
$scope.showSales = true;
$scope.inReport = true;
}
$scope.toReports = function () {
$scope.showInventory = false;
$scope.showSales = false;
$scope.inReport = false;
}
$scope.getPlaylists = function () {
$scope.playlists = [];
$http.get("http://localhost:50031/api/GetPlaylistList")
.success(function (response) {
$scope.playlists = angular.copy(response);
$scope.playlistGridOptions.data = angular.copy(response);
console.log(response);
})
}
$scope.getReports = function () {
$scope.getInventory();
console.log("inventory");
$scope.getSales();
console.log("sales");
}
$scope.getInventory = function () {
$scope.inventoryGridOptions.data = [];
$http.get("http://localhost:50031/api/GetAllTracks")
.success(function (response) {
$scope.inventoryGridOptions.data = angular.copy(response);
console.log(response);
})
}
$scope.getSales = function () {
$scope.salesGridOptions.data = [];
$http.get("http://localhost:50031/api/GetAllInvoices")
.success(function (response) {
$scope.salesGridOptions.data = angular.copy(response);
console.log(response);
})
}
$scope.inventoryGridOptions = {
enableFiltering: true,
showColumnFooter: true,
showGridFoorter: true,
columnDefs: [
{ field: 'TrackName', displayName: 'Track Title', width:'20%' },
{ field: 'artist' },
{ field: 'AlbumTitle' },
{ field: 'MediaType', displayName: 'Track Title' },
{ field: 'Genre' },
{ field: 'Composer' },
{ field: 'Milliseconds',
filters: [
{
condition: uiGridConstants.filter.GREATER_THAN,
placeholder: 'greater than'
},
{
condition: uiGridConstants.filter.LESS_THAN,
placeholder: 'less than'
}
],
width: '8%'
},
{ field: 'UnitPrice', width : '5%' },
{ field: 'Bytes' }
]
}
$scope.salesGridOptions = {
enableFiltering: true,
showColumnFooter: true,
showGridFoorter: true,
columnDefs: [
{ field: 'invoiceId', displayName: 'Invoice Id',
filters: [
{
condition: uiGridConstants.filter.GREATER_THAN,
placeholder: 'greater than'
},
{
condition: uiGridConstants.filter.LESS_THAN,
placeholder: 'less than'
}
],
width: '5%'
},
{ field: 'customerId', displayName: 'Customer Id',
filters: [
{
condition: uiGridConstants.filter.GREATER_THAN,
placeholder: 'greater than'
},
{
condition: uiGridConstants.filter.LESS_THAN,
placeholder: 'less than'
}
],
width: '5%'
},
{ field: 'invoiceDate', displayName: 'Date' },
{ field: 'address', displayName: 'Street Address' },
{ field: 'city', displayName: 'City' },
{ field: 'state', displayName: 'State', width: '5%' },
{ field: 'country', displayName: 'Country' },
{ field: 'post', displayName: 'Postal Code' },
{field: 'total',
filters: [
{
condition: uiGridConstants.filter.GREATER_THAN,
placeholder: 'greater than'
},
{
condition: uiGridConstants.filter.LESS_THAN,
placeholder: 'less than'
}
]
}
]
}
$scope.inventoryGridOptions.data = [
{
"Title": "Test",
"Artist": "Test",
"Album": "Test",
"Address": "Test",
"MediaType": "Test",
"Genre": "Test",
"Composer": "Test",
"Milliseconds": "Test",
"UnitPrice": "Test",
"Bytes": "Test"
}
]
//End Reports
$scope.debug = function () {
alert("alert")
}
});