Skip to content

Commit

Permalink
[Enhancement #538] Allow downloading file without unconfirmed occurre…
Browse files Browse the repository at this point in the history
…nces from annotator.
  • Loading branch information
ledsoft committed Oct 14, 2024
1 parent d96ba2a commit a75e6e9
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 4 deletions.
16 changes: 13 additions & 3 deletions src/action/AsyncActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1133,9 +1133,15 @@ export function loadLatestTextAnalysisRecord(resourceIri: IRI) {
/**
* Downloads the content of a file with the specified IRI (assuming it is stored on the server).
* @param fileIri File identifier
* @param at Timestamp of the file version to download
* @param options File export options
*/
export function exportFileContent(fileIri: IRI, at?: string) {
export function exportFileContent(
fileIri: IRI,
options: {
at?: string;
withoutUnconfirmedOccurrences?: boolean;
} = {}
) {
const action = {
type: ActionType.EXPORT_FILE_CONTENT,
};
Expand All @@ -1147,7 +1153,11 @@ export function exportFileContent(fileIri: IRI, at?: string) {
url,
param("namespace", fileIri.namespace)
.param("attachment", "true")
.param("at", at)
.param("at", options.at)
.param(
"withoutUnconfirmedOccurrences",
options.withoutUnconfirmedOccurrences?.toString()
)
.responseType("arraybuffer")
)
.then((resp: AxiosResponse) => {
Expand Down
5 changes: 5 additions & 0 deletions src/component/annotator/Annotator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import {
AnnotationClass,
AnnotationOrigin,
} from "../../model/AnnotatorLegendFilter";
import AnnotatorDownloadActions from "./AnnotatorDownloadActions";

interface AnnotatorProps extends HasI18n {
fileIri: IRI;
Expand Down Expand Up @@ -657,6 +658,10 @@ export class Annotator extends React.Component<AnnotatorProps, AnnotatorState> {
)}
/>
</IfVocabularyActionAuthorized>,
<AnnotatorDownloadActions
fileIri={this.props.fileIri}
key="annotator-download-actions"
/>,
<LegendToggle key="legend-toggle" />,
]}
/>
Expand Down
78 changes: 78 additions & 0 deletions src/component/annotator/AnnotatorDownloadActions.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import React from "react";
import { IRI } from "../../util/VocabularyUtils";
import { useI18n } from "../hook/useI18n";
import {
DropdownItem,
DropdownMenu,
DropdownToggle,
UncontrolledButtonDropdown,
} from "reactstrap";
import { FaCloudDownloadAlt } from "react-icons/fa";
import { useDispatch } from "react-redux";
import { ThunkDispatch } from "../../util/Types";
import { exportFileContent } from "../../action/AsyncActions";
import { trackPromise } from "react-promise-tracker";
import { DateTime } from "luxon";
import Constants from "../../util/Constants";

const AnnotatorDownloadActions: React.FC<{ fileIri: IRI }> = ({ fileIri }) => {
const { i18n } = useI18n();
const dispatch: ThunkDispatch = useDispatch();

const downloadCurrentFile = () => {
trackPromise(dispatch(exportFileContent(fileIri)), "annotator");
};
const downloadOriginalFile = () => {
const timestamp = DateTime.fromMillis(0).toFormat(
Constants.TIMESTAMP_PARAM_FORMAT
);
trackPromise(
dispatch(exportFileContent(fileIri, { at: timestamp })),
"annotator"
);
};
const downloadWithoutUnconfirmed = () => {
trackPromise(
dispatch(
exportFileContent(fileIri, { withoutUnconfirmedOccurrences: true })
),
"annotator"
);
};

return (
<UncontrolledButtonDropdown
id="annotator-download"
color="primary"
className="ml-1 mr-2"
>
<DropdownToggle
size="sm"
caret={false}
color="primary"
style={{ borderRadius: "0.2rem" }}
>
<FaCloudDownloadAlt className="mr-1" />
<span className="dropdown-toggle">
{i18n("resource.metadata.file.content.download")}
</span>
</DropdownToggle>
<DropdownMenu>
<DropdownItem key="download-current" onClick={downloadCurrentFile}>
{i18n("annotator.download.thisFile")}
</DropdownItem>
<DropdownItem key="download-original" onClick={downloadOriginalFile}>
{i18n("annotator.download.original")}
</DropdownItem>
<DropdownItem
key="download-without-unconfirmed"
onClick={downloadWithoutUnconfirmed}
>
{i18n("annotator.download.withoutUnconfirmed")}
</DropdownItem>
</DropdownMenu>
</UncontrolledButtonDropdown>
);
};

export default AnnotatorDownloadActions;
4 changes: 3 additions & 1 deletion src/component/resource/document/DocumentFiles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ export const DocumentFiles = (props: DocumentFilesProps) => {
Constants.TIMESTAMP_PARAM_FORMAT
);
dispatch(
exportFileContent(VocabularyUtils.create(termitFile.iri), timestamp)
exportFileContent(VocabularyUtils.create(termitFile.iri), {
at: timestamp,
})
);
};

Expand Down
3 changes: 3 additions & 0 deletions src/i18n/cs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,9 @@ const cs = {

annotator: "Anotátor",
"annotator.content.loading": "Načítám obsah souboru...",
"annotator.download.thisFile": "Tento soubor",
"annotator.download.original": "Originál",
"annotator.download.withoutUnconfirmed": "Bez nepotvrzených výskytů",
"annotator.vocabulary": "Používá pojmy ze slovníku",
"annotator.selectionPurpose.dialog.title":
"K čemu bude sloužit vybraný text?",
Expand Down
3 changes: 3 additions & 0 deletions src/i18n/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,9 @@ const en = {

annotator: "Annotator",
"annotator.content.loading": "Loading file content...",
"annotator.download.thisFile": "This file",
"annotator.download.original": "Original",
"annotator.download.withoutUnconfirmed": "Without unconfirmed occurrences",
"annotator.vocabulary": "Uses terms from vocabulary",
"annotator.selectionPurpose.dialog.title":
"What do you want to do with the selected text?",
Expand Down

0 comments on commit a75e6e9

Please sign in to comment.