Commit 2366105b by Mac Stephens

Update timer system to work with units and complaints and map form, add new…

Update timer system to work with units and complaints and map form, add new panels for navigation, change warnings table to cards on small size
parent 375df95d
...@@ -590,17 +590,66 @@ object ApiDatabaseModule: TApiDatabaseModule ...@@ -590,17 +590,66 @@ object ApiDatabaseModule: TApiDatabaseModule
' a.STRPREFIX,' ' a.STRPREFIX,'
' a.STRNAME,' ' a.STRNAME,'
' a.STRSUFFIX,' ' a.STRSUFFIX,'
' a.CITY' ' a.CITY.'
' 0 as status'
'FROM COMPLAINT_ACTIVE ca' 'FROM COMPLAINT_ACTIVE ca'
'JOIN COMPLAINT_TIMES ct' 'JOIN COMPLAINT_TIMES ct'
' ON ca.COMPLAINTID = ct.COMPLAINTID' ' ON ca.COMPLAINTID = ct.COMPLAINTID'
'LEFT JOIN CD_DISPATCHCODES cdc' 'LEFT JOIN CD_DISPATCHCODES cdc'
' ON ca.DISPATCHCODE = cdc.CODE' ' ON ca.DISPATCHCODE = cdc.CODE'
'JOIN CD_DISTRICT cd' 'LEFT JOIN CD_DISTRICT cd'
' ON cd.AGENCYCODE = ca.DISPATCHDISTRICT'
'LEFT JOIN ADDRESS a'
' ON ca.ADDRESSID = a.ADDRESSID'
'WHERE ca.COMPLAINTID = :COMPLAINTID'
''
'union'
''
'SELECT'
' ca.COMPLAINTID,'
' ca.CFSID,'
' ca.COMPLAINT,'
' ca.PRIORITY,'
' ca.DISPATCHCODE,'
' cdc.CODE_DESC AS DISPATCH_CODE_DESC,'
' cd.CODE_DESC AS DISPATCHDISTRICT,'
' ca.ADDRESS,'
' ca.BUSINESS,'
' ct.DATEREPORTED,'
' ct.DATERECEIVED,'
' ct.DATEDISPATCHED,'
' ct.DATERESPONDED,'
' ct.DATEARRIVED,'
' ct.DATECLEARED,'
''
' -- For enabling/disabling buttons (disable when = '#39'-1'#39')'
' ca.HISTORY,'
' ca.CONTACTS,'
' ca.WARNINGS,'
''
' -- For Contacts + Warnings lookups'
' ca.ADDRESSID,'
' ca.AGENCY,'
''
' -- For History matching (address parts)'
' a.STRNUMBER,'
' a.STRHNUMBER,'
' a.STRPREFIX,'
' a.STRNAME,'
' a.STRSUFFIX,'
' a.CITY.'
' 1 as status'
'FROM COMPLAINT_ARCHIVE ca'
'JOIN COMPLAINT_TIMES ct'
' ON ca.COMPLAINTID = ct.COMPLAINTID'
'LEFT JOIN CD_DISPATCHCODES cdc'
' ON ca.DISPATCHCODE = cdc.CODE'
'LEFT JOIN CD_DISTRICT cd'
' ON cd.AGENCYCODE = ca.DISPATCHDISTRICT' ' ON cd.AGENCYCODE = ca.DISPATCHDISTRICT'
'LEFT JOIN ADDRESS a' 'LEFT JOIN ADDRESS a'
' ON ca.ADDRESSID = a.ADDRESSID' ' ON ca.ADDRESSID = a.ADDRESSID'
'WHERE ca.COMPLAINTID = :COMPLAINTID;') 'WHERE ca.COMPLAINTID = :COMPLAINTID;'
'')
ReadOnly = True ReadOnly = True
Left = 80 Left = 80
Top = 302 Top = 302
...@@ -608,7 +657,7 @@ object ApiDatabaseModule: TApiDatabaseModule ...@@ -608,7 +657,7 @@ object ApiDatabaseModule: TApiDatabaseModule
item item
DataType = ftUnknown DataType = ftUnknown
Name = 'COMPLAINTID' Name = 'COMPLAINTID'
Value = Null Value = nil
end> end>
object uqComplaintDetailsCOMPLAINTID: TFloatField object uqComplaintDetailsCOMPLAINTID: TFloatField
FieldName = 'COMPLAINTID' FieldName = 'COMPLAINTID'
......
[Settings] [Settings]
LogFileNum=625 LogFileNum=627
webClientVersion=0.1.0 webClientVersion=0.1.0
...@@ -360,8 +360,8 @@ object FViewComplaintDetails: TFViewComplaintDetails ...@@ -360,8 +360,8 @@ object FViewComplaintDetails: TFViewComplaintDetails
ListSource = wdsWarnings ListSource = wdsWarnings
end end
object btnComplaintViewOnMap: TWebButton object btnComplaintViewOnMap: TWebButton
Left = 510 Left = 687
Top = 430 Top = 496
Width = 96 Width = 96
Height = 25 Height = 25
Caption = 'Map' Caption = 'Map'
...@@ -430,8 +430,8 @@ object FViewComplaintDetails: TFViewComplaintDetails ...@@ -430,8 +430,8 @@ object FViewComplaintDetails: TFViewComplaintDetails
Top = 350 Top = 350
end end
object xdwdsContacts: TXDataWebDataSet object xdwdsContacts: TXDataWebDataSet
Left = 436 Left = 438
Top = 352 Top = 350
object xdwdsContactsName: TStringField object xdwdsContactsName: TStringField
FieldName = 'Name' FieldName = 'Name'
end end
...@@ -448,11 +448,11 @@ object FViewComplaintDetails: TFViewComplaintDetails ...@@ -448,11 +448,11 @@ object FViewComplaintDetails: TFViewComplaintDetails
object wdsContacts: TWebDataSource object wdsContacts: TWebDataSource
DataSet = xdwdsContacts DataSet = xdwdsContacts
Left = 530 Left = 530
Top = 352 Top = 350
end end
object xdwdsWarnings: TXDataWebDataSet object xdwdsWarnings: TXDataWebDataSet
Left = 634 Left = 612
Top = 492 Top = 424
object xdwdsWarningsCodeDesc: TStringField object xdwdsWarningsCodeDesc: TStringField
FieldName = 'CodeDesc' FieldName = 'CodeDesc'
end end
...@@ -465,7 +465,7 @@ object FViewComplaintDetails: TFViewComplaintDetails ...@@ -465,7 +465,7 @@ object FViewComplaintDetails: TFViewComplaintDetails
end end
object wdsWarnings: TWebDataSource object wdsWarnings: TWebDataSource
DataSet = xdwdsWarnings DataSet = xdwdsWarnings
Left = 728 Left = 712
Top = 492 Top = 424
end end
end end
...@@ -121,10 +121,4 @@ object FViewComplaints: TFViewComplaints ...@@ -121,10 +121,4 @@ object FViewComplaints: TFViewComplaints
Left = 156 Left = 156
Top = 410 Top = 410
end end
object tmrRefresh: TWebTimer
Interval = 30000
OnTimer = tmrRefreshTimer
Left = 164
Top = 44
end
end end
...@@ -31,20 +31,19 @@ type ...@@ -31,20 +31,19 @@ type
xdwdsComplaintsPriorityColor: TStringField; xdwdsComplaintsPriorityColor: TStringField;
xdwdsComplaintsPriorityTextColor: TStringField; xdwdsComplaintsPriorityTextColor: TStringField;
xdwdsComplaintsDistrictSector: TStringField; xdwdsComplaintsDistrictSector: TStringField;
tmrRefresh: TWebTimer;
xdwdsComplaintsBusiness: TStringField; xdwdsComplaintsBusiness: TStringField;
procedure WebFormCreate(Sender: TObject); procedure WebFormCreate(Sender: TObject);
procedure btnRefreshClick(Sender: TObject);
procedure tmrRefreshTimer(Sender: TObject);
procedure WebFormDestroy(Sender: TObject); procedure WebFormDestroy(Sender: TObject);
private private
FSelectProc: TSelectProc; FSelectProc: TSelectProc;
FLoading: Boolean; FLoading: Boolean;
FFirstLoad: Boolean;
[async] procedure GetComplaints; [async] procedure GetComplaints;
procedure HandleListClick(e: TJSMouseEvent); procedure HandleListClick(e: TJSMouseEvent);
procedure ShowHideBusinessRows; procedure ShowHideBusinessRows;
public public
property OnShowDetails: TSelectProc read FSelectProc write FSelectProc; property OnShowDetails: TSelectProc read FSelectProc write FSelectProc;
procedure RefreshData;
end; end;
var var
...@@ -57,18 +56,12 @@ implementation ...@@ -57,18 +56,12 @@ implementation
procedure TFViewComplaints.WebFormCreate(Sender: TObject); procedure TFViewComplaints.WebFormCreate(Sender: TObject);
begin begin
Document.addEventListener('click', @HandleListClick); Document.addEventListener('click', @HandleListClick);
tmrRefresh.Enabled := False; FFirstLoad := True;
GetComplaints; GetComplaints;
tmrRefresh.Enabled := True;
asm asm
if (!window.showComplaintDetails) { if (!window.showComplaintDetails) {
window.showComplaintDetails = function (id) { window.showComplaintDetails = function (id) {
console.log('JS bridge showComplaintDetails called, id=', id); pas['View.Main'].FViewMain.ShowComplaintDetails(id);
try {
pas['View.Main'].FViewMain.ShowComplaintDetails(id);
} catch (e) {
console.log('Error in TFViewMain.ShowComplaintDetails', e);
}
}; };
} }
end; end;
...@@ -138,18 +131,12 @@ begin ...@@ -138,18 +131,12 @@ begin
end; end;
end; end;
procedure TFViewComplaints.WebFormDestroy(Sender: TObject); procedure TFViewComplaints.WebFormDestroy(Sender: TObject);
begin begin
Document.removeEventListener('click', @HandleListClick); Document.removeEventListener('click', @HandleListClick);
end; end;
//Note: HTML for individual complaint cards can be found in the twebdblistcontrol HTMLString property //Note: HTML for individual complaint cards can be found in the twebdblistcontrol HTMLString property
procedure TFViewComplaints.btnRefreshClick(Sender: TObject);
begin
GetComplaints;
end;
[async] procedure TFViewComplaints.GetComplaints; [async] procedure TFViewComplaints.GetComplaints;
var var
xdcResponse: TXDataClientResponse; xdcResponse: TXDataClientResponse;
...@@ -160,6 +147,9 @@ begin ...@@ -160,6 +147,9 @@ begin
Exit; Exit;
FLoading := True; FLoading := True;
if FFirstLoad then
ShowSpinner('spinner');
try try
try try
xdcResponse := await(xdwcComplaints.RawInvokeAsync('IApiService.GetComplaintList', [])); xdcResponse := await(xdwcComplaints.RawInvokeAsync('IApiService.GetComplaintList', []));
...@@ -181,11 +171,17 @@ begin ...@@ -181,11 +171,17 @@ begin
end; end;
finally finally
FLoading := False; FLoading := False;
if FFirstLoad then
begin
HideSpinner('spinner');
FFirstLoad := False;
end;
end; end;
end; end;
procedure TFViewComplaints.tmrRefreshTimer(Sender: TObject); procedure TFViewComplaints.RefreshData;
begin begin
Console.Log('Complaints.RefreshData');
GetComplaints; GetComplaints;
end; end;
......
...@@ -186,4 +186,10 @@ object FViewMain: TFViewMain ...@@ -186,4 +186,10 @@ object FViewMain: TFViewMain
Left = 42 Left = 42
Top = 360 Top = 360
end end
object tmrGlobalRefresh: TWebTimer
Interval = 30000
OnTimer = tmrGlobalRefreshTimer
Left = 42
Top = 434
end
end end
...@@ -27,6 +27,7 @@ type ...@@ -27,6 +27,7 @@ type
pnlMap: TWebPanel; pnlMap: TWebPanel;
pnlUnits: TWebPanel; pnlUnits: TWebPanel;
pnlComplaints: TWebPanel; pnlComplaints: TWebPanel;
tmrGlobalRefresh: TWebTimer;
procedure WebFormCreate(Sender: TObject); procedure WebFormCreate(Sender: TObject);
procedure mnuLogoutClick(Sender: TObject); procedure mnuLogoutClick(Sender: TObject);
procedure wllblLogoutClick(Sender: TObject); procedure wllblLogoutClick(Sender: TObject);
...@@ -34,6 +35,7 @@ type ...@@ -34,6 +35,7 @@ type
procedure btnComplaintsClick(Sender: TObject); procedure btnComplaintsClick(Sender: TObject);
procedure btnMapClick(Sender: TObject); procedure btnMapClick(Sender: TObject);
procedure tmrBadgeCountsTimer(Sender: TObject); procedure tmrBadgeCountsTimer(Sender: TObject);
procedure tmrGlobalRefreshTimer(Sender: TObject);
private private
{ Private declarations } { Private declarations }
FUserInfo: string; FUserInfo: string;
...@@ -45,6 +47,20 @@ type ...@@ -45,6 +47,20 @@ type
[async] procedure RefreshBadgesAsync; [async] procedure RefreshBadgesAsync;
procedure ShowUnitDetails(UnitId: string); procedure ShowUnitDetails(UnitId: string);
procedure SetHeaderTitle(const title: string); procedure SetHeaderTitle(const title: string);
type TActivePanel = (apNone, apMap, apUnits, apComplaints);
var
FActivePanel: TActivePanel;
FGlobalRefreshTick: Integer;
FMapRefreshTick: Integer;
FUnitsRefreshTick: Integer;
FComplaintsRefreshTick: Integer;
procedure SetActivePanel(panel: TActivePanel);
procedure MarkPanelCreatedUpToDate(panel: TActivePanel);
procedure RefreshPanelIfNeeded(panel: TActivePanel);
procedure RefreshActivePanelFromTimer;
public public
{ Public declarations } { Public declarations }
class procedure Display(LogoutProc: TLogoutProc); class procedure Display(LogoutProc: TLogoutProc);
...@@ -82,6 +98,13 @@ begin ...@@ -82,6 +98,13 @@ begin
userName := JS.toString(AuthService.TokenPayload.Properties['user_name']); userName := JS.toString(AuthService.TokenPayload.Properties['user_name']);
lblUsername.Caption := ' ' + userName.ToLower + ' '; lblUsername.Caption := ' ' + userName.ToLower + ' ';
FChildForm := nil; FChildForm := nil;
FActivePanel := apNone;
FGlobalRefreshTick := 0;
FMapRefreshTick := 0;
FUnitsRefreshTick := 0;
FComplaintsRefreshTick := 0;
if (not (JS.toBoolean(AuthService.TokenPayload.Properties['user_admin']))) then if (not (JS.toBoolean(AuthService.TokenPayload.Properties['user_admin']))) then
lblUsers.Visible := false; lblUsers.Visible := false;
Utils.HideSpinner('spinner'); Utils.HideSpinner('spinner');
...@@ -89,6 +112,66 @@ begin ...@@ -89,6 +112,66 @@ begin
RefreshBadgesAsync; RefreshBadgesAsync;
end; end;
procedure TFViewMain.SetActivePanel(panel: TActivePanel);
begin
FActivePanel := panel;
end;
procedure TFViewMain.MarkPanelCreatedUpToDate(panel: TActivePanel);
begin
case panel of
apMap: FMapRefreshTick := FGlobalRefreshTick;
apUnits: FUnitsRefreshTick := FGlobalRefreshTick;
apComplaints: FComplaintsRefreshTick := FGlobalRefreshTick;
end;
end;
procedure TFViewMain.RefreshPanelIfNeeded(panel: TActivePanel);
var
needsRefresh: Boolean;
begin
if FGlobalRefreshTick <= 0 then
Exit;
needsRefresh := False;
case panel of
apMap: needsRefresh := (FMapRefreshTick <> FGlobalRefreshTick);
apUnits: needsRefresh := (FUnitsRefreshTick <> FGlobalRefreshTick);
apComplaints: needsRefresh := (FComplaintsRefreshTick <> FGlobalRefreshTick);
end;
if not needsRefresh then
Exit;
Console.Log('GlobalRefresh: refreshing panel=' + IntToStr(Ord(panel)) + ' at tick=' + IntToStr(FGlobalRefreshTick));
case panel of
apUnits:
if Assigned(FUnitsForm) then
FUnitsForm.RefreshData;
apComplaints:
if Assigned(FComplaintsForm) then
FComplaintsForm.RefreshData;
apMap:
if Assigned(FMapForm) then
FMapForm.RefreshData;
end;
case panel of
apMap: FMapRefreshTick := FGlobalRefreshTick;
apUnits: FUnitsRefreshTick := FGlobalRefreshTick;
apComplaints: FComplaintsRefreshTick := FGlobalRefreshTick;
end;
end;
procedure TFViewMain.RefreshActivePanelFromTimer;
begin
RefreshPanelIfNeeded(FActivePanel);
end;
procedure TFViewMain.SetHeaderTitle(const title: string); procedure TFViewMain.SetHeaderTitle(const title: string);
var el: TJSElement; var el: TJSElement;
begin begin
...@@ -141,7 +224,7 @@ end; ...@@ -141,7 +224,7 @@ end;
procedure TFViewMain.ShowForm(AFormClass: TWebFormClass); procedure TFViewMain.ShowForm(AFormClass: TWebFormClass);
begin begin
// Map (cached in pnlMapHost -> ElementID = 'pnl_map') // Map Panel
if AFormClass = TFViewMap then if AFormClass = TFViewMap then
begin begin
HidePanel(pnlMain); HidePanel(pnlMain);
...@@ -151,14 +234,21 @@ begin ...@@ -151,14 +234,21 @@ begin
SetHeaderTitle('Map'); SetHeaderTitle('Map');
SetActiveNavButton('view.main.btnmap'); SetActiveNavButton('view.main.btnmap');
SetActivePanel(apMap);
if not Assigned(FMapForm) then if not Assigned(FMapForm) then
begin
Application.CreateForm(TFViewMap, pnlMap.ElementID, TWebForm(FMapForm)); Application.CreateForm(TFViewMap, pnlMap.ElementID, TWebForm(FMapForm));
MarkPanelCreatedUpToDate(apMap);
end
else
RefreshPanelIfNeeded(apMap);
FChildForm := FMapForm; FChildForm := FMapForm;
Exit; Exit;
end; end;
// Units Panel
if AFormClass = TFViewUnits then if AFormClass = TFViewUnits then
begin begin
HidePanel(pnlMain); HidePanel(pnlMain);
...@@ -168,14 +258,21 @@ begin ...@@ -168,14 +258,21 @@ begin
SetHeaderTitle('Units'); SetHeaderTitle('Units');
SetActiveNavButton('view.main.btnunits'); SetActiveNavButton('view.main.btnunits');
SetActivePanel(apUnits);
if not Assigned(FUnitsForm) then if not Assigned(FUnitsForm) then
begin
Application.CreateForm(TFViewUnits, pnlUnits.ElementID, TWebForm(FUnitsForm)); Application.CreateForm(TFViewUnits, pnlUnits.ElementID, TWebForm(FUnitsForm));
MarkPanelCreatedUpToDate(apUnits);
end
else
RefreshPanelIfNeeded(apUnits);
FChildForm := FUnitsForm; FChildForm := FUnitsForm;
Exit; Exit;
end; end;
// Complaints Panel
if AFormClass = TFViewComplaints then if AFormClass = TFViewComplaints then
begin begin
HidePanel(pnlMain); HidePanel(pnlMain);
...@@ -185,15 +282,23 @@ begin ...@@ -185,15 +282,23 @@ begin
SetHeaderTitle('Complaints'); SetHeaderTitle('Complaints');
SetActiveNavButton('view.main.btncomplaints'); SetActiveNavButton('view.main.btncomplaints');
SetActivePanel(apComplaints);
if not Assigned(FComplaintsForm) then if not Assigned(FComplaintsForm) then
begin
Application.CreateForm(TFViewComplaints, pnlComplaints.ElementID, TWebForm(FComplaintsForm)); Application.CreateForm(TFViewComplaints, pnlComplaints.ElementID, TWebForm(FComplaintsForm));
MarkPanelCreatedUpToDate(apComplaints);
end
else
RefreshPanelIfNeeded(apComplaints);
FChildForm := FComplaintsForm; FChildForm := FComplaintsForm;
Exit; Exit;
end; end;
// Everything else: use pnlMain // Everything else: use pnlMain
SetActivePanel(apNone);
HidePanel(pnlMap); HidePanel(pnlMap);
HidePanel(pnlUnits); HidePanel(pnlUnits);
HidePanel(pnlComplaints); HidePanel(pnlComplaints);
...@@ -229,6 +334,7 @@ end; ...@@ -229,6 +334,7 @@ end;
procedure TFViewMain.ShowComplaintDetails(ComplaintId: string); procedure TFViewMain.ShowComplaintDetails(ComplaintId: string);
begin begin
SetActivePanel(apNone);
SetHeaderTitle('Complaint Details'); SetHeaderTitle('Complaint Details');
HidePanel(pnlMap); HidePanel(pnlMap);
...@@ -244,6 +350,7 @@ end; ...@@ -244,6 +350,7 @@ end;
procedure TFViewMain.ShowUnitDetails(UnitId: string); procedure TFViewMain.ShowUnitDetails(UnitId: string);
begin begin
SetActivePanel(apNone);
SetHeaderTitle('Unit Details'); SetHeaderTitle('Unit Details');
HidePanel(pnlMap); HidePanel(pnlMap);
...@@ -266,12 +373,10 @@ begin ...@@ -266,12 +373,10 @@ begin
c := TJSHTMLElement(btnComplaints.ElementHandle); c := TJSHTMLElement(btnComplaints.ElementHandle);
u := TJSHTMLElement(btnUnits.ElementHandle); u := TJSHTMLElement(btnUnits.ElementHandle);
// clear
m.classList.remove('active'); m.classList.remove('active');
c.classList.remove('active'); c.classList.remove('active');
u.classList.remove('active'); u.classList.remove('active');
// set
if btnId = 'view.main.btnmap' then if btnId = 'view.main.btnmap' then
m.classList.add('active') m.classList.add('active')
else if btnId = 'view.main.btncomplaints' then else if btnId = 'view.main.btncomplaints' then
...@@ -288,6 +393,13 @@ begin ...@@ -288,6 +393,13 @@ begin
end; end;
procedure TFViewMain.tmrGlobalRefreshTimer(Sender: TObject);
begin
Inc(FGlobalRefreshTick);
Console.Log('GlobalRefresh tick=' + IntToStr(FGlobalRefreshTick) + ' activePanel=' + IntToStr(Ord(FActivePanel)));
RefreshActivePanelFromTimer;
end;
[async] procedure TFViewMain.RefreshBadgesAsync; [async] procedure TFViewMain.RefreshBadgesAsync;
var var
resp: TXDataClientResponse; resp: TXDataClientResponse;
......
...@@ -72,12 +72,6 @@ object FViewMap: TFViewMap ...@@ -72,12 +72,6 @@ object FViewMap: TFViewMap
Left = 232 Left = 232
Top = 696 Top = 696
end end
object tmrRefresh: TWebTimer
Interval = 30000
OnTimer = tmrRefreshTimer
Left = 358
Top = 696
end
object tmrLocate: TWebTimer object tmrLocate: TWebTimer
Enabled = False Enabled = False
Interval = 100 Interval = 100
......
...@@ -16,7 +16,6 @@ type ...@@ -16,7 +16,6 @@ type
lfMap: TTMSFNCLeaflet; lfMap: TTMSFNCLeaflet;
httpReqGeoJson: TWebHttpRequest; httpReqGeoJson: TWebHttpRequest;
xdwcMap: TXDataWebClient; xdwcMap: TXDataWebClient;
tmrRefresh: TWebTimer;
btnFindLocation: TWebButton; btnFindLocation: TWebButton;
tmrLocate: TWebTimer; tmrLocate: TWebTimer;
...@@ -25,7 +24,6 @@ type ...@@ -25,7 +24,6 @@ type
procedure lfMapCustomizeMarker(Sender: TObject; procedure lfMapCustomizeMarker(Sender: TObject;
var ACustomizeMarker: string); var ACustomizeMarker: string);
procedure lfMapCustomizeCSS(Sender: TObject; var ACustomizeCSS: string); procedure lfMapCustomizeCSS(Sender: TObject; var ACustomizeCSS: string);
procedure tmrRefreshTimer(Sender: TObject);
procedure btnFindLocationClick(Sender: TObject); procedure btnFindLocationClick(Sender: TObject);
procedure tmrLocateTimer(Sender: TObject); procedure tmrLocateTimer(Sender: TObject);
private private
...@@ -50,6 +48,7 @@ type ...@@ -50,6 +48,7 @@ type
public public
procedure FocusUnit(const unitId: string); procedure FocusUnit(const unitId: string);
procedure FocusComplaint(const complaintId: string); procedure FocusComplaint(const complaintId: string);
procedure RefreshData;
end; end;
var var
...@@ -284,7 +283,6 @@ begin ...@@ -284,7 +283,6 @@ begin
// --- Swap Markers (no blank map while loading) --------------------------- // --- Swap Markers (no blank map while loading) ---------------------------
lfMap.BeginUpdate; lfMap.BeginUpdate;
try try
// Delete old unit/complaint markers right before adding new ones
for i := lfMap.Markers.Count - 1 downto 0 do for i := lfMap.Markers.Count - 1 downto 0 do
begin begin
m := lfMap.Markers[i]; m := lfMap.Markers[i];
...@@ -293,7 +291,7 @@ begin ...@@ -293,7 +291,7 @@ begin
lfMap.Markers.Delete(i); lfMap.Markers.Delete(i);
end; end;
// Add unit markers // Unit markers
if unitsData <> nil then if unitsData <> nil then
begin begin
for i := 0 to unitsData.Length - 1 do for i := 0 to unitsData.Length - 1 do
...@@ -402,7 +400,7 @@ begin ...@@ -402,7 +400,7 @@ begin
end; end;
end; end;
// Add complaint markers // Complaint markers
if complaintsData <> nil then if complaintsData <> nil then
begin begin
for i := 0 to complaintsData.Length - 1 do for i := 0 to complaintsData.Length - 1 do
...@@ -638,14 +636,6 @@ begin ...@@ -638,14 +636,6 @@ begin
FDoFocusZoom := False; FDoFocusZoom := False;
end; end;
procedure TFViewMap.tmrRefreshTimer(Sender: TObject);
begin
if FLoadingPoints then
Exit;
LoadPointsAsync(False);
end;
procedure TFViewMap.btnFindLocationClick(Sender: TObject); procedure TFViewMap.btnFindLocationClick(Sender: TObject);
var var
coord: TTMSFNCMapsCoordinateRec; coord: TTMSFNCMapsCoordinateRec;
...@@ -758,6 +748,12 @@ begin ...@@ -758,6 +748,12 @@ begin
end; end;
procedure TFViewMap.RefreshData;
begin
Console.Log('Map.RefreshData');
LoadPointsAsync(False);
end;
end. end.
...@@ -53,7 +53,7 @@ object FViewUnits: TFViewUnits ...@@ -53,7 +53,7 @@ object FViewUnits: TFViewUnits
'pe="button" class="btn btn-primary btn-sm btn-unit-details" data' + 'pe="button" class="btn btn-primary btn-sm btn-unit-details" data' +
'-unitid="(%UnitId%)">Details</button> <button type="button"' + '-unitid="(%UnitId%)">Details</button> <button type="button"' +
' class="btn btn-primary btn-sm btn-unit-map" data-unitid="(%Unit' + ' class="btn btn-primary btn-sm btn-unit-map" data-unitid="(%Unit' +
'Id%)">View On Map</button> </div> </div></div>' 'Id%)">Map</button> </div> </div></div>'
ListSource = wdsUnits ListSource = wdsUnits
end end
object wdsUnits: TWebDataSource object wdsUnits: TWebDataSource
...@@ -96,10 +96,4 @@ object FViewUnits: TFViewUnits ...@@ -96,10 +96,4 @@ object FViewUnits: TFViewUnits
Left = 58 Left = 58
Top = 410 Top = 410
end end
object tmrRefresh: TWebTimer
Interval = 30000
OnTimer = tmrRefreshTimer
Left = 172
Top = 22
end
end end
...@@ -25,16 +25,14 @@ type ...@@ -25,16 +25,14 @@ type
xdwdsUnitsOfficer1: TStringField; xdwdsUnitsOfficer1: TStringField;
xdwdsUnitsOfficer2: TStringField; xdwdsUnitsOfficer2: TStringField;
xdwdsUnitsCallType: TStringField; xdwdsUnitsCallType: TStringField;
tmrRefresh: TWebTimer;
procedure WebFormCreate(Sender: TObject); procedure WebFormCreate(Sender: TObject);
procedure btnRefreshClick(Sender: TObject);
procedure tmrRefreshTimer(Sender: TObject);
private private
FLoading: Boolean; FLoading: Boolean;
FFirstLoad: Boolean;
[async] procedure GetUnits; [async] procedure GetUnits;
procedure HandleListClick(e: TJSMouseEvent); procedure HandleListClick(e: TJSMouseEvent);
public public
procedure RefreshData;
end; end;
var var
...@@ -49,19 +47,13 @@ procedure TFViewUnits.WebFormCreate(Sender: TObject); ...@@ -49,19 +47,13 @@ procedure TFViewUnits.WebFormCreate(Sender: TObject);
begin begin
DMConnection.ApiConnection.Connected := True; DMConnection.ApiConnection.Connected := True;
Document.addEventListener('click', @HandleListClick); Document.addEventListener('click', @HandleListClick);
tmrRefresh.Enabled := False; FFirstLoad := True;
GetUnits; GetUnits;
tmrRefresh.Enabled := True;
asm asm
if (!window.showUnitDetails) { if (!window.showUnitDetails) {
window.showUnitDetails = function (id) { window.showUnitDetails = function (id) {
console.log('JS bridge showUnitDetails called, id=', id); pas['View.Main'].FViewMain.ShowUnitDetails(id);
try {
pas['View.Main'].FViewMain.ShowUnitDetails(id);
} catch (e) {
console.log('Error in TFViewMain.ShowUnitDetails', e);
}
}; };
} }
end; end;
...@@ -106,61 +98,56 @@ begin ...@@ -106,61 +98,56 @@ begin
e.stopPropagation; e.stopPropagation;
asm asm
try { pas['View.Main'].FViewMain.ShowMapFocusUnit(unitId);
pas['View.Main'].FViewMain.ShowMapFocusUnit(unitId);
} catch (e) {
console.log('ShowMapFocusUnit failed', e);
}
end; end;
end; end;
end; end;
end; end;
procedure TFViewUnits.btnRefreshClick(Sender: TObject); [async] procedure TFViewUnits.GetUnits;
begin
GetUnits;
end;
procedure TFViewUnits.GetUnits;
var var
xdcResponse: TXDataClientResponse; xdcResponse: TXDataClientResponse;
respObj: TJSObject; respObj: TJSObject;
unitCount: Integer; unitCount: Integer;
begin begin
if FLoading then Exit; if FLoading then
Exit;
FLoading := True; FLoading := True;
console.log('GetUnits: Invoking API...'); if FFirstLoad then
Utils.ShowSpinner('spinner');
try try
try try
xdcResponse := await(xdwcUnits.RawInvokeAsync('IApiService.GetUnitList', [])); xdcResponse := await(xdwcUnits.RawInvokeAsync('IApiService.GetUnitList', []));
console.log('RawInvoke returned:', xdcResponse.Result);
respObj := TJSObject(xdcResponse.Result); respObj := TJSObject(xdcResponse.Result);
xdwdsUnits.Close; xdwdsUnits.Close;
xdwdsUnits.SetJsonData(respObj['data']); xdwdsUnits.SetJsonData(respObj['data']);
xdwdsUnits.Open; xdwdsUnits.Open;
unitCount := Integer(respObj['count']); unitCount := Integer(respObj['count']);
lblEntries.Caption := Format('%d units', [unitCount]); lblEntries.Caption := Format('%d units', [unitCount]);
except except
on E: EXDataClientRequestException do on E: EXDataClientRequestException do
begin
Utils.ShowErrorModal(E.ErrorResult.ErrorMessage); Utils.ShowErrorModal(E.ErrorResult.ErrorMessage);
end; on E: Exception do
Utils.ShowErrorModal(E.Message);
end; end;
finally finally
if FFirstLoad then
Utils.HideSpinner('spinner');
FFirstLoad := False;
FLoading := False; FLoading := False;
console.log('GetUnits complete');
end; end;
end; end;
procedure TFViewUnits.tmrRefreshTimer(Sender: TObject); procedure TFViewUnits.RefreshData;
begin begin
Console.Log('Units.RefreshData');
GetUnits; GetUnits;
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