Skip to content

Commit

Permalink
imp: dynamic command options
Browse files Browse the repository at this point in the history
  • Loading branch information
Tardo committed Nov 5, 2023
1 parent b77b7c8 commit 8db11ab
Show file tree
Hide file tree
Showing 28 changed files with 378 additions and 350 deletions.
10 changes: 10 additions & 0 deletions src/css/terminal.css
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,14 @@
background-color: var(--terminal-screen-assistant-desc-background-color);
}

.o_terminal div#terminal_assistant > span#terminal_assistant_args_info {
position: absolute;
bottom: 0;
right: 10px;
border-radius: 2px 2px 0 0;
background-color: #878787;
}

.o_terminal .terminal-user-input {
background-color: var(--terminal-screen-background-color);
border: 1px dotted #5a5a5a;
Expand Down Expand Up @@ -257,6 +265,8 @@
color: var(--terminal-screen-extra-info-color);
}

/** COMMAND ASSISTANT **/

/** HELP COMMAND **/
.o_terminal .terminal-info-section {
margin-left: 2em;
Expand Down
49 changes: 21 additions & 28 deletions src/js/page/odoo/commands/backoffice/lang.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import searchRead from '@odoo/orm/search_read';
import callModelMulti from '@odoo/osv/call_model_multi';
import callModel from '@odoo/osv/call_model';
import getContent from '@odoo/utils/get_content';
import cachedSearchRead from '@odoo/utils/cached_search_read';
import file2base64 from '@terminal/utils/file2base64';
import isEmpty from '@terminal/utils/is_empty';
import {ARG} from '@trash/constants';
Expand Down Expand Up @@ -146,37 +147,29 @@ async function cmdLang(kwargs, screen) {
throw new Error('Invalid operation!');
}

const cache = {
modules: [],
langs: [],
};
async function getOptions(arg_name, arg_info, arg_value) {
function getOptions(arg_name) {
if (arg_name === 'module') {
if (!arg_value) {
const records = await searchRead(
'ir.module.module',
[],
['name'],
this.getContext(),
);
cache.modules = records.map(item => item.name);
return cache.modules;
}
return cache.modules.filter(item => item.startsWith(arg_value));
return cachedSearchRead(
'options_ir.module.module_active',
'ir.module.module',
[],
['name'],
this.getContext({active_test: true}),
null,
item => item.name,
);
} else if (arg_name === 'lang') {
if (!arg_value) {
const records = await searchRead(
'res.lang',
[['active', '=', true]],
['code'],
this.getContext(),
);
cache.langs = records.map(item => item.code);
return cache.langs;
}
return cache.langs.filter(item => item.startsWith(arg_value));
return cachedSearchRead(
'options_res.lang_active',
'res.lang',
[],
['code'],
this.getContext({active_test: true}),
null,
item => item.code,
);
}
return [];
return Promise.resolve([]);
}

export default {
Expand Down
27 changes: 12 additions & 15 deletions src/js/page/odoo/commands/backoffice/settings.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

import doAction from '@odoo/base/do_action';
import searchRead from '@odoo/orm/search_read';
import cachedSearchRead from '@odoo/utils/cached_search_read';
import {ARG} from '@trash/constants';

async function cmdOpenSettings(kwargs) {
Expand All @@ -18,22 +18,19 @@ async function cmdOpenSettings(kwargs) {
this.doHide();
}

let cache = [];
async function getOptions(arg_name, arg_info, arg_value) {
function getOptions(arg_name) {
if (arg_name === 'module') {
if (!arg_value) {
const records = await searchRead(
'ir.module.module',
[],
['name'],
this.getContext(),
);
cache = records.map(item => item.name);
return cache;
}
return cache.filter(item => item.startsWith(arg_value));
return cachedSearchRead(
'options_ir.module.module_active',
'ir.module.module',
[],
['name'],
this.getContext({active_test: true}),
null,
item => item.name,
);
}
return [];
return Promise.resolve([]);
}

export default {
Expand Down
27 changes: 12 additions & 15 deletions src/js/page/odoo/commands/backoffice/view.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import doAction from '@odoo/base/do_action';
import getParentAdapter from '@odoo/utils/get_parent_adapter';
import getOdooService from '@odoo/utils/get_odoo_service';
import getOdooVersionMajor from '@odoo/utils/get_odoo_version_major';
import searchRead from '@odoo/orm/search_read';
import cachedSearchRead from '@odoo/utils/cached_search_read';
import {ARG} from '@trash/constants';

function openSelectCreateDialog(model, title, domain, on_selected) {
Expand Down Expand Up @@ -71,22 +71,19 @@ async function cmdViewModelRecord(kwargs) {
);
}

let cache = [];
async function getOptions(arg_name, arg_info, arg_value) {
function getOptions(arg_name) {
if (arg_name === 'model') {
if (!arg_value) {
const records = await searchRead(
'ir.model',
[],
['model'],
this.getContext(),
);
cache = records.map(item => item.model);
return cache;
}
return cache.filter(item => item.startsWith(arg_value));
return cachedSearchRead(
'options_ir.model_active',
'ir.model',
[],
['model'],
this.getContext({active_test: true}),
null,
item => item.model,
);
}
return [];
return Promise.resolve([]);
}

export default {
Expand Down
27 changes: 12 additions & 15 deletions src/js/page/odoo/commands/common/caf.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

import callModel from '@odoo/osv/call_model';
import searchRead from '@odoo/orm/search_read';
import cachedSearchRead from '@odoo/utils/cached_search_read';
import isEmpty from '@terminal/utils/is_empty';
import {ARG} from '@trash/constants';

Expand Down Expand Up @@ -70,22 +70,19 @@ async function cmdCheckFieldAccess(kwargs, screen) {
return s_result;
}

let cache = [];
async function getOptions(arg_name, arg_info, arg_value) {
function getOptions(arg_name) {
if (arg_name === 'model') {
if (!arg_value) {
const records = await searchRead(
'ir.model',
[],
['model'],
this.getContext(),
);
cache = records.map(item => item.model);
return cache;
}
return cache.filter(item => item.startsWith(arg_value));
return cachedSearchRead(
'options_ir.model_active',
'ir.model',
[],
['model'],
this.getContext({active_test: true}),
null,
item => item.model,
);
}
return [];
return Promise.resolve([]);
}

export default {
Expand Down
27 changes: 12 additions & 15 deletions src/js/page/odoo/commands/common/call.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

import rpcQuery from '@odoo/rpc';
import searchRead from '@odoo/orm/search_read';
import cachedSearchRead from '@odoo/utils/cached_search_read';
import {ARG} from '@trash/constants';

async function cmdCallModelMethod(kwargs, screen) {
Expand All @@ -21,22 +21,19 @@ async function cmdCallModelMethod(kwargs, screen) {
});
}

let cache = [];
async function getOptions(arg_name, arg_info, arg_value) {
function getOptions(arg_name) {
if (arg_name === 'model') {
if (!arg_value) {
const records = await searchRead(
'ir.model',
[],
['model'],
this.getContext(),
);
cache = records.map(item => item.model);
return cache;
}
return cache.filter(item => item.startsWith(arg_value));
return cachedSearchRead(
'options_ir.model_active',
'ir.model',
[],
['model'],
this.getContext({active_test: true}),
null,
item => item.model,
);
}
return [];
return Promise.resolve([]);
}

export default {
Expand Down
27 changes: 12 additions & 15 deletions src/js/page/odoo/commands/common/cam.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

import callModel from '@odoo/osv/call_model';
import searchRead from '@odoo/orm/search_read';
import cachedSearchRead from '@odoo/utils/cached_search_read';
import {ARG} from '@trash/constants';

async function cmdCheckModelAccess(kwargs, screen) {
Expand All @@ -24,22 +24,19 @@ async function cmdCheckModelAccess(kwargs, screen) {
});
}

let cache = [];
async function getOptions(arg_name, arg_info, arg_value) {
function getOptions(arg_name) {
if (arg_name === 'model') {
if (!arg_value) {
const records = await searchRead(
'ir.model',
[],
['model'],
this.getContext(),
);
cache = records.map(item => item.model);
return cache;
}
return cache.filter(item => item.startsWith(arg_value));
return cachedSearchRead(
'options_ir.model_active',
'ir.model',
[],
['model'],
this.getContext({active_test: true}),
null,
item => item.model,
);
}
return [];
return Promise.resolve([]);
}

export default {
Expand Down
27 changes: 12 additions & 15 deletions src/js/page/odoo/commands/common/count.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

import searchCount from '@odoo/orm/search_count';
import searchRead from '@odoo/orm/search_read';
import cachedSearchRead from '@odoo/utils/cached_search_read';
import {ARG} from '@trash/constants';

async function cmdCount(kwargs, screen) {
Expand All @@ -14,22 +14,19 @@ async function cmdCount(kwargs, screen) {
);
}

let cache = [];
async function getOptions(arg_name, arg_info, arg_value) {
function getOptions(arg_name) {
if (arg_name === 'model') {
if (!arg_value) {
const records = await searchRead(
'ir.model',
[],
['model'],
this.getContext(),
);
cache = records.map(item => item.model);
return cache;
}
return cache.filter(item => item.startsWith(arg_value));
return cachedSearchRead(
'options_ir.model_active',
'ir.model',
[],
['model'],
this.getContext({active_test: true}),
null,
item => item.model,
);
}
return [];
return Promise.resolve([]);
}

export default {
Expand Down
27 changes: 12 additions & 15 deletions src/js/page/odoo/commands/common/create.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import doAction from '@odoo/base/do_action';
import createRecord from '@odoo/orm/create_record';
import searchRead from '@odoo/orm/search_read';
import cachedSearchRead from '@odoo/utils/cached_search_read';
import Recordset from '@terminal/core/recordset';
import renderRecordCreated from '@odoo/templates/record_created';
import {ARG} from '@trash/constants';
Expand Down Expand Up @@ -39,22 +39,19 @@ async function cmdCreateModelRecord(kwargs, screen) {
return Recordset.make(kwargs.model, records);
}

let cache = [];
async function getOptions(arg_name, arg_info, arg_value) {
function getOptions(arg_name) {
if (arg_name === 'model') {
if (!arg_value) {
const records = await searchRead(
'ir.model',
[],
['model'],
this.getContext(),
);
cache = records.map(item => item.model);
return cache;
}
return cache.filter(item => item.startsWith(arg_value));
return cachedSearchRead(
'options_ir.model_active',
'ir.model',
[],
['model'],
this.getContext({active_test: true}),
null,
item => item.model,
);
}
return [];
return Promise.resolve([]);
}

export default {
Expand Down
Loading

0 comments on commit 8db11ab

Please sign in to comment.