Skip to content

Commit 31cb13e

Browse files
oomsvetaMohammedBasioni
authored andcommitted
wip
1 parent a8c401f commit 31cb13e

34 files changed

+305
-238
lines changed

addons/t9n/__manifest__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "1.0",
44
"category": "TODO: find the appropriate category",
55
"description": "TODO: write a description of the module",
6-
"depends": ["base", "web"],
6+
"depends": ["base", "mail", "web"],
77
"application": True,
88
"assets": {
99
"web.assets_backend": [

addons/t9n/models/language.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,12 @@ class Language(models.Model):
2020
_sql_constraints = [
2121
("language_code_unique", "unique(code)", "The language code must be unique.")
2222
]
23+
24+
def _format(self):
25+
return [{
26+
"id": language.id,
27+
"name": language.name,
28+
"code": language.code,
29+
"native_name": language.native_name,
30+
"direction": language.direction,
31+
} for language in self]

addons/t9n/models/project.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,18 @@ def get_projects(self):
4040
{
4141
"id": record.id,
4242
"name": record.name,
43-
"src_lang": {
43+
"src_lang_id": {
4444
"id": record.src_lang_id.id,
4545
"name": record.src_lang_id.name if record.src_lang_id.name else "",
4646
},
47-
"resources": [
47+
"resource_ids": [
4848
{
4949
"id": resource.id,
50+
"file_name": resource.file_name,
5051
}
5152
for resource in record.resource_ids
5253
],
53-
"target_langs": [
54+
"target_lang_ids": [
5455
{
5556
"id": lang.id,
5657
"name": lang.name,

addons/t9n/models/resource.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,24 @@ def write(self, vals):
9494
return super().write(vals)
9595

9696
@api.model
97-
def get_resources(self, project_id):
98-
resources_records = self.search([("project_id.id", "=", project_id)])
97+
def get_resources(self, ids):
98+
return self.browse(ids)._format()
99+
100+
def _format(self):
99101
return [
100102
{
101-
"id": record.id,
102-
"file_name": record.file_name,
103-
}
104-
for record in resources_records
103+
"id": resource.id,
104+
"file_name": resource.file_name,
105+
"message_ids": [
106+
{
107+
"id": msg.id,
108+
"body": msg.body,
109+
} for msg in resource.message_ids
110+
],
111+
"project_id": {
112+
"id": resource.project_id.id,
113+
},
114+
} for resource in self
105115
]
106116

107117
@api.model

addons/t9n/models/translation.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,17 @@ class Translation(models.Model):
1818
string="Language",
1919
help="The language to which the translation translates the original message.",
2020
)
21+
22+
@api.model
23+
def create_and_format(self, **kwargs):
24+
return self.create(kwargs)._format()
25+
26+
def _format(self):
27+
return [{
28+
"id": translation.id,
29+
"body": translation.body,
30+
"source_id": {
31+
"id": translation.source_id.id,
32+
},
33+
"lang_id": translation.lang_id._format()[0],
34+
} for translation in self]

addons/t9n/static/src/core/app.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,25 @@
1-
import { Component } from "@odoo/owl";
1+
import { Component, useState } from "@odoo/owl";
2+
23
import { ProjectList } from "@t9n/core/project_list";
4+
import { LanguageList } from "@t9n/core/language_list";
5+
import { ResourceList } from "@t9n/core/resource_list";
6+
import { TranslationEditor } from "@t9n/core/translation_editor";
7+
8+
import { useService } from "@web/core/utils/hooks";
39

410
/**
511
* The "root", the "homepage" of the translation application.
612
*/
713
export class App extends Component {
8-
static components = { ProjectList };
14+
static components = { LanguageList, ProjectList, ResourceList, TranslationEditor };
915
static props = {};
1016
static template = "t9n.App";
17+
18+
setup() {
19+
this.store = useState(useService("mail.store"));
20+
}
21+
22+
get activeView() {
23+
return this.store.t9n.activeView;
24+
}
1125
}

addons/t9n/static/src/core/app.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
<templates>
33

44
<t t-name="t9n.App">
5-
<ProjectList/>
5+
<ProjectList t-if="activeView === 'ProjectList'"/>
6+
<LanguageList t-elif="activeView === 'LanguageList'" languages="store.t9n.activeProject.target_lang_ids"/>
7+
<ResourceList t-elif="activeView === 'ResourceList'" resources="store.t9n.activeProject.resource_ids"/>
8+
<TranslationEditor t-elif="activeView === 'TranslationEditor'"/>
69
</t>
710

811
</templates>

addons/t9n/static/src/core/language_list.js

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Component, useState } from "@odoo/owl";
33
import { useService } from "@web/core/utils/hooks";
44

55
export class LanguageList extends Component {
6-
static props = {};
6+
static props = { languages: Array };
77
static template = "t9n.LanguageList";
88

99
setup() {
@@ -17,22 +17,17 @@ export class LanguageList extends Component {
1717
order: "asc",
1818
},
1919
});
20-
this.store = useState(useService("t9n.store"));
21-
this.store.fetchLanguages();
20+
this.store = useState(useService("mail.store"));
2221
}
2322

2423
get languages() {
2524
const searchTerms = this.state.filters.searchText.trim().toUpperCase();
2625
const languages = searchTerms
27-
? this.store.languages.filter((l) => l.name.toUpperCase().includes(searchTerms))
28-
: [...this.store.languages];
29-
30-
languages.sort((l1, l2) => {
31-
let l1Col = l1[this.state.sorting.column];
32-
let l2Col = l2[this.state.sorting.column];
33-
34-
l1Col = l1Col.toLowerCase();
35-
l2Col = l2Col.toLowerCase();
26+
? this.props.languages.filter((l) => l.name.toUpperCase().includes(searchTerms))
27+
: [...this.props.languages];
28+
return languages.sort((l1, l2) => {
29+
const l1Col = l1[this.state.sorting.column];
30+
const l2Col = l2[this.state.sorting.column];
3631

3732
if (l1Col < l2Col) {
3833
return this.state.sorting.order === "asc" ? -1 : 1;
@@ -42,7 +37,6 @@ export class LanguageList extends Component {
4237
}
4338
return 0;
4439
});
45-
return languages;
4640
}
4741

4842
onClickColumnName(column) {
@@ -54,12 +48,8 @@ export class LanguageList extends Component {
5448
}
5549
}
5650

57-
onClickLanguage(id) {
58-
this.store.setTargetLangId(id);
59-
this.action.doAction({
60-
type: "ir.actions.client",
61-
tag: "t9n.open_resource_list",
62-
target: "current",
63-
});
51+
onClickLanguage(language) {
52+
this.store.t9n.activeView = "ResourceList";
53+
this.store.t9n.activeLanguage = language;
6454
}
6555
}

addons/t9n/static/src/core/language_list.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<t t-foreach="this.languages" t-as="language" t-key="language.id">
2121
<tr>
2222
<td>
23-
<button class="btn btn-link " t-on-click="() => this.onClickLanguage(language.id)">
23+
<button class="btn btn-link " t-on-click="() => this.onClickLanguage(language)">
2424
<t t-esc="language.name"/>
2525
</button>
2626
</td>

addons/t9n/static/src/core/message_form.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { Component, useState, useRef } from "@odoo/owl";
2+
3+
import { CopyPopover } from "@t9n/core/copy_button_popover";
4+
25
import { useService } from "@web/core/utils/hooks";
36
import { usePopover } from "@web/core/popover/popover_hook";
4-
import { CopyPopover } from "@t9n/core/copy_button_popover";
57

68
export class MessageForm extends Component {
79
static props = {};
@@ -11,7 +13,7 @@ export class MessageForm extends Component {
1113
this.state = useState({
1214
suggestedTranslationText: "",
1315
});
14-
this.store = useState(useService("t9n.store"));
16+
this.store = useState(useService("mail.store"));
1517
this.orm = useService("orm");
1618
this.popoverButtonRef = useRef("popover-button");
1719
this.copyPopover = usePopover(CopyPopover, {
@@ -23,11 +25,11 @@ export class MessageForm extends Component {
2325
}
2426

2527
get message() {
26-
return this.store.active_message;
28+
return this.store.t9n.activeMessage;
2729
}
2830

2931
get translations() {
30-
return this.store.active_message.translations;
32+
return this.message.translationsInCurrentLanguage;
3133
}
3234

3335
onClickClear() {
@@ -47,14 +49,15 @@ export class MessageForm extends Component {
4749
}
4850

4951
async onClickSuggest() {
50-
await this.orm.create("t9n.translation", [
52+
const data = await this.orm.call("t9n.translation", "create_and_format", [],
5153
{
5254
body: this.state.suggestedTranslationText.trim(),
53-
source_id: this.store.active_message.id,
54-
lang_id: this.store.target_lang_id,
55+
source_id: this.store.t9n.activeMessage.id,
56+
lang_id: this.store.t9n.activeLanguage.id,
5557
},
56-
]);
57-
this.store.fetchActiveMessage();
58-
this.onClickClear();
58+
);
59+
console.log(data);
60+
this.store["t9n.translation"].insert(data);
61+
this.state.suggestedTranslationText = "";
5962
}
6063
}

0 commit comments

Comments
 (0)