Skip to content
This repository has been archived by the owner on Jan 7, 2023. It is now read-only.

Commit

Permalink
Sample updates.
Browse files Browse the repository at this point in the history
  • Loading branch information
RickStrahl committed Apr 1, 2015
1 parent 0a93172 commit 5eec949
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 44 deletions.
Binary file modified Samples/AlbumViewer/AlbumViewerAngular/Scripts/_references.js
Binary file not shown.
13 changes: 5 additions & 8 deletions Samples/AlbumViewer/AlbumViewerAngular/app/js/albumController.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,16 @@


if (!app.configuration.useLocalData)
albumController.$inject = ['$routeParams', '$window', '$animate', 'albumService'];
albumController.$inject = ['$routeParams', '$window', '$animate', 'albumService','errorService'];
else
albumController.$inject = [ '$routeParams', '$window', '$animate','albumServiceLocal'];
albumController.$inject = [ '$routeParams', '$window', '$animate','albumServiceLocal','errorService'];

function albumController($routeParams,$window,$animate,albumService) {
function albumController($routeParams,$window,$animate,albumService,errorService) {
var vm = this;

vm.album = null;
vm.selectedArtist = { ArtistName: null, Description: null };
vm.error = {
message: null,
icon: "warning",
reset: function() { vm.error = { message: "", icon: "warning"} }
};
vm.error = errorService.error;

vm.isSongVisible = false;
vm.song = {
Expand Down Expand Up @@ -110,6 +106,7 @@

// set up the type ahead control
vm.bandTypeAhead();
vm.error.reset();

// force explicit animation of the view and edit forms always
//$animate.addClass("#MainView","slide-animation");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
.success(function (data) {
service.albums = data;
})
.error(onPageError);

}

function getAlbum(id, useExisting) {
Expand Down
50 changes: 15 additions & 35 deletions Samples/AlbumViewer/AlbumViewerAngular/app/js/albumsController.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,16 @@
.controller('albumsController', albumsController);

if (!app.configuration.useLocalData)
albumsController.$inject = ['$scope', 'albumService'];
albumsController.$inject = ['$scope', 'albumService','errorService'];
else
albumsController.$inject = ['$scope','albumServiceLocal'];
albumsController.$inject = ['$scope','albumServiceLocal','errorService'];

function albumsController($scope, albumService) {
function albumsController($scope, albumService,errorService) {
console.log("albums controller accessed.");
var vm = this;
vm.albums = null;

vm.error = {
message: null,
icon: "warning",
reset: function () { vm.error = { message: "", icon: "warning" } },
error: function(message, icon) {
vm.error.reset();
vm.error.message = message;
if (!icon)
icon = "error";

vm.icon = icon;
},
info: function(message, icon) {
vm.error.reset();
vm.error.message = message;
if (!icon)
icon = "info";
vm.icon = icon;
}
};
vm.error = errorService.error;

// filled view event emit from root form
vm.searchText = '';
Expand All @@ -47,41 +28,40 @@
.success(function(data) {
vm.albums = data;
})
.error(function(err) {
vm.error.error(err.message);
});
.error(vm.error.parseHttpError);
};
vm.albumClick = function (album) {
vm.albumClick = function(album) {
window.location = "#/album/" + album.Id;
};
vm.addAlbum = function () {
vm.addAlbum = function() {
albumService.album = albumService.newAlbum();
albumService.updateAlbum(albumService.album);
window.location = "#/album/edit/" + albumService.album.Id;
};
vm.deleteAlbum = function (album) {
vm.deleteAlbum = function(album) {
// on purpose! - force explicit prompt to minimize vandalization of demo
if(!confirm("Are you sure you want to delete this album?"))
if (!confirm("Are you sure you want to delete this album?"))
return;

albumService.deleteAlbum(album)
.success(function(){
.success(function() {
vm.albums = albumService.albums;
})
.error(onPageError);
.error(vm.error.parseHttpError);
};
vm.albumsFilter = function (alb) {
vm.albumsFilter = function(alb) {
var search = vm.searchText.toLowerCase();
if (!alb || !alb.Title)
return false;

if ( alb.Title.toLowerCase().indexOf(search) > -1 ||
if (alb.Title.toLowerCase().indexOf(search) > -1 ||
alb.Artist.ArtistName.toLowerCase().indexOf(search) > -1)
return true;

return false;
};



// forwarded from Header controller
$scope.$root.$on('onsearchkey', function (e,searchText) {
Expand All @@ -90,7 +70,7 @@

// controller initialization
vm.getAlbums();

vm.error.reset();

return;
}
Expand Down
88 changes: 88 additions & 0 deletions Samples/AlbumViewer/AlbumViewerAngular/app/js/errorService.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
(function () {
'use strict';

angular
.module('app')
.service('errorService', errorService);

errorService.$inject = [];

function errorService() {
var vm = {
message: null,
icon: "warning",
reset: function() {
vm.message = null;
vm.icon = "warning";
},
error: function(message, icon) {
vm.error.reset();
vm.error.message = message;
if (!icon)
icon = "error";

vm.icon = icon;
},
info: function(message, icon) {
vm.reset();
vm.message = message;
if (!icon)
icon = "info";
vm.icon = icon;
},
parseHttpError: function() {
var args = arguments;

// error/message object passed rather than parm object
if (args.hasOwnProperty("message")) {
vm.message = args.message;
return;
}
if (args.hasOwnProperty("Message")) {
vm.message = args.Message;
return;
}

var data = args[0]; // http content
var status = args[1];
var msg = args[2];
if(typeof msg != "String")
msg = null;

if (data) {
if (data.hasOwnProperty("message")) {
vm.message = data.message;
return;
}
if (data.hasOwnProperty("Message")) {
vm.message = data.Message;
return;
}

// assume JSON
try {
var msg = JSON.parse(data);
if (msg && msg.hasOwnProperty("message"))
vm.message = msg.message;
else if (msg.hasOwnProperty("Message"))
vm.message = msg.Message;

if(vm.message)
return;
} catch (exception) {}
}
if (!msg) {
if (status === 404)
msg = "URL not found.";
else if (status === 401)
msg = "Not authorized.";
else
msg = "Unknown error. Status: " + status;
}
vm.message = msg;
}
};

this.error = vm;
}
})();
1 change: 1 addition & 0 deletions Samples/AlbumViewer/AlbumViewerAngular/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@

<script src="app/js/albumServiceLocal.js"></script>
<script src="app/js/artistServiceLocal.js"></script>
<script src="app/js/errorService.js"></script>

<script src="app/js/headerController.js"></script>
<script src="app/js/albumsController.js"></script>
Expand Down

0 comments on commit 5eec949

Please sign in to comment.