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