Skip to content

Commit

Permalink
fix models
Browse files Browse the repository at this point in the history
  • Loading branch information
talp-525 committed Feb 18, 2022
1 parent d8cae1c commit 1648e37
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 43 deletions.
35 changes: 9 additions & 26 deletions altrpnjs/app/Controllers/Http/admin/ModelsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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,
})
Expand All @@ -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,
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions altrpnjs/app/Generators/ControllerGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
`;
}

Expand Down
6 changes: 3 additions & 3 deletions altrpnjs/app/Generators/ModelGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = []
Expand Down Expand Up @@ -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('')}
`
}
Expand Down
4 changes: 2 additions & 2 deletions altrpnjs/app/Models/Column.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,15 @@ 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);
`
}

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);
`
Expand Down
10 changes: 6 additions & 4 deletions altrpnjs/app/Models/Controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion altrpnjs/app/Models/Source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)}
Expand Down
5 changes: 3 additions & 2 deletions altrpnjs/app/altrp-templates/prod/AltrpController.stub
Original file line number Diff line number Diff line change
@@ -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}}}

Expand All @@ -11,3 +11,4 @@ export default class {{{classname}}} extends AltrpBaseController {
{{{custom}}}
// CUSTOM_START
}
exports.default = {{{classname}}};
2 changes: 1 addition & 1 deletion altrpnjs/config/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: '/',
Expand Down
4 changes: 2 additions & 2 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: 'Архив готов',
Expand Down Expand Up @@ -176,6 +176,6 @@ exports.packTest = () => {

// exports.packJS = ()=>{return altrpJSZip()};
exports.packJS = gulp.series(copyPublicToAdonis, altrpJSZip);
exports.altrpJSZip = () => {
exports.altrpJSZip = () => {
return altrpJSZip()
};
11 changes: 11 additions & 0 deletions resources/modules/editor/src/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<DndProvider backend={HTML5Backend}>

<div
className={templateClasses}
onClick={this.onClick}
Expand Down

0 comments on commit 1648e37

Please sign in to comment.