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 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  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. <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" AfterRender="AfterRenderMap"></Map>
  84. </div>
  85. </div>
  86. }
  87. <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">
  88. <div class="mat-layout-grid-inner">
  89. <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">
  90. <MatStringField Class="w-100 form-check-label" Label="@getAddressLbl()" Outlined="true" Required="true" type="text" @bind-Value="@bicycleGeoPosition.Address"></MatStringField>
  91. </div>
  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-12-desktop">
  93. <MatStringField Class="w-100 form-check-label" Label="@i18n["PlaceOfDiscovery"]" Outlined="true" Required="true" type="text" @bind-Value="@bicycleGeoPosition.DisplayCity"></MatStringField>
  94. </div>
  95. <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">
  96. <MatTextField Class="w-100 form-check-label italic" Label="@i18n["Latitude"]" Outlined="true" ReadOnly="true" @bind-Value="@bicycleGeoPosition.Latitude"></MatTextField>
  97. </div>
  98. <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">
  99. <MatTextField Class="w-100 form-check-label italic" Label="@i18n["Longitude"]" Outlined="true" ReadOnly="true" @bind-Value="@bicycleGeoPosition.Longitude"></MatTextField>
  100. </div>
  101. </div>
  102. </div>
  103. <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">
  104. <div class="mat-layout-grid-inner">
  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. <MatSelectValue Class="required" FullWidth="true" Outlined="true" Label="@i18n["Color"]" @bind-Value="selectedColor" Items="@Colors" ValueSelector="@(i=>i)">
  107. <ItemTemplate>
  108. <div>
  109. <span class="btn-sm" style="background-color:@context.Code;
  110. display:initial;
  111. border:1px solid black;
  112. box-shadow:0.2em 0.2em 0.3em 0.025em #3f4244" />
  113. <span class="btn">@context?.Bezeichnung</span>
  114. </div>
  115. </ItemTemplate>
  116. </MatSelectValue>
  117. </div>
  118. <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">
  119. <div class="outlined">
  120. <MatAutocompleteList TItem="Brand" FullWidth="true" Label="@i18n["Brand"]" Required="true" Items="@Brands" OnTextChanged="setBrandValue" @bind-Value="SelectedBrand" CustomStringSelector="@(i => i?.Bezeichnung)">
  121. <ItemTemplate>
  122. <div>
  123. <span>@context?.Bezeichnung</span>
  124. </div>
  125. </ItemTemplate>
  126. </MatAutocompleteList>
  127. </div>
  128. </div>
  129. <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">
  130. <MatSelectValue Class="required" FullWidth="true" Outlined="true" Label="@i18n["Type"]" @bind-Value="selectedBcType" Items="@BicycleTypes" ValueSelector="@(i=>i)">
  131. <ItemTemplate>
  132. <div>
  133. <span>@context?.Bezeichnung</span>
  134. </div>
  135. </ItemTemplate>
  136. </MatSelectValue>
  137. </div>
  138. <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">
  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-12-desktop">
  140. <MatStringField Class="w-100 form-check-label" Label="@i18n["FrameNumber"]" Outlined="true" type="text" @bind-Value="frameNumber"></MatStringField>
  141. </div>
  142. </div>
  143. <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">
  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-12-desktop">
  145. <MatStringField Class="w-100 form-check-label" Label="@i18n["Remark"]" Outlined="true" type="text" @bind-Value="remark"></MatStringField>
  146. </div>
  147. </div>
  148. <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">
  149. <div>
  150. <MatCheckbox @bind-Value="@abholadresseIsNotContact" Label="@i18n["AlternatePickupContact"]"></MatCheckbox>
  151. </div>
  152. </div>
  153. </div>
  154. </div>
  155. </div>
  156. </div>
  157. </div>
  158. <div class="row no-gutters align-items-end justify-content-center w-100" style="padding-bottom:2em;padding-top:2em">
  159. <div class="col" style="padding-right:0.5em">
  160. <MatButton Class="w-100" Outlined="true" @onclick="Cancel">@i18n["Cancel"]</MatButton>
  161. </div>
  162. <div class="col" style="padding-left:0.5em">
  163. <MatButton Class="w-100" Raised="true" @onclick="Next">@i18n["Continue"]</MatButton>
  164. </div>
  165. </div>
  166. </div>
  167. @code {
  168. private static long MAX_FILE_SIZE = 3145728; //3MB
  169. private string imgUrl = string.Empty;
  170. private Boolean loading = false;
  171. private ColorItem selectedColor;
  172. private BicycleType selectedBcType;
  173. private string brandStringValue;
  174. private Brand selectedBrand;
  175. private Brand SelectedBrand {
  176. get { return selectedBrand; }
  177. set { selectedBrand = (value != null) ? value : new Brand(-999, brandStringValue); }
  178. }
  179. private void setBrandValue(string value) {
  180. brandStringValue = value;
  181. selectedBrand = null;
  182. }
  183. private string frameNumber;
  184. private string remark;
  185. private bool abholadresseIsNotContact;
  186. public void Dispose() {
  187. OnlineStatusProvider.RemoveOnlineStatusChangeCallBack(OnOnlineStatusChanged);
  188. }
  189. protected async override void OnInitialized() {
  190. base.OnInitialized();
  191. await GetColors();
  192. await GetBicycleTypes();
  193. await GetBrands();
  194. refreshGUIFromDto();
  195. PageHistoryManager.AddPageToHistory(NavigationManager.Uri);
  196. OnlineStatusProvider.AddOnlineStatusChangeCallBack(OnOnlineStatusChanged);
  197. StateHasChanged();
  198. }
  199. private void OnOnlineStatusChanged(bool isOnline) {
  200. StateHasChanged();
  201. }
  202. private async void AfterRenderMap() {
  203. FoundReport report = ReportDataProvider.GetFoundReport();
  204. if (report.GeographicInfo.Latitude != 0 && report.GeographicInfo.Longitude != 0) {
  205. bicycleGeoPosition.DisplayCity = GetFormattedAddressZipAndTown();
  206. LatLng coordinates = new LatLng(report.GeographicInfo.Latitude, report.GeographicInfo.Longitude);
  207. MouseEvent mouseEvent = new MouseEvent();
  208. mouseEvent.LatLng = coordinates;
  209. await InitializeMapPosition();
  210. await AddBicycleMarkerOnClickPosition(mouseEvent);
  211. }
  212. }
  213. private Brand getBrand(Brand brand) {
  214. return brand != null ? brand : new Brand(-999, "Test");
  215. }
  216. private async Task GetColors() {
  217. await MasterDataService.GetColors();
  218. }
  219. private async Task GetBicycleTypes() {
  220. await MasterDataService.GetBicycleTypes();
  221. }
  222. private async Task GetBrands() {
  223. await MasterDataService.GetBrands();
  224. }
  225. private ColorItem[] Colors {
  226. get => MasterDataService.Colors;
  227. }
  228. private BicycleType[] BicycleTypes {
  229. get => MasterDataService.BicycleTypes;
  230. }
  231. private Brand[] Brands {
  232. get => MasterDataService.Brands;
  233. }
  234. private void Next() {
  235. updateDtoFromGUI();
  236. if (abholadresseIsNotContact) {
  237. NavigationManager.NavigateTo("fundvelo/alternate_pickup");
  238. } else {
  239. NavigationManager.NavigateTo("fundvelo/account/Found");
  240. }
  241. }
  242. private void Cancel() {
  243. NavigationManager.NavigateTo("caritas_services");
  244. }
  245. private string getAddressLbl() {
  246. return i18n.GetString("Address") + " (" + i18n.GetString("PlaceOfDiscovery") + ")";
  247. }
  248. private async Task OnGatheringPicture(InputFileChangeEventArgs e) {
  249. IBrowserFile imgFile = e.File;
  250. var buffer = new byte[imgFile.Size];
  251. imgUrl = string.Empty;
  252. loading = true;
  253. StateHasChanged();
  254. try {
  255. using (var stream = imgFile.OpenReadStream(MAX_FILE_SIZE)) {
  256. await stream.ReadAsync(buffer);
  257. imgUrl = $"data:{imgFile.ContentType};base64,{Convert.ToBase64String(buffer)}";
  258. await stream.DisposeAsync();
  259. }
  260. } catch (IOException ex) {
  261. Console.WriteLine("Ex.Message is: {0}.", ex.Message);
  262. if (ex.Message.Contains("exceeds the maximum of")) {
  263. Toaster.ShowError(i18n.GetString("Error.PhotoOrPictureToBig.Title"), i18n.GetString("Error.PhotoOrPictureToBig.Msg", MAX_FILE_SIZE / (1024 * 1024)));
  264. } else {
  265. Toaster.ShowError(i18n.GetString("Error.IOException.Title"), i18n.GetString("Error.IOException.Msg"));
  266. }
  267. } catch (JSException ex) {
  268. Console.WriteLine("Ex.Message is: {0}.", ex.Message);
  269. } finally {
  270. Array.Clear(buffer, 0, buffer.Length);
  271. buffer = null;
  272. loading = false;
  273. StateHasChanged();
  274. }
  275. }
  276. private void refreshGUIFromDto() {
  277. FoundReport report = ReportDataProvider.GetFoundReport();
  278. bicycleGeoPosition.Address = report.GeographicInfo.Address;
  279. bicycleGeoPosition.Zip = report.GeographicInfo.Postcode;
  280. bicycleGeoPosition.City = report.GeographicInfo.Town;
  281. bicycleGeoPosition.Latitude = report.GeographicInfo.Latitude;
  282. bicycleGeoPosition.Longitude = report.GeographicInfo.Longitude;
  283. imgUrl = report.FotoString;
  284. selectedColor = Array.Find(Colors, color => color.Id == report.FarbeId);
  285. selectedBrand = String.IsNullOrEmpty(report.NeueMarke) ? Array.Find(Brands, brand => brand.Id == report.MarkeId) : new Brand(-999, report.NeueMarke);
  286. selectedBcType = Array.Find(BicycleTypes, bcType => bcType.Id == report.TypId);
  287. frameNumber = report.RahmenNummer;
  288. remark = report.Bemerkung;
  289. abholadresseIsNotContact = !report.AbholadresseIstKontakt;
  290. }
  291. private void updateDtoFromGUI() {
  292. FoundReport report = ReportDataProvider.GetFoundReport();
  293. report.GeographicInfo.Address = bicycleGeoPosition.Address;
  294. report.GeographicInfo.Postcode = bicycleGeoPosition.Zip;
  295. report.GeographicInfo.Town = bicycleGeoPosition.City;
  296. report.GeographicInfo.Latitude = bicycleGeoPosition.Latitude;
  297. report.GeographicInfo.Longitude = bicycleGeoPosition.Longitude;
  298. report.FotoString = imgUrl;
  299. report.FarbeId = selectedColor != null ? selectedColor.Id : null;
  300. report.TypId = selectedBcType != null ? selectedBcType.Id : null;
  301. if (SelectedBrand != null) {
  302. if (SelectedBrand.Id == -999) {
  303. report.NeueMarke = SelectedBrand.Bezeichnung;
  304. } else {
  305. report.MarkeId = SelectedBrand.Id;
  306. }
  307. }
  308. report.RahmenNummer = frameNumber;
  309. report.Bemerkung = remark;
  310. report.AbholadresseIstKontakt = !abholadresseIsNotContact;
  311. }
  312. }