Commit de1aebb1 by Mac Stephens

wip from old vm

parent 1d985813
...@@ -7,27 +7,27 @@ object ApiDatabaseModule: TApiDatabaseModule ...@@ -7,27 +7,27 @@ object ApiDatabaseModule: TApiDatabaseModule
SpecificOptions.Strings = ( SpecificOptions.Strings = (
'PostgreSQL.Schema=envoy') 'PostgreSQL.Schema=envoy')
LoginPrompt = False LoginPrompt = False
Left = 77 Left = 35
Top = 137 Top = 29
end end
object PostgreSQLUniProvider1: TPostgreSQLUniProvider object PostgreSQLUniProvider1: TPostgreSQLUniProvider
Left = 228 Left = 180
Top = 138 Top = 30
end end
object UniQuery1: TUniQuery object UniQuery1: TUniQuery
Connection = ucEnvoy Connection = ucEnvoy
SQL.Strings = ( SQL.Strings = (
'') '')
Left = 363 Left = 351
Top = 138 Top = 34
end end
object OracleUniProvider1: TOracleUniProvider object OracleUniProvider1: TOracleUniProvider
Left = 226 Left = 182
Top = 236 Top = 98
end end
object uqBooking: TUniQuery object uqBooking: TUniQuery
Left = 374 Left = 350
Top = 222 Top = 98
end end
object uqMapUnits: TUniQuery object uqMapUnits: TUniQuery
Connection = ucENTCAD Connection = ucENTCAD
...@@ -41,8 +41,8 @@ object ApiDatabaseModule: TApiDatabaseModule ...@@ -41,8 +41,8 @@ object ApiDatabaseModule: TApiDatabaseModule
' uc.GPS_LONGITUDE' ' uc.GPS_LONGITUDE'
'FROM UNITS_CURRENT@AVL_LINK uc') 'FROM UNITS_CURRENT@AVL_LINK uc')
ReadOnly = True ReadOnly = True
Left = 366 Left = 470
Top = 306 Top = 414
object uqMapUnitsENTRYID: TFloatField object uqMapUnitsENTRYID: TFloatField
FieldName = 'ENTRYID' FieldName = 'ENTRYID'
end end
...@@ -125,8 +125,8 @@ object ApiDatabaseModule: TApiDatabaseModule ...@@ -125,8 +125,8 @@ object ApiDatabaseModule: TApiDatabaseModule
'' ''
'') '')
ReadOnly = True ReadOnly = True
Left = 446 Left = 278
Top = 394 Top = 322
object uqUnitListUNITID: TFloatField object uqUnitListUNITID: TFloatField
FieldName = 'UNITID' FieldName = 'UNITID'
end end
...@@ -241,8 +241,8 @@ object ApiDatabaseModule: TApiDatabaseModule ...@@ -241,8 +241,8 @@ object ApiDatabaseModule: TApiDatabaseModule
'WHERE ca.COMPLAINTID = :COMPLAINTID' 'WHERE ca.COMPLAINTID = :COMPLAINTID'
'ORDER BY ca.DATEDISPATCHED') 'ORDER BY ca.DATEDISPATCHED')
ReadOnly = True ReadOnly = True
Left = 256 Left = 470
Top = 308 Top = 356
ParamData = < ParamData = <
item item
DataType = ftUnknown DataType = ftUnknown
...@@ -290,8 +290,8 @@ object ApiDatabaseModule: TApiDatabaseModule ...@@ -290,8 +290,8 @@ object ApiDatabaseModule: TApiDatabaseModule
'WHERE cm.CFSID = :CFSID' 'WHERE cm.CFSID = :CFSID'
'ORDER BY cm.TIMESTAMP ASC') 'ORDER BY cm.TIMESTAMP ASC')
ReadOnly = True ReadOnly = True
Left = 284 Left = 278
Top = 388 Top = 382
ParamData = < ParamData = <
item item
DataType = ftUnknown DataType = ftUnknown
...@@ -375,8 +375,8 @@ object ApiDatabaseModule: TApiDatabaseModule ...@@ -375,8 +375,8 @@ object ApiDatabaseModule: TApiDatabaseModule
'') '')
ReadOnly = True ReadOnly = True
OnCalcFields = uqComplaintListCalcFields OnCalcFields = uqComplaintListCalcFields
Left = 76 Left = 94
Top = 324 Top = 320
object uqComplaintListCOMPLAINTID: TFloatField object uqComplaintListCOMPLAINTID: TFloatField
FieldName = 'COMPLAINTID' FieldName = 'COMPLAINTID'
Required = True Required = True
...@@ -507,31 +507,15 @@ object ApiDatabaseModule: TApiDatabaseModule ...@@ -507,31 +507,15 @@ object ApiDatabaseModule: TApiDatabaseModule
object uqComplaintDetails: TUniQuery object uqComplaintDetails: TUniQuery
Connection = ucENTCAD Connection = ucENTCAD
SQL.Strings = ( SQL.Strings = (
'-- uqComplaintActive_Detail'
'SELECT' 'SELECT'
' ca.COMPLAINTID,' ' ca.COMPLAINTID,'
' ca.CFSID,' ' ca.CFSID,'
' ca.COMPLAINT,' ' ca.COMPLAINT,'
' ca.AGENCY,' ' ca.PRIORITY,'
' ca.DISPATCHCODE,' ' ca.DISPATCHCODE,'
' cdc.CODE_DESC AS DISPATCH_CODE_DESC,' ' cdc.CODE_DESC AS DISPATCH_CODE_DESC,'
' ca.SOURCE,'
' ccs.CODE_DESC AS SOURCE_DESC,'
' ca.PRIORITY,'
' ca.ADDRESSID,'
' ca.ADDRESS,'
' ca.APARTMENT,'
' ca.CITY,'
' ca.BUSINESS,'
' ca.DISPATCHDISTRICT,' ' ca.DISPATCHDISTRICT,'
' ca.DISPATCHSECTOR,' ' ca.ADDRESS,'
' ca.ADDRESSDISTRICT,'
' ca.ADDRESSSECTOR,'
' ca.XCOORD,'
' ca.YCOORD,'
' ca.WARNINGS,'
' ca.CONTACTS,'
' ca.HISTORY,'
' ct.DATEREPORTED,' ' ct.DATEREPORTED,'
' ct.DATERECEIVED,' ' ct.DATERECEIVED,'
' ct.DATEDISPATCHED,' ' ct.DATEDISPATCHED,'
...@@ -541,10 +525,10 @@ object ApiDatabaseModule: TApiDatabaseModule ...@@ -541,10 +525,10 @@ object ApiDatabaseModule: TApiDatabaseModule
'FROM COMPLAINT_ACTIVE ca' 'FROM COMPLAINT_ACTIVE ca'
'JOIN COMPLAINT_TIMES ct ON ca.COMPLAINTID = ct.COMPLAINTID' 'JOIN COMPLAINT_TIMES ct ON ca.COMPLAINTID = ct.COMPLAINTID'
'LEFT JOIN CD_DISPATCHCODES cdc ON ca.DISPATCHCODE = cdc.CODE' 'LEFT JOIN CD_DISPATCHCODES cdc ON ca.DISPATCHCODE = cdc.CODE'
'LEFT JOIN CD_CALLSOURCES ccs ON ca.SOURCE = ccs.CODE' 'WHERE ca.COMPLAINTID = :COMPLAINTID;'
'WHERE ca.COMPLAINTID = :COMPLAINTID') '')
ReadOnly = True ReadOnly = True
Left = 74 Left = 92
Top = 376 Top = 376
ParamData = < ParamData = <
item item
...@@ -563,8 +547,8 @@ object ApiDatabaseModule: TApiDatabaseModule ...@@ -563,8 +547,8 @@ object ApiDatabaseModule: TApiDatabaseModule
FieldName = 'COMPLAINT' FieldName = 'COMPLAINT'
Size = 10 Size = 10
end end
object uqComplaintDetailsAGENCY: TStringField object uqComplaintDetailsPRIORITY: TStringField
FieldName = 'AGENCY' FieldName = 'PRIORITY'
Size = 6 Size = 6
end end
object uqComplaintDetailsDISPATCHCODE: TStringField object uqComplaintDetailsDISPATCHCODE: TStringField
...@@ -576,68 +560,14 @@ object ApiDatabaseModule: TApiDatabaseModule ...@@ -576,68 +560,14 @@ object ApiDatabaseModule: TApiDatabaseModule
ReadOnly = True ReadOnly = True
Size = 60 Size = 60
end end
object uqComplaintDetailsSOURCE: TStringField object uqComplaintDetailsDISPATCHDISTRICT: TStringField
FieldName = 'SOURCE' FieldName = 'DISPATCHDISTRICT'
Size = 6
end
object uqComplaintDetailsSOURCE_DESC: TStringField
FieldName = 'SOURCE_DESC'
ReadOnly = True
Size = 120
end
object uqComplaintDetailsPRIORITY: TStringField
FieldName = 'PRIORITY'
Size = 6 Size = 6
end end
object uqComplaintDetailsADDRESSID: TFloatField
FieldName = 'ADDRESSID'
end
object uqComplaintDetailsADDRESS: TStringField object uqComplaintDetailsADDRESS: TStringField
FieldName = 'ADDRESS' FieldName = 'ADDRESS'
Size = 64 Size = 64
end end
object uqComplaintDetailsAPARTMENT: TStringField
FieldName = 'APARTMENT'
Size = 6
end
object uqComplaintDetailsCITY: TStringField
FieldName = 'CITY'
end
object uqComplaintDetailsBUSINESS: TStringField
FieldName = 'BUSINESS'
Size = 35
end
object uqComplaintDetailsDISPATCHDISTRICT: TStringField
FieldName = 'DISPATCHDISTRICT'
Size = 6
end
object uqComplaintDetailsDISPATCHSECTOR: TStringField
FieldName = 'DISPATCHSECTOR'
Size = 6
end
object uqComplaintDetailsADDRESSDISTRICT: TStringField
FieldName = 'ADDRESSDISTRICT'
Size = 5
end
object uqComplaintDetailsADDRESSSECTOR: TStringField
FieldName = 'ADDRESSSECTOR'
Size = 5
end
object uqComplaintDetailsXCOORD: TFloatField
FieldName = 'XCOORD'
end
object uqComplaintDetailsYCOORD: TFloatField
FieldName = 'YCOORD'
end
object uqComplaintDetailsWARNINGS: TFloatField
FieldName = 'WARNINGS'
end
object uqComplaintDetailsCONTACTS: TFloatField
FieldName = 'CONTACTS'
end
object uqComplaintDetailsHISTORY: TFloatField
FieldName = 'HISTORY'
end
object uqComplaintDetailsDATEREPORTED: TDateTimeField object uqComplaintDetailsDATEREPORTED: TDateTimeField
FieldName = 'DATEREPORTED' FieldName = 'DATEREPORTED'
ReadOnly = True ReadOnly = True
...@@ -668,9 +598,10 @@ object ApiDatabaseModule: TApiDatabaseModule ...@@ -668,9 +598,10 @@ object ApiDatabaseModule: TApiDatabaseModule
Port = 1521 Port = 1521
Username = 'ENTCAD' Username = 'ENTCAD'
Server = 'BUFENTCAD' Server = 'BUFENTCAD'
Connected = True
LoginPrompt = False LoginPrompt = False
Left = 76 Left = 36
Top = 244 Top = 98
EncryptedPassword = 'BAFFB1FFABFFBCFFBEFFBBFF' EncryptedPassword = 'BAFFB1FFABFFBCFFBEFFBBFF'
end end
object uqMapComplaints: TUniQuery object uqMapComplaints: TUniQuery
...@@ -715,8 +646,8 @@ object ApiDatabaseModule: TApiDatabaseModule ...@@ -715,8 +646,8 @@ object ApiDatabaseModule: TApiDatabaseModule
'') '')
ReadOnly = True ReadOnly = True
OnCalcFields = uqMapComplaintsCalcFields OnCalcFields = uqMapComplaintsCalcFields
Left = 476 Left = 470
Top = 308 Top = 296
object uqMapComplaintsCOMPLAINTID: TFloatField object uqMapComplaintsCOMPLAINTID: TFloatField
FieldName = 'COMPLAINTID' FieldName = 'COMPLAINTID'
Required = True Required = True
...@@ -756,4 +687,30 @@ object ApiDatabaseModule: TApiDatabaseModule ...@@ -756,4 +687,30 @@ object ApiDatabaseModule: TApiDatabaseModule
Calculated = True Calculated = True
end end
end end
object uqBadgeCounts: TUniQuery
Connection = ucENTCAD
SQL.Strings = (
'select'
' (select count(*)'
' from COMPLAINT_ACTIVE ca'
' join COMPLAINT_TIMES ct on ct.COMPLAINTID = ca.COMPLAINTID'
' where ca.COMPLAINT is not null) as Complaints,'
''
' (select count(distinct dua.UNITID)'
' from DIS_UNIT_ACTIVE dua) as Units'
'from dual;'
'')
ReadOnly = True
Active = True
Left = 194
Top = 270
object uqBadgeCountsCOMPLAINTS: TFloatField
FieldName = 'COMPLAINTS'
ReadOnly = True
end
object uqBadgeCountsUNITS: TFloatField
FieldName = 'UNITS'
ReadOnly = True
end
end
end end
...@@ -49,35 +49,6 @@ type ...@@ -49,35 +49,6 @@ type
uqComplaintListDATERESPONDED: TDateTimeField; uqComplaintListDATERESPONDED: TDateTimeField;
uqComplaintListDATEARRIVED: TDateTimeField; uqComplaintListDATEARRIVED: TDateTimeField;
uqComplaintListDATECLEARED: TDateTimeField; uqComplaintListDATECLEARED: TDateTimeField;
uqComplaintDetailsCOMPLAINTID: TFloatField;
uqComplaintDetailsCFSID: TFloatField;
uqComplaintDetailsCOMPLAINT: TStringField;
uqComplaintDetailsAGENCY: TStringField;
uqComplaintDetailsDISPATCHCODE: TStringField;
uqComplaintDetailsDISPATCH_CODE_DESC: TStringField;
uqComplaintDetailsSOURCE: TStringField;
uqComplaintDetailsSOURCE_DESC: TStringField;
uqComplaintDetailsPRIORITY: TStringField;
uqComplaintDetailsADDRESSID: TFloatField;
uqComplaintDetailsADDRESS: TStringField;
uqComplaintDetailsAPARTMENT: TStringField;
uqComplaintDetailsCITY: TStringField;
uqComplaintDetailsBUSINESS: TStringField;
uqComplaintDetailsDISPATCHDISTRICT: TStringField;
uqComplaintDetailsDISPATCHSECTOR: TStringField;
uqComplaintDetailsADDRESSDISTRICT: TStringField;
uqComplaintDetailsADDRESSSECTOR: TStringField;
uqComplaintDetailsXCOORD: TFloatField;
uqComplaintDetailsYCOORD: TFloatField;
uqComplaintDetailsWARNINGS: TFloatField;
uqComplaintDetailsCONTACTS: TFloatField;
uqComplaintDetailsHISTORY: TFloatField;
uqComplaintDetailsDATEREPORTED: TDateTimeField;
uqComplaintDetailsDATERECEIVED: TDateTimeField;
uqComplaintDetailsDATEDISPATCHED: TDateTimeField;
uqComplaintDetailsDATERESPONDED: TDateTimeField;
uqComplaintDetailsDATEARRIVED: TDateTimeField;
uqComplaintDetailsDATECLEARED: TDateTimeField;
uqComplaintUnitsCOMPLAINTID: TFloatField; uqComplaintUnitsCOMPLAINTID: TFloatField;
uqComplaintUnitsUNITID: TFloatField; uqComplaintUnitsUNITID: TFloatField;
uqComplaintUnitsUNITNAME: TStringField; uqComplaintUnitsUNITNAME: TStringField;
...@@ -133,6 +104,23 @@ type ...@@ -133,6 +104,23 @@ type
uqMapComplaintsDISPATCHCODECATEGORY: TStringField; uqMapComplaintsDISPATCHCODECATEGORY: TStringField;
uqMapComplaintspriorityKey: TStringField; uqMapComplaintspriorityKey: TStringField;
uqMapComplaintspngName: TStringField; uqMapComplaintspngName: TStringField;
uqBadgeCounts: TUniQuery;
uqBadgeCountsCOMPLAINTS: TFloatField;
uqBadgeCountsUNITS: TFloatField;
uqComplaintDetailsCOMPLAINTID: TFloatField;
uqComplaintDetailsCFSID: TFloatField;
uqComplaintDetailsCOMPLAINT: TStringField;
uqComplaintDetailsPRIORITY: TStringField;
uqComplaintDetailsDISPATCHCODE: TStringField;
uqComplaintDetailsDISPATCH_CODE_DESC: TStringField;
uqComplaintDetailsDISPATCHDISTRICT: TStringField;
uqComplaintDetailsADDRESS: TStringField;
uqComplaintDetailsDATEREPORTED: TDateTimeField;
uqComplaintDetailsDATERECEIVED: TDateTimeField;
uqComplaintDetailsDATEDISPATCHED: TDateTimeField;
uqComplaintDetailsDATERESPONDED: TDateTimeField;
uqComplaintDetailsDATEARRIVED: TDateTimeField;
uqComplaintDetailsDATECLEARED: TDateTimeField;
procedure DataModuleCreate(Sender: TObject); procedure DataModuleCreate(Sender: TObject);
procedure uqComplaintListCalcFields(DataSet: TDataSet); procedure uqComplaintListCalcFields(DataSet: TDataSet);
procedure uqMapComplaintsCalcFields(DataSet: TDataSet); procedure uqMapComplaintsCalcFields(DataSet: TDataSet);
...@@ -141,6 +129,7 @@ type ...@@ -141,6 +129,7 @@ type
public public
function DerivePriorityKeyFromPriorityString(const priorityString: string): string; function DerivePriorityKeyFromPriorityString(const priorityString: string): string;
function HandleUniqueFilenames(const category: string): string; function HandleUniqueFilenames(const category: string): string;
function BadgeCounts(const BaseQuery: TUniQuery): Integer;
class procedure ExecSQL(const SQL: string); class procedure ExecSQL(const SQL: string);
end; end;
...@@ -282,4 +271,28 @@ begin ...@@ -282,4 +271,28 @@ begin
Result := '5-9'; Result := '5-9';
end; end;
function TApiDatabaseModule.BadgeCounts(const BaseQuery: TUniQuery): Integer;
var
Q: TUniQuery;
WrappedSQL: string;
begin
Q := TUniQuery.Create(nil);
try
Q.Connection := BaseQuery.Connection;
// Wrap the original query text in a COUNT(*) shell
WrappedSQL := 'select count(*) as CNT from (' + BaseQuery.SQL.Text + ') t';
Q.SQL.Text := WrappedSQL;
// Carry over params (if the base query uses any)
Q.Params.AssignValues(BaseQuery.Params);
Q.Open;
Result := Q.Fields[0].AsInteger;
finally
Q.Free;
end;
end;
end. end.
...@@ -16,10 +16,12 @@ type ...@@ -16,10 +16,12 @@ type
[ServiceContract, Model(API_MODEL)] [ServiceContract, Model(API_MODEL)]
IApiService = interface(IInvokable) IApiService = interface(IInvokable)
['{4FCB7FAF-44E5-49D6-9C0F-EE44BFB33313}'] ['{4FCB7FAF-44E5-49D6-9C0F-EE44BFB33313}']
[HttpGet] function GetBadgeCounts: TJSONObject;
[HttpGet] function GetComplaintList: TJSONObject; [HttpGet] function GetComplaintList: TJSONObject;
[HttpGet] function GetUnitList: TJSONObject; [HttpGet] function GetUnitList: TJSONObject;
[HttpGet] function GetComplaintMap: TJSONObject; [HttpGet] function GetComplaintMap: TJSONObject;
[HttpGet] function GetUnitMap: TJSONObject; [HttpGet] function GetUnitMap: TJSONObject;
[HttpGet] function GetComplaintDetails(const ComplaintId: string): TJSONObject;
end; end;
implementation implementation
......
...@@ -17,10 +17,12 @@ type ...@@ -17,10 +17,12 @@ type
procedure AfterConstruction; override; procedure AfterConstruction; override;
procedure BeforeDestruction; override; procedure BeforeDestruction; override;
public public
function GetBadgeCounts: TJSONObject;
function GetComplaintList: TJSONObject; function GetComplaintList: TJSONObject;
function GetUnitList: TJSONObject; function GetUnitList: TJSONObject;
function GetComplaintMap: TJSONObject; function GetComplaintMap: TJSONObject;
function GetUnitMap: TJSONObject; function GetUnitMap: TJSONObject;
function GetComplaintDetails(const ComplaintId: string): TJSONObject;
end; end;
implementation implementation
...@@ -43,6 +45,36 @@ begin ...@@ -43,6 +45,36 @@ begin
end; end;
function TApiService.GetBadgeCounts: TJSONObject;
begin
Logger.Log(3, '---TApiService.GetBadgeCounts initiated');
Result := TJSONObject.Create;
TXDataOperationContext.Current.Handler.ManagedObjects.Add(Result);
try
with ApiDB.uqBadgeCounts do
begin
Open;
try
// NOTE: your TUniQuery exposes fields named COMPLAINTS and UNITS
Result.AddPair('BadgeComplaints', TJSONNumber.Create(FieldByName('COMPLAINTS').AsInteger));
Result.AddPair('BadgeUnits', TJSONNumber.Create(FieldByName('UNITS').AsInteger));
finally
Close;
end;
end;
except
on E: Exception do
begin
Logger.Log(3, '---TApiService.GetBadgeCounts End (error): ' + E.Message);
raise EXDataHttpException.Create(500, 'Failed to load badge counts');
end;
end;
Logger.Log(3, '---TApiService.GetBadgeCounts End');
end;
function TApiService.GetComplaintMap: TJSONObject; function TApiService.GetComplaintMap: TJSONObject;
var var
data: TJSONArray; data: TJSONArray;
...@@ -316,6 +348,71 @@ end; ...@@ -316,6 +348,71 @@ end;
function TApiService.GetComplaintDetails(const ComplaintId: string): TJSONObject;
var
obj: TJSONObject;
begin
Logger.Log(3,'---TApiService.GetComplaintDetails initiated: '+ComplaintId);
Result := TJSONObject.Create;
TXDataOperationContext.Current.Handler.ManagedObjects.Add(Result);
try
with ApiDB.uqComplaintDetails do
begin
ParamByName('COMPLAINTID').AsString := ComplaintId;
Open;
try
if Eof then raise EXDataHttpException.Create(404,'Complaint not found');
obj := TJSONObject.Create;
obj.AddPair('ComplaintId',FieldByName('COMPLAINTID').AsString);
obj.AddPair('CFSId',FieldByName('CFSID').AsString);
obj.AddPair('Complaint',FieldByName('COMPLAINT').AsString);
obj.AddPair('Priority',FieldByName('PRIORITY').AsString);
obj.AddPair('DispatchCode',FieldByName('DISPATCHCODE').AsString);
obj.AddPair('DispatchCodeDesc',FieldByName('DISPATCH_CODE_DESC').AsString);
obj.AddPair('DispatchDistrict',FieldByName('DISPATCHDISTRICT').AsString);
obj.AddPair('Address',FieldByName('ADDRESS').AsString);
if FieldByName('DATEREPORTED').IsNull
then obj.AddPair('DateReported','')
else obj.AddPair('DateReported',FormatDateTime('yyyy-mm-dd hh:nn:ss',(FieldByName('DATEREPORTED') as TDateTimeField).AsDateTime));
if FieldByName('DATERECEIVED').IsNull
then obj.AddPair('DateReceived','')
else obj.AddPair('DateReceived',FormatDateTime('yyyy-mm-dd hh:nn:ss',(FieldByName('DATERECEIVED') as TDateTimeField).AsDateTime));
if FieldByName('DATEDISPATCHED').IsNull
then obj.AddPair('DateDispatched','')
else obj.AddPair('DateDispatched',FormatDateTime('yyyy-mm-dd hh:nn:ss',(FieldByName('DATEDISPATCHED') as TDateTimeField).AsDateTime));
if FieldByName('DATERESPONDED').IsNull
then obj.AddPair('DateResponded','')
else obj.AddPair('DateResponded',FormatDateTime('yyyy-mm-dd hh:nn:ss',(FieldByName('DATERESPONDED') as TDateTimeField).AsDateTime));
if FieldByName('DATEARRIVED').IsNull
then obj.AddPair('DateArrived','')
else obj.AddPair('DateArrived',FormatDateTime('yyyy-mm-dd hh:nn:ss',(FieldByName('DATEARRIVED') as TDateTimeField).AsDateTime));
if FieldByName('DATECLEARED').IsNull
then obj.AddPair('DateCleared','')
else obj.AddPair('DateCleared',FormatDateTime('yyyy-mm-dd hh:nn:ss',(FieldByName('DATECLEARED') as TDateTimeField).AsDateTime));
Result.AddPair('data',obj);
finally
Close;
end;
end;
except
on E: EXDataHttpException do
begin
Logger.Log(3,'---TApiService.GetComplaintDetails not found');
raise;
end;
on E: Exception do
begin
Logger.Log(3,'---TApiService.GetComplaintDetails error: '+E.Message);
raise EXDataHttpException.Create(500,'Failed to load complaint details');
end;
end;
Logger.Log(3,'---TApiService.GetComplaintDetails End');
end;
initialization initialization
......
...@@ -4,7 +4,6 @@ object AuthDatabase: TAuthDatabase ...@@ -4,7 +4,6 @@ object AuthDatabase: TAuthDatabase
Height = 249 Height = 249
Width = 433 Width = 433
object uq: TUniQuery object uq: TUniQuery
Connection = ucEnvoy
SQL.Strings = ( SQL.Strings = (
'select * from users') 'select * from users')
FetchRows = 100 FetchRows = 100
...@@ -52,14 +51,6 @@ object AuthDatabase: TAuthDatabase ...@@ -52,14 +51,6 @@ object AuthDatabase: TAuthDatabase
Left = 249 Left = 249
Top = 45 Top = 45
end end
object ucEnvoy: TUniConnection
ProviderName = 'PostgreSQL'
SpecificOptions.Strings = (
'PostgreSQL.Schema=envoy')
LoginPrompt = False
Left = 43
Top = 79
end
object PostgreSQLUniProvider1: TPostgreSQLUniProvider object PostgreSQLUniProvider1: TPostgreSQLUniProvider
Left = 276 Left = 276
Top = 156 Top = 156
......
...@@ -10,7 +10,6 @@ type ...@@ -10,7 +10,6 @@ type
TAuthDatabase = class(TDataModule) TAuthDatabase = class(TDataModule)
uq: TUniQuery; uq: TUniQuery;
uqMisc: TUniQuery; uqMisc: TUniQuery;
ucEnvoy: TUniConnection;
PostgreSQLUniProvider1: TPostgreSQLUniProvider; PostgreSQLUniProvider1: TPostgreSQLUniProvider;
uquser_id: TLargeintField; uquser_id: TLargeintField;
uqusername: TStringField; uqusername: TStringField;
...@@ -55,22 +54,12 @@ var ...@@ -55,22 +54,12 @@ var
begin begin
iniFile := TIniFile.Create(ChangeFileExt(Application.ExeName, '.ini')); iniFile := TIniFile.Create(ChangeFileExt(Application.ExeName, '.ini'));
try try
ucEnvoy.Server := iniFile.ReadString('Database', 'Server', '');
ucEnvoy.Database := iniFile.ReadString('Database', 'Database', '');
ucEnvoy.Username := iniFile.ReadString('Database', 'Username', '');
ucEnvoy.Password := iniFile.ReadString('Database', 'Password', '');
ucBooking.Server := IniFile.ReadString('EMB Database', 'Server', 'EMBOOKING'); ucBooking.Server := IniFile.ReadString('EMB Database', 'Server', 'EMBOOKING');
ucBooking.Username := IniFile.ReadString('EMB Database', 'Username', 'emBooking'); ucBooking.Username := IniFile.ReadString('EMB Database', 'Username', 'emBooking');
ucBooking.Password := IniFile.ReadString('EMB Database', 'Password', 'embook01'); ucBooking.Password := IniFile.ReadString('EMB Database', 'Password', 'embook01');
try try
Logger.Log(2, ''); Logger.Log(2, '');
Logger.Log(2, 'Connecting to envoyCalls Database...');
Logger.Log(2, Format('--ucEnvoy.Server: %s ucEnvoy.Username: %s', [ucEnvoy.Server, ucEnvoy.Username]));
if not ucEnvoy.Connected then
ucEnvoy.Connect;
Logger.Log(2, '--ucEnvoy connected!');
Logger.Log(2, '');
Logger.Log(2, 'Connecting to emBooking Database...'); Logger.Log(2, 'Connecting to emBooking Database...');
if not ucBooking.Connected then if not ucBooking.Connected then
ucBooking.Connect; ucBooking.Connect;
...@@ -104,7 +93,6 @@ end; ...@@ -104,7 +93,6 @@ end;
procedure TAuthDatabase.DataModuleDestroy(Sender: TObject); procedure TAuthDatabase.DataModuleDestroy(Sender: TObject);
begin begin
ucEnvoy.Connected := false;
ucBooking.Connected := false; ucBooking.Connected := false;
end; end;
......
...@@ -282,4 +282,5 @@ begin ...@@ -282,4 +282,5 @@ begin
Result := uq.FieldByName('surname').AsString + ', ' + uq.FieldByName('given1').AsString + ' (' + uq.FieldByName('empno').AsString + ')'; Result := uq.FieldByName('surname').AsString + ', ' + uq.FieldByName('given1').AsString + ' (' + uq.FieldByName('empno').AsString + ')';
end; end;
end. end.
[Settings] [Settings]
LogFileNum=484 LogFileNum=493
webClientVersion=0.1.0 webClientVersion=0.1.0
TwilioUpdateTime=0 TwilioUpdateTime=0
......
object FViewComplaintDetails: TFViewComplaintDetails
Width = 640
Height = 480
end
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title>TMS Web Project</title>
<style>
</style>
</head>
<body>
</body>
</html>
\ No newline at end of file
unit View.ComplaintDetails;
interface
uses
System.SysUtils, System.Classes, JS, Web, WEBLib.Graphics, WEBLib.Controls,
WEBLib.Forms, WEBLib.Dialogs;
type
TFViewComplaintDetails = class(TWebForm)
private
{ Private declarations }
public
{ Public declarations }
end;
var
FViewComplaintDetails: TFViewComplaintDetails;
implementation
{$R *.dfm}
end.
\ No newline at end of file
...@@ -11,6 +11,7 @@ object FViewComplaints: TFViewComplaints ...@@ -11,6 +11,7 @@ object FViewComplaints: TFViewComplaints
ParentFont = False ParentFont = False
Visible = True Visible = True
OnCreate = WebFormCreate OnCreate = WebFormCreate
OnDestroy = WebFormDestroy
object lblEntries: TWebLabel object lblEntries: TWebLabel
Left = 44 Left = 44
Top = 88 Top = 88
...@@ -84,15 +85,20 @@ object FViewComplaints: TFViewComplaints ...@@ -84,15 +85,20 @@ object FViewComplaints: TFViewComplaints
Style = lsListGroup Style = lsListGroup
DataSource = wdsComplaints DataSource = wdsComplaints
ItemTemplate = ItemTemplate =
'<div class="list-section-header small fw-semibold bg-secondary t' + '<div class="list-section-header small fw-semibold bg-secondary ' +
'ext-white rounded-1 px-2 mb-1"> (%DistrictHeader%)</div><div cl' + 'text-white rounded-1 px-2 mb-1"> (%DistrictHeader%)</div><div ' +
'ass="card border shadow-sm" style="--bs-card-bg:(%PriorityCo' + 'class="card border shadow-sm" style=" --bs-card-bg: (%Priori' +
'lor%); --bs-card-color:(%PriorityTextColor%);"> <div class="car' + 'tyColor%); --bs-card-color: (%PriorityTextColor%); "> <div ' +
'd-body py-2 px-3"> <div class="fw-bold text-uppercase small">' + 'class="card-body py-2 px-3"> <div class="fw-bold text-upperca' +
'(%Priority%): (%DispatchCodeDesc%)</div> <div class="small">(' + 'se small"> (%Priority%): (%DispatchCodeDesc%) </div> ' +
'%Address%)</div> <div class="small text-opacity-75">(%Complai' + '<div class="small">(%Address%)</div> <div class="small text-o' +
'nt%): (%Status%)&nbsp;&nbsp;(%DistrictSector%)</div> <div cla' + 'pacity-75"> (%Complaint%): (%Status%)&nbsp;&nbsp;(%District' +
'ss="small text-opacity-75">(%DateReported%)</div> </div></div>' 'Sector%) </div> <div class="small text-opacity-75">(%DateR' +
'eported%)</div> <div class="d-flex justify-content-end mt-2' +
'"> <button type="button" class="btn btn-li' +
'ght btn-sm complaint-details-btn" data-id="(%Comp' +
'laintId%)"> Details </button> </div> </div' +
'></div>'
ListSource = wdsComplaints ListSource = wdsComplaints
end end
object xdwcComplaints: TXDataWebClient object xdwcComplaints: TXDataWebClient
......
...@@ -38,10 +38,13 @@ type ...@@ -38,10 +38,13 @@ type
procedure WebFormCreate(Sender: TObject); procedure WebFormCreate(Sender: TObject);
procedure btnRefreshClick(Sender: TObject); procedure btnRefreshClick(Sender: TObject);
procedure tmrRefreshTimer(Sender: TObject); procedure tmrRefreshTimer(Sender: TObject);
procedure WebFormDestroy(Sender: TObject);
private private
FLoading: Boolean; FLoading: Boolean;
[async] procedure GetComplaints; [async] procedure GetComplaints;
procedure HandleListClick(e: TJSMouseEvent);
public public
end; end;
var var
...@@ -53,15 +56,30 @@ implementation ...@@ -53,15 +56,30 @@ implementation
procedure TFViewComplaints.WebFormCreate(Sender: TObject); procedure TFViewComplaints.WebFormCreate(Sender: TObject);
begin begin
console.log('WebFormCreate: Starting setup...'); Document.addEventListener('click', @HandleListClick);
DMConnection.ApiConnection.Connected := True;
console.log('API connection active:', DMConnection.ApiConnection.Connected);
ShowSpinner('spinner'); ShowSpinner('spinner');
tmrRefresh.Enabled := False; tmrRefresh.Enabled := False;
GetComplaints; GetComplaints;
tmrRefresh.Enabled := True; tmrRefresh.Enabled := True;
end; end;
procedure TFViewComplaints.HandleListClick(e: TJSMouseEvent);
var el: TJSElement; id: string;
begin
el := TJSElement(e.target);
if (el is TJSHtmlElement) and TJSHtmlElement(el).classList.contains('complaint-details-btn') then
begin
id := string(TJSHtmlElement(el).dataset['id']); // comes from (%ComplaintId%)
e.preventDefault;
e.stopPropagation;
end;
end;
procedure TFViewComplaints.WebFormDestroy(Sender: TObject);
begin
Document.removeEventListener('click', @HandleListClick);
end;
//HTML for individual complaint cards can be found in the twebdblistcontrol HTMLString property //HTML for individual complaint cards can be found in the twebdblistcontrol HTMLString property
procedure TFViewComplaints.btnRefreshClick(Sender: TObject); procedure TFViewComplaints.btnRefreshClick(Sender: TObject);
......
...@@ -151,9 +151,15 @@ object FViewMain: TFViewMain ...@@ -151,9 +151,15 @@ object FViewMain: TFViewMain
WidthPercent = 100.000000000000000000 WidthPercent = 100.000000000000000000
OnClick = btnUnitsClick OnClick = btnUnitsClick
end end
object XDataWebClient: TXDataWebClient object xdwcBadgeCounts: TXDataWebClient
Connection = DMConnection.ApiConnection Connection = DMConnection.ApiConnection
Left = 44 Left = 44
Top = 280 Top = 280
end end
object tmrBadgeCounts: TWebTimer
Interval = 30000
OnTimer = tmrBadgeCountsTimer
Left = 42
Top = 360
end
end end
...@@ -17,12 +17,13 @@ type ...@@ -17,12 +17,13 @@ type
WebMessageDlg1: TWebMessageDlg; WebMessageDlg1: TWebMessageDlg;
lblAppTitle: TWebLabel; lblAppTitle: TWebLabel;
WebMemo1: TWebMemo; WebMemo1: TWebMemo;
XDataWebClient: TXDataWebClient; xdwcBadgeCounts: TXDataWebClient;
lblCallsList: TWebLinkLabel; lblCallsList: TWebLinkLabel;
lblUsers: TWebLinkLabel; lblUsers: TWebLinkLabel;
btnMap: TWebButton; btnMap: TWebButton;
btnComplaints: TWebButton; btnComplaints: TWebButton;
btnUnits: TWebButton; btnUnits: TWebButton;
tmrBadgeCounts: TWebTimer;
procedure WebFormCreate(Sender: TObject); procedure WebFormCreate(Sender: TObject);
procedure mnuLogoutClick(Sender: TObject); procedure mnuLogoutClick(Sender: TObject);
procedure wllblUserProfileClick(Sender: TObject); procedure wllblUserProfileClick(Sender: TObject);
...@@ -32,6 +33,7 @@ type ...@@ -32,6 +33,7 @@ type
procedure btnUnitsClick(Sender: TObject); procedure btnUnitsClick(Sender: TObject);
procedure btnComplaintsClick(Sender: TObject); procedure btnComplaintsClick(Sender: TObject);
procedure btnMapClick(Sender: TObject); procedure btnMapClick(Sender: TObject);
procedure tmrBadgeCountsTimer(Sender: TObject);
private private
{ Private declarations } { Private declarations }
FUserInfo: string; FUserInfo: string;
...@@ -43,6 +45,7 @@ type ...@@ -43,6 +45,7 @@ type
//procedure EditUser( AParam, BParam, CParam, DParam, EParam: string); //procedure EditUser( AParam, BParam, CParam, DParam, EParam: string);
function GetUserInfo: string; function GetUserInfo: string;
procedure SetActiveNavButton(const BtnId: string); procedure SetActiveNavButton(const BtnId: string);
[async] procedure RefreshBadgesAsync;
public public
{ Public declarations } { Public declarations }
class procedure Display(LogoutProc: TLogoutProc); class procedure Display(LogoutProc: TLogoutProc);
...@@ -81,6 +84,7 @@ begin ...@@ -81,6 +84,7 @@ begin
lblUsers.Visible := false; lblUsers.Visible := false;
ShowForm(TFViewMap); ShowForm(TFViewMap);
RefreshBadgesAsync;
end; end;
...@@ -181,6 +185,7 @@ begin ...@@ -181,6 +185,7 @@ begin
FChildForm := TFViewUsers.CreateForm(WebPanel1.ElementID, Info); FChildForm := TFViewUsers.CreateForm(WebPanel1.ElementID, Info);
end; end;
procedure TFViewMain.SetActiveNavButton(const btnId: string); procedure TFViewMain.SetActiveNavButton(const btnId: string);
var var
m, c, u: TJSHTMLElement; m, c, u: TJSHTMLElement;
...@@ -203,4 +208,42 @@ begin ...@@ -203,4 +208,42 @@ begin
u.classList.add('active'); u.classList.add('active');
end; end;
procedure TFViewMain.tmrBadgeCountsTimer(Sender: TObject);
begin
console.log('Badges Refreshed');
RefreshBadgesAsync;
end;
[async] procedure TFViewMain.RefreshBadgesAsync;
var
resp: TXDataClientResponse;
badgeObj: TJSObject;
el: TJSElement;
begin
try
resp := await(xdwcBadgeCounts.RawInvokeAsync('IApiService.GetBadgeCounts', []));
badgeObj := TJSObject(resp.Result);
el := Document.getElementById('view.main.badgecomplaints');
if Assigned(el) then
TJSHtmlElement(el).innerText := string(badgeObj['BadgeComplaints']);
el := Document.getElementById('view.main.badgeunits');
if Assigned(el) then
TJSHtmlElement(el).innerText := string(badgeObj['BadgeUnits']);
except
on E: Exception do
begin
el := Document.getElementById('view.main.badgecomplaints');
if Assigned(el) then TJSHtmlElement(el).innerText := '';
el := Document.getElementById('view.main.badgeunits');
if Assigned(el) then TJSHtmlElement(el).innerText := '';
Console.Log('Badge refresh error: ' + E.Message);
end;
end;
end;
end. end.
...@@ -18,7 +18,8 @@ uses ...@@ -18,7 +18,8 @@ uses
View.Users in 'View.Users.pas' {FViewUsers: TWebForm} {*.html}, View.Users in 'View.Users.pas' {FViewUsers: TWebForm} {*.html},
View.EditUser in 'View.EditUser.pas' {FViewEditUser: TWebForm} {*.html}, View.EditUser in 'View.EditUser.pas' {FViewEditUser: TWebForm} {*.html},
Utils in 'Utils.pas', Utils in 'Utils.pas',
View.ErrorPage in 'View.ErrorPage.pas' {FViewErrorPage: TWebForm} {*.html}; View.ErrorPage in 'View.ErrorPage.pas' {FViewErrorPage: TWebForm} {*.html},
View.ComplaintDetails in 'View.ComplaintDetails.pas' {FViewComplaintDetails: TWebForm} {*.html};
{$R *.res} {$R *.res}
......
...@@ -176,6 +176,11 @@ ...@@ -176,6 +176,11 @@
<FormType>dfm</FormType> <FormType>dfm</FormType>
<DesignClass>TWebForm</DesignClass> <DesignClass>TWebForm</DesignClass>
</DCCReference> </DCCReference>
<DCCReference Include="View.ComplaintDetails.pas">
<Form>FViewComplaintDetails</Form>
<FormType>dfm</FormType>
<DesignClass>TWebForm</DesignClass>
</DCCReference>
<None Include="index.html"/> <None Include="index.html"/>
<None Include="css\app.css"/> <None Include="css\app.css"/>
<None Include="css\spinner.css"/> <None Include="css\spinner.css"/>
......
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