PWA Fundvelo der Caritas.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CaritasServiceFundVeloKeyDataPage.razor 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  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. @inject IJSRuntime JS
  13. <div class="row px-3 h-100">
  14. <div class="row no-gutters align-items-center justify-content-center w-100" style="padding-top:1em">
  15. @if ("Found".Equals(FromRoute)) {
  16. <h2>@i18n["FoundBike"]</h2>
  17. } else {
  18. <h2>@i18n["MissingBike"]</h2>
  19. }
  20. </div>
  21. <div class="row no-gutters align-items-center justify-content-center w-100">
  22. <div class="mat-layout-grid w-100">
  23. <div class="mat-layout-grid-inner">
  24. <div class="mat-layout-grid-cell mat-layout-grid-cell-span-1 justify-content-center" style="text-align: center">
  25. <div>
  26. <InputFile class="inputFile" id="camera" type="file" name="camera" accept="image/*" capture="environment" OnChange="@OnGatheringPicture" />
  27. <MatRipple class="inputfile-mat-ripple" Color="@MatRippleColor.Default">
  28. <label for="camera">
  29. <svg xmlns="http://www.w3.org/2000/svg" width="48px" height="48px" viewBox="0 0 24 24" fill="#000000">
  30. <path d="M0 0h21v21H0V0z" fill="none" />
  31. <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" />
  32. <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" />
  33. </svg>
  34. </label>
  35. </MatRipple>
  36. </div>
  37. <div style="margin-top:1rem">
  38. <InputFile class="inputFile" id="file" type="file" name="file" accept="image/x-png,image/jpeg,image/gif" OnChange="@OnGatheringPicture" />
  39. <MatRipple class="inputfile-mat-ripple" Color="@MatRippleColor.Default">
  40. <label for="file">
  41. <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">
  42. <g><rect fill="none" height="24" width="24" /></g>
  43. <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>
  44. </svg>
  45. </label>
  46. </MatRipple>
  47. </div>
  48. </div>
  49. <div class="mat-layout-grid-cell mat-layout-grid-cell-span-3">
  50. <div>
  51. <MatCard Id="bikePic" Class="fv-mat-card">
  52. <MatCardContent>
  53. <MatCardMedia Square="true" Class="" ImageUrl="@imgUrl">
  54. @if (loading) {
  55. <MatProgressCircle Indeterminate="true" Size="MatProgressCircleSize.Medium" />
  56. }
  57. </MatCardMedia>
  58. </MatCardContent>
  59. </MatCard>
  60. </div>
  61. </div>
  62. <div class="mat-layout-grid-cell mat-layout-grid-cell-span-1 justify-content-center" style="text-align: center">
  63. <div>
  64. <MatIconButton Class="mat-icon-large" Icon="location_on" />
  65. </div>
  66. </div>
  67. <div class="mat-layout-grid-cell mat-layout-grid-cell-span-3">
  68. <div>
  69. <MatCard Id="OSM" Class="fv-mat-card">
  70. <MatCardContent>
  71. <MatCardMedia Square="true" Class="" />
  72. </MatCardContent>
  73. </MatCard>
  74. </div>
  75. </div>
  76. <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">
  77. <div class="mat-layout-grid-inner">
  78. <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">
  79. <MatStringField Class="w-100 form-check-label" Label="@getAddressLbl()" Outlined="true" type="text"></MatStringField>
  80. </div>
  81. <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">
  82. <MatStringField Class="w-100 form-check-label" Label="@getPlaceLbl()" Outlined="true" type="text"></MatStringField>
  83. </div>
  84. <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">
  85. <MatStringField Class="w-100 form-check-label" Label="@i18n["Latitude"]" Outlined="true" type="text"></MatStringField>
  86. </div>
  87. <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">
  88. <MatStringField Class="w-100 form-check-label" Label="@i18n["Longitude"]" Outlined="true" type="text"></MatStringField>
  89. </div>
  90. </div>
  91. </div>
  92. <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">
  93. <div class="mat-layout-grid-inner">
  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-4-desktop">
  95. <MatSelectValue FullWidth="true" Outlined="true" Label="@i18n["Color"]" @bind-Value="selectedColor" Items="@Colors" ValueSelector="@(i=>i)">
  96. <ItemTemplate>
  97. <div>
  98. <span class="btn-sm" style="background-color:rgb(@context.RGB);
  99. display:initial;
  100. border:1px solid black;
  101. box-shadow:0.2em 0.2em 0.3em 0.025em #3f4244" />
  102. <span class="btn">@i18n["Color." + @context?.Name]</span>
  103. </div>
  104. </ItemTemplate>
  105. </MatSelectValue>
  106. </div>
  107. <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">
  108. <div class="outlined">
  109. <MatAutocompleteList TItem="Brand" FullWidth="true" Label="@i18n["Brand"]" Items="@Brands" @bind-Value="selectedBrand" CustomStringSelector="@(i => i?.Name)">
  110. <ItemTemplate>
  111. <div>
  112. <span>@context?.Name</span>
  113. </div>
  114. </ItemTemplate>
  115. </MatAutocompleteList>
  116. </div>
  117. @*<div style="display: inline-flex; width: 100%">
  118. <MatStringField Class="w-100 form-check-label" Label="@i18n["Brand"]" Outlined="true" type="text"></MatStringField>
  119. <MatSelectValue Class="icon-only" Outlined="true" @bind-Value="selectedBrand" Items="@Brands" ValueSelector="@(i=>i)" >
  120. <ItemTemplate>
  121. <div>
  122. <span>@context?.Name</span>
  123. </div>
  124. </ItemTemplate>
  125. </MatSelectValue>
  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?.Type</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 ColorItem selectedColor;
  156. private BicycleType selectedBcType;
  157. private Brand selectedBrand;
  158. // private ElementReference inputTypeFileElement;
  159. private string imgUrl = string.Empty;
  160. private Boolean loading = false;
  161. protected async override void OnInitialized() {
  162. Console.WriteLine("CurrentCulture is {0}.", CultureInfo.CurrentCulture.Name);
  163. Console.WriteLine("Current language is {0}.", CultureInfo.CurrentCulture.TwoLetterISOLanguageName.ToUpper());
  164. await GetColors();
  165. await GetBicycleTypes();
  166. await GetBrands();
  167. PageHistoryManager.AddPageToHistory(NavigationManager.Uri);
  168. base.OnInitialized();
  169. }
  170. private async Task GetColors() {
  171. await InvokeAsync(async () => {
  172. await MasterDataService.GetColors();
  173. StateHasChanged();
  174. });
  175. }
  176. private async Task GetBicycleTypes() {
  177. await InvokeAsync(async () => {
  178. await MasterDataService.GetBicycleTypes();
  179. StateHasChanged();
  180. });
  181. }
  182. private async Task GetBrands() {
  183. await InvokeAsync(async () => {
  184. await MasterDataService.GetBrands();
  185. StateHasChanged();
  186. });
  187. }
  188. private ColorItem[] Colors {
  189. get => MasterDataService.Colors;
  190. }
  191. private BicycleType[] BicycleTypes {
  192. get => MasterDataService.BicycleTypes;
  193. }
  194. private Brand[] Brands {
  195. get => MasterDataService.Brands;
  196. }
  197. private void Next() {
  198. NavigationManager.NavigateTo("fundvelo/account/" + @FromRoute);
  199. }
  200. private void Cancel() {
  201. NavigationManager.NavigateTo("caritas_services");
  202. }
  203. private string getAddressLbl() {
  204. return i18n.GetString("Address") + " (" + getPlaceLbl() + ")";
  205. }
  206. private string getPlaceLbl() {
  207. return @FromRoute == "Found" ? i18n.GetString("PlaceOfDiscovery") : i18n.GetString("PlaceOfLoss");
  208. }
  209. private async Task OnGatheringPicture(InputFileChangeEventArgs e) {
  210. IBrowserFile imgFile = e.File;
  211. var buffer = new byte[imgFile.Size];
  212. imgUrl = string.Empty;
  213. loading = true;
  214. StateHasChanged();
  215. try {
  216. //string text = new(await JS.InvokeAsync<string>("LoadFile", e));
  217. //imgUrl = text;
  218. using (var stream = imgFile.OpenReadStream(MAX_FILE_SIZE)) {
  219. await stream.ReadAsync(buffer);
  220. imgUrl = $"data:{imgFile.ContentType};base64,{Convert.ToBase64String(buffer)}";
  221. await stream.DisposeAsync();
  222. }
  223. } catch (IOException ex) {
  224. Console.WriteLine("Ex.Message is: {0}.", ex.Message);
  225. if (ex.Message.Contains("exceeds the maximum of")) {
  226. Show(MatToastType.Danger, i18n.GetString("Error.PhotoOrPictureToBig.Title"), i18n.GetString("Error.PhotoOrPictureToBig.Msg", MAX_FILE_SIZE / (1024 * 1024)));
  227. } else {
  228. Show(MatToastType.Danger, i18n.GetString("Error.IOException.Title"), i18n.GetString("Error.IOException.Msg"));
  229. }
  230. } catch (JSException ex) {
  231. Console.WriteLine("Ex.Message is: {0}.", ex.Message);
  232. } finally {
  233. Array.Clear(buffer, 0, buffer.Length);
  234. buffer = null;
  235. loading = false;
  236. StateHasChanged();
  237. }
  238. }
  239. public void Show(MatToastType type, string title, string message, string icon = "") {
  240. Toaster.Add(message, type, title, icon);
  241. }
  242. //private async Task OnGatheringPicture(InputFileChangeEventArgs e) {
  243. // //public async Task ReadFile() {
  244. // //foreach (var file in await fileReaderService.CreateReference(inputTypeFileElement).EnumerateFilesAsync()) {
  245. // //IFileInfo fileInfo = await file.ReadFileInfoAsync();
  246. // IBrowserFile imgFile = e.File;
  247. // //IFileInfo fileInfo = await imgFile.ReadFileInfoAsync();
  248. // if (fileInfo.Size > MAX_FILE_SIZE) {
  249. // Show(MatToastType.Danger, i18n.GetString("Error.PhotoOrPictureToBig.Title"), i18n.GetString("Error.PhotoOrPictureToBig.Msg", MAX_FILE_SIZE / (1024 * 1024)));
  250. // } else {
  251. // imgUrl = string.Empty;
  252. // loading = true;
  253. // StateHasChanged();
  254. // byte[] buffer = new byte[fileInfo.Size];
  255. // await using (Stream stream = await imgFile.OpenReadAsync()) {
  256. // buffer = new Byte[stream.Length];
  257. // await stream.ReadAsync(buffer);
  258. // }
  259. // using (MemoryStream memoryStream = await imgFile.CreateMemoryStreamAsync(4096)) {
  260. // memoryStream.Read(buffer);
  261. // string imageType = fileInfo.Type;
  262. // loading = false;
  263. // imgUrl = $"data:{imageType};base64,{Convert.ToBase64String(buffer)}";
  264. // StateHasChanged();
  265. // }
  266. // //}
  267. // }
  268. //}
  269. }