Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
nengyuanzhang committed Feb 20, 2024
2 parents 7324879 + cf4c728 commit d984e28
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 70 deletions.
117 changes: 59 additions & 58 deletions myems-web/src/components/MyEMS/KnowledgeBase/KnowledgeBase.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
import React, { useEffect, useState} from 'react';
import { Alert, Card, CardBody, Col, Row, Spinner, } from 'reactstrap';
import React, { useEffect, useState } from 'react';
import { Alert, Card, CardBody, Col, Row, Spinner } from 'reactstrap';
import Summary from './Summary';
import FalconCardHeader from '../../common/FalconCardHeader';
import createMarkup from '../../../helpers/createMarkup';
import { isIterableArray } from '../../../helpers/utils'
import { isIterableArray } from '../../../helpers/utils';
import { getCookieValue, createCookie } from '../../../helpers/utils';
import withRedirect from '../../../hoc/withRedirect';
import { withTranslation } from 'react-i18next';
import { APIBaseURL, settings } from '../../../config';



const KnowledgeBase = ({ setRedirect, setRedirectUrl, t }) => {

const [fetchSuccess, setFetchSuccess] = useState(false);

//Results
Expand All @@ -39,73 +36,77 @@ const KnowledgeBase = ({ setRedirect, setRedirectUrl, t }) => {

let isResponseOK = false;
if (!fetchSuccess) {
fetch(
APIBaseURL +
'/knowledgefiles', {
fetch(APIBaseURL + '/knowledgefiles', {
method: 'GET',
headers: {
'Content-type': 'application/json',
'User-UUID': getCookieValue('user_uuid'),
Token: getCookieValue('token')
},
body: null,

}).then(response => {
if (response.ok) {
isResponseOK = true;
}
return response.json();
}).then(json => {
if (isResponseOK) {
console.log(json);
setFetchSuccess(true);

let reportList = []

if (json.length > 0) {
json.forEach((currentValue, index) => {
let report = {}
report['id'] = json[index]['id'];
report['calendar'] = { month: json[index]['upload_datetime'].substring(5, 7),
day: json[index]['upload_datetime'].substring(8, 10) };
report['title'] = json[index]['file_name'];
report['additional'] = t('Created Datetime') + ': ' + json[index]['upload_datetime'] + '<br/>' +
t('File Size') + ': ' + (json[index]['file_size_bytes']/(1024*1024)).toFixed(2) + ' MB';
report['to'] = '#';
report['file_bytes_base64'] = json[index]['file_bytes_base64'];

reportList.push(report);
});
body: null
})
.then(response => {
if (response.ok) {
isResponseOK = true;
}

setReports(reportList);
setSpinnerHidden(true);
}
});
return response.json();
})
.then(json => {
if (isResponseOK) {
console.log(json);
setFetchSuccess(true);
let reportList = [];
if (json.length > 0) {
json.forEach((currentValue, index) => {
let report = {};
report['id'] = json[index]['id'];
report['calendar'] = {
month: json[index]['upload_datetime'].substring(5, 7),
day: json[index]['upload_datetime'].substring(8, 10)
};
report['title'] = json[index]['file_name'];
report['additional'] =
t('Created Datetime') +
': ' +
json[index]['upload_datetime'] +
'<br/>' +
t('File Size') +
': ' +
(json[index]['file_size_bytes'] / (1024 * 1024)).toFixed(2) +
' MB';
report['to'] = '#';
report['file_bytes_base64'] = json[index]['file_bytes_base64'];
reportList.push(report);
});
}
setReports(reportList);
setSpinnerHidden(true);
}
});
}
}
}, );
});

return (
<Card>
<FalconCardHeader title={t('Knowledge Base')} titleClass="text-lightSlateGray mb-0" />
<CardBody className="fs--1">
<Spinner color="primary" hidden={spinnerHidden} />
<Spinner color="primary" hidden={spinnerHidden} />
{isIterableArray(reports) ? (
<Row>
{reports.map(({ additional, ...rest }, index) => (
<Col md={6} className="h-100" key={index}>
<Summary divider={reports.length !== index + 1} {...rest}>
<p className="text-1000 mb-0" dangerouslySetInnerHTML={createMarkup(additional)} />
</Summary>
</Col>
))}
</Row>
) : (
<Alert color="info" className="mb-0">
{t('No data found')}
</Alert>
)}
<Row>
{reports.map(({ additional, ...rest }, index) => (
<Col md={6} className="h-100" key={index}>
<Summary divider={reports.length !== index + 1} {...rest}>
<p className="text-1000 mb-0" dangerouslySetInnerHTML={createMarkup(additional)} />
</Summary>
</Col>
))}
</Row>
) : (
<Alert color="info" className="mb-0">
{t('No data found')}
</Alert>
)}
</CardBody>
</Card>
);
Expand Down
27 changes: 15 additions & 12 deletions myems-web/src/components/MyEMS/KnowledgeBase/Summary.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,29 @@ ReportBadge.propTypes = {

const handleExport = (fileName, fileBytesBase64) => e => {
e.preventDefault();
const mimeType='application/*'
var fileUrl = "data:" + mimeType + ";base64," + fileBytesBase64;
const mimeType = 'application/*';
var fileUrl = 'data:' + mimeType + ';base64,' + fileBytesBase64;
fetch(fileUrl)
.then(response => response.blob())
.then(blob => {
var link = window.document.createElement('a');
link.href = window.URL.createObjectURL(blob, { type: mimeType });
link.download = fileName;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
});
.then(response => response.blob())
.then(blob => {
var link = window.document.createElement('a');
link.href = window.URL.createObjectURL(blob, { type: mimeType });
link.download = fileName;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
});
};

const Summary = ({ calendar, title, badge, divider, to, children, file_bytes_base64 }) => (
<Media>
<Calendar {...calendar} />
<Media body className="position-relative pl-3">
<h6 className="fs-0 mb-0">
<Link to={to} onClick={handleExport(title, file_bytes_base64)}>{title}</Link> {badge && <ReportBadge {...badge} className="ml-1" />}
<Link to={to} onClick={handleExport(title, file_bytes_base64)}>
{title}
</Link>
{badge && <ReportBadge {...badge} className="ml-1" />}
</h6>
{children}

Expand Down

0 comments on commit d984e28

Please sign in to comment.