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

CaritasServiceFundVeloKeyDataPage.razor 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. @page "/fundvelo/keydata/{FromRoute}"
  2. @inherits CaritasServiceFundVeloKeyDataPageBase
  3. @using CaritasPWA.Shared.Models;
  4. @using CaritasPWA.Shared.Services;
  5. @using System.Globalization;
  6. @using Microsoft.AspNetCore.Components.Forms;
  7. @using System.IO;
  8. @inject NavigationManager NavigationManager
  9. @inject IStringLocalizer<Resources> i18n
  10. @inject PageHistoryManager PageHistoryManager
  11. @inject MasterDataService MasterDataService
  12. @inject Toaster Toaster
  13. @inject IJSRuntime JS
  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="environment" OnChange="@OnGatheringPicture" />
  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. <InputFile class="inputFile" id="file" type="file" name="file" accept="image/x-png,image/jpeg,image/gif" OnChange="@OnGatheringPicture" />
  40. <MatRipple class="inputfile-mat-ripple" Color="@MatRippleColor.Default">
  41. <label for="file">
  42. <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">
  43. <g><rect fill="none" height="24" width="24" /></g>
  44. <g>
  45. <g>
  46. <path d="M13,4H6v16h12V9h-5V4z M16,15h-3v4h-2v-4H8l4.01-4L16,15z" opacity=".3" />
  47. <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" />
  48. <polygon points="8,15 11,15 11,19 13,19 13,15 16,15 12.01,11" />
  49. </g>
  50. </g>
  51. </svg>
  52. </label>
  53. </MatRipple>
  54. </div>
  55. </div>
  56. <div class="mat-layout-grid-cell mat-layout-grid-cell-span-3">
  57. <div>
  58. <MatCard Id="bikePic" Class="fv-mat-card">
  59. <MatCardContent>
  60. <MatCardMedia Square="true" Class="" ImageUrl="@imgUrl">
  61. @if (loading) {
  62. <MatProgressCircle Indeterminate="true" Size="MatProgressCircleSize.Medium" />
  63. }
  64. </MatCardMedia>
  65. </MatCardContent>
  66. </MatCard>
  67. </div>
  68. </div>
  69. <div class="mat-layout-grid-cell mat-layout-grid-cell-span-1 justify-content-center" style="text-align: center">
  70. <MatRipple class="inputfile-mat-ripple" Color="@MatRippleColor.Default" @onclick="InitializeMapPosition">
  71. <label>
  72. <svg xmlns="http://www.w3.org/2000/svg" height="48px" width="48px" viewBox="0 0 24 24" fill="#000000">
  73. <path d="M0 0h24v24H0V0z" fill="none" />
  74. <path d="M13 3.06V1h-2v2.06C6.83 3.52 3.52 6.83 3.06 11H1v2h2.06c.46 4.17 3.77 7.48 7.94 7.94V23h2v-2.06c4.17-.46 7.48-3.77 7.94-7.94H23v-2h-2.06c-.46-4.17-3.77-7.48-7.94-7.94zM12 19c-3.87 0-7-3.13-7-7s3.13-7 7-7 7 3.13 7 7-3.13 7-7 7z" />
  75. <circle cx="12" cy="12" opacity=".3" r="2" />
  76. <path d="M12 8c-2.21 0-4 1.79-4 4s1.79 4 4 4 4-1.79 4-4-1.79-4-4-4zm0 6c-1.1 0-2-.9-2-2s.9-2 2-2 2 .9 2 2-.9 2-2 2z" />
  77. </svg>
  78. </label>
  79. </MatRipple>
  80. </div>
  81. <div class="mat-layout-grid-cell mat-layout-grid-cell-span-3">
  82. <div class="w-100 fv-osm-tile map-wrapper">
  83. <Map @ref="mapRef" MapOptions="@mapOptions"></Map>
  84. </div>
  85. </div>
  86. <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">
  87. <div class="mat-layout-grid-inner">
  88. <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">
  89. <MatStringField Class="w-100 form-check-label" Label="@getAddressLbl()" Outlined="true" Required="true" type="text" @bind-Value="@bicycleGeoPosition.Address"></MatStringField>
  90. </div>
  91. <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">
  92. <MatStringField Class="w-100 form-check-label" Label="@getPlaceLbl()" Outlined="true" Required="true" type="text" @bind-Value="@bicycleGeoPosition.City"></MatStringField>
  93. </div>
  94. <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">
  95. <MatTextField Class="w-100 form-check-label italic" Label="@i18n["Latitude"]" Outlined="true" ReadOnly="true" @bind-Value="@bicycleGeoPosition.Latitude"></MatTextField>
  96. </div>
  97. <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">
  98. <MatTextField Class="w-100 form-check-label italic" Label="@i18n["Longitude"]" Outlined="true" ReadOnly="true" @bind-Value="@bicycleGeoPosition.Longitude"></MatTextField>
  99. </div>
  100. </div>
  101. </div>
  102. <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">
  103. <div class="mat-layout-grid-inner">
  104. <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">
  105. <MatSelectValue FullWidth="true" Outlined="true" Label="@i18n["Color"]" @bind-Value="selectedColor" Items="@Colors" ValueSelector="@(i=>i)">
  106. <ItemTemplate>
  107. <div>
  108. <span class="btn-sm" style="background-color:@context.Code;
  109. display:initial;
  110. border:1px solid black;
  111. box-shadow:0.2em 0.2em 0.3em 0.025em #3f4244" />
  112. <span class="btn">@context?.Bezeichnung</span>
  113. </div>
  114. </ItemTemplate>
  115. </MatSelectValue>
  116. </div>
  117. <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">
  118. <div class="outlined">
  119. <MatAutocompleteList TItem="Brand" FullWidth="true" Label="@i18n["Brand"]" Items="@Brands" OnTextChanged="setBrandValue" @bind-Value="SelectedBrand" CustomStringSelector="@(i => i?.Bezeichnung)">
  120. <ItemTemplate>
  121. <div>
  122. <span>@context?.Bezeichnung</span>
  123. </div>
  124. </ItemTemplate>
  125. </MatAutocompleteList>
  126. </div>
  127. </div>
  128. <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">
  129. <MatSelectValue FullWidth="true" Outlined="true" Label="@i18n["Type"]" @bind-Value="selectedBcType" Items="@BicycleTypes" ValueSelector="@(i=>i)">
  130. <ItemTemplate>
  131. <div>
  132. <span>@context?.Bezeichnung</span>
  133. </div>
  134. </ItemTemplate>
  135. </MatSelectValue>
  136. </div>
  137. </div>
  138. </div>
  139. </div>
  140. </div>
  141. </div>
  142. <div class="row no-gutters align-items-end justify-content-center w-100" style="padding-bottom:2em;padding-top:2em">
  143. <div class="col" style="padding-right:0.5em">
  144. <MatButton Class="w-100" Outlined="true" @onclick="Cancel">@i18n["Cancel"]</MatButton>
  145. </div>
  146. <div class="col" style="padding-left:0.5em">
  147. <MatButton Class="w-100" Raised="true" @onclick="Next">@i18n["Continue"]</MatButton>
  148. </div>
  149. </div>
  150. </div>
  151. @code {
  152. [Parameter]
  153. public string FromRoute { get; set; }
  154. private static long MAX_FILE_SIZE = 3145728; //3MB
  155. private string imgUrl = string.Empty;
  156. private Boolean loading = false;
  157. private ColorItem selectedColor;
  158. private BicycleType selectedBcType;
  159. private string brandStringValue;
  160. private Brand selectedBrand;
  161. private Brand SelectedBrand {
  162. get { return selectedBrand; }
  163. set { selectedBrand = (value != null) ? value : new Brand(-999, brandStringValue); }
  164. }
  165. private void setBrandValue(string value) {
  166. brandStringValue = value;
  167. selectedBrand = null;
  168. }
  169. protected async override void OnInitialized() {
  170. await GetColors();
  171. await GetBicycleTypes();
  172. await GetBrands();
  173. PageHistoryManager.AddPageToHistory(NavigationManager.Uri);
  174. base.OnInitialized();
  175. }
  176. private Brand getBrand(Brand brand) {
  177. return brand != null ? brand : new Brand(-999, "Test");
  178. }
  179. private async Task GetColors() {
  180. await MasterDataService.GetColors();
  181. StateHasChanged();
  182. }
  183. private async Task GetBicycleTypes() {
  184. await MasterDataService.GetBicycleTypes();
  185. StateHasChanged();
  186. }
  187. private async Task GetBrands() {
  188. await MasterDataService.GetBrands();
  189. StateHasChanged();
  190. }
  191. private ColorItem[] Colors {
  192. get => MasterDataService.Colors;
  193. }
  194. private BicycleType[] BicycleTypes {
  195. get => MasterDataService.BicycleTypes;
  196. }
  197. private Brand[] Brands {
  198. get => MasterDataService.Brands;
  199. }
  200. private void Next() {
  201. NavigationManager.NavigateTo("fundvelo/account/" + @FromRoute);
  202. }
  203. private void Cancel() {
  204. NavigationManager.NavigateTo("caritas_services");
  205. }
  206. private string getAddressLbl() {
  207. return i18n.GetString("Address") + " (" + getPlaceLbl() + ")";
  208. }
  209. private string getPlaceLbl() {
  210. return @FromRoute == "Found" ? i18n.GetString("PlaceOfDiscovery") : i18n.GetString("PlaceOfLoss");
  211. }
  212. private async Task OnGatheringPicture(InputFileChangeEventArgs e) {
  213. IBrowserFile imgFile = e.File;
  214. var buffer = new byte[imgFile.Size];
  215. imgUrl = string.Empty;
  216. loading = true;
  217. StateHasChanged();
  218. try {
  219. using (var stream = imgFile.OpenReadStream(MAX_FILE_SIZE)) {
  220. await stream.ReadAsync(buffer);
  221. imgUrl = $"data:{imgFile.ContentType};base64,{Convert.ToBase64String(buffer)}";
  222. await stream.DisposeAsync();
  223. }
  224. } catch (IOException ex) {
  225. Console.WriteLine("Ex.Message is: {0}.", ex.Message);
  226. if (ex.Message.Contains("exceeds the maximum of")) {
  227. Toaster.ShowError(i18n.GetString("Error.PhotoOrPictureToBig.Title"), i18n.GetString("Error.PhotoOrPictureToBig.Msg", MAX_FILE_SIZE / (1024 * 1024)));
  228. } else {
  229. Toaster.ShowError(i18n.GetString("Error.IOException.Title"), i18n.GetString("Error.IOException.Msg"));
  230. }
  231. } catch (JSException ex) {
  232. Console.WriteLine("Ex.Message is: {0}.", ex.Message);
  233. } finally {
  234. Array.Clear(buffer, 0, buffer.Length);
  235. buffer = null;
  236. loading = false;
  237. StateHasChanged();
  238. }
  239. }
  240. }