Skip to content

Commit 5a50327

Browse files
wip
1 parent 31cb13e commit 5a50327

14 files changed

+48
-214
lines changed

addons/t9n/models/message.py

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from odoo import api, fields, models
1+
from odoo import fields, models
22

33

44
class Message(models.Model):
@@ -41,25 +41,3 @@ class Message(models.Model):
4141
"The combination of a text to translate and its context must be unique within the same resource!",
4242
),
4343
]
44-
45-
@api.model
46-
def get_message(self, message_id, target_lang_id):
47-
message_records = self.browse([message_id])
48-
message_records.ensure_one()
49-
message_record = next(iter(message_records))
50-
return {
51-
"id": message_record.id,
52-
"body": message_record.body,
53-
"context": message_record.context,
54-
"translator_comments": message_record.translator_comments,
55-
"extracted_comments": message_record.extracted_comments,
56-
"references": message_record.references,
57-
"translations": [
58-
{
59-
"id": record.id,
60-
"body": record.body,
61-
}
62-
for record in message_record.translation_ids
63-
if record.lang_id.id == target_lang_id
64-
],
65-
}

addons/t9n/models/project.py

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -35,44 +35,22 @@ def _check_source_and_target_languages(self):
3535

3636
@api.model
3737
def get_projects(self):
38-
projects_records = self.search([])
38+
return self.search([])._format()
39+
40+
def _format(self):
3941
return [
4042
{
4143
"id": record.id,
4244
"name": record.name,
43-
"src_lang_id": {
44-
"id": record.src_lang_id.id,
45-
"name": record.src_lang_id.name if record.src_lang_id.name else "",
46-
},
45+
"src_lang_id": record.src_lang_id._format()[0],
4746
"resource_ids": [
4847
{
4948
"id": resource.id,
5049
"file_name": resource.file_name,
5150
}
5251
for resource in record.resource_ids
5352
],
54-
"target_lang_ids": [
55-
{
56-
"id": lang.id,
57-
"name": lang.name,
58-
}
59-
for lang in record.target_lang_ids
60-
],
61-
}
62-
for record in projects_records
63-
]
64-
65-
@api.model
66-
def get_target_langs(self, id):
67-
project_records = self.browse([id])
68-
project_records.ensure_one()
69-
project_record = next(iter(project_records))
70-
return [
71-
{
72-
"id": lang.id,
73-
"name": lang.name,
74-
"code": lang.code,
75-
"native_name": lang.native_name,
53+
"target_lang_ids": record.target_lang_ids._format(),
7654
}
77-
for lang in project_record.target_lang_ids
55+
for record in self
7856
]

addons/t9n/models/resource.py

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -106,40 +106,20 @@ def _format(self):
106106
{
107107
"id": msg.id,
108108
"body": msg.body,
109-
} for msg in resource.message_ids
109+
"translation_ids": [
110+
{
111+
"id": translation.id,
112+
"body": translation.body,
113+
"lang_id": translation.lang_id.id,
114+
}
115+
for translation in msg.translation_ids
116+
],
117+
}
118+
for msg in resource.message_ids
110119
],
111120
"project_id": {
112121
"id": resource.project_id.id,
113122
},
114-
} for resource in self
123+
}
124+
for resource in self
115125
]
116-
117-
@api.model
118-
def get_resource(self, id, target_lang_id):
119-
resource_records = self.browse([id])
120-
resource_records.ensure_one()
121-
resource_record = next(iter(resource_records))
122-
return {
123-
"id": resource_record.id,
124-
"file_name": resource_record.file_name,
125-
"project_id": resource_record.project_id.id,
126-
"messages": [
127-
{
128-
"id": message.id,
129-
"body": message.body,
130-
"context": message.context,
131-
"translator_comments": message.translator_comments,
132-
"extracted_comments": message.extracted_comments,
133-
"references": message.references,
134-
"translations": [
135-
{
136-
"id": lang.id,
137-
"body": lang.body,
138-
}
139-
for lang in message.translation_ids
140-
if lang.lang_id.id == target_lang_id
141-
],
142-
}
143-
for message in resource_record.message_ids
144-
],
145-
}

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

Lines changed: 0 additions & 6 deletions
This file was deleted.

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

Lines changed: 0 additions & 6 deletions
This file was deleted.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
</tr>
1818
</thead>
1919
<tbody>
20-
<t t-foreach="this.languages" t-as="language" t-key="language.id">
20+
<t t-foreach="languages" t-as="language" t-key="language.id">
2121
<tr>
2222
<td>
2323
<button class="btn btn-link " t-on-click="() => this.onClickLanguage(language)">

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

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
import { Component, useState, useRef } from "@odoo/owl";
2-
3-
import { CopyPopover } from "@t9n/core/copy_button_popover";
1+
import { Component, useState } from "@odoo/owl";
42

3+
import { _t } from "@web/core/l10n/translation";
54
import { useService } from "@web/core/utils/hooks";
6-
import { usePopover } from "@web/core/popover/popover_hook";
75

86
export class MessageForm extends Component {
97
static props = {};
@@ -15,13 +13,7 @@ export class MessageForm extends Component {
1513
});
1614
this.store = useState(useService("mail.store"));
1715
this.orm = useService("orm");
18-
this.popoverButtonRef = useRef("popover-button");
19-
this.copyPopover = usePopover(CopyPopover, {
20-
position: "top",
21-
animation: true,
22-
arrow: true,
23-
closeOnClickAway: true,
24-
});
16+
this.notification = useService("notification");
2517
}
2618

2719
get message() {
@@ -38,11 +30,11 @@ export class MessageForm extends Component {
3830

3931
async onClickCopy(ev) {
4032
try {
41-
await navigator.clipboard.writeText(this.state.suggestedTranslationText.trim());
42-
this.copyPopover.open(this.popoverButtonRef.el, {});
43-
setTimeout(() => {
44-
this.copyPopover.close();
45-
}, 3000);
33+
await navigator.clipboard.writeText(this.message.body.trim());
34+
this.notification.add(
35+
_t("Copied to clipboard!"),
36+
{ type: "info" }
37+
);
4638
} catch (error) {
4739
console.error("Error copying text:", error);
4840
}
@@ -56,7 +48,7 @@ export class MessageForm extends Component {
5648
lang_id: this.store.t9n.activeLanguage.id,
5749
},
5850
);
59-
console.log(data);
51+
6052
this.store["t9n.translation"].insert(data);
6153
this.state.suggestedTranslationText = "";
6254
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@
5050
</p>
5151
</div>
5252
<div class="form-group">
53-
<textarea class="form-control" rows="3" placeholder="Write your translation" t-model="state.suggestedTranslationText" t-ref="popover-button"></textarea>
53+
<textarea class="form-control" rows="3" placeholder="Write your translation" t-model="state.suggestedTranslationText" ></textarea>
5454
</div>
5555
<div class="d-flex justify-content-end my-3">
5656
<button class="btn btn-outline-primary mx-1" t-on-click="onClickClear">Clear</button>
57-
<button class="btn btn-outline-primary mx-1" data-toggle="popover" t-on-click="onClickCopy">Copy</button>
57+
<button class="btn btn-outline-primary mx-1" t-on-click="onClickCopy">Copy</button>
5858
<button class="btn btn-primary mx-1" t-on-click="onClickSuggest">Suggest</button>
5959
</div>
6060
</div>

addons/t9n/static/src/core/models/app_model.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export class AppModel extends Record {
77
activeLanguage = Record.one("t9n.language");
88
activeResource = Record.one("t9n.resource");
99
activeMessage = Record.one("t9n.message");
10-
/** @type {"ProjectList|"LanguageList"|"ResourceList"|"TranslationEditor"} */
10+
/** @type {"ProjectList"|"LanguageList"|"ResourceList"|"TranslationEditor"} */
1111
activeView = "ProjectList";
1212
}
1313

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export class ResourceList extends Component {
1313
searchText: "",
1414
},
1515
sorting: {
16-
column: "fileName",
16+
column: "file_name",
1717
order: "asc",
1818
},
1919
});
@@ -24,8 +24,8 @@ export class ResourceList extends Component {
2424
get resources() {
2525
const searchTerms = this.state.filters.searchText.trim().toUpperCase();
2626
const resources = searchTerms
27-
? this.store.resources.filter((r) => r.fileName.toUpperCase().includes(searchTerms))
28-
: [...this.store.resources];
27+
? this.props.resources.filter((r) => r.file_name.toUpperCase().includes(searchTerms))
28+
: [...this.props.resources];
2929

3030
resources.sort((r1, r2) => {
3131
let r1Col = r1[this.state.sorting.column];
@@ -49,7 +49,7 @@ export class ResourceList extends Component {
4949
const resourceData = await this.env.services.orm.call(
5050
"t9n.resource",
5151
"get_resources",
52-
this.props.resources.map(({ id }) => id)
52+
[this.props.resources.map(({ id }) => id)],
5353
);
5454
this.store["t9n.resource"].insert(resourceData);
5555
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
<table class="table table-hover">
1111
<thead>
1212
<tr>
13-
<th t-on-click="() => this.onClickColumnName('fileName')">Resource <i t-attf-class="btn btn-link fa fa-sort-{{this.state.sorting.column === 'name' and this.state.sorting.order === 'asc' ? 'up' : 'down'}}"></i>
13+
<th t-on-click="() => this.onClickColumnName('file_name')">Resource <i t-attf-class="btn btn-link fa fa-sort-{{this.state.sorting.column === 'file_name' and this.state.sorting.order === 'asc' ? 'up' : 'down'}}"></i>
1414
</th>
1515
</tr>
1616
</thead>
1717
<tbody>
18-
<t t-foreach="props.resources" t-as="resource" t-key="resource.id">
18+
<t t-foreach="resources" t-as="resource" t-key="resource.id">
1919
<tr>
2020
<td>
2121
<button class="btn btn-link " t-on-click="() => this.onClickResource(resource)">

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

Lines changed: 0 additions & 86 deletions
This file was deleted.

addons/t9n/static/src/web/open_app_action.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import { Component, xml } from "@odoo/owl";
1+
import { Component, xml, useState} from "@odoo/owl";
22

33
import { App } from "@t9n/core/app";
44

55
import { registry } from "@web/core/registry";
66
import { standardActionServiceProps } from "@web/webclient/actions/action_service";
7+
import { useService } from "@web/core/utils/hooks";
78

89
/**
910
* Wraps the application root, allowing us to open the application as a result
@@ -13,6 +14,14 @@ export class OpenApp extends Component {
1314
static components = { App };
1415
static props = { ...standardActionServiceProps };
1516
static template = xml`<App/>`;
17+
18+
setup() {
19+
this.store = useState(useService("mail.store"));
20+
this.store.t9n.activeView = 'ProjectList';
21+
this.store.t9n.activeLanguage = null;
22+
this.store.t9n.activeResource = null;
23+
this.store.t9n.activeMessage = null;
24+
}
1625
}
1726

1827
registry.category("actions").add("t9n.open_app", OpenApp);

0 commit comments

Comments
 (0)