Skip to content

Commit

Permalink
Merge pull request #5337 from bcgov/dev-rook-NK-FOIMOD-3184
Browse files Browse the repository at this point in the history
add sorting and request type filter for historical search
  • Loading branch information
nkan-aot2 authored Jul 24, 2024
2 parents 85362d1 + ae4d680 commit 2aabf55
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,24 @@ export const fetchHistoricalSearchData = ({
errorCallback,
dispatch,
}) => {
let sortingItems = [];
let sortingOrders = [];
sort.forEach((item) => {
sortingItems.push(item.field);
sortingOrders.push(item.sort);
});
// let sortingItems = [];
// let sortingOrders = [];
// sort.forEach((item) => {
// sortingItems.push(item.field);
// sortingOrders.push(item.sort);
// });

if (sort[0].field === 'axisrequestid') {
sort[0].field = 'visualrequestfilenumber'
}

httpGETRequest(
API.FOI_HISTORICAL_SEARCH_API,
{
page: page,
size: size,
sortingitem: sortingItems,
sortingorder: sortingOrders,
sortingitem: sort[0]['field'],
sortingorder: sort[0]['sort'],
search: search,
keywords: keywords,
requestType: requestType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,12 @@ const DataGridAdvancedSearch = ({ userDetail }) => {
);
}

const test = (model) => {
if (model.length > 0) {
setHistoricsearchSortModel(model)
}
}

return (
<ConditionalComponent condition={!!queryData}>
<Grid
Expand Down Expand Up @@ -611,11 +617,9 @@ const DataGridAdvancedSearch = ({ userDetail }) => {
onSortModelChange={(model) => setSortModel(model)}
getRowClassName={(params) =>
clsx(
`super-app-theme--${params.row.currentState
.toLowerCase()
.replace(/ +/g, "")}`,
`super-app-theme--${params.row.currentState?.toLowerCase().replace(/ +/g, "")}`,
tableInfo?.stateClassName?.[
params.row.currentState.toLowerCase().replace(/ +/g, "")
params.row.currentState?.toLowerCase().replace(/ +/g, "")
]
)
}
Expand All @@ -627,24 +631,32 @@ const DataGridAdvancedSearch = ({ userDetail }) => {
autoHeight
className="foi-data-grid"
getRowId={(row) => row.axisrequestid}
rows={searchHistoricalSearchResults || []}
columns={HistoricalSearchResultsColumns}
rows={searchHistoricalSearchResults?.results || []}
columns={historiccolumnsRef?.current}
rowHeight={30}
headerHeight={50}
rowCount={0}
pageSize={10}
rowsPerPageOptions={[10]}
rowCount={searchHistoricalSearchResults?.count || 0}
pageSize={historicrowsState.pageSize}
// rowsPerPageOptions={[10]}
hideFooterSelectedRowCount={true}
disableColumnMenu={true}
pagination
//paginationMode="server"
paginationMode="server"
initialState={{
pagination: historicrowsState
}}
onPageChange={(newPage) => sethistoricRowsState((prev) => ({ ...prev, page: newPage }))}
onPageSizeChange={(newpageSize) =>
sethistoricRowsState((prev) => ({ ...prev, pageSize: newpageSize }))
}
components={{
Footer: ()=> <CustomFooter rowCount={searchHistoricalSearchResults?.count || 0} defaultSortModel={defaultHistoricalResultsTableInfo.sort} footerFor={"advancedsearch"}></CustomFooter>
}}

sortingOrder={["desc", "asc"]}
sortModel={[sortHistoricsearchSortModel[0]]}
sortingMode={"server"}
onSortModelChange={test}


loading={searchHistoricalDataLoading}

Expand Down
20 changes: 16 additions & 4 deletions historical-search-api/request_api/models/factRequestDetails.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,10 @@ def getdescriptionhistorybyid(cls, requestid):
@classmethod
def getadvancedsearchresults(cls,isiaorestictedmanager:False, params):
searchresults = []
count = 0
try:
basequery = 'SELECT foirequestid \
basequery = 'SELECT count(*) OVER() AS full_count\
,foirequestid \
,requesttypename \
,applicantname \
,visualrequestfilenumber \
Expand Down Expand Up @@ -180,14 +182,23 @@ def getadvancedsearchresults(cls,isiaorestictedmanager:False, params):
for keyword in params['keywords']:
filterbysearchcondition.append("LOWER(visualrequestfilenumber) like LOWER('%{0}%')".format(keyword))

conditioncount = len(filterbysearchcondition)
requesttypecondition = []
if len(params['requesttype'] + params['requestflags']) > 0:
for requesttype in (params['requesttype'] + params['requestflags']):
if (requesttype == 'oipc'): requesttype = 'review'
requesttypecondition.append("LOWER(requesttypename) like '%{0}%'".format(requesttype))
basequery+= (' (' +' OR '.join(requesttypecondition) + ')')

conditioncount = len(filterbysearchcondition + requesttypecondition)

for idx,searchcondition in enumerate(filterbysearchcondition):
basequery+= ' {0} '.format(searchcondition)

if(idx!=(conditioncount-1)):
basequery+= ' AND '



if(conditioncount == 0):
basequery+= "LOWER(description) like LOWER('%{0}%')".format(keyword)

Expand All @@ -197,18 +208,19 @@ def getadvancedsearchresults(cls,isiaorestictedmanager:False, params):
basequery+= ' ORDER BY {0} {1}'.format(params['sortingitem'],params['sortingorder'])

if params['size'] is not None:
basequery+= ' LIMIT {0}'.format(params['size'])
basequery+= ' LIMIT {0} OFFSET {1}'.format(params['size'], (params['page'] - 1) * params['size'] )
else:
basequery+= ' LIMIT 100'

rs = db.session.execute(text(basequery))

for row in rs:
searchresults.append({"axisrequestid": row["visualrequestfilenumber"], "description": row["description"], "assignee": row["assignee"], "requeststatus": row["requeststatus"], "applicantname": row["applicantname"], "requesttype": row["requesttypename"],"receiveddate": row["receiveddate"],"oipcno": row["oipcno"]})
count = row["full_count"]
except Exception as ex:
logging.error(ex)
raise ex
finally:
db.session.close()
return searchresults
return {'results': searchresults, 'count': count}

Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def get():
'usertype': AuthHelper.getusertype(),
'groups': '',
'size': flask.request.args.get('size', DEFAULT_SIZE, type=int),
'page': flask.request.args.get('page', DEFAULT_SIZE, type=int),
'sortingitem': flask.request.args.get('sortingitem'),
'sortingorder': flask.request.args.get('sortingorder'),

Expand Down

0 comments on commit 2aabf55

Please sign in to comment.