diff --git a/altrpnjs/app/Controllers/Http/admin/ModelsController.ts b/altrpnjs/app/Controllers/Http/admin/ModelsController.ts index 5a9bbe657..411545319 100644 --- a/altrpnjs/app/Controllers/Http/admin/ModelsController.ts +++ b/altrpnjs/app/Controllers/Http/admin/ModelsController.ts @@ -18,8 +18,6 @@ import Role from "App/Models/Role" import SourceRole from "App/Models/SourceRole" import guid from "../../../../helpers/guid" import SQLEditor from "App/Models/SQLEditor"; -import isProd from "../../../../helpers/isProd"; -import path from "path"; export default class ModelsController { async index({response, request}: HttpContextContract) { @@ -178,16 +176,10 @@ export default class ModelsController { httpContext.params[model.name] = rowId - const controllerName = path.resolve( `App/AltrpControllers/${model.name}Controller.${isProd() ? 'js' : 'ts'}`) try { - const ControllerClass = isProd() ? (await require(controllerName)).default - : (await import(controllerName)).default - - const controller = new ControllerClass() - return { - data: await controller.destroy(httpContext), + data: await Controller.callControllerMethod(id, 'destroy', httpContext), success: true } } catch (e) { @@ -202,18 +194,9 @@ export default class ModelsController { public async addModelRow(httpContext: HttpContextContract) { const id = parseInt(httpContext.params.id); - const model = await Model.query().where("id", id).firstOrFail(); - - const controllerName = path.resolve( `App/AltrpControllers/${model.name}Controller.${isProd() ? 'js' : 'ts'}`) - try { - const ControllerClass = isProd() ? (await require(controllerName)).default - : (await import(controllerName)).default - - const controller = new ControllerClass() - return { - data: await controller.add(httpContext), + data: await Controller.callControllerMethod(id, 'add', httpContext), success: true } } catch (e) { @@ -235,16 +218,10 @@ export default class ModelsController { httpContext.params[model.name] = rowId - const controllerName = path.resolve( `App/AltrpControllers/${model.name}Controller.${isProd() ? 'js' : 'ts'}`) try { - const ControllerClass = isProd() ? (await require(controllerName)).default - : (await import(controllerName)).default - - const controller = new ControllerClass() - return { - data: await controller.update(httpContext), + data: await Controller.callControllerMethod(id, 'update', httpContext), success: true } } catch (e) { @@ -369,8 +346,10 @@ export default class ModelsController { name: 'created_at', title: 'created_at', description: 'created_at', + null: true, type: 'timestamp', table_id: table.id, + model_id: model.id, // @ts-ignore user_id: auth?.user?.id, }) @@ -380,7 +359,9 @@ export default class ModelsController { name: 'updated_at', title: 'updated_at', description: 'updated_at', + null: true, type: 'timestamp', + model_id: model.id, table_id: table.id, // @ts-ignore user_id: auth?.user?.id, @@ -394,6 +375,8 @@ export default class ModelsController { title: 'deleted_at', description: 'deleted_at', type: 'timestamp', + null: true, + model_id: model.id, table_id: table.id, // @ts-ignore user_id: auth?.user?.id, diff --git a/altrpnjs/app/Generators/ControllerGenerator.ts b/altrpnjs/app/Generators/ControllerGenerator.ts index a43de5317..183108910 100644 --- a/altrpnjs/app/Generators/ControllerGenerator.ts +++ b/altrpnjs/app/Generators/ControllerGenerator.ts @@ -118,8 +118,8 @@ export default class ControllerGenerator extends BaseGenerator { private _getProdImportsContent() { return ` -const ${this.model.name} = require('../AltrpModels/${this.model.name}') -const AltrpBaseController = require('../Controllers/AltrpBaseController') +const ${this.model.name} = require('../AltrpModels/${this.model.name}').default +const AltrpBaseController = require('../Controllers/AltrpBaseController').default `; } diff --git a/altrpnjs/app/Generators/ModelGenerator.ts b/altrpnjs/app/Generators/ModelGenerator.ts index 36c2eac0a..8274b431a 100644 --- a/altrpnjs/app/Generators/ModelGenerator.ts +++ b/altrpnjs/app/Generators/ModelGenerator.ts @@ -13,7 +13,7 @@ export default class ModelGenerator extends BaseGenerator { public static directory = app_path('/AltrpModels/') public static template = app_path(`/altrp-templates/${isProd() ? 'prod' : 'dev'}/AltrpModel.stub`) - public static ext = '.ts' + public static ext = isProd() ? '.js': '.ts' private model: Model private table: Table private altrp_relationships: Relationship[] = [] @@ -141,9 +141,9 @@ ${_.uniqBy( let columns = this.columns.filter(column => column.type !== 'calculated') return ` decorate([ - (0, Orm_1.column)({ isPrimary: true }), + (0, Orm.column)({ isPrimary: true }), metadata("design:type", Number) -], Area.prototype, "id", void 0); +], ${this.model.name}.prototype, "id", void 0); ${columns.map(column => column.altrp_model ? column.renderProdForModel() : '').join('')} ` } diff --git a/altrpnjs/app/Models/Column.ts b/altrpnjs/app/Models/Column.ts index cf60f4204..5488d5f9e 100644 --- a/altrpnjs/app/Models/Column.ts +++ b/altrpnjs/app/Models/Column.ts @@ -122,7 +122,7 @@ decorate([ '{autoCreate: true, autoUpdate: true}' : ''}${ this.name === 'created_at' ? '{autoCreate: true}' : ''}), - metadata("design:type", luxon.${this.getColumnTypeForModel()}) + metadata("design:type", ${this.getColumnTypeForModel()}) ], ${this.altrp_model.name}.prototype, "${this.name}", void 0); ` } @@ -130,7 +130,7 @@ decorate([ return ` decorate([ - (0, Orm_1.column)(${this.name == 'id' ? '{isPrimary: true}' : ''}), + (0, Orm.column)(${this.name == 'id' ? '{isPrimary: true}' : ''}), metadata("design:type", ${this.getColumnTypeForModel()}) ], ${this.altrp_model.name}.prototype, "${this.name}", void 0); ` diff --git a/altrpnjs/app/Models/Controller.ts b/altrpnjs/app/Models/Controller.ts index f79b0a5b0..842cc544e 100644 --- a/altrpnjs/app/Models/Controller.ts +++ b/altrpnjs/app/Models/Controller.ts @@ -64,10 +64,12 @@ export default class Controller extends BaseModel { if(! model){ throw new NotFoundException('Model not Found', 404, NotFoundException.code); } - const controllerName = base_path(`/app/AltrpControllers/${model.name}controller`) - let controller = isProd() ? - (new (await import(controllerName)).default) - : new (require(controllerName).default) + const controllerName = base_path(`/app/AltrpControllers/${model.name}Controller`) + if(isProd()){ + require.cache = {} + } + let controller = isProd() ? new (require(controllerName).default) + : (new (await import(controllerName)).default) if( ! _.isFunction(controller[method])){ throw new NotFoundException('Model not Found', 404, NotFoundException.code); } diff --git a/altrpnjs/app/Models/Source.ts b/altrpnjs/app/Models/Source.ts index e52a78f2f..0b2c37a29 100644 --- a/altrpnjs/app/Models/Source.ts +++ b/altrpnjs/app/Models/Source.ts @@ -144,7 +144,7 @@ export default class Source extends BaseModel { renderForController(modelClassName:string):string { this.prepareContent() return ` - public async ${this.getMethodName()}(httpContext){ + async ${this.getMethodName()}(httpContext){ ${this.renderRolesCheck()} ${this.renderPermissionsCheck()} ${this.renderMethodBody(modelClassName)} diff --git a/altrpnjs/app/altrp-templates/prod/AltrpController.stub b/altrpnjs/app/altrp-templates/prod/AltrpController.stub index 0e0a8730a..bed26613f 100644 --- a/altrpnjs/app/altrp-templates/prod/AltrpController.stub +++ b/altrpnjs/app/altrp-templates/prod/AltrpController.stub @@ -1,7 +1,7 @@ -const selectForSQLEditor = require("../../helpers/selectForSQLEditor") +const selectForSQLEditor = require("../../helpers/selectForSQLEditor").default {{{imports}}} -export default class {{{classname}}} extends AltrpBaseController { +class {{{classname}}} extends AltrpBaseController { {{{properties}}} @@ -11,3 +11,4 @@ export default class {{{classname}}} extends AltrpBaseController { {{{custom}}} // CUSTOM_START } +exports.default = {{{classname}}}; diff --git a/altrpnjs/config/session.ts b/altrpnjs/config/session.ts index c859d8975..2beaf932d 100644 --- a/altrpnjs/config/session.ts +++ b/altrpnjs/config/session.ts @@ -14,7 +14,7 @@ const sessionConfig: SessionConfig = { driver: Env.get('SESSION_DRIVER', 'cookie'), cookieName: 'adonis-session', clearWithBrowser: false, - age: Env.get('SESSION_LIFETIME',7200), + age: parseInt(Env.get('SESSION_LIFETIME',7200)), cookie: { domain: '', path: '/', diff --git a/gulpfile.js b/gulpfile.js index dbc8dd3cd..6ea475872 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -106,7 +106,7 @@ function altrpJSZip() { '!./altrpnjs/build/app/AltrpControllers/**/*', '!./altrpnjs/build/public/altrp-plugins/**/*', '!./altrpnjs/build/public/app/media/**/*', - ], {dot: true,}).pipe(zip(filename, {compress: 9,})) + ], {dot: true,}).pipe(zip(filename)) .pipe(gulp.dest('../')) .pipe(notify({ message: 'Архив готов', @@ -176,6 +176,6 @@ exports.packTest = () => { // exports.packJS = ()=>{return altrpJSZip()}; exports.packJS = gulp.series(copyPublicToAdonis, altrpJSZip); -exports.altrpJSZip = () => { + exports.altrpJSZip = () => { return altrpJSZip() }; diff --git a/resources/modules/editor/src/Editor.js b/resources/modules/editor/src/Editor.js index 2287a894d..c1a1d6fe7 100644 --- a/resources/modules/editor/src/Editor.js +++ b/resources/modules/editor/src/Editor.js @@ -388,8 +388,19 @@ class Editor extends Component { ) { navigationActive = " active"; } + let list = this.clients[guid] + if(! list){ + return + } + let sockets = list.sockets + sockets = sockets.filter(_s => _s !== socket) + if(! sockets.length){ + delete this.clients[guid] + } + this.clients[guid]['sockets'] = sockets return ( +