Skip to content

Commit d2105be

Browse files
committed
index most deep relation, interact with dialog
1 parent 6bf8f6a commit d2105be

3 files changed

Lines changed: 64 additions & 8 deletions

File tree

typesense_ir_exports/static/src/action_ir_export.esm.js

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ const {onWillDestroy} = owl;
1414
class CustomExportDataDialog extends ExportDataDialog {
1515
setup() {
1616
super.setup();
17+
Object.assign(this.state, {
18+
showApplyTemplatetButton: false,
19+
});
1720
this.title = this.env._t("Select Data for Indexing");
1821
// We hack the current model from props obj to avoid patching other methods
1922
this.swapResModel = this.props.root.resModel;
@@ -26,6 +29,29 @@ class CustomExportDataDialog extends ExportDataDialog {
2629
this.props.root.resModel = this.swapResModel;
2730
});
2831
}
32+
async onChangeExportList(ev) {
33+
this.loadExportList(ev.target.value);
34+
// Show button only when there is selected saved template with different id
35+
if (
36+
this.state.templateId === this.props.context.exporter_id[0] ||
37+
this.state.templateId === "new_template"
38+
) {
39+
this.state.showApplyTemplatetButton = false;
40+
} else {
41+
this.state.showApplyTemplatetButton = true;
42+
}
43+
}
44+
onQuickOverlap(templ) {
45+
this.props.context.overlap(templ);
46+
}
47+
onClickApplyTemplatetButton() {
48+
const arrayOfTemplates = this.templates.map(({id, name}) => [id, name]);
49+
const templ = arrayOfTemplates.find(
50+
(subArray) => subArray[0] === this.state.templateId
51+
);
52+
this.onQuickOverlap(templ);
53+
this.props.close();
54+
}
2955
async onUpdateExportTemplate() {
3056
const oldRec = await this.orm.read(
3157
"ir.exports",
@@ -80,6 +106,11 @@ class IrExportWidget extends Many2OneField {
80106
this.rpc = useService("rpc");
81107
this.orm = useService("orm");
82108
this.dialogService = useService("dialog");
109+
this.quickOverlap = (templ) => {
110+
if (templ && templ[0] && templ[1]) {
111+
return this.props.update(templ);
112+
}
113+
};
83114
}
84115
async downloadExport() {
85116
return true;
@@ -97,7 +128,10 @@ class IrExportWidget extends Many2OneField {
97128
context: {
98129
...this.props.record.context,
99130
resModel: this.props.record.data.model_name,
100-
exporter_id: this.props.record.data.exporter_id,
131+
exporter_id: this.props.value,
132+
overlap: (templ) => {
133+
this.quickOverlap(templ);
134+
},
101135
},
102136
defaultExportList: [],
103137
download: this.downloadExport.bind(this),

typesense_ir_exports/static/src/action_ir_export.xml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,17 @@
3131
<xpath expr="//t[@t-set-slot='footer']" position="attributes">
3232
<attribute name="t-if">false</attribute>
3333
</xpath>
34-
34+
<xpath expr="//Dialog" position="inside">
35+
<t t-set-slot="footer" t-if="state.showApplyTemplatetButton">
36+
<button
37+
class="btn btn-primary o_select_button"
38+
data-hotkey="v"
39+
t-on-click.stop="onClickApplyTemplatetButton"
40+
t-att-disabled="state.disabled"
41+
>Apply selected template and close
42+
</button>
43+
</t>
44+
</xpath>
3545
<xpath
3646
expr="//button[@t-on-click.stop='onCancelExportTemplate']"
3747
position="after"

typesense_ir_exports/tools/resolver.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,34 @@ def __init__(self, parser):
2828
if parser.get("fields") and isinstance(parser["fields"], list):
2929
fields = parser["fields"]
3030
self.resolved_parser = [self.convert(field) for field in fields]
31+
# Remove elements from the list if they are empty lists
32+
self.resolved_parser = [item for item in self.resolved_parser if item]
3133

3234
def get_dict_key(self, field):
3335
if isinstance(field, dict) and "name" in field:
3436
return field["name"]
3537
else:
3638
return field
3739

38-
def convert(self, field):
39-
if isinstance(field, dict):
40-
return self.get_dict_key(field)
41-
elif isinstance(field, tuple) and len(field) == 2:
40+
def resolve_tuple_field(self, field):
41+
if isinstance(field, tuple) and len(field) == 2:
4242
parent, children = field
4343
if isinstance(parent, dict):
4444
return (
4545
self.get_dict_key(parent),
46-
[self.get_dict_key(child) for child in children],
46+
[
47+
self.get_dict_key(child)
48+
if isinstance(child, dict)
49+
else self.resolve_tuple_field(child)
50+
for child in children
51+
],
4752
)
53+
# Safeguarding the structure result if the branch is broken,
54+
# assign this branch empty list to protect other branches and the root
55+
return []
56+
57+
def convert(self, field):
58+
if isinstance(field, dict):
59+
return self.get_dict_key(field)
4860
else:
49-
return field
61+
return self.resolve_tuple_field(field)

0 commit comments

Comments
 (0)