This commit is contained in:
Paul Schneider
2014-10-12 15:22:45 +02:00
parent 83ac08cfd4
commit 1606fd0871
17 changed files with 136 additions and 90 deletions

View File

@ -138,22 +138,21 @@ namespace WorkFlowProvider
using (NpgsqlConnection cnx = CreateConnection ()) { using (NpgsqlConnection cnx = CreateConnection ()) {
using (NpgsqlCommand cmd = cnx.CreateCommand ()) { using (NpgsqlCommand cmd = cnx.CreateCommand ()) {
cmd.CommandText = cmd.CommandText =
"select _id,title,username from estimate where _id = @estid"; "select title,username from estimate where _id = @estid";
cmd.Parameters.Add ("@estid", estimid); cmd.Parameters.Add ("@estid", estimid);
cnx.Open (); cnx.Open ();
Estimate est = null; Estimate est = null;
using (NpgsqlDataReader rdr = cmd.ExecuteReader ()) { using (NpgsqlDataReader rdr = cmd.ExecuteReader ()) {
if (!rdr.Read ()) { if (!rdr.Read ()) {
throw new Exception ( return null;
string.Format("Estimate not found : {0}", estimid));
} }
est = new Estimate (); est = new Estimate ();
est.Title = rdr.GetString( est.Title = rdr.GetString(
rdr.GetOrdinal("title")); rdr.GetOrdinal("title"));
est.Owner = rdr.GetString( est.Owner = rdr.GetString(
rdr.GetOrdinal("username")); rdr.GetOrdinal("username"));
est.Id = estimid;
using (NpgsqlCommand cmdw = new NpgsqlCommand ("select _id, productid, ucost, count, description from writtings where _id = @estid", cnx)) { using (NpgsqlCommand cmdw = new NpgsqlCommand ("select _id, productid, ucost, count, description from writtings where _id = @estid", cnx)) {
cmdw.Parameters.Add("@estid", estimid); cmdw.Parameters.Add("@estid", estimid);
using (NpgsqlDataReader rdrw = cmdw.ExecuteReader ()) { using (NpgsqlDataReader rdrw = cmdw.ExecuteReader ()) {

View File

@ -18,11 +18,16 @@ namespace Yavsc.Admin
{ {
Environment.SetEnvironmentVariable("PGPASSWORD", da.Password); Environment.SetEnvironmentVariable("PGPASSWORD", da.Password);
Export e = new Export (); Export e = new Export ();
string fileName = da.BackupPrefix + "-" + DateTime.Now.ToString ("yyyyMMdd"); string fileName = da.BackupPrefix + "-" + DateTime.Now.ToString ("yyyyMMddhhmmss")+".tar";
FileInfo ofi = new FileInfo (fileName); FileInfo ofi = new FileInfo (fileName);
e.FileName = ofi.FullName; e.FileName = ofi.FullName;
/*
Exec ("pg_dump", string.Format ( Exec ("pg_dump", string.Format (
"-wb -Z3 -f {0} -Fd -h {1} -U {2} -p {3} {4}", "-wb -Z3 -f {0} -Ft -h {1} -U {2} -p {3} {4}",
fileName, da.Host, da.Dbuser, da.Port, da.Dbname ),e);
*/
Exec ("pg_dump", string.Format (
"-f {0} -Ft -h {1} -U {2} -p {3} {4}",
fileName, da.Host, da.Dbuser, da.Port, da.Dbname ),e); fileName, da.Host, da.Dbuser, da.Port, da.Dbname ),e);
return e; return e;
} }
@ -50,9 +55,14 @@ namespace Yavsc.Admin
{ {
Environment.SetEnvironmentVariable("PGPASSWORD", da.Password); Environment.SetEnvironmentVariable("PGPASSWORD", da.Password);
var t = new TaskOutput (); var t = new TaskOutput ();
Exec ("pg_restore", (dataOnly?"-a ":"")+string.Format (
"-1 -Ft -O -h {0} -U {1} -p {2} -d {3} {4}",
da.Host, da.Dbuser, da.Port, da.Dbname, fileName ),t);
/*
Exec ("pg_restore", (dataOnly?"-a ":"")+string.Format ( Exec ("pg_restore", (dataOnly?"-a ":"")+string.Format (
"-1 -w -Fd -O -h {0} -U {1} -p {2} -d {3} {4}", "-1 -w -Fd -O -h {0} -U {1} -p {2} -d {3} {4}",
da.Host, da.Dbuser, da.Port, da.Dbname, fileName ),t); da.Host, da.Dbuser, da.Port, da.Dbname, fileName ),t);
*/
return t; return t;
} }
public TaskOutput CreateDb () public TaskOutput CreateDb ()

View File

@ -8,6 +8,7 @@ using System.Web.Security;
using Yavsc.Model.RolesAndMembers; using Yavsc.Model.RolesAndMembers;
using Yavsc.Model.Admin; using Yavsc.Model.Admin;
using Yavsc.Admin; using Yavsc.Admin;
using System.IO;
namespace Yavsc.Controllers namespace Yavsc.Controllers
@ -27,6 +28,7 @@ namespace Yavsc.Controllers
[Authorize(Roles="Admin")] [Authorize(Roles="Admin")]
public ActionResult Backups(DataAccess model) public ActionResult Backups(DataAccess model)
{ {
return View (model); return View (model);
} }
@ -37,6 +39,7 @@ namespace Yavsc.Controllers
if (ModelState.IsValid) { if (ModelState.IsValid) {
if (string.IsNullOrEmpty (datac.Password)) if (string.IsNullOrEmpty (datac.Password))
ModelState.AddModelError ("Password", "Invalid passord"); ModelState.AddModelError ("Password", "Invalid passord");
datac.BackupPrefix = Server.MapPath (datac.BackupPrefix);
DataManager ex = new DataManager (datac); DataManager ex = new DataManager (datac);
Export e = ex.CreateBackup (); Export e = ex.CreateBackup ();
if (e.ExitCode > 0) if (e.ExitCode > 0)
@ -65,14 +68,30 @@ namespace Yavsc.Controllers
{ {
ViewData ["BackupName"] = backupName; ViewData ["BackupName"] = backupName;
if (ModelState.IsValid) { if (ModelState.IsValid) {
// TODO BETTER
datac.BackupPrefix = Server.MapPath (datac.BackupPrefix);
DataManager mgr = new DataManager (datac); DataManager mgr = new DataManager (datac);
ViewData ["BackupName"] = backupName; ViewData ["BackupName"] = backupName;
ViewData ["DataOnly"] = dataOnly; ViewData ["DataOnly"] = dataOnly;
TaskOutput t = mgr.Restore (backupName,dataOnly);
TaskOutput t = mgr.Restore (
Path.Combine(new FileInfo(datac.BackupPrefix).DirectoryName,
backupName),dataOnly);
return View ("Restored", t); return View ("Restored", t);
} }
BuildBackupList (datac);
return View (datac); return View (datac);
} }
private void BuildBackupList(DataAccess datac)
{
// build ViewData ["Backups"];
string bckd=Server.MapPath (datac.BackupPrefix);
DirectoryInfo di = new DirectoryInfo (new FileInfo(bckd).DirectoryName);
List<string> bks = new List<string> ();
foreach (FileInfo ti in di.GetFiles("*.tar"))
bks.Add (ti.Name);
ViewData ["Backups"] = bks.ToArray ();
}
[Authorize(Roles="Admin")] [Authorize(Roles="Admin")]
public ActionResult RemoveFromRole(string username, string rolename, string returnUrl) public ActionResult RemoveFromRole(string username, string rolename, string returnUrl)

View File

@ -20,19 +20,37 @@ namespace Yavsc.Controllers
/// </summary> /// </summary>
public class FrontOfficeController : Controller public class FrontOfficeController : Controller
{ {
[HttpGet] [Authorize]
[HttpPost] public ActionResult Estimate(Estimate model,string submit)
public ActionResult Estimate(Estimate e)
{ {
if (ModelState.IsValid) { if (ModelState.IsValid) {
if (e.Id > 0) { string username = HttpContext.User.Identity.Name;
Estimate f = WorkFlowManager.GetEstimate (e.Id); if (model.Id > 0) {
if (e.Owner != f.Owner) Estimate f = WorkFlowManager.GetEstimate (model.Id);
if (f == null) {
ModelState.AddModelError ("Id", "Wrong Id");
return View (model);
}
if (username != f.Owner)
if (!Roles.IsUserInRole ("FrontOffice")) if (!Roles.IsUserInRole ("FrontOffice"))
throw new UnauthorizedAccessException ("You're not allowed to modify this estimate"); throw new UnauthorizedAccessException ("You're not allowed to view/modify this estimate");
if (submit == "Update") {
if (model != f) {
WorkFlowManager.SetTitle (model.Id, model.Title);
}
} else if (submit == null) {
model = f;
}
} else if (model.Id == 0 && submit=="Create") {
// Create the estimate
model.Id=WorkFlowManager.CreateEstimate (username,
model.Title);
model.Owner = username;
} }
} }
return View (e); return View(model);
} }
[AcceptVerbs("GET")] [AcceptVerbs("GET")]

View File

@ -52,6 +52,7 @@ namespace Yavsc.ApiControllers
{ {
WorkFlowManager.DropEstimate (estid); WorkFlowManager.DropEstimate (estid);
} }
[HttpGet] [HttpGet]
[Authorize] [Authorize]
public object Index() public object Index()
@ -60,48 +61,12 @@ namespace Yavsc.ApiControllers
string username = Membership.GetUser ().UserName; string username = Membership.GetUser ().UserName;
return new { test=string.Format("Hello {0}!",username) }; return new { test=string.Format("Hello {0}!",username) };
} }
[HttpGet] [HttpGet]
[Authorize] [Authorize]
public long Write (long estid, string desc, decimal ucost, int count, long productid=0) { public long Write (long estid, string desc, decimal ucost, int count, long productid=0) {
// TODO ensure estid owner matches the current one // TODO ensure estid owner matches the current one
return WorkFlowManager.Write(estid, desc, ucost, count, productid); return WorkFlowManager.Write(estid, desc, ucost, count, productid);
} }
/*
public object Details(int id)
{
throw new NotImplementedException ();
}
public object Create()
{
throw new NotImplementedException ();
}
public object Edit(int id)
{
throw new NotImplementedException ();
}
public object Delete(int id)
{
throw new NotImplementedException ();
}
IContentProvider contentProvider = null;
IContentProvider ContentProvider {
get {
if (contentProvider == null )
contentProvider = WFManager.GetContentProviderFWC ();
return contentProvider;
}
}
*/
} }
} }

View File

@ -305,7 +305,7 @@ namespace Yavsc.Helpers
new BBTag ("h", "<h2>", "</h2>"), new BBTag ("h", "<h2>", "</h2>"),
bblist, bblist,
new BBTag ("*", "<li>", "</li>", true, false), new BBTag ("*", "<li>", "</li>", true, false),
new BBTag ("url", "<a href=\"${href}\">", "</a>", true, false, new BBAttribute ("href", ""), new BBAttribute ("href", "href")), new BBTag ("url", "<a href=\"${href}\">", "</a>", true, true, new BBAttribute ("href", ""), new BBAttribute ("href", "href")),
new BBTag ("br", "<br/>", "", true, false), new BBTag ("br", "<br/>", "", true, false),
new BBTag ("video", "<video style=\"${style}\" controls>" + new BBTag ("video", "<video style=\"${style}\" controls>" +
"<source src=\"${mp4}\" type=\"video/mp4\"/>" + "<source src=\"${mp4}\" type=\"video/mp4\"/>" +
@ -348,4 +348,3 @@ namespace Yavsc.Helpers
} }
} }
} }

View File

@ -3,9 +3,9 @@
<%= Html.ValidationSummary("Restore a database backup") %> <%= Html.ValidationSummary("Restore a database backup") %>
<% using (Html.BeginForm("Restore")) { %> <% using (Html.BeginForm("Restore")) { %>
<% string [] bckdirs = Model.GetBackupDirs(); %> <% string [] bcfiles = (string[]) ViewData["Backups"]; %>
<select name="backupName"> <select name="backupName">
<% foreach (string s in bckdirs) <% foreach (string s in bcfiles)
{ {
%> %>
<option value="<%=s%>"><%=s%></option> <option value="<%=s%>"><%=s%></option>

View File

@ -36,7 +36,7 @@ Usage BBcodes :
<%= Html.ValidationSummary("Edition du billet") %> <%= Html.ValidationSummary("Edition du billet") %>
<% using(Html.BeginForm("ValidateEdit", "Blogs")) { %> <% using(Html.BeginForm("ValidateEdit")) { %>
<%= Html.LabelFor(model => model.Title) %>:<br/> <%= Html.LabelFor(model => model.Title) %>:<br/>
<%= Html.TextBox( "Title" ) %> <%= Html.TextBox( "Title" ) %>
<%= Html.ValidationMessage("Title", "*") %> <%= Html.ValidationMessage("Title", "*") %>

View File

@ -1,10 +1,6 @@
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<BlogEditEntryModel>" MasterPageFile="~/Models/App.master"%> <%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<BlogEditEntryModel>" MasterPageFile="~/Models/App.master"%>
<asp:Content ContentPlaceHolderID="head" ID="head" runat="server">
<title><%= Html.Encode(ViewData["BlogTitle"]) %> - Nouveau billet <asp:Content ContentPlaceHolderID="overHeaderOne" ID="headerContent" runat="server">
- <%=Html.Encode(YavscHelpers.SiteName) %>
</title>
</asp:Content>
<asp:Content ContentPlaceHolderID="header" ID="headerContent" runat="server">
<h1 class="blogtitle"> <h1 class="blogtitle">
<a href="/Blog/<%=ViewData["UserName"]%>"> <a href="/Blog/<%=ViewData["UserName"]%>">
<img class="avatar" src="/Blogs/Avatar?user=<%=ViewData["UserName"]%>" alt="from <%=ViewData["UserName"]%>"/> <img class="avatar" src="/Blogs/Avatar?user=<%=ViewData["UserName"]%>" alt="from <%=ViewData["UserName"]%>"/>

View File

@ -1,4 +1,4 @@
<%@ Page Title="Commande" Language="C#" MasterPageFile="~/Models/App.master" Inherits="System.Web.Mvc.ViewPage<FormCollection collection>" %> <%@ Page Title="Commande" Language="C#" MasterPageFile="~/Models/App.master" Inherits="System.Web.Mvc.ViewPage<FormCollection>" %>
<asp:Content ID="MainContentContent" ContentPlaceHolderID="MainContent" runat="server"> <asp:Content ID="MainContentContent" ContentPlaceHolderID="MainContent" runat="server">
rha
</asp:Content> </asp:Content>

View File

@ -1,19 +1,42 @@
<%@ Page Title="" Language="C#" Inherits="System.Web.Mvc.ViewPage" MasterPageFile="~/Models/App.master" %> <%@ Page Title="Devis" Language="C#" Inherits="System.Web.Mvc.ViewPage<Estimate>" MasterPageFile="~/Models/App.master" %>
<!-- <asp:Content ContentPlaceHolderID="init" ID="initContent" runat="server">
</asp:Content>
<asp:Content ContentPlaceHolderID="overHeaderOne" ID="overHeaderOneContent" runat="server">
</asp:Content>
<asp:Content ContentPlaceHolderID="header" ID="headerContent" runat="server">
</asp:Content> -->
<asp:Content ContentPlaceHolderID="MainContent" ID="MainContentContent" runat="server"> <asp:Content ContentPlaceHolderID="MainContent" ID="MainContentContent" runat="server">
<% using (Html.BeginForm("Estimate")) { %> <%= Html.ValidationSummary("Devis") %>
<% using (Html.BeginForm("Estimate","FrontOffice")) { %>
<%= Html.LabelFor(model => model.Title) %>:<br/>
<%= Html.TextBox( "Title" ) %>
<%= Html.ValidationMessage("Title", "*") %>
<% if (Model.Id > 0) { %>
<br/>
<%= Html.LabelFor(model => model.Owner) %>:<%=Model.Owner%>
<%= Html.ValidationMessage("Owner", "*") %>
<br/>
<%= Html.LabelFor(model => model.Ciffer) %>:<%=Model.Ciffer%>
<br/>
<%= Html.LabelFor(model => model.Id) %>:<%=Model.Id%>
<%= Html.Hidden( "Id" ) %>
<br/>
<% if (Model.Lines ==null || Model.Lines.Length == 0) { %>
<i>Pas de ligne.</i>
<%
} else { %>
<ul>
<% foreach (Writting wr in Model.Lines) { %>
<li><%=wr.Count%>/<%=wr.Id%>/<%=wr.ProductReference%>/<%=wr.UnitaryCost%>/<%=wr.Description%></li>
<% } %>
</ul>
<% } %>
<% } %>
<% if (Model.Id==0) { %>
<input type="submit" name="submit" value="Create"/>
<% } else { %>
<input type="submit" name="submit" value="Update"/>
<% }
%>
<% } %> <% } %>
</asp:Content> </asp:Content>
<!--
<asp:Content ContentPlaceHolderID="MASContent" ID="MASContentContent" runat="server">
</asp:Content>
-->

View File

@ -0,0 +1,17 @@
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<title>test</title>
</head>
<body>
<div>
test
</div>
</body>
</html>

View File

@ -1,7 +1,11 @@
<%@ Page Title="Yavsc - indexe" Language="C#" Inherits="System.Web.Mvc.ViewPage" MasterPageFile="~/Models/App.master"%> <%@ Page Title="Yavsc - indexe" Language="C#" Inherits="System.Web.Mvc.ViewPage" MasterPageFile="~/Models/App.master"%>
<asp:Content ContentPlaceHolderID="MainContent" ID="MainContentContent" runat="server"> <asp:Content ContentPlaceHolderID="MainContent" ID="MainContentContent" runat="server">
<div>
<%= Html.ActionLink("blogs","Index","Blogs") %> <p>
« Voir le monde comme un rêve est un bon point de vue. Quand on fait un cauchemar, on se réveille et on se dit que ce nétait quun rêve. Il est dit que le monde où nous vivons nen diffère en rien ».
<br/><a href="http://unefenetresurlemonde.over-blog.com/article-34325590.html">Ghost Dog, la Voie du samouraï</a>
</p><div>
<%= Html.ActionLink("Les blogs","Index","Blogs") %>
</div> </div>
</asp:Content> </asp:Content>

View File

@ -28,6 +28,7 @@
<add namespace="Yavsc.Model.RolesAndMembers" /> <add namespace="Yavsc.Model.RolesAndMembers" />
<add namespace="Yavsc.Model.Admin" /> <add namespace="Yavsc.Model.Admin" />
<add namespace="Yavsc.Model.Blogs" /> <add namespace="Yavsc.Model.Blogs" />
<add namespace="Yavsc.Model.WorkFlow" />
</namespaces> </namespaces>
</pages> </pages>
</system.web> </system.web>

View File

@ -98,7 +98,6 @@
<Folder Include="Views\FrontOffice\" /> <Folder Include="Views\FrontOffice\" />
<Folder Include="avatars\" /> <Folder Include="avatars\" />
<Folder Include="Admin\" /> <Folder Include="Admin\" />
<Folder Include="Views\BackOffice\" />
<Folder Include="backup\" /> <Folder Include="backup\" />
<Folder Include="errors\" /> <Folder Include="errors\" />
<Folder Include="Views\FileSystem\" /> <Folder Include="Views\FileSystem\" />
@ -196,6 +195,7 @@
<Content Include="Views\Admin\Restored.aspx" /> <Content Include="Views\Admin\Restored.aspx" />
<Content Include="Views\Admin\Index.aspx" /> <Content Include="Views\Admin\Index.aspx" />
<Content Include="Views\FrontOffice\Estimate.aspx" /> <Content Include="Views\FrontOffice\Estimate.aspx" />
<Content Include="Views\FrontOffice\test.cshtml" />
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" /> <Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />

View File

@ -53,7 +53,7 @@ namespace Yavsc.Model.Admin
} }
private string dbpassword ; private string dbpassword ;
private string backupPrefix= "backup/global.backup"; private string backupPrefix= "~/backup/global.backup";
public string BackupPrefix { public string BackupPrefix {
get { get {
@ -69,16 +69,6 @@ namespace Yavsc.Model.Admin
get { return dbpassword; } get { return dbpassword; }
set { dbpassword = value; } set { dbpassword = value; }
} }
public string [] GetBackupDirs()
{
List<string> res = new List<string> ();
string bkpdir = new FileInfo (backupPrefix).DirectoryName;
DirectoryInfo bkpdiri = new DirectoryInfo(bkpdir);
foreach (DirectoryInfo di in bkpdiri.EnumerateDirectories())
res.Add (Path.Combine(bkpdir,di.Name));
return res.ToArray ();
}
} }
} }

View File

@ -13,6 +13,11 @@ namespace Yavsc.Model.WorkFlow
/// </summary> /// </summary>
public static class WorkFlowManager public static class WorkFlowManager
{ {
public static void SetTitle (long id, string title)
{
ContentProvider.SetTitle (id, title);
}
public static event EventHandler NewOrder; public static event EventHandler NewOrder;
public static Estimate GetEstimate (long estid) public static Estimate GetEstimate (long estid)