2022-04-18 11:29:20 +00:00
|
|
|
import { Frappe } from 'frappe';
|
2022-04-14 09:22:45 +00:00
|
|
|
import { DocValue, DocValueMap } from 'frappe/core/types';
|
2022-04-18 08:01:41 +00:00
|
|
|
import SystemSettings from 'frappe/models/SystemSettings';
|
2022-04-11 09:41:49 +00:00
|
|
|
import { FieldType } from 'schemas/types';
|
|
|
|
import { QueryFilter } from 'utils/db/types';
|
2022-04-11 12:44:36 +00:00
|
|
|
import { Router } from 'vue-router';
|
2022-04-01 09:35:51 +00:00
|
|
|
import Doc from './doc';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The functions below are used for dynamic evaluation
|
|
|
|
* and setting of field types.
|
|
|
|
*
|
|
|
|
* Since they are set directly on the doc, they can
|
|
|
|
* access the doc by using `this`.
|
|
|
|
*
|
|
|
|
* - `Formula`: Async function used for obtaining a computed value such as amount (rate * qty).
|
|
|
|
* - `Default`: Regular function used to dynamically set the default value, example new Date().
|
|
|
|
* - `Validation`: Async function that throw an error if the value is invalid.
|
|
|
|
* - `Required`: Regular function used to decide if a value is mandatory (there are !notnul in the db).
|
|
|
|
*/
|
2022-04-14 09:22:45 +00:00
|
|
|
export type FormulaReturn = DocValue | DocValueMap[] | undefined | Doc[];
|
|
|
|
export type Formula = () => Promise<FormulaReturn> | FormulaReturn;
|
2022-04-01 09:35:51 +00:00
|
|
|
export type Default = () => DocValue;
|
|
|
|
export type Validation = (value: DocValue) => Promise<void>;
|
|
|
|
export type Required = () => boolean;
|
2022-04-14 05:24:11 +00:00
|
|
|
export type Hidden = () => boolean;
|
2022-04-18 08:01:41 +00:00
|
|
|
export type GetCurrency = () => string;
|
2022-04-01 09:35:51 +00:00
|
|
|
|
|
|
|
export type FormulaMap = Record<string, Formula | undefined>;
|
|
|
|
export type DefaultMap = Record<string, Default | undefined>;
|
|
|
|
export type ValidationMap = Record<string, Validation | undefined>;
|
|
|
|
export type RequiredMap = Record<string, Required | undefined>;
|
2022-04-18 08:01:41 +00:00
|
|
|
export type CurrenciesMap = Record<string, GetCurrency>;
|
2022-04-14 05:24:11 +00:00
|
|
|
export type HiddenMap = Record<string, Hidden>;
|
2022-04-11 09:41:49 +00:00
|
|
|
export type DependsOnMap = Record<string, string[]>;
|
2022-04-01 09:35:51 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Should add this for hidden too
|
|
|
|
*/
|
2022-04-07 06:20:14 +00:00
|
|
|
|
2022-04-11 09:41:49 +00:00
|
|
|
export type ModelMap = Record<string, typeof Doc | undefined>;
|
|
|
|
export type DocMap = Record<string, Doc | undefined>;
|
|
|
|
|
2022-04-18 08:01:41 +00:00
|
|
|
export interface SinglesMap {
|
2022-04-18 11:29:20 +00:00
|
|
|
SystemSettings?: SystemSettings;
|
|
|
|
[key: string]: Doc | undefined;
|
2022-04-18 08:01:41 +00:00
|
|
|
}
|
|
|
|
|
2022-04-11 09:41:49 +00:00
|
|
|
// Static Config properties
|
|
|
|
|
|
|
|
export type FilterFunction = (doc: Doc) => QueryFilter;
|
|
|
|
export type FiltersMap = Record<string, FilterFunction>;
|
|
|
|
|
2022-04-18 11:29:20 +00:00
|
|
|
export type EmptyMessageFunction = (doc: Doc, frappe: Frappe) => string;
|
2022-04-11 12:44:36 +00:00
|
|
|
export type EmptyMessageMap = Record<string, EmptyMessageFunction>;
|
|
|
|
|
|
|
|
export type ListFunction = (doc?: Doc) => string[];
|
2022-04-11 09:41:49 +00:00
|
|
|
export type ListsMap = Record<string, ListFunction>;
|
|
|
|
|
2022-04-11 12:44:36 +00:00
|
|
|
export interface Action {
|
|
|
|
label: string;
|
|
|
|
condition: (doc: Doc) => boolean;
|
|
|
|
action: (doc: Doc, router: Router) => Promise<void>;
|
|
|
|
}
|
|
|
|
|
2022-04-11 09:41:49 +00:00
|
|
|
export interface ColumnConfig {
|
|
|
|
label: string;
|
|
|
|
fieldtype: FieldType;
|
2022-04-14 05:24:11 +00:00
|
|
|
fieldname?: string;
|
2022-04-11 09:41:49 +00:00
|
|
|
size?: string;
|
|
|
|
render?: (doc: Doc) => { template: string };
|
|
|
|
getValue?: (doc: Doc) => string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export type ListViewColumn = string | ColumnConfig;
|
|
|
|
export interface ListViewSettings {
|
|
|
|
formRoute?: (name: string) => string;
|
|
|
|
columns?: ListViewColumn[];
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface TreeViewSettings {
|
|
|
|
parentField: string;
|
|
|
|
getRootLabel: () => Promise<string>;
|
|
|
|
}
|