Skip to content
Browse files

tiny Busy changes

this is going to be much harder since the API doesn't expose archived
tasks
  • Loading branch information...
1 parent e8680e3 commit 14a23efc373e41d7329c68974d176f59e270e5bf @cbarbara committed Jun 18, 2012
View
4 AsanaApi/AsanaApi.csproj
@@ -67,7 +67,9 @@
<Compile Include="Service\UsersService.cs" />
<Compile Include="Service\WorkspacesService.cs" />
</ItemGroup>
- <ItemGroup />
+ <ItemGroup>
+ <Folder Include="Analytics\" />
+ </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
View
33 Website/Controllers/BusyWeekController.cs
@@ -29,13 +29,13 @@ public ActionResult Index()
private void FindWeekRange( out DateTime startOfWeek, out DateTime endOfWeek )
{
- DateTime now = DateTime.UtcNow.Date;
- while( now.DayOfWeek != DayOfWeek.Sunday )
- {
- now = now.AddDays( -1 );
- }
+ DateTime now = DateTime.UtcNow.Date; //new DateTime( 2012, 6, 17 );
+ ////while( now.DayOfWeek != DayOfWeek.Sunday )
+ ////{
+ //// now = now.AddDays( -1 );
+ ////}
endOfWeek = now;
- startOfWeek = endOfWeek.AddDays( -7 );
+ startOfWeek = endOfWeek.AddDays( -7 );//-17 );
}
@@ -50,7 +50,8 @@ public JsonResult GetTasks( TasksSearchQuery data )
{
TasksService tasksService = new TasksService( Shared.API_KEY );
List<Task> allTasks = new List<Task>();
- Task[] tasks = null,
+ Task[] tasks = null;
+ BusyTask[] startedAndCompleted = null,
started = null,
completed = null;
@@ -63,28 +64,28 @@ public JsonResult GetTasks( TasksSearchQuery data )
}
}
- GetTasks( DateTime.Parse( data.Start ), DateTime.Parse( data.End ), allTasks, out tasks, out started, out completed );
+ GetTasks( DateTime.Parse( data.Start ), DateTime.Parse( data.End ), allTasks, out startedAndCompleted, out started, out completed );
TasksSearchResults results = new TasksSearchResults()
{
StartedDuringRange = started,
CompletedDuringRange = completed,
- StartedAndCompletedDuringRange = tasks
+ StartedAndCompletedDuringRange = startedAndCompleted
};
return Json( results );
}
- private void GetTasks( DateTime startDateUtc, DateTime endDateUtc, List<Task> allTasks, out Task[] startedAndCompleted, out Task[] started, out Task[] completed )
+ private void GetTasks( DateTime startDateUtc, DateTime endDateUtc, List<Task> allTasks, out BusyTask[] startedAndCompleted, out BusyTask[] started, out BusyTask[] completed )
{
endDateUtc = endDateUtc.AddDays( 1 );
startedAndCompleted = null;
started = null;
completed = null;
- List<Task> startedTasks = new List<Task>(),
- completedTasks = new List<Task>(),
- startedAndCompletedTasks = new List<Task>();
+ List<BusyTask> startedTasks = new List<BusyTask>(),
+ completedTasks = new List<BusyTask>(),
+ startedAndCompletedTasks = new List<BusyTask>();
foreach( var t in allTasks )
{
@@ -94,19 +95,19 @@ private void GetTasks( DateTime startDateUtc, DateTime endDateUtc, List<Task> al
{
if( t.CreatedAt >= startDateUtc && t.CompletedAt.Value < endDateUtc )
{
- startedAndCompletedTasks.Add( t );
+ startedAndCompletedTasks.Add( new BusyTask( t ) );
}
else if( t.CompletedAt.Value < endDateUtc )
{
- completedTasks.Add( t );
+ completedTasks.Add( new BusyTask( t ) );
}
}
}
else
{
if( t.CreatedAt >= startDateUtc )
{
- startedTasks.Add( t );
+ startedTasks.Add( new BusyTask( t ) );
}
}
}
View
35 Website/Models/BusyWeek/BusyWeekModel.cs
@@ -6,26 +6,53 @@
namespace Website.Models.BusyWeek
{
+ [Serializable]
public class BusyWeekModel
{
public DateTime StartDate { get; set; }
-
public DateTime EndDate { get; set; }
}
+ [Serializable]
public class TasksSearchQuery
{
public string Start { get; set; }
public string End { get; set; }
public List<long> Workspaces { get; set; }
}
+ [Serializable]
public class TasksSearchResults
{
- public Task[] StartedDuringRange { get; set; }
+ public BusyTask[] StartedDuringRange { get; set; }
+ public BusyTask[] CompletedDuringRange { get; set; }
+ public BusyTask[] StartedAndCompletedDuringRange { get; set; }
+ }
- public Task[] CompletedDuringRange { get; set; }
+ [Serializable]
+ public class BusyTask
+ {
+ public BusyTask() { }
+ public BusyTask( Task task )
+ {
+ this.Name = task.Name;
+ this.CreatedAt = task.CreatedAt;
+ this.CompletedAt = task.CompletedAt;
+
+ if( this.CompletedAt.HasValue )
+ {
+ this.TimeTaken = Shared.ToRelativeTime( this.CompletedAt.Value - this.CreatedAt );
+ }
+ else
+ {
+ this.CurrentRunTime = Shared.ToRelativeTime( DateTime.UtcNow - this.CreatedAt );
+ }
+ }
- public Task[] StartedAndCompletedDuringRange { get; set; }
+ public string Name { get; set; }
+ public DateTime CreatedAt { get; set; }
+ public DateTime? CompletedAt { get; set; }
+ public string TimeTaken { get; set; }
+ public string CurrentRunTime { get; set; }
}
}
View
36 Website/Scripts/AsanaApi.BusyWeek.js
@@ -3,6 +3,10 @@
var _endDate = null;
var _workspaces = new Array();
+ function _parseDate(aspNetMvcDate) {
+ return new Date(parseInt(aspNetMvcDate.substr(6)));
+ }
+
function _onWorkspacesFound(result) {
var wsDiv = $("#workspaces");
var content = "<br/><span>Workspaces being searched for Tasks:</span><ul>";
@@ -32,32 +36,44 @@
});
}
function _onTasksFound(result) {
- console.log(result.CompletedDuringRange);
- console.log(result.StartedAndCompletedDuringRange);
- console.log(result.StartedDuringRange);
-
$("#tasks").children().remove();
if (result.CompletedDuringRange == null) {
- $("#cTasks").html("<em>none</em>");
+ $("#cTasks").html("No tasks created before the start date and completed in this time range.<br/>");
}
else {
- $("#cTasks").html(result.CompletedDuringRange.length);
+ $("#cTasks").html(_renderTasks(result.CompletedDuringRange, " tasks created before the start date and completed in this time range."));
}
if (result.StartedDuringRange == null) {
- $("#sTasks").html("<em>none</em>");
+ $("#sTasks").html("No tasks created in this time range, but not yet completed.<br/>");
}
else {
- $("#sTasks").html(result.StartedDuringRange.length);
+ $("#sTasks").html(_renderTasks(result.StartedDuringRange, " tasks created in this time range, but not yet completed."));
}
if (result.StartedAndCompletedDuringRange == null) {
- $("#sacTasks").html("<em>none</em>");
+ $("#sacTasks").html("No tasks created and completed in this time range.<br/>");
}
else {
- $("#sacTasks").html(result.StartedAndCompletedDuringRange.length);
+ $("#sacTasks").html(_renderTasks(result.StartedAndCompletedDuringRange, " tasks created and completed in this time range."));
+ }
+ }
+ function _renderTasks(tasks, message) {
+ var content = "<span>" + tasks.length.toString() + message + "</span><ul>";
+ for (var i = 0; i < tasks.length; i++) {
+ content += "<li><div>" + tasks[i].Name + "<br/>";
+ content += "Started: " + _parseDate(tasks[i].CreatedAt) + "<br/>";
+ if (tasks[i].TimeTaken != null) {
+ content += "Finished: " + _parseDate(tasks[i].CompletedAt) + "<br/>";
+ content += "Time taken: " + tasks[i].TimeTaken;
+ }
+ else {
+ content += "Unfinished For: " + tasks[i].CurrentRunTime;
+ }
+ content += "</div></li>";
}
+ return content + "</ul>";
}
return {
View
54 Website/Shared.cs
@@ -15,5 +15,59 @@ public class Shared
public static Project[] Projects;
public static int DefaultProjectIndex = 0;
+
+ public static string ToRelativeTime( TimeSpan ts )
+ {
+ //stolen from http://stackoverflow.com/questions/11/calculating-relative-time
+ const int SECOND = 1;
+ const int MINUTE = 60 * SECOND;
+ const int HOUR = 60 * MINUTE;
+ const int DAY = 24 * HOUR;
+ const int MONTH = 30 * DAY;
+ double delta = Math.Abs( ts.TotalSeconds );
+
+ if( delta < 0 )
+ {
+ return "not yet";
+ }
+ if( delta < 1 * MINUTE )
+ {
+ return ts.Seconds == 1 ? "one second" : ts.Seconds + " seconds";
+ }
+ if( delta < 2 * MINUTE )
+ {
+ return "a minute";
+ }
+ if( delta < 45 * MINUTE )
+ {
+ return ts.Minutes + " minutes";
+ }
+ if( delta < 90 * MINUTE )
+ {
+ return "an hour";
+ }
+ if( delta < 24 * HOUR )
+ {
+ return ts.Hours + " hours";
+ }
+ if( delta < 48 * HOUR )
+ {
+ return "yesterday";
+ }
+ if( delta < 30 * DAY )
+ {
+ return ts.Days + " days";
+ }
+ if( delta < 12 * MONTH )
+ {
+ int months = Convert.ToInt32( Math.Floor( (double)ts.Days / 30 ) );
+ return months <= 1 ? "one month" : months + " months";
+ }
+ else
+ {
+ int years = Convert.ToInt32( Math.Floor( (double)ts.Days / 365 ) );
+ return years <= 1 ? "one year" : years + " years";
+ }
+ }
}
}
View
6 Website/Views/BusyWeek/Index.cshtml
@@ -20,9 +20,9 @@
</div>
<div id="workspaces"></div>
<div id="tasks"></div>
-<div id="sacTasks"></div>
-<div id="cTasks"></div>
-<div id="sTasks"></div>
+<div id="sacTasks"></div><br />
+<div id="cTasks"></div><br />
+<div id="sTasks"></div><br />
@section footerScripts {
<script type="text/javascript">
View
4 Website/Website.csproj
@@ -158,9 +158,7 @@
<Content Include="Views\Shared\_Layout.cshtml" />
<Content Include="Views\Web.config" />
</ItemGroup>
- <ItemGroup>
- <Folder Include="App_Data\" />
- </ItemGroup>
+ <ItemGroup />
<ItemGroup>
<Content Include="packages.config" />
</ItemGroup>

0 comments on commit 14a23ef

Please sign in to comment.
Something went wrong with that request. Please try again.