PWA Fundvelo der Caritas.
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

CaritasServiceFundVeloHistoryPage.razor 6.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. @page "/fundvelo/{FromRoute}"
  2. @using cwebplusApp.Shared.Services;
  3. @using cwebplusApp.Shared.Models;
  4. @inject NavigationManager NavigationManager
  5. @inject PageHistoryManager PageHistoryManager
  6. @inject ReportDataProvider ReportDataProvider
  7. @inject ReportRepositoryService ReportRepositoryService
  8. @inject IStringLocalizer<Resources> i18n;
  9. @inject Toaster Toaster;
  10. @inject IMatDialogService MatDialogService;
  11. @inject ScrollLockRemover ScrollLockRemover;
  12. <div class="row px-3">
  13. <div class="row no-gutters align-items-start justify-content-center w-100" style="padding-top:1em">
  14. @if (FromRoute.Equals("history_found")) {
  15. <h2>@i18n["HistoryFound"]</h2>
  16. } else {
  17. <h2>@i18n["HistoryMissing"]</h2>
  18. }
  19. </div>
  20. <div class="row no-gutters align-items-start w-100">
  21. <MatTable RowClass="ReportRepositoryItem" Items="transmittedReports" class="mat-elevation-z5" ShowPaging="false" UseSortHeaderRow="true"
  22. AllowSelection="true">
  23. <MatTableHeader>
  24. <th>Id</th>
  25. <th>@i18n["Type"]</th>
  26. <th>@i18n["Date"]</th>
  27. @if (FromRoute.Equals("history_found")) {
  28. <th>@i18n["Address"]</th>
  29. }
  30. <th>@i18n["Picture"]</th>
  31. <th style="width:2400px">@i18n["Action"]</th>
  32. </MatTableHeader>
  33. <MatTableRow>
  34. <td>@context.ID</td>
  35. <td style="@getTypeBackgroundStyle(context.ReportType)">@translateType(context.ReportType)</td>
  36. <td style="white-space: nowrap">@ReportRepositoryService.GetCurrentDateTimeFromMillis(context.ID)</td>
  37. @if (FromRoute.Equals("history_found")) {
  38. <td style="white-space: nowrap">@getAddress(context)</td>
  39. }
  40. <td>
  41. <MatIconButton Disabled="@HasNoPicture(context)" Icon="photo" OnClick="@(_ => ShowPicture(context))"></MatIconButton>
  42. </td>
  43. <td>
  44. <MatIconButton Icon="delete_forever" OnClick="@(_ => DeleteReport(context))"></MatIconButton>
  45. </td>
  46. </MatTableRow>
  47. </MatTable>
  48. </div>
  49. <div class="row no-gutters justify-content-end w-100">
  50. <MatRipple class="inputfile-mat-ripple" Color="@MatRippleColor.Default" @onclick="DeleteAll" Style="background: lightgrey; width: 64px; height: 64px; border-radius: 32px; align-items: flex-end; justify-content: center; display: inline-flex;">
  51. <label>
  52. <svg xmlns="http://www.w3.org/2000/svg" height="48px" viewBox="0 0 24 24" width="48px" fill="#000000">
  53. <path d="M0 0h24v24H0V0z" fill="none" />
  54. <path d="M5 10h6v8H5z" opacity=".3" />
  55. <path d="M15 16h4v2h-4zm0-8h7v2h-7zm0 4h6v2h-6zM3 18c0 1.1.9 2 2 2h6c1.1 0 2-.9 2-2V8H3v10zm2-8h6v8H5v-8zm5-6H6L5 5H2v2h12V5h-3z" />
  56. </svg>
  57. </label>
  58. </MatRipple>
  59. </div>
  60. </div>
  61. @code {
  62. [Parameter]
  63. public string FromRoute { get; set; }
  64. private List<ReportRepositoryItem> transmittedReports = new();
  65. private ReportRepositoryItem selectedReport;
  66. protected override void OnInitialized() {
  67. base.OnInitialized();
  68. PageHistoryManager.AddPageToHistory(NavigationManager.Uri);
  69. StateHasChanged();
  70. }
  71. protected async override void OnParametersSet() {
  72. if (FromRoute.Equals("history_found")) {
  73. transmittedReports.AddRange(await ReportRepositoryService.GetTransmittedFoundReports());
  74. } else {
  75. transmittedReports.AddRange(await ReportRepositoryService.GetTransmittedMissingReports());
  76. }
  77. StateHasChanged();
  78. }
  79. private string translateType(ReportRepositoryItem.Type type) {
  80. return i18n.GetString("ReportType." + type);
  81. }
  82. private string getTypeBackgroundStyle(ReportRepositoryItem.Type type) {
  83. return ReportRepositoryItem.Type.FOUND.Equals(type) ? "background: linear-gradient(45deg, darkseagreen, transparent)" : "background: linear-gradient(45deg, darksalmon, transparent)";
  84. }
  85. private string getAddress(ReportRepositoryItem item) {
  86. if (ReportRepositoryItem.Type.FOUND.Equals(item.ReportType)) {
  87. GeographicInfo geoInfo = ((FoundReportRepositoryItem)item).Report.GeographicInfo;
  88. return geoInfo.Address + ", " + geoInfo.Postcode + " " + geoInfo.Town;
  89. }
  90. return "";
  91. }
  92. private async Task ShowPicture(ReportRepositoryItem item) {
  93. string picData = ReportRepositoryItem.Type.FOUND.Equals(item.ReportType) ? ((FoundReportRepositoryItem)item).Report.FotoString : ((MissingReportRepositoryItem)item).Report.FotoString;
  94. await MatDialogService.OpenAsync(typeof(PictureDialog), new MatDialogOptions() {
  95. Attributes = new Dictionary<string, object>(){
  96. {"ImgUrl", picData},
  97. }
  98. });
  99. await ScrollLockRemover.removeScrollLockAsync();
  100. }
  101. private bool HasNoPicture(ReportRepositoryItem item) {
  102. string picData = ReportRepositoryItem.Type.FOUND.Equals(item.ReportType) ? ((FoundReportRepositoryItem)item).Report.FotoString : ((MissingReportRepositoryItem)item).Report.FotoString;
  103. return String.IsNullOrEmpty(picData);
  104. }
  105. private async void DeleteReport(ReportRepositoryItem item, bool ask = true) {
  106. string yes = i18n.GetString("Yes");
  107. string no = i18n.GetString("No");
  108. string result = ask ? await MatDialogService.AskAsync(i18n.GetString("Pending." + item.ReportType + ".Delete"), new string[] { yes, no }) : yes;
  109. await ScrollLockRemover.removeScrollLockAsync();
  110. if (result.Equals(yes)) {
  111. try {
  112. await ReportRepositoryService.DeleteReport(item);
  113. transmittedReports.Remove(item);
  114. StateHasChanged();
  115. Toaster.ShowSuccess(i18n.GetString("Success.DeleteReport.Title"), i18n.GetString("Success.DeleteReport.Msg", item.ID));
  116. } catch (Exception ex) {
  117. Toaster.ShowWarning(i18n.GetString("Error.DeleteReport.Title"), i18n.GetString("Error.DeleteReport.Msg", item.ID));
  118. }
  119. }
  120. }
  121. private async void DeleteAll() {
  122. string yes = i18n.GetString("Yes");
  123. string no = i18n.GetString("No");
  124. string result = await MatDialogService.AskAsync(i18n.GetString("History.DELETE"), new string[] { yes, no });
  125. await ScrollLockRemover.removeScrollLockAsync();
  126. if (result.Equals(yes)) {
  127. foreach (ReportRepositoryItem item in transmittedReports) {
  128. DeleteReport(item, false);
  129. }
  130. }
  131. }
  132. }