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.

CaritasServiceFundVeloFoundKeyDataPage.razor 18KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. @page "/fundvelo/keydata/Found"
  2. @inherits CaritasServiceFundVeloKeyDataPageBase
  3. @using cwebplusApp.Shared.Models;
  4. @using cwebplusApp.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. @inject ReportDataProvider ReportDataProvider
  15. <div class="row px-3 h-100">
  16. <div class="row no-gutters align-items-center justify-content-center w-100" style="padding-top:1em">
  17. <h2>@i18n["FoundBike"]</h2>
  18. </div>
  19. <div class="row no-gutters align-items-center justify-content-center w-100">
  20. <div class="mat-layout-grid w-100">
  21. <div class="mat-layout-grid-inner">
  22. <div class="mat-layout-grid-cell mat-layout-grid-cell-span-1 justify-content-center" style="text-align: center">
  23. <div>
  24. <InputFile class="inputFile" id="camera" type="file" name="camera" accept="image/*" capture="environment" OnChange="@OnGatheringPicture" />
  25. <MatRipple class="inputfile-mat-ripple" Color="@MatRippleColor.Default">
  26. <label for="camera">
  27. <svg xmlns="http://www.w3.org/2000/svg" width="48px" height="48px" viewBox="0 0 24 24" fill="#000000">
  28. <path d="M0 0h21v21H0V0z" fill="none" />
  29. <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" />
  30. <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" />
  31. </svg>
  32. </label>
  33. </MatRipple>
  34. </div>
  35. <div style="margin-top:1rem">
  36. <InputFile class="inputFile" id="file" type="file" name="file" accept="image/x-png,image/jpeg,image/gif" OnChange="@OnGatheringPicture" />
  37. <MatRipple class="inputfile-mat-ripple" Color="@MatRippleColor.Default">
  38. <label for="file">
  39. <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">
  40. <g><rect fill="none" height="24" width="24" /></g>
  41. <g>
  42. <g>
  43. <path d="M13,4H6v16h12V9h-5V4z M16,15h-3v4h-2v-4H8l4.01-4L16,15z" opacity=".3" />
  44. <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" />
  45. <polygon points="8,15 11,15 11,19 13,19 13,15 16,15 12.01,11" />
  46. </g>
  47. </g>
  48. </svg>
  49. </label>
  50. </MatRipple>
  51. </div>
  52. </div>
  53. <div class="mat-layout-grid-cell mat-layout-grid-cell-span-3">
  54. <div>
  55. <MatCard Id="bikePic" Class="fv-mat-card">
  56. <MatCardContent>
  57. <MatCardMedia Square="true" ImageUrl="@imgUrl">
  58. @if (loading) {
  59. <MatProgressCircle Indeterminate="true" Size="MatProgressCircleSize.Medium" />
  60. }
  61. </MatCardMedia>
  62. </MatCardContent>
  63. </MatCard>
  64. </div>
  65. </div>
  66. <div class="mat-layout-grid-cell mat-layout-grid-cell-span-1 justify-content-center" style="text-align: center">
  67. <MatRipple class="inputfile-mat-ripple" Color="@MatRippleColor.Default" @onclick="InitializeMapPosition">
  68. <label>
  69. <svg xmlns="http://www.w3.org/2000/svg" height="48px" width="48px" viewBox="0 0 24 24" fill="#000000">
  70. <path d="M0 0h24v24H0V0z" fill="none" />
  71. <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" />
  72. <circle cx="12" cy="12" opacity=".3" r="2" />
  73. <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" />
  74. </svg>
  75. </label>
  76. </MatRipple>
  77. </div>
  78. <div class="mat-layout-grid-cell mat-layout-grid-cell-span-3">
  79. <div class="w-100 fv-osm-tile map-wrapper">
  80. <Map @ref="mapRef" MapOptions="@mapOptions" AfterRender="AfterRenderMap"></Map>
  81. </div>
  82. </div>
  83. <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">
  84. <div class="mat-layout-grid-inner">
  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="@getAddressLbl()" Outlined="true" Required="true" type="text" @bind-Value="@bicycleGeoPosition.Address"></MatStringField>
  87. </div>
  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="@i18n["PlaceOfDiscovery"]" Outlined="true" Required="true" type="text" @bind-Value="@bicycleGeoPosition.DisplayCity"></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. <MatTextField Class="w-100 form-check-label italic" Label="@i18n["Latitude"]" Outlined="true" ReadOnly="true" @bind-Value="@bicycleGeoPosition.Latitude"></MatTextField>
  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["Longitude"]" Outlined="true" ReadOnly="true" @bind-Value="@bicycleGeoPosition.Longitude"></MatTextField>
  96. </div>
  97. </div>
  98. </div>
  99. <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">
  100. <div class="mat-layout-grid-inner">
  101. <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">
  102. <MatSelectValue FullWidth="true" Outlined="true" Label="@i18n["Color"]" Required="true" @bind-Value="selectedColor" Items="@Colors" ValueSelector="@(i=>i)">
  103. <ItemTemplate>
  104. <div>
  105. <span class="btn-sm" style="background-color:@context.Code;
  106. display:initial;
  107. border:1px solid black;
  108. box-shadow:0.2em 0.2em 0.3em 0.025em #3f4244" />
  109. <span class="btn">@context?.Bezeichnung</span>
  110. </div>
  111. </ItemTemplate>
  112. </MatSelectValue>
  113. </div>
  114. <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">
  115. <div class="outlined">
  116. <MatAutocompleteList TItem="Brand" FullWidth="true" Label="@i18n["Brand"]" Required="true" Items="@Brands" OnTextChanged="setBrandValue" @bind-Value="SelectedBrand" CustomStringSelector="@(i => i?.Bezeichnung)">
  117. <ItemTemplate>
  118. <div>
  119. <span>@context?.Bezeichnung</span>
  120. </div>
  121. </ItemTemplate>
  122. </MatAutocompleteList>
  123. </div>
  124. </div>
  125. <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">
  126. <MatSelectValue FullWidth="true" Outlined="true" Label="@i18n["Type"]" Required="true" @bind-Value="selectedBcType" Items="@BicycleTypes" ValueSelector="@(i=>i)">
  127. <ItemTemplate>
  128. <div>
  129. <span>@context?.Bezeichnung</span>
  130. </div>
  131. </ItemTemplate>
  132. </MatSelectValue>
  133. </div>
  134. <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">
  135. <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">
  136. <MatStringField Class="w-100 form-check-label" Label="@i18n["FrameNumber"]" Outlined="true" type="text" @bind-Value="frameNumber"></MatStringField>
  137. </div>
  138. </div>
  139. <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">
  140. <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">
  141. <MatStringField Class="w-100 form-check-label" Label="@i18n["Remark"]" Outlined="true" type="text" @bind-Value="remark"></MatStringField>
  142. </div>
  143. </div>
  144. <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">
  145. <div>
  146. <MatCheckbox @bind-Value="@abholadresseIsNotContact" Label="@i18n["AlternatePickupContact"]"></MatCheckbox>
  147. </div>
  148. </div>
  149. </div>
  150. </div>
  151. </div>
  152. </div>
  153. </div>
  154. <div class="row no-gutters align-items-end justify-content-center w-100" style="padding-bottom:2em;padding-top:2em">
  155. <div class="col" style="padding-right:0.5em">
  156. <MatButton Class="w-100" Outlined="true" @onclick="Cancel">@i18n["Cancel"]</MatButton>
  157. </div>
  158. <div class="col" style="padding-left:0.5em">
  159. <MatButton Class="w-100" Raised="true" @onclick="Next">@i18n["Continue"]</MatButton>
  160. </div>
  161. </div>
  162. </div>
  163. @code {
  164. private static long MAX_FILE_SIZE = 3145728; //3MB
  165. private string imgUrl = string.Empty;
  166. private Boolean loading = false;
  167. private ColorItem selectedColor;
  168. private BicycleType selectedBcType;
  169. private string brandStringValue;
  170. private Brand selectedBrand;
  171. private Brand SelectedBrand {
  172. get { return selectedBrand; }
  173. set { selectedBrand = (value != null) ? value : new Brand(-999, brandStringValue); }
  174. }
  175. private void setBrandValue(string value) {
  176. brandStringValue = value;
  177. selectedBrand = null;
  178. }
  179. private string frameNumber;
  180. private string remark;
  181. private bool abholadresseIsNotContact;
  182. protected async override void OnInitialized() {
  183. base.OnInitialized();
  184. await GetColors();
  185. await GetBicycleTypes();
  186. await GetBrands();
  187. refreshGUIFromDto();
  188. PageHistoryManager.AddPageToHistory(NavigationManager.Uri);
  189. StateHasChanged();
  190. }
  191. private async void AfterRenderMap() {
  192. FoundReport report = ReportDataProvider.GetFoundReport();
  193. if (report.GeographicInfo.Latitude != 0 && report.GeographicInfo.Longitude != 0) {
  194. bicycleGeoPosition.DisplayCity = GetFormattedAddressZipAndTown();
  195. LatLng coordinates = new LatLng(report.GeographicInfo.Latitude, report.GeographicInfo.Longitude);
  196. MouseEvent mouseEvent = new MouseEvent();
  197. mouseEvent.LatLng = coordinates;
  198. await InitializeMapPosition();
  199. await AddBicycleMarkerOnClickPosition(mouseEvent);
  200. }
  201. }
  202. private Brand getBrand(Brand brand) {
  203. return brand != null ? brand : new Brand(-999, "Test");
  204. }
  205. private async Task GetColors() {
  206. await MasterDataService.GetColors();
  207. }
  208. private async Task GetBicycleTypes() {
  209. await MasterDataService.GetBicycleTypes();
  210. }
  211. private async Task GetBrands() {
  212. await MasterDataService.GetBrands();
  213. }
  214. private ColorItem[] Colors {
  215. get => MasterDataService.Colors;
  216. }
  217. private BicycleType[] BicycleTypes {
  218. get => MasterDataService.BicycleTypes;
  219. }
  220. private Brand[] Brands {
  221. get => MasterDataService.Brands;
  222. }
  223. private void Next() {
  224. updateDtoFromGUI();
  225. if (abholadresseIsNotContact) {
  226. NavigationManager.NavigateTo("fundvelo/alternate_pickup");
  227. } else {
  228. NavigationManager.NavigateTo("fundvelo/account/Found");
  229. }
  230. }
  231. private void Cancel() {
  232. NavigationManager.NavigateTo("caritas_services");
  233. }
  234. private string getAddressLbl() {
  235. return i18n.GetString("Address") + " (" + i18n.GetString("PlaceOfDiscovery") + ")";
  236. }
  237. private async Task OnGatheringPicture(InputFileChangeEventArgs e) {
  238. IBrowserFile imgFile = e.File;
  239. var buffer = new byte[imgFile.Size];
  240. imgUrl = string.Empty;
  241. loading = true;
  242. StateHasChanged();
  243. try {
  244. using (var stream = imgFile.OpenReadStream(MAX_FILE_SIZE)) {
  245. await stream.ReadAsync(buffer);
  246. imgUrl = $"data:{imgFile.ContentType};base64,{Convert.ToBase64String(buffer)}";
  247. await stream.DisposeAsync();
  248. }
  249. } catch (IOException ex) {
  250. Console.WriteLine("Ex.Message is: {0}.", ex.Message);
  251. if (ex.Message.Contains("exceeds the maximum of")) {
  252. Toaster.ShowError(i18n.GetString("Error.PhotoOrPictureToBig.Title"), i18n.GetString("Error.PhotoOrPictureToBig.Msg", MAX_FILE_SIZE / (1024 * 1024)));
  253. } else {
  254. Toaster.ShowError(i18n.GetString("Error.IOException.Title"), i18n.GetString("Error.IOException.Msg"));
  255. }
  256. } catch (JSException ex) {
  257. Console.WriteLine("Ex.Message is: {0}.", ex.Message);
  258. } finally {
  259. Array.Clear(buffer, 0, buffer.Length);
  260. buffer = null;
  261. loading = false;
  262. StateHasChanged();
  263. }
  264. }
  265. private void refreshGUIFromDto() {
  266. FoundReport report = ReportDataProvider.GetFoundReport();
  267. bicycleGeoPosition.Address = report.GeographicInfo.Address;
  268. bicycleGeoPosition.Zip = report.GeographicInfo.Postcode;
  269. bicycleGeoPosition.City = report.GeographicInfo.Town;
  270. bicycleGeoPosition.Latitude = report.GeographicInfo.Latitude;
  271. bicycleGeoPosition.Longitude = report.GeographicInfo.Longitude;
  272. imgUrl = report.FotoString;
  273. selectedColor = Array.Find(Colors, color => color.Id == report.FarbeId);
  274. selectedBrand = String.IsNullOrEmpty(report.NeueMarke) ? Array.Find(Brands, brand => brand.Id == report.MarkeId): new Brand(-999, report.NeueMarke);
  275. selectedBcType = Array.Find(BicycleTypes, bcType => bcType.Id == report.TypId);
  276. frameNumber = report.RahmenNummer;
  277. remark = report.Bemerkung;
  278. abholadresseIsNotContact = !report.AbholadresseIstKontakt;
  279. }
  280. private void updateDtoFromGUI() {
  281. FoundReport report = ReportDataProvider.GetFoundReport();
  282. report.GeographicInfo.Address = bicycleGeoPosition.Address;
  283. report.GeographicInfo.Postcode = bicycleGeoPosition.Zip;
  284. report.GeographicInfo.Town = bicycleGeoPosition.City;
  285. report.GeographicInfo.Latitude = bicycleGeoPosition.Latitude;
  286. report.GeographicInfo.Longitude = bicycleGeoPosition.Longitude;
  287. report.FotoString = imgUrl;
  288. report.FarbeId = selectedColor != null ? selectedColor.Id : 0;
  289. report.TypId = selectedBcType != null ? selectedBcType.Id : 0;
  290. if (SelectedBrand != null) {
  291. if (SelectedBrand.Id == -999) {
  292. report.NeueMarke = SelectedBrand.Bezeichnung;
  293. } else {
  294. report.MarkeId = SelectedBrand.Id;
  295. }
  296. }
  297. report.RahmenNummer = frameNumber;
  298. report.Bemerkung = remark;
  299. report.AbholadresseIstKontakt = !abholadresseIsNotContact;
  300. }
  301. }