Skip to content

Commit

Permalink
feat: add new attribute calls
Browse files Browse the repository at this point in the history
  • Loading branch information
mguellsegarra committed Mar 4, 2025
1 parent ce8282c commit 6c9de67
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
24 changes: 24 additions & 0 deletions lib/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
RequestOptions,
SaveViewPrefsOptions,
ReadViewPrefsOptions,
ParseConditionsOpts,
} from "./types";
import {
createEvalDomainPayload,
Expand All @@ -20,6 +21,7 @@ import {
createButTreeOpenPayload,
createSaveViewPrefsPayload,
createReadViewPrefsPayload,
createParseConditionsPayload,
} from "./payloads";
export class Client {
host?: string;
Expand Down Expand Up @@ -220,6 +222,28 @@ export class Client {
});
}

public async parseConditions(
data: ParseConditionsOpts,
options?: RequestOptions,
): Promise<any> {
const { color, status, values, context } = data;

This comment has been minimized.

Copy link
@ecarreras

ecarreras Mar 4, 2025

Member

Crec que els exemples estan malament, realement l'atribut es diu colors, aquí la idea és genèrica ja que la API retornarà les claus que se li passin.

Per exemple:

si poses font="bold:unread==True;normal:unread==False" el sistema tornarà {"id": 32, "font": "bold"} contant que se li ha passat un values que té el unread a true.

const { database, token } = this;

const executePayload = createParseConditionsPayload({
database: database!,
token: token!,
color,
status,
values,
context,
});

return await this._fetch({
payload: executePayload,
options,
});
}

public async getShortcuts(
data: GetShortcutsOpts,
options?: RequestOptions,
Expand Down
22 changes: 22 additions & 0 deletions lib/payloads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
SaveViewPrefsPayload,
ReadViewPrefsPayload,
ModelGetToolbarPayload,
ParseConditionsPayload,
} from "./types";

export const makeLoginTokenPayload = (options: LoginTokenPayload): Payload => {
Expand Down Expand Up @@ -347,6 +348,27 @@ export const createAttributeConditionPayload = (
];
};

export const createParseConditionsPayload = (
options: ParseConditionsPayload,
): Payload => {
const { database, token, color, status, values, context } = options;
const conditions: any = {};
if (color !== undefined) conditions.color = color;
if (status !== undefined) conditions.status = status;

return [
"execute",
database,
"token",
token,
"ir.ui.view",
"parse_conditions",
conditions,
values,
context,
];
};

export const createGetShortcutsPayload = (
options: GetShortcutsPayload,
): Payload => {
Expand Down
9 changes: 9 additions & 0 deletions lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,15 @@ export type AttributeConditionPayload = Database &
Token &
AttributeConditionParserOpts;

export type ParseConditionsOpts = {
color: string;
status: string;
values: any;
context?: Context;
};

export type ParseConditionsPayload = Database & Token & ParseConditionsOpts;

export type GetShortcutsOpts = {
context?: Context;
};
Expand Down

0 comments on commit 6c9de67

Please sign in to comment.