diff --git a/Areas/admin/Controllers/metaController.cs b/Areas/admin/Controllers/metaController.cs index 01715d6..3566291 100644 --- a/Areas/admin/Controllers/metaController.cs +++ b/Areas/admin/Controllers/metaController.cs @@ -1,4 +1,5 @@ -using BuildFeed.Models; +using BuildFeed.Areas.admin.Models.ViewModel; +using BuildFeed.Models; using System; using System.Collections.Generic; using System.Linq; @@ -19,7 +20,58 @@ group i by i.Id.Type into b var pendingLabs = MetaItem.SelectUnusedLabs(); - return View(); + return View(new MetaListing() + { + CurrentItems = from i in MetaItem.Select() + group i by i.Id.Type into b + select b, + + NewItems = from i in (from l in MetaItem.SelectUnusedLabs() + select new MetaItem() + { + Id = new MetaItemKey() + { + Type = MetaType.Lab, + Value = l + } + }) + group i by i.Id.Type into b + select b + }); + } + + public ActionResult create(MetaType type, string value) + { + return View(new MetaItem() { Id = new MetaItemKey() { Type = type, Value = value } }); + } + + [HttpPost] + public ActionResult create(MetaItem meta) + { + if (ModelState.IsValid) + { + MetaItem.Insert(meta); + return RedirectToAction("index"); + } + + return View(meta); + } + + public ActionResult edit(MetaType type, string value) + { + return View("create", MetaItem.SelectById(new MetaItemKey() { Type = type, Value = value })); + } + + [HttpPost] + public ActionResult edit(MetaItem meta) + { + if (ModelState.IsValid) + { + MetaItem.Update(meta); + return RedirectToAction("index"); + } + + return View("create", meta); } } } \ No newline at end of file diff --git a/Areas/admin/Models/ViewModel/MetaListing.cs b/Areas/admin/Models/ViewModel/MetaListing.cs new file mode 100644 index 0000000..de3d5c7 --- /dev/null +++ b/Areas/admin/Models/ViewModel/MetaListing.cs @@ -0,0 +1,14 @@ +using BuildFeed.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; + +namespace BuildFeed.Areas.admin.Models.ViewModel +{ + public class MetaListing + { + public IEnumerable> CurrentItems { get; set; } + public IEnumerable> NewItems { get; set; } + } +} \ No newline at end of file diff --git a/Areas/admin/Views/base/index.cshtml b/Areas/admin/Views/base/index.cshtml index 2909c94..b1e3814 100644 --- a/Areas/admin/Views/base/index.cshtml +++ b/Areas/admin/Views/base/index.cshtml @@ -11,6 +11,9 @@
  • @Html.ActionLink("View administrators", "admins", "users")
  • +
  • + @Html.ActionLink("Manage metadata", "index", "meta") +
  • @if (User.Identity.Name == "hounsell") {
  • @Html.ActionLink("Initial setup", "setup")
  • diff --git a/Areas/admin/Views/meta/create.cshtml b/Areas/admin/Views/meta/create.cshtml new file mode 100644 index 0000000..11da63b --- /dev/null +++ b/Areas/admin/Views/meta/create.cshtml @@ -0,0 +1,71 @@ +@model BuildFeed.Models.MetaItem + +@{ + ViewBag.Title = string.Format("Add metadata for {0}|| BuildFeed", Model.Id.Value); +} + +

    @string.Format("Add metadata for {0}", Model.Id.Value)

    + +@using (Html.BeginForm()) +{ + @Html.AntiForgeryToken() + + @Html.HiddenFor(model => model.Id.Type); + @Html.HiddenFor(model => model.Id.Value); + +
    +
    + @Html.LabelFor(model => model.MetaDescription, htmlAttributes: new { @class = "control-label col-sm-2" }) +
    +
    +
    + @Html.TextAreaFor(model => model.MetaDescription, new { @class = "form-control", rows = "2" }) +
    +
    + @Html.ValidationMessageFor(model => model.MetaDescription) +
    +
    + +
    + @Html.LabelFor(model => model.PageContent, new { @class = "control-label col-sm-2" }) +
    +
    +
    + @Html.TextAreaFor(model => model.PageContent, new { @class = "form-control" }) +
    +
    + @Html.ValidationMessageFor(model => model.PageContent) +
    +
    + +
    +
    + +
    +
    +
    +} + +@section Scripts +{ + + + + @Scripts.Render("~/bundles/jqueryval") + + +} \ No newline at end of file diff --git a/Areas/admin/Views/meta/index.cshtml b/Areas/admin/Views/meta/index.cshtml new file mode 100644 index 0000000..d17b3b1 --- /dev/null +++ b/Areas/admin/Views/meta/index.cshtml @@ -0,0 +1,55 @@ +@model BuildFeed.Areas.admin.Models.ViewModel.MetaListing + +@{ + ViewBag.Title = "Metadata | BuildFeed"; +} + +

    Metadata

    +

    Current items

    + + + + + + + + + @foreach (var group in Model.CurrentItems) + { + + + + foreach (var item in group) + { + + + + + } + } + +
    Name

    @group.Key

    @item.Id.Value@Html.ActionLink("Edit", "edit", new { type = item.Id.Type, value = item.Id.Value }, new { @class = "btn btn-info btn-xs btn-block" })
    +

    Add new metadata

    + + + + + + + + + @foreach (var group in Model.NewItems) + { + + + + foreach (var item in group) + { + + + + + } + } + +
    Name

    @group.Key

    @item.Id.Value@Html.ActionLink("Create", "create", new { type = item.Id.Type, value = item.Id.Value }, new { @class = "btn btn-info btn-xs btn-block" })
    \ No newline at end of file diff --git a/Areas/admin/adminAreaRegistration.cs b/Areas/admin/adminAreaRegistration.cs index 2f0dfa1..66fcb8a 100644 --- a/Areas/admin/adminAreaRegistration.cs +++ b/Areas/admin/adminAreaRegistration.cs @@ -14,6 +14,12 @@ public override string AreaName public override void RegisterArea(AreaRegistrationContext context) { + context.MapRoute( + "Meta", + "admin/{controller}/{action}/{type}/{value}", + new { action = "index", controller = "meta" } + ); + context.MapRoute( "Admin (Default)", "admin/{controller}/{action}/{id}", diff --git a/BuildFeed.csproj b/BuildFeed.csproj index 5d7860c..7c95c5b 100644 --- a/BuildFeed.csproj +++ b/BuildFeed.csproj @@ -179,6 +179,7 @@ + @@ -220,6 +221,8 @@ + + @@ -308,8 +311,6 @@ - - diff --git a/Controllers/buildController.cs b/Controllers/buildController.cs index 45efbbb..004aebb 100644 --- a/Controllers/buildController.cs +++ b/Controllers/buildController.cs @@ -41,6 +41,8 @@ public ActionResult lab(string lab, int page = 1) ViewBag.PageNumber = page; ViewBag.PageCount = Math.Ceiling(Convert.ToDouble(builds.Count()) / Convert.ToDouble(pageSize)); + ViewBag.MetaItem = MetaItem.SelectById(new MetaItemKey() { Type = MetaType.Lab, Value = lab }); + return View("index", pageBuilds); } diff --git a/Models/MetaItem.cs b/Models/MetaItem.cs index d480233..2596ec6 100644 --- a/Models/MetaItem.cs +++ b/Models/MetaItem.cs @@ -1,6 +1,7 @@ using NServiceKit.DataAnnotations; using NServiceKit.DesignPatterns.Model; using NServiceKit.Redis; +using System; using System.Collections.Generic; using System.ComponentModel; using System.ComponentModel.DataAnnotations; @@ -121,8 +122,20 @@ public static void DeleteById(long id) public struct MetaItemKey { - public object Value { get; set; } + public string Value { get; set; } public MetaType Type { get; set; } + + public MetaItemKey(string id) + { + var items = id.Split(':'); + Type = (MetaType)Enum.Parse(typeof(MetaType), items[0]); + Value = items[1]; + } + + public override string ToString() + { + return string.Format("{0}:{1}", Type, Value); + } } public enum MetaType diff --git a/Views/build/create.cshtml b/Views/build/create.cshtml index 5d1de3d..9dbe7cc 100644 --- a/Views/build/create.cshtml +++ b/Views/build/create.cshtml @@ -227,7 +227,7 @@ @Scripts.Render("~/bundles/jqueryval") -