-
Notifications
You must be signed in to change notification settings - Fork 369
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* doc ocr * update * update * feat: optimize code * feat: optimize code * feat: optimize code * feat: optimize code --------- Co-authored-by: zheng.shen <[email protected]> Co-authored-by: 杨国璇 <[email protected]>
- Loading branch information
1 parent
36e8f64
commit 2470f6e
Showing
25 changed files
with
425 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 0 additions & 26 deletions
26
frontend/src/metadata/components/dialog/metadata-face-recognition-dialog/turn-off-confirm.js
This file was deleted.
Oops, something went wrong.
100 changes: 100 additions & 0 deletions
100
frontend/src/metadata/components/dialog/metadata-ocr-status-management-dialog/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import React, { useCallback, useState } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import classnames from 'classnames'; | ||
import { ModalBody, ModalFooter, Button } from 'reactstrap'; | ||
import Switch from '../../../../components/common/switch'; | ||
import toaster from '../../../../components/toast'; | ||
import TurnOffConfirmDialog from '../turn-off-confirm-dialog'; | ||
import metadataAPI from '../../../api'; | ||
import { Utils } from '../../../../utils/utils'; | ||
import { gettext } from '../../../../utils/constants'; | ||
|
||
const MetadataOCRStatusManagementDialog = ({ value: oldValue, repoID, toggleDialog: toggle, submit }) => { | ||
const [value, setValue] = useState(oldValue); | ||
const [submitting, setSubmitting] = useState(false); | ||
const [showTurnOffConfirmDialog, setShowTurnOffConfirmDialog] = useState(false); | ||
|
||
const onToggle = useCallback(() => { | ||
if (submitting) return; | ||
toggle && toggle(); | ||
}, [submitting, toggle]); | ||
|
||
const onSubmit = useCallback(() => { | ||
if (!value) { | ||
setShowTurnOffConfirmDialog(true); | ||
return; | ||
} | ||
setSubmitting(true); | ||
metadataAPI.openOCR(repoID).then(res => { | ||
submit(true); | ||
toggle(); | ||
}).catch(error => { | ||
const errorMsg = Utils.getErrorMsg(error); | ||
toaster.danger(errorMsg); | ||
setSubmitting(false); | ||
}); | ||
}, [repoID, value, submit, toggle]); | ||
|
||
const turnOffConfirmToggle = useCallback(() => { | ||
setShowTurnOffConfirmDialog(!showTurnOffConfirmDialog); | ||
}, [showTurnOffConfirmDialog]); | ||
|
||
const turnOffConfirmSubmit = useCallback(() => { | ||
setShowTurnOffConfirmDialog(false); | ||
setSubmitting(true); | ||
metadataAPI.closeOCR(repoID).then(res => { | ||
submit(false); | ||
toggle(); | ||
}).catch(error => { | ||
const errorMsg = Utils.getErrorMsg(error); | ||
toaster.danger(errorMsg); | ||
setSubmitting(false); | ||
}); | ||
}, [repoID, submit, toggle]); | ||
|
||
const onValueChange = useCallback(() => { | ||
const nextValue = !value; | ||
setValue(nextValue); | ||
}, [value]); | ||
|
||
return ( | ||
<> | ||
{!showTurnOffConfirmDialog && ( | ||
<> | ||
<ModalBody className="metadata-status-management-dialog"> | ||
<Switch | ||
checked={value} | ||
disabled={submitting} | ||
size="large" | ||
textPosition="right" | ||
className={classnames('change-metadata-status-management w-100', { 'disabled': submitting })} | ||
onChange={onValueChange} | ||
placeholder={gettext('Enable OCR')} | ||
/> | ||
<p className="tip m-0"> | ||
{gettext('After enable OCR, you can extract text from images or scanned PDFs.')} | ||
</p> | ||
</ModalBody> | ||
<ModalFooter> | ||
<Button color="secondary" onClick={onToggle}>{gettext('Cancel')}</Button> | ||
<Button color="primary" disabled={oldValue === value || submitting} onClick={onSubmit}>{gettext('Submit')}</Button> | ||
</ModalFooter> | ||
</> | ||
)} | ||
{showTurnOffConfirmDialog && ( | ||
<TurnOffConfirmDialog title={gettext('Turn off OCR')} toggle={turnOffConfirmToggle} submit={turnOffConfirmSubmit}> | ||
<p>{gettext('Do you really want to turn off OCR? Existing OCR results will be deleted.')}</p> | ||
</TurnOffConfirmDialog> | ||
)} | ||
</> | ||
); | ||
}; | ||
|
||
MetadataOCRStatusManagementDialog.propTypes = { | ||
value: PropTypes.bool, | ||
repoID: PropTypes.string.isRequired, | ||
toggleDialog: PropTypes.func.isRequired, | ||
submit: PropTypes.func.isRequired, | ||
}; | ||
|
||
export default MetadataOCRStatusManagementDialog; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 0 additions & 26 deletions
26
frontend/src/metadata/components/dialog/metadata-status-manage-dialog/turn-off-confirm.js
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.