Commit fad3b6f3 by Mac Stephens

Fix auth duplication, request IP logging, and stale map focus

parent 6491a54f
...@@ -206,7 +206,6 @@ var ...@@ -206,7 +206,6 @@ var
JWT: TJWT; JWT: TJWT;
begin begin
Logger.Log(1, Format('AuthService.Login - User: "%s" Agency: "%s"', [User, Agency])); Logger.Log(1, Format('AuthService.Login - User: "%s" Agency: "%s"', [User, Agency]));
userState := CheckUser(User, Password, Agency);
try try
userState := CheckUser(User, Password, Agency); userState := CheckUser(User, Password, Agency);
......
...@@ -148,7 +148,7 @@ begin ...@@ -148,7 +148,7 @@ begin
Result := ''; Result := '';
Msg := TStringList.Create; Msg := TStringList.Create;
try try
Msg.Add(Format('%s %s %s', Msg.Add(Format('%s %s %s %s',
[ [
FMethod, FMethod,
FUriPath + FUriQuery, FUriPath + FUriQuery,
......
...@@ -15,6 +15,7 @@ function FormatPhoneNumber(PhoneNumber: string): string; ...@@ -15,6 +15,7 @@ function FormatPhoneNumber(PhoneNumber: string): string;
procedure ApplyReportTitle(CurrentReportType: string); procedure ApplyReportTitle(CurrentReportType: string);
procedure ShowToast(const MessageText: string; const ToastType: string = 'success'); procedure ShowToast(const MessageText: string; const ToastType: string = 'success');
procedure ShowConfirmationModal(msg, leftLabel, rightLabel: string; ConfirmProc: TProc<Boolean>); procedure ShowConfirmationModal(msg, leftLabel, rightLabel: string; ConfirmProc: TProc<Boolean>);
procedure ShowInformationModal(const Title, MessageText: string);
// function FormatDollarValue(ValueStr: string): string; // function FormatDollarValue(ValueStr: string): string;
...@@ -220,6 +221,28 @@ begin ...@@ -220,6 +221,28 @@ begin
end; end;
procedure ShowInformationModal(const Title, MessageText: string);
begin
asm
var modal = document.getElementById('main_information_modal');
var title = document.getElementById('main_information_modal_title');
var body = document.getElementById('main_information_modal_body');
if (!modal) return;
if (title) title.innerText = Title;
if (body) body.innerText = MessageText;
if (modal.parentNode !== document.body) {
document.body.appendChild(modal);
}
var bsModal = bootstrap.Modal.getOrCreateInstance(modal);
bsModal.show();
end;
end;
function CalculateAge(DateOfBirth: TDateTime): Integer; function CalculateAge(DateOfBirth: TDateTime): Integer;
var var
Today, BirthDate: TJSDate; Today, BirthDate: TJSDate;
......
...@@ -79,6 +79,23 @@ ...@@ -79,6 +79,23 @@
</nav> </nav>
</div> </div>
<!-- Information modal -->
<div class="modal fade" id="main_information_modal" tabindex="-1"
aria-labelledby="main_information_modal_title" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered modal-sm mx-auto px-3">
<div class="modal-content shadow-lg">
<div class="modal-header">
<h5 class="modal-title" id="main_information_modal_title">Information</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body fs-6 fw-bold" id="main_information_modal_body"></div>
<div class="modal-footer">
<button type="button" class="btn btn-primary w-100" data-bs-dismiss="modal">OK</button>
</div>
</div>
</div>
</div>
<!-- Spinner --> <!-- Spinner -->
<div id="spinner" class="position-absolute top-50 start-50 translate-middle d-none"> <div id="spinner" class="position-absolute top-50 start-50 translate-middle d-none">
<div class="lds-roller"> <div class="lds-roller">
......
...@@ -37,6 +37,9 @@ type ...@@ -37,6 +37,9 @@ type
FPendingFocusCoord: TTMSFNCMapsCoordinateRec; FPendingFocusCoord: TTMSFNCMapsCoordinateRec;
FPendingFocusZoom: Integer; FPendingFocusZoom: Integer;
FDoFocusZoom: Boolean; FDoFocusZoom: Boolean;
FPendingFocusMarkerData: string;
FPendingWsUnitMapData: TJSArray;
FPendingWsComplaintMapData: TJSArray;
FGeoJsonLoadStep: Integer; FGeoJsonLoadStep: Integer;
[async] procedure LoadPointsAsync(showBusy: Boolean); [async] procedure LoadPointsAsync(showBusy: Boolean);
...@@ -307,6 +310,22 @@ begin ...@@ -307,6 +310,22 @@ begin
Console.Log('Complaints XData error: ' + E.ErrorResult.ErrorMessage); Console.Log('Complaints XData error: ' + E.ErrorResult.ErrorMessage);
end; end;
// A WebSocket snapshot received while the HTTP requests were in flight is
// newer than those responses, so use the latest pushed data for the map.
if Assigned(FPendingWsUnitMapData) then
begin
unitsData := FPendingWsUnitMapData;
FPendingWsUnitMapData := nil;
FUnitsLoaded := True;
end;
if Assigned(FPendingWsComplaintMapData) then
begin
complaintsData := FPendingWsComplaintMapData;
FPendingWsComplaintMapData := nil;
FComplaintsLoaded := True;
end;
// --- Place markers (BeginUpdate wraps both so the map redraws once) ------ // --- Place markers (BeginUpdate wraps both so the map redraws once) ------
lfMap.BeginUpdate; lfMap.BeginUpdate;
try try
...@@ -553,8 +572,13 @@ end; ...@@ -553,8 +572,13 @@ end;
procedure TFViewMap.ApplyWsUnitMapData(aData: TJSArray); procedure TFViewMap.ApplyWsUnitMapData(aData: TJSArray);
begin begin
// Skip if the map is still initialising or an HTTP load is in flight. if FLoadingPoints then
if (not Assigned(mapFilters)) or FLoadingPoints then begin
FPendingWsUnitMapData := aData;
Exit;
end;
if not Assigned(mapFilters) then
Exit; Exit;
lfMap.BeginUpdate; lfMap.BeginUpdate;
...@@ -570,7 +594,13 @@ end; ...@@ -570,7 +594,13 @@ end;
procedure TFViewMap.ApplyWsComplaintMapData(aData: TJSArray); procedure TFViewMap.ApplyWsComplaintMapData(aData: TJSArray);
begin begin
if (not Assigned(mapFilters)) or FLoadingPoints then if FLoadingPoints then
begin
FPendingWsComplaintMapData := aData;
Exit;
end;
if not Assigned(mapFilters) then
Exit; Exit;
lfMap.BeginUpdate; lfMap.BeginUpdate;
...@@ -641,15 +671,47 @@ begin ...@@ -641,15 +671,47 @@ begin
end; end;
procedure TFViewMap.tmrLocateTimer(Sender: TObject); procedure TFViewMap.tmrLocateTimer(Sender: TObject);
var
i: Integer;
markerFound: Boolean;
missingTarget: string;
begin begin
tmrLocate.Enabled := False; tmrLocate.Enabled := False;
if not FDoFocusZoom then if not FDoFocusZoom then
Exit; Exit;
if FPendingFocusMarkerData <> '' then
begin
markerFound := False;
for i := 0 to lfMap.Markers.Count - 1 do
if SameText(lfMap.Markers[i].DataString, FPendingFocusMarkerData) or
StartsText(FPendingFocusMarkerData + '|', lfMap.Markers[i].DataString) then
begin
markerFound := True;
Break;
end;
if not markerFound then
begin
missingTarget := FPendingFocusMarkerData;
FPendingFocusMarkerData := '';
FDoFocusZoom := False;
if StartsText('unit|', missingTarget) then
ShowInformationModal('No Longer Available',
'This unit is no longer available on the map.')
else if StartsText('complaint|', missingTarget) then
ShowInformationModal('No Longer Available',
'This complaint is no longer active on the map.');
Exit;
end;
end;
lfMap.SetCenterCoordinate(FPendingFocusCoord); lfMap.SetCenterCoordinate(FPendingFocusCoord);
lfMap.SetZoomLevel(FPendingFocusZoom); lfMap.SetZoomLevel(FPendingFocusZoom);
FPendingFocusMarkerData := '';
FDoFocusZoom := False; FDoFocusZoom := False;
end; end;
...@@ -666,6 +728,7 @@ begin ...@@ -666,6 +728,7 @@ begin
FPendingFocusCoord := coord; FPendingFocusCoord := coord;
FPendingFocusZoom := 17; FPendingFocusZoom := 17;
FDoFocusZoom := True; FDoFocusZoom := True;
FPendingFocusMarkerData := '';
tmrLocate.Interval := 250; tmrLocate.Interval := 250;
tmrLocate.Enabled := True; tmrLocate.Enabled := True;
...@@ -674,6 +737,10 @@ end; ...@@ -674,6 +737,10 @@ end;
procedure TFViewMap.FocusUnit(const unitId: string); procedure TFViewMap.FocusUnit(const unitId: string);
begin begin
tmrLocate.Enabled := False;
FDoFocusZoom := False;
FPendingFocusMarkerData := '';
FPendingComplaintId := '';
FPendingUnitId := Trim(unitId); FPendingUnitId := Trim(unitId);
if mapFilters <> nil then if mapFilters <> nil then
LoadPointsAsync(True); LoadPointsAsync(True);
...@@ -682,6 +749,10 @@ end; ...@@ -682,6 +749,10 @@ end;
procedure TFViewMap.FocusComplaint(const complaintId: string); procedure TFViewMap.FocusComplaint(const complaintId: string);
begin begin
tmrLocate.Enabled := False;
FDoFocusZoom := False;
FPendingFocusMarkerData := '';
FPendingUnitId := '';
FPendingComplaintId := Trim(complaintId); FPendingComplaintId := Trim(complaintId);
if mapFilters <> nil then if mapFilters <> nil then
LoadPointsAsync(True); LoadPointsAsync(True);
...@@ -713,6 +784,7 @@ begin ...@@ -713,6 +784,7 @@ begin
FPendingFocusCoord := coord; FPendingFocusCoord := coord;
FPendingFocusZoom := 17; FPendingFocusZoom := 17;
FDoFocusZoom := True; FDoFocusZoom := True;
FPendingFocusMarkerData := targetDs;
tmrLocate.Interval := 250; tmrLocate.Interval := 250;
tmrLocate.Enabled := True; tmrLocate.Enabled := True;
...@@ -722,8 +794,15 @@ begin ...@@ -722,8 +794,15 @@ begin
end; end;
end; end;
if found then FPendingUnitId := '';
FPendingUnitId := '';
if not found then
begin
FPendingFocusMarkerData := '';
FDoFocusZoom := False;
ShowInformationModal('No Longer Available',
'This unit is no longer available on the map.');
end;
end; end;
procedure TFViewMap.ApplyPendingComplaintFocus; procedure TFViewMap.ApplyPendingComplaintFocus;
...@@ -751,6 +830,7 @@ begin ...@@ -751,6 +830,7 @@ begin
FPendingFocusCoord := coord; FPendingFocusCoord := coord;
FPendingFocusZoom := 17; FPendingFocusZoom := 17;
FDoFocusZoom := True; FDoFocusZoom := True;
FPendingFocusMarkerData := targetDs;
tmrLocate.Interval := 250; tmrLocate.Interval := 250;
tmrLocate.Enabled := True; tmrLocate.Enabled := True;
...@@ -760,8 +840,15 @@ begin ...@@ -760,8 +840,15 @@ begin
end; end;
end; end;
if found then FPendingComplaintId := '';
FPendingComplaintId := '';
if not found then
begin
FPendingFocusMarkerData := '';
FDoFocusZoom := False;
ShowInformationModal('No Longer Available',
'This complaint is no longer active on the map.');
end;
end; end;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment