Finally completed meta system for labs

This commit is contained in:
Thomas Hounsell 2015-01-29 21:44:54 +00:00
parent 9932db03e9
commit 0e3522a24c
12 changed files with 259 additions and 8 deletions

View File

@ -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);
}
}
}

View File

@ -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<IGrouping<MetaType, MetaItem>> CurrentItems { get; set; }
public IEnumerable<IGrouping<MetaType, MetaItem>> NewItems { get; set; }
}
}

View File

@ -11,6 +11,9 @@
<li>@Html.ActionLink("View administrators", "admins", "users")</li>
</ul>
</li>
<li>
@Html.ActionLink("Manage metadata", "index", "meta")
</li>
@if (User.Identity.Name == "hounsell")
{
<li>@Html.ActionLink("Initial setup", "setup")</li>

View File

@ -0,0 +1,71 @@
@model BuildFeed.Models.MetaItem
@{
ViewBag.Title = string.Format("Add metadata for {0}|| BuildFeed", Model.Id.Value);
}
<h2>@string.Format("Add metadata for {0}", Model.Id.Value)</h2>
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
@Html.HiddenFor(model => model.Id.Type);
@Html.HiddenFor(model => model.Id.Value);
<div class="form-horizontal">
<div class="form-group">
@Html.LabelFor(model => model.MetaDescription, htmlAttributes: new { @class = "control-label col-sm-2" })
<div class="col-sm-10">
<div class="row">
<div class="col-sm-8">
@Html.TextAreaFor(model => model.MetaDescription, new { @class = "form-control", rows = "2" })
</div>
</div>
@Html.ValidationMessageFor(model => model.MetaDescription)
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.PageContent, new { @class = "control-label col-sm-2" })
<div class="col-sm-10">
<div class="row">
<div class="col-sm-8">
@Html.TextAreaFor(model => model.PageContent, new { @class = "form-control" })
</div>
</div>
@Html.ValidationMessageFor(model => model.PageContent)
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<input type="submit" value="Add metadata" class="btn btn-primary" />
</div>
</div>
</div>
}
@section Scripts
{
<script src="~/Scripts/trumbowyg/trumbowyg.min.js" type="text/javascript"></script>
<link href="~/Scripts/trumbowyg/ui/trumbowyg.min.css" rel="stylesheet" type="text/css" />
@Scripts.Render("~/bundles/jqueryval")
<script type="text/javascript">
$(function () {
var btnsGrps = $.trumbowyg.btnsGrps;
$("#@Html.IdFor(model => model.PageContent)").trumbowyg({
semantic: true,
autogrow: true,
btns: ['viewHTML',
'|', 'strong', 'em',
'|', 'link',
'|', btnsGrps.justify,
'|', btnsGrps.lists]
});
})
</script>
}

View File

@ -0,0 +1,55 @@
@model BuildFeed.Areas.admin.Models.ViewModel.MetaListing
@{
ViewBag.Title = "Metadata | BuildFeed";
}
<h2>Metadata</h2>
<h3>Current items</h3>
<table class="table table-striped table-bordered table-admin">
<thead>
<tr>
<th>Name</th>
<th style="width:80px;"></th>
</tr>
</thead>
<tbody>
@foreach (var group in Model.CurrentItems)
{
<tr>
<td colspan="3"><h4>@group.Key</h4></td>
</tr>
foreach (var item in group)
{
<tr>
<td>@item.Id.Value</td>
<td>@Html.ActionLink("Edit", "edit", new { type = item.Id.Type, value = item.Id.Value }, new { @class = "btn btn-info btn-xs btn-block" })</td>
</tr>
}
}
</tbody>
</table>
<h3>Add new metadata</h3>
<table class="table table-striped table-bordered table-admin">
<thead>
<tr>
<th>Name</th>
<th style="width:80px;"></th>
</tr>
</thead>
<tbody>
@foreach (var group in Model.NewItems)
{
<tr>
<td colspan="3"><h4>@group.Key</h4></td>
</tr>
foreach (var item in group)
{
<tr>
<td>@item.Id.Value</td>
<td>@Html.ActionLink("Create", "create", new { type = item.Id.Type, value = item.Id.Value }, new { @class = "btn btn-info btn-xs btn-block" })</td>
</tr>
}
}
</tbody>
</table>

View File

@ -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}",

View File

@ -179,6 +179,7 @@
<ItemGroup>
<Compile Include="Areas\admin\Controllers\baseController.cs" />
<Compile Include="Areas\admin\Controllers\metaController.cs" />
<Compile Include="Areas\admin\Models\ViewModel\MetaListing.cs" />
<Compile Include="Auth\RedisRoleProvider.cs" />
<Compile Include="Code\DateTimeModelBinder.cs" />
<Compile Include="Code\DisplayHelpers.cs" />
@ -220,6 +221,8 @@
<Content Include="Areas\admin\Views\base\index.cshtml" />
<Content Include="ApplicationInsights.config" />
<Content Include="Areas\admin\Views\users\admins.cshtml" />
<Content Include="Areas\admin\Views\meta\index.cshtml" />
<Content Include="Areas\admin\Views\meta\create.cshtml" />
<None Include="Properties\PublishProfiles\Milestone 1 FTP.pubxml" />
<Content Include="googleacffc6da14c53e15.html" />
<Content Include="content\tile\large.png" />
@ -308,8 +311,6 @@
</ItemGroup>
<ItemGroup>
<Folder Include="App_Data\" />
<Folder Include="Areas\admin\Models\" />
<Folder Include="Areas\admin\Views\meta\" />
<Folder Include="Areas\admin\Views\Shared\" />
</ItemGroup>
<ItemGroup>

View File

@ -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);
}

View File

@ -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

View File

@ -227,7 +227,7 @@
@Scripts.Render("~/bundles/jqueryval")
<script>
<script type="text/javascript">
jQuery(function ($) {
$.validator.addMethod('date',
function (value, element) {

View File

@ -43,8 +43,16 @@
<meta property="og:description" content="BuildFeed is a collaborative build list for Microsoft Windows. Keep up to date with the latest Windows 10 builds or take a peek at the list back to 2000" />
break;
case "lab":
<meta name="description" content="Check out all the known builds to come out of the Windows development lab @ViewBag.ItemId through BuildFeed, a collaborative Windows build list" />
<meta property="og:description" content="Check out all the known builds to come out of the Windows development lab @ViewBag.ItemId through BuildFeed, a collaborative Windows build list" />
if (ViewBag.MetaItem != null)
{
<meta name="description" content="@ViewBag.MetaItem.MetaDescription" />
<meta property="og:description" content="@ViewBag.MetaItem.MetaDescription" />
}
else
{
<meta name="description" content="Check out all the known builds to come out of the Windows development lab @ViewBag.ItemId through BuildFeed, a collaborative Windows build list" />
<meta property="og:description" content="Check out all the known builds to come out of the Windows development lab @ViewBag.ItemId through BuildFeed, a collaborative Windows build list" />
}
break;
case "year":
<meta name="description" content="View a list of all Windows builds compiled in @ViewBag.ViewId, and watch how Windows developed steadily over time, through the collaborative build list, BuildFeed" />
@ -55,6 +63,27 @@
<div class="row">
<div class="col-sm-9">
@switch (ViewBag.Action as string)
{
case "lab":
<h2>@string.Format("Builds from {0}", ViewBag.ItemId)</h2>
break;
case "year":
<h2>@string.Format("Builds from {0}", ViewBag.ItemId)</h2>
break;
case "version":
<h2>@string.Format("Windows NT {0}", ViewBag.ItemId)</h2>
break;
case "source":
<h2>@ViewBag.ItemId)</h2>
break;
}
@if (ViewBag.PageNumber == 1 && ViewBag.MetaItem != null && !string.IsNullOrWhiteSpace(ViewBag.MetaItem.PageContent))
{
<h3>About</h3>
@Html.Raw(ViewBag.MetaItem.PageContent)
<h3>Listing</h3>
}
<ul class="list-unstyled">
@foreach (var item in Model)
{

View File

@ -163,6 +163,11 @@ label, .control-label, .help-block, .checkbox, .radio
padding: 4px 9px;
}
.table-admin h4
{
margin: .1em 0;
}
.table-admin > tbody > tr > th,
.table-admin > tbody > tr > td
{