* Presta.csproj: A first class

* AssemblyInfo.cs: initial commit

* NpgsqlCircleProvider.cs: circle members are now stored in bd upon
  their user's name

* InputCircle.cs: fixes the new CircleManager interface usage

* Yavsc.sln: Adds the `Presta` project

* CircleController.cs: * Authorize some Http methods
* Lists circles as circles

* style.css: Fixes the missing "hidden" css class

* AccountController.cs: using the new Circle provider interface

* BlogsController.cs: * using the new Circle provider interface
* do not test blog entry collections in order to group them by a
  unique user name or title, it's too bad,
instead, keep user's request id as guide to model and view.

* YavscHelpers.cs: Adds a Circle Html formatter

* Circles.aspx: List of circles is now given as a list of `Circle`
  objects

* instdbws.sql: fixes the db in order to store user names in circle
  member's records.

* BlogEntryCollection.cs: ConcernsAUniqueTitle and ConcernsAUniqueUser
  are now Obsoletes

* UUTBlogEntryCollection.cs: Drops a useless ctor

* CircleProvider.cs: The `CircleManager` now delivers the user's
  circle as a `Circle` object collection.
This commit is contained in:
Paul Schneider 2015-08-20 20:02:46 +02:00
commit bdbda2a21f
21 changed files with 322 additions and 82 deletions

View file

@ -60,7 +60,8 @@ namespace Yavsc.ApiControllers
/// Create the specified circle.
/// </summary>
/// <param name="model">Model.</param>
[Authorize]
[Authorize,
AcceptVerbs ("POST")]
public long Create(NewCircle model)
{
string user = Membership.GetUser ().UserName;
@ -72,7 +73,8 @@ namespace Yavsc.ApiControllers
/// </summary>
/// <param name="id">Circle Identifier.</param>
/// <param name="username">username.</param>
[Authorize]
[Authorize,
AcceptVerbs ("POST")]
public void Add(long id, string username)
{
checkIsOwner (CircleManager.DefaultProvider.Get (id));
@ -84,7 +86,9 @@ namespace Yavsc.ApiControllers
/// Delete the circle specified by id.
/// </summary>
/// <param name="id">Identifier.</param>
[Authorize] public void Delete(long id)
[Authorize,
AcceptVerbs ("GET")]
public void Delete(long id)
{
checkIsOwner (CircleManager.DefaultProvider.Get(id));
CircleManager.DefaultProvider.Delete (id);
@ -101,7 +105,8 @@ namespace Yavsc.ApiControllers
/// Get the circle specified id.
/// </summary>
/// <param name="id">Identifier.</param>
[Authorize]
[Authorize,
AcceptVerbs ("GET")]
public Circle Get(long id)
{
var c = CircleManager.DefaultProvider.Get (id);
@ -112,8 +117,9 @@ namespace Yavsc.ApiControllers
/// <summary>
/// List the circles
/// </summary>
[Authorize]
public IEnumerable<ListItem> List()
[Authorize,
AcceptVerbs ("GET")]
public IEnumerable<Circle> List()
{
string user = Membership.GetUser ().UserName;
return CircleManager.DefaultProvider.List (user);

View file

@ -12,7 +12,7 @@ body {
textarea {
width:25em;
height:5em;
}
}
input, textarea, checkbox {
color: #FFFFA0;
@ -86,7 +86,7 @@ footer {
font-size:75%;
}
#login img { max-height:5em; max-width:5em; }
#login img { max-height:5em; max-width:5em; }
header {
background-color:rgba(16,16,0,0.8);
@ -155,6 +155,7 @@ label {
padding-left: 20px;
}
.hidden { display:none; }
ul.preview li:nth-child(-n+10) {
display:inline;
@ -180,6 +181,7 @@ usertitleref {
font-family: 'Arial', cursive;
font-size: 140%;
display:block;
padding: .2em;
}
input, select {
@ -230,34 +232,35 @@ a.actionlink img { top:4px; }
.field-validation-error { color: red; }
.c2 { font-size: small; font-style: italic; }
.c3 { font-size: x-small; font-style: italic; }
@media print {
body {background-color:white;color:black;}
header,footer,.postcomment,.actionlink,.metablog,#login{ display:none;}
header,footer,.postcomment,.actionlink,.metablog,#login
{ display:none;}
}
@media all and (min-width: 641px) {
.bshpanel { display:block; }
.bsh { display: none; }
.c3 { display:initial; }
.c3-alt { display:none; }
}
@media all and (max-width: 640px) {
.bshpanel { cursor:zoom-in; }
@media all and (max-width: 640px) {
.bshpanel { cursor:zoom-in; }
footer {
font-size: x-small;
}
.c2 { display:initial; }
.c2-alt { display:none; }
.c3 { display:none; }
.c3-alt { display:initial; }
}
@media all and (max-width: 350px) {
.c2 { display:none; }
.c2-alt { display:initial; }
}
}
@media all and (max-width: 350px) {
.c2 { display:none; }
.c2-alt { display:initial; }
}

View file

@ -1,3 +1,28 @@
2015-08-20 Paul Schneider <paul@pschneider.fr>
* CircleController.cs: * Authorize some Http methods
* Lists circles as circles
* style.css: Fixes the missing "hidden" css class
* AccountController.cs: using the new Circle provider
interface
* BlogsController.cs: * using the new Circle provider
interface
* do not test blog entry collections in order to group them by
a unique user name or title, it's too bad,
instead, keep user's request id as guide to model and view.
* YavscHelpers.cs: Adds a Circle Html formatter
* Circles.aspx: List of circles is now given as a list of
`Circle` objects
* instdbws.sql: fixes the db in order to store user names in
circle member's records.
2015-08-14 Paul Schneider <paul@pschneider.fr>
* FileSystemController.cs: Fixes the route to user's Files by

View file

@ -13,6 +13,7 @@ using Yavsc.Helpers;
using System.Web.Mvc;
using Yavsc.Model.Circles;
using System.Collections.Specialized;
using System.Text;
namespace Yavsc.Controllers
{
@ -309,12 +310,10 @@ namespace Yavsc.Controllers
public ActionResult Circles ()
{
string user = Membership.GetUser ().UserName;
ViewData["Circles"] = CircleManager.DefaultProvider.List (user).Select (x => new SelectListItem {
Value = x.Value,
Text = x.Text
});;
ViewData["Circles"] = CircleManager.DefaultProvider.List (user);
return View ();
}
/// <summary>
/// Logout the specified returnUrl.
/// </summary>

View file

@ -18,6 +18,7 @@ using Yavsc.Model.RolesAndMembers;
using System.Net;
using System.Web.Mvc;
using Yavsc.Model.Circles;
using Yavsc.Helpers;
namespace Yavsc.Controllers
{
@ -131,11 +132,6 @@ namespace Yavsc.Controllers
ViewData ["Avatar"] = bupr.avatar;
ViewData ["RecordCount"] = tr;
UUBlogEntryCollection uuc = new UUBlogEntryCollection (user, c);
if (uuc.ConcernsAUniqueTitle) {
var uutc = new UUTBlogEntryCollection (uuc.UserName,
uuc [0].Title, uuc);
return View ("UserPost", uutc );
}
return View ("UserPosts", uuc);
}
@ -259,8 +255,8 @@ namespace Yavsc.Controllers
title = "";
ViewData ["UserName"] = un;
ViewData ["AllowedCircles"] = CircleManager.DefaultProvider.List (Membership.GetUser ().UserName).Select (x => new SelectListItem {
Value = x.Value,
Text = x.Text
Value = x.Id.ToString(),
Text = YavscHelpers.FormatCircle(x).ToHtmlString()
});
return View ("Edit", new BlogEntry { Title = title });
@ -306,9 +302,9 @@ namespace Yavsc.Controllers
e.AllowedCircles = new long[0];
ViewData ["AllowedCircles"] = CircleManager.DefaultProvider.List (Membership.GetUser ().UserName).Select (x => new SelectListItem {
Value = x.Value,
Text = x.Text,
Selected = e.AllowedCircles.Contains (long.Parse (x.Value))
Value = x.Id.ToString(),
Text = YavscHelpers.FormatCircle(x).ToHtmlString(),
Selected = e.AllowedCircles.Contains (x.Id)
});
return View (e);
}

View file

@ -21,6 +21,32 @@ namespace Yavsc.Helpers
/// </summary>
public static class YavscHelpers
{
/// <summary>
/// Formats the circle.
/// </summary>
/// <returns>The circle.</returns>
/// <param name="c">C.</param>
public static HtmlString FormatCircle (Circle c)
{
if (c.Members!=null)
if (c.Members.Length > 0) {
TagBuilder i = new TagBuilder ("i");
i.SetInnerText (String.Join (", ", c.Members));
return new HtmlString (c.Title+"<br/>\n"+i.ToString());
}
return new HtmlString (c.Title);
}
/// <summary>
/// Formats the circle.
/// </summary>
/// <returns>The circle as Html string.</returns>
/// <param name="helper">Helper.</param>
/// <param name="c">C.</param>
public static HtmlString FormatCircle(this HtmlHelper helper, Circle c)
{
return FormatCircle (c);
}
private static string siteName = null;
/// <summary>
/// Gets the name of the site.

View file

@ -13,12 +13,11 @@
</thead>
<tbody id="tbcb">
<% int lc=0;
foreach (SelectListItem ci in (IEnumerable<SelectListItem>) ViewData["Circles"]) { lc++; %>
<tr class="<%= (lc%2==0)?"even ":"odd " %>row" id="c_<%=ci.Value%>">
<td><%=ci.Text%></td>
foreach (var ci in (IEnumerable<Circle>) ViewData["Circles"]) { lc++; %>
<tr class="<%= (lc%2==0)?"even ":"odd " %>row" id="c_<%=ci.Id%>">
<td><%=Html.FormatCircle(ci)%></td>
<td>
<input type="button" value="<%=Html.Translate("Remove")%>" class="actionlink rowbtnrm"/>
<input type="button" value="<%=Html.Translate("Members")%>" class="actionlink rowbtnvw"/>
<input type="button" value="<%=Html.Translate("Remove")%>" class="btnremovecircle actionlink" cid="<%=ci.Id%>"/>
</td>
</tr>
<% } %>
@ -33,13 +32,13 @@ $("#tbc").stupidtable();
<asp:Content ID="MASContentContent" ContentPlaceHolderID="MASContent" runat="server">
<div id="dfnuser" class="hidden panel">
<%= Html.Partial("~/Views/Account/Register.ascx",new RegisterClientModel(),new ViewDataDictionary(ViewData)
<%= Html.Partial("~/Views/Account/Register.ascx",new RegisterClientModel(),new ViewDataDictionary(ViewData)
{
TemplateInfo = new System.Web.Mvc.TemplateInfo
{
TemplateInfo = new System.Web.Mvc.TemplateInfo
{
HtmlFieldPrefix = ViewData.TemplateInfo.HtmlFieldPrefix==""?"ur":ViewData.TemplateInfo.HtmlFieldPrefix+"_ur"
}
}) %>
HtmlFieldPrefix = ViewData.TemplateInfo.HtmlFieldPrefix==""?"ur":ViewData.TemplateInfo.HtmlFieldPrefix+"_ur"
}
}) %>
</div>
<form>
<fieldset>
@ -87,9 +86,38 @@ $("#tbc").stupidtable();
$("#Err_ur_IsApprouved").text("");
}
function clearCircleValidation() {}
function removeCircle() {
message(false);
var id = $(this).attr('cid');
$.ajax({
url: "<%=Url.Content("~/api/Circle/Delete/")%>"+id,
type: "GET",
success: function (data) {
// Drops the detroyed circle row
$("c_"+id).remove();
},
statusCode: {
400: function(data) {
$.each(data.responseJSON, function (key, value) {
var errspanid = "Err_cr_" + value.key.replace("model.","");
var errspan = document.getElementById(errspanid);
if (errspan==null)
alert('enoent '+errspanid);
else
errspan.innerHTML=value.errors.join("<br/>");
});
}
},
error: function (xhr, ajaxOptions, thrownError) {
if (xhr.status!=400)
message(xhr.status+" : "+xhr.responseText);
else message(false);
}});
}
function addCircle()
{
message(false);
var circle = { title: $("#title").val(), users: $("#users").val() } ;
$("#title").text('');
$("#users").val('');
@ -98,7 +126,8 @@ $("#tbc").stupidtable();
type: "POST",
data: circle,
success: function (data) {
$("#users option:last").after($('<option>'+user.UserName+'</option>'));
// Adds a node rendering the new circle
$("#tbcb").append("<tr><td>"+circle.title+" <br><i>"+circle.users+"</i></td></tr>");
},
statusCode: {
400: function(data) {
@ -121,6 +150,7 @@ $("#tbc").stupidtable();
function addUser()
{
message(false);
var user={
UserName: $("#ur_UserName").val(),
Name: $("#ur_Name").val(),
@ -174,6 +204,7 @@ $("#tbc").stupidtable();
$(document).ready(function () {
$("#btnnewuser").click(addUser);
$("#btnnewcircle").click(addCircle);
$(".btnremovecircle").click(removeCircle);
});
</script>
</asp:Content>

View file

@ -680,11 +680,12 @@ COMMENT ON COLUMN circle.public IS 'true when this circle is a public circle, fr
CREATE TABLE circle_members
(
circle_id bigint NOT NULL,
member character varying NOT NULL,
circle_id bigserial NOT NULL,
member character varying (255) NOT NULL,
applicationname character varying (255) NOT NULL,
CONSTRAINT circle_members_pkey PRIMARY KEY (circle_id, member),
CONSTRAINT circle_members_member_fkey FOREIGN KEY (member)
REFERENCES users (pkid) MATCH SIMPLE
CONSTRAINT fk_circle_members_users FOREIGN KEY (member, applicationname)
REFERENCES users (username, applicationname) MATCH SIMPLE
ON UPDATE CASCADE ON DELETE CASCADE
)
WITH (