UNPKG

react-antd-admin-panel

Version:

Easy prototyping admin panel using React and Antd

194 lines 8.76 kB
export default class Default { constructor(_class) { this._componentIsBuild = false; this._history = {}; // What should happen to the .tsx once your /view/*.tsx calls the function. // This is basically the .tsx's action-interface. this.onHandleAdd = () => { }; this.onHandleClear = () => { }; this.onHandleReset = () => { }; this.onHandleChange = () => { }; this.onHandleSearch = () => { }; this.onHandleToggle = () => { }; this.onHandleLoading = () => { }; /** */ this.tsxHistoryRevert = () => { console.log('[UNSET] tsxHistoryRevert'); }; this.tsxSetDisabled = () => { console.log('[UNSET] tsxSetDisabled'); }; this.tsxSetLoading = () => { console.log('[UNSET] tsxSetLoading'); }; this.tsxSetValue = () => { console.log('[UNSET] tsxSetValue'); }; this.tsxClear = () => { console.log('[UNSET] tsxClear'); }; /** */ this._call = {}; this._useCache = false; this._filterFunction = () => false; this._access = true; this._required = false; this._disabled = false; this._readOnly = false; this._fields = []; // Some function to format the value before we return it. this._format = (value) => value; // The Parent *.tsx-component should set this. this._update = () => { console.log('Update not implemented'); }; this._onComplete = () => { }; // For both Error and Complete, these are called by the binding Post or Get. this._onError = () => { }; // These are called by the .tsx, implemented in the /view/*.tsx this._onClick = () => { }; this._onChange = undefined; this._onChangeNext = undefined; this._onAfterChange = () => { }; this._onChangeSelect = () => { }; this._onDelete = () => { }; // Any data we got back from the Action or Get can be placed her if needed. this._data = undefined; this._size = 24; this._sizeString = 'large'; this._clearable = true; this._ignoreOnChange = false; this._ignoreSetState = false; this._width = '100%'; this._class = 'undefined'; if (_class) this._class = _class; } history(v) { let key = Math.round(Math.random() * 10000); this._history[key] = { success: false, completed: false, value: v }; return key; } getFieldByClass(v) { return this._fields.find(r => r._class === v); } call(key, v) { this._call[key] = v; return this; } alter(v) { this._alter = v; return this; } useCache(v) { this._useCache = v; return this; } filter(filter) { this._filter = filter; return this; } filters() { return this.filterModels(this._filter, []); } edit(edit) { this._editFunction = edit; return this; } editBuild(node, next, main, model) { var _a; (_a = this._editFunction) === null || _a === void 0 ? void 0 : _a.call(this, node, next, main, model); } show(show) { this._showFunction = show; return this; } showBuild(node, next, main) { var _a; (_a = this._showFunction) === null || _a === void 0 ? void 0 : _a.call(this, node, next, main); } filterFunction(func) { this._filterFunction = func; return this; } ref(ref) { this._ref = ref; return this; } key(key) { this._key = key; return this; } index(index) { this._index = index; return this; } style(v) { this._style = v; return this; } styleForm(v) { this._styleForm = v; return this; } access(access) { this._access = access; return this; } accessLevel(feature, level) { this._accessLevel = { feature: feature, level: level }; return this; } label(label) { this._label = label; return this; } required(v) { this._required = !!v; return this; } disabled(v) { this._disabled = !!v; return this; } readOnly(v) { this._readOnly = !!v; return this; } default(v) { this._defaultObject = v; this._default = v; return this; } add(v) { this._fields.push(v); return this; } addMore(v) { v.forEach((r) => this._fields.push(r)); return this; } formula(formula) { this._formula = formula; this._formulaIsRoot = true; return this; } formulaSetChildren(formula) { var _a, _b; this._formula = (_a = this._formula) !== null && _a !== void 0 ? _a : formula; (_b = this._action) === null || _b === void 0 ? void 0 : _b.formula(this._formula); this._fields.forEach((field) => { var _a; if (!field._formulaIsRoot) (_a = field.formulaSetChildren) === null || _a === void 0 ? void 0 : _a.call(field, this._formula); }); } // Send values to the formula. value(value) { this.formulaValue(value); } params() { return this.formulaParams(); } paramsRaw() { return this.formulaParamsRaw(); } formulaValue(value) { this._formula.value(this, value); } formulaParams() { return this._formula.params(); } formulaParamsRaw() { return this._formula.paramsRaw(); } section(section) { var _a; this._section = section; (_a = this._action) === null || _a === void 0 ? void 0 : _a.section(this._section); this._fields.forEach((field) => { var _a; return (_a = field.bindSection) === null || _a === void 0 ? void 0 : _a.call(field, this._section); }); } // (1) Set and do nothing. setGet(v, args) { return this.get(v, args); } get(func, args) { this._getFunction = func; this._get = func(args); return this; } // (2) Set and run the Get fetch(func, args) { this._getFunction = func; this.refresh(args); return this; } // (3) Run a Get that is already set refresh(args, callback) { this._get = args ? this._getFunction(args) : this._getFunction(); // TODO: Both the GET and the calling COMPONENT should be able to call _onComplete. // Right now its just the calling COMPONENT, e.g. the button that set the _onComplete. // The button.tsx may use this to toggle its loading state. this._get.onComplete(this._onComplete); this._get.onError(this._onError); this._get.parent(this); this._get.get(args, callback); return this; } refreshWithoutGetCall(args) { this._get.onComplete(this._onComplete); this._get.onError(this._onError); this._get.finalize(args); return this; } refreshWithoutFunctionCall(args) { this._get.onComplete(this._onComplete); this._get.onError(this._onError); this._get.get(args); return this; } action(action) { this._action = action; return this; } format(func) { this._format = func; return this; } formatValue(value) { return this._format(value); } update(func) { this._update = func; return this; } onDelete(func) { this._onDelete = func; return this; } onAfterChange(func, index) { this._onAfterChange = func; this.index(index); return this; } onChangeSelect(func) { this._onChangeSelect = func; return this; } onComplete(func) { this._onComplete = func; return this; } onChange(func) { this._onChange = func; return this; } onChangeNext(func, index) { this._onChangeNext = func; this.index(index); return this; } onClick(func) { this._onClick = func; return this; } onError(func) { this._onError = func; return this; } data(data) { this._data = data; return this; } size(size) { this._size = size; return this; } sizeString(sizeString) { this._sizeString = sizeString; return this; } clearable(v) { this._clearable = v; return this; } ignoreOnChange(v) { this._ignoreOnChange = v; return this; } ignoreSetState(v) { this._ignoreSetState = v; return this; } width(width) { this._width = width; return this; } component(component, args) { this._component = component; this._componentArgs = args; return this; } defaultFromCache() { let store = window.localStorage.getItem(`${this._class.toLowerCase()}:${this._key}`); this._defaultObject = store ? JSON.parse(store) : this._defaultObject; return this; } filterModels(el, filters = []) { if (!el) return filters; el._fields.forEach((r) => { filters.push(r); this.filterModels(r, filters); }); return filters; } } //# sourceMappingURL=Default.js.map