react-antd-admin-panel
Version:
Easy prototyping admin panel using React and Antd
91 lines • 3.34 kB
JavaScript
import Controller from "./controllers/Controller";
import Mapping from "./utils/Mapping";
import User from "./models/User";
import Get from "./models/Get";
export default class Main {
constructor(root, config) {
this.Store = {};
this.Function = {};
this.tsxErrorMessage = () => { console.log('[UNSET] tsxErrorMessage'); };
this.tsxSuccessMessage = () => { console.log('[UNSET] tsxSuccessMessage'); };
this.$root = root;
this.$config = config;
this.$map = new Mapping();
this.Controller = new Controller(this);
}
setRouteKey(v) { this._routeKey = v; }
$modal(v) { this._setModal(v); }
setModal(v) { this._setModal = v; }
$modalClose() { this._setModalClose(); }
setModalClose(v) { this._setModalClose = v; }
$modalLoading(v) { this._setModalLoading(v); }
setModalLoading(v) { this._setModalLoading = v; }
setSiderRight(v) { this._setSiderRight = v; }
setSiderRightReload(v) { this._setSiderRightReload = v; }
setSiderRightLoading(v) { this._setSiderRightLoading = v; }
setSiderRightClose(v) { this._setSiderRightClose = v; }
$access(access, cycle) {
return this.$config.config.access.access(access, this, cycle);
}
$params(key, route) {
return this.$path(route)._params[key];
}
$mapping(key) {
var _a, _b;
return (_b = (_a = this.$config.config) === null || _a === void 0 ? void 0 : _a.mapping) === null || _b === void 0 ? void 0 : _b[key];
}
$store(data, key) {
this.Store[key] = data;
}
$function(func, key) {
if (key in this.Function) {
console.log('Function:', key, 'already set.');
}
this.Function[key] = func;
}
$cycle(route) {
if (!this.Controller._cycles[route])
return undefined;
return this.Controller._cycles[route][this.Controller._cycles[route].length - 1];
}
$route(route, next = false, failed) {
if (!next)
next = () => {
this.$map.$navigate(route);
};
const n = next;
next = () => {
n();
this._routeKey(route);
};
// The .ts tells .tsx to toggle a loading state.
this.$map.$loading(true);
// Construct a Cycle, i.e. pre-building the next page.
this.Controller.onCycle(route, next, failed);
}
$get(cycle, key) {
if (!cycle) {
console.log('$data: cycle is undefined.');
return new Get();
}
let search = cycle._route._gets.filter((r) => {
if (r._key)
return r._key === key;
let target = typeof r._target === 'string' ? r._target : r._target(cycle);
if (typeof target !== 'string')
target = target.target;
return target === key;
});
return search.length ? search[0] : new Get();
}
$path(route) {
return this.$map.$path(route ? route : `${document.location.pathname}${document.location.search}`);
}
$user(user) {
if (!user)
return this.User;
this.User = new User(user);
return this.User;
}
}
//# sourceMappingURL=main.js.map