files tree made better.
This commit is contained in:
parent
ffbf032480
commit
ccc91bbf19
1630 changed files with 18209 additions and 41860 deletions
30
src/Yavsc/ViewComponents/AvatarViewComponent.cs
Normal file
30
src/Yavsc/ViewComponents/AvatarViewComponent.cs
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
using System.Linq;
|
||||
using Microsoft.AspNet.Mvc;
|
||||
using Yavsc.Helpers;
|
||||
using Yavsc.Models;
|
||||
using Yavsc.ViewModels.Account;
|
||||
|
||||
namespace Yavsc.ViewComponents
|
||||
{
|
||||
public class AvatarViewComponent : ViewComponent
|
||||
{
|
||||
ApplicationDbContext dbContext;
|
||||
public AvatarViewComponent(ApplicationDbContext dbContext)
|
||||
{
|
||||
this.dbContext = dbContext;
|
||||
}
|
||||
|
||||
public IViewComponentResult Invoke ( string userId, string imgFmt )
|
||||
{
|
||||
var user = dbContext.Users.Single(u=>u.Id == userId);
|
||||
|
||||
return View ( "Default", new ShortUserInfo
|
||||
{
|
||||
Avatar = dbContext.AvatarUri(userId, imgFmt),
|
||||
UserName = user.UserName,
|
||||
UserId = userId
|
||||
} );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
102
src/Yavsc/ViewComponents/BillViewComponent.cs
Normal file
102
src/Yavsc/ViewComponents/BillViewComponent.cs
Normal file
|
|
@ -0,0 +1,102 @@
|
|||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Mvc;
|
||||
using Microsoft.Data.Entity;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Yavsc.Abstract.FileSystem;
|
||||
using Yavsc.Billing;
|
||||
using Yavsc.Helpers;
|
||||
using Yavsc.Models;
|
||||
using Yavsc.ViewModels;
|
||||
using Yavsc.ViewModels.Gen;
|
||||
using Yavsc.Services;
|
||||
|
||||
namespace Yavsc.ViewComponents
|
||||
{
|
||||
public class BillViewComponent : ViewComponent
|
||||
{
|
||||
ApplicationDbContext dbContext;
|
||||
IBillingService billing;
|
||||
IStringLocalizer<Yavsc.Resources.YavscLocalisation> localizer;
|
||||
ILogger logger ;
|
||||
|
||||
public BillViewComponent(ApplicationDbContext dbContext,
|
||||
IStringLocalizer<Yavsc.Resources.YavscLocalisation> localizer,
|
||||
IBillingService billing,
|
||||
ILoggerFactory loggerFactory)
|
||||
{
|
||||
this.billing = billing;
|
||||
this.dbContext = dbContext;
|
||||
this.localizer = localizer;
|
||||
logger = loggerFactory.CreateLogger<BillViewComponent>();
|
||||
}
|
||||
|
||||
public async Task<IViewComponentResult> InvokeAsync(string code, IBillable billable, OutputFormat format, bool asBill)
|
||||
{
|
||||
var di = new DirectoryInfo(Startup.SiteSetup.Bills);
|
||||
var dia = new DirectoryInfo(Startup.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 = Startup.Temp,
|
||||
TeXSource = tex,
|
||||
DestDir = AbstractFileSystemHelpers.UserBillsDirName,
|
||||
BaseFileName = billable.GetFileBaseName(billing)
|
||||
};
|
||||
if (genrtrData.GenerateEstimatePdf()) {
|
||||
return Json(new { Generated = genrtrData.BaseFileName+".pdf" });
|
||||
} else {
|
||||
return Json(new { Error = genrtrData.GenerationErrorMessage } );
|
||||
}
|
||||
}
|
||||
ViewBag.BillFileInfo = billable.GetBillInfo(billing);
|
||||
return View("Default",billable);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
59
src/Yavsc/ViewComponents/BlogIndexViewComponent.cs
Normal file
59
src/Yavsc/ViewComponents/BlogIndexViewComponent.cs
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Mvc;
|
||||
using Microsoft.AspNet.Identity;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.AspNet.Authorization;
|
||||
using Microsoft.Extensions.OptionsModel;
|
||||
using Yavsc.Models;
|
||||
using Microsoft.Data.Entity;
|
||||
using System.Linq;
|
||||
using Yavsc.Models.Blog;
|
||||
|
||||
namespace Yavsc.ViewComponents
|
||||
{
|
||||
public class BlogIndexViewComponent: ViewComponent
|
||||
{
|
||||
ILogger _logger;
|
||||
private ApplicationDbContext _context;
|
||||
private IAuthorizationService _authorizationService;
|
||||
public BlogIndexViewComponent(
|
||||
ApplicationDbContext context,
|
||||
UserManager<ApplicationUser> userManager,
|
||||
ILoggerFactory loggerFactory,
|
||||
IAuthorizationService authorizationService,
|
||||
IOptions<SiteSettings> siteSettings)
|
||||
{
|
||||
_context = context;
|
||||
_logger = loggerFactory.CreateLogger<BlogIndexViewComponent>();
|
||||
_authorizationService = authorizationService;
|
||||
}
|
||||
|
||||
// Renders blog index ofr the specified user by name
|
||||
public async Task<IViewComponentResult> InvokeAsync(string viewerId, int skip=0, int maxLen=25)
|
||||
{
|
||||
long[] usercircles = await _context.Circle.Include(c=>c.Members).
|
||||
Where(c=>c.Members.Any(m=>m.MemberId == viewerId))
|
||||
.Select(c=>c.Id).ToArray();
|
||||
IQueryable<BlogPost> posts ;
|
||||
var allposts = _context.Blogspot
|
||||
.Include(b => b.Author)
|
||||
.Include(p=>p.ACL)
|
||||
.Include(p=>p.Tags)
|
||||
.Include(p=>p.Comments)
|
||||
.Where(p=>p.AuthorId == viewerId || p.Visible);
|
||||
|
||||
if (usercircles != null) {
|
||||
posts = allposts.Where(p=> p.ACL.Count==0 || p.ACL.Any(a=> usercircles.Contains(a.CircleId)))
|
||||
;
|
||||
}
|
||||
else {
|
||||
posts = allposts.Where(p => p.ACL.Count == 0);
|
||||
}
|
||||
|
||||
var data = posts.OrderByDescending( p=> p.DateCreated).ToArray();
|
||||
var grouped = data.GroupBy(p=> p.Title).Skip(skip).Take(maxLen);
|
||||
|
||||
return View("Default", grouped);
|
||||
}
|
||||
}
|
||||
}
|
||||
50
src/Yavsc/ViewComponents/CalendarViewComponent.cs
Normal file
50
src/Yavsc/ViewComponents/CalendarViewComponent.cs
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Mvc;
|
||||
using Yavsc.Models;
|
||||
using Yavsc.Services;
|
||||
|
||||
namespace Yavsc.ViewComponents
|
||||
{
|
||||
public class CalendarViewComponent : ViewComponent
|
||||
{
|
||||
ApplicationDbContext _dbContext;
|
||||
ICalendarManager _manager;
|
||||
|
||||
public CalendarViewComponent (
|
||||
ApplicationDbContext dbContext,
|
||||
ICalendarManager manager)
|
||||
{
|
||||
_manager = manager;
|
||||
_dbContext = dbContext;
|
||||
}
|
||||
|
||||
public async Task<IViewComponentResult> InvokeAsync (
|
||||
string htmlFieldName,
|
||||
string calId = null)
|
||||
{
|
||||
var minDate = DateTime.Now;
|
||||
var maxDate = minDate.AddDays(20);
|
||||
|
||||
var model = await _manager.CreateViewModelAsync(
|
||||
htmlFieldName,
|
||||
calId, minDate, maxDate
|
||||
);
|
||||
|
||||
return View(model);
|
||||
}
|
||||
public async Task<IViewComponentResult> InvokeAsync (
|
||||
string htmlFieldName)
|
||||
{
|
||||
var minDate = DateTime.Now;
|
||||
var maxDate = minDate.AddDays(20);
|
||||
|
||||
var model = await _manager.CreateViewModelAsync(
|
||||
htmlFieldName,
|
||||
null, minDate, maxDate
|
||||
);
|
||||
|
||||
return View(model);
|
||||
}
|
||||
}
|
||||
}
|
||||
47
src/Yavsc/ViewComponents/CirclesControlViewComponent.cs
Normal file
47
src/Yavsc/ViewComponents/CirclesControlViewComponent.cs
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
using System.Linq;
|
||||
using Microsoft.AspNet.Mvc;
|
||||
using Microsoft.AspNet.Mvc.Rendering;
|
||||
|
||||
namespace Yavsc.ViewComponents
|
||||
{
|
||||
using Models;
|
||||
using ViewModels.Controls;
|
||||
using ViewModels.Relationship;
|
||||
using Yavsc.Abstract.Identity.Security;
|
||||
|
||||
public class CirclesControlViewComponent : ViewComponent
|
||||
{
|
||||
ApplicationDbContext dbContext;
|
||||
public CirclesControlViewComponent(ApplicationDbContext dbContext)
|
||||
{
|
||||
this.dbContext = dbContext;
|
||||
}
|
||||
|
||||
|
||||
public IViewComponentResult Invoke (ICircleAuthorized target)
|
||||
{
|
||||
var oid = target.GetOwnerId();
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
20
src/Yavsc/ViewComponents/CommentViewComponent.cs
Normal file
20
src/Yavsc/ViewComponents/CommentViewComponent.cs
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
using Microsoft.AspNet.Mvc;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using Yavsc.Models.Blog;
|
||||
|
||||
namespace Yavsc.ViewComponents
|
||||
{
|
||||
public class CommentViewComponent : ViewComponent
|
||||
{
|
||||
IStringLocalizer<CommentViewComponent> localizer;
|
||||
public CommentViewComponent(IStringLocalizer<CommentViewComponent> localizer)
|
||||
{
|
||||
this.localizer = localizer;
|
||||
}
|
||||
public IViewComponentResult Invoke(IIdentified<long> longCommentable)
|
||||
{
|
||||
ViewData["apictlr"] = "/api/"+localizer["apiRouteComment"+longCommentable.GetType().Name];
|
||||
return View(longCommentable.GetType().Name, new Comment{ PostId = longCommentable.Id });
|
||||
}
|
||||
}
|
||||
}
|
||||
21
src/Yavsc/ViewComponents/DirectoryViewComponent.cs
Normal file
21
src/Yavsc/ViewComponents/DirectoryViewComponent.cs
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
using Microsoft.AspNet.Mvc;
|
||||
|
||||
namespace Yavsc.ViewComponents
|
||||
{
|
||||
using System.Threading.Tasks;
|
||||
using Yavsc.Abstract.FileSystem;
|
||||
using Yavsc.ViewModels.UserFiles;
|
||||
|
||||
public class DirectoryViewComponent : ViewComponent
|
||||
{
|
||||
public async Task<IViewComponentResult> InvokeAsync(string dirname)
|
||||
{
|
||||
IViewComponentResult result = null;
|
||||
await Task.Run(() =>
|
||||
{
|
||||
result = View(new UserDirectoryInfo(AbstractFileSystemHelpers.UserFilesDirName, User.Identity.Name, dirname));
|
||||
});
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
18
src/Yavsc/ViewComponents/PayPalButtonComponent.cs
Normal file
18
src/Yavsc/ViewComponents/PayPalButtonComponent.cs
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
using Microsoft.AspNet.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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
32
src/Yavsc/ViewComponents/TaggerComponent.cs
Normal file
32
src/Yavsc/ViewComponents/TaggerComponent.cs
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
using Microsoft.AspNet.Mvc;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Yavsc.Interfaces;
|
||||
using Yavsc.Models;
|
||||
|
||||
namespace Yavsc.ViewComponents
|
||||
{
|
||||
public class TaggerViewComponent : ViewComponent
|
||||
|
||||
{
|
||||
ApplicationDbContext dbContext;
|
||||
IStringLocalizer<TaggerViewComponent> localizer;
|
||||
ILogger logger ;
|
||||
public TaggerViewComponent(
|
||||
ApplicationDbContext pdbContext,
|
||||
IStringLocalizer<TaggerViewComponent> pLocalizer,
|
||||
ILoggerFactory loggerFactory)
|
||||
{
|
||||
dbContext = pdbContext;
|
||||
this.localizer = pLocalizer;
|
||||
this.logger = loggerFactory.CreateLogger<TaggerViewComponent>();
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue