wip - admin tasks

This commit is contained in:
Frede Hundewadt 2022-06-27 08:48:25 +02:00
parent e42c4ffe0d
commit 0d7202cdb7
18 changed files with 316 additions and 96 deletions

View file

@ -0,0 +1,73 @@
@if (ReportList.Any())
{
<div class="list-group list-group-flush">
<div class="list-group-item px-3 bg-black text-white opacity-75">
<div class="row">
<div class="fw-bold col">
Dato
</div>
<div class="fw-bold col">
Dag
</div>
<div class="fw-bold col">
Start
</div>
<div class="fw-bold col">
Slut
</div>
<div class="fw-bold col text-end">
Resultat
</div>
</div>
</div>
@foreach (var report in ReportList)
{
<a class="list-group-item list-group-item-action" href="/admin/users/@ErpUserId/reports/@report.ReportDate">
<div class="row">
<div class="col">
@report.ReportDate
</div>
<div class="col">
@{
switch (report.DayTypeEnum)
{
case "Sales":
<span>Salgsdag</span>
break;
case "SickLeave":
<span>Sygdom</span>
break;
case "Office":
<span>Kontordag</span>
break;
case "Meeting":
<span>Salgsmøde</span>
break;
case "Leave":
<span>Ferie</span>
break;
}
}
</div>
<div class="col">
@(report.DayTypeEnum == "Sales" ? report.FromDateTime.Split(" ")[1] : report.FromDateTime.Split(" ")[0])
</div>
<div class="col">
@(report.DayTypeEnum == "Sales" ? report.ToDateTime.Split(" ")[1] : report.ToDateTime.Split(" ")[0])
</div>
<div class="col text-end">
@report.Turnover
</div>
</div>
</a>
}
</div>
}
else
{
<div class="row">
<div class="col">
Ingen data
</div>
</div>
}

View file

@ -0,0 +1,10 @@
using Microsoft.AspNetCore.Components;
using Wonky.Entity.Views;
namespace Wonky.Client.Components;
public partial class AdminReportTableComponent
{
[Parameter] public List<NgSalesReportListView> ReportList { get; set; } = new();
[Parameter] public string ErpUserId { get; set; } = "";
}

View file

@ -0,0 +1,64 @@
@*
// Copyright (C) 2022 FCS Frede's Computer Services.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see [https://www.gnu.org/licenses/agpl-3.0.en.html]
//
*@
@if (UserList.Any())
{
<table class="table table-striped">
<thead>
<tr>
<th scope="col">
Land
</th>
<th scope="col">
Nr.
</th>
<th scope="col">
Navn
</th>
<th scope="col">
Telefon
</th>
<th scope="col">
Email
</th>
<th scope="col">
</th>
<th scope="col">
</th>
</tr>
</thead>
<tbody>
@foreach (var user in UserList)
{
<tr class="align-middle">
<td class="align-content-center">@user.CountryCode</td>
<td>@user.SalesRep</td>
<td><a href="/admin/users/@user.UserId">@user.FullName</a></td>
<td>@user.PhoneNumber</td>
<td>@user.Email</td>
<td><a class="btn btn-info" href="/admin/users/advisers/@user.UserId/reports">Salg</a></td>
</tr>
}
</tbody>
</table>
}
else
{
<AppSpinner/>
}

View file

@ -4,7 +4,7 @@ using Wonky.Entity.Views;
namespace Wonky.Client.Components;
public partial class UserTableComponent
public partial class AdviserTableComponent
{
[Parameter] public List<AdminAdviserListView> UserList { get; set; }
}

View file

@ -50,10 +50,10 @@
}
</div>
<div class="col">
@report.FromDateTime
@(report.DayTypeEnum == "Sales" ? report.FromDateTime.Split(" ")[1] : report.FromDateTime.Split(" ")[0])
</div>
<div class="col">
@report.ToDateTime
@(report.DayTypeEnum == "Sales" ? report.ToDateTime.Split(" ")[1] : report.ToDateTime.Split(" ")[0])
</div>
<div class="col text-end">
@report.Turnover

View file

@ -1,67 +0,0 @@
@*
// Copyright (C) 2022 FCS Frede's Computer Services.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see [https://www.gnu.org/licenses/agpl-3.0.en.html]
//
*@
@if (UserList.Any())
{
<div class="list-group">
<div class="list-group-item bg-dark bg-opacity-75 text-white">
<div class="row">
<div class="col-sm-1">
Land
</div>
<div class="col-sm-1">
Nr.
</div>
<div class="col">
Navn
</div>
<div class="col">
Telefonnr.
</div>
<div class="col">
Email
</div>
</div>
</div>
@foreach (var user in UserList)
{
<a class="list-group-item list-group-item-action" href="/admin/users/@user.UserId">
<div class="row">
<div class="col-sm-1">
@user.CountryCode
</div>
<div class="col-sm-1">
@user.SalesRep
</div>
<div class="col">
@user.FullName
</div>
<div class="col">
@user.PhoneNumber
</div>
<div class="col">
@user.Email
</div>
</div>
</a>
}
</div>
}
else
{
<AppSpinner/>
}

View file

@ -0,0 +1,43 @@
using System.Net.Http.Json;
using System.Text.Json;
using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.Options;
using Wonky.Entity.Configuration;
using Wonky.Entity.DTO;
using Wonky.Entity.Views;
namespace Wonky.Client.HttpRepository;
public class AdminReportHttpRepository : IAdminReportHttpRepository
{
private readonly JsonSerializerOptions _options = new JsonSerializerOptions
{
PropertyNameCaseInsensitive = true
};
private readonly NavigationManager _navigation;
private ILogger<AdminReportHttpRepository> _logger;
private readonly HttpClient _client;
private readonly ApiConfig _apiConfig;
public AdminReportHttpRepository(HttpClient client,
ILogger<AdminReportHttpRepository> logger,
NavigationManager navigation, IOptions<ApiConfig> configuration)
{
_client = client;
_logger = logger;
_navigation = navigation;
_apiConfig = configuration.Value;
}
public async Task<List<NgSalesReportListView>> GetReports(string userId)
{
return await _client.GetFromJsonAsync<List<NgSalesReportListView>>($"{_apiConfig.AdminAdviserUri}/{userId}/reports");
}
public async Task<NgSalesReportView> GetReport(string userId, string workDate)
{
return await _client.GetFromJsonAsync<NgSalesReportView>($"{_apiConfig.AdminAdviserUri}/{userId}/reports/{workDate}");
}
}

View file

@ -0,0 +1,11 @@
using Wonky.Client.Pages;
using Wonky.Entity.DTO;
using Wonky.Entity.Views;
namespace Wonky.Client.HttpRepository;
public interface IAdminReportHttpRepository
{
Task<List<NgSalesReportListView>> GetReports(string userId);
Task<NgSalesReportView> GetReport(string userId, string workDate);
}

View file

@ -16,12 +16,12 @@ public class ReportHttpRepository :IReportHttpRepository
};
private readonly NavigationManager _navigation;
private ILogger<SalesItemHttpRepository> _logger;
private ILogger<ReportHttpRepository> _logger;
private readonly HttpClient _client;
private readonly ApiConfig _apiConfig;
public ReportHttpRepository(HttpClient client,
ILogger<SalesItemHttpRepository> logger,
ILogger<ReportHttpRepository> logger,
NavigationManager navigation, IOptions<ApiConfig> configuration)
{
_client = client;

View file

@ -1,4 +1,6 @@
@using Wonky.Client.Components
@using Microsoft.AspNetCore.Authorization
@attribute [Authorize(Roles = "Admin")]
@page "/admin/users"
<div class="card">
@ -6,6 +8,6 @@
<h3>Sælgere</h3>
</div>
<div class="card-body">
<UserTableComponent UserList="_salesReps"></UserTableComponent>
<AdviserTableComponent UserList="_salesReps"></AdviserTableComponent>
</div>
</div>

View file

@ -5,7 +5,7 @@ using Wonky.Entity.DTO;
namespace Wonky.Client.Pages;
public partial class AdminUserList : IDisposable
public partial class AdminAdviserUserList : IDisposable
{
[Inject] private HttpInterceptorService _interceptor { get; set; }
[Inject] private IUserHttpRepository _userRepo { get; set; }

View file

@ -1,4 +1,6 @@
@page "/admin/users/{UserId}"
@using Microsoft.AspNetCore.Authorization
@attribute [Authorize(Roles = "Admin")]
<div class="card">
<div class="card-header">
<h3>Sælger info</h3>
@ -72,11 +74,14 @@
</div>
</div>
<div class="row">
<div class="col">
<button type="submit" class="btn btn-primary">Gem</button>
</div>
<div class="col">
<a class="btn btn-primary" href="/admin/users">Tilbage</a>
</div>
<div class="col">
<button type="submit" class="btn btn-primary">Gem</button>
<a class="btn btn-primary" href="/admin/users/advisers/@UserId/reports">Salg</a>
</div>
</div>
</EditForm>

View file

@ -8,12 +8,12 @@ using Wonky.Entity.DTO;
namespace Wonky.Client.Pages;
public partial class AdminUserView : IDisposable
public partial class AdminAdviserView : IDisposable
{
[Parameter] public string UserId { get; set; } = "";
[Inject] private HttpInterceptorService _interceptor { get; set; }
[Inject] private IUserHttpRepository _userRepo { get; set; }
[Inject] private ILogger<AdminUserView> _logger { get; set; }
[Inject] private ILogger<AdminAdviserView> _logger { get; set; }
[Inject] private NavigationManager _navigator { get; set; }
[Inject] private IToastService _toast { get; set; }
private AdviserInfoView _adviserInfo { get; set; } = new();

View file

@ -15,7 +15,9 @@
//
*@
@using Wonky.Client.Components
@page "/sales-reports"
@using Microsoft.AspNetCore.Authorization
@attribute [Authorize(Roles = "Admin")]
@page "/admin/users/advisers/{UserId}/reports"
<div class="card">
<div class="card-header">
<div class="row">

View file

@ -0,0 +1,41 @@
@*
// Copyright (C) 2022 FCS Frede's Computer Services.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see [https://www.gnu.org/licenses/agpl-3.0.en.html]
//
*@
@using Wonky.Client.Components
@using Microsoft.AspNetCore.Authorization
@page "/admin/users/advisers/{UserId}/reports/{ReportDate}"
@attribute [Authorize(Roles = "Admin")]
<div class="card">
<div class="card-header">
<div class="row">
<div class="col">
@if (!string.IsNullOrWhiteSpace(ReportDate))
{
<h3 class="workDate">@DateTime.Parse(ReportDate).ToLongDateString()</h3>
}
</div>
<div class="col">
<WorkDateComponent OnChanged="GetReport"></WorkDateComponent>
</div>
</div>
</div>
<div class="card-body">
<ReportSummaryComponent Report="_report.Report"></ReportSummaryComponent>
<ActivityTableComponent Activities="_report.Activities"></ActivityTableComponent>
</div>
</div>

View file

@ -0,0 +1,34 @@
using Microsoft.AspNetCore.Components;
using Wonky.Client.HttpRepository;
using Wonky.Entity.DTO;
using Wonky.Entity.Views;
namespace Wonky.Client.Pages;
public partial class AdminSalesReportView
{
[Parameter] public string ReportDate { get; set; }
[Parameter] public string UserId { get; set; }
[Inject] private IAdminReportHttpRepository _reportRepo { get; set; }
private NgSalesReportView _report { get; set; } = new();
protected override async Task OnInitializedAsync()
{
if (!string.IsNullOrWhiteSpace(ReportDate))
{
await GetReport(ReportDate);
}
}
private async Task GetReport(string workDate)
{
ReportDate = workDate;
_report = new NgSalesReportView();
_report = await GetUserReport(UserId, workDate);
}
private async Task<NgSalesReportView> GetUserReport(string userId, string workDate)
{
return _report = await _reportRepo.GetReport(userId, workDate);
}
}

View file

@ -33,7 +33,8 @@ builder.RootComponents.Add<HeadOutlet>("head::after");
builder.Logging.AddConfiguration(builder.Configuration.GetSection("Logging"));
builder.Services.AddScoped(sp => sp.GetService<IHttpClientFactory>().CreateClient("InnoAPI"));
builder.Services.AddScoped(sp =>
sp.GetService<IHttpClientFactory>().CreateClient("InnoAPI"));
builder.Services.AddHttpClient("InnoAPI", (sp, cl) =>
{
@ -55,6 +56,7 @@ builder.Services.AddScoped<IReportHttpRepository, ReportHttpRepository>();
builder.Services.AddScoped<ITaskItemHttpRepository, TaskItemHttpRepository>();
builder.Services.AddScoped<IHistoryHttpRepository, HistoryHttpRepository>();
builder.Services.AddScoped<IUserHttpRepository, UserHttpRepository>();
builder.Services.AddScoped<IAdminReportHttpRepository, AdminReportHttpRepository>();
builder.Services.AddScoped<HttpInterceptorService>();
builder.Services.AddBlazoredLocalStorage();

View file

@ -1,21 +1,4 @@
{
"Logging": {
"LogLevel": {
"Default": "Debug",
"System": "Debug",
"Microsoft": "Information"
},
"Debug": {
"LogLevel": {
"Default": "Critical"
}
},
"ActivityHttpRepository": {
"LogLevel": {
"Default": "Error"
}
}
},
"appInfo": {
"name": "Wonky Client",
"version": "0.8.38",
@ -43,5 +26,22 @@
"adminPasswdUri": "api/v2/admin/users/passwd",
"adminReportUri": "reports",
"adminCompanyUri": "companies"
},
"Logging": {
"LogLevel": {
"Default": "Debug",
"System": "Debug",
"Microsoft": "Information"
},
"Debug": {
"LogLevel": {
"Default": "Critical"
}
},
"ActivityHttpRepository": {
"LogLevel": {
"Default": "Error"
}
}
}
}