Initial changes to support forms & form builder
This commit is contained in:
parent
7bde7576d5
commit
48fe2c7757
@ -1,4 +1,5 @@
|
|||||||
const Controller = require('libflitter/controller/Controller')
|
const Controller = require('libflitter/controller/Controller')
|
||||||
|
const { PageType } = require('../../../enum')
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Menu Controller
|
* Menu Controller
|
||||||
@ -26,7 +27,7 @@ class Menu extends Controller {
|
|||||||
noDelete: true,
|
noDelete: true,
|
||||||
noChildren: true,
|
noChildren: true,
|
||||||
virtual: true,
|
virtual: true,
|
||||||
type: 'branch',
|
type: PageType.Branch,
|
||||||
})
|
})
|
||||||
|
|
||||||
// Get view only shared trees
|
// Get view only shared trees
|
||||||
@ -39,7 +40,7 @@ class Menu extends Controller {
|
|||||||
name: tree.Name,
|
name: tree.Name,
|
||||||
children: await this._build_secure_menu_object(tree, req.user),
|
children: await this._build_secure_menu_object(tree, req.user),
|
||||||
level: await tree.access_level_for(req.user),
|
level: await tree.access_level_for(req.user),
|
||||||
type: 'page',
|
type: tree.PageType || PageType.Note,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,7 +54,7 @@ class Menu extends Controller {
|
|||||||
name: tree.Name,
|
name: tree.Name,
|
||||||
children: await this._build_secure_menu_object(tree, req.user),
|
children: await this._build_secure_menu_object(tree, req.user),
|
||||||
level: await tree.access_level_for(req.user),
|
level: await tree.access_level_for(req.user),
|
||||||
type: 'page',
|
type: tree.PageType || PageType.Note,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,7 +68,7 @@ class Menu extends Controller {
|
|||||||
name: tree.Name,
|
name: tree.Name,
|
||||||
children: await this._build_secure_menu_object(tree, req.user),
|
children: await this._build_secure_menu_object(tree, req.user),
|
||||||
level: await tree.access_level_for(req.user),
|
level: await tree.access_level_for(req.user),
|
||||||
type: 'page',
|
type: tree.PageType || PageType.Note,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,7 +79,7 @@ class Menu extends Controller {
|
|||||||
noDelete: true,
|
noDelete: true,
|
||||||
noChildren: true,
|
noChildren: true,
|
||||||
virtual: true,
|
virtual: true,
|
||||||
type: 'branch',
|
type: PageType.Branch,
|
||||||
})
|
})
|
||||||
|
|
||||||
return res.api(menu)
|
return res.api(menu)
|
||||||
@ -93,7 +94,7 @@ class Menu extends Controller {
|
|||||||
name: child.is_shared() ? child.Name + ' ⁽ˢʰᵃʳᵉᵈ⁾' : child.Name,
|
name: child.is_shared() ? child.Name + ' ⁽ˢʰᵃʳᵉᵈ⁾' : child.Name,
|
||||||
shared: child.is_shared(),
|
shared: child.is_shared(),
|
||||||
children: [...(await child.get_menu_items(page_only)), ...(await this._build_menu_object(child, [], page_only))],
|
children: [...(await child.get_menu_items(page_only)), ...(await this._build_menu_object(child, [], page_only))],
|
||||||
type: 'page',
|
type: child.PageType || PageType.Note,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -111,7 +112,7 @@ class Menu extends Controller {
|
|||||||
name: child.Name,
|
name: child.Name,
|
||||||
children: await this._build_secure_menu_object(child, user),
|
children: await this._build_secure_menu_object(child, user),
|
||||||
level: await child.access_level_for(user),
|
level: await child.access_level_for(user),
|
||||||
type: 'page',
|
type: child.PageType || PageType.Note,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
const Controller = require('libflitter/controller/Controller')
|
const Controller = require('libflitter/controller/Controller')
|
||||||
const PageModel = require('../../../models/api/Page.model')
|
const PageModel = require('../../../models/api/Page.model')
|
||||||
const Node = require('../../../models/api/Node.model')
|
const Node = require('../../../models/api/Node.model')
|
||||||
|
const { PageType } = require('../../../enum')
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Page Controller
|
* Page Controller
|
||||||
@ -267,13 +268,21 @@ class Page extends Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const root_page = await req.user.get_root_page()
|
const root_page = await req.user.get_root_page()
|
||||||
|
const page_type = req.body.pageType || PageType.Note
|
||||||
|
|
||||||
|
if ( !PageType._isValid(page_type) ) {
|
||||||
|
return res.status(400)
|
||||||
|
.message('Invalid PageType.')
|
||||||
|
.api()
|
||||||
|
}
|
||||||
|
|
||||||
const new_page = new PageModel({
|
const new_page = new PageModel({
|
||||||
Name: req.body.name,
|
Name: req.body.name,
|
||||||
OrgUserId: req.user._id,
|
OrgUserId: req.user._id,
|
||||||
ParentId: root_page.UUID,
|
ParentId: root_page.UUID,
|
||||||
CreatedUserId: req.user.id,
|
CreatedUserId: req.user.id,
|
||||||
UpdateUserId: req.user.id
|
UpdateUserId: req.user.id,
|
||||||
|
PageType: page_type,
|
||||||
})
|
})
|
||||||
|
|
||||||
if ( req.body.UUID ) {
|
if ( req.body.UUID ) {
|
||||||
@ -327,12 +336,21 @@ class Page extends Controller {
|
|||||||
return res.security.deny()
|
return res.security.deny()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const page_type = req.body.pageType || PageType.Note
|
||||||
|
|
||||||
|
if ( !PageType._isValid(page_type) ) {
|
||||||
|
return res.status(400)
|
||||||
|
.message('Invalid PageType.')
|
||||||
|
.api()
|
||||||
|
}
|
||||||
|
|
||||||
const new_page = new PageModel({
|
const new_page = new PageModel({
|
||||||
Name: req.body.name,
|
Name: req.body.name,
|
||||||
OrgUserId: req.user._id,
|
OrgUserId: req.user._id,
|
||||||
ParentId: parent.UUID,
|
ParentId: parent.UUID,
|
||||||
CreatedUserId: req.user.id,
|
CreatedUserId: req.user.id,
|
||||||
UpdateUserId: req.user.id,
|
UpdateUserId: req.user.id,
|
||||||
|
PageType: page_type,
|
||||||
})
|
})
|
||||||
|
|
||||||
if ( req.body.UUID ) {
|
if ( req.body.UUID ) {
|
||||||
|
11
app/enum.js
Normal file
11
app/enum.js
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
module.exports = {
|
||||||
|
PageType: {
|
||||||
|
Note: 'page',
|
||||||
|
Form: 'form',
|
||||||
|
Branch: 'branch',
|
||||||
|
|
||||||
|
_isValid(value) {
|
||||||
|
return ['page', 'form', 'branch'].includes(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -21,6 +21,7 @@ class Node extends VersionedModel {
|
|||||||
Mode: {type: String, default: 'norm'},
|
Mode: {type: String, default: 'norm'},
|
||||||
Value: String,
|
Value: String,
|
||||||
},
|
},
|
||||||
|
AdditionalData: Object,
|
||||||
PageId: String,
|
PageId: String,
|
||||||
CreatedAt: { type: Date, default: () => new Date },
|
CreatedAt: { type: Date, default: () => new Date },
|
||||||
UpdatedAt: { type: Date, default: () => new Date },
|
UpdatedAt: { type: Date, default: () => new Date },
|
||||||
@ -57,6 +58,7 @@ class Node extends VersionedModel {
|
|||||||
update_from_raw(data) {
|
update_from_raw(data) {
|
||||||
if ( data.Type ) this.Type = data.Type
|
if ( data.Type ) this.Type = data.Type
|
||||||
if ( data.Value ) this.Value = data.Value
|
if ( data.Value ) this.Value = data.Value
|
||||||
|
if ( data.AdditionalData ) this.AdditionalData = data.AdditionalData;
|
||||||
}
|
}
|
||||||
|
|
||||||
async cast_to_version_data() {
|
async cast_to_version_data() {
|
||||||
|
@ -3,6 +3,7 @@ const { ObjectId } = require('mongodb')
|
|||||||
const uuid = require('uuid/v4')
|
const uuid = require('uuid/v4')
|
||||||
|
|
||||||
const ActiveScope = require('../scopes/Active.scope')
|
const ActiveScope = require('../scopes/Active.scope')
|
||||||
|
const { PageType } = require('../../enum');
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Page Model
|
* Page Model
|
||||||
@ -31,6 +32,7 @@ class Page extends VersionedModel {
|
|||||||
CreatedUserId: {type: String},
|
CreatedUserId: {type: String},
|
||||||
UpdateUserId: {type: String},
|
UpdateUserId: {type: String},
|
||||||
ChildPageIds: [String],
|
ChildPageIds: [String],
|
||||||
|
PageType: {type: String, default: PageType.Note}, // PageType
|
||||||
|
|
||||||
// Menu flags
|
// Menu flags
|
||||||
noDelete: { type: Boolean, default: false },
|
noDelete: { type: Boolean, default: false },
|
||||||
|
@ -39,6 +39,7 @@ class ColumnDef extends VersionedModel {
|
|||||||
return {
|
return {
|
||||||
name: this.headerName,
|
name: this.headerName,
|
||||||
uuid: this.UUID,
|
uuid: this.UUID,
|
||||||
|
field: this.field,
|
||||||
database_id: this.DatabaseId,
|
database_id: this.DatabaseId,
|
||||||
type: this.Type,
|
type: this.Type,
|
||||||
metadata: this.data(),
|
metadata: this.data(),
|
||||||
|
Loading…
Reference in New Issue
Block a user