Skip to content

Commit 6335a11

Browse files
authored
Merge pull request #97 from clowder-framework/feature/job-status
Deployed hub.ncsa.illinois.edu/clowder/consort-frontend:0.9.0.0 Tested works fine.
2 parents 7e1b6bc + 587d833 commit 6335a11

File tree

8 files changed

+240
-142
lines changed

8 files changed

+240
-142
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "consort-frontend",
3-
"version": "0.8.0",
3+
"version": "0.9.0",
44
"description": "",
55
"engines": {
66
"npm": ">=8.11",

src/actions/client.js

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,6 @@ import {ADD_FILE_TO_DATASET, addFileToDataset, CREATE_DATASETS, createDataset} f
1616

1717
const clientInfo = await getClientInfo();
1818

19-
export function setStatement(statementType) {
20-
return (dispatch) => {
21-
dispatch({
22-
type: 'SET_STATEMENT_TYPE',
23-
statementType: statementType,
24-
receivedAt: Date.now(),
25-
});
26-
};
27-
}
2819

2920
// createUploadExtract thunk function
3021
export function createUploadExtract(file, config) {
@@ -43,29 +34,30 @@ export function createUploadExtract(file, config) {
4334
if (file_json !== undefined){
4435
file_json["filename"] = file.name;
4536
// submit uploaded file for extraction
37+
dispatch(setExtractionStatus("Analyzing file"));
4638
if (file.type == "application/vnd.openxmlformats-officedocument.wordprocessingml.document" || file.type =="application/msword"){
4739
const word_pipeline_status = await wordPipeline(file_json, dataset_json, config, clientInfo);
4840
if (word_pipeline_status) {
49-
console.log("File extraction complete.");
50-
dispatch(setExtractionStatus(SET_EXTRACTION_STATUS, true));
41+
console.log("File extraction complete");
42+
dispatch(setExtractionStatus("File extraction complete"));
5143

5244
}
5345
else {
5446
console.error("File extraction failed");
55-
dispatch(setExtractionStatus(SET_EXTRACTION_STATUS, false));
47+
dispatch(setExtractionStatus("File extraction failed"));
5648
}
57-
49+
5850
}
5951
else if (file.type == "application/pdf") {
6052
const pdf_pipeline_status = await pdfPipeline(file_json, dataset_json, config, clientInfo);
6153
if (pdf_pipeline_status) {
6254
console.log("File extraction complete.");
63-
dispatch(setExtractionStatus(SET_EXTRACTION_STATUS, true));
55+
dispatch(setExtractionStatus("File extraction complete"));
6456

6557
}
6658
else {
6759
console.error("File extraction failed");
68-
dispatch(setExtractionStatus(SET_EXTRACTION_STATUS, false));
60+
dispatch(setExtractionStatus("File extraction failed"));
6961
}
7062

7163
// TODO add extracted output files to dataset state
@@ -75,20 +67,20 @@ export function createUploadExtract(file, config) {
7567
else {
7668
// TODO add error action
7769
console.error("Error in file type");
78-
dispatch(setExtractionStatus(SET_EXTRACTION_STATUS, false));
70+
dispatch(setExtractionStatus("Error in file type"));
7971
}
8072
// after submitting uploaded file for extraction, add the file to dataset state
8173
dispatch(addFileToDataset(ADD_FILE_TO_DATASET, file_json));
8274
}
8375
else {
8476
console.error("Error in clowder upload of file ", file.name)
85-
dispatch(setExtractionStatus(SET_EXTRACTION_STATUS, false));
77+
dispatch(setExtractionStatus("Error in clowder upload of file " + file.name));
8678
}
8779
}
8880
else {
8981
console.error("Error in dataset creation");
90-
dispatch(setExtractionStatus(SET_EXTRACTION_STATUS, false));
91-
}
82+
dispatch(setExtractionStatus("Error in dataset creation"));
83+
}
9284
};
9385
}
9486

src/actions/file.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,10 @@ export function fetchFileMetadataJsonld(id) {
8989
}
9090

9191
export const SET_EXTRACTION_STATUS = "SET_EXTRACTION_STATUS";
92-
export function setExtractionStatus(type, status) {
92+
export function setExtractionStatus(status) {
9393
return (dispatch) => {
9494
dispatch({
95-
type: type,
95+
type: SET_EXTRACTION_STATUS,
9696
extractionStatus: status
9797
});
9898
};

src/components/childComponents/CreateAndUpload.js

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {getClientInfo} from "../../utils/common";
1313
import Dropfile from "./Dropfile";
1414
import {createUploadExtract} from "../../actions/client";
1515
import {getDatasetMetadata, getFileInDataset} from "../../utils/dataset";
16-
import {fetchFilePreviews} from "../../actions/file";
16+
import { fetchFilePreviews, SET_EXTRACTION_STATUS, setExtractionStatus } from "../../actions/file";
1717
import {SET_DATASET_METADATA, setDatasetMetadata} from "../../actions/dataset";
1818
import {SET_STATEMENT_TYPE, setStatement} from '../../actions/statement';
1919
import config from "../../app.config";
@@ -27,7 +27,6 @@ export default function CreateAndUpload() {
2727
const rctExtractor = config.rct_extractor;
2828

2929
const [mouseHover, setMouseHover] = useState(false); // mouse hover state for dropzone
30-
const [statementTypeSelected, setStatementTypeSelected] = useState(false); // user choice of statement type consort or spirit
3130
const [loading, setLoading] = useState(false); // loading overlay state and button disabled state. set to active when dropfile is active
3231
const [loading_text, setLoadingText] = useState("Processing"); // loading overlay text.
3332
const [filename, setFilename] = useState(''); // uploaded filename
@@ -39,11 +38,11 @@ export default function CreateAndUpload() {
3938
const extractionStatus = useSelector(state => state.file.extractionStatus);
4039
const listFilePreviews = (fileId, clientInfo) => dispatch(fetchFilePreviews(fileId, clientInfo));
4140
const datasetMetadata = (json) => dispatch(setDatasetMetadata(SET_DATASET_METADATA, json));
41+
const statementType = useSelector(state => state.statement.statementType);
4242

4343
const handleStatementChange = (event) => {
4444
dispatch(setStatement(SET_STATEMENT_TYPE, event.target.value));
4545
config.statementType = event.target.value;
46-
setStatementTypeSelected(true);
4746
};
4847

4948
const onDropFile = (file) => {
@@ -55,13 +54,13 @@ export default function CreateAndUpload() {
5554

5655
// useEffect on extractionStatus for preview generation
5756
useEffect(async () => {
58-
if (extractionStatus !== null && extractionStatus === true) {
57+
if (extractionStatus !== null) {
58+
setLoadingText(extractionStatus);
5959
const clientInfo = await getClientInfo();
6060
const file_name = filename.replace(/\.[^/.]+$/, ""); // get filename without extension;
6161
const dataset_id = datasets[0].id;
6262
// check extraction status and html file generation in loop
6363
const html_file_loop = async () => {
64-
setLoadingText("Checking extraction status");
6564
const highlights_filename = file_name + '_highlights' + '.json'
6665
const highlightsFile = await getFileInDataset(dataset_id, "application/json", highlights_filename, clientInfo);
6766
if (highlightsFile !== null && typeof highlightsFile.id === "string") {
@@ -86,7 +85,6 @@ export default function CreateAndUpload() {
8685
}
8786
datasetMetadata(metadata);
8887

89-
setLoadingText("Extraction completed");
9088
setPreview(false) // Continue button activated
9189
setSpinner(false); // stop display of spinner
9290
} else {
@@ -102,35 +100,30 @@ export default function CreateAndUpload() {
102100
}
103101
}
104102
else if (extractionStatus === false){
105-
setLoadingText("Error in extraction");
103+
dispatch(setExtractionStatus("Error in extraction"));
106104
setSpinner(false); // stop display of spinner
107105
}
108-
}, [extractionStatus]);
106+
}, [extractionStatus]); // TODO: This useEffect will trigger again when the extractionStatus is completed
109107

110108

111109
// onDrop function to trigger createUploadExtract action dispatch
112110
const onDrop = useCallback((acceptedFiles, rejectedFiles) => {
113-
if (!statementTypeSelected) {
114-
setLoadingText("Please select a statement type (Trial results or Trial protocol) first");
115-
setSpinner(false);
116-
return;
117-
}
118-
111+
// this callback function is triggered when a file is dropped into the dropzone
119112
setLoading(true);
120113
try {
121114
acceptedFiles.map(file => {
122115
onDropFile(file)
123116
})
124117
rejectedFiles.map(file => {
125-
setLoadingText("File rejected");
118+
dispatch(setExtractionStatus("File rejected"));
126119
setSpinner(false);
127120
})
128121
}
129122
catch(error) {
130-
setLoadingText("Upload failed", error)
123+
dispatch(setExtractionStatus("Upload failed"));
131124
setSpinner(false);
132125
}
133-
}, [mouseHover, statementTypeSelected]);
126+
}, [mouseHover]);
134127

135128

136129
const goToPreviewRoute = () => {
@@ -144,23 +137,22 @@ export default function CreateAndUpload() {
144137
<Box className="createupload">
145138
<LoadingOverlay active={loading} text={loading_text} spinner={spinner}>
146139
<div className="mousehoverdrop" onMouseEnter={() => setMouseHover(true)}>
147-
<Dropfile
148-
onDrop={onDrop}
140+
<Dropfile
141+
onDrop={onDrop}
149142
accept={{
150-
"application/vnd.openxmlformats-officedocument.wordprocessingml.document": [".docx"],
151-
"application/msword": [".doc"],
143+
"application/vnd.openxmlformats-officedocument.wordprocessingml.document": [".docx"],
144+
"application/msword": [".doc"],
152145
"application/pdf": [".pdf"]
153146
}}
154-
message={!statementTypeSelected ?
155-
"Please select a statement type above before uploading files" :
156-
"Drag and drop files here"}
147+
message={"Drag and drop files here"}
157148
/>
158149
</div>
159150
</LoadingOverlay>
160151

161152
<div className="radio-buttons-group-div">
162-
<RadioGroup
163-
name="radio-buttons-group"
153+
<RadioGroup
154+
defaultValue={statementType}
155+
name="radio-buttons-group"
164156
row
165157
onChange={handleStatementChange}
166158
>

src/components/childComponents/FilePreview.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export default function FilePreview() {
3333
if (filePreviews !== undefined && filePreviews.length > 0) {
3434
const previewsTemp = [];
3535
// get either pdf preview / html preview
36-
if (filePreviews.length === 1){
36+
if (filePreviews.length > 0){
3737
console.log("filePreviews:", filePreviews);
3838
const fileId = filePreviews[0][0].file_id;
3939
const previewsList = filePreviews[0][0].previews;

src/components/previewers/Pdf.js

Lines changed: 11 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -4,91 +4,16 @@ import {useDispatch, useSelector} from "react-redux";
44
import { pdfjs , Document, Page } from 'react-pdf';
55
import "react-pdf/dist/esm/Page/TextLayer.css";
66
import {SET_PAGE_NUMBER, setPageNumber} from "../../actions/pdfpreview";
7+
import {
8+
consort_highlight_color,
9+
consort_label_color,
10+
spirit_highlight_color,
11+
spirit_label_color
12+
} from '../styledComponents/HighlightColors';
713

814

915
pdfjs.GlobalWorkerOptions.workerSrc = `//cdnjs.cloudflare.com/ajax/libs/pdf.js/${pdfjs.version}/pdf.worker.js`;
1016

11-
const highlight_color = {
12-
"1a":"#88FF88",
13-
"1b":"#88FF88",
14-
"2a": "#CCAAFF",
15-
"2b": "#CCAAFF",
16-
"3a": "#88FFFF",
17-
"3b": "#88FFFF",
18-
"4a": "#88FFFF",
19-
"4b": "#88FFFF",
20-
"5": "#88FFFF",
21-
"6a": "#88FFFF",
22-
"6b": "#88FFFF",
23-
"7a": "#88FFFF",
24-
"7b": "#88FFFF",
25-
"8a": "#88FFFF",
26-
"8b": "#88FFFF",
27-
"9" : "#88FFFF",
28-
"10" :"#88FFFF",
29-
"11a" :"#88FFFF",
30-
"11b" :"#88FFFF",
31-
"12a ":"#88FFFF",
32-
"12b" :"#88FFFF",
33-
"13a":"#bbff44",
34-
"13b" :"#bbff44",
35-
"14a" :"#bbff44",
36-
"14b" :"#bbff44",
37-
"15" :"#bbff44",
38-
"16" :"#bbff44",
39-
"17a" :"#bbff44",
40-
"17b" :"#bbff44",
41-
"18" :"#bbff44",
42-
"19" :"#bbff44",
43-
"20" :"#AACCFF",
44-
"21" :"#AACCFF",
45-
"22" :"#AACCFF",
46-
"23" :"#FFAACC",
47-
"24" :"#FFAACC",
48-
"25" :"#FFAACC",
49-
}
50-
51-
const label_color = {
52-
"1a":"#009c00",
53-
"1b":"#009c00",
54-
"2a": "#4400aa",
55-
"2b": "#4400aa",
56-
"3a": "#009c9c",
57-
"3b": "#009c9c",
58-
"4a": "#009c9c",
59-
"4b": "#009c9c",
60-
"5": "#009c9c",
61-
"6a": "#009c9c",
62-
"6b": "#009c9c",
63-
"7a": "#009c9c",
64-
"7b": "#009c9c",
65-
"8a": "#009c9c",
66-
"8b": "#009c9c",
67-
"9" : "#009c9c",
68-
"10" :"#009c9c",
69-
"11a" :"#009c9c",
70-
"11b" :"#009c9c",
71-
"12a ":"#009c9c",
72-
"12b" :"#009c9c",
73-
"13a":"#528100",
74-
"13b" :"#528100",
75-
"14a" :"#528100",
76-
"14b" :"#528100",
77-
"15" :"#528100",
78-
"16" :"#528100",
79-
"17a" :"#528100",
80-
"17b" :"#528100",
81-
"18" :"#528100",
82-
"19" :"#528100",
83-
"20" :"#0044aa",
84-
"21" :"#0044aa",
85-
"22" :"#0044aa",
86-
"23" :"#0044aa",
87-
"24" :"#0044aa",
88-
"25" :"#0044aa",
89-
}
90-
91-
9217
export default function Pdf(props) {
9318
const dispatch = useDispatch();
9419

@@ -105,6 +30,8 @@ export default function Pdf(props) {
10530
let pageNumber = useSelector((state) => state.pdfpreview.pageNumber);
10631
const dispatchPageNumber = (number) => dispatch(setPageNumber(SET_PAGE_NUMBER, number));
10732

33+
const statementType = useSelector(state => state.statement.statementType);
34+
10835
const [pageWidth, setPageWidth] = useState(500);
10936
const [pageHeight, setPageHeight]= useState(799);
11037
let [canvas_width, setCanvasWidth] = useState(500);
@@ -197,16 +124,16 @@ export default function Pdf(props) {
197124
function highlightText(context, label, x, y, width, height){
198125
// rectangle highlights styling
199126
context.globalAlpha = 0.2
200-
context.fillStyle = highlight_color[label]; // 'rgb(255, 190, 60)';
127+
context.fillStyle = statementType === "consort" ? consort_highlight_color[label] : spirit_highlight_color[label];
201128
context.fillRect(x , y , width , height );
202129
}
203130

204131
function highlightLabel(context, label, x, y){
205132
context.globalAlpha = 1.0
206-
context.fillStyle = highlight_color[label];
133+
context.fillStyle = statementType === "consort" ? consort_highlight_color[label] : spirit_highlight_color[label];
207134
context.fillRect(x, y, 25, 12);
208135
context.font = "bold 12px Verdana";
209-
context.fillStyle = label_color[label];
136+
context.fillStyle = statementType === "consort" ? consort_label_color[label] : spirit_label_color[label];
210137
context.textAlign = "start";
211138
context.textBaseline = "top";
212139
context.fillText(label, x, y);

0 commit comments

Comments
 (0)