Permalink
Browse files

Adding Avatar functionality to Groups and Users WIP

  • Loading branch information...
1 parent b5e7ba2 commit 460f8896bc1fc02ed9934d35339c5f5cab97f02b @hamishcrittenden hamishcrittenden committed May 23, 2012
@@ -12,6 +12,8 @@
*/
+using System;
+
namespace Bowerbird.Core.Config
{
public static class Constants
@@ -20,12 +22,49 @@ public static class Constants
public static string AppRootId = "bowerbird/approot";
}
+ /// <summary>
+ /// Set an Avatar Type when creating new entity which requires a blank Avatar.
+ /// Possibilities are Project, Team, Organisation and User
+ /// </summary>
+ public enum AvatarDefaultType
+ {
+ Project,
+ Team,
+ Organisation,
+ User
+ }
+
public static class AvatarUris
{
public static string DefaultUser = "/img/default-user-avatar.jpg";
public static string DefaultProject = "/img/default-project-avatar.jpg";
public static string DefaultTeam = "/img/default-team-avatar.jpg";
public static string DefaultOrganisation = "/img/default-organisation-avatar.jpg";
+
+ public static string AvatarTypeUris(this AvatarDefaultType avatarType)
+ {
+ switch (avatarType)
+ {
+ case AvatarDefaultType.Project:
+ {
+ return DefaultProject;
+ }
+ case AvatarDefaultType.Team:
+ {
+ return DefaultTeam;
+ }
+ case AvatarDefaultType.Organisation:
+ {
+ return DefaultOrganisation;
+ }
+ case AvatarDefaultType.User:
+ {
+ return DefaultUser;
+ }
+ default:
+ throw new ApplicationException("No Avatar Type Specified");
+ }
+ }
}
public static class ActivitySender
@@ -126,4 +165,5 @@ public static class Default
public static int PageSize = 10;
public static int PageMax = 100;
}
+
}
@@ -11,6 +11,7 @@
*/
using System.Linq;
+using Bowerbird.Core.Config;
using Bowerbird.Core.DesignByContract;
using Bowerbird.Core.DomainModels;
using Bowerbird.Core.Indexes;
@@ -61,6 +62,19 @@ public object BuildProject(IdInput idInput)
return MakeProject(project);
}
+ public object BuildNewProject()
+ {
+ return new
+ {
+ Id = "",
+ Name = "New Project",
+ Description = "New Project",
+ Website = "",
+ Avatar = _avatarFactory.MakeDefaultAvatar(AvatarDefaultType.Project, "New Project"),
+ MemberCount = 1
+ };
+ }
+
public object BuildProjectList(PagingInput pagingInput)
{
RavenQueryStatistics stats;
@@ -184,7 +198,7 @@ private object MakeProject(All_Groups.Result result)
{
return new
{
- Id = result.Project.Id,
+ result.Project.Id,
result.Project.Name,
result.Project.Description,
result.Project.Website,
@@ -83,9 +83,9 @@ public ActionResult PostUpload(string key, string originalFileName, HttpPostedFi
[HttpPost]
[Authorize]
- public ActionResult AvatarUpload(string key, string originalFileName, HttpPostedFileBase file)
+ public ActionResult AvatarUpload(HttpPostedFileBase file, string recordType)
{
- return ProcessPostedImage(key, originalFileName, file, "user");
+ return ProcessPostedImage(string.Empty, string.Empty, file, recordType);
}
private ActionResult ProcessPostedImage(string key, string originalFileName, HttpPostedFileBase file, string recordType)
@@ -214,7 +214,11 @@ public ActionResult CreateForm(IdInput idInput)
Name = "Enter Name",
Description = "Enter Description",
Website = "Enter Website",
- ImgUrl = "/img/default-project-avatar.jpg"
+ Avatar = new
+ {
+ UrlToImage = "../img/default-team-avatar.jpg",
+ AltTag = "Project"
+ }
},
Teams = GetTeams(_userContext.GetAuthenticatedUserId())
@@ -327,7 +331,11 @@ public ActionResult Leave(IdInput idInput)
[HttpPost]
public ActionResult Create(ProjectCreateInput createInput)
{
- if (!_userContext.HasGroupPermission(PermissionNames.CreateProject, createInput.Team ?? Constants.AppRootId))
+ Check.RequireNotNull(createInput, "createInput");
+
+ var groupId = createInput.Team != null ? createInput.Team.PrependWith("teams/") : Constants.AppRootId;
+
+ if (!_userContext.HasGroupPermission(PermissionNames.CreateProject, groupId))
{
return HttpUnauthorized();
}
@@ -200,14 +200,19 @@ public ActionResult CreateForm(IdInput idInput)
Name = "Enter Name",
Description = "Enter Description",
Website = "Enter Website",
- ImgUrl = "../img/default-team-avatar.jpg"
+ Avatar = new
+ {
+ UrlToImage = "../img/default-team-avatar.jpg",
+ AltTag = "Project"
+ }
},
+
Organisations = GetOrganisations(_userContext.GetAuthenticatedUserId())
};
if (Request.IsAjaxRequest())
{
- return new JsonNetResult(ViewBag.Model);
+ return new JsonNetResult(new {Model = ViewBag.Model});
}
ViewBag.PrerenderedView = "teams";
@@ -3,10 +3,8 @@
Developers:
* Frank Radocaj : frank@radocaj.com
* Hamish Crittenden : hamish.crittenden@gmail.com
-
Project Manager:
* Ken Walker : kwalker@museum.vic.gov.au
-
Funded by:
* Atlas of Living Australia
@@ -46,6 +44,15 @@ IMediaFilePathService mediaFilePathService
#region Methods
+ public object MakeDefaultAvatar(AvatarDefaultType avatarType, string altTag)
+ {
+ return new
+ {
+ AltTag = altTag,
+ UrlToImage = avatarType.AvatarTypeUris()
+ };
+ }
+
public object Make(Team team)
{
return new
@@ -3,24 +3,28 @@
Developers:
* Frank Radocaj : frank@radocaj.com
* Hamish Crittenden : hamish.crittenden@gmail.com
-
Project Manager:
* Ken Walker : kwalker@museum.vic.gov.au
-
Funded by:
* Atlas of Living Australia
*/
+using Bowerbird.Core.Config;
using Bowerbird.Core.DomainModels;
namespace Bowerbird.Web.Factories
{
public interface IAvatarFactory
{
object Make(Team team);
+
object Make(Project project);
+
object Make(Organisation organisation);
+
object Make(User user);
+
+ object MakeDefaultAvatar(AvatarDefaultType avatarType, string altTag);
}
}
@@ -131,6 +131,7 @@
<Content Include="js\bowerbird\collections\streamItemCollection.js" />
<Content Include="js\bowerbird\collections\userCollection.js" />
<Content Include="js\bowerbird\controllers\observationController.js" />
+ <Content Include="js\bowerbird\models\avatar.js" />
<Content Include="js\bowerbird\models\referenceSpecies.js" />
<Content Include="js\bowerbird\models\species.js" />
<Content Include="js\bowerbird\models\organisation.js" />
@@ -40,17 +40,13 @@
</div>
</div>
</fieldset>
- <fieldset id="media-resources-fieldset">
+ <fieldset id="avatar-fieldset">
<legend>Avatar Image</legend>
- <div id="avatar" class="field">
- <div>
- <label for="avatar">Project Avatar</label>
- </div>
- <div id="avatar-field" class="field">
- <img src="{{Model.Project.ImgUrl}}" />
- </div>
- <div id="avatar-upload-button" class="button avatar-upload-button">
- Change Avatar<input id="fileupload" type="file" name="file" multiple="" />
+ <div id="avatar-viewer" class="field">
+ </div>
+ <div id="avatar-add-pane" class="field">
+ <div id="media-resource-upload-button" class="button media-resource-upload-button">
+ Change Avatar Image<input id="fileupload" type="file" name="file" multiple="" />
</div>
</div>
</fieldset>
@@ -1,3 +1,4 @@
-<div id="media-resource-upload-button" class="button media-resource-upload-button">
+<p>Avatar Choose File</p>
+<div id="media-resource-upload-button" class="button media-resource-upload-button">
Change Avatar Image<input id="fileupload" type="file" name="file" multiple="" />
</div>
@@ -14,4 +14,15 @@
</div>
</div>
</div>
-</div>
+</div>
+
+<!--
+<div>
+ <label for="avatar">Project Avatar</label>
+</div>
+<div id="avatar-field" class="field">
+ <img src="{{Model.Project.ImgUrl}}" />
+ </div>
+ <div id="avatar-upload-button" class="button avatar-upload-button">
+ Change Avatar<input id="fileupload" type="file" name="file" multiple="" />
+</div>-->
@@ -16,7 +16,7 @@
<!--DEV-->
<bowerbird>
<!--<environment rootPath="c:\projects\bowerbird.web\src\bowerbird.website" rootUri="http://localhost:65060" />-->
- <environment rootPath="c:\projects\bowerbird\bowerbird-web\src\bowerbird.website" rootUri="http://localhost:65060" />
+ <environment rootPath="c:\projects\bowerbird.web\src\bowerbird.website" rootUri="http://localhost:65060" />
<documentStore databaseName="" url="http://localhost:8080/" />
<email serverName="vespa.mv.vic.gov.au" adminAccount="fradocaj@museum.vic.gov.au" resetPasswordRelativeUri="/account/resetpassword/{0}" />
<media rootUri="/media/" relativePath="\media\" />
@@ -0,0 +1,24 @@
+/// <reference path="../../libs/log.js" />
+/// <reference path="../../libs/require/require.js" />
+/// <reference path="../../libs/jquery/jquery-1.7.2.js" />
+/// <reference path="../../libs/underscore/underscore.js" />
+/// <reference path="../../libs/backbone/backbone.js" />
+/// <reference path="../../libs/backbone.marionette/backbone.marionette.js" />
+
+// MediaResource
+// -------------
+
+define(['jquery', 'underscore', 'backbone', 'app'], function ($, _, Backbone, app) {
+
+ var Avatar = Backbone.Model.extend({
+ defaults: {
+ AltTag: 0,
+ UrlToImage: '/img/image-upload.png'
+ },
+
+ idAttribute: 'Id'
+ });
+
+ return MediaResource;
+
+});
@@ -12,6 +12,12 @@ define(['jquery', 'underscore', 'backbone', 'app'], function ($, _, Backbone, ap
var Project = Backbone.Model.extend({
defaults: {
+ Id: '',
+ Name: '',
+ Description: '',
+ Website: '',
+ Avatar: null,
+ Team: null,
Type: 'Project'
},
@@ -29,6 +35,10 @@ define(['jquery', 'underscore', 'backbone', 'app'], function ($, _, Backbone, ap
Team: this.get('Team'),
Type: 'Project'
};
+ },
+
+ setAvatar: function (mediaResource) {
+ this.set('Avatar', mediaResource.id);
}
});
@@ -20,16 +20,19 @@ define(['jquery', 'underscore', 'backbone', 'app', 'ich'], function ($, _, Backb
'click .remove-media-resource-button': 'removeMediaResource'
},
- template: "AvatarUploaded",
+ //template: "AvatarUploaded",
initialize: function (options) {
_.extend(this, Backbone.Events);
- _.bindAll(this, 'showTempMedia', 'showUploadedMedia');
+ _.bindAll(this,
+ 'showTempMedia',
+ 'showUploadedMedia'
+ );
this.mediaResource = options.MediaResource;
this.mediaResource.on('change:mediumImageUri', this.showUploadedMedia);
},
- onRender: function () {
+ render: function () {
// this.$el.append(ich.AvatarUploaded(this.MediaResource.toJSON()));
// return this;
},
Oops, something went wrong.

0 comments on commit 460f889

Please sign in to comment.