Skip to content

Commit 115d428

Browse files
authored
add chose language on run OCR
Let user choose language on run OCR
1 parent 29f8676 commit 115d428

File tree

6 files changed

+154
-8
lines changed

6 files changed

+154
-8
lines changed

app/components/select/index.hbs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
class="form-select"
44
...attributes>
55
{{#each @options as |opt|}}
6-
<option value="{{opt.key}}">{{opt.value}}</option>
6+
{{#if opt.selected}}
7+
<option value="{{opt.key}}" selected>{{opt.value}}</option>
8+
{{else }}
9+
<option value="{{opt.key}}">{{opt.value}}</option>
10+
{{/if}}
711
{{/each}}
8-
</select>
12+
</select>

app/components/viewer/action_buttons/index.hbs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@
1414
class="btn btn-light"
1515
type="button"
1616
disabled
17-
{{on "click" @onRunOCR}}>
17+
{{on "click" @openRerunOCRModal}}>
1818
<OcrStatus @status={{@ocrStatus}} />
1919
Run OCR
2020
</button>
2121
{{else}}
2222
<button
2323
class="btn btn-light"
2424
type="button"
25-
{{on "click" @onRunOCR}}>
25+
{{on "click" @openRerunOCRModal}}>
2626
<OcrStatus @status={{@ocrStatus}} />
2727
Run OCR
2828
</button>

app/components/viewer/index.hbs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
@openConfirmDeletionModal={{this.openConfirmDeletionModal}}
1313
@openRenameDocumentModal={{this.openRenameDocumentModal}}
1414
@openOCRedTextModal={{this.openOCRedTextModal}}
15-
@onRotateClockwise={{this.onRotateClockwise}}
16-
@onRunOCR={{this.onRunOCR}} />
15+
@openRerunOCRModal={{this.openRunOCRModal}}
16+
@onRotateClockwise={{this.onRotateClockwise}} />
1717

1818
<Viewer::ActionModes
1919
@onPanelToggle={{@onPanelToggle}}
@@ -62,6 +62,14 @@
6262
@onSubmit={{this.submitConfirmDocumentMergeModal}}
6363
{{show-when this.show_confirm_document_merge_modal}} />
6464

65+
<Viewer::Modal::RunOcr
66+
id="run-ocr"
67+
@doc={{@doc}}
68+
@getOCRLanguages={{this.getOCRLanguages}}
69+
@ocr_languages={{this.ocr_languages}}
70+
@onSubmit={{this.onRunOCR}}
71+
{{show-when this.show_run_ocr_modal}} />
72+
6573
<Modal::RenameNode
6674
@node={{@doc}}
6775
@onClose={{this.onCloseRenameModal}}

app/components/viewer/index.js

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ export default class ViewerComponent extends Component {
4747
@tracked show_ocred_text_modal = false;
4848
@tracked ocred_text_result;
4949

50+
// show runOCR modal ?
51+
@tracked show_run_ocr_modal = false;
52+
@tracked ocr_languages;
53+
5054
@tracked page_order_changed = false;
5155
@tracked apply_page_order_changes_in_progress = false;
5256
// extract page = document -> folder
@@ -115,12 +119,13 @@ export default class ViewerComponent extends Component {
115119
}
116120

117121
@action
118-
onRunOCR() {
122+
onRunOCR(lang) {
119123
this.is_locked = true;
120124
this.requests.runOCR({
121125
doc_id: this.args.doc.id,
122-
lang: 'deu'
126+
lang: lang
123127
});
128+
this.show_run_ocr_modal = false;
124129
}
125130

126131
@action
@@ -255,6 +260,34 @@ export default class ViewerComponent extends Component {
255260
});
256261
}
257262

263+
@action
264+
openRunOCRModal() {
265+
this.show_run_ocr_modal = true;
266+
this.getOCRLanguages.perform();
267+
}
268+
269+
@task *getOCRLanguages() {
270+
let result1 = yield this.requests.preferences({
271+
section_name: 'ocr'
272+
});
273+
274+
let result2 = yield result1.json();
275+
let ocr_language, languages, current_value;
276+
277+
ocr_language = result2.data.find(
278+
item => item.attributes.identifier == 'ocr__language'
279+
);
280+
281+
languages = ocr_language.attributes.additional_data.choices;
282+
current_value = ocr_language.attributes.value;
283+
284+
this.ocr_languages = {
285+
languages,
286+
current_value
287+
};
288+
289+
}
290+
258291
@action
259292
onCloseOCRedTextModal() {
260293
this.show_ocred_text_modal = false;
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<div class="modal" tabindex="-1" ...attributes>
2+
<div class="modal-dialog">
3+
<div class="modal-content">
4+
<div class="modal-header">
5+
<h5 class="modal-title">Run OCR</h5>
6+
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
7+
</div>
8+
<div class="modal-body">
9+
<p>
10+
<Label
11+
@for="language"
12+
@text="OCR Language:" />
13+
{{#if this.getOCRLanguages.isRunning}}
14+
<Spinner @inProgress={{true}} />
15+
{{else}}
16+
<Select
17+
@options={{this.ocr_language_options}}
18+
@onChange={{this.onLanguageChanged}}
19+
name="ocr_language" />
20+
{{/if}}
21+
</p>
22+
</div>
23+
<div class="modal-footer">
24+
<button
25+
type="button"
26+
class="btn btn-secondary"
27+
data-bs-dismiss="modal"
28+
{{on "click" this.onCancel}}>Cancel</button>
29+
<button
30+
type="button"
31+
class="btn btn-primary btn-success"
32+
{{on "click" this.onSubmit}}>
33+
Start
34+
</button>
35+
</div>
36+
</div>
37+
</div>
38+
</div>
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import { action } from '@ember/object';
2+
import { tracked } from '@glimmer/tracking';
3+
import Component from '@glimmer/component';
4+
5+
6+
export default class RunOCRModalComponent extends Component {
7+
@tracked _lang;
8+
9+
get ocr_language_options() {
10+
let langs;
11+
12+
if (this.args.ocr_languages) {
13+
langs = this.args.ocr_languages['languages'];
14+
15+
return langs.map(item => {
16+
let result = {
17+
'key': item[0],
18+
'value': item[1],
19+
'selected': false
20+
};
21+
22+
if (this.args.ocr_languages['current_value'] == item[0]) {
23+
result['selected'] = true;
24+
}
25+
26+
return result;
27+
});
28+
}
29+
30+
return [];
31+
}
32+
33+
get getOCRLanguages() {
34+
return this.args.getOCRLanguages;
35+
}
36+
37+
@action
38+
onLanguageChanged(event) {
39+
this._lang = event.target.value;
40+
}
41+
42+
@action
43+
async onSubmit() {
44+
let lang;
45+
46+
if (this._lang) {
47+
lang = this._lang;
48+
} else {
49+
lang = this.args.ocr_languages['current_value'];
50+
}
51+
52+
this.args.onSubmit(lang);
53+
}
54+
55+
get lang() {
56+
return this._lang;
57+
}
58+
59+
@action
60+
onCancel() {
61+
}
62+
63+
}

0 commit comments

Comments
 (0)