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/adminController.js
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
358 lines (313 sloc)
11.3 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
// 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) { | |
/* Retrieve Url */ | |
var url = urlService.web; | |
$cookies.put('PAGE', 'Admin'); | |
/* Functions Defined */ | |
// Logging out | |
$scope.logout = function () { | |
$cookies.remove('userid'); | |
$state.go('home'); | |
} | |
/* Dealing with Order Processing */ | |
/* 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'} | |
] | |
} | |
//End Customer Demographics | |
//Playlist Editor | |
$scope.editing = false; | |
$scope.currentPlaylist = 0; | |
$scope.addingTrack = false; | |
$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); | |
}) | |
} | |
$scope.getPlaylists(); | |
$state.reload(); | |
} | |
$scope.toEdit = function (playlistID) { | |
$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); | |
console.log(response); | |
}) | |
} | |
$scope.deletePlaylist = function (playlistID) { | |
if (confirm("Are you sure you want to delete this playlist? \nPress OK to confirm") == true) { | |
$scope.dropPlaylist(playlistID); | |
} | |
$scope.getPlaylists(); | |
$state.reload(); | |
} | |
$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); | |
}) | |
$scope.getPlaylistTracks($scope.currentPlaylist); | |
} | |
$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); | |
} | |
} | |
$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.inventoryGridOptions = { | |
enableFiltering: true, | |
columnDefs: [ | |
{ field: 'Title', displayName: 'Track Title' }, | |
{ field: 'Artist' }, | |
{ field: 'Album' }, | |
{ field: 'MediaType', displayName: 'Track Title' }, | |
{ field: 'Genre' }, | |
{ field: 'Composer' }, | |
{ field: 'Milliseconds' }, | |
{ field: 'UnitPrice' }, | |
{ field: 'Bytes' } | |
] | |
} | |
$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 | |
}); |