lynx-admin-ui
Version:
this module adds annotations for entities in order to automatically generate an Administration UI
243 lines (242 loc) • 9.93 kB
JavaScript
;
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __spreadArrays = (this && this.__spreadArrays) || function () {
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
for (var r = Array(s), k = 0, i = 0; i < il; i++)
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
return r;
};
Object.defineProperty(exports, "__esModule", { value: true });
var app_1 = require("lynx-framework/app");
var simple_module_1 = require("lynx-framework/simple.module");
var decorators_1 = require("./decorators");
var AdminUIModule = /** @class */ (function (_super) {
__extends(AdminUIModule, _super);
function AdminUIModule() {
var _this = _super.call(this) || this;
AdminUIModule.configuration[decorators_1.AdminType.Id] = '/admin-ui/editors/id';
AdminUIModule.configuration[decorators_1.AdminType.String] =
'/admin-ui/editors/string';
AdminUIModule.configuration[decorators_1.AdminType.Text] = '/admin-ui/editors/text';
AdminUIModule.configuration[decorators_1.AdminType.Selection] =
'/admin-ui/editors/selection';
AdminUIModule.configuration[decorators_1.AdminType.RichText] =
'/admin-ui/editors/rich-text';
AdminUIModule.configuration[decorators_1.AdminType.Checkbox] =
'/admin-ui/editors/checkbox';
AdminUIModule.configuration[decorators_1.AdminType.Radio] =
'/admin-ui/editors/radio';
AdminUIModule.configuration[decorators_1.AdminType.Number] =
'/admin-ui/editors/number';
AdminUIModule.configuration[decorators_1.AdminType.Date] = '/admin-ui/editors/date';
AdminUIModule.configuration[decorators_1.AdminType.Table] =
'/admin-ui/editors/table';
AdminUIModule.configuration[decorators_1.AdminType.Expanded] =
'/admin-ui/editors/expanded';
AdminUIModule.configuration[decorators_1.AdminType.Time] = '/admin-ui/editors/time';
AdminUIModule.configuration[decorators_1.AdminType.Color] =
'/admin-ui/editors/color';
AdminUIModule.configuration[decorators_1.AdminType.Media] =
'/admin-ui/editors/media';
AdminUIModule.configuration[decorators_1.AdminType.AjaxSelection] =
'/admin-ui/editors/ajax-selection';
AdminUIModule.configuration[decorators_1.AdminType.DateTime] =
'/admin-ui/editors/date-time';
AdminUIModule.configuration[decorators_1.AdminType.ActionButton] =
'/admin-ui/editors/action-button';
AdminUIModule.configuration[decorators_1.AdminType.Currency] =
'/admin-ui/editors/currency';
AdminUIModule.configuration[decorators_1.AdminType.ExpandedAndSelection] =
'/admin-ui/editors/expanded-and-selection';
AdminUIModule.configuration[decorators_1.AdminType.CustomInclude] =
'/admin-ui/editors/custom-include';
setTimeout(function () {
app_1.app.nunjucksEnvironment.addFilter('_adminUIMasterFilter_', function (str, filterName) {
var name = filterName;
var args = [str];
var endName = filterName.indexOf('(');
if (endName > -1) {
name = filterName.substring(0, endName);
var parsed = JSON.parse('[' +
filterName.substring(endName + 1, filterName.length - 1) +
']');
args = __spreadArrays([str], parsed);
}
return app_1.app.nunjucksEnvironment.getFilter(name).apply(void 0, args);
});
}, 2000);
return _this;
}
/**
* Set a new template path for the specified type.
* @param type The type of widget
* @param templatePath The view path of the editor
*/
AdminUIModule.setEditor = function (type, templatePath) {
AdminUIModule.configuration[type] = templatePath;
};
/**
* Customize the index template
* @param path the index template path
*/
AdminUIModule.setIndexTemplatePath = function (path) {
AdminUIModule.indexTemplatePath = path;
};
/**
* Customize the editor template
* @param path the editor template path
*/
AdminUIModule.setEditorTemplatePath = function (path) {
AdminUIModule.editorTemplatePath = path;
};
/**
* Customize the list template
* @param path the list template path
*/
AdminUIModule.setListTemplatePath = function (path) {
AdminUIModule.listTemplatePath = path;
};
/**
* Customize the nested template
* @param path the nested template path
*/
AdminUIModule.setNestedTemplatePath = function (path) {
AdminUIModule.nestedTemplatePath = path;
};
/**
* Customize the popup editor template
* @param path the popup editor template path
*/
AdminUIModule.setEditorPopupTemplatePath = function (path) {
AdminUIModule.popupEditorTemplatePath = path;
};
/**
* Customize the index template
* @param path the index father template path
*/
AdminUIModule.setIndexParentTemplatePath = function (path) {
AdminUIModule.indexParentTemplatePath = path;
};
/**
* Customize the editor template
* @param path the editor father template path
*/
AdminUIModule.setEditorParentTemplatePath = function (path) {
AdminUIModule.editorParentTemplatePath = path;
};
/**
* Customize the list template
* @param path the list father template path
*/
AdminUIModule.setListParentTemplatePath = function (path) {
AdminUIModule.listParentTemplatePath = path;
};
/**
* Customize the nested template
* @param path the nested father template path
*/
AdminUIModule.setNestedParentTemplatePath = function (path) {
AdminUIModule.nestedParentTemplatePath = path;
};
/**
* Customize the popup editor father template
* @param path the popup editor father template path
*/
AdminUIModule.setEditorPopupParentTemplatePath = function (path) {
AdminUIModule.popupEditorParentTemplatePath = path;
};
/**
* Customize to protect routes and frontend
* @param func the function that contains the access logic
*/
AdminUIModule.setCanReadFunction = function (func) {
AdminUIModule.canReadFunction = func;
};
/**
* Customize to protect routes and frontend
* @param func the function that contains the access logic
*/
AdminUIModule.setCanWriteFunction = function (func) {
AdminUIModule.canWriteFunction = func;
};
/**
* Customize the response when access permission is denied (based on canRead/Write methods)
* @param func the function that contains the permission denied logc
*/
AdminUIModule.setPermissionDeniedHandler = function (func) {
AdminUIModule.permissionDeniedHandler = func;
};
Object.defineProperty(AdminUIModule.prototype, "translation", {
get: function () {
return __dirname + '/locale';
},
enumerable: false,
configurable: true
});
Object.defineProperty(AdminUIModule.prototype, "controllers", {
get: function () {
return __dirname + '/controllers';
},
enumerable: false,
configurable: true
});
Object.defineProperty(AdminUIModule.prototype, "views", {
get: function () {
return __dirname + '/views';
},
enumerable: false,
configurable: true
});
Object.defineProperty(AdminUIModule.prototype, "public", {
get: function () {
return __dirname + '/public';
},
enumerable: false,
configurable: true
});
Object.defineProperty(AdminUIModule.prototype, "templating", {
get: function () {
return __dirname + '/templating';
},
enumerable: false,
configurable: true
});
Object.defineProperty(AdminUIModule.prototype, "middlewares", {
get: function () {
return __dirname + '/middlewares';
},
enumerable: false,
configurable: true
});
AdminUIModule.configuration = {};
AdminUIModule.indexParentTemplatePath = '/admin-ui/layouts/base';
AdminUIModule.indexTemplatePath = 'admin-ui/index';
AdminUIModule.editorParentTemplatePath = '/admin-ui/layouts/base';
AdminUIModule.editorTemplatePath = 'admin-ui/edit';
AdminUIModule.listParentTemplatePath = '/admin-ui/layouts/base';
AdminUIModule.listTemplatePath = 'admin-ui/list';
AdminUIModule.nestedParentTemplatePath = '/admin-ui/layouts/nested-base';
AdminUIModule.nestedTemplatePath = 'admin-ui/nested';
AdminUIModule.popupEditorParentTemplatePath = '/admin-ui/layouts/nested-base';
AdminUIModule.popupEditorTemplatePath = 'admin-ui/edit-popup';
AdminUIModule.canReadFunction = function (req, entityName) { return true; };
AdminUIModule.canWriteFunction = function (req, entityName) { return true; };
AdminUIModule.permissionDeniedHandler = function (req, res, entityName) {
res.redirect('/AdminUI/');
};
return AdminUIModule;
}(simple_module_1.default));
exports.default = AdminUIModule;