Skip to content

Commit

Permalink
Merge pull request #738 from bcgov/dev-rook
Browse files Browse the repository at this point in the history
filter comments, consult changes and other bug fixes to test-rook
  • Loading branch information
divyav-aot authored Jan 25, 2024
2 parents 9970e8a + c819053 commit 2b2d073
Show file tree
Hide file tree
Showing 12 changed files with 294 additions and 56 deletions.
9 changes: 9 additions & 0 deletions MCS.FOI.S3FileConversion/MCS.FOI.S3FileConversion/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,14 @@ static async System.Threading.Tasks.Task Main(string[] args)
{
for (int i = 0; i < attachments.Count; i++)
{
Dictionary<string, object> attributesDictionary = JsonSerializer.Deserialize<Dictionary<string, object>>(attachments[i]["attributes"]);
string _incompatible;
if (attributesDictionary.ContainsKey("incompatible"))
{
_incompatible = attributesDictionary["incompatible"].ToString().ToLower();
} else {
_incompatible = "false";
}
if (Array.IndexOf(ConversionSettings.ConversionFormats, attachments[i]["extension"].ToLower()) == -1)
{
db.StreamAdd(dedupeStreamKey, new NameValueEntry[]
Expand All @@ -131,6 +139,7 @@ static async System.Threading.Tasks.Task Main(string[] args)
new("batch", message["batch"]),
new("jobid", jobIDs[attachments[i]["filepath"]]["jobID"]),
new("documentmasterid", jobIDs[attachments[i]["filepath"]]["masterID"]),
new("incompatible", _incompatible),
new("trigger", "attachment"),
new("createdby", message["createdby"]),
new("usertoken", message["usertoken"])
Expand Down
2 changes: 1 addition & 1 deletion api/reviewer_api/models/DocumentPageflags.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,4 +342,4 @@ class Meta:
"updatedby",
"updated_at",
"redactionlayerid",
)
)
50 changes: 37 additions & 13 deletions api/reviewer_api/services/documentpageflagservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from datetime import datetime


class documentpageflagservice:
class documentpageflagservice:
def getpageflags(self, requestid, redactionlayer, documentids):
layerids = []
layerids.append(redactionlayerservice().getredactionlayerid(redactionlayer))
Expand Down Expand Up @@ -201,6 +201,7 @@ def __filterandsavepageflags(
pageflag["pageflag"],
json.dumps(userinfo),
redactionlayerid,
json.dumps(pageflag["attributes"]),
)

def __getupdatedpageflag(self, pageflag, pages_to_remove):
Expand All @@ -214,20 +215,43 @@ def __getupdatedpageflag(self, pageflag, pages_to_remove):
]

def __createnewpageflag(self, pageflag, data):
formattted_data = self.__formatpageflag(data)
if pageflag is not None and len(pageflag) > 0:
isnew = True
for entry in pageflag:
if entry["page"] == data["page"]:
isnew = False
pageflag.remove(entry)
pageflag.append(formattted_data)
if isnew == True:
pageflag.append(formattted_data)
else:
formatted_data = self.__formatpageflag(data)
if not pageflag:
pageflag = []
pageflag.append(formattted_data)
isnew = True
updated = False
for index, entry in enumerate(pageflag):
if entry["page"] == data["page"]:
isnew = False
if data["flagid"] == 4:
pageflag, updated = self.__handleconsultflag(data, entry, index, pageflag, formatted_data)
# handle all other flags except consult
elif data["flagid"] != 4 and entry["flagid"] != 4:
del pageflag[index]
pageflag.append(formatted_data)
updated = True
break

if isnew or not updated:
pageflag.append(formatted_data)

return pageflag

def __handleconsultflag(self, data, entry, index, pageflag, formatted_data):
updated = False
# remove consult flag
if data["flagid"] == 4 and not data["other"] and not data["programareaid"]:
if entry["flagid"] == data["flagid"]:
del pageflag[index]
updated = True
return pageflag, updated
# update consult flag
elif data["flagid"] == 4 and entry["flagid"] == data["flagid"]:
del pageflag[index]
pageflag.append(formatted_data)
updated = True
return pageflag, updated
return pageflag, updated

def __formatpageflag(self, data):
_normalised = data
Expand Down
4 changes: 4 additions & 0 deletions api/reviewer_api/services/documentservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,10 @@ def getdocuments(self, requestid,bcgovcode):
map(lambda d: {"divisionid": d}, documentdivisions)
)
document["divisions"] = list(map(lambda d: divisions[d], documentdivisions))
# For replaced attachments, change filepath to .pdf instead of original extension
if "trigger" in document["attributes"] and document["attributes"]["trigger"] == "recordreplace":
base_path, current_extension = path.splitext(document["filepath"])
document["filepath"] = base_path + ".pdf"

return [documents[documentid] for documentid in documents]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ def gets3documenthashcode(producermessage):
filepath = path.splitext(filepath)[0] + extension
response = requests.get("{0}".format(filepath), auth=auth, stream=True)
reader = None
if extension.lower() in [".pdf"]:

if extension.lower() in [".pdf"] or (
producermessage.attributes.get("isattachment", False) and producermessage.trigger == "recordreplace"
):
reader = PdfReader(BytesIO(response.content))

# "No of pages in {0} is {1} ".format(_filename, len(reader.pages)))
Expand Down
11 changes: 10 additions & 1 deletion web/src/apiManager/services/docReviewerService.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,18 @@ export const fetchDocuments = (

httpGETRequest(apiUrlGet, {}, UserService.getToken())
.then((res:any) => {
const getFileExt = (filepath: any) => {
const parts = filepath.split(".")
const fileExt = parts.pop()
return fileExt
}
if (res.data) {
// res.data.documents has all documents including the incompatible ones, below code is to filter out the incompatible ones
const __files = res.data.documents.filter((d: any) => !d.attributes.incompatible);
const __files = res.data.documents.filter((d: any) => {
const isPdfFile = getFileExt(d.filepath) === "pdf"
const isCompatible = !d.attributes.incompatible || isPdfFile
return isCompatible
});
store.dispatch(setDocumentList(__files) as any);
store.dispatch(setRequestNumber(res.data.requestnumber) as any);
store.dispatch(setRequestStatus(res.data.requeststatuslabel) as any);
Expand Down
4 changes: 3 additions & 1 deletion web/src/components/FOI/Home/ConsultModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ const ConsultModal = ({
}

const isSaveDisabled = () => {
return _.isEqual(selectedPageFlag, initialPageFlag) || (selectedPageFlag.other.length + selectedPageFlag.programareaid.length) === 0;

return (_.isEqual(selectedPageFlag, initialPageFlag));
// return (_.isEqual(selectedPageFlag, initialPageFlag) || (selectedPageFlag.other.length + selectedPageFlag.programareaid.length) === 0);
}

return (
Expand Down
6 changes: 6 additions & 0 deletions web/src/components/FOI/Home/DocumentSelector.scss
Original file line number Diff line number Diff line change
Expand Up @@ -275,3 +275,9 @@
margin-bottom:12px;
}
}
.MuiTreeItem-content {
.MuiTreeItem-iconContainer {
justify-content: right !important;
gap: 2px !important;
}
}
81 changes: 55 additions & 26 deletions web/src/components/FOI/Home/DocumentSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,15 @@ const DocumentSelector = React.forwardRef(({
//Revisit this method & assign icons when fetching itself!!
const assignPageIcon = (docId: number, page: number) => {
let docs: any = pageFlags?.find((doc: any) => doc?.documentid === docId);
let pageFlagObj = docs?.pageflag?.find((flag: any) => flag.page === page);
return assignIcon(pageFlagObj?.flagid);
let pageFlagObjs = docs?.pageflag?.filter((flag: any) => flag.page === page).sort((a: any, b: any) => (Number(b.flagid === pageFlagTypes["Consult"] || false)) - (Number(a.flagid === pageFlagTypes["Consult"] || false)));
let assignIconValue: any = [];
for (const pageFlag of pageFlagObjs) {
if (pageFlag.flagid !== undefined) {
assignIconValue.push({icon: assignIcon(pageFlag.flagid), flagid: pageFlag.flagid});
}
}
return assignIconValue;

}

let arr: any[] = [];
Expand Down Expand Up @@ -338,6 +345,9 @@ const DocumentSelector = React.forwardRef(({
const openContextMenu = (file: any, page: number, e: any) => {
e.preventDefault();
let nodeId: string = e.target.parentElement.parentElement.id;
if (nodeId === "") {
nodeId = e.currentTarget.id;
}
nodeId = nodeId.substring(nodeId.indexOf('{'));
let selectedNodes: any;
if (!selected.includes(nodeId)) {
Expand Down Expand Up @@ -454,21 +464,23 @@ const DocumentSelector = React.forwardRef(({

const getFlagName = (file: any, pageNo: number) => {
let flag: any = file?.pageFlag?.find((flg: any) => flg.page === pageNo);
if (flag.flagid === 4 && file.consult?.length > 0) {
let ministries = flag.programareaid.map((m: any) => consultMinistries?.find((ministry: any) => ministry.programareaid === m)?.iaocode);
ministries.push(...flag.other);
let consultFlag: any = file?.pageFlag?.find((flg: any) => flg.page === pageNo && flg.flagid === 4);
if (consultFlag && file.consult?.length > 0) {
let ministries = consultFlag.programareaid.map((m: any) => consultMinistries?.find((ministry: any) => ministry.programareaid === m)?.iaocode);
ministries.push(...consultFlag.other);
return `Consult - [` + ministries.join(`]\nConsult - [`) + ']';
}
return PAGE_FLAGS[flag.flagid as keyof typeof PAGE_FLAGS];
}

const codeById: Record<number, string> = {}
if (consultMinistries && consultMinistries?.length > 0) {
const codeById: Record<number, string> = consultMinistries?.reduce((acc: any, item: any) => {
acc[item.programareaid] = item.iaocode;
return acc;
}, {});
const codeById: Record<number, String> = {};
if (consultMinistries && consultMinistries?.length > 0) {
consultMinistries?.map((item: any) => {
codeById[item.programareaid] = item.iaocode;
});
}



const openConsulteeList = (e: any) => {
const consultFlagged = files.filter((file: any) => file.pageFlag?.find((obj: any) => (obj.flagid == 4)));
Expand All @@ -488,8 +500,7 @@ const DocumentSelector = React.forwardRef(({


const showConsultee = (assignedConsulteeList: any[]) => assignedConsulteeList?.map((consultee: any, index: number) => {
return (
<>
return (
<div key={consultee.id} className="consulteeItem">
<span style={{ marginRight: '10px' }}>
<input
Expand All @@ -502,8 +513,7 @@ const DocumentSelector = React.forwardRef(({
<label htmlFor={`checkbox-${index}`}>
{consultee.code}
</label>
</div>
</>
</div>
)
})

Expand All @@ -525,6 +535,17 @@ const DocumentSelector = React.forwardRef(({
setOpenConsulteeModal(false)
};

const addIcons = (file: any, p: any) => {
return assignPageIcon(file.documentid, p + 1).map((icon: any, index: any) => (
<FontAwesomeIcon
key={icon.flagid}
className='leftPanelIcons'
icon={icon.icon as IconProp}
size='1x'
title={PAGE_FLAGS[icon.flagid as keyof typeof PAGE_FLAGS]}
/>
))
}

const consulteeFilterView = (file: any, p: number, division?: any) => {
return (
Expand All @@ -534,8 +555,8 @@ const DocumentSelector = React.forwardRef(({
(obj.programareaid?.some((val: any) => consulteeFilter.includes(val))) ||
(obj.other?.some((val: any) => consulteeFilter.includes(val))))))
&&
<div ref={pageRefs.current[displayStitchedPageNo(file, pageMappedDocs, p + 1) - 1]}>
<StyledTreeItem nodeId={division ? `{"division": ${division?.divisionid}, "docid": ${file.documentid}, "page": ${p + 1}}` : `{"docid": ${file.documentid}, "page": ${p + 1}}`} key={p + 1} icon={<FontAwesomeIcon className='leftPanelIcons' icon={assignPageIcon(file.documentid, p + 1) as IconProp} size='1x' />}
<div ref={pageRefs.current[displayStitchedPageNo(file, pageMappedDocs, p + 1) - 1]}>
<StyledTreeItem nodeId={division ? `{"division": ${division?.divisionid}, "docid": ${file.documentid}, "page": ${p + 1}}` : `{"docid": ${file.documentid}, "page": ${p + 1}}`} key={p + 1} icon= {addIcons(file, p)}
title={getFlagName(file, p + 1)} label={isConsult(file.consult, p + 1) ? `Page ${displayStitchedPageNo(file, pageMappedDocs, p + 1)} (${ministryOrgCode(p + 1, file.consult)})` : `Page ${displayStitchedPageNo(file, pageMappedDocs, p + 1)}`}
onContextMenu={(e) => openContextMenu(file, p + 1, e)} />
</div>
Expand All @@ -548,8 +569,8 @@ const DocumentSelector = React.forwardRef(({
const noFilterView = (file: any, p: number, division?: any) => {
return (
(file.pageFlag?.find((obj: any) => obj.page === p + 1) ?
<div ref={pageRefs.current[displayStitchedPageNo(file, pageMappedDocs, p + 1) - 1]}>
<StyledTreeItem nodeId={division ? `{"division": ${division.divisionid}, "docid": ${file.documentid}, "page": ${p + 1}}` : `{"docid": ${file.documentid}, "page": ${p + 1}}`} key={p + 1} icon={<FontAwesomeIcon className='leftPanelIcons' icon={assignPageIcon(file.documentid, p + 1) as IconProp} size='1x' />}
<div ref={pageRefs.current[displayStitchedPageNo(file, pageMappedDocs, p + 1) - 1]}>
<StyledTreeItem nodeId={division ? `{"division": ${division.divisionid}, "docid": ${file.documentid}, "page": ${p + 1}}` : `{"docid": ${file.documentid}, "page": ${p + 1}}`} key={p + 1} icon= {addIcons(file, p)}
title={getFlagName(file, p + 1)} label={isConsult(file.consult, p + 1) ? `Page ${displayStitchedPageNo(file, pageMappedDocs, p + 1)} (${ministryOrgCode(p + 1, file.consult)})` : `Page ${displayStitchedPageNo(file, pageMappedDocs, p + 1)}`}
onContextMenu={(e) => openContextMenu(file, p + 1, e)} />
</div>
Expand All @@ -570,7 +591,7 @@ const DocumentSelector = React.forwardRef(({
return (file.pageFlag?.find((obj: any) => obj.page === p + 1 && obj.flagid != 4 && filterFlags?.includes(obj.flagid))) ?
(
<div ref={pageRefs.current[displayStitchedPageNo(file, pageMappedDocs, p + 1) - 1]}>
<StyledTreeItem nodeId={`{"docid": ${file.documentid}, "page": ${p + 1}}`} key={p + 1} icon={<FontAwesomeIcon className='leftPanelIcons' icon={assignPageIcon(file.documentid, p + 1) as IconProp} size='1x' />}
<StyledTreeItem nodeId={`{"docid": ${file.documentid}, "page": ${p + 1}}`} key={p + 1} icon= {addIcons(file, p)}
title={getFlagName(file, p + 1)} label={isConsult(file.consult, p + 1) ? `Page ${displayStitchedPageNo(file, pageMappedDocs, p + 1)} (${ministryOrgCode(p + 1, file.consult)})` : `Page ${displayStitchedPageNo(file, pageMappedDocs, p + 1)}`}
onContextMenu={(e) => openContextMenu(file, p + 1, e)} />
</div>
Expand Down Expand Up @@ -694,8 +715,18 @@ const DocumentSelector = React.forwardRef(({
}

const handleExpandClick = () => {
setExpanded((oldExpanded:any) =>
oldExpanded.length === 0 ? (organizeBy == "lastmodified" ? expandall : expandallorganizebydivision) : [],
setExpanded((oldExpanded:any) => {
let result: any = [];
if (oldExpanded.length === 0 ) {
if (organizeBy == "lastmodified" ) {
result = expandall;
}
else {
result = expandallorganizebydivision;
}
}
return result;
}
);
};

Expand All @@ -704,7 +735,6 @@ const DocumentSelector = React.forwardRef(({
};

return (
<>
<div className='leftPanel'>
<Stack sx={{ maxHeight: "calc(100vh - 117px)" }}>
<Paper
Expand Down Expand Up @@ -815,12 +845,12 @@ const DocumentSelector = React.forwardRef(({
</>
)}

< >

<FontAwesomeIcon key='0' title='No Flag'
className='filterIcons'
onClick={(event) => applyFilter(0, null, event, [])} id='0'
icon={faCircleExclamation as IconProp} size='1x' />
</>

</span>

<Popover
Expand Down Expand Up @@ -906,7 +936,6 @@ const DocumentSelector = React.forwardRef(({
</Stack>

</div>
</>
)
}
)
Expand Down
21 changes: 19 additions & 2 deletions web/src/components/FOI/Home/Home.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,31 @@ function Home() {
fetchDocuments(
parseInt(foiministryrequestid),
async (data) => {

const getFileExt = (filepath) => {
const parts = filepath.split(".")
const fileExt = parts.pop()
return fileExt
}
// New code added to get the incompatable files for download redline
// data has all the files including incompatable ones
// _files has all files except incompatable ones
const _incompatableFiles = data.filter(
(d) => d.attributes.incompatible
(d) => {
const isPdfFile = getFileExt(d.filepath) === "pdf"
if (isPdfFile) {
return false
} else {
return d.attributes.incompatible
}
}
);
setIncompatibleFiles(_incompatableFiles);
const _files = data.filter((d) => !d.attributes.incompatible);
const _files = data.filter((d) => {
const isPdfFile = getFileExt(d.filepath) === "pdf"
const isCompatible = !d.attributes.incompatible || isPdfFile
return isCompatible
});
setFiles(_files);
setCurrentPageInfo({ file: _files[0] || {}, page: 1 });
if (_files.length > 0) {
Expand Down
Loading

0 comments on commit 2b2d073

Please sign in to comment.