infra du badge paramêtre manquant
This commit is contained in:
9
Yavsc/Attributes/ActivitySettingAttribute.cs
Normal file
9
Yavsc/Attributes/ActivitySettingAttribute.cs
Normal file
@ -0,0 +1,9 @@
|
||||
using System;
|
||||
|
||||
namespace Yavsc.Attributes
|
||||
{
|
||||
public class ActivitySettingAttribute : Attribute
|
||||
{
|
||||
|
||||
}
|
||||
}
|
@ -41,9 +41,9 @@ namespace Yavsc.Controllers
|
||||
var items = Startup.ProfileTypes.Select(
|
||||
pt => new SelectListItem
|
||||
{
|
||||
Text = SR[pt.Key],
|
||||
Value = pt.Key,
|
||||
Selected = currentCode == pt.Key
|
||||
Text = SR[pt.FullName],
|
||||
Value = pt.FullName,
|
||||
Selected = currentCode == pt.FullName
|
||||
}).ToList();
|
||||
items.Add(new SelectListItem { Text = SR[Constants.NoneCode], Value = Constants.NoneCode, Selected = currentCode == null});
|
||||
ViewBag.SettingsClassName = items;
|
||||
|
@ -7,16 +7,21 @@ using Microsoft.Data.Entity;
|
||||
|
||||
namespace Yavsc.Controllers
|
||||
{
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Models;
|
||||
using Models.Workflow;
|
||||
using Yavsc.ViewModels.Workflow;
|
||||
|
||||
[Authorize]
|
||||
public class DoController : Controller
|
||||
{
|
||||
private ApplicationDbContext _context;
|
||||
ILogger _logger;
|
||||
|
||||
public DoController(ApplicationDbContext context)
|
||||
public DoController(ApplicationDbContext context,ILogger<DoController> logger)
|
||||
{
|
||||
_context = context;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
// GET: /Do/Index
|
||||
@ -48,8 +53,15 @@ namespace Yavsc.Controllers
|
||||
}
|
||||
ViewBag.HasConfigurableSettings = (userActivity.Does.SettingsClassName != null);
|
||||
if (ViewBag.HasConfigurableSettings)
|
||||
ViewBag.SettingsControllerName = Startup.ProfileTypes[userActivity.Does.SettingsClassName].Name;
|
||||
return View(userActivity);
|
||||
ViewBag.SettingsControllerName = Startup.ProfileTypes.Single(t=>t.FullName==userActivity.Does.SettingsClassName).Name;
|
||||
_logger.LogWarning(userActivity.Does.SettingsClassName);
|
||||
var dbset = _context.GetDbSet(userActivity.Does.SettingsClassName);
|
||||
_logger.LogWarning(dbset.Any(i=>i.UserId == id).ToString());
|
||||
return View(new UserActivityViewModel {
|
||||
Declaration = userActivity,
|
||||
HasSettings = dbset?.Any(ua=>ua.UserId==id) ?? false,
|
||||
NeedsSettings = userActivity.Does.SettingsClassName != null
|
||||
} );
|
||||
}
|
||||
|
||||
// GET: Do/Create
|
||||
|
@ -12,16 +12,13 @@ namespace Yavsc.Helpers
|
||||
{
|
||||
public static ISpecializationSettings CreateSettings (this Activity activity, string userId) {
|
||||
if (activity.SettingsClassName==null) return null;
|
||||
var ctor = Startup.ProfileTypes[activity.SettingsClassName].GetConstructor(System.Type.EmptyTypes);
|
||||
var ctor = Startup.ProfileTypes.Single(t=>t.FullName==activity.SettingsClassName).GetConstructor(System.Type.EmptyTypes);
|
||||
if (ctor==null) return null;
|
||||
ISpecializationSettings result = (ISpecializationSettings) ctor.Invoke(null);
|
||||
result.UserId = userId;
|
||||
return result;
|
||||
}
|
||||
public static bool HasSettings (this UserActivity useract, ApplicationDbContext dbContext) {
|
||||
ISpecializationSettings candidate = CreateSettings(useract.Does,useract.UserId);
|
||||
return candidate.ExistsInDb(dbContext);
|
||||
}
|
||||
|
||||
public static List<PerformerProfile> ListPerformers(this ApplicationDbContext context, string actCode)
|
||||
{
|
||||
return context.Performers
|
||||
|
@ -26,6 +26,8 @@ namespace Yavsc.Models
|
||||
using Musical.Profiles;
|
||||
using Workflow.Profiles;
|
||||
using Drawing;
|
||||
using System.Collections.Generic;
|
||||
using Yavsc.Attributes;
|
||||
|
||||
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
|
||||
{
|
||||
@ -51,8 +53,15 @@ namespace Yavsc.Models
|
||||
if (et.ClrType.GetInterface("IBaseTrackedEntity")!=null)
|
||||
et.FindProperty("DateCreated").IsReadOnlyAfterSave = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public IQueryable<ISpecializationSettings> GetDbSet(string settingsClassName)
|
||||
{
|
||||
var dbSetPropInfo = Startup.UserSettings.SingleOrDefault(s => s.PropertyType.GenericTypeArguments[0].FullName == settingsClassName ) ;
|
||||
if (dbSetPropInfo == null) return null;
|
||||
return (IQueryable<ISpecializationSettings>) dbSetPropInfo.GetValue(this);
|
||||
}
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
optionsBuilder.UseNpgsql(Startup.ConnectionString);
|
||||
@ -274,6 +283,7 @@ namespace Yavsc.Models
|
||||
|
||||
public DbSet<HairPrestation> HairPrestation { get; set; }
|
||||
|
||||
[ActivitySetting]
|
||||
public DbSet<BrusherProfile> BrusherProfile { get; set; }
|
||||
|
||||
|
||||
|
@ -400,6 +400,8 @@
|
||||
<data name="Yavsc.Models.Musical.Profiles.DjSettings"><value>Paramètres Dj (le compte SoundCloud.com)</value></data>
|
||||
<data name="Yavsc.Models.Musical.Profiles.FormationSettings"><value>Paramètres formation (les partenaires)</value></data>
|
||||
<data name="Yavsc.Models.Musical.Profiles.GeneralSettings"><value>Paramètres généraux (visibilité et présentation)</value></data>
|
||||
<data name="Yavsc.Models.Haircut.BrusherProfile"><value>Paramètres coiffeur: tarifs, disponibilité</value></data>
|
||||
|
||||
<data name="Yes"><value>Oui</value></data>
|
||||
<data name="YouNeedToBeAuthenticatedIOToContact"><value>Vous devez vous authentifier pour pouvoir demander un devis
|
||||
à un préstataire.</value></data>
|
||||
|
@ -18,8 +18,10 @@ namespace Yavsc
|
||||
{
|
||||
private Client GetApplication(string clientId)
|
||||
{
|
||||
var dbContext = new ApplicationDbContext();
|
||||
var app = dbContext.Applications.FirstOrDefault(x => x.Id == clientId);
|
||||
Client app=null;
|
||||
using (var dbContext = new ApplicationDbContext()) {
|
||||
app = dbContext.Applications.FirstOrDefault(x => x.Id == clientId);
|
||||
}
|
||||
return app;
|
||||
}
|
||||
private readonly ConcurrentDictionary<string, string> _authenticationCodes = new ConcurrentDictionary<string, string>(StringComparer.Ordinal);
|
||||
|
@ -1,6 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Microsoft.AspNet.Builder;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Yavsc.Models;
|
||||
using YavscLib;
|
||||
|
||||
namespace Yavsc
|
||||
{
|
||||
@ -10,15 +15,16 @@ namespace Yavsc
|
||||
/// Lists Available user profile classes,
|
||||
/// populated at startup, using reflexion.
|
||||
/// </summary>
|
||||
public static Dictionary<string,Type> ProfileTypes = new Dictionary<string,Type>() ;
|
||||
|
||||
public static List<Type> ProfileTypes = new List<Type>() ;
|
||||
public static List<PropertyInfo> UserSettings = new List<PropertyInfo> ();
|
||||
|
||||
/// <summary>
|
||||
/// Lists available command forms.
|
||||
/// This is hard coded.
|
||||
/// </summary>
|
||||
public static readonly string [] Forms = new string [] { "Profiles" , "HairCut" };
|
||||
|
||||
private void ConfigureWorkflow(IApplicationBuilder app, SiteSettings settings)
|
||||
private void ConfigureWorkflow(IApplicationBuilder app, SiteSettings settings, ILogger logger)
|
||||
{
|
||||
System.AppDomain.CurrentDomain.ResourceResolve += OnYavscResourceResolve;
|
||||
|
||||
@ -26,10 +32,32 @@ namespace Yavsc
|
||||
foreach (var c in a.GetTypes()) {
|
||||
if (c.IsClass && !c.IsAbstract &&
|
||||
c.GetInterface("ISpecializationSettings")!=null) {
|
||||
ProfileTypes.Add(c.FullName,c);
|
||||
ProfileTypes.Add(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach (var propinfo in typeof(ApplicationDbContext).GetProperties()) {
|
||||
foreach (var attr in propinfo.CustomAttributes) {
|
||||
if (attr.AttributeType.FullName == "Yavsc.Attributes.ActivitySettingAttribute") {
|
||||
// bingo
|
||||
if (typeof(IQueryable<ISpecializationSettings>).IsAssignableFrom(propinfo.PropertyType))
|
||||
{
|
||||
logger.LogInformation($"Paramêtres utilisateur déclaré: {propinfo.Name}");
|
||||
UserSettings.Add(propinfo);
|
||||
|
||||
} else
|
||||
// Design time error
|
||||
{
|
||||
logger.LogCritical(
|
||||
$@"la propriété {propinfo.Name} du contexte de la
|
||||
base de donnée déclare être un refuge de paramêtre utilisateur
|
||||
du workflow, mais l'implemente pas l'interface IQueryable<ISpecializationSettings>,
|
||||
Elle est du type {propinfo.MemberType.GetType()}");
|
||||
throw new NotSupportedException("invalid ActivitySettingAttribute on property from dbcontext");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public static System.Reflection.Assembly OnYavscResourceResolve (object sender, ResolveEventArgs ev)
|
||||
{
|
||||
|
@ -335,7 +335,7 @@ namespace Yavsc
|
||||
ConfigureOAuthApp(app, SiteSetup);
|
||||
ConfigureFileServerApp(app, SiteSetup, env, authorizationService);
|
||||
ConfigureWebSocketsApp(app, SiteSetup, env);
|
||||
ConfigureWorkflow(app, SiteSetup);
|
||||
ConfigureWorkflow(app, SiteSetup, logger);
|
||||
app.UseRequestLocalization(localizationOptions.Value, (RequestCulture) new RequestCulture((string)"fr"));
|
||||
app.UseSession();
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
using Yavsc.Models.Billing;
|
||||
|
||||
namespace Yavsc.ViewModels.WorkFlow
|
||||
namespace Yavsc.ViewModels.Workflow
|
||||
{
|
||||
public class EstimateEdition
|
||||
{
|
11
Yavsc/ViewModels/Workflow/UserActivityViewModel.cs
Normal file
11
Yavsc/ViewModels/Workflow/UserActivityViewModel.cs
Normal file
@ -0,0 +1,11 @@
|
||||
using Yavsc.Models.Workflow;
|
||||
|
||||
namespace Yavsc.ViewModels.Workflow
|
||||
{
|
||||
public class UserActivityViewModel
|
||||
{
|
||||
public UserActivity Declaration { get; set; }
|
||||
public bool NeedsSettings { get; set; }
|
||||
public bool HasSettings { get; set; }
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
@model UserActivity
|
||||
@model UserActivityViewModel
|
||||
|
||||
@{
|
||||
ViewData["Title"] = SR["Details"];
|
||||
@ -7,20 +7,24 @@
|
||||
<h2>@ViewData["Title"]</h2>
|
||||
|
||||
<div>
|
||||
<h4>Détails de votre activité @Model.DoesCode</h4>
|
||||
<h4>Détails de votre activité en <em>@Model.Declaration.Does.Name</em></h4>
|
||||
<hr />
|
||||
<dl class="dl-horizontal">
|
||||
<dt>@SR["Activity"]</dt>
|
||||
<dd> @Html.DisplayFor(m=>m.Does)
|
||||
<dd> @Html.DisplayFor(m=>m.Declaration.Does)
|
||||
@if (ViewBag.HasConfigurableSettings) {
|
||||
<a asp-controller="@ViewBag.SettingsControllerName" asp-action="Index" >
|
||||
[@SR["Manage"] @SR[Model.Does.SettingsClassName]]
|
||||
<a asp-controller="@ViewBag.SettingsControllerName" asp-action="Index" class="btn btn-default">
|
||||
@SR[Model.Declaration.Does.SettingsClassName]
|
||||
|
||||
NeedsSettings: @Model.NeedsSettings
|
||||
HasSettings: @Model.HasSettings
|
||||
|
||||
</a>
|
||||
}
|
||||
</dd>
|
||||
</dl>
|
||||
</div>
|
||||
<p>
|
||||
<a asp-action="Edit" asp-route-id="@Model.UserId" asp-route-activityCode="@Model.DoesCode">Edit</a> |
|
||||
<a asp-action="Edit" asp-route-id="@Model.Declaration.UserId" asp-route-activityCode="@Model.Declaration.DoesCode">Edit</a> |
|
||||
<a asp-action="Index">Back to List</a>
|
||||
</p>
|
||||
|
@ -13,6 +13,7 @@
|
||||
<tr>
|
||||
<th>@SR["Activity"]</th>
|
||||
<th>@SR["Weight"]</th>
|
||||
<th>@SR["Settings"]</th>
|
||||
</tr>
|
||||
|
||||
@foreach (var item in Model) {
|
||||
@ -21,6 +22,8 @@
|
||||
</td>
|
||||
<td> @item.Weight
|
||||
</td>
|
||||
<dt>
|
||||
</dt>
|
||||
<td>
|
||||
<a asp-action="Edit" asp-route-id="@item.UserId" asp-route-activityCode="@item.DoesCode">Edit</a> |
|
||||
<a asp-action="Details" asp-route-id="@item.UserId" asp-route-activityCode="@item.DoesCode">Details</a> |
|
||||
|
@ -29,6 +29,7 @@
|
||||
@using Yavsc.ViewModels.Auth;
|
||||
@using Yavsc.ViewModels.Administration;
|
||||
@using Yavsc.ViewModels.Relationship;
|
||||
@using Yavsc.ViewModels.Workflow;
|
||||
|
||||
@inject IViewLocalizer LocString
|
||||
@addTagHelper "*, Microsoft.AspNet.Mvc.TagHelpers"
|
||||
|
@ -3,6 +3,5 @@ namespace YavscLib
|
||||
public interface ISpecializationSettings
|
||||
{
|
||||
string UserId { get ; set ; }
|
||||
bool ExistsInDb(object dbContext);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user