|
| 1 | +@using TelegramDownloader.Models |
| 2 | +@using TelegramDownloader.Services |
| 3 | + |
| 4 | +<Modal @ref="Modal" title="Download Info" Size="ModalSize.ExtraLarge"> |
| 5 | + <BodyTemplate> |
| 6 | + @if (downloadModel != null) |
| 7 | + { |
| 8 | + <table class="table table-striped"> |
| 9 | + <tbody> |
| 10 | + <tr> |
| 11 | + <th scope="row"><i class="bi bi-file-earmark"></i> File Name</th> |
| 12 | + <td>@downloadModel.name</td> |
| 13 | + </tr> |
| 14 | + <tr> |
| 15 | + <th scope="row"><i class="bi bi-folder"></i> Path</th> |
| 16 | + <td>@downloadModel.path</td> |
| 17 | + </tr> |
| 18 | + <tr> |
| 19 | + <th scope="row"><i class="bi bi-chat"></i> Channel</th> |
| 20 | + <td>@downloadModel.channelName</td> |
| 21 | + </tr> |
| 22 | + <tr> |
| 23 | + <th scope="row"><i class="bi bi-hdd"></i> Size</th> |
| 24 | + <td>@downloadModel._sizeString</td> |
| 25 | + </tr> |
| 26 | + <tr> |
| 27 | + <th scope="row"><i class="bi bi-cloud-download"></i> Transmitted</th> |
| 28 | + <td>@downloadModel._transmittedString</td> |
| 29 | + </tr> |
| 30 | + <tr> |
| 31 | + <th scope="row"><i class="bi bi-flag"></i> State</th> |
| 32 | + <td> |
| 33 | + <span class="badge @GetStateBadgeClass(downloadModel.state)">@downloadModel.state</span> |
| 34 | + </td> |
| 35 | + </tr> |
| 36 | + <tr> |
| 37 | + <th scope="row"><i class="bi bi-calendar-plus"></i> Creation Date</th> |
| 38 | + <td>@downloadModel.creationDate.ToString("yyyy-MM-dd HH:mm:ss")</td> |
| 39 | + </tr> |
| 40 | + <tr> |
| 41 | + <th scope="row"><i class="bi bi-play-circle"></i> Start Date</th> |
| 42 | + <td>@(downloadModel.startDate != default ? downloadModel.startDate.ToString("yyyy-MM-dd HH:mm:ss") : "-")</td> |
| 43 | + </tr> |
| 44 | + <tr> |
| 45 | + <th scope="row"><i class="bi bi-stop-circle"></i> End Date</th> |
| 46 | + <td>@(downloadModel.endnDate != default && downloadModel.state == StateTask.Completed ? downloadModel.endnDate.ToString("yyyy-MM-dd HH:mm:ss") : "-")</td> |
| 47 | + </tr> |
| 48 | + <tr> |
| 49 | + <th scope="row"><i class="bi bi-stopwatch"></i> Duration</th> |
| 50 | + <td>@GetDuration()</td> |
| 51 | + </tr> |
| 52 | + <tr> |
| 53 | + <th scope="row"><i class="bi bi-speedometer2"></i> Average Speed</th> |
| 54 | + <td>@GetAverageSpeed()</td> |
| 55 | + </tr> |
| 56 | + </tbody> |
| 57 | + </table> |
| 58 | + } |
| 59 | + </BodyTemplate> |
| 60 | +</Modal> |
| 61 | + |
| 62 | +@code { |
| 63 | + [Parameter] |
| 64 | + public DownloadModel downloadModel { get; set; } |
| 65 | + private Modal Modal = default!; |
| 66 | + |
| 67 | + public async Task ShowModal(DownloadModel downloadModel) |
| 68 | + { |
| 69 | + this.downloadModel = downloadModel; |
| 70 | + if (this.downloadModel != null) |
| 71 | + { |
| 72 | + await Modal.ShowAsync(); |
| 73 | + } |
| 74 | + } |
| 75 | + |
| 76 | + private string GetDuration() |
| 77 | + { |
| 78 | + if (downloadModel.startDate == default) |
| 79 | + return "-"; |
| 80 | + |
| 81 | + DateTime endTime = downloadModel.state == StateTask.Completed && downloadModel.endnDate != default |
| 82 | + ? downloadModel.endnDate |
| 83 | + : DateTime.Now; |
| 84 | + |
| 85 | + TimeSpan duration = endTime - downloadModel.startDate; |
| 86 | + |
| 87 | + if (duration.TotalHours >= 1) |
| 88 | + return $"{(int)duration.TotalHours}h {duration.Minutes}m {duration.Seconds}s"; |
| 89 | + if (duration.TotalMinutes >= 1) |
| 90 | + return $"{duration.Minutes}m {duration.Seconds}s"; |
| 91 | + return $"{duration.Seconds}s"; |
| 92 | + } |
| 93 | + |
| 94 | + private string GetAverageSpeed() |
| 95 | + { |
| 96 | + if (downloadModel.startDate == default || downloadModel._transmitted == 0) |
| 97 | + return "-"; |
| 98 | + |
| 99 | + DateTime endTime = downloadModel.state == StateTask.Completed && downloadModel.endnDate != default |
| 100 | + ? downloadModel.endnDate |
| 101 | + : DateTime.Now; |
| 102 | + |
| 103 | + double seconds = (endTime - downloadModel.startDate).TotalSeconds; |
| 104 | + if (seconds <= 0) |
| 105 | + return "-"; |
| 106 | + |
| 107 | + double bytesPerSecond = downloadModel._transmitted / seconds; |
| 108 | + return $"{HelperService.SizeSuffix((long)bytesPerSecond)}/s"; |
| 109 | + } |
| 110 | + |
| 111 | + private string GetStateBadgeClass(StateTask state) |
| 112 | + { |
| 113 | + return state switch |
| 114 | + { |
| 115 | + StateTask.Completed => "bg-success", |
| 116 | + StateTask.Working => "bg-primary", |
| 117 | + StateTask.Error => "bg-danger", |
| 118 | + StateTask.Canceled => "bg-warning", |
| 119 | + StateTask.Pending => "bg-secondary", |
| 120 | + StateTask.Paused => "bg-info", |
| 121 | + _ => "bg-secondary" |
| 122 | + }; |
| 123 | + } |
| 124 | +} |
0 commit comments