mirror of
https://github.com/Sea-Haven-Industries/shoc-backend.git
synced 2026-09-30 17:43:12 +00:00
- Replace all Contacts.Name with (FirstName + " " + LastName) pattern - Fix ContactService, Index.razor, QuotesPDF, QuotesDetails, CreateQuotes - Fix WorkOrderPDF, Viewworkorder, UserViewWordOrder, Addworkorders - Fix ViewTemplate, AddTemplate, Templates settings pages - Blazor project now builds successfully
404 lines
No EOL
14 KiB
Text
404 lines
No EOL
14 KiB
Text
@page "/addtemplate/{id:int}"
|
|
<style>
|
|
select:disabled {
|
|
color: #babcc2 !important;
|
|
}
|
|
</style>
|
|
@if (step == 0)
|
|
{
|
|
//Template list
|
|
<div class="row">
|
|
<div class="col-12">
|
|
<div class="card cardbg">
|
|
<!-- Card header -->
|
|
<div class="card-header pb-0 px-1 cardbg">
|
|
<div class="d-lg-flex">
|
|
<div>
|
|
<h5 class="mb-0">Work Order Templates</h5>
|
|
|
|
</div>
|
|
<div class="ms-auto my-auto mt-lg-0 mt-4">
|
|
<div class="ms-auto my-auto">
|
|
<a href="javascript:;" @onclick="() => Changestep(1)" class="btn bg-gradient-info btn-sm mb-0 text-capitalize"> New Template</a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="card-body px-0 pb-0">
|
|
<div class="table-responsive">
|
|
<table class="table table-flush" id="products-list">
|
|
<thead class="thead-light">
|
|
<tr>
|
|
<th class="p-0">Template Name</th>
|
|
<th class="text-end p-0 pe-4">Action</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
@if (templates != null)
|
|
{
|
|
foreach (var itm in templates)
|
|
{
|
|
<tr>
|
|
<td>
|
|
@* <div class="d-flex">
|
|
<div class="form-check my-auto ps-0">
|
|
<input class="form-check-input" type="checkbox" id="customCheck1">
|
|
</div>
|
|
</div> *@
|
|
<p class="mb-0 my-auto">@itm.WorkerOrderTitle</p>
|
|
</td>
|
|
|
|
<td class="text-end text-sm">
|
|
<a href="javascript:;" class="mb-0 btn btn-sm btn-info" @onclick="()=> View(itm.Id)">
|
|
<i class="material-icons position-relative text-lg">visibility</i>
|
|
</a>
|
|
<a href="javascript:;" class="mb-0 btn btn-sm btn-success" @onclick="()=> Edit(itm.Id)">
|
|
<i class="material-icons position-relative text-lg">drive_file_rename_outline</i>
|
|
</a>
|
|
<a href="javascript:;" class="mb-0 btn btn-sm btn-danger" @onclick="()=> Delete(itm.Id)">
|
|
<i class="material-icons position-relative text-lg">delete</i>
|
|
</a>
|
|
</td>
|
|
</tr>
|
|
}
|
|
}
|
|
else
|
|
{
|
|
<tr>
|
|
<td colspan="2">
|
|
<div class="loading">Loading…</div>
|
|
|
|
</td>
|
|
</tr>
|
|
}
|
|
</tbody>
|
|
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
}
|
|
else if (step == 1)
|
|
{
|
|
|
|
@if (model.Id == 0)
|
|
{
|
|
<h6 > <a href="javascript:;" @onclick="() => Changestep(0)" class="me-3"><i class="material-icons">reply</i></a>New Work Order Template</h6>
|
|
}
|
|
else
|
|
{
|
|
<h6><a href="javascript:;" @onclick="() => Changestep(0)" class="me-3"><i class="material-icons">reply</i></a> Edit Template</h6>
|
|
}
|
|
<AddTemplate id="@eid"></AddTemplate>
|
|
}
|
|
else if (step == 2)
|
|
{
|
|
|
|
@if (model.Id == 0)
|
|
{
|
|
<h6><a href="javascript:;" @onclick="() => Changestep(0)" class="me-3"><i class="material-icons">reply</i></a>Template Details</h6>
|
|
}
|
|
else
|
|
{
|
|
<h6 ><a href="javascript:;" @onclick="() => Changestep(0)" class="me-3"><i class="material-icons">reply</i></a>Template Details</h6>
|
|
}
|
|
<ViewTemplate id="@eid"></ViewTemplate>
|
|
}
|
|
@using SeaHavenIndustries.Components.Layout
|
|
@using SeaHavenIndustries.Data.IRepository;
|
|
@inject ISettingsRepository _service;
|
|
@inject IWorkOrderRepository _serviceworkorder;
|
|
@using Microsoft.JSInterop
|
|
@using SeaHavenIndustries.ViewModel
|
|
@using System.Text.Json
|
|
@using global::Data.SeaHavenIndustries
|
|
@inject IJSRuntime JSRuntime
|
|
@inject NavigationManager Navigation
|
|
@code {
|
|
private bool isLoading = true;
|
|
|
|
private int step = 0;
|
|
private ModalDialog? ModalDialog { get; set; }
|
|
[Parameter]
|
|
public int? id { get; set; }
|
|
private WorkOrder model = new();
|
|
private List<WorkOrder>? templates { get; set; }
|
|
private IEnumerable<ApplicationUser>? users { get; set; }
|
|
private IEnumerable<ApplicationUser>? userslist { get; set; }
|
|
private IEnumerable<Category>? category { get; set; }
|
|
private IEnumerable<Category>? categorylist { get; set; }
|
|
private IEnumerable<Locations>? locations { get; set; }
|
|
private IEnumerable<Locations>? locationslist { get; set; }
|
|
private IEnumerable<Contacts>? contacts { get; set; }
|
|
private IEnumerable<Contacts>? contactslist { get; set; }
|
|
private List<FileUploadViewModel> files = new List<FileUploadViewModel>();
|
|
|
|
List<int>? workordercontacts = new List<int>();
|
|
List<int>? workordercategories = new List<int>();
|
|
protected override async Task OnParametersSetAsync()
|
|
{
|
|
var result = await _service.GetTemplates();
|
|
if (result != null)
|
|
{
|
|
templates = result;
|
|
}
|
|
}
|
|
|
|
protected void LoadcontactData(LoadDataArgs args)
|
|
{
|
|
|
|
var query = contactslist;
|
|
if (!string.IsNullOrEmpty(args.Filter))
|
|
{
|
|
query = query.Where(c => (c.FirstName + " " + c.LastName).ToLower().Contains(args.Filter.ToLower()));
|
|
}
|
|
if (query != null)
|
|
{
|
|
contacts = query.ToList();
|
|
}
|
|
InvokeAsync(StateHasChanged);
|
|
}
|
|
|
|
protected void LoadUserData(LoadDataArgs args)
|
|
{
|
|
var query = userslist;
|
|
|
|
if (!string.IsNullOrEmpty(args.Filter))
|
|
{
|
|
query = query.Where(c => c.FirstName.ToLower().Contains(args.Filter.ToLower())).ToList();
|
|
}
|
|
if (query != null)
|
|
{
|
|
users = query.ToList();
|
|
}
|
|
InvokeAsync(StateHasChanged);
|
|
}
|
|
protected void LoadLocationData(LoadDataArgs args)
|
|
{
|
|
var query = locationslist;
|
|
if (!string.IsNullOrEmpty(args.Filter))
|
|
{
|
|
query = query.Where(c => c.Name.ToLower().Contains(args.Filter.ToLower()));
|
|
}
|
|
if (query != null)
|
|
{
|
|
locations = query.ToList();
|
|
}
|
|
InvokeAsync(StateHasChanged);
|
|
}
|
|
protected void LoadcategoryData(LoadDataArgs args)
|
|
{
|
|
|
|
var query = categorylist;
|
|
|
|
if (!string.IsNullOrEmpty(args.Filter))
|
|
{
|
|
query = query.Where(c => c.Name.ToLower().Contains(args.Filter.ToLower()));
|
|
}
|
|
if (query != null)
|
|
{
|
|
category = query.ToList();
|
|
}
|
|
InvokeAsync(StateHasChanged);
|
|
}
|
|
private string signaturePreview = string.Empty;
|
|
private string signatureData = string.Empty;
|
|
private IJSObjectReference signaturePad;
|
|
|
|
protected async Task SaveSignature()
|
|
{
|
|
signatureData = await signaturePad.InvokeAsync<string>("toDataURL");
|
|
UpdateSignaturePreview();
|
|
}
|
|
private void UpdateSignaturePreview()
|
|
{
|
|
var base64Index = signatureData.IndexOf("base64,", StringComparison.OrdinalIgnoreCase);
|
|
|
|
if (base64Index != -1)
|
|
{
|
|
// Skip "base64," to get the actual base64-encoded string
|
|
var base64String = signatureData.Substring(base64Index + 7);
|
|
signaturePreview = $"data:image/png;base64,{base64String}";
|
|
}
|
|
else
|
|
{
|
|
Console.WriteLine("Invalid signatureData format");
|
|
}
|
|
}
|
|
[JSInvokable]
|
|
public static Task UpdateSignatureData(string signatureData)
|
|
{
|
|
return Task.CompletedTask;
|
|
}
|
|
protected async Task SaveData()
|
|
{
|
|
try
|
|
{
|
|
model.SignOffSignature = await signaturePad.InvokeAsync<string>("toDataURL");
|
|
}
|
|
catch
|
|
{
|
|
|
|
}
|
|
model.istemplate = true;
|
|
model.WorkOrderContacts = null;
|
|
model.WorkOrderContacts = model.WorkOrderContacts == null ? new List<WorkOrderContacts>() : model.WorkOrderContacts;
|
|
foreach (var itm in workordercontacts)
|
|
{
|
|
model.WorkOrderContacts.Add(new WorkOrderContacts { ContactId = itm });
|
|
}
|
|
model.WorkOrderCategories = null;
|
|
model.WorkOrderCategories = model.WorkOrderCategories == null ? new List<WorkOrderCategories>() : model.WorkOrderCategories;
|
|
foreach (var itm in workordercategories)
|
|
{
|
|
model.WorkOrderCategories.Add(new WorkOrderCategories { CategoryId = itm });
|
|
}
|
|
var res = await _serviceworkorder.Addworkorder(model, files);
|
|
if (res == "success")
|
|
{
|
|
await ShowSweetAlert("Sucessfully Saved Data", "success");
|
|
var result = await _service.GetTemplates();
|
|
if (result != null)
|
|
{
|
|
templates = result;
|
|
step = 0;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
await ShowSweetAlert(res, "error");
|
|
}
|
|
}
|
|
private int eid = 0;
|
|
protected async Task Edit(int id)
|
|
{
|
|
if (id != 0)
|
|
{
|
|
eid = id;
|
|
step = 1;
|
|
}
|
|
await InvokeAsync(StateHasChanged);
|
|
}
|
|
protected async Task View(int id)
|
|
{
|
|
if (id != 0)
|
|
{
|
|
eid = id;
|
|
step = 2;
|
|
}
|
|
await InvokeAsync(StateHasChanged);
|
|
}
|
|
protected async void OpenPopup()
|
|
{
|
|
ModalDialog.Open();
|
|
await JSRuntime.InvokeVoidAsync("initializedsignature1");
|
|
var canvasElement = await JSRuntime.InvokeAsync<IJSObjectReference>("document.querySelector", "#signatureCanvas1");
|
|
await canvasElement.InvokeVoidAsync("setAttribute", "data-signature-pad", "new SignaturePad()");
|
|
signaturePad = canvasElement;
|
|
await signaturePad.InvokeVoidAsync("addEventListener", "change", DotNetObjectReference.Create(this));
|
|
}
|
|
protected void ClosePopup()
|
|
{
|
|
ModalDialog.Close();
|
|
}
|
|
|
|
private async Task HandleFileUpload(InputFileChangeEventArgs e)
|
|
{
|
|
var imageFile = e.File;
|
|
files.Add(new FileUploadViewModel { file = imageFile, Name = "attachment1" });
|
|
}
|
|
private async Task HandleFileUpload1(InputFileChangeEventArgs e)
|
|
{
|
|
var imageFile = e.File;
|
|
files.Add(new FileUploadViewModel { file = imageFile, Name = "attachment2" });
|
|
}
|
|
private async Task HandleFileUpload2(InputFileChangeEventArgs e)
|
|
{
|
|
var imageFile = e.File;
|
|
files.Add(new FileUploadViewModel { file = imageFile, Name = "attachment3" });
|
|
}
|
|
private async Task HandleFileUpload3(InputFileChangeEventArgs e)
|
|
{
|
|
var imageFile = e.File;
|
|
files.Add(new FileUploadViewModel { file = imageFile, Name = "attachment4" });
|
|
}
|
|
|
|
private async Task ShowSweetAlert(string title, string icon)
|
|
{
|
|
// Display a SweetAlert dialog
|
|
await JSRuntime.InvokeVoidAsync("Swal.fire", new
|
|
{
|
|
toast = true,
|
|
showConfirmButton = false,
|
|
timer = 3000,
|
|
title = title,
|
|
icon = icon,
|
|
position = "top-end"
|
|
});
|
|
await JSRuntime.InvokeVoidAsync("closemodal");
|
|
}
|
|
private async Task Delete(int val)
|
|
{
|
|
var result = await JSRuntime.InvokeAsync<JsonElement>("Swal.fire", new
|
|
{
|
|
html = "<div style='text-align: center;'><img src='./assets/img/delete icon.png' style='width: 100px;' /></div>" +
|
|
"<h4>Are you sure you want to delete</h4>" +
|
|
"<p style='font-size: 18px;'>\"Nicolas Alvarado\"</p>",
|
|
type = "warning",
|
|
showCancelButton = true,
|
|
customClass = new
|
|
{
|
|
confirmButton = "btn btn-success m-1",
|
|
cancelButton = "btn btn-danger m-1"
|
|
},
|
|
buttonsStyling = false,
|
|
confirmButtonText = "Yes",
|
|
cancelButtonText = "No"
|
|
});
|
|
|
|
if (result.TryGetProperty("isConfirmed", out var isConfirmedProperty) && isConfirmedProperty.GetBoolean())
|
|
{
|
|
// Call your delete API here
|
|
var response = await _service.DeleteTemplate(val);
|
|
if (response == "success")
|
|
{
|
|
await JSRuntime.InvokeVoidAsync("Swal.fire", new
|
|
{
|
|
icon = "success",
|
|
title = "Deleted!",
|
|
text = "Data has been deleted.",
|
|
type = "info",
|
|
showCancelButton = false,
|
|
customClass = new
|
|
{
|
|
confirmButton = "btn btn-success",
|
|
cancelButton = "btn btn-danger"
|
|
},
|
|
buttonsStyling = false,
|
|
confirmButtonText = "Ok"
|
|
});
|
|
templates = await _service.GetTemplates();
|
|
// await JSRuntime.InvokeVoidAsync("location.reload");
|
|
}
|
|
else
|
|
{
|
|
await JSRuntime.InvokeVoidAsync("Swal.fire", new
|
|
{
|
|
title = "Not Deleted!",
|
|
text = "Unsuccessful! Cannot delete this.",
|
|
type = "danger"
|
|
});
|
|
}
|
|
}
|
|
}
|
|
private void Changestep(int val)
|
|
{
|
|
step = val;
|
|
if (val == 1)
|
|
{
|
|
model = new WorkOrder();
|
|
}
|
|
}
|
|
} |