PWA Fundvelo der Caritas.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

CaritasServiceFundVeloFoundKeyDataPage.razor 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. @page "/fundvelo/keydata/Found"
  2. @inherits CaritasServiceFundVeloKeyDataPageBase
  3. @implements IDisposable;
  4. @using cwebplusApp.Shared.Models;
  5. @using cwebplusApp.Shared.Services;
  6. @using System.Globalization;
  7. @using Microsoft.AspNetCore.Components.Forms;
  8. @using System.IO;
  9. @inject NavigationManager NavigationManager
  10. @inject IStringLocalizer<Resources> i18n
  11. @inject PageHistoryManager PageHistoryManager
  12. @inject MasterDataService MasterDataService
  13. @inject Toaster Toaster
  14. @inject IJSRuntime JS
  15. @inject ReportDataProvider ReportDataProvider
  16. @inject OnlineStatusProvider OnlineStatusProvider
  17. <div class="row px-3 h-100">
  18. <div class="row no-gutters align-items-center justify-content-center w-100" style="padding-top:1em">
  19. <h2>@i18n["FoundBike"]</h2>
  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>
  44. <g>
  45. <path d="M13,4H6v16h12V9h-5V4z M16,15h-3v4h-2v-4H8l4.01-4L16,15z" opacity=".3" />
  46. <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" />
  47. <polygon points="8,15 11,15 11,19 13,19 13,15 16,15 12.01,11" />
  48. </g>
  49. </g>
  50. </svg>
  51. </label>
  52. </MatRipple>
  53. </div>
  54. </div>
  55. <div class="mat-layout-grid-cell mat-layout-grid-cell-span-3">
  56. <div>
  57. <MatCard Id="bikePic" Class="fv-mat-card">
  58. <MatCardContent>
  59. <MatCardMedia Square="true" ImageUrl="@imgUrl">
  60. @if (loading) {
  61. <MatProgressCircle Indeterminate="true" Size="MatProgressCircleSize.Medium" />
  62. }
  63. </MatCardMedia>
  64. </MatCardContent>
  65. </MatCard>
  66. </div>
  67. </div>
  68. @if (OnlineStatusProvider.Online) {
  69. <div class="mat-layout-grid-cell mat-layout-grid-cell-span-1 justify-content-center" style="text-align: center">
  70. <div>
  71. <MatRipple class="inputfile-mat-ripple" Color="@MatRippleColor.Default" @onclick="InitializeDeviceMapPosition">
  72. <label>
  73. <svg xmlns="http://www.w3.org/2000/svg" height="48px" width="48px" viewBox="0 0 24 24" fill="#000000">
  74. <path d="M0 0h24v24H0V0z" fill="none" />
  75. <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" />
  76. <circle cx="12" cy="12" opacity=".3" r="2" />
  77. <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" />
  78. </svg>
  79. </label>
  80. </MatRipple>
  81. </div>
  82. <div style="margin-top:1rem">
  83. <MatRipple class="inputfile-mat-ripple" Color="@MatRippleColor.Default" @onclick="InitializeBicycleMapPosition">
  84. <label>
  85. <svg xmlns="http://www.w3.org/2000/svg" enable-background="new 0 0 20 20" height="48px" viewBox="0 0 20 20" width="48px" fill="#000000">
  86. <g><rect fill="none" height="20" width="20" /></g>
  87. <g><g><path d="M15.5,9h-0.68l-1.58-4.34C13.1,4.26,12.72,4,12.3,4H10v1h2.3l1.46,4H8.75L8.38,8H10V7H6v1h1.32l1.46,4H7.95 C7.7,10.19,6.13,8.86,4.2,9.01c-1.64,0.13-3.01,1.46-3.18,3.1C0.8,14.25,2.41,16,4.5,16c1.79,0,3.21-1.29,3.45-3h4.1 c0.25,1.81,1.83,3.14,3.75,2.99c1.64-0.13,3.01-1.46,3.18-3.1C19.2,10.75,17.59,9,15.5,9z M6.95,13c-0.23,1.15-1.22,2-2.45,2 C3.1,15,2,13.9,2,12.5S3.1,10,4.5,10c1.23,0,2.23,0.85,2.45,2H4v1H6.95z M12.05,12H9.84l-0.73-2h3.92 C12.5,10.52,12.16,11.22,12.05,12z M15.5,15c-1.4,0-2.5-1.1-2.5-2.5c0-0.94,0.5-1.73,1.24-2.16l1.03,2.83l0.94-0.34l-1.02-2.8 C15.3,10.02,15.4,10,15.5,10c1.4,0,2.5,1.1,2.5,2.5S16.9,15,15.5,15z" /></g></g>
  88. </svg>
  89. </label>
  90. </MatRipple>
  91. </div>
  92. </div>
  93. <div class="mat-layout-grid-cell mat-layout-grid-cell-span-3">
  94. <div class="w-100 fv-osm-tile map-wrapper">
  95. <Map @ref="mapRef" MapOptions="@mapOptions" AfterRender="AfterRenderMap"></Map>
  96. </div>
  97. </div>
  98. }
  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-4-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-12-desktop">
  102. <MatStringField Class="w-100 form-check-label" Label="@getAddressLbl()" Outlined="true" Required="true" type="text" @bind-Value="@bicycleGeoPosition.Address"></MatStringField>
  103. </div>
  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-12-desktop">
  105. <MatStringField Class="w-100 form-check-label" Label="@i18n["PlaceOfDiscovery"]" Outlined="true" Required="true" type="text" @bind-Value="@bicycleGeoPosition.DisplayCity"></MatStringField>
  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-12-desktop">
  108. <MatTextField Class="w-100 form-check-label italic" Label="@i18n["Latitude"]" Outlined="true" ReadOnly="true" @bind-Value="@bicycleGeoPosition.Latitude"></MatTextField>
  109. </div>
  110. <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">
  111. <MatTextField Class="w-100 form-check-label italic" Label="@i18n["Longitude"]" Outlined="true" ReadOnly="true" @bind-Value="@bicycleGeoPosition.Longitude"></MatTextField>
  112. </div>
  113. </div>
  114. </div>
  115. <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">
  116. <div class="mat-layout-grid-inner">
  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. <MatSelectValue Class="required" FullWidth="true" Outlined="true" Label="@i18n["Color"]" @bind-Value="selectedColor" Items="@Colors" ValueSelector="@(i=>i)">
  119. <ItemTemplate>
  120. <div>
  121. <span class="btn-sm" style="background-color:@context.Code;
  122. display:initial;
  123. border:1px solid black;
  124. box-shadow:0.2em 0.2em 0.3em 0.025em #3f4244" />
  125. <span class="btn">@context?.Bezeichnung</span>
  126. </div>
  127. </ItemTemplate>
  128. </MatSelectValue>
  129. </div>
  130. <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">
  131. <div class="outlined">
  132. <MatAutocompleteList TItem="Brand" FullWidth="true" Label="@i18n["Brand"]" Required="true" Items="@Brands" OnTextChanged="setBrandValue" @bind-Value="SelectedBrand" CustomStringSelector="@(i => i?.Bezeichnung)">
  133. <ItemTemplate>
  134. <div>
  135. <span>@context?.Bezeichnung</span>
  136. </div>
  137. </ItemTemplate>
  138. </MatAutocompleteList>
  139. </div>
  140. </div>
  141. <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">
  142. <MatSelectValue Class="required" FullWidth="true" Outlined="true" Label="@i18n["Type"]" @bind-Value="selectedBcType" Items="@BicycleTypes" ValueSelector="@(i=>i)">
  143. <ItemTemplate>
  144. <div>
  145. <span>@context?.Bezeichnung</span>
  146. </div>
  147. </ItemTemplate>
  148. </MatSelectValue>
  149. </div>
  150. <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">
  151. <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">
  152. <MatStringField Class="w-100 form-check-label" Label="@i18n["FrameNumber"]" Outlined="true" type="text" @bind-Value="frameNumber"></MatStringField>
  153. </div>
  154. </div>
  155. <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">
  156. <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">
  157. <MatStringField Class="w-100 form-check-label" Label="@i18n["Remark"]" Outlined="true" type="text" @bind-Value="remark"></MatStringField>
  158. </div>
  159. </div>
  160. <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">
  161. <div>
  162. <MatCheckbox @bind-Value="@abholadresseIsNotContact" Label="@i18n["AlternatePickupContact"]"></MatCheckbox>
  163. </div>
  164. </div>
  165. </div>
  166. </div>
  167. </div>
  168. </div>
  169. </div>
  170. <div class="row no-gutters align-items-end justify-content-center w-100" style="padding-bottom:2em;padding-top:2em">
  171. <div class="col" style="padding-right:0.5em">
  172. <MatButton Class="w-100" Outlined="true" @onclick="Cancel">@i18n["Cancel"]</MatButton>
  173. </div>
  174. <div class="col" style="padding-left:0.5em">
  175. <MatButton Class="w-100" Raised="true" @onclick="Next">@i18n["Continue"]</MatButton>
  176. </div>
  177. </div>
  178. </div>
  179. @code {
  180. private static long MAX_FILE_SIZE = 3145728; //3MB
  181. private string imgUrl = string.Empty;
  182. private Boolean loading = false;
  183. private ColorItem selectedColor;
  184. private BicycleType selectedBcType;
  185. private string brandStringValue;
  186. private Brand selectedBrand;
  187. private Brand SelectedBrand {
  188. get { return selectedBrand; }
  189. set { selectedBrand = (value != null) ? value : new Brand(-999, brandStringValue); }
  190. }
  191. private void setBrandValue(string value) {
  192. brandStringValue = value;
  193. selectedBrand = null;
  194. }
  195. private string frameNumber;
  196. private string remark;
  197. private bool abholadresseIsNotContact;
  198. public void Dispose() {
  199. OnlineStatusProvider.RemoveOnlineStatusChangeCallBack(OnOnlineStatusChanged);
  200. }
  201. protected async override void OnInitialized() {
  202. base.OnInitialized();
  203. await GetColors();
  204. await GetBicycleTypes();
  205. await GetBrands();
  206. refreshGUIFromDto();
  207. PageHistoryManager.AddPageToHistory(NavigationManager.Uri);
  208. OnlineStatusProvider.AddOnlineStatusChangeCallBack(OnOnlineStatusChanged);
  209. StateHasChanged();
  210. }
  211. private void OnOnlineStatusChanged(bool isOnline) {
  212. StateHasChanged();
  213. }
  214. private async void AfterRenderMap() {
  215. FoundReport report = ReportDataProvider.GetFoundReport();
  216. if (report.GeographicInfo.Latitude != 0 && report.GeographicInfo.Longitude != 0) {
  217. bicycleGeoPosition.DisplayCity = await GetFormattedAddressZipAndTown(ReportDataProvider);
  218. LatLng coordinates = new LatLng(report.GeographicInfo.Latitude, report.GeographicInfo.Longitude);
  219. MouseEvent mouseEvent = new MouseEvent();
  220. mouseEvent.LatLng = coordinates;
  221. await InitializeBicycleMapPosition();
  222. await AddBicycleMarkerOnClickPosition(mouseEvent);
  223. StateHasChanged();
  224. }
  225. }
  226. private Brand getBrand(Brand brand) {
  227. return brand != null ? brand : new Brand(-999, "Test");
  228. }
  229. private async Task GetColors() {
  230. await MasterDataService.GetColors();
  231. }
  232. private async Task GetBicycleTypes() {
  233. await MasterDataService.GetBicycleTypes();
  234. }
  235. private async Task GetBrands() {
  236. await MasterDataService.GetBrands();
  237. }
  238. private ColorItem[] Colors {
  239. get => MasterDataService.Colors;
  240. }
  241. private BicycleType[] BicycleTypes {
  242. get => MasterDataService.BicycleTypes;
  243. }
  244. private Brand[] Brands {
  245. get => MasterDataService.Brands;
  246. }
  247. private void Next() {
  248. updateDtoFromGUI();
  249. if (abholadresseIsNotContact) {
  250. NavigationManager.NavigateTo("fundvelo/alternate_pickup");
  251. } else {
  252. NavigationManager.NavigateTo("fundvelo/account/Found");
  253. }
  254. }
  255. private void Cancel() {
  256. NavigationManager.NavigateTo("caritas_services");
  257. }
  258. private string getAddressLbl() {
  259. return i18n.GetString("Address") + " (" + i18n.GetString("PlaceOfDiscovery") + ")";
  260. }
  261. private async Task OnGatheringPicture(InputFileChangeEventArgs e) {
  262. IBrowserFile imgFile = e.File;
  263. var buffer = new byte[imgFile.Size];
  264. imgUrl = string.Empty;
  265. loading = true;
  266. StateHasChanged();
  267. try {
  268. using (var stream = imgFile.OpenReadStream(MAX_FILE_SIZE)) {
  269. await stream.ReadAsync(buffer);
  270. imgUrl = $"data:{imgFile.ContentType};base64,{Convert.ToBase64String(buffer)}";
  271. await stream.DisposeAsync();
  272. }
  273. } catch (IOException ex) {
  274. Console.WriteLine("Ex.Message is: {0}.", ex.Message);
  275. if (ex.Message.Contains("exceeds the maximum of")) {
  276. Toaster.ShowError(i18n.GetString("Error.PhotoOrPictureToBig.Title"), i18n.GetString("Error.PhotoOrPictureToBig.Msg", MAX_FILE_SIZE / (1024 * 1024)));
  277. } else {
  278. Toaster.ShowError(i18n.GetString("Error.IOException.Title"), i18n.GetString("Error.IOException.Msg"));
  279. }
  280. } catch (JSException ex) {
  281. Console.WriteLine("Ex.Message is: {0}.", ex.Message);
  282. } finally {
  283. Array.Clear(buffer, 0, buffer.Length);
  284. buffer = null;
  285. loading = false;
  286. StateHasChanged();
  287. }
  288. }
  289. private async void refreshGUIFromDto() {
  290. FoundReport report = ReportDataProvider.GetFoundReport();
  291. bicycleGeoPosition.Address = report.GeographicInfo.Address;
  292. bicycleGeoPosition.Zip = report.GeographicInfo.Postcode;
  293. bicycleGeoPosition.City = report.GeographicInfo.Town;
  294. bicycleGeoPosition.Latitude = report.GeographicInfo.Latitude;
  295. bicycleGeoPosition.Longitude = report.GeographicInfo.Longitude;
  296. bicycleGeoPosition.DisplayCity = await GetFormattedAddressZipAndTown(ReportDataProvider);
  297. imgUrl = report.FotoString;
  298. selectedColor = Array.Find(Colors, color => color.Id == report.FarbeId);
  299. selectedBrand = String.IsNullOrEmpty(report.NeueMarke) ? Array.Find(Brands, brand => brand.Id == report.MarkeId) : new Brand(-999, report.NeueMarke);
  300. selectedBcType = Array.Find(BicycleTypes, bcType => bcType.Id == report.TypId);
  301. frameNumber = report.RahmenNummer;
  302. remark = report.Bemerkung;
  303. abholadresseIsNotContact = !report.AbholadresseIstKontakt;
  304. StateHasChanged();
  305. }
  306. private void updateDtoFromGUI() {
  307. FoundReport report = ReportDataProvider.GetFoundReport();
  308. report.GeographicInfo.Address = bicycleGeoPosition.Address;
  309. report.GeographicInfo.Postcode = bicycleGeoPosition.Zip;
  310. report.GeographicInfo.Town = bicycleGeoPosition.City;
  311. report.GeographicInfo.Latitude = bicycleGeoPosition.Latitude;
  312. report.GeographicInfo.Longitude = bicycleGeoPosition.Longitude;
  313. report.FotoString = imgUrl;
  314. report.FarbeId = selectedColor != null ? selectedColor.Id : null;
  315. report.TypId = selectedBcType != null ? selectedBcType.Id : null;
  316. if (SelectedBrand != null) {
  317. if (SelectedBrand.Id == -999) {
  318. report.NeueMarke = SelectedBrand.Bezeichnung;
  319. } else {
  320. report.MarkeId = SelectedBrand.Id;
  321. }
  322. }
  323. report.RahmenNummer = frameNumber;
  324. report.Bemerkung = remark;
  325. report.AbholadresseIstKontakt = !abholadresseIsNotContact;
  326. }
  327. }