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 { PageType } = require('../../../enum')
|
||||
|
||||
/*
|
||||
* Menu Controller
|
||||
@ -26,7 +27,7 @@ class Menu extends Controller {
|
||||
noDelete: true,
|
||||
noChildren: true,
|
||||
virtual: true,
|
||||
type: 'branch',
|
||||
type: PageType.Branch,
|
||||
})
|
||||
|
||||
// Get view only shared trees
|
||||
@ -39,7 +40,7 @@ class Menu extends Controller {
|
||||
name: tree.Name,
|
||||
children: await this._build_secure_menu_object(tree, 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,
|
||||
children: await this._build_secure_menu_object(tree, 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,
|
||||
children: await this._build_secure_menu_object(tree, 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,
|
||||
noChildren: true,
|
||||
virtual: true,
|
||||
type: 'branch',
|
||||
type: PageType.Branch,
|
||||
})
|
||||
|
||||
return res.api(menu)
|
||||
@ -93,7 +94,7 @@ class Menu extends Controller {
|
||||
name: child.is_shared() ? child.Name + ' ⁽ˢʰᵃʳᵉᵈ⁾' : child.Name,
|
||||
shared: child.is_shared(),
|
||||
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,
|
||||
children: await this._build_secure_menu_object(child, 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 PageModel = require('../../../models/api/Page.model')
|
||||
const Node = require('../../../models/api/Node.model')
|
||||
const { PageType } = require('../../../enum')
|
||||
|
||||
/*
|
||||
* Page Controller
|
||||
@ -267,13 +268,21 @@ class Page extends Controller {
|
||||
}
|
||||
|
||||
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({
|
||||
Name: req.body.name,
|
||||
OrgUserId: req.user._id,
|
||||
ParentId: root_page.UUID,
|
||||
CreatedUserId: req.user.id,
|
||||
UpdateUserId: req.user.id
|
||||
UpdateUserId: req.user.id,
|
||||
PageType: page_type,
|
||||
})
|
||||
|
||||
if ( req.body.UUID ) {
|
||||
@ -327,12 +336,21 @@ class Page extends Controller {
|
||||
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({
|
||||
Name: req.body.name,
|
||||
OrgUserId: req.user._id,
|
||||
ParentId: parent.UUID,
|
||||
CreatedUserId: req.user.id,
|
||||
UpdateUserId: req.user.id,
|
||||
PageType: page_type,
|
||||
})
|
||||
|
||||
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'},
|
||||
Value: String,
|
||||
},
|
||||
AdditionalData: Object,
|
||||
PageId: String,
|
||||
CreatedAt: { type: Date, default: () => new Date },
|
||||
UpdatedAt: { type: Date, default: () => new Date },
|
||||
@ -57,6 +58,7 @@ class Node extends VersionedModel {
|
||||
update_from_raw(data) {
|
||||
if ( data.Type ) this.Type = data.Type
|
||||
if ( data.Value ) this.Value = data.Value
|
||||
if ( data.AdditionalData ) this.AdditionalData = data.AdditionalData;
|
||||
}
|
||||
|
||||
async cast_to_version_data() {
|
||||
|
@ -3,6 +3,7 @@ const { ObjectId } = require('mongodb')
|
||||
const uuid = require('uuid/v4')
|
||||
|
||||
const ActiveScope = require('../scopes/Active.scope')
|
||||
const { PageType } = require('../../enum');
|
||||
|
||||
/*
|
||||
* Page Model
|
||||
@ -31,6 +32,7 @@ class Page extends VersionedModel {
|
||||
CreatedUserId: {type: String},
|
||||
UpdateUserId: {type: String},
|
||||
ChildPageIds: [String],
|
||||
PageType: {type: String, default: PageType.Note}, // PageType
|
||||
|
||||
// Menu flags
|
||||
noDelete: { type: Boolean, default: false },
|
||||
|
@ -39,6 +39,7 @@ class ColumnDef extends VersionedModel {
|
||||
return {
|
||||
name: this.headerName,
|
||||
uuid: this.UUID,
|
||||
field: this.field,
|
||||
database_id: this.DatabaseId,
|
||||
type: this.Type,
|
||||
metadata: this.data(),
|
||||
|
Loading…
Reference in New Issue
Block a user