Вытащил солюшен на уровень выше, чтобы прощё было дотнетить
	
		
			
	
		
	
	
		
	
		
			Some checks failed
		
		
	
	
		
			
				
	
				continuous-integration/drone/push Build is failing
				
			
		
		
	
	
				
					
				
			
		
			Some checks failed
		
		
	
	continuous-integration/drone/push Build is failing
				
			This commit is contained in:
		
							
								
								
									
										143
									
								
								BlazorWebAssemblyVisaApiClient/Pages/Applications.razor
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										143
									
								
								BlazorWebAssemblyVisaApiClient/Pages/Applications.razor
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,143 @@ | ||||
| @page "/applications" | ||||
| @using BlazorWebAssemblyVisaApiClient.Common.Exceptions | ||||
| @using BlazorWebAssemblyVisaApiClient.Infrastructure.Helpers | ||||
| @using BlazorWebAssemblyVisaApiClient.Infrastructure.Services.UserDataProvider | ||||
| @using BlazorWebAssemblyVisaApiClient.Validation.VisaApplications.Models | ||||
| @using VisaApiClient | ||||
| @inherits BlazorWebAssemblyVisaApiClient.Components.Base.VisaClientComponentBase | ||||
|  | ||||
| <PageTitle>Applications</PageTitle> | ||||
|  | ||||
| <table class="table table-bordered table-hover"> | ||||
|     <thead> | ||||
|     <tr> | ||||
|         <th>Destination Country</th> | ||||
|         <th>Visa Category</th> | ||||
|         <th>Request date</th> | ||||
|         <th>Days requested</th> | ||||
|         <th>Status</th> | ||||
|         <th></th> | ||||
|     </tr> | ||||
|     </thead> | ||||
|  | ||||
|     <tbody> | ||||
|     @foreach (var application in applications) | ||||
|     { | ||||
|         var rowClass = application.Status switch | ||||
|         { | ||||
|             ApplicationStatus.Pending => "", | ||||
|             ApplicationStatus.Approved => "table-success", | ||||
|             ApplicationStatus.Rejected => "table-danger", | ||||
|             ApplicationStatus.Closed => "table-danger", | ||||
|             _ => throw new ArgumentOutOfRangeException() | ||||
|         }; | ||||
|  | ||||
|         <tr class="@rowClass"> | ||||
|             <td>@application.DestinationCountry</td> | ||||
|             <td>@(((VisaCategoryModel)application.VisaCategory).GetDisplayName())</td> | ||||
|             <td>@application.RequestDate.ToString("d")</td> | ||||
|             <td>@application.ValidDaysRequested</td> | ||||
|             <td>@application.Status.GetDisplayName()</td> | ||||
|             <td> | ||||
|                 <NavLink href="@($"/applications/{application.Id}")"> | ||||
|                     <button class="btn-primary">See</button> | ||||
|                 </NavLink> | ||||
|                 @if (currentRole == Constants.ApplicantRole) | ||||
|                 { | ||||
|                     <span> | </span> | ||||
|                     <input type="button" class="btn-outline-primary" @onclick="() => DownloadApplication(application)" value="Download"/> | ||||
|                     if (application.Status is ApplicationStatus.Pending) | ||||
|                     { | ||||
|                         <span> | </span> | ||||
|                         <input type="button" class="border-danger" @onclick="() => CloseApplication(application)" value="Close"/> | ||||
|                     } | ||||
|                 } | ||||
|             </td> | ||||
|         </tr> | ||||
|     } | ||||
|     </tbody> | ||||
| </table > | ||||
|  | ||||
| <script> | ||||
|     window.downloadFileFromStream = async (contentStreamReference) => { | ||||
|         const arrayBuffer = await contentStreamReference.arrayBuffer(); | ||||
|         const blob = new Blob([arrayBuffer]); | ||||
|         const url = URL.createObjectURL(blob); | ||||
|         const anchorElement = document.createElement('a'); | ||||
|         anchorElement.href = url; | ||||
|         anchorElement.download = 'Application.xlsx'; | ||||
|         anchorElement.click(); | ||||
|         anchorElement.remove(); | ||||
|         URL.revokeObjectURL(url); | ||||
|     } | ||||
| </script> | ||||
|  | ||||
| @code { | ||||
|     private string currentRole = null!; | ||||
|     private List<VisaApplicationPreview> applications = []; | ||||
|  | ||||
|     [Inject] private IUserDataProvider UserDataProvider { get; set; } = null!; | ||||
|  | ||||
|     [Inject] private IJSRuntime JavaScriptInterop { get; set; } = null!; | ||||
|  | ||||
|     protected override async Task OnInitializedAsync() | ||||
|     { | ||||
|         try | ||||
|         { | ||||
|             currentRole = UserDataProvider.CurrentRole ?? throw new NotLoggedInException(); | ||||
|         } | ||||
|         catch (Exception e) | ||||
|         { | ||||
|             ErrorHandler.Handle(e); | ||||
|         } | ||||
|  | ||||
|         await Fetch(); | ||||
|     } | ||||
|  | ||||
|     private async Task Fetch() | ||||
|     { | ||||
|         try | ||||
|         { | ||||
|             applications = currentRole switch | ||||
|             { | ||||
|                 Constants.ApplicantRole => (await Client.GetApplicationsForApplicantAsync()).OrderByDescending(a => a.RequestDate).ToList(), | ||||
|                 Constants.ApprovingAuthorityRole => (await Client.GetPendingAsync()).OrderByDescending(a => a.RequestDate).ToList(), | ||||
|                 _ => throw new NotLoggedInException() | ||||
|             }; | ||||
|         } | ||||
|         catch (Exception e) | ||||
|         { | ||||
|             ErrorHandler.Handle(e); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private async Task CloseApplication(VisaApplicationPreview application) | ||||
|     { | ||||
|         try | ||||
|         { | ||||
|             await Client.CloseApplicationAsync(application.Id); | ||||
|             application.Status = ApplicationStatus.Closed; | ||||
|             StateHasChanged(); | ||||
|         } | ||||
|         catch (Exception e) | ||||
|         { | ||||
|             ErrorHandler.Handle(e); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private async Task DownloadApplication(VisaApplicationPreview application) | ||||
|     { | ||||
|         try | ||||
|         { | ||||
|             var response = await Client.DownloadApplicationForApplicantAsync(application.Id); | ||||
|             using var streamRef = new DotNetStreamReference(stream: response.Stream); | ||||
|  | ||||
|             await JavaScriptInterop.InvokeVoidAsync("downloadFileFromStream", streamRef); | ||||
|         } | ||||
|         catch (Exception e) | ||||
|         { | ||||
|             ErrorHandler.Handle(e); | ||||
|         } | ||||
|     } | ||||
|  | ||||
| } | ||||
		Reference in New Issue
	
	Block a user