Skip to content

Commit

Permalink
Merge pull request #315 from wcmc-its/dev_v2_mrj4001
Browse files Browse the repository at this point in the history
Dev v2 mrj4001
  • Loading branch information
mrj4001 authored Apr 17, 2023
2 parents b552bae + 94b3700 commit 16f0af5
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 33 deletions.
14 changes: 7 additions & 7 deletions controllers/db/reports/publication.report.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,22 @@ export const generatePubsRtf = async (
try {
let apiBody: GeneratePubsApiBody = JSON.parse(req.body);
let generatePubsRtfOutput: any = [];

if (apiBody.personIdentifiers && apiBody.personIdentifiers.length > 0) {
generatePubsRtfOutput = await sequelize.query(
"CALL generatePubsRTF (:uids , :pmids)",
"CALL generatePubsRTF (:uids , :pmids, :limit)",
{
replacements: { uids: apiBody.personIdentifiers.join(','), pmids: apiBody.pmids.join(',') },
replacements: { uids: apiBody.personIdentifiers.join(','), pmids: apiBody.pmids.join(','), limit: apiBody.limit },
raw: true,
}
);
} else {


generatePubsRtfOutput = await sequelize.query(
"CALL generatePubsNoPeopleRTF ( :pmids)",
"CALL generatePubsNoPeopleRTF ( :pmids, :limit)",
{
replacements: { pmids: apiBody.pmids.join(',') },
replacements: { pmids: apiBody.pmids.join(','), limit: apiBody.limit },
raw: true,
}
);
Expand All @@ -68,9 +68,9 @@ export const generatePubsPeopleOnlyRtf = async (
try {
let apiBody: GeneratePubsPeopleOnlyApiBody = JSON.parse(req.body);
const generatePubsPeopleOnlyRtfOutput: any = await sequelize.query(
"CALL generatePubsPeopleOnlyRTF (:uids)",
"CALL generatePubsPeopleOnlyRTF (:uids, :limit)",
{
replacements: { uids: apiBody.personIdentifiers?apiBody.personIdentifiers.join(','):'' },
replacements: { uids: apiBody.personIdentifiers?apiBody.personIdentifiers.join(','):'', limit: apiBody.limit },
raw: true,
}
);
Expand Down
26 changes: 21 additions & 5 deletions src/components/elements/Manage/AdminSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ const AdminSettings = () => {
}

const handleValueChange = (viewLabelIndex?: number, viewAttrIndex?: number, name? : string, e?:any , labelName? : string) => {
console.log('name of the field',name,e);
setSettings(settings.map((obj, index1) => {
console.log('inside map function',obj,index1)
if (index1 == viewLabelIndex) {
return {
...obj,
Expand All @@ -75,8 +77,8 @@ const AdminSettings = () => {
if (index2 == viewAttrIndex) {
// return innerObj[name] = e.target.value
if(name === "isVisible") return { ...innerObj, [name]: !innerObj.isVisible }
else if(labelName === "Reporting Article RTF" && e.target.value > 40000) return { ...innerObj, [name]: e.target.value || 0, ["isValidate"]: true }
else if(labelName === "Reporting Article RTF" && e.target.value < 40000) return { ...innerObj, [name]: e.target.value || 0, ["isValidate"]: false }
else if(labelName === "Reporting Article RTF" && e.target.value > 30000) return { ...innerObj, [name]: e.target.value || 0, ["isValidate"]: true }
else if(labelName === "Reporting Article RTF" && e.target.value < 30000) return { ...innerObj, [name]: e.target.value || 0, ["isValidate"]: false }

else return { ...innerObj, [name]: e.target.value }
}
Expand Down Expand Up @@ -140,7 +142,7 @@ const AdminSettings = () => {
<Accordion.Body>
{
obj.viewAttributes.map((innerObj, viewAttrIndex) => {
const { labelSettingsView, labelUserView,errorMessage,isValidate, labelUserKey, helpTextSettingsView, isVisible, helpTextUserView, maxLimit,syntax} = innerObj;
const { labelSettingsView, labelUserView,errorMessage,isValidate, labelUserKey, helpTextSettingsView, isVisible, helpTextUserView, maxLimit,syntax,displayRank} = innerObj;
return <Card style={{ width: '40rem', marginBottom: '3px' }} key={`${viewAttrIndex}`}>
<Card.Body>
<Card.Title>{labelSettingsView}</Card.Title>
Expand Down Expand Up @@ -200,15 +202,29 @@ const AdminSettings = () => {
</div>
</div>
}
{ (innerObj && innerObj.hasOwnProperty('displayRank')) &&
<div className="d-flex">
<p className={styles.labelForCheckBox}>Display Rank</p>
<Form.Control
type="text"
name="displayRank"
className={`form-control ${styles.searchInput}`}
placeholder="Display Rank"
value={displayRank}
onChange={(e) => handleValueChange(viewLabelIndex, viewAttrIndex, "displayRank", e, obj.viewLabel)}
/>
</div>
}
{ maxLimit && maxLimit >= 0 && <>
<div className="d-flex">
<p className={styles.labels}>Max Limit</p>
<Form.Control
type="number"
type="text"
name="maxLimit"
className={`form-control ${styles.searchInput}`}
placeholder="Max Limit"
value={maxLimit|| ""}
defaultValue="30000"
value={maxLimit}
onChange={(e) => handleValueChange(viewLabelIndex, viewAttrIndex, "maxLimit", e, obj.viewLabel)}
/>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/components/elements/Report/ExportModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const ExportModal = ({ count, reportsResultsIds,articleLimit,authorLimit, export
<p>According to the criteria you have set, there are {countInfo}.</p>
{
isDownloading &&
<Alert variant="light"><b>The first {exportArticleCsvLoading ? formatter.format(articleLimit?.maxLimit) : formatter.format(authorLimit?.maxLimit)} records will be downloaded.</b></Alert>
<Alert variant="light"><b>Downloading the first {exportArticleCsvLoading ? formatter.format(articleLimit?.maxLimit) : formatter.format(authorLimit?.maxLimit)} records.</b></Alert>
}

{
Expand Down
49 changes: 34 additions & 15 deletions src/components/elements/Report/SearchSummary.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Button, Dropdown, DropdownButton, Form } from "react-bootstrap";
import { useState } from "react";
import { useEffect, useState } from "react";
import ExportModal from "./ExportModal";
import { sortOptions } from "../../../../config/report";
import { AiOutlineCheck } from "react-icons/ai";
Expand All @@ -11,7 +11,7 @@ import { PublicationSearchFilter, ReporstResultId } from "../../../../types/publ
import Excel from 'exceljs';
import ArrowUpwardIcon from '@mui/icons-material/ArrowUpward';
import ArrowDownwardIcon from '@mui/icons-material/ArrowDownward';
import { setReportFilterLabels } from "../../../utils/constants";
import { setReportFilterDisplayRank, setReportFilterLabels } from "../../../utils/constants";


const SearchSummary = ({
Expand All @@ -32,6 +32,8 @@ const SearchSummary = ({
const [exportAuthorshipCsvLoading, setExportAuthorshipCsvLoading] = useState(false);
const [exportArticleCsvLoading, setExportArticleCsvLoading] = useState(false);
const formatter = new Intl.NumberFormat('en-US')
const [formattedSortOptions, serFormatedSOrtOptions] = useState([]);


// Search Results
const reportsSearchResults = useSelector((state: RootStateOrAny) => state.reportsSearchResults)
Expand All @@ -49,8 +51,18 @@ const SearchSummary = ({
let authorshipFileName = `AuthorshipReport-ReCiter-${date}`;
let articleFileName = `ArticleReport-ReCiter-${date}`;
const articleLimit = exportArticleLabels && exportArticleLabels.length > 0 && exportArticleLabels.find(obj => obj.maxLimit)
const articleLimitForRTF = exportArticlesRTF && exportArticlesRTF.length > 0 && exportArticlesRTF.find(obj => obj.maxLimit)
const authorLimit = exportAuthorShipLabels && exportAuthorShipLabels.length > 0 && exportAuthorShipLabels.find(obj => obj.maxLimit)

useEffect(() => {

let sortWithDisplayRank = [];
Object.keys(sortOptions).filter(option => sortOptions[option] === true).map((sortOption, index) => {
let labelObj = { labelName: setReportFilterLabels(reportLabelsForSort, labels.article[sortOption] || labels.articleInfo[sortOption]), displayRank: setReportFilterDisplayRank(reportLabelsForSort, labels.article[sortOption] || labels.articleInfo[sortOption]) };
sortWithDisplayRank.push(labelObj);
})
serFormatedSOrtOptions(sortWithDisplayRank.sort((a: any, b: any) => a.displayRank - b.displayRank))
}, [])

const handleSelect = (option) => {
let optionInfo = option.split('_');
Expand Down Expand Up @@ -187,22 +199,22 @@ const SearchSummary = ({

if (labels.person) {
Object.keys(labels.person).forEach((labelField) => {
let labelObj = { header: setReportFilterLabels(exportAuthorShipLabels, labels.person[labelField]) , key: labelField};
let labelObj = { header: setReportFilterLabels(exportAuthorShipLabels, labels.person[labelField]) , key: labelField, displayRank : setReportFilterDisplayRank(exportAuthorShipLabels, labels.person[labelField]) };
columns.push(labelObj);
})
}

if (labels.articleInfo) {
Object.keys(labels.articleInfo).forEach((articleInfoField) => {
let labelObj = { header: setReportFilterLabels(exportAuthorShipLabels,labels.articleInfo[articleInfoField]), key: articleInfoField };
let labelObj = { header: setReportFilterLabels(exportAuthorShipLabels,labels.articleInfo[articleInfoField]), key: articleInfoField, displayRank:setReportFilterDisplayRank(exportAuthorShipLabels,labels.articleInfo[articleInfoField]) };
columns.push(labelObj);
})
}

if (metrics.article && labels.article) {
Object.keys(metrics.article).forEach(articleField => {
if (metrics.article[articleField] == true) {
let labelObj = { header: setReportFilterLabels(exportAuthorShipLabels,labels.article[articleField]), key: articleField};
let labelObj = { header: setReportFilterLabels(exportAuthorShipLabels,labels.article[articleField]), key: articleField, displayRank:setReportFilterDisplayRank(exportAuthorShipLabels,labels.article[articleField])};
columns.push(labelObj);
}
})
Expand All @@ -211,19 +223,19 @@ const SearchSummary = ({
if (labels.article) {
Object.keys(labels.article).forEach(label => {
if (!metrics.article.hasOwnProperty(label)) {
let labelObj = { header: setReportFilterLabels(exportAuthorShipLabels,labels.article[label]), key: label};
let labelObj = { header: setReportFilterLabels(exportAuthorShipLabels,labels.article[label]), key: label, displayRank:setReportFilterDisplayRank(exportAuthorShipLabels,labels.article[label])};
columns.push(labelObj);
}
})
}

if (labels.authorsInfo) {
Object.keys(labels.authorsInfo).forEach(label => {
let labelObj = { header: setReportFilterLabels(exportAuthorShipLabels,labels.authorsInfo[label]), key: label};
let labelObj = { header: setReportFilterLabels(exportAuthorShipLabels,labels.authorsInfo[label]), key: label, displayRank:setReportFilterDisplayRank(exportAuthorShipLabels,labels.authorsInfo[label])};
columns.push(labelObj);
})
}

columns.sort((a: any, b: any) => a.displayRank - b.displayRank)

try {
let options = {}
Expand Down Expand Up @@ -296,15 +308,15 @@ const SearchSummary = ({

if (labels.articleInfo) {
Object.keys(labels.articleInfo).forEach((articleInfoField) => {
let labelObj = { header: setReportFilterLabels(exportAuthorShipLabels, labels.articleInfo[articleInfoField]), key: articleInfoField };
let labelObj = { header: setReportFilterLabels(exportArticleLabels, labels.articleInfo[articleInfoField]), key: articleInfoField, displayRank:setReportFilterDisplayRank(exportArticleLabels, labels.articleInfo[articleInfoField]) };
columns.push(labelObj);
})
}

if (metrics.article && labels.article) {
Object.keys(metrics.article).forEach(articleField => {
if (metrics.article[articleField] == true) {
let labelObj = { header:setReportFilterLabels(exportAuthorShipLabels, labels.article[articleField]), key: articleField};
let labelObj = { header:setReportFilterLabels(exportArticleLabels, labels.article[articleField]), key: articleField, displayRank: setReportFilterDisplayRank(exportArticleLabels, labels.article[articleField])};
columns.push(labelObj);
}
})
Expand All @@ -313,11 +325,11 @@ const SearchSummary = ({

if (labels.authorsInfo) {
Object.keys(labels.authorsInfo).forEach(label => {
let labelObj = { header: setReportFilterLabels(exportAuthorShipLabels,labels.authorsInfo[label]), key: label};
let labelObj = { header: setReportFilterLabels(exportArticleLabels,labels.authorsInfo[label]), key: label, displayRank:setReportFilterDisplayRank(exportArticleLabels,labels.authorsInfo[label])};
columns.push(labelObj);
})
}

columns.sort((a: any, b: any) => a.displayRank - b.displayRank)
try {
// creating one worksheet in workbook
const worksheet = workbook.addWorksheet(articleFileName);
Expand Down Expand Up @@ -364,19 +376,23 @@ const SearchSummary = ({
<div className="search-summary-buttons">
<DropdownButton className={`d-inline-block mx-2`} title="Sort by" id="dropdown-basic-button" onSelect={(value) => handleSelect(value)}>
{
Object.keys(sortOptions).filter(option => sortOptions[option] === true).map((sortOption, index) => {
formattedSortOptions.map((sortOption, index) => {
return (
<div key={index}>
<Dropdown.Item eventKey={`${sortOption}_DESC`} key={`${sortOption}_DESC`} className={`dropdown-item ${selected.type === sortOption && selected.order === 'DESC' ? styles.selected : styles.dropdownItem}`}>
{selected.type === sortOption && selected.order === 'DESC' && <AiOutlineCheck />}
{/* {labels.article[sortOption] || labels.articleInfo[sortOption]} */}
{setReportFilterLabels(reportLabelsForSort, labels.article[sortOption] || labels.articleInfo[sortOption])}
{/* {setReportFilterLabels(reportLabelsForSort, labels.article[sortOption] || labels.articleInfo[sortOption])} */}
{sortOption.labelName}

{<ArrowDownwardIcon />}
</Dropdown.Item>
<Dropdown.Item eventKey={`${sortOption}_ASC`} key={`${sortOption}_ASC`} className={`dropdown-item ${selected.type === sortOption && selected.order === 'ASC' ? styles.selected : styles.dropdownItem}`}>
{selected.type === sortOption && selected.order === 'ASC' && <AiOutlineCheck />}
{/* {labels.article[sortOption] || labels.articleInfo[sortOption]} */}
{setReportFilterLabels(reportLabelsForSort, labels.article[sortOption] || labels.articleInfo[sortOption])}
{/* {setReportFilterLabels(reportLabelsForSort, labels.article[sortOption] || labels.articleInfo[sortOption])} */}
{sortOption.labelName}

{<ArrowUpwardIcon />}
</Dropdown.Item>
</div>
Expand Down Expand Up @@ -417,6 +433,9 @@ const SearchSummary = ({
buttonsList={[
{ title: 'Export article report', loading: exportArticleLoading, onClick: exportArticle}
]}
count = {count}
exportArticleCsvLoading = {exportArticleLoading}
articleLimit = {articleLimitForRTF}
/>
</>
)
Expand Down
5 changes: 2 additions & 3 deletions src/pages/api/auth/[...nextauth].jsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,8 @@ const options = {
async session(session, token,apiResponse) {
session.data = token
//loading adminsettings after creating users specific data as it does not belogs to specific user.
const adminSettings = await fetchUpdatedAdminSettings();
session.adminSettings = adminSettings;
console.log(session)
if(session && !session.adminSettings)
session.adminSettings = await fetchUpdatedAdminSettings();
return session
},
async jwt(token, apiResponse) {
Expand Down
1 change: 1 addition & 0 deletions src/pages/api/db/reports/publication/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { reciterConfig } from '../../../../../../config/local';
import { generatePubsRtf } from '../../../../../../controllers/db/reports/publication.report.controller';
import { GeneratePubsApiBody } from '../../../../../../types/publication.report.body';

export const config = { api: { bodyParser: { sizeLimit: '5mb', responseLimit: false } } }
export default async function handler(req: NextApiRequest,
res: NextApiResponse<Buffer | string>) {
if (req.method === "POST") {
Expand Down
5 changes: 5 additions & 0 deletions src/utils/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ export const setReportFilterLabels = (allFilters, filterLabel) => {
return filteredLabel?.labelUserView || ""
}

export const setReportFilterDisplayRank = (allFilters, filterLabel) => {
let filteredLabel = allFilters?.length > 0 && allFilters?.find((allLabels) => allLabels.labelUserKey === filterLabel)
return filteredLabel?.displayRank || ""
}

export const setHelptextInfo = (allFilters, filterLabel) => {
let filteredLabel = allFilters?.length > 0 && allFilters?.find((allLabels) => allLabels.labelUserKey === filterLabel)
return filteredLabel?.helpTextUserView || ""
Expand Down
6 changes: 4 additions & 2 deletions types/publication.report.body.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
export type GeneratePubsApiBody = {
personIdentifiers: Array<string>,
pmids: Array<number>
pmids: Array<number>,
limit: number
}

export type GeneratePubsPeopleOnlyApiBody = {
personIdentifiers: Array<string>
personIdentifiers: Array<string>,
limit: number
}

0 comments on commit 16f0af5

Please sign in to comment.