Commit fad3b6f3 by Mac Stephens

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

parent 6491a54f
......@@ -206,7 +206,6 @@ var
JWT: TJWT;
begin
Logger.Log(1, Format('AuthService.Login - User: "%s" Agency: "%s"', [User, Agency]));
userState := CheckUser(User, Password, Agency);
try
userState := CheckUser(User, Password, Agency);
......
......@@ -148,7 +148,7 @@ begin
Result := '';
Msg := TStringList.Create;
try
Msg.Add(Format('%s %s %s',
Msg.Add(Format('%s %s %s %s',
[
FMethod,
FUriPath + FUriQuery,
......
......@@ -15,6 +15,7 @@ function FormatPhoneNumber(PhoneNumber: string): string;
procedure ApplyReportTitle(CurrentReportType: string);
procedure ShowToast(const MessageText: string; const ToastType: string = 'success');
procedure ShowConfirmationModal(msg, leftLabel, rightLabel: string; ConfirmProc: TProc<Boolean>);
procedure ShowInformationModal(const Title, MessageText: string);
// function FormatDollarValue(ValueStr: string): string;
......@@ -220,6 +221,28 @@ begin
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;
var
Today, BirthDate: TJSDate;
......
......@@ -79,6 +79,23 @@
</nav>
</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 -->
<div id="spinner" class="position-absolute top-50 start-50 translate-middle d-none">
<div class="lds-roller">
......
......@@ -37,6 +37,9 @@ type
FPendingFocusCoord: TTMSFNCMapsCoordinateRec;
FPendingFocusZoom: Integer;
FDoFocusZoom: Boolean;
FPendingFocusMarkerData: string;
FPendingWsUnitMapData: TJSArray;
FPendingWsComplaintMapData: TJSArray;
FGeoJsonLoadStep: Integer;
[async] procedure LoadPointsAsync(showBusy: Boolean);
......@@ -307,6 +310,22 @@ begin
Console.Log('Complaints XData error: ' + E.ErrorResult.ErrorMessage);
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) ------
lfMap.BeginUpdate;
try
......@@ -553,8 +572,13 @@ end;
procedure TFViewMap.ApplyWsUnitMapData(aData: TJSArray);
begin
// Skip if the map is still initialising or an HTTP load is in flight.
if (not Assigned(mapFilters)) or FLoadingPoints then
if FLoadingPoints then
begin
FPendingWsUnitMapData := aData;
Exit;
end;
if not Assigned(mapFilters) then
Exit;
lfMap.BeginUpdate;
......@@ -570,7 +594,13 @@ end;
procedure TFViewMap.ApplyWsComplaintMapData(aData: TJSArray);
begin
if (not Assigned(mapFilters)) or FLoadingPoints then
if FLoadingPoints then
begin
FPendingWsComplaintMapData := aData;
Exit;
end;
if not Assigned(mapFilters) then
Exit;
lfMap.BeginUpdate;
......@@ -641,15 +671,47 @@ begin
end;
procedure TFViewMap.tmrLocateTimer(Sender: TObject);
var
i: Integer;
markerFound: Boolean;
missingTarget: string;
begin
tmrLocate.Enabled := False;
if not FDoFocusZoom then
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.SetZoomLevel(FPendingFocusZoom);
FPendingFocusMarkerData := '';
FDoFocusZoom := False;
end;
......@@ -666,6 +728,7 @@ begin
FPendingFocusCoord := coord;
FPendingFocusZoom := 17;
FDoFocusZoom := True;
FPendingFocusMarkerData := '';
tmrLocate.Interval := 250;
tmrLocate.Enabled := True;
......@@ -674,6 +737,10 @@ end;
procedure TFViewMap.FocusUnit(const unitId: string);
begin
tmrLocate.Enabled := False;
FDoFocusZoom := False;
FPendingFocusMarkerData := '';
FPendingComplaintId := '';
FPendingUnitId := Trim(unitId);
if mapFilters <> nil then
LoadPointsAsync(True);
......@@ -682,6 +749,10 @@ end;
procedure TFViewMap.FocusComplaint(const complaintId: string);
begin
tmrLocate.Enabled := False;
FDoFocusZoom := False;
FPendingFocusMarkerData := '';
FPendingUnitId := '';
FPendingComplaintId := Trim(complaintId);
if mapFilters <> nil then
LoadPointsAsync(True);
......@@ -713,6 +784,7 @@ begin
FPendingFocusCoord := coord;
FPendingFocusZoom := 17;
FDoFocusZoom := True;
FPendingFocusMarkerData := targetDs;
tmrLocate.Interval := 250;
tmrLocate.Enabled := True;
......@@ -722,8 +794,15 @@ begin
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;
procedure TFViewMap.ApplyPendingComplaintFocus;
......@@ -751,6 +830,7 @@ begin
FPendingFocusCoord := coord;
FPendingFocusZoom := 17;
FDoFocusZoom := True;
FPendingFocusMarkerData := targetDs;
tmrLocate.Interval := 250;
tmrLocate.Enabled := True;
......@@ -760,8 +840,15 @@ begin
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;
......
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