Skip to content

Commit

Permalink
Worked on List, edit, show UI for Projects, Sits, Photos, Bookmarks, …
Browse files Browse the repository at this point in the history
…Tags, AudioEvents.

Details and edit are on the same page now.

modified:   Gemfile
modified:   Gemfile.lock
new file:   app/assets/javascripts/angular/controllers/audio_events.js
new file:   app/assets/javascripts/angular/controllers/bookmarks.js
deleted:    app/assets/javascripts/angular/controllers/photo.js
modified:   app/assets/javascripts/angular/controllers/photos.js
modified:   app/assets/javascripts/angular/controllers/projects.js
modified:   app/assets/javascripts/angular/controllers/sites.js
modified:   app/assets/javascripts/angular/controllers/tags.js
modified:   app/assets/javascripts/angular/services/services.js
modified:   app/assets/javascripts/app.js
modified:   app/assets/stylesheets/_layout.css.scss
renamed:    app/assets/javascripts/angular/controllers/recording.js -> app/assets/templates/bookmark_details.html
renamed:    app/assets/templates/search_show.html -> app/assets/templates/bookmarks_list.html
modified:   app/assets/templates/home.html
renamed:    app/assets/templates/photo.html -> app/assets/templates/photo_details.html
deleted:    app/assets/templates/photos.html
new file:   app/assets/templates/photos_list.html
new file:   app/assets/templates/project_details.html
deleted:    app/assets/templates/project_edit.html
deleted:    app/assets/templates/project_show.html
modified:   app/assets/templates/projects_list.html
renamed:    app/assets/templates/tags.html -> app/assets/templates/search_details.html
new file:   app/assets/templates/site_details.html
deleted:    app/assets/templates/site_edit.html
deleted:    app/assets/templates/site_show.html
new file:   app/assets/templates/tag_details.html
new file:   app/assets/templates/tags_list.html
modified:   app/models/project.rb
  • Loading branch information
Mark Cottman-Fields committed Jan 7, 2013
1 parent cb2a691 commit bdab4af
Show file tree
Hide file tree
Showing 27 changed files with 458 additions and 237 deletions.
29 changes: 29 additions & 0 deletions app/assets/javascripts/angular/controllers/audio_events.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"use strict";

function AudioEventsCtrl($scope, $resource, Project) {
$scope.audioEventsResource = $resource('/audioEvents', {});
$scope.audioEvents = $scope.audioEventsResource.query();

$scope.links = function(key) {
return AudioEventsCtrl.linkList(this.audioEvent.id)[key];
};

$scope.delete = function(id) {
alert("deleting audio event {0}!".format(id));
};
}

AudioEventsCtrl.linkList = function (id) {
return {
edit: '/audioEvents/' + id + '/edit',
details: '/audioEvents/' + id
};
};

AudioEventsCtrl.$inject = ['$scope', '$resource', 'AudioEvent'];

function AudioEventCtrl($scope, $resource, $routeParams, AudioEvent) {

}

AudioEventCtrl.$inject = ['$scope', '$resource', '$routeParams', 'AudioEvent'];
28 changes: 28 additions & 0 deletions app/assets/javascripts/angular/controllers/bookmarks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"use strict";

function BookmarksCtrl($scope, $resource, Bookmark) {
$scope.bookmarksResource = $resource('/bookmarks', {});
$scope.bookmarks = $scope.bookmarksResource.query();

$scope.links = function(key) {
return BookmarksCtrl.linkList(this.bookmark.id)[key];
};

$scope.delete = function(id) {
alert("deleting bookmark {0}!".format(id));
};
}

BookmarksCtrl.linkList = function (id) {
return {
edit: '/bookmarks/' + id + '/edit',
details: '/bookmarks/' + id
};
};

BookmarksCtrl.$inject = ['$scope', '$resource', 'Bookmark'];

function BookmarkCtrl($scope, $resource, $routeParams, Bookmark) {
}

BookmarkCtrl.$inject = ['$scope', '$resource', '$routeParams', 'Bookmark'];
11 changes: 0 additions & 11 deletions app/assets/javascripts/angular/controllers/photo.js

This file was deleted.

75 changes: 71 additions & 4 deletions app/assets/javascripts/angular/controllers/photos.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,74 @@
"use strict";
function PhotosCtrl($scope, $resource) {
$scope.photosResource = $resource('/photos', {}, { get: { method:'GET', params:{}, isArray: true }});
$scope.photos = $scope.photosResource.get();

function PhotosCtrl($scope, $resource, Photo) {
$scope.photosResource = $resource('/photos', {});
$scope.photos = $scope.photosResource.query();

$scope.links = function(key) {
return PhotosCtrl.linkList(this.photo.id)[key];
};
}

PhotosCtrl.$inject = ['$scope', '$resource'];
PhotosCtrl.linkList = function (id) {
return {
edit: '/photos/' + id + '/edit',
details: '/photos/' + id
};
};

PhotosCtrl.$inject = ['$scope', '$resource', 'Photo'];

function PhotoCtrl($scope, $resource, $routeParams, Photo) {

var photoResource = Photo;
var routeArgs = {photoId: $routeParams.photoId};

$scope.editing = $routeParams.editing === "edit";

$scope.photo = photoResource.get(routeArgs, function () {
$scope.links = PhotosCtrl.linkList($scope.photo.id);

$scope.original = angular.copy($scope.project);

});

$scope.links = {};

$scope.delete = function() {
var doit = confirm("Are you sure you want to delete this photo (id {0})?".format(this.project.id));
if (doit) {
photoResource.remove();
}
};

$scope.reset = function() {
if($scope.editing){
$scope.project = angular.copy($scope.original);
}
};

$scope.update = function updateProject() {
if($scope.editing){
// do not send back the full object for update
var p = { "photo": {} };
// p.project.name = $scope.project.name;
// p.project.urn = $scope.project.urn;
// p.project.description = $scope.project.description;
// p.project.notes = $scope.project.notes;
//
// p.project.siteIds = $scope.siteIds;

photoResource.update(routeArgs, p, function() {
$scope.original = angular.copy($scope.site);
var msg = "Photo details updated successfully.";
console.log(msg); alert(msg);
}, function() {
var msg = "There was a problem updating the photo details. Please check for errors and try again.";
console.log(msg); alert(msg);
});
}
};
}

PhotoCtrl.$inject = ['$scope', '$resource', '$routeParams', 'Photo'];

108 changes: 74 additions & 34 deletions app/assets/javascripts/angular/controllers/projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ function ProjectsCtrl($scope, $resource, Project) {
$scope.links = function(key) {
return ProjectsCtrl.linkList(this.project.id)[key];
};

$scope.delete = function(id) {
alert("deleting project {0}!".format(id));
};
}

ProjectsCtrl.linkList = function (id) {
Expand All @@ -22,31 +18,43 @@ ProjectsCtrl.linkList = function (id) {

ProjectsCtrl.$inject = ['$scope', '$resource', 'Project'];

function ProjectCtrl($scope, $resource, $routeParams, Project, Site) {
function ProjectCtrl($scope, $location, $resource, $routeParams, Project, Site, Photo) {

var projectResource = Project; //$resource('/projects/:projectId', {projectId: $routeParams.projectId});
var routeArgs = {projectId: $routeParams.projectId};

$scope.siteIds = [];

$scope.editing = $routeParams.editing === "edit";

// $scope.editMode = function(mode){
// if(mode){
// $scope.editing = true;
// $location.path($location.path()+'/edit');
// } else {
// $scope.editing = false;
// }
// };

$scope.project = projectResource.get(routeArgs, function () {
$scope.links = ProjectsCtrl.linkList($scope.project.id);

$scope.original = angular.copy($scope.project);

// HACK: race condition requires this be done later (not sure what we're racing)
setTimeout(function(){
// need ids to pre-populate selector
var currentSiteIds = $scope.project.sites || [];
for(var index=0;currentSiteIds.length > index;index++){
$scope.siteIds.push(currentSiteIds[index].id.toString());
}

// HACK: and this too...
$scope.$apply(function() { });
// the timeout required is based on the time to wait to ensure the data is available
}, 1000);

if($scope.editing) {
// HACK: race condition requires this be done later (not sure what we're racing)
setTimeout(function(){
// need ids to pre-populate selector
var currentSiteIds = $scope.project.sites || [];
for(var index=0;currentSiteIds.length > index;index++){
$scope.siteIds.push(currentSiteIds[index].id.toString());
}

// HACK: and this too...
$scope.$apply(function() { });
// the timeout required is based on the time to wait to ensure the data is available
}, 1000);
}

//$scope.siteIds.push(($scope.project.sites || []).map(function(value) {return value.id.toString()} );

Expand All @@ -57,34 +65,66 @@ function ProjectCtrl($scope, $resource, $routeParams, Project, Site) {
$scope.links = {};

$scope.delete = function() {
var doit = confirm("deleting project {0}!".format(this.project.id));
var doit = confirm("Are you sure you want to delete this project (id {0})?".format(this.project.id));
if (doit) {
projectResource.remove();
}
};

$scope.deletePhoto = function(photoId){
var doit = confirm("Are you sure you want to delete this photo (id {0})?".format(photoId));
if (doit) {

for(var remPhotoIndex = 0;remPhotoIndex<this.project.photos.length;remPhotoIndex++){
if(this.project.photos[remPhotoIndex].id === photoId){
// remove the element
this.project.photos.splice(remPhotoIndex, 1);
break;
}
}
}
};

$scope.reset = function() {
$scope.project = angular.copy($scope.original);
if($scope.editing){
$scope.project = angular.copy($scope.original);
}
};

$scope.update = function updateProject() {
// do not send back the full object for update
var p = { "project": {} };
p.project.name = $scope.project.name;
p.project.urn = $scope.project.urn;
p.project.description = $scope.project.description;
p.project.notes = $scope.project.notes;

p.project.siteIds = $scope.siteIds;

projectResource.update(routeArgs, p, function() {
console.log("Updating Project: success.");
$scope.original = angular.copy($scope.project);
}, function() { console.log("Updating Project: failed.")} );
if($scope.editing){
// do not send back the full object for update
var p = { "project": {} };

p.project.name = $scope.project.name;
p.project.urn = $scope.project.urn;
p.project.description = $scope.project.description;
p.project.notes = $scope.project.notes;

p.project.siteIds = $scope.siteIds;

p.project.photos_attributes = [];
for(var photoindex=0;photoindex<$scope.project.photos.length;photoindex++){
p.project.photos_attributes[photoindex] = {};
p.project.photos_attributes[photoindex].uri = $scope.project.photos[photoindex].uri;
p.project.photos_attributes[photoindex].description = $scope.project.photos[photoindex].description;
p.project.photos_attributes[photoindex].copyright = $scope.project.photos[photoindex].copyright;
p.project.photos_attributes[photoindex].id = $scope.project.photos[photoindex].id;
}

projectResource.update(routeArgs, p, function() {
$scope.original = angular.copy($scope.site);
var msg = "Project details updated successfully.";
console.log(msg); alert(msg);
}, function() {
var msg = "There was a problem updating the project details. Please check for errors and try again.";
console.log(msg); alert(msg);
});
}
};

$scope.allSites = Site.query();
}

ProjectCtrl.$inject = ['$scope', '$resource', '$routeParams', 'Project', 'Site'];
ProjectCtrl.$inject = ['$scope', '$location', '$resource', '$routeParams', 'Project', 'Site'];

17 changes: 10 additions & 7 deletions app/assets/javascripts/angular/controllers/sites.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ function SitesCtrl($scope, $resource, Site) {
$scope.links = function(key) {
return SitesCtrl.linkList(this.site.id)[key];
};

$scope.delete = function(id) {
alert("deleting site {0}!".format(id));
};
}

SitesCtrl.linkList = function (id) {
Expand All @@ -26,6 +22,8 @@ function SiteCtrl($scope, $resource, $routeParams, Project, Site, AudioRecording
var siteResource = Site;
var routeArgs = {siteId: $routeParams.siteId};

$scope.editing = $routeParams.editing === "edit";

$scope.site = siteResource.get(routeArgs, function () {
$scope.links = SitesCtrl.linkList($scope.site.id);

Expand All @@ -38,9 +36,10 @@ function SiteCtrl($scope, $resource, $routeParams, Project, Site, AudioRecording
$scope.links = {};

$scope.delete = function() {
var doit = confirm("deleting site {0}!".format(this.site.id));
var doit = confirm("Are you sure you want to delete this site (id {0})?".format(this.site.id));
if (doit) {
siteResource.remove();

}
};

Expand All @@ -55,9 +54,13 @@ function SiteCtrl($scope, $resource, $routeParams, Project, Site, AudioRecording
p.site.notes = $scope.site.notes;

siteResource.update(routeArgs, p, function() {
console.log("Updating Site: success.");
$scope.original = angular.copy($scope.site);
}, function() { console.log("Updating Site: failed.")} );
var msg = "Site details updated successfully.";
console.log(msg); alert(msg);
}, function() {
var msg = "There was a problem updating the site details. Please check for errors and try again.";
console.log(msg); alert(msg);
});
};
}

Expand Down
29 changes: 29 additions & 0 deletions app/assets/javascripts/angular/controllers/tags.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"use strict";

function TagsCtrl($scope, $resource, Tag) {
$scope.tagsResource = $resource('/tags', {});
$scope.tags = $scope.tagsResource.query();

$scope.links = function(key) {
return TagsCtrl.linkList(this.tag.id)[key];
};

$scope.delete = function(id) {
alert("deleting tag {0}!".format(id));
};
}

TagsCtrl.linkList = function (id) {
return {
edit: '/tags/' + id + '/edit',
details: '/tags/' + id
};
};

TagsCtrl.$inject = ['$scope', '$resource', 'Tag'];

function TagCtrl($scope, $resource, $routeParams, Tag) {

}

TagCtrl.$inject = ['$scope', '$resource', '$routeParams', 'Tag'];
4 changes: 4 additions & 0 deletions app/assets/javascripts/angular/services/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
return resourcePut($resource, '/sites/:siteId', {siteId: "@siteId"});
});

bawss.factory('Photo', function ($resource) {
return resourcePut($resource, '/photos/:photoId', {photoId: "@photoId"});
});

bawss.factory('AudioRecording', function ($resource) {
return resourcePut($resource, '/audio_recordings/:recordingId', {recordingId: '@recordingId'});
});
Expand Down
Loading

0 comments on commit bdab4af

Please sign in to comment.