From ae4d6806dcc5167cde4b2e1af181261862d4b421 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 24 Jul 2024 11:00:24 -0700 Subject: [PATCH] add sorting and request type filter for historical search --- .../FOI/foiHistoricalSearchServices.js | 20 ++++++----- .../AdvancedSearch/DataGridAdvancedSearch.js | 34 +++++++++++++------ .../request_api/models/factRequestDetails.py | 20 ++++++++--- .../request_api/resources/historicalsearch.py | 1 + 4 files changed, 52 insertions(+), 23 deletions(-) diff --git a/forms-flow-web/src/apiManager/services/FOI/foiHistoricalSearchServices.js b/forms-flow-web/src/apiManager/services/FOI/foiHistoricalSearchServices.js index 9a9f19b55..3e2da3ac4 100644 --- a/forms-flow-web/src/apiManager/services/FOI/foiHistoricalSearchServices.js +++ b/forms-flow-web/src/apiManager/services/FOI/foiHistoricalSearchServices.js @@ -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, diff --git a/forms-flow-web/src/components/FOI/Dashboard/IAO/AdvancedSearch/DataGridAdvancedSearch.js b/forms-flow-web/src/components/FOI/Dashboard/IAO/AdvancedSearch/DataGridAdvancedSearch.js index f4ace3a36..34f339605 100644 --- a/forms-flow-web/src/components/FOI/Dashboard/IAO/AdvancedSearch/DataGridAdvancedSearch.js +++ b/forms-flow-web/src/components/FOI/Dashboard/IAO/AdvancedSearch/DataGridAdvancedSearch.js @@ -542,6 +542,12 @@ const DataGridAdvancedSearch = ({ userDetail }) => { ); } + const test = (model) => { + if (model.length > 0) { + setHistoricsearchSortModel(model) + } + } + return ( { 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, "") ] ) } @@ -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: ()=> }} - sortingOrder={["desc", "asc"]} sortModel={[sortHistoricsearchSortModel[0]]} sortingMode={"server"} + onSortModelChange={test} + loading={searchHistoricalDataLoading} diff --git a/historical-search-api/request_api/models/factRequestDetails.py b/historical-search-api/request_api/models/factRequestDetails.py index 539a0738d..9fa711504 100644 --- a/historical-search-api/request_api/models/factRequestDetails.py +++ b/historical-search-api/request_api/models/factRequestDetails.py @@ -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 \ @@ -180,7 +182,14 @@ 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) @@ -188,6 +197,8 @@ def getadvancedsearchresults(cls,isiaorestictedmanager:False, params): if(idx!=(conditioncount-1)): basequery+= ' AND ' + + if(conditioncount == 0): basequery+= "LOWER(description) like LOWER('%{0}%')".format(keyword) @@ -197,7 +208,7 @@ 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' @@ -205,10 +216,11 @@ def getadvancedsearchresults(cls,isiaorestictedmanager:False, params): 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} \ No newline at end of file diff --git a/historical-search-api/request_api/resources/historicalsearch.py b/historical-search-api/request_api/resources/historicalsearch.py index 6712296e6..988100b75 100644 --- a/historical-search-api/request_api/resources/historicalsearch.py +++ b/historical-search-api/request_api/resources/historicalsearch.py @@ -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'),