From 427ee9195a208974e3250f34dd2a80984f008902 Mon Sep 17 00:00:00 2001 From: Frede Hundewadt <22748698+fhdk@users.noreply.github.com> Date: Sat, 11 Jun 2022 19:27:29 +0200 Subject: [PATCH] wip 0.5.1 --- Wonky.Client/Components/Home.razor | 9 +- Wonky.Client/Components/Home.razor.cs | 31 +-- .../Components/WorkDateComponent.razor | 13 ++ .../Components/WorkDateComponent.razor.cs | 39 ++++ .../Components/WorkDateComponent.razor.css | 3 + Wonky.Client/Pages/CrmActivityCreate.razor | 197 ++++++++---------- Wonky.Client/Pages/CrmActivityCreate.razor.cs | 47 ++--- Wonky.Client/wwwroot/appsettings.json | 2 +- Wonky.Entity/DTO/ActivityDto.cs | 1 - 9 files changed, 163 insertions(+), 179 deletions(-) create mode 100644 Wonky.Client/Components/WorkDateComponent.razor create mode 100644 Wonky.Client/Components/WorkDateComponent.razor.cs create mode 100644 Wonky.Client/Components/WorkDateComponent.razor.css diff --git a/Wonky.Client/Components/Home.razor b/Wonky.Client/Components/Home.razor index 7ff9353c..6785ba80 100644 --- a/Wonky.Client/Components/Home.razor +++ b/Wonky.Client/Components/Home.razor @@ -18,14 +18,7 @@ Innotec Danmark A/S -
-
-
@_workDate.ToLongDateString()
-
-
- -
-
+
Dagens aktivitet
diff --git a/Wonky.Client/Components/Home.razor.cs b/Wonky.Client/Components/Home.razor.cs index 35e46290..e99b0ac1 100644 --- a/Wonky.Client/Components/Home.razor.cs +++ b/Wonky.Client/Components/Home.razor.cs @@ -35,50 +35,25 @@ public partial class Home : IDisposable [Inject] public NavigationManager Navigator { get; set; } [Inject] public IActivityHttpRepository ActivityRepo { get; set; } private Preferences _prefs { get; set; } = new(); - private DateTime _workDate { get; set; } = new(); private List Activities { get; set; } - //private EditContext _editContext { get; set; } - protected override async Task OnInitializedAsync() { - //_editContext = new EditContext(_workDate); - //_editContext.OnFieldChanged += HandleFieldChanged; - Interceptor.RegisterEvent(); Interceptor.RegisterBeforeSendEvent(); - - if (string.IsNullOrWhiteSpace(await Storage.GetItemAsStringAsync("_xa").ConfigureAwait(true))) - Navigator.NavigateTo("/login/home"); - _prefs = await UserPrefs.GetPreferences(); - _workDate = string.IsNullOrWhiteSpace(_prefs.WorkDate) - ? DateTime.Now - : DateTime.Parse(_prefs.WorkDate); - - await UserPrefs.SetWorkDate(_workDate); - - - await FetchActivities(); - } - - private void HandleFieldChanged(object sender, FieldChangedEventArgs e) - { - StateHasChanged(); + await FetchActivities(_prefs.WorkDate); } - private async Task FetchActivities() + private async Task FetchActivities(string workDate) { Activities = new List(); - await UserPrefs.SetWorkDate(_workDate); - Activities = await ActivityRepo.GetActivities($"{_workDate:yyyy-MM-dd}"); + Activities = await ActivityRepo.GetActivities(workDate); } public void Dispose() { Interceptor.DisposeEvent(); - //_editContext.OnFieldChanged -= HandleFieldChanged; - //_editContext.OnValidationStateChanged -= ValidationChanged; } } diff --git a/Wonky.Client/Components/WorkDateComponent.razor b/Wonky.Client/Components/WorkDateComponent.razor new file mode 100644 index 00000000..302470f4 --- /dev/null +++ b/Wonky.Client/Components/WorkDateComponent.razor @@ -0,0 +1,13 @@ +@using Blazored.LocalStorage +@using Wonky.Client.Services + +
+
+
@DateTime.Parse(WorkDate).ToLongDateString()
+
+
+ +
+
diff --git a/Wonky.Client/Components/WorkDateComponent.razor.cs b/Wonky.Client/Components/WorkDateComponent.razor.cs new file mode 100644 index 00000000..14995e24 --- /dev/null +++ b/Wonky.Client/Components/WorkDateComponent.razor.cs @@ -0,0 +1,39 @@ +using Blazored.LocalStorage; +using Microsoft.AspNetCore.Components; +using Wonky.Client.Services; + +namespace Wonky.Client.Components; + +public partial class WorkDateComponent : IDisposable +{ + [Inject] private ILocalStorageService LocalStorage { get; set; } + [Inject] private UserPreferenceService UserPrefs { get; set; } + [Parameter] public EventCallback OnChanged { get; set; } + + private Preferences _prefs = new(); + private string WorkDate { get; set; } + + protected override async Task OnInitializedAsync() + { + UserPrefs.OnChange += ProfileServiceOnOnChange; + _prefs = await UserPrefs.GetPreferences(); + WorkDate = _prefs.WorkDate; + } + private async Task OnDateChanged(ChangeEventArgs e) + { + var val = $"{DateOnly.Parse(e.Value?.ToString()!):yyyy-MM-dd}"; + await OnChanged.InvokeAsync(val); + await UserPrefs.SetWorkDate(DateTime.Parse(val)); + } + + private void ProfileServiceOnOnChange(Preferences newPreferences) + { + _prefs = newPreferences; + StateHasChanged(); + } + + public void Dispose() + { + UserPrefs.OnChange -= ProfileServiceOnOnChange; + } +} \ No newline at end of file diff --git a/Wonky.Client/Components/WorkDateComponent.razor.css b/Wonky.Client/Components/WorkDateComponent.razor.css new file mode 100644 index 00000000..6ab96e32 --- /dev/null +++ b/Wonky.Client/Components/WorkDateComponent.razor.css @@ -0,0 +1,3 @@ +h5 { + font-variant: small-caps; +} \ No newline at end of file diff --git a/Wonky.Client/Pages/CrmActivityCreate.razor b/Wonky.Client/Pages/CrmActivityCreate.razor index 27655a55..2e18276f 100644 --- a/Wonky.Client/Pages/CrmActivityCreate.razor +++ b/Wonky.Client/Pages/CrmActivityCreate.razor @@ -19,11 +19,11 @@ @using Microsoft.AspNetCore.Authorization @attribute [Authorize(Roles = "Adviser")] @using Wonky.Client.Components + @if (DraftContext != null) { - + -

@@ -36,26 +36,13 @@
- @*
- +
- - -
- -
- - -
-
- *@ - -
- -
- + @@ -63,129 +50,69 @@
- + - + @* *@
- +
- - +
- +
-
- -
- -
- -
- -
-
-
- -
- -
-
-
- +
+
-
-
-
- +
+
-
- +
+
-
-
-
- +
+
-
- +
+
- - @* Leverings adresse *@ -
-

- -

-
-
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
-
-
- @* Order lines *@

@@ -314,7 +241,7 @@

} - @* Ordrekladde *@ + @* Order draft lines *@
Kladdelinjer Global kladde (udløber efter @(DraftStateProvider.Draft.TimeToLiveInSeconds / 60)m inaktivitet) @@ -365,13 +292,67 @@
+ @* Delivery address *@ +
+

+ +

+
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+
@@ -380,7 +361,7 @@
@* *@ - +
diff --git a/Wonky.Client/Pages/CrmActivityCreate.razor.cs b/Wonky.Client/Pages/CrmActivityCreate.razor.cs index 6f9c94af..4a3675ba 100644 --- a/Wonky.Client/Pages/CrmActivityCreate.razor.cs +++ b/Wonky.Client/Pages/CrmActivityCreate.razor.cs @@ -61,23 +61,18 @@ public partial class CrmActivityCreate : IDisposable private bool InvalidStatusType { get; set; } = true; private bool InvalidActivity { get; set; } = true; private bool InvalidCanvas { get; set; } = true; - private bool InvalidDate { get; set; } = true; private UserInfoView Ux { get; set; } = new(); - private DateTime _draftDate { get; set; } - - protected override void OnParametersSet() - { - base.OnParametersSet(); - } protected override async Task OnInitializedAsync() { Interceptor.RegisterEvent(); Interceptor.RegisterBeforeSendEvent(); - + _prefs = await UserPrefs.GetPreferences(); - _paging.SearchColumn = _prefs.ItemSearch; + + _paging.SearchColumn = _prefs.ItemSearch ?? "name"; _paging.PageSize = Convert.ToInt32(_prefs.PageSize); + await GetSalesItems(); Ux = await StorageService.GetItemAsync("_xu"); NgCompany = await CompanyRepo.GetCompanyById(CompanyId); @@ -85,10 +80,7 @@ public partial class CrmActivityCreate : IDisposable // set up identification _poDraft.SalesHeadId = ""; _poDraft.CompanyId = CompanyId; - _draftDate = string.IsNullOrWhiteSpace(_prefs.WorkDate) - ? DateTime.Now - : DateTime.Parse(_prefs.WorkDate); - _poDraft.ActivityDate = $"{_draftDate:yyyy-MM-dd}"; + _poDraft.ActivityDate = _prefs.WorkDate; // permanent identifications _poDraft.SalesRep = Ux.Adviser; @@ -108,18 +100,21 @@ public partial class CrmActivityCreate : IDisposable _poDraft.DlvAddress2 = NgCompany.Address2; _poDraft.DlvZipCode = NgCompany.ZipCode; _poDraft.DlvCity = NgCompany.City; - + DraftContext = new EditContext(_poDraft); DraftContext.OnFieldChanged += HandleFieldChanged; DraftContext.OnValidationStateChanged += ValidationChanged; } + private void SetWorkDate(string workDate) + { + _poDraft.ActivityDate = workDate; + } + private async Task CreateActivity() { HideButtons = true; - // write work date to preference - await UserPrefs.SetWorkDate(_draftDate); var activityType = _poDraft.ActivityTypeEnum switch { "phone" => "Tlf", @@ -127,7 +122,6 @@ public partial class CrmActivityCreate : IDisposable _ => "" }; _poDraft.OurRef = $"{Ux.FullName.Split(" ")[0]} {activityType}"; - _poDraft.ActivityDate = $"{_draftDate:yyyy-MM-dd}"; var ln = 0; // post to create activity endpoint @@ -160,19 +154,10 @@ public partial class CrmActivityCreate : IDisposable private void CheckActivity() { InvalidActivityType = string.IsNullOrWhiteSpace(_poDraft.ActivityTypeEnum); - Console.WriteLine($"ActivityType => {InvalidActivityType}"); } private void CheckStatus() { InvalidStatusType = string.IsNullOrWhiteSpace(_poDraft.ActivityStatusEnum); - Console.WriteLine($"StatusType => {InvalidStatusType}"); - } - - private void CheckDate() - { - _poDraft.ActivityDate = $"{_draftDate:yyyy-MM-dd}"; - InvalidDate = _poDraft.CheckDate; - Console.WriteLine($"InvalidDate => {InvalidDate}"); } private async Task DeleteDraft() @@ -269,11 +254,10 @@ public partial class CrmActivityCreate : IDisposable private void HandleFieldChanged(object sender, FieldChangedEventArgs e) { - InvalidCanvas = InvalidActivityType || InvalidDate; + InvalidCanvas = InvalidActivityType; InvalidActivity = InvalidActivityType || _poFormInvalid || DraftStateProvider.Draft.Items.Count == 0 - || InvalidDate || (_poDraft.ActivityStatusEnum == "offer" && string.IsNullOrWhiteSpace(_poDraft.EMail)); if (InvalidCanvas || InvalidActivity) @@ -286,14 +270,11 @@ public partial class CrmActivityCreate : IDisposable } private void ValidationChanged(object sender, ValidationStateChangedEventArgs e) { - if (!string.IsNullOrEmpty(_poDraft.VatNumber)) - { - if(!VatUtils.ValidateFormat(NgCompany.CountryCode, _poDraft.VatNumber)) - ToastService.ShowWarning("CVR / ORG nummer er ikke et gyldigt registreringsnummer"); - } if (string.IsNullOrEmpty(_poDraft.ActivityTypeEnum)) ToastService.ShowWarning("Aktivitet type kan ikke være tom"); + _poFormInvalid = false; + DraftContext.OnFieldChanged -= HandleFieldChanged; DraftContext = new EditContext(_poDraft); DraftContext.OnFieldChanged += HandleFieldChanged; diff --git a/Wonky.Client/wwwroot/appsettings.json b/Wonky.Client/wwwroot/appsettings.json index ca5adf05..6e6bac3b 100644 --- a/Wonky.Client/wwwroot/appsettings.json +++ b/Wonky.Client/wwwroot/appsettings.json @@ -8,7 +8,7 @@ }, "appInfo": { "name": "Wonky Client", - "version": "0.4.3", + "version": "0.5.1", "isBeta": true, "image": "grumpy-coder.png" }, diff --git a/Wonky.Entity/DTO/ActivityDto.cs b/Wonky.Entity/DTO/ActivityDto.cs index f09a73b6..b0923518 100644 --- a/Wonky.Entity/DTO/ActivityDto.cs +++ b/Wonky.Entity/DTO/ActivityDto.cs @@ -36,7 +36,6 @@ namespace Wonky.Entity.DTO [Required(ErrorMessage = "Vælg aktivitetstype")] public string ActivityTypeEnum { get; set; } = ""; [Required(ErrorMessage = "Vælg status for besøg ")] public string ActivityStatusEnum { get; set; } = ""; public string VisitTypeEnum { get; set; } = "recall"; - public bool CheckDate { get; set; } [Required] public string ActivityDate { get; set; } = ""; [MaxLength(50, ErrorMessage = "Du kan højst bruge 50 tegn")] public string Demo { get; set; } = ""; [MaxLength(20, ErrorMessage = "Du kan højst bruge 20 tegn")] public string OurRef { get; set; } = "";