This commit is contained in:
Paul Schneider 2026-02-28 21:17:54 +00:00
commit 40e8e08690
3487 changed files with 39 additions and 21 deletions

View file

@ -0,0 +1,98 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Localization;
using Yavsc.Billing;
using Yavsc.Helpers;
using Yavsc.Models;
using Yavsc.ViewModels;
using Yavsc.ViewModels.Gen;
using Yavsc.Services;
using Microsoft.EntityFrameworkCore;
using Yavsc.Server.Helpers;
namespace Yavsc.ViewComponents
{
public class BillViewComponent : ViewComponent
{
readonly ApplicationDbContext dbContext;
readonly IBillingService billing;
readonly IStringLocalizer<BillViewComponent> localizer;
public BillViewComponent(ApplicationDbContext dbContext,
IStringLocalizer<BillViewComponent> localizer,
IBillingService billing)
{
this.billing = billing;
this.dbContext = dbContext;
this.localizer = localizer;
}
public async Task<IViewComponentResult> InvokeAsync(string code, IBillable billable, OutputFormat format, bool asBill)
{
var di = new DirectoryInfo(Config.SiteSetup.Bills);
var dia = new DirectoryInfo(Config.SiteSetup.Avatars);
ViewBag.BillsDir = di.FullName;
ViewBag.AvatarsDir = dia.FullName;
ViewBag.AsBill = asBill; // vrai pour une facture, sinon, c'est un devis
ViewBag.Acquitted = billable.GetIsAcquitted();
ViewBag.BillingCode = code;
var client = await dbContext.Users
.Include(u=>u.PostalAddress)
.SingleAsync(u=>u.Id == billable.ClientId);
ViewBag.Client = client;
var performer = await dbContext.Users
.Include(u=>u.BankInfo)
.Include(u=>u.PostalAddress)
.SingleAsync(u=>u.Id == billable.PerformerId);
ViewBag.Performer = performer;
string clientAddress = client.PostalAddress?.Address ?? null;
ViewBag.ClientAddress = clientAddress.SplitAddressToTeX();
var profile = await dbContext.Performers
.Include(p=>p.OrganizationAddress)
.SingleAsync(p=>p.PerformerId == billable.PerformerId);
ViewBag.PerformerProfile = profile;
ViewBag.ActivityLabel = (await dbContext.Activities.SingleAsync(a => a.Code == billable.ActivityCode)).Name;
var proaddr = profile.OrganizationAddress.Address;
ViewBag.PerformerOrganizationAddress = proaddr.SplitAddressToTeX() ;
ViewBag.FooterPerformerOrganizationAddress = proaddr.SplitAddressToTeX(", ");
ViewBag.PerformerAddress = performer.PostalAddress?.Address.SplitAddressToTeX() ;
switch (format) {
case OutputFormat.LaTeX :
return this.View("Bill_tex", billable);
case OutputFormat.Pdf :
string tex = null;
var oldWriter = ViewComponentContext.ViewContext.Writer;
using (var writer = new StringWriter())
{
this.ViewComponentContext.ViewContext.Writer = writer;
var resultTex = View("Bill_tex", billable);
await resultTex.ExecuteAsync(this.ViewComponentContext);
tex = writer.ToString();
}
ViewComponentContext.ViewContext.Writer = oldWriter;
var genrtrData = new PdfGenerationViewModel
{
Temp = Config.Temp,
TeXSource = tex,
DestDir = AbstractFileSystemHelpers.UserBillsDirName,
BaseFileName = billable.GetFileBaseName(billing)
};
if (genrtrData.GenerateEstimatePdf()) {
return this.View(new { Generated = genrtrData.BaseFileName+".pdf" });
} else {
return View(new { Error = genrtrData.GenerationErrorMessage } );
}
}
ViewBag.BillFileInfo = billable.GetBillInfo(billing);
return View("Default",billable);
}
}
}

View file

@ -0,0 +1,35 @@
using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Yavsc.Models;
using Yavsc.Services;
namespace Yavsc.ViewComponents
{
public class CalendarViewComponent : ViewComponent
{
readonly ICalendarManager _manager;
public CalendarViewComponent (
ICalendarManager manager)
{
_manager = manager;
}
public async Task<IViewComponentResult> InvokeAsync (
string htmlFieldName,
string calId )
{
var minDate = DateTime.Now;
var maxDate = minDate.AddDays(20);
var model = await _manager.CreateViewModelAsync(
htmlFieldName,
calId, minDate, maxDate
);
return View(model);
}
}
}

View file

@ -0,0 +1,51 @@
using System.Linq;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
namespace Yavsc.ViewComponents
{
using Models;
using ViewModels.Controls;
using ViewModels.Relationship;
using Yavsc.Abstract.Identity.Security;
public class CirclesControlViewComponent : ViewComponent
{
private readonly ApplicationDbContext dbContext;
public CirclesControlViewComponent(ApplicationDbContext dbContext)
{
this.dbContext = dbContext;
}
public IViewComponentResult Invoke (ICircleAuthorized target)
{
if (target!=null)
{
var oid = target.AuthorId;
ViewBag.ACL = dbContext.Circle.Where(
c=>c.OwnerId == oid)
.Select(
c => new SelectListItem
{
Text = c.Name,
Value = c.Id.ToString(),
Selected = target.AuthorizeCircle(c.Id)
} 
);
ViewBag.Access = dbContext.Circle.Where(
c=>c.OwnerId == oid)
.Select( c=>
new AjaxCheckBoxInfo
{
Text = c.Name,
Checked = target.AuthorizeCircle(c.Id),
Value = c.Id.ToString()
});
}
return View(new CirclesViewModel(target));
}
}
}

View file

@ -0,0 +1,35 @@
using System.Diagnostics;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Localization;
using Yavsc.Models;
using Yavsc.Models.Blog;
namespace Yavsc.ViewComponents
{
public class CommentViewComponent : ViewComponent
{
private readonly ApplicationDbContext context;
private readonly IStringLocalizer<CommentViewComponent> localizer;
public CommentViewComponent(IStringLocalizer<CommentViewComponent> localizer,
ApplicationDbContext context
)
{
this.context = context;
this.localizer = localizer;
}
public async Task<IViewComponentResult> InvokeAsync(long id)
{
var comment = await context.Comment.Include(c=>c.Children).FirstOrDefaultAsync(c => c.Id==id);
if (comment == null)
throw new InvalidOperationException();
ViewData["apictlr"] = "/api/blogcomments";
return View("Default", comment);
}
private string GetDebuggerDisplay()
{
return ToString();
}
}
}

View file

@ -0,0 +1,36 @@
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;
using Yavsc.Helpers;
using Yavsc.Models;
using Yavsc.Server.Helpers;
using Yavsc.ViewModels.UserFiles;
namespace Yavsc.ViewComponents
{
public class DirectoryViewComponent : ViewComponent
{
private readonly UserManager<ApplicationUser> _userManager;
private readonly SignInManager<ApplicationUser> _signInManager;
public DirectoryViewComponent(UserManager<ApplicationUser> userManager,
SignInManager<ApplicationUser> signInManager)
{
_userManager = userManager;
_signInManager = signInManager;
}
public async Task<IViewComponentResult> InvokeAsync(string dirname)
{
string uid = ViewContext.HttpContext.User.GetUserId();
IViewComponentResult result = null;
result = View(new UserDirectoryInfo(
AbstractFileSystemHelpers.UserFilesDirName,
uid, dirname));
return result;
}
}
}

View file

@ -0,0 +1,18 @@
using Microsoft.AspNetCore.Mvc;
using Yavsc.Helpers;
using Yavsc.Models.Billing;
namespace Yavsc.ViewComponents
{
public class PayPalButtonViewComponent : ViewComponent
{
public IViewComponentResult Invoke(NominativeServiceCommand command, string apiControllerName , string controllerName)
{
ViewBag.CreatePaymentUrl = Request.ToAbsolute($"api/{apiControllerName}/createpayment/"+command.Id);
ViewBag.ExecutePaymentUrl = Request.ToAbsolute("api/payment/execute");
ViewBag.Urls=Request.GetPaymentUrls(controllerName,command.Id.ToString());
return View ( command);
}
}
}

View file

@ -0,0 +1,25 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Localization;
using Microsoft.Extensions.Logging;
using Yavsc.Interfaces;
using Yavsc.Models;
namespace Yavsc.ViewComponents
{
public class TaggerViewComponent : ViewComponent
{
readonly IStringLocalizer<TaggerViewComponent> localizer;
public TaggerViewComponent(
IStringLocalizer<TaggerViewComponent> pLocalizer)
{
this.localizer = pLocalizer;
}
public IViewComponentResult Invoke(ITaggable<long> longTaggable)
{
ViewData["Tags"] = longTaggable.GetTags();
ViewData["at"] = localizer["at"];
ViewData["apictlr"] = "~/api/"+localizer["apiRouteTag"+longTaggable.GetType().Name];
return View(longTaggable);
}
}
}