Commit 95124371 by Mac Stephens

Add UnitDetails + UnitLogs endpoints/queries and implement WEB Core UnitDetails…

Add UnitDetails + UnitLogs endpoints/queries and implement WEB Core UnitDetails UI with logs table, navigation.
parent a35bb057
......@@ -1024,4 +1024,129 @@ object ApiDatabaseModule: TApiDatabaseModule
Value = nil
end>
end
object uqUnitDetails: TUniQuery
Connection = ucENTCAD
SQL.Strings = (
'SELECT'
' dua.UNITID,'
' dua.UNITNAME,'
' cun.CODE_DESC AS CARNUMBER_DESC,'
' cd.CODE_DESC AS DISTRICT_DESC,'
' ca.LOCATION,'
' cus.CODE_DESC AS UNIT_STATUS_DESC,'
' p1.PF_LNAME AS OFFICER1_LNAME,'
' p1.PF_FNAME AS OFFICER1_FNAME,'
' p1.PF_EMPNUM AS OFFICER1_EMPNUM,'
' p2.PF_LNAME AS OFFICER2_LNAME,'
' p2.PF_FNAME AS OFFICER2_FNAME,'
' p2.PF_EMPNUM AS OFFICER2_EMPNUM,'
' uc.UPDATETIME AS UPDATE_TIME'
'FROM DIS_UNITS_ACTIVE dua'
'LEFT JOIN CD_UNIT_NUMBER cun ON cun.AGENCYCODE = dua.CARNUMBER'
'LEFT JOIN CD_DISTRICT cd ON cd.AGENCYCODE = dua.DISTRICT'
'LEFT JOIN CFS_ACTIVE ca ON dua.UNITID = ca.UNITID'
'LEFT JOIN CD_UNITSTATUS cus ON ca.UNITSTATUS = cus.CODE'
'LEFT JOIN PERSONNEL p1 ON dua.OFFICER1ID = p1.PF_NAMEID'
'LEFT JOIN PERSONNEL p2 ON dua.OFFICER2ID = p2.PF_NAMEID'
'LEFT JOIN UNITS_CURRENT@AVL_LINK uc ON dua.UNITID = uc.UNITID'
'WHERE dua.UNITID = :UNITID')
Left = 192
Top = 312
ParamData = <
item
DataType = ftUnknown
Name = 'UNITID'
Value = nil
end>
object uqUnitDetailsUNITID: TFloatField
FieldName = 'UNITID'
end
object uqUnitDetailsUNITNAME: TStringField
FieldName = 'UNITNAME'
Size = 10
end
object uqUnitDetailsCARNUMBER_DESC: TStringField
FieldName = 'CARNUMBER_DESC'
ReadOnly = True
Size = 120
end
object uqUnitDetailsDISTRICT_DESC: TStringField
FieldName = 'DISTRICT_DESC'
ReadOnly = True
Size = 120
end
object uqUnitDetailsLOCATION: TStringField
FieldName = 'LOCATION'
ReadOnly = True
Size = 30
end
object uqUnitDetailsUNIT_STATUS_DESC: TStringField
FieldName = 'UNIT_STATUS_DESC'
ReadOnly = True
end
object uqUnitDetailsOFFICER1_LNAME: TStringField
FieldName = 'OFFICER1_LNAME'
ReadOnly = True
Size = 45
end
object uqUnitDetailsOFFICER1_FNAME: TStringField
FieldName = 'OFFICER1_FNAME'
ReadOnly = True
Size = 30
end
object uqUnitDetailsOFFICER1_EMPNUM: TStringField
FieldName = 'OFFICER1_EMPNUM'
ReadOnly = True
Size = 10
end
object uqUnitDetailsOFFICER2_LNAME: TStringField
FieldName = 'OFFICER2_LNAME'
ReadOnly = True
Size = 45
end
object uqUnitDetailsOFFICER2_FNAME: TStringField
FieldName = 'OFFICER2_FNAME'
ReadOnly = True
Size = 30
end
object uqUnitDetailsOFFICER2_EMPNUM: TStringField
FieldName = 'OFFICER2_EMPNUM'
ReadOnly = True
Size = 10
end
object uqUnitDetailsUPDATE_TIME: TDateTimeField
FieldName = 'UPDATE_TIME'
ReadOnly = True
end
end
object uqUnitLogs: TUniQuery
Connection = ucENTCAD
SQL.Strings = (
'select'
' dul."TIMESTAMP" as LOG_TIME,'
' dul.COMPLAINT as COMPLAINT_NUM,'
' dul.LOG as LOG_TEXT'
'from ENTCAD.DIS_UNIT_LOG dul'
'where dul.UNITID = :UNITID'
'order by dul."TIMESTAMP" desc')
Left = 190
Top = 374
ParamData = <
item
DataType = ftUnknown
Name = 'UNITID'
Value = nil
end>
object uqUnitLogsLOG_TIME: TDateTimeField
FieldName = 'LOG_TIME'
end
object uqUnitLogsCOMPLAINT_NUM: TStringField
FieldName = 'COMPLAINT_NUM'
Size = 10
end
object uqUnitLogsLOG_TEXT: TStringField
FieldName = 'LOG_TEXT'
Size = 2000
end
end
end
......@@ -151,6 +151,24 @@ type
uqMapUnitsOFFICER2_LNAME: TStringField;
uqMapUnitsOFFICER2_FNAME: TStringField;
uqMapUnitsOFFICER2_EMPNUM: TStringField;
uqUnitDetails: TUniQuery;
uqUnitDetailsUNITID: TFloatField;
uqUnitDetailsUNITNAME: TStringField;
uqUnitDetailsCARNUMBER_DESC: TStringField;
uqUnitDetailsDISTRICT_DESC: TStringField;
uqUnitDetailsLOCATION: TStringField;
uqUnitDetailsUNIT_STATUS_DESC: TStringField;
uqUnitDetailsOFFICER1_LNAME: TStringField;
uqUnitDetailsOFFICER1_FNAME: TStringField;
uqUnitDetailsOFFICER1_EMPNUM: TStringField;
uqUnitDetailsOFFICER2_LNAME: TStringField;
uqUnitDetailsOFFICER2_FNAME: TStringField;
uqUnitDetailsOFFICER2_EMPNUM: TStringField;
uqUnitDetailsUPDATE_TIME: TDateTimeField;
uqUnitLogs: TUniQuery;
uqUnitLogsLOG_TIME: TDateTimeField;
uqUnitLogsCOMPLAINT_NUM: TStringField;
uqUnitLogsLOG_TEXT: TStringField;
procedure uqComplaintListCalcFields(DataSet: TDataSet);
procedure uqMapComplaintsCalcFields(DataSet: TDataSet);
private
......
......@@ -26,6 +26,9 @@ type
[HttpGet] function GetComplaintHistory(const ComplaintId: string): TJSONObject;
[HttpGet] function GetComplaintContacts(const ComplaintId: string): TJSONObject;
[HttpGet] function GetComplaintWarnings(const ComplaintId: string): TJSONObject;
[HttpGet] function GetUnitDetails(const UnitId: string): TJSONObject;
[HttpGet] function GetUnitLogs(const UnitId: string): TJSONObject;
end;
......
......@@ -27,6 +27,8 @@ type
function GetComplaintHistory(const ComplaintId: string): TJSONObject;
function GetComplaintContacts(const ComplaintId: string): TJSONObject;
function GetComplaintWarnings(const ComplaintId: string): TJSONObject;
function GetUnitDetails(const UnitId: string): TJSONObject;
function GetUnitLogs(const UnitId: string): TJSONObject;
end;
implementation
......@@ -749,9 +751,140 @@ begin
end;
end;
function TApiService.GetUnitLogs(const UnitId: string): TJSONObject;
var
dataArr: TJSONArray;
rowObj: TJSONObject;
returnedCount: Integer;
ts: string;
complaintText: string;
begin
Logger.Log(4, '---TApiService.GetUnitLogs initiated: ' + UnitId);
Result := TJSONObject.Create;
TXDataOperationContext.Current.Handler.ManagedObjects.Add(Result);
dataArr := TJSONArray.Create;
returnedCount := 0;
try
with ApiDB.uqUnitLogs do
begin
ParamByName('UNITID').AsString := UnitId;
Open;
try
while not Eof do
begin
rowObj := TJSONObject.Create;
dataArr.AddElement(rowObj);
ts := '';
if not ApiDB.uqUnitLogsLOG_TIME.IsNull then
ts := FormatDateTime('yyyy-mm-dd hh:nn:ss', ApiDB.uqUnitLogsLOG_TIME.AsDateTime);
complaintText := Trim(ApiDB.uqUnitLogsCOMPLAINT_NUM.AsString);
if complaintText = '0' then
complaintText := 'N/A';
rowObj.AddPair('LogTime', ts);
rowObj.AddPair('Complaint', complaintText);
rowObj.AddPair('Log', ApiDB.uqUnitLogsLOG_TEXT.AsString);
Inc(returnedCount);
Next;
end;
finally
Close;
end;
end;
Result.AddPair('count', TJSONNumber.Create(returnedCount));
Result.AddPair('returned', TJSONNumber.Create(returnedCount));
Result.AddPair('data', dataArr);
Logger.Log(4, '---TApiService.GetUnitLogs End (returned=' + IntToStr(returnedCount) + ')');
except
on E: EXDataHttpException do
begin
Logger.Log(2, '---TApiService.GetUnitLogs http error: ' + E.Message);
raise;
end;
on E: Exception do
begin
Logger.Log(2, '---TApiService.GetUnitLogs error: ' + E.Message);
raise EXDataHttpException.Create(500, 'Failed to load unit logs');
end;
end;
end;
function TApiService.GetUnitDetails(const UnitId: string): TJSONObject;
var
obj: TJSONObject;
updateTimeText: string;
unitStatus: string;
begin
Logger.Log(4, '---TApiService.GetUnitDetails initiated: ' + UnitId);
Result := TJSONObject.Create;
TXDataOperationContext.Current.Handler.ManagedObjects.Add(Result);
try
with ApiDB.uqUnitDetails do
begin
ParamByName('UNITID').AsString := UnitId;
Open;
try
if Eof then
raise EXDataHttpException.Create(404, 'Unit not found');
obj := TJSONObject.Create;
obj.AddPair('UnitId', ApiDB.uqUnitDetailsUNITID.AsString);
obj.AddPair('UnitName', ApiDB.uqUnitDetailsUNITNAME.AsString);
obj.AddPair('CarNumberDesc', ApiDB.uqUnitDetailsCARNUMBER_DESC.AsString);
obj.AddPair('District', ApiDB.uqUnitDetailsDISTRICT_DESC.AsString);
obj.AddPair('Location', ApiDB.uqUnitDetailsLOCATION.AsString);
unitStatus := Trim(ApiDB.uqUnitDetailsUNIT_STATUS_DESC.AsString);
if unitStatus = '' then
unitStatus := 'Available';
obj.AddPair('Status', unitStatus);
obj.AddPair('Officer1Lname', ApiDB.uqUnitDetailsOFFICER1_LNAME.AsString);
obj.AddPair('Officer1Fname', ApiDB.uqUnitDetailsOFFICER1_FNAME.AsString);
obj.AddPair('Officer1Empnum', ApiDB.uqUnitDetailsOFFICER1_EMPNUM.AsString);
obj.AddPair('Officer2Lname', ApiDB.uqUnitDetailsOFFICER2_LNAME.AsString);
obj.AddPair('Officer2Fname', ApiDB.uqUnitDetailsOFFICER2_FNAME.AsString);
obj.AddPair('Officer2Empnum', ApiDB.uqUnitDetailsOFFICER2_EMPNUM.AsString);
updateTimeText := '';
if not ApiDB.uqUnitDetailsUPDATE_TIME.IsNull then
updateTimeText := FormatDateTime('yyyy-mm-dd hh:nn:ss', ApiDB.uqUnitDetailsUPDATE_TIME.AsDateTime);
obj.AddPair('UpdateTime', updateTimeText);
Result.AddPair('data', obj);
finally
Close;
end;
end;
except
on E: EXDataHttpException do
begin
Logger.Log(2, '---TApiService.GetUnitDetails http error: ' + E.Message);
raise;
end;
on E: Exception do
begin
Logger.Log(2, '---TApiService.GetUnitDetails error: ' + E.Message);
raise EXDataHttpException.Create(500, 'Failed to load unit details');
end;
end;
Logger.Log(4, '---TApiService.GetUnitDetails End');
end;
......
[Settings]
LogFileNum=552
LogFileNum=554
webClientVersion=0.1.0
object FViewComplaintDetails: TFViewComplaintDetails
Width = 800
Height = 672
Caption = 'tbl_logs'
CSSLibrary = cssBootstrap
ElementFont = efCSS
object btnHistory: TWebButton
......
object FViewUnitDetails: TFViewUnitDetails
Width = 640
Height = 480
CSSLibrary = cssBootstrap
ElementFont = efCSS
object tblLogs: TWebDBTableControl
Left = 166
Top = 114
Width = 300
Height = 200
ElementId = 'tbl_logs'
BorderColor = clSilver
ElementFont = efCSS
ElementHeaderClassName = 'table-light'
ElementTableClassName =
'table table-sm table-striped table-hover table-bordered mb-0 ali' +
'gn-middle'
Footer.ButtonActiveElementClassName = 'btn btn-primary'
Footer.ButtonElementClassName = 'btn btn-light'
Footer.DropDownElementClassName = 'form-control'
Footer.InputElementClassName = 'form-control'
Footer.LinkActiveElementClassName = 'link-primary'
Footer.LinkElementClassName = 'link-secondary'
Footer.ListElementClassName = 'pagination'
Footer.ListItemElementClassName = 'page-item'
Footer.ListLinkElementClassName = 'page-link'
Header.ButtonActiveElementClassName = 'btn btn-primary'
Header.ButtonElementClassName = 'btn btn-light'
Header.DropDownElementClassName = 'form-control'
Header.InputElementClassName = 'form-control'
Header.LinkActiveElementClassName = 'link-primary'
Header.LinkElementClassName = 'link-secondary'
Header.ListElementClassName = 'pagination'
Header.ListItemElementClassName = 'page-item'
Header.ListLinkElementClassName = 'page-link'
Columns = <
item
ElementClassName = 'text-nowrap'
DataField = 'LogTime'
Title = 'Log Time'
end
item
ElementClassName = 'text-nowrap'
DataField = 'Complaint'
Title = 'Complaint'
end
item
DataField = 'Log'
Title = 'Log'
end>
DataSource = wdsUnitLogs
end
object xdwcUnitDetails: TXDataWebClient
Connection = DMConnection.ApiConnection
Left = 150
Top = 394
end
object xdwdsUnitLogs: TXDataWebDataSet
Left = 274
Top = 394
object xdwdsUnitLogsLogTime: TStringField
FieldName = 'LogTime'
end
object xdwdsUnitLogsComplaint: TStringField
FieldName = 'Complaint'
end
object xdwdsUnitLogsLog: TStringField
FieldName = 'Log'
end
end
object wdsUnitLogs: TWebDataSource
DataSet = xdwdsUnitLogs
Left = 208
Top = 362
end
object xdwdsUnitDetails: TXDataWebDataSet
Left = 364
Top = 368
object xdwdsUnitDetailsUnitId: TStringField
FieldName = 'UnitId'
end
object xdwdsUnitDetailsUnitName: TStringField
FieldName = 'UnitName'
end
object xdwdsUnitDetailsCarNumberDesc: TStringField
FieldName = 'CarNumberDesc'
end
object xdwdsUnitDetailsDistrict: TStringField
FieldName = 'District'
end
object xdwdsUnitDetailsLocation: TStringField
FieldName = 'Location'
end
object xdwdsUnitDetailsStatus: TStringField
FieldName = 'Status'
end
object xdwdsUnitDetailsOfficer1LName: TStringField
FieldName = 'Officer1LName'
end
object xdwdsUnitDetailsOfficer1Fname: TStringField
FieldName = 'Officer1Fname'
end
object xdwdsUnitDetailsOfficer1Empnum: TStringField
FieldName = 'Officer1Empnum'
end
object xdwdsUnitDetailsOfficer2Lname: TStringField
FieldName = 'Officer2Lname'
end
object xdwdsUnitDetailsOfficer2Fname: TStringField
FieldName = 'Officer2Fname'
end
object xdwdsUnitDetailsOfficer2Empnum: TStringField
FieldName = 'Officer2Empnum'
end
object xdwdsUnitDetailsUpdateTime: TStringField
FieldName = 'UpdateTime'
end
end
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
<div class="d-flex flex-column h-100 w-100 overflow-hidden">
<div class="flex-grow-1 d-flex flex-column overflow-auto bg-light p-2 p-md-3" style="min-height:0;">
<!-- Sticky block: Summary header + (expanded) summary body -->
<div class="sticky-top bg-light" style="z-index:20;">
<!-- Summary header -->
<div class="card border-0 shadow-sm mb-2">
<div class="card-header bg-white py-2">
<button
class="btn btn-link text-decoration-none p-0 w-100 d-flex align-items-center justify-content-between"
type="button"
data-bs-toggle="collapse"
data-bs-target="#udetails_summary"
aria-expanded="false"
aria-controls="udetails_summary">
<span class="fw-semibold text-dark" id="lbl_summary_title">Summary</span>
<i class="fa fa-chevron-down"></i>
</button>
</div>
</div>
<!-- Summary body -->
<div id="udetails_summary" class="collapse">
<div class="card border-0 shadow-sm mb-2">
<div class="card-body py-2">
<!-- Optional: Close/Back row (wire in code) -->
<div class="d-flex justify-content-end mb-2">
<button type="button" class="btn btn-outline-secondary btn-sm" id="btn_close">Back</button>
</div>
<div class="row gy-1 gx-2">
<div class="col-5 col-sm-4 fw-semibold text-muted">Car:</div>
<div class="col-7 col-sm-8" id="lbl_car"></div>
<div class="col-5 col-sm-4 fw-semibold text-muted">Unit Name:</div>
<div class="col-7 col-sm-8" id="lbl_unit_name"></div>
<div class="col-5 col-sm-4 fw-semibold text-muted">District:</div>
<div class="col-7 col-sm-8" id="lbl_district"></div>
<div class="col-5 col-sm-4 fw-semibold text-muted">Location:</div>
<div class="col-7 col-sm-8" id="lbl_location"></div>
<div class="col-5 col-sm-4 fw-semibold text-muted">Status:</div>
<div class="col-7 col-sm-8" id="lbl_status"></div>
<div class="col-5 col-sm-4 fw-semibold text-muted">Officer 1:</div>
<div class="col-7 col-sm-8" id="lbl_officer1"></div>
<div class="col-5 col-sm-4 fw-semibold text-muted">Officer 2:</div>
<div class="col-7 col-sm-8" id="lbl_officer2"></div>
<div class="col-5 col-sm-4 fw-semibold text-muted">Updated:</div>
<div class="col-7 col-sm-8" id="lbl_updated"></div>
</div>
</div>
</div>
</div>
<!-- Logs header row (stays sticky) -->
<div class="pb-2">
<div class="d-flex align-items-center justify-content-between">
<div class="fw-semibold text-muted">Logs</div>
<!-- Spinner shown while loading logs -->
<div class="spinner-border spinner-border-sm text-secondary d-none" role="status" id="spinner_logs">
<span class="visually-hidden">Loading...</span>
</div>
</div>
</div>
</div>
<!-- Logs table (scroll with page) -->
<div class="card border-0 shadow-sm">
<div class="card-body p-0">
<div id="tbl_logs"></div>
</div>
</div>
</div>
</div>
......@@ -3,14 +3,56 @@ unit View.UnitDetails;
interface
uses
System.SysUtils, System.Classes, JS, Web, WEBLib.Graphics, WEBLib.Controls,
WEBLib.Forms, WEBLib.Dialogs;
System.SysUtils, System.Classes, JS, Web,
WEBLib.Forms, WEBLib.Dialogs, WEBLib.Graphics,
XData.Web.Client, XData.Web.JsonDataset, XData.Web.Dataset,
ConnectionModule,
Utils,
Data.DB, WEBLib.DB,
Vcl.Controls, WEBLib.Controls, WEBLib.Grids, WEBLib.DBCtrls;
type
TFViewUnitDetails = class(TWebForm)
xdwcUnitDetails: TXDataWebClient;
// Details (single-object) dataset
xdwdsUnitDetails: TXDataWebDataSet;
xdwdsUnitDetailsUnitId: TStringField;
xdwdsUnitDetailsUnitName: TStringField;
xdwdsUnitDetailsCarNumberDesc: TStringField;
xdwdsUnitDetailsDistrict: TStringField;
xdwdsUnitDetailsLocation: TStringField;
xdwdsUnitDetailsStatus: TStringField;
xdwdsUnitDetailsOfficer1Lname: TStringField;
xdwdsUnitDetailsOfficer1Fname: TStringField;
xdwdsUnitDetailsOfficer1Empnum: TStringField;
xdwdsUnitDetailsOfficer2Lname: TStringField;
xdwdsUnitDetailsOfficer2Fname: TStringField;
xdwdsUnitDetailsOfficer2Empnum: TStringField;
xdwdsUnitDetailsUpdateTime: TStringField;
// Logs (array) dataset + table
xdwdsUnitLogs: TXDataWebDataSet;
wdsUnitLogs: TWebDataSource;
tblLogs: TWebDBTableControl;
xdwdsUnitLogsLogTime: TStringField;
xdwdsUnitLogsComplaint: TStringField;
xdwdsUnitLogsLog: TStringField;
private
FUnitId: string;
FLoading: Boolean;
procedure InitializeForm;
procedure WireUi;
procedure CloseClick(Event: TJSEvent);
procedure SetTextById(const elementId, value: string);
procedure SetHiddenById(const elementId: string; hidden: Boolean);
function FormatOfficer(const lname, fname, empnum: string): string;
[async] procedure LoadAsync;
[async] procedure LoadLogsAsync;
public
class function CreateForm(AElementID, UnitId: string): TWebForm;
end;
......@@ -20,8 +62,11 @@ var
implementation
{$R *.dfm}
uses
View.Main,
View.Units;
{$R *.dfm}
class function TFViewUnitDetails.CreateForm(AElementID, UnitId: string): TWebForm;
......@@ -30,7 +75,7 @@ class function TFViewUnitDetails.CreateForm(AElementID, UnitId: string): TWebFor
with TFViewUnitDetails(AForm) do
begin
FUnitId := UnitId;
InitializeForm; // kick off loading / UI binding here
InitializeForm;
end;
end;
......@@ -38,13 +83,180 @@ begin
Application.CreateForm(TFViewUnitDetails, AElementID, Result, @AfterCreate);
end;
procedure TFViewUnitDetails.InitializeForm;
begin
// TODO:
// - call your XData endpoint with FUnitId
// - bind fields / populate controls
// - handle spinner / errors as you do elsewhere
xdwcUnitDetails.Connection := DMConnection.ApiConnection;
xdwdsUnitDetails.Connection := DMConnection.ApiConnection;
xdwdsUnitLogs.Connection := DMConnection.ApiConnection;
FLoading := False;
WireUi;
LoadAsync;
end;
procedure TFViewUnitDetails.WireUi;
var
btnClose: TJSElement;
begin
btnClose := Document.getElementById('btn_close');
if btnClose <> nil then
btnClose.addEventListener('click', @CloseClick);
end;
procedure TFViewUnitDetails.CloseClick(Event: TJSEvent);
begin
Event.preventDefault;
if Assigned(FViewMain) then
begin
FViewMain.SetActiveNavButton('view.main.btnunits');
FViewMain.ShowForm(TFViewUnits);
end;
end;
procedure TFViewUnitDetails.SetTextById(const elementId, value: string);
var
el: TJSElement;
begin
el := Document.getElementById(elementId);
if el <> nil then
TJSHtmlElement(el).innerText := value;
end;
procedure TFViewUnitDetails.SetHiddenById(const elementId: string; hidden: Boolean);
var
el: TJSHTMLElement;
begin
el := TJSHTMLElement(Document.getElementById(elementId));
if el = nil then
Exit;
if hidden then
el.classList.add('d-none')
else
el.classList.remove('d-none');
end;
function TFViewUnitDetails.FormatOfficer(const lname, fname, empnum: string): string;
var
nameText: string;
begin
nameText := Trim(lname);
if nameText = '' then
Exit('');
if Trim(fname) <> '' then
nameText := nameText + ', ' + Trim(fname);
if Trim(empnum) <> '' then
nameText := nameText + ' (' + Trim(empnum) + ')';
Result := nameText;
end;
[async] procedure TFViewUnitDetails.LoadAsync;
var
resp: TXDataClientResponse;
rootObj: TJSObject;
dataObj: TJSObject;
summaryTitle: string;
officer1Text: string;
officer2Text: string;
begin
if FLoading then
Exit;
FLoading := True;
Utils.ShowSpinner('spinner');
try
resp := await(xdwcUnitDetails.RawInvokeAsync('IApiService.GetUnitDetails', [FUnitId]));
rootObj := TJSObject(resp.Result);
dataObj := TJSObject(rootObj['data']);
xdwdsUnitDetails.Close;
xdwdsUnitDetails.SetJsonData(dataObj);
xdwdsUnitDetails.Open;
summaryTitle := xdwdsUnitDetails.FieldByName('UnitName').AsString;
if Trim(summaryTitle) <> '' then
SetTextById('lbl_summary_title', 'Summary for Unit ' + summaryTitle)
else
SetTextById('lbl_summary_title', 'Summary for Unit ' + xdwdsUnitDetails.FieldByName('UnitId').AsString);
SetTextById('lbl_car', xdwdsUnitDetails.FieldByName('CarNumberDesc').AsString);
SetTextById('lbl_unit_name', xdwdsUnitDetails.FieldByName('UnitName').AsString);
SetTextById('lbl_district', xdwdsUnitDetails.FieldByName('District').AsString);
SetTextById('lbl_location', xdwdsUnitDetails.FieldByName('Location').AsString);
SetTextById('lbl_status', xdwdsUnitDetails.FieldByName('Status').AsString);
SetTextById('lbl_updated', xdwdsUnitDetails.FieldByName('UpdateTime').AsString);
officer1Text := FormatOfficer(
xdwdsUnitDetails.FieldByName('Officer1Lname').AsString,
xdwdsUnitDetails.FieldByName('Officer1Fname').AsString,
xdwdsUnitDetails.FieldByName('Officer1Empnum').AsString
);
officer2Text := FormatOfficer(
xdwdsUnitDetails.FieldByName('Officer2Lname').AsString,
xdwdsUnitDetails.FieldByName('Officer2Fname').AsString,
xdwdsUnitDetails.FieldByName('Officer2Empnum').AsString
);
SetTextById('lbl_officer1', officer1Text);
SetTextById('lbl_officer2', officer2Text);
await(LoadLogsAsync);
Utils.HideSpinner('spinner');
FLoading := False;
except
on E: EXDataClientRequestException do
begin
Utils.HideSpinner('spinner');
FLoading := False;
Utils.ShowErrorModal(E.ErrorResult.ErrorMessage);
end;
on E: Exception do
begin
Utils.HideSpinner('spinner');
FLoading := False;
Utils.ShowErrorModal(E.Message);
end;
end;
end;
[async] procedure TFViewUnitDetails.LoadLogsAsync;
var
resp: TXDataClientResponse;
rootObj: TJSObject;
dataArr: TJSArray;
begin
SetHiddenById('spinner_logs', False);
try
resp := await(xdwcUnitDetails.RawInvokeAsync('IApiService.GetUnitLogs', [FUnitId]));
rootObj := TJSObject(resp.Result);
dataArr := TJSArray(rootObj['data']);
xdwdsUnitLogs.Close;
xdwdsUnitLogs.SetJsonData(dataArr);
xdwdsUnitLogs.Open;
SetHiddenById('spinner_logs', True);
except
on E: EXDataClientRequestException do
begin
SetHiddenById('spinner_logs', True);
Utils.ShowErrorModal(E.ErrorResult.ErrorMessage);
end;
on E: Exception do
begin
SetHiddenById('spinner_logs', True);
Utils.ShowErrorModal(E.Message);
end;
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