PWA Fundvelo der Caritas.
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

CaritasServiceFundVeloFoundKeyDataPage.razor 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  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. OnlineStatusProvider.AddOnlineStatusChangeCallBack(OnOnlineStatusChanged);
  208. StateHasChanged();
  209. }
  210. private void OnOnlineStatusChanged(bool isOnline) {
  211. StateHasChanged();
  212. }
  213. private async void AfterRenderMap() {
  214. FoundReport report = ReportDataProvider.GetFoundReport();
  215. MouseEvent mouseEvent = new MouseEvent();
  216. LatLng coordinates;
  217. LatLng devicePosition = await InitializeDeviceMapPosition();
  218. if (report != null && ((report.GeographicInfo.Latitude != 0 && report.GeographicInfo.Longitude != 0) ||
  219. (ReportDataProvider.ReportRepositoryItem != null && ReportDataProvider.ReportRepositoryItem.ID != 0))) {
  220. bicycleGeoPosition.DisplayCity = await GetFormattedAddressZipAndTown(ReportDataProvider);
  221. coordinates = new LatLng(report.GeographicInfo.Latitude, report.GeographicInfo.Longitude);
  222. mouseEvent.LatLng = coordinates;
  223. await InitializeBicycleMapPosition();
  224. await AddBicycleMarkerOnClickPosition(mouseEvent);
  225. StateHasChanged();
  226. } else { // Set bicycle postion equal to device position
  227. coordinates = new LatLng(devicePosition.Lat, devicePosition.Lng);
  228. mouseEvent.LatLng = coordinates;
  229. await OnMouseMapClicked(mouseEvent);
  230. }
  231. StateHasChanged();
  232. }
  233. private Brand getBrand(Brand brand) {
  234. return brand != null ? brand : new Brand(-999, "Test");
  235. }
  236. private async Task GetColors() {
  237. await MasterDataService.GetColors();
  238. }
  239. private async Task GetBicycleTypes() {
  240. await MasterDataService.GetBicycleTypes();
  241. }
  242. private async Task GetBrands() {
  243. await MasterDataService.GetBrands();
  244. }
  245. private ColorItem[] Colors {
  246. get => MasterDataService.Colors;
  247. }
  248. private BicycleType[] BicycleTypes {
  249. get => MasterDataService.BicycleTypes;
  250. }
  251. private Brand[] Brands {
  252. get => MasterDataService.Brands;
  253. }
  254. private void Next() {
  255. updateDtoFromGUI();
  256. PageHistoryManager.AddPageToHistory(NavigationManager.Uri);
  257. try {
  258. Validator.ValidateFoundReportKeyData(ReportDataProvider.GetFoundReport());
  259. if (abholadresseIsNotContact) {
  260. NavigationManager.NavigateTo("fundvelo/alternate_pickup");
  261. } else {
  262. NavigationManager.NavigateTo("fundvelo/account/Found");
  263. }
  264. } catch (ArgumentException) {
  265. Toaster.ShowWarning(I18n.GetString("Warning.MandatoryFields.Title"), I18n.GetString("Warning.MandatoryFields.Msg"));
  266. }
  267. }
  268. private void Cancel() {
  269. NavigationManager.NavigateTo("caritas_services");
  270. }
  271. private string getAddressLbl() {
  272. return I18n.GetString("Address") + " (" + I18n.GetString("PlaceOfDiscovery") + ")";
  273. }
  274. private async Task OnGatheringPicture(InputFileChangeEventArgs e) {
  275. IBrowserFile imgFile = e.File;
  276. var buffer = new byte[imgFile.Size];
  277. imgUrl = string.Empty;
  278. loading = true;
  279. StateHasChanged();
  280. try {
  281. using (var stream = imgFile.OpenReadStream(MAX_FILE_SIZE)) {
  282. await stream.ReadAsync(buffer);
  283. imgUrl = $"data:{imgFile.ContentType};base64,{Convert.ToBase64String(buffer)}";
  284. await stream.DisposeAsync();
  285. }
  286. } catch (IOException ex) {
  287. Console.WriteLine("Ex.Message is: {0}.", ex.Message);
  288. if (ex.Message.Contains("exceeds the maximum of")) {
  289. Toaster.ShowError(I18n.GetString("Error.PhotoOrPictureToBig.Title"), I18n.GetString("Error.PhotoOrPictureToBig.Msg", MAX_FILE_SIZE / (1024 * 1024)));
  290. } else {
  291. Toaster.ShowError(I18n.GetString("Error.IOException.Title"), I18n.GetString("Error.IOException.Msg"));
  292. }
  293. } catch (JSException ex) {
  294. Console.WriteLine("Ex.Message is: {0}.", ex.Message);
  295. } finally {
  296. Array.Clear(buffer, 0, buffer.Length);
  297. buffer = null;
  298. loading = false;
  299. StateHasChanged();
  300. }
  301. }
  302. private async void refreshGUIFromDto() {
  303. FoundReport report = ReportDataProvider.GetFoundReport();
  304. bicycleGeoPosition.Address = report.GeographicInfo.Address;
  305. bicycleGeoPosition.Zip = report.GeographicInfo.Postcode;
  306. bicycleGeoPosition.City = report.GeographicInfo.Town;
  307. bicycleGeoPosition.Latitude = report.GeographicInfo.Latitude;
  308. bicycleGeoPosition.Longitude = report.GeographicInfo.Longitude;
  309. bicycleGeoPosition.DisplayCity = await GetFormattedAddressZipAndTown(ReportDataProvider);
  310. imgUrl = report.FotoString;
  311. selectedColor = Array.Find(Colors, color => color.Id == report.FarbeId);
  312. selectedBrand = String.IsNullOrEmpty(report.NeueMarke) ? Array.Find(Brands, brand => brand.Id == report.MarkeId) : new Brand(-999, report.NeueMarke);
  313. selectedBcType = Array.Find(BicycleTypes, bcType => bcType.Id == report.TypId);
  314. frameNumber = report.RahmenNummer;
  315. remark = report.Bemerkung;
  316. abholadresseIsNotContact = !report.AbholadresseIstKontakt;
  317. StateHasChanged();
  318. }
  319. private void updateDtoFromGUI() {
  320. FoundReport report = ReportDataProvider.GetFoundReport();
  321. report.GeographicInfo.Address = bicycleGeoPosition.Address;
  322. report.GeographicInfo.Postcode = bicycleGeoPosition.Zip;
  323. report.GeographicInfo.Town = bicycleGeoPosition.City;
  324. report.GeographicInfo.Latitude = bicycleGeoPosition.Latitude;
  325. report.GeographicInfo.Longitude = bicycleGeoPosition.Longitude;
  326. report.FotoString = imgUrl;
  327. report.FarbeId = selectedColor != null ? selectedColor.Id : null;
  328. report.TypId = selectedBcType != null ? selectedBcType.Id : null;
  329. if (SelectedBrand != null) {
  330. if (SelectedBrand.Id == -999) {
  331. report.NeueMarke = SelectedBrand.Bezeichnung;
  332. report.MarkeId = null;
  333. } else {
  334. report.MarkeId = SelectedBrand.Id;
  335. }
  336. }
  337. report.RahmenNummer = frameNumber;
  338. report.Bemerkung = remark;
  339. report.AbholadresseIstKontakt = !abholadresseIsNotContact;
  340. }
  341. }