PWA Fundvelo der Caritas.
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

CaritasServiceFundVeloKeyDataPage.razor 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. @page "/fundvelo/keydata/{FromRoute}"
  2. @using CaritasPWA.Shared.Models;
  3. @using CaritasPWA.Shared.Services;
  4. @using System.Globalization;
  5. @using Microsoft.AspNetCore.Components.Forms;
  6. @using System.IO;
  7. @inject NavigationManager NavigationManager
  8. @inject IStringLocalizer<Resources> i18n
  9. @inject PageHistoryManager PageHistoryManager
  10. @inject MasterDataService MasterDataService
  11. @inject IMatToaster Toaster
  12. @*@using Tewr.Blazor.FileReader
  13. @inject IFileReaderService fileReaderService;*@
  14. <div class="row px-3 h-100">
  15. <div class="row no-gutters align-items-center justify-content-center w-100" style="padding-top:1em">
  16. @if ("Found".Equals(FromRoute)) {
  17. <h2>@i18n["FoundBike"]</h2>
  18. } else {
  19. <h2>@i18n["MissingBike"]</h2>
  20. }
  21. </div>
  22. <div class="row no-gutters align-items-center justify-content-center w-100">
  23. <div class="mat-layout-grid w-100">
  24. <div class="mat-layout-grid-inner">
  25. <div class="mat-layout-grid-cell mat-layout-grid-cell-span-1 justify-content-center" style="text-align: center">
  26. <div>
  27. <InputFile class="inputFile" id="camera" type="file" name="camera" accept="image/*" capture="user" OnChange="@OnFileSelection" />
  28. <MatRipple class="inputfile-mat-ripple" Color="@MatRippleColor.Default">
  29. <label for="camera">
  30. <svg xmlns="http://www.w3.org/2000/svg" width="48px" height="48px" viewBox="0 0 24 24" fill="#000000">
  31. <path d="M0 0h21v21H0V0z" fill="none" />
  32. <path d="M20 6h-4.05l-1.83-2H9.88L8.05 6H4v12h16V6zm-8 11c-2.76 0-5-2.24-5-5s2.24-5 5-5 5 2.24 5 5-2.24 5-5 5z" opacity=".3" />
  33. <path d="M4 20h16c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2h-3.17L15 2H9L7.17 4H4c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2zM4 6h4.05l1.83-2h4.24l1.83 2H20v12H4V6zm8 1c-2.76 0-5 2.24-5 5s2.24 5 5 5 5-2.24 5-5-2.24-5-5-5zm0 8c-1.65 0-3-1.35-3-3s1.35-3 3-3 3 1.35 3 3-1.35 3-3 3z" />
  34. </svg>
  35. </label>
  36. </MatRipple>
  37. </div>
  38. <div style="margin-top:1rem">
  39. @*<input @ref="inputTypeFileElement" id="file" type="file" name="file" accept="image/x-png,image/jpeg,image/gif" class="inputFile" @onchange="ReadFile" />*@
  40. <InputFile id="file" type="file" name="file" accept="image/x-png,image/jpeg,image/gif" class="inputFile" OnChange="@OnFileSelection" />
  41. <MatRipple class="inputfile-mat-ripple" Color="@MatRippleColor.Default">
  42. <label for="file">
  43. <svg xmlns="http://www.w3.org/2000/svg" enable-background="new 0 0 24 24" width="48px" height="48px" viewBox="0 0 24 24" fill="#000000">
  44. <g><rect fill="none" height="24" width="24" /></g>
  45. <g><g><path d="M13,4H6v16h12V9h-5V4z M16,15h-3v4h-2v-4H8l4.01-4L16,15z" opacity=".3" /><path d="M14,2H6C4.9,2,4.01,2.9,4.01,4L4,20c0,1.1,0.89,2,1.99,2H18c1.1,0,2-0.9,2-2V8L14,2z M18,20H6V4h7v5h5V20z" /><polygon points="8,15 11,15 11,19 13,19 13,15 16,15 12.01,11" /></g></g>
  46. </svg>
  47. </label>
  48. </MatRipple>
  49. </div>
  50. </div>
  51. <div class="mat-layout-grid-cell mat-layout-grid-cell-span-3">
  52. <div>
  53. <MatCard Class="demo-mat-card">
  54. <MatCardContent>
  55. <MatCardMedia Square="true" Class="" ImageUrl="@imgUrl" />
  56. </MatCardContent>
  57. </MatCard>
  58. </div>
  59. </div>
  60. <div class="mat-layout-grid-cell mat-layout-grid-cell-span-1 justify-content-center" style="text-align: center">
  61. <div>
  62. <MatIconButton Class="mat-icon-large" Icon="location_on" />
  63. </div>
  64. </div>
  65. <div class="mat-layout-grid-cell mat-layout-grid-cell-span-3">
  66. <div>
  67. <MatCard Class="demo-mat-card">
  68. <MatCardContent>
  69. <MatCardMedia Square="true" Class="" />
  70. </MatCardContent>
  71. </MatCard>
  72. </div>
  73. </div>
  74. <div class="mat-layout-grid-cell mat-layout-grid-cell-span-4-phone mat-layout-grid-cell-span-8-tablet mat-layout-grid-cell-span-4-desktop">
  75. <div class="mat-layout-grid-inner">
  76. <div class="mat-layout-grid-cell mat-layout-grid-cell-span-4-phone mat-layout-grid-cell-span-4-tablet mat-layout-grid-cell-span-12-desktop">
  77. <MatStringField Class="w-100 form-check-label" Label="@getAddressLbl()" Outlined="true" type="text"></MatStringField>
  78. </div>
  79. <div class="mat-layout-grid-cell mat-layout-grid-cell-span-4-phone mat-layout-grid-cell-span-4-tablet mat-layout-grid-cell-span-12-desktop">
  80. <MatStringField Class="w-100 form-check-label" Label="@getPlaceLbl()" Outlined="true" type="text"></MatStringField>
  81. </div>
  82. <div class="mat-layout-grid-cell mat-layout-grid-cell-span-4-phone mat-layout-grid-cell-span-4-tablet mat-layout-grid-cell-span-12-desktop">
  83. <MatStringField Class="w-100 form-check-label" Label="@i18n["Latitude"]" Outlined="true" type="text"></MatStringField>
  84. </div>
  85. <div class="mat-layout-grid-cell mat-layout-grid-cell-span-4-phone mat-layout-grid-cell-span-4-tablet mat-layout-grid-cell-span-12-desktop">
  86. <MatStringField Class="w-100 form-check-label" Label="@i18n["Longitude"]" Outlined="true" type="text"></MatStringField>
  87. </div>
  88. </div>
  89. </div>
  90. <div class="mat-layout-grid-cell mat-layout-grid-cell-span-4-phone mat-layout-grid-cell-span-8-tablet mat-layout-grid-cell-span-12-desktop">
  91. <div class="mat-layout-grid-inner">
  92. <div class="mat-layout-grid-cell mat-layout-grid-cell-span-4-phone mat-layout-grid-cell-span-4-tablet mat-layout-grid-cell-span-4-desktop">
  93. <MatSelectValue FullWidth="true" Outlined="true" Label="@i18n["Color"]" @bind-Value="selectedColor" Items="@Colors" ValueSelector="@(i=>i)">
  94. <ItemTemplate>
  95. <div>
  96. <span class="btn-sm" style="background-color:rgb(@context.RGB);
  97. display:initial;
  98. border:1px solid black;
  99. box-shadow:0.2em 0.2em 0.3em 0.025em #3f4244" />
  100. <span class="btn">@i18n["Color." + @context?.Name]</span>
  101. </div>
  102. </ItemTemplate>
  103. </MatSelectValue>
  104. </div>
  105. <div class="mat-layout-grid-cell mat-layout-grid-cell-span-4-phone mat-layout-grid-cell-span-4-tablet mat-layout-grid-cell-span-4-desktop">
  106. <MatStringField Class="w-100 form-check-label" Label="@i18n["Brand"]" Outlined="true" type="text"></MatStringField>
  107. </div>
  108. <div class="mat-layout-grid-cell mat-layout-grid-cell-span-4-phone mat-layout-grid-cell-span-4-tablet mat-layout-grid-cell-span-4-desktop">
  109. <MatSelectValue FullWidth="true" Outlined="true" Label="@i18n["Type"]" @bind-Value="selectedBcType" Items="@BicycleTypes" ValueSelector="@(i=>i)">
  110. <ItemTemplate>
  111. <div>
  112. <span>@i18n["Bike." + @context?.Type]</span>
  113. </div>
  114. </ItemTemplate>
  115. </MatSelectValue>
  116. </div>
  117. </div>
  118. </div>
  119. </div>
  120. </div>
  121. </div>
  122. <div class="row no-gutters align-items-end justify-content-center w-100" style="padding-bottom:2em;padding-top:2em">
  123. <div class="col" style="padding-right:0.5em">
  124. <MatButton Class="w-100" Outlined="true" @onclick="Cancel">@i18n["Cancel"]</MatButton>
  125. </div>
  126. <div class="col" style="padding-left:0.5em">
  127. <MatButton Class="w-100" Raised="true" @onclick="Next">@i18n["Continue"]</MatButton>
  128. </div>
  129. </div>
  130. </div>
  131. @code {
  132. [Parameter]
  133. public string FromRoute { get; set; }
  134. [Parameter(CaptureUnmatchedValues = true)]
  135. public IDictionary<string, object> Attributes { get; set; }
  136. private static int MAX_FILE_SIZE = 4000000;
  137. private ColorItem selectedColor;
  138. private BicycleType selectedBcType;
  139. private string imgUrl = string.Empty;
  140. protected async override void OnInitialized() {
  141. Console.WriteLine("CurrentCulture is {0}.", CultureInfo.CurrentCulture.Name);
  142. Console.WriteLine("Current language is {0}.", CultureInfo.CurrentCulture.TwoLetterISOLanguageName.ToUpper());
  143. await GetColors();
  144. await GetBicycleTypes();
  145. PageHistoryManager.AddPageToHistory(NavigationManager.Uri);
  146. base.OnInitialized();
  147. }
  148. private async Task GetColors() {
  149. await InvokeAsync(async () => {
  150. await MasterDataService.GetColors();
  151. StateHasChanged();
  152. });
  153. }
  154. private async Task GetBicycleTypes() {
  155. await InvokeAsync(async () => {
  156. await MasterDataService.GetBicycleTypes();
  157. StateHasChanged();
  158. });
  159. }
  160. private ColorItem[] Colors {
  161. get => MasterDataService.Colors;
  162. }
  163. private BicycleType[] BicycleTypes {
  164. get => MasterDataService.BicycleTypes;
  165. }
  166. private void Next() {
  167. NavigationManager.NavigateTo("fundvelo/account/" + @FromRoute);
  168. }
  169. private void Cancel() {
  170. NavigationManager.NavigateTo("caritas_services");
  171. }
  172. private string getAddressLbl() {
  173. return i18n.GetString("Address") + " (" + getPlaceLbl() + ")";
  174. }
  175. private string getPlaceLbl() {
  176. return @FromRoute == "Found" ? i18n.GetString("PlaceOfDiscovery") : i18n.GetString("PlaceOfLoss");
  177. }
  178. private async Task OnFileSelection(InputFileChangeEventArgs e) {
  179. IBrowserFile imgFile = e.File;
  180. var buffers = new byte[imgFile.Size];
  181. try {
  182. await imgFile.OpenReadStream(MAX_FILE_SIZE).ReadAsync(buffers);
  183. string imageType = imgFile.ContentType;
  184. imgUrl = $"data:{imageType};base64,{Convert.ToBase64String(buffers)}";
  185. } catch (IOException ex) {
  186. Console.WriteLine("Ex.Meesage is: {0}.", ex.Message);
  187. Show(MatToastType.Danger, i18n.GetString("Error.PhotoOrPictureToBig.Title"), i18n.GetString("Error.PhotoOrPictureToBig.Msg", MAX_FILE_SIZE / 1000));
  188. }
  189. }
  190. public void Show(MatToastType type, string title, string message, string icon = "") {
  191. Toaster.Add(message, type, title, icon);
  192. }
  193. //*******
  194. //private ElementReference inputTypeFileElement;
  195. //public async Task ReadFile() {
  196. // foreach (var file in await fileReaderService.CreateReference(inputTypeFileElement).EnumerateFilesAsync()) {
  197. // IFileInfo fileInfo = await file.ReadFileInfoAsync();
  198. // byte[] buffer = new byte[fileInfo.Size];
  199. // using (MemoryStream memoryStream = await file.CreateMemoryStreamAsync(4096)) {
  200. // int bytesRead = 0;
  201. // int offset = 0;
  202. // do {
  203. // bytesRead = memoryStream.Read(buffer, offset, 4096);
  204. // offset = offset + bytesRead;
  205. // } while (bytesRead < 4096);
  206. // string imageType = fileInfo.Type;
  207. // imgUrl = $"data:{imageType};base64,{Convert.ToBase64String(buffer)}";
  208. // }
  209. // }
  210. //}
  211. }