un positionnement de paramètre workflow des pros
This commit is contained in:
parent
fbd352e788
commit
96746fcc0b
322 changed files with 25893 additions and 3844 deletions
16
Yavsc/Helpers/EstimateHelpers.cs
Normal file
16
Yavsc/Helpers/EstimateHelpers.cs
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
|
||||
using Yavsc.Models.Billing;
|
||||
|
||||
namespace Yavsc.Helpers
|
||||
{
|
||||
public static class EstimateHelpers {
|
||||
public static decimal GetTotal(this Estimate estimate)
|
||||
{
|
||||
decimal result = 0;
|
||||
foreach (var l in estimate.Bill)
|
||||
result += l.Count*l.UnitaryCost;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,5 +1,4 @@
|
|||
using Microsoft.Extensions.Localization;
|
||||
using Yavsc.Model;
|
||||
using Yavsc.Models.Booking;
|
||||
using Yavsc.Models.Messaging;
|
||||
|
||||
|
|
@ -12,14 +11,18 @@ namespace Yavsc.Helpers
|
|||
{
|
||||
var yaev = new BookQueryEvent
|
||||
{
|
||||
Client = new ClientProviderInfo { UserName = query.Client.UserName , UserId = query.ClientId } ,
|
||||
Client = new ClientProviderInfo {
|
||||
UserName = query.Client.UserName ,
|
||||
UserId = query.ClientId,
|
||||
Avatar = query.Client.Avatar } ,
|
||||
Previsional = query.Previsional,
|
||||
EventDate = query.EventDate,
|
||||
Location = query.Location,
|
||||
Id = query.Id
|
||||
Id = query.Id,
|
||||
Reason = query.Reason
|
||||
};
|
||||
return yaev;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,15 +1,18 @@
|
|||
|
||||
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net.Mime;
|
||||
using System.Security.Claims;
|
||||
using System.Web;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Yavsc.ApiControllers;
|
||||
using Yavsc.Models;
|
||||
using Yavsc.Models.FileSystem;
|
||||
using Yavsc.ViewModels;
|
||||
using Yavsc.ViewModels.UserFiles;
|
||||
|
||||
namespace Yavsc.Helpers
|
||||
|
|
@ -24,7 +27,7 @@ namespace Yavsc.Helpers
|
|||
|
||||
return di;
|
||||
}
|
||||
static char[] ValidChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_~.".ToCharArray();
|
||||
static char[] ValidChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_~. ".ToCharArray();
|
||||
|
||||
public static bool IsValidDirectoryName(this string name)
|
||||
{
|
||||
|
|
@ -95,16 +98,17 @@ namespace Yavsc.Helpers
|
|||
user.DiskUsage = usage;
|
||||
return item;
|
||||
}
|
||||
public static HtmlString FileLink(this DefaultFileInfo info, string username, string subpath)
|
||||
{
|
||||
return new HtmlString( Startup.UserFilesOptions.RequestPath+"/"+ username + "/" + subpath + "/" +
|
||||
HttpUtility.UrlEncode(info.Name) );
|
||||
}
|
||||
public static FileRecievedInfo ReceiveAvatar(this ApplicationUser user, IFormFile formFile)
|
||||
{
|
||||
var item = new FileRecievedInfo();
|
||||
item.FileName = user.UserName + ".png";
|
||||
var destFileName = Path.Combine(Startup.SiteSetup.UserFiles.Avatars, item.FileName);
|
||||
|
||||
ImageProcessor.ImageFactory f = new ImageProcessor.ImageFactory();
|
||||
|
||||
ImageProcessor.Web.Processors.Resize r = new ImageProcessor.Web.Processors.Resize();
|
||||
|
||||
var fi = new FileInfo(destFileName);
|
||||
if (fi.Exists) item.Overriden = true;
|
||||
Rectangle cropRect = new Rectangle();
|
||||
|
|
@ -166,5 +170,27 @@ namespace Yavsc.Helpers
|
|||
dir, xsmallname), ImageFormat.Png);
|
||||
}
|
||||
}
|
||||
public static Func<string,long,string>
|
||||
SignFileNameFormat = new Func<string,long,string> ((signType,estimateId) => $"estimate-{signType}sign-{estimateId}.png");
|
||||
|
||||
public static FileRecievedInfo ReceiveProSignature(this ClaimsPrincipal user, long estimateId, IFormFile formFile, string signtype)
|
||||
{
|
||||
var item = new FileRecievedInfo();
|
||||
item.FileName = SignFileNameFormat("pro",estimateId);
|
||||
var destFileName = Path.Combine(Startup.SiteSetup.UserFiles.Bills, item.FileName);
|
||||
|
||||
var fi = new FileInfo(destFileName);
|
||||
if (fi.Exists) item.Overriden = true;
|
||||
|
||||
using (var org = formFile.OpenReadStream())
|
||||
{
|
||||
Image i = Image.FromStream(org);
|
||||
using (Bitmap source = new Bitmap(i))
|
||||
{
|
||||
source.Save(destFileName, ImageFormat.Png);
|
||||
}
|
||||
}
|
||||
return item;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,25 +3,19 @@ using System.Collections.Generic;
|
|||
using System.Linq;
|
||||
using Microsoft.AspNet.Mvc.Rendering;
|
||||
using Yavsc.Models;
|
||||
using Yavsc.Models.Workflow;
|
||||
|
||||
namespace Yavsc.Helpers {
|
||||
public static class ListItemHelpers {
|
||||
|
||||
public static List<SelectListItem> ActivityItems(
|
||||
this ApplicationDbContext _dbContext, string selectedCode)
|
||||
this ApplicationDbContext _dbContext, List<UserActivity> activity)
|
||||
{
|
||||
var codeIsNull = (string.IsNullOrEmpty(selectedCode));
|
||||
List<SelectListItem> items;
|
||||
if (codeIsNull) items = _dbContext.Activities.Select(
|
||||
List<SelectListItem> items = _dbContext.Activities.Select(
|
||||
x=> new SelectListItem() {
|
||||
Value=x.Code, Text=x.Name
|
||||
} ).ToList();
|
||||
else items =
|
||||
_dbContext.Activities.Select(
|
||||
x=> new SelectListItem() {
|
||||
Value=x.Code, Text=x.Name,
|
||||
Selected = (x.Code == selectedCode)
|
||||
Value = x.Code, Text = x.Name, Selected = activity.Any(a=>a.DoesCode == x.Code)
|
||||
} ).ToList();
|
||||
|
||||
return items;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,14 +6,26 @@ using Microsoft.AspNet.Http;
|
|||
using Microsoft.AspNet.Mvc;
|
||||
using Microsoft.AspNet.Mvc.Rendering;
|
||||
using Microsoft.AspNet.Mvc.ViewEngines;
|
||||
using Yavsc.ViewModels.Gen;
|
||||
|
||||
namespace Yavsc.Helpers
|
||||
{
|
||||
public class TeXString
|
||||
using ViewModels.Gen;
|
||||
public class TeXString : HtmlString
|
||||
{
|
||||
|
||||
public class Replacement
|
||||
public TeXString(TeXString teXString): base(teXString.ToString())
|
||||
{
|
||||
}
|
||||
|
||||
public TeXString(string str) : base(str)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
public class Replacement
|
||||
{
|
||||
string target;
|
||||
string replacement;
|
||||
|
|
@ -27,8 +39,9 @@ namespace Yavsc.Helpers
|
|||
return source.Replace(target, replacement);
|
||||
}
|
||||
}
|
||||
|
||||
public readonly static Replacement[] SpecialCharsRendering =
|
||||
public static class TeXHelpers
|
||||
{
|
||||
public static readonly Replacement[] SpecialCharsRendering =
|
||||
{
|
||||
new Replacement("<","\\textless"),
|
||||
new Replacement(">","\\textgreater"),
|
||||
|
|
@ -53,23 +66,16 @@ namespace Yavsc.Helpers
|
|||
new Replacement("†","\\dag"),
|
||||
new Replacement("–","\\textendash")
|
||||
};
|
||||
string data;
|
||||
public TeXString(string str)
|
||||
|
||||
public static TeXString ToTeX(this string source)
|
||||
{
|
||||
data = str;
|
||||
string result=source;
|
||||
foreach (var r in SpecialCharsRendering)
|
||||
{
|
||||
data = r.Execute(data);
|
||||
result = r.Execute(result);
|
||||
}
|
||||
return new TeXString(result);
|
||||
}
|
||||
|
||||
override public string ToString()
|
||||
{
|
||||
return data;
|
||||
}
|
||||
}
|
||||
public static class TeXHelpers
|
||||
{
|
||||
public static string NewLinesWith(this string target, string separator)
|
||||
{
|
||||
var items = target.Split(new char[] { '\n' }).Where(
|
||||
|
|
@ -78,11 +84,19 @@ namespace Yavsc.Helpers
|
|||
return string.Join(separator, items);
|
||||
}
|
||||
|
||||
public static TeXString ToTeX(string target, string lineSeparator = "\n\\\\")
|
||||
public static TeXString ToTeX(this string target, string lineSeparator = "\n\\\\")
|
||||
{
|
||||
if (target == null) return null;
|
||||
return new TeXString(target.NewLinesWith(lineSeparator));
|
||||
return new TeXString( target.ToTeX().ToString().NewLinesWith(lineSeparator) );
|
||||
}
|
||||
|
||||
public static TeXString SplitAddressToTeX (this string target)
|
||||
{
|
||||
var alines = target.Split(',');
|
||||
var texlines = alines.Select(l=>l.ToTeX().ToString());
|
||||
return new TeXString(string.Join("\\\\\n",texlines));
|
||||
}
|
||||
|
||||
public static bool GenerateEstimatePdf(this PdfGenerationViewModel Model)
|
||||
{
|
||||
string errorMsg = null;
|
||||
|
|
@ -111,6 +125,7 @@ namespace Yavsc.Helpers
|
|||
p.StartInfo.WorkingDirectory = tempdir;
|
||||
p.StartInfo = new ProcessStartInfo();
|
||||
p.StartInfo.UseShellExecute = false;
|
||||
p.StartInfo.WorkingDirectory = tempdir;
|
||||
p.StartInfo.FileName = "/usr/bin/texi2pdf";
|
||||
p.StartInfo.Arguments = $"--batch --build-dir=. -o {fo.FullName} {fi.FullName}";
|
||||
p.Start();
|
||||
|
|
@ -121,6 +136,8 @@ namespace Yavsc.Helpers
|
|||
}
|
||||
}
|
||||
fi.Delete();
|
||||
var di = new DirectoryInfo(Path.Combine(tempdir,$"{Model.BaseFileName}.t2d"));
|
||||
di.Delete(true);
|
||||
}
|
||||
Model.Generated = fo.Exists;
|
||||
Model.GenerationErrorMessage = new HtmlString(errorMsg);
|
||||
|
|
|
|||
16
Yavsc/Helpers/WorkflowHelpers.cs
Normal file
16
Yavsc/Helpers/WorkflowHelpers.cs
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
using Yavsc.Models;
|
||||
using Yavsc.Models.Workflow;
|
||||
using YavscLib;
|
||||
|
||||
namespace Yavsc.Helpers
|
||||
{
|
||||
public static class WorkflowHelpers
|
||||
{
|
||||
public static ISpecializationSettings CreateSettings (this Activity activity) {
|
||||
if (activity.SettingsClassName==null) return null;
|
||||
var ctor = Startup.ProfileTypes[activity.SettingsClassName].GetConstructor(System.Type.EmptyTypes);
|
||||
if (ctor==null) return null;
|
||||
return (ISpecializationSettings) ctor.Invoke(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue