PWA Fundvelo der Caritas.
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

CaritasServiceFundVeloHistoryPage.razor 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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>@getPicture(context)</td>
  41. <td>
  42. <MatIconButton Icon="delete_forever" OnClick="@(_ => DeleteReport(context))"></MatIconButton>
  43. </td>
  44. </MatTableRow>
  45. </MatTable>
  46. </div>
  47. <div class="row no-gutters justify-content-end w-100">
  48. <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;">
  49. <label>
  50. <svg xmlns="http://www.w3.org/2000/svg" height="48px" viewBox="0 0 24 24" width="48px" fill="#000000">
  51. <path d="M0 0h24v24H0V0z" fill="none" />
  52. <path d="M5 10h6v8H5z" opacity=".3" />
  53. <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" />
  54. </svg>
  55. </label>
  56. </MatRipple>
  57. </div>
  58. </div>
  59. @code {
  60. [Parameter]
  61. public string FromRoute { get; set; }
  62. private List<ReportRepositoryItem> transmittedReports = new();
  63. private ReportRepositoryItem selectedReport;
  64. protected override void OnInitialized() {
  65. base.OnInitialized();
  66. PageHistoryManager.AddPageToHistory(NavigationManager.Uri);
  67. StateHasChanged();
  68. }
  69. protected async override void OnParametersSet() {
  70. if (FromRoute.Equals("history_found")) {
  71. transmittedReports.AddRange(await ReportRepositoryService.GetTransmittedFoundReports());
  72. } else {
  73. transmittedReports.AddRange(await ReportRepositoryService.GetTransmittedMissingReports());
  74. }
  75. StateHasChanged();
  76. }
  77. private string translateType(ReportRepositoryItem.Type type) {
  78. return i18n.GetString("ReportType." + type);
  79. }
  80. private string getTypeBackgroundStyle(ReportRepositoryItem.Type type) {
  81. return ReportRepositoryItem.Type.FOUND.Equals(type) ? "background: linear-gradient(45deg, darkseagreen, transparent)" : "background: linear-gradient(45deg, darksalmon, transparent)";
  82. }
  83. private string getAddress(ReportRepositoryItem item) {
  84. if (ReportRepositoryItem.Type.FOUND.Equals(item.ReportType)) {
  85. GeographicInfo geoInfo = ((FoundReportRepositoryItem)item).Report.GeographicInfo;
  86. return geoInfo.Address + ", " + geoInfo.Postcode + " " + geoInfo.Town;
  87. }
  88. return "";
  89. }
  90. private string getPicture(ReportRepositoryItem item) {
  91. string picData = ReportRepositoryItem.Type.FOUND.Equals(item.ReportType) ? ((FoundReportRepositoryItem)item).Report.FotoString : ((MissingReportRepositoryItem)item).Report.FotoString;
  92. return "";
  93. }
  94. private async void DeleteReport(ReportRepositoryItem item, bool ask = true) {
  95. string yes = i18n.GetString("Yes");
  96. string no = i18n.GetString("No");
  97. string result = ask ? await MatDialogService.AskAsync(i18n.GetString("Pending." + item.ReportType + ".Delete"), new string[] { yes, no }) : yes;
  98. await ScrollLockRemover.removeScrollLockAsync();
  99. if (result.Equals(yes)) {
  100. try {
  101. await ReportRepositoryService.DeleteReport(item);
  102. transmittedReports.Remove(item);
  103. StateHasChanged();
  104. Toaster.ShowSuccess(i18n.GetString("Success.DeleteReport.Title"), i18n.GetString("Success.DeleteReport.Msg", item.ID));
  105. } catch (Exception ex) {
  106. Toaster.ShowWarning(i18n.GetString("Error.DeleteReport.Title"), i18n.GetString("Error.DeleteReport.Msg", item.ID));
  107. }
  108. }
  109. }
  110. private async void DeleteAll() {
  111. string yes = i18n.GetString("Yes");
  112. string no = i18n.GetString("No");
  113. string result = await MatDialogService.AskAsync(i18n.GetString("History.DELETE"), new string[] { yes, no });
  114. await ScrollLockRemover.removeScrollLockAsync();
  115. if (result.Equals(yes)) {
  116. foreach (ReportRepositoryItem item in transmittedReports) {
  117. DeleteReport(item, false);
  118. }
  119. }
  120. }
  121. }