Skip to content

Commit

Permalink
Added tags
Browse files Browse the repository at this point in the history
  • Loading branch information
abdullin committed Jul 26, 2011
1 parent 8413943 commit 28e002a
Show file tree
Hide file tree
Showing 17 changed files with 378 additions and 76 deletions.
4 changes: 2 additions & 2 deletions FarleyFile.Abstractions/FarleyFile.Abstractions.csproj
Expand Up @@ -58,7 +58,7 @@
<Compile Include="Views\ItemIndex.cs" /> <Compile Include="Views\ItemIndex.cs" />
<Compile Include="Views\NoteList.cs" /> <Compile Include="Views\NoteList.cs" />
<Compile Include="Views\NoteView.cs" /> <Compile Include="Views\NoteView.cs" />
<Compile Include="Views\StoryComposite.cs" /> <Compile Include="Views\FocusComposite.cs" />
<Compile Include="Views\StoryList.cs" /> <Compile Include="Views\StoryList.cs" />
<Compile Include="Views\StoryView.cs" /> <Compile Include="Views\StoryView.cs" />
<Compile Include="Views\TaskList.cs" /> <Compile Include="Views\TaskList.cs" />
Expand All @@ -80,4 +80,4 @@
<Target Name="AfterBuild"> <Target Name="AfterBuild">
</Target> </Target>
--> -->
</Project> </Project>
16 changes: 16 additions & 0 deletions FarleyFile.Abstractions/IEvent.cs
Expand Up @@ -116,6 +116,8 @@ public ActivityId(Guid id)


ActivityId() {} ActivityId() {}
} }


[DataContract] [DataContract]
public sealed class TaskId : Identity public sealed class TaskId : Identity
{ {
Expand All @@ -128,4 +130,18 @@ public TaskId(Guid id)


TaskId() {} TaskId() {}
} }

[DataContract]
public sealed class TagId : Identity
{
public const int TagIdValue = 7;
public TagId(Guid id)
{
Tag = TagIdValue;
Id = id;
}


TagId() { }
}
} }
3 changes: 2 additions & 1 deletion FarleyFile.Abstractions/IdentityEvil.cs
Expand Up @@ -14,7 +14,8 @@ static IdentityEvil()
{NoteId.TagId, g => new NoteId(g)}, {NoteId.TagId, g => new NoteId(g)},
{StoryId.TagId, g => new StoryId(g)}, {StoryId.TagId, g => new StoryId(g)},
{TaskId.TagId, g => new TaskId(g)}, {TaskId.TagId, g => new TaskId(g)},
{ActivityId.TagId, g => new ActivityId(g)} {ActivityId.TagId, g => new ActivityId(g)},
{TagId.TagIdValue, g => new TagId(g)}
}; };
} }


Expand Down
43 changes: 43 additions & 0 deletions FarleyFile.Abstractions/Messages.cs
Expand Up @@ -238,6 +238,49 @@ public TaskAdded (TaskId taskId, string text, StoryId storyId)
} }
} }


[DataContract] public sealed class TagItem : ICommand
{
[DataMember(Order = 1)] public string Tag { get; internal set; }
[DataMember(Order = 2)] public Identity ItemId { get; internal set; }

internal TagItem () {}
public TagItem (string tag, Identity itemId)
{
Tag = tag;
ItemId = itemId;
}
}

[DataContract] public sealed class TagCreated : IEvent
{
[DataMember(Order = 1)] public string Tag { get; internal set; }
[DataMember(Order = 2)] public TagId TagId { get; internal set; }

internal TagCreated () {}
public TagCreated (string tag, TagId tagId)
{
Tag = tag;
TagId = tagId;
}
}

[DataContract] public sealed class TagAddedToStory : IEvent
{
[DataMember(Order = 1)] public StoryId StoryId { get; internal set; }
[DataMember(Order = 2)] public TagId TagId { get; internal set; }
[DataMember(Order = 3)] public string Tag { get; internal set; }
[DataMember(Order = 4)] public string StoryName { get; internal set; }

internal TagAddedToStory () {}
public TagAddedToStory (StoryId storyId, TagId tagId, string tag, string storyName)
{
StoryId = storyId;
TagId = tagId;
Tag = tag;
StoryName = storyName;
}
}

[DataContract] public sealed class ArchiveItem : ICommand [DataContract] public sealed class ArchiveItem : ICommand
{ {
[DataMember(Order = 1)] public Identity Id { get; internal set; } [DataMember(Order = 1)] public Identity Id { get; internal set; }
Expand Down
8 changes: 8 additions & 0 deletions FarleyFile.Abstractions/Messages.tt
Expand Up @@ -18,6 +18,7 @@ let taskId = TaskId TaskId;
let date = DateTime Date; let date = DateTime Date;
let activity = ActivityId ActivityId; let activity = ActivityId ActivityId;
let id = Identity Id; let id = Identity Id;
let tagId = TagId TagId;
let time = DateTimeOffset Time; let time = DateTimeOffset Time;
PerspectiveCreated! () PerspectiveCreated! ()


Expand Down Expand Up @@ -51,6 +52,13 @@ AddTask? (string text, storyId)
TaskAdded! (taskId, string text, storyId) TaskAdded! (taskId, string text, storyId)




TagItem? (string tag, Identity itemId)
TagCreated! (string tag, tagId)

TagAddedToStory! (storyId, tagId, string tag, string storyName)



ArchiveItem? (id, storyId) ArchiveItem? (id, storyId)


NoteArchived!(noteId, storyId) NoteArchived!(noteId, storyId)
Expand Down
24 changes: 24 additions & 0 deletions FarleyFile.Abstractions/Views/FocusComposite.cs
@@ -0,0 +1,24 @@
using System.Collections.Generic;

namespace FarleyFile.Views
{
public sealed class FocusComposite
{
public readonly Identity Focus;
public readonly string Name;

//public readonly StoryView View;
public readonly ICollection<ActivityList.Item> Activities;
public readonly ICollection<TaskList.Item> Tasks;
public readonly ICollection<NoteList.Item> Notes;

public FocusComposite(Identity id, string name, ICollection<ActivityList.Item> activities, ICollection<TaskList.Item> tasks, ICollection<NoteList.Item> notes)
{
Focus = id;
Name = name;
Activities = activities;
Tasks = tasks;
Notes = notes;
}
}
}
18 changes: 0 additions & 18 deletions FarleyFile.Abstractions/Views/StoryComposite.cs

This file was deleted.

7 changes: 5 additions & 2 deletions FarleyFile.Abstractions/Views/StoryView.cs
Expand Up @@ -8,9 +8,12 @@ public sealed class StoryView : IEntityBase
{ {
public string Name { get; set; } public string Name { get; set; }
public StoryId StoryId { get; set; } public StoryId StoryId { get; set; }
public IDictionary<string, TagId> Tags { get; private set; }



public StoryView()

{
Tags = new Dictionary<string,TagId>();
}




} }
Expand Down
39 changes: 39 additions & 0 deletions FarleyFile.Abstractions/Views/TaskList.cs
Expand Up @@ -47,4 +47,43 @@ public sealed class Item
public bool Completed { get; set; } public bool Completed { get; set; }
} }
} }

public sealed class TagList : IEntityBase
{
public Dictionary<string, TagId> Items { get; private set; }

public TagList()
{
Items = new Dictionary<string, TagId>();
}
}

public sealed class TagView : IEntityBase
{
public string Name { get; set; }
public TagId Id { get; set; }

public List<StoryItem> Stories { get; private set; }

public void AddStory(StoryId id, string name)
{
Stories.Add(new StoryItem()
{
Name = name,
Story = id
});
}

public TagView()
{
Stories = new List<StoryItem>();
}


public sealed class StoryItem
{
public string Name { get; set; }
public StoryId Story { get; set; }
}
}
} }
1 change: 1 addition & 0 deletions FarleyFile.Desktop/FarleyFile.Desktop.csproj
Expand Up @@ -58,6 +58,7 @@
<Compile Include="Interactions\InteractionProcessor.cs" /> <Compile Include="Interactions\InteractionProcessor.cs" />
<Compile Include="Interactions\InteractionResultStatus.cs" /> <Compile Include="Interactions\InteractionResultStatus.cs" />
<Compile Include="Interactions\Specific\DoAddActivity.cs" /> <Compile Include="Interactions\Specific\DoAddActivity.cs" />
<Compile Include="Interactions\Specific\FocusOnStory.cs" />
<Compile Include="Solarized.cs" /> <Compile Include="Solarized.cs" />
<Compile Include="Form1.cs"> <Compile Include="Form1.cs">
<SubType>Form</SubType> <SubType>Form</SubType>
Expand Down
42 changes: 0 additions & 42 deletions FarleyFile.Desktop/Interactions/Specific/ClearScreen.cs
Expand Up @@ -36,48 +36,6 @@ namespace FarleyFile.Interactions.Specific
// } // }
//} //}


public sealed class FocusOnStory : AbstractInteraction
{
protected override string[] Alias
{
get { return new[] { "cd",""}; }
}

public override InteractionResult Handle(InteractionContext context)
{
StoryId id;
var source = context.Request.Data;
if (string.IsNullOrEmpty(source))
{
id = context.Request.CurrentStoryId;
if (id.IsEmpty)
{
return Error("Story id was not specified and there is no focused story");
}
}
else if (!context.Request.TryGetId(source, out id))
{
return Error("Could not find story ID '{0}'", source);
}

var store = context.Storage;
var result = store.GetEntity<StoryView>(id);
if (!result.HasValue)
{
return Error("Story id not found '{0}'", id);
}
var story = result.Value;
var activities = store.GetEntity<ActivityList>(id).GetValue(new ActivityList());
var tasks = store.GetEntity<TaskList>(id).GetValue(new TaskList());
var notes = store.GetEntity<NoteList>(id).GetValue(new NoteList());
var composite = new StoryComposite(story, activities, tasks, notes);
context.Response.RenderView(composite);
context.Response.FocusStory(story.StoryId, story.Name);

return Handled();
}
}

public sealed class DoAddNote : AbstractInteraction public sealed class DoAddNote : AbstractInteraction
{ {
protected override string[] Alias protected override string[] Alias
Expand Down
105 changes: 105 additions & 0 deletions FarleyFile.Desktop/Interactions/Specific/FocusOnStory.cs
@@ -0,0 +1,105 @@
using System.Collections.Generic;
using FarleyFile.Views;
using System.Linq;

namespace FarleyFile.Interactions.Specific
{
public sealed class DoTagItem : AbstractInteraction
{
protected override string[] Alias
{
get { return new[] {"tag"}; }
}

public override InteractionResult Handle(InteractionContext context)
{
var items = context.Request.Data.Split(' ');
Identity itemId;
if (!context.Request.TryGetId(items[0], out itemId))
{
return Error("Failed to lookup item '{0}'", items[0]);
}
context.Response.SendToProject(new TagItem(items[1], itemId));
return Handled();
}
}

public sealed class ListTags : AbstractInteraction
{
protected override string[] Alias
{
get { return new string[] {"lt"}; }
}

public override InteractionResult Handle(InteractionContext context)
{
var tags = context.Storage.GetSingletonOrNew<TagList>();
context.Response.RenderView(tags);
return Handled();
}
}

public sealed class FocusOnStory : AbstractInteraction
{
protected override string[] Alias
{
get { return new[] { "cd",""}; }
}

public override InteractionResult Handle(InteractionContext context)
{
Identity id;
var source = context.Request.Data;
if (string.IsNullOrEmpty(source))
{
id = context.Request.CurrentStoryId;
if (id.IsEmpty)
{
return Error("Id was not specified and there is no focused story");
}
}
else if (!context.Request.TryGetId(source, out id))
{
return Error("Could not find story ID '{0}'", source);
}
var store = context.Storage;
if (id is StoryId)
{
var result = store.GetEntity<StoryView>(id);
if (!result.HasValue)
{
return Error("Story id not found '{0}'", id);
}
var story = result.Value;
var activities = store.GetEntity<ActivityList>(id).GetValue(new ActivityList());
var tasks = store.GetEntity<TaskList>(id).GetValue(new TaskList());
var notes = store.GetEntity<NoteList>(id).GetValue(new NoteList());
var composite = new FocusComposite(story.StoryId, story.Name, activities.List, tasks.List, notes.Notes);
context.Response.RenderView(composite);
context.Response.FocusStory(story.StoryId, story.Name);
return Handled();
}
if (id is TagId)
{
var result = store.GetEntity<TagView>(id);
if (!result.HasValue)
{
return Error("Tag not found '{0}'", id);
}
var view = result.Value;
var stories = view.Stories
.Select(s => store.GetEntity<StoryView>(s.Story))
.Where(o => o.HasValue)
.Select(o => o.Value)
.ToList();
var activities = stories.SelectMany(s => store.GetEntity<ActivityList>(s.StoryId).Convert(al => al.List, new List<ActivityList.Item>())).ToList();
var tasks = stories.SelectMany(s => store.GetEntity<TaskList>(s.StoryId).Convert(al => al.List, new List<TaskList.Item>())).ToList();
var notes = stories.SelectMany(s => store.GetEntity<NoteList>(s.StoryId).Convert(al => al.Notes, new List<NoteList.Item>())).ToList();
var composite = new FocusComposite(id, view.Name, activities, tasks, notes);
context.Response.RenderView(composite);
return Handled();
}
return Error("Can't focus");
}
}
}

0 comments on commit 28e002a

Please sign in to comment.