mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-05 13:39:24 +08:00
* feat: add import client * feat: add import server * refactor: change export use library of file-saver * refactor: upload excel file done * refactor: upload xls transform * feat: upload ui done * feat: exclude unable import fields * feat: excel file validator done * feat: import done * feat: import transform done * fix: add import plugin in presets * fix: explain will not output in template what is empty * fix: config permission * fix: permission skip * fix: import password must be string * fix: done close Modal * fix: loop through, inserting data item by item * fix: number calc with using mathjs * fix: import plugin add locale * fix: fix some bugs * feat: bulk update done * fix: transaction cannot be rolled back because it has been finished with state: rollback * fix(plugin-system-settings): convert array to json * fix(collection-manager): o2m is array type * fix: missing RefreshActionInitializer * fix(collection-manger): incorrect scope key parameter * fix: can't access pages without permission via url (#826) * feat(database): add sequence field type (#779) * feat(database): add serialString field type * feat(database): add serial string type field ui (skip ci) * test(feat/database): test field options * docs: demo * fix(database): fix array table field behavior * fix(database): fix serial type interface ui * fix(database): add match logic for patterns changes * fix(database): fix serial type query last bug in mysql * refactor(database): refactor last record logic * chore: revert modification on unnecessary file * refactor(database): rename serialString type to sequence Co-authored-by: chenos <chenlinxh@gmail.com> * added Russian translation (#840) * Russian translation * Add files via upload Add RU locale into index.ts Bugs fixed in the ru_RU.ts * Update index.ts Correct lines 4 and 8 * feat: update option must have filter or filterByTk (#847) * feat: update option must have filter or filterByTk * fix: typo * fix: typo * feat(core/cache): support cache (#876) * feat(core/cache): support cache * build(create-nocobase-app): remove --cache-store-package cli option * perf(core/cache): modify default cache config and remove unnecessary logic code * fix: slow join query issued by appends field in find method of repository (#845) * fix: slow join query issue by appends field in repository.find * feat: handle appending query in multiple relation repository * feat: handle appending query in single relation repository Co-authored-by: chenos <chenlinxh@gmail.com> * fix: sort parameter is missing (#849) * fix: 审计日志翻页sort丢失 * fix: 审计日志翻页sort丢失 * fix: 审计日志翻页sort丢失 Co-authored-by: 唐小爱 <tangxiaoai@192.168.0.103> * fix(formula): support integer and fix NaN error (#879) * fix(formula): support integer and fix NaN error * style(formula-input): remove debugger * fix(database): fix the index name too long error * feat(collection-manager): inverse fields can be configured (#883) * feat: inverse field * feat: improve code * feat: translations * fix: required * fix: run test by jest (#891) * fix: unable to submit form during file upload (#892) * fix(client/block-select-collection): fix select collection menu view error (#889) * fix(client/block-select-collection): fix too many collection menu view error * fix(client/relate-collection-field-menu): fix relate collection field menu view too long error * fix(client/record-picker): support record-picker show format DataPicker (#888) * fix(client/record-picker): support record-picker show format DataPicker * fix(client/record-picker): undefined judgment and when change field's label refresh format in time * feat: improve signin and signup page components * feat(plugin-workflow): add concat calculator (#894) * fix: single relation repository appends query issue (#901) * fix: appends merge includes (#905) * fix: build error * fix(client): tab pane initializers for create form block * fix: version judgment is not accurate * fix: sync collection field default value (#907) * feat: limit database identifier (#908) * fix: cannot read properties of undefined (reading 'target') * fix: appends merge now using primary key (#911) * fix: appends merge now using primary key * chore: console.log * fix: unbind on error throwing (#914) * feat: create with array of values (#912) * feat: create with array of values * chore: console.log * chore: debug * fix(client/route-switch): skip sub routes * Feat: plugin workflow collection field (#919) * feat(plugin-workflow): use Collectionfield component to render form * fix(plugin-workflow): fix association types value assigning in nodes * fix: missing menuItemGroupCss * fix: multiple = false * chore(versions): 😊 publish v0.7.5-alpha.1 (#920) * fix(plugin-workflow): temp disable validation of collection field in node (#928) * fix(plugin-workflow): fix schedule infinitely trigger when repeat not set (#926) * Feat/plugin workflow collection field (#934) * feat(plugin-workflow): support association constant simple input * fix(plugin-workflow): remove useless code * fix(plugin-workflow): add req context to processor (#936) * feat: bulk update done * feat: bulk edit done * fix: fix import bug * Update database.ts * fix: workflow * fix: error * fix: plugin-import * fix: handle locale * fix: handle locale * fix: allow email is undefined * fix: action add loading * fix: fix import bug * fix: not allow sequence import * fix: remove field not allow download template * fix: remove field not allow download template * fix: checkbox batch edit error * fix: fix build edit Co-authored-by: Semmy <semmywong@126.com> Co-authored-by: Junyi <mytharcher@users.noreply.github.com> Co-authored-by: arzanov <59161748+arzanov@users.noreply.github.com> Co-authored-by: ChengLei Shao <chareice@live.com> Co-authored-by: lyf-coder <58352715+lyf-coder@users.noreply.github.com> Co-authored-by: katherinehhh <shunai.tang@hand-china.com> Co-authored-by: 唐小爱 <tangxiaoai@192.168.0.103>
161 lines
5.1 KiB
TypeScript
161 lines
5.1 KiB
TypeScript
import { str2moment } from '@nocobase/utils';
|
|
import * as math from 'mathjs';
|
|
import moment from 'moment';
|
|
import { namespace } from '../../';
|
|
|
|
export async function _({ value, field }) {
|
|
return value;
|
|
}
|
|
|
|
export async function email({ value, field, ctx }) {
|
|
if (!value?.trim()) {
|
|
return value;
|
|
}
|
|
const emailReg = /^([a-zA-Z0-9._-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/;
|
|
if (!emailReg.test(value)) {
|
|
throw new Error(ctx.t('Incorrect email format', { ns: namespace }));
|
|
}
|
|
return value;
|
|
}
|
|
|
|
export async function password({ value, field, ctx }) {
|
|
if (value === undefined || value === null) {
|
|
throw new Error(ctx.t('password is empty', { ns: namespace }));
|
|
}
|
|
return `${value}`;
|
|
}
|
|
|
|
export async function o2o({ value, column, field, ctx }) {
|
|
const { dataIndex, enum: enumData } = column;
|
|
const repository = ctx.db.getRepository(field.options.target);
|
|
let enumItem = null;
|
|
if (enumData?.length > 0) {
|
|
enumItem = enumData.find((e) => e.label === value);
|
|
}
|
|
const val = await repository.findOne({ filter: { [dataIndex[1]]: enumItem?.value ?? value } });
|
|
return val;
|
|
}
|
|
export const oho = o2o;
|
|
export const obo = o2o;
|
|
|
|
export async function o2m({ value, column, field, ctx }) {
|
|
let results = [];
|
|
const values = value.split(';').map((val) => val.trim());
|
|
const { dataIndex, enum: enumData } = column;
|
|
const repository = ctx.db.getRepository(field.options.target);
|
|
if (enumData?.length > 0) {
|
|
const enumValues = values.map((val) => {
|
|
const v = enumData.find((e) => e.label === val);
|
|
if (v === undefined) {
|
|
throw new Error(`not found enum value ${val}`);
|
|
}
|
|
return v.value;
|
|
});
|
|
results = await repository.find({ filter: { [dataIndex[1]]: enumValues } });
|
|
} else {
|
|
results = await repository.find({ filter: { [dataIndex[1]]: values } });
|
|
}
|
|
return results;
|
|
}
|
|
|
|
export async function m2o({ value, column, field, ctx }) {
|
|
let results = null;
|
|
const { dataIndex, enum: enumData } = column;
|
|
const repository = ctx.db.getRepository(field.options.target);
|
|
if (enumData?.length > 0) {
|
|
const enumValue = enumData.find((e) => e.label === value?.trim())?.value;
|
|
results = await repository.findOne({ filter: { [dataIndex[1]]: enumValue } });
|
|
} else {
|
|
results = await repository.findOne({ filter: { [dataIndex[1]]: value } });
|
|
}
|
|
return results;
|
|
}
|
|
|
|
export async function m2m({ value, column, field, ctx }) {
|
|
let results = [];
|
|
const values = value.split(';').map((val) => val.trim());
|
|
const { dataIndex, enum: enumData } = column;
|
|
const repository = ctx.db.getRepository(field.options.target);
|
|
if (enumData?.length > 0) {
|
|
const enumValues = values.map((val) => {
|
|
const v = enumData.find((e) => e.label === val);
|
|
if (v === undefined) {
|
|
throw new Error(`not found enum value ${val}`);
|
|
}
|
|
return v.value;
|
|
});
|
|
results = await repository.find({ filter: { [dataIndex[1]]: enumValues } });
|
|
} else {
|
|
results = await repository.find({ filter: { [dataIndex[1]]: values } });
|
|
}
|
|
return results;
|
|
}
|
|
export async function datetime({ value, field, ctx }) {
|
|
if (!value) {
|
|
return '';
|
|
}
|
|
const utcOffset = ctx.get('X-Timezone');
|
|
const props = field.options?.uiSchema?.['x-component-props'] ?? {};
|
|
const m = str2moment(value, { ...props, utcOffset });
|
|
if (!m.isValid()) {
|
|
throw new Error(ctx.t('Incorrect date format', { ns: namespace }));
|
|
}
|
|
return m.toDate();
|
|
}
|
|
export async function time({ value, field, ctx }) {
|
|
const { format } = field.options?.uiSchema?.['x-component-props'] ?? {};
|
|
if (format) {
|
|
const m = moment(value, format);
|
|
if (!m.isValid()) {
|
|
throw new Error(ctx.t('Incorrect time format', { ns: namespace }));
|
|
}
|
|
return m.format(format);
|
|
}
|
|
return value;
|
|
}
|
|
export async function percent({ value, field, ctx }) {
|
|
if (value) {
|
|
const numberValue = Number(value?.split('%')?.[0] ?? value);
|
|
if (isNaN(numberValue)) {
|
|
throw new Error(ctx.t('Illegal percentage format', { ns: namespace }));
|
|
}
|
|
return math.round(numberValue / 100, 9);
|
|
}
|
|
return 0;
|
|
}
|
|
export async function checkbox({ value, column, field, ctx }) {
|
|
return value === ctx.t('Yes', { ns: namespace }) ? 1 : 0;
|
|
}
|
|
|
|
export const boolean = checkbox;
|
|
|
|
export async function select({ value, column, field, ctx }) {
|
|
const { enum: enumData } = column;
|
|
const item = enumData.find((item) => item.label === value);
|
|
return item?.value;
|
|
}
|
|
export const radio = select;
|
|
|
|
export const radioGroup = select;
|
|
|
|
export async function multipleSelect({ value, column, field, ctx }) {
|
|
const values = value?.split(';');
|
|
const { enum: enumData } = column;
|
|
const results = values?.map((val) => {
|
|
const item = enumData.find((item) => item.label === val);
|
|
return item;
|
|
});
|
|
return results?.map((result) => result?.value);
|
|
}
|
|
|
|
export const checkboxes = multipleSelect;
|
|
|
|
export const checkboxGroup = multipleSelect;
|
|
|
|
export async function chinaRegion({ value, column, field, ctx }) {
|
|
const values = value?.split('/')?.map((val) => val.trim());
|
|
const repository = ctx.db.getRepository('chinaRegions');
|
|
const results = await repository.find({ filter: { name: values } });
|
|
return results;
|
|
}
|