1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-07-19 13:19:43 +02:00

document tab basics

This commit is contained in:
Harvey Kandola 2016-11-09 15:16:44 -08:00
parent 5c09407d2f
commit 8caa53bed7
49 changed files with 493 additions and 239 deletions

View file

@ -182,6 +182,7 @@ type Page struct {
DocumentID string `json:"documentId"`
UserID string `json:"userId"`
ContentType string `json:"contentType"`
PageType string `json:"pageType"`
Level uint64 `json:"level"`
Sequence float64 `json:"sequence"`
Title string `json:"title"`
@ -193,6 +194,7 @@ type Page struct {
func (p *Page) SetDefaults() {
if len(p.ContentType) == 0 {
p.ContentType = "wysiwyg"
p.PageType = "section"
}
p.Title = strings.TrimSpace(p.Title)

View file

@ -50,7 +50,7 @@ func (p *Persister) AddPage(model models.PageModel) (err error) {
model.Page.Sequence = maxSeq * 2
}
stmt, err := p.Context.Transaction.Preparex("INSERT INTO page (refid, orgid, documentid, userid, contenttype, level, title, body, revisions, sequence, created, revised) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")
stmt, err := p.Context.Transaction.Preparex("INSERT INTO page (refid, orgid, documentid, userid, contenttype, pagetype, level, title, body, revisions, sequence, created, revised) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")
defer utility.Close(stmt)
if err != nil {
@ -58,7 +58,7 @@ func (p *Persister) AddPage(model models.PageModel) (err error) {
return
}
_, err = stmt.Exec(model.Page.RefID, model.Page.OrgID, model.Page.DocumentID, model.Page.UserID, model.Page.ContentType, model.Page.Level, model.Page.Title, model.Page.Body, model.Page.Revisions, model.Page.Sequence, model.Page.Created, model.Page.Revised)
_, err = stmt.Exec(model.Page.RefID, model.Page.OrgID, model.Page.DocumentID, model.Page.UserID, model.Page.ContentType, model.Page.PageType, model.Page.Level, model.Page.Title, model.Page.Body, model.Page.Revisions, model.Page.Sequence, model.Page.Created, model.Page.Revised)
if err != nil {
log.Error("Unable to execute insert for page", err)
@ -91,7 +91,7 @@ func (p *Persister) AddPage(model models.PageModel) (err error) {
func (p *Persister) GetPage(pageID string) (page entity.Page, err error) {
err = nil
stmt, err := Db.Preparex("SELECT a.id, a.refid, a.orgid, a.documentid, a.userid, a.contenttype, a.level, a.sequence, a.title, a.body, a.revisions, a.created, a.revised FROM page a WHERE a.orgid=? AND a.refid=?")
stmt, err := Db.Preparex("SELECT a.id, a.refid, a.orgid, a.documentid, a.userid, a.contenttype, a.pagetype, a.level, a.sequence, a.title, a.body, a.revisions, a.created, a.revised FROM page a WHERE a.orgid=? AND a.refid=?")
defer utility.Close(stmt)
if err != nil {
@ -113,7 +113,7 @@ func (p *Persister) GetPage(pageID string) (page entity.Page, err error) {
func (p *Persister) GetPages(documentID string) (pages []entity.Page, err error) {
err = nil
err = Db.Select(&pages, "SELECT a.id, a.refid, a.orgid, a.documentid, a.userid, a.contenttype, a.level, a.sequence, a.title, a.body, a.revisions, a.created, a.revised FROM page a WHERE a.orgid=? AND a.documentid=? ORDER BY a.sequence", p.Context.OrgID, documentID)
err = Db.Select(&pages, "SELECT a.id, a.refid, a.orgid, a.documentid, a.userid, a.contenttype, a.pagetype, a.level, a.sequence, a.title, a.body, a.revisions, a.created, a.revised FROM page a WHERE a.orgid=? AND a.documentid=? ORDER BY a.sequence", p.Context.OrgID, documentID)
if err != nil {
log.Error(fmt.Sprintf("Unable to execute select pages for org %s and document %s", p.Context.OrgID, documentID), err)
@ -130,7 +130,7 @@ func (p *Persister) GetPagesWhereIn(documentID, inPages string) (pages []entity.
args := []interface{}{p.Context.OrgID, documentID}
tempValues := strings.Split(inPages, ",")
sql := "SELECT a.id, a.refid, a.orgid, a.documentid, a.userid, a.contenttype, a.level, a.sequence, a.title, a.body, a.revisions, a.created, a.revised FROM page a WHERE a.orgid=? AND a.documentid=? AND a.refid IN (?" + strings.Repeat(",?", len(tempValues)-1) + ") ORDER BY sequence"
sql := "SELECT a.id, a.refid, a.orgid, a.documentid, a.userid, a.contenttype, a.pagetype, a.level, a.sequence, a.title, a.body, a.revisions, a.created, a.revised FROM page a WHERE a.orgid=? AND a.documentid=? AND a.refid IN (?" + strings.Repeat(",?", len(tempValues)-1) + ") ORDER BY sequence"
inValues := make([]interface{}, len(tempValues))
@ -180,7 +180,7 @@ func (p *Persister) GetPagesWhereIn(documentID, inPages string) (pages []entity.
// GetPagesWithoutContent returns a slice containing all the page records for a given documentID, in presentation sequence,
// but without the body field (which holds the HTML content).
func (p *Persister) GetPagesWithoutContent(documentID string) (pages []entity.Page, err error) {
err = Db.Select(&pages, "SELECT id, refid, orgid, documentid, userid, contenttype, sequence, level, title, revisions, created, revised FROM page WHERE orgid=? AND documentid=? ORDER BY sequence", p.Context.OrgID, documentID)
err = Db.Select(&pages, "SELECT id, refid, orgid, documentid, userid, contenttype, pagetype, sequence, level, title, revisions, created, revised FROM page WHERE orgid=? AND documentid=? ORDER BY sequence", p.Context.OrgID, documentID)
if err != nil {
log.Error(fmt.Sprintf("Unable to execute select pages for org %s and document %s", p.Context.OrgID, documentID), err)
@ -199,7 +199,7 @@ func (p *Persister) UpdatePage(page entity.Page, refID, userID string, skipRevis
// Store revision history
if !skipRevision {
var stmt *sqlx.Stmt
stmt, err = p.Context.Transaction.Preparex("INSERT INTO revision (refid, orgid, documentid, ownerid, pageid, userid, contenttype, title, body, rawbody, config, created, revised) SELECT ? as refid, a.orgid, a.documentid, a.userid as ownerid, a.refid as pageid, ? as userid, a.contenttype, a.title, a.body, b.rawbody, b.config, ? as created, ? as revised FROM page a, pagemeta b WHERE a.refid=? AND a.refid=b.pageid")
stmt, err = p.Context.Transaction.Preparex("INSERT INTO revision (refid, orgid, documentid, ownerid, pageid, userid, contenttype, pagetype, title, body, rawbody, config, created, revised) SELECT ? as refid, a.orgid, a.documentid, a.userid as ownerid, a.refid as pageid, ? as userid, a.contenttype, a.pagetype, a.title, a.body, b.rawbody, b.config, ? as created, ? as revised FROM page a, pagemeta b WHERE a.refid=? AND a.refid=b.pageid")
defer utility.Close(stmt)

View file

@ -149,6 +149,7 @@ CREATE TABLE IF NOT EXISTS `page` (
`documentid` CHAR(16) NOT NULL COLLATE utf8_bin,
`userid` CHAR(16) DEFAULT '' COLLATE utf8_bin,
`contenttype` CHAR(20) NOT NULL DEFAULT 'wysiwyg',
`pagetype` CHAR(10) NOT NULL DEFAULT 'section',
`level` INT UNSIGNED NOT NULL,
`sequence` DOUBLE NOT NULL,
`title` NVARCHAR(2000) NOT NULL,
@ -239,6 +240,7 @@ CREATE TABLE IF NOT EXISTS `revision` (
`pageid` CHAR(16) NOT NULL COLLATE utf8_bin,
`userid` CHAR(16) NOT NULL COLLATE utf8_bin,
`contenttype` CHAR(20) NOT NULL DEFAULT 'wysiwyg',
`pagetype` CHAR(10) NOT NULL DEFAULT 'section',
`title` NVARCHAR(2000) NOT NULL,
`body` LONGTEXT,
`rawbody` LONGBLOB,

View file

@ -0,0 +1,6 @@
/* community edition */
ALTER TABLE page ADD COLUMN `pagetype` CHAR(10) NOT NULL DEFAULT 'section' AFTER `contenttype`;
UPDATE page SET pagetype='tab' WHERE refid IN (SELECT pageid FROM pagemeta WHERE externalsource=1);
ALTER TABLE revision ADD COLUMN `pagetype` CHAR(10) NOT NULL DEFAULT 'section' AFTER `contenttype`;
UPDATE revision SET pagetype='tab' WHERE pageid IN (SELECT pageid FROM pagemeta WHERE externalsource=1);

View file

@ -29,6 +29,7 @@ func (*Provider) Meta() provider.TypeMeta {
section.Title = "Airtable"
section.Description = "Databases, tables, views"
section.ContentType = "airtable"
section.PageType = "tab"
return section
}

View file

@ -29,6 +29,7 @@ func (*Provider) Meta() provider.TypeMeta {
section.Title = "Code"
section.Description = "Formatted code snippets"
section.ContentType = "code"
section.PageType = "section"
section.Order = 9997
return section

View file

@ -35,6 +35,7 @@ func (*Provider) Meta() provider.TypeMeta {
section.Title = "Gemini"
section.Description = "Work items and tickets"
section.ContentType = "gemini"
section.PageType = "tab"
return section
}

View file

@ -39,6 +39,7 @@ func init() {
meta.Title = "GitHub"
meta.Description = "Link code commits and issues"
meta.ContentType = "github"
meta.PageType = "tab"
meta.Callback = Callback
}

View file

@ -30,6 +30,7 @@ func (*Provider) Meta() provider.TypeMeta {
section.Title = "Markdown"
section.Description = "CommonMark based content"
section.ContentType = "markdown"
section.PageType = "section"
section.Order = 9998
return section

View file

@ -38,6 +38,7 @@ func (*Provider) Meta() provider.TypeMeta {
section.Title = "Papertrail"
section.Description = "Display log entries"
section.ContentType = "papertrail"
section.PageType = "tab"
return section
}

View file

@ -35,6 +35,7 @@ type TypeMeta struct {
ID string `json:"id"`
Order int `json:"order"`
ContentType string `json:"contentType"`
PageType string `json:"pageType"`
Title string `json:"title"`
Description string `json:"description"`
Preview bool `json:"preview"` // coming soon!

View file

@ -39,5 +39,5 @@ func Register() {
provider.Register("wysiwyg", &wysiwyg.Provider{})
provider.Register("airtable", &airtable.Provider{})
p := provider.List()
log.Info(fmt.Sprintf("Documize registered %d smart sections", len(p)))
log.Info(fmt.Sprintf("Documize registered %d sections and tabs", len(p)))
}

View file

@ -29,6 +29,7 @@ func (*Provider) Meta() provider.TypeMeta {
section.Title = "Tabular"
section.Description = "Rows, columns for tabular data"
section.ContentType = "table"
section.PageType = "section"
section.Order = 9996
return section

View file

@ -36,6 +36,7 @@ func init() {
meta.Title = "Trello"
meta.Description = "Embed cards from boards and lists"
meta.ContentType = "trello"
meta.PageType = "tab"
}
// Provider represents Trello

View file

@ -29,6 +29,7 @@ func (*Provider) Meta() provider.TypeMeta {
section.Title = "Rich Text"
section.Description = "Rich text WYSIWYG"
section.ContentType = "wysiwyg"
section.PageType = "section"
section.Order = 9999
return section