2020-02-08 09:54:48 +00:00
|
|
|
const Model = require("flitter-orm/src/model/Model");
|
2020-02-08 12:57:38 +00:00
|
|
|
const uuid = require('uuid/v4');
|
2020-02-08 09:54:48 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Node Model
|
|
|
|
* -------------------------------------------------------------
|
|
|
|
* Put some description here!
|
|
|
|
*/
|
|
|
|
class Node extends Model {
|
2020-03-01 21:37:52 +00:00
|
|
|
static get services() {
|
|
|
|
return [...super.services, 'models']
|
|
|
|
}
|
|
|
|
|
2020-02-08 09:54:48 +00:00
|
|
|
static get schema() {
|
|
|
|
// Return a flitter-orm schema here.
|
|
|
|
return {
|
2020-02-08 12:57:38 +00:00
|
|
|
UUID: { type: String, default: () => uuid() },
|
2020-02-08 09:54:48 +00:00
|
|
|
Type: String,
|
2020-02-08 12:57:38 +00:00
|
|
|
Value: {
|
|
|
|
Mode: {type: String, default: 'norm'},
|
|
|
|
Value: String,
|
|
|
|
},
|
|
|
|
PageId: String,
|
|
|
|
CreatedAt: { type: Date, default: () => new Date },
|
|
|
|
UpdatedAt: { type: Date, default: () => new Date },
|
|
|
|
CreatedUserId: String,
|
|
|
|
UpdateUserId: String
|
2020-02-08 09:54:48 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
// Static and instance methods can go here
|
|
|
|
get page() {
|
2020-03-01 21:37:52 +00:00
|
|
|
const Page = this.models.get('api:Page')
|
2020-10-13 02:46:50 +00:00
|
|
|
return this.belongs_to_one(Page, "PageId", "UUID")
|
2020-02-08 09:54:48 +00:00
|
|
|
}
|
2020-02-08 17:16:04 +00:00
|
|
|
|
2020-02-08 18:47:03 +00:00
|
|
|
to_html() {
|
|
|
|
switch(this.Type){
|
|
|
|
case 'paragraph':
|
|
|
|
return '<p>' + this.Value.Value + '</p>'
|
|
|
|
case 'header1':
|
|
|
|
return '<h1>' + this.Value.Value + '</h1>'
|
|
|
|
case 'header2':
|
|
|
|
return '<h2>' + this.Value.Value + '</h2>'
|
|
|
|
case 'header3':
|
|
|
|
return '<h3>' + this.Value.Value + '</h3>'
|
|
|
|
case 'header4':
|
|
|
|
return '<h4>' + this.Value.Value + '</h4>'
|
|
|
|
case 'block_code':
|
|
|
|
return '<pre><code>' + this.Value.Value + '</code></pre>'
|
|
|
|
case 'click_link':
|
|
|
|
return '<a href="' + this.Value.Value + '">' + this.Value.Value + '</a>'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-08 17:16:04 +00:00
|
|
|
update_from_raw(data) {
|
|
|
|
if ( data.Type ) this.Type = data.Type
|
|
|
|
if ( data.Value ) this.Value = data.Value
|
|
|
|
}
|
2020-02-08 09:54:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = exports = Node;
|