Skip to content

Commit

Permalink
Added tags
Browse files Browse the repository at this point in the history
  • Loading branch information
digitalBush committed Aug 11, 2011
1 parent 0c18086 commit 6fbe245
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 11 deletions.
44 changes: 40 additions & 4 deletions sample-app/NoteTaker/NoteTaker/Controllers/NoteController.cs
Expand Up @@ -16,12 +16,48 @@ public class NoteController : Controller

public ActionResult Index()
{
var json = Couch.Uri.Get("_all_docs?include_docs=true");
var notes = JsonConvert.DeserializeObject<DocumentCollection<Note>>(json);

return View(notes.Items.Select(i=>i.Item));
var notes = GetNotes();
var tags = GetTags();

return View(new NoteList()
{
Notes=notes.Items.Select(n=>n.Document),
Tags=tags.Items.ToDictionary(x=>x.Key,x=>Int32.Parse(x.Value))
});
}

public ActionResult Tagged(string id)
{
var notes = GetNotesByTag(id);
var tags = GetTags();

return View("Index",new NoteList()
{
Notes = notes.Items.Select(n => n.Document),
Tags = tags.Items.ToDictionary(x => x.Key, x => Int32.Parse(x.Value))
});
}

public DocumentCollection<Note> GetNotes()
{
var json = Couch.Uri.Get("_design/Notes/_view/all?include_docs=true");
return JsonConvert.DeserializeObject<DocumentCollection<Note>>(json);
}

public DocumentCollection<Note> GetNotesByTag(string tag)
{
var json = Couch.Uri.Get("_design/Tags/_view/all?key=\""+tag+"\"&reduce=false&include_docs=true");
return JsonConvert.DeserializeObject<DocumentCollection<Note>>(json);
}

public DocumentCollection<object> GetTags()
{
var json = Couch.Uri.Get("_design/Tags/_view/all?group_level=1");
return JsonConvert.DeserializeObject<DocumentCollection<object>>(json);
}



public ActionResult Create()
{

Expand Down
2 changes: 1 addition & 1 deletion sample-app/NoteTaker/NoteTaker/Models/Note.cs
Expand Up @@ -16,6 +16,6 @@ public class Note

public string Title { get; set; }
public string Text { get; set; }

public string Tags { get; set; }
}
}
8 changes: 8 additions & 0 deletions sample-app/NoteTaker/NoteTaker/Views/Note/Edit.cshtml
Expand Up @@ -36,6 +36,14 @@
@Html.TextAreaFor(model => model.Text)
</div>

<div class="editor-label">
@Html.LabelFor(model => model.Tags)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Tags)
<em>(separated by spaces)</em>
</div>

<p>
<input type="submit" value="Save" />
</p>
Expand Down
24 changes: 18 additions & 6 deletions sample-app/NoteTaker/NoteTaker/Views/Note/Index.cshtml
@@ -1,4 +1,4 @@
@model IEnumerable<NoteTaker.Models.Note>
@model NoteTaker.Models.NoteList

@{
ViewBag.Title = "List";
Expand All @@ -14,21 +14,33 @@
</th>
<th></th>
</tr>

@foreach (var item in Model) {
@if (!Model.Notes.Any()){
<tr>
<td colspan=2>
<em>No Notes to show.</em>
</td>
</tr>
}
@foreach (var item in Model.Notes)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Title)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id=item.Id }) |
@Html.ActionLink("Delete", "Delete", new { id=item.Id,rev=item.Revision })
@Html.ActionLink("Edit", "Edit", new { id = item.Id }) |
@Html.ActionLink("Delete", "Delete", new { id = item.Id, rev = item.Revision })
</td>
</tr>
}

</table>

<ul>
<li><a href='/Note'>View All</a></li>
@foreach (var tag in Model.Tags.OrderByDescending(x=>x.Value)) {
<li><a href='/Note/Tagged/@tag.Key'>@(tag.Key)(@tag.Value)</a></li>
}
</ul>
<p>
@Html.ActionLink("Create New", "Create")
</p>

0 comments on commit 6fbe245

Please sign in to comment.