mirror of
https://github.com/documize/community.git
synced 2025-08-04 21:15:24 +02:00
[WIP] PDF viewer section & per section attachments
This commit is contained in:
parent
c0ed3c3d04
commit
166aeba09b
428 changed files with 45874 additions and 802 deletions
|
@ -217,7 +217,6 @@ func (h *Handler) Get(w http.ResponseWriter, r *http.Request) {
|
|||
response.WriteServerError(w, method, err)
|
||||
return
|
||||
}
|
||||
|
||||
if len(a) == 0 {
|
||||
a = []attachment.Attachment{}
|
||||
}
|
||||
|
@ -299,6 +298,9 @@ func (h *Handler) Add(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
// File can be associated with a section as well.
|
||||
sectionID := request.Query(r, "page")
|
||||
|
||||
if !permission.CanChangeDocument(ctx, *h.Store, documentID) {
|
||||
response.WriteForbiddenError(w)
|
||||
return
|
||||
|
@ -336,6 +338,7 @@ func (h *Handler) Add(w http.ResponseWriter, r *http.Request) {
|
|||
a.FileID = random[0:9]
|
||||
a.Filename = filename.Filename
|
||||
a.Data = b.Bytes()
|
||||
a.SectionID = sectionID
|
||||
|
||||
ctx.Transaction, err = h.Runtime.Db.Beginx()
|
||||
if err != nil {
|
||||
|
|
|
@ -36,8 +36,8 @@ func (s Store) Add(ctx domain.RequestContext, a attachment.Attachment) (err erro
|
|||
bits := strings.Split(a.Filename, ".")
|
||||
a.Extension = bits[len(bits)-1]
|
||||
|
||||
_, err = ctx.Transaction.Exec(s.Bind("INSERT INTO dmz_doc_attachment (c_refid, c_orgid, c_docid, c_job, c_fileid, c_filename, c_data, c_extension, c_created, c_revised) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"),
|
||||
a.RefID, a.OrgID, a.DocumentID, a.Job, a.FileID, a.Filename, a.Data, a.Extension, a.Created, a.Revised)
|
||||
_, err = ctx.Transaction.Exec(s.Bind("INSERT INTO dmz_doc_attachment (c_refid, c_orgid, c_docid, c_sectionid, c_job, c_fileid, c_filename, c_data, c_extension, c_created, c_revised) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"),
|
||||
a.RefID, a.OrgID, a.DocumentID, a.SectionID, a.Job, a.FileID, a.Filename, a.Data, a.Extension, a.Created, a.Revised)
|
||||
|
||||
if err != nil {
|
||||
err = errors.Wrap(err, "execute insert attachment")
|
||||
|
@ -50,7 +50,7 @@ func (s Store) Add(ctx domain.RequestContext, a attachment.Attachment) (err erro
|
|||
func (s Store) GetAttachment(ctx domain.RequestContext, orgID, attachmentID string) (a attachment.Attachment, err error) {
|
||||
err = s.Runtime.Db.Get(&a, s.Bind(`
|
||||
SELECT id, c_refid AS refid,
|
||||
c_orgid AS orgid, c_docid AS documentid, c_job AS job, c_fileid AS fileid,
|
||||
c_orgid AS orgid, c_docid AS documentid, c_sectionid AS sectionid, c_job AS job, c_fileid AS fileid,
|
||||
c_filename AS filename, c_data AS data, c_extension AS extension,
|
||||
c_created AS created, c_revised AS revised
|
||||
FROM dmz_doc_attachment
|
||||
|
@ -68,7 +68,7 @@ func (s Store) GetAttachment(ctx domain.RequestContext, orgID, attachmentID stri
|
|||
func (s Store) GetAttachments(ctx domain.RequestContext, docID string) (a []attachment.Attachment, err error) {
|
||||
err = s.Runtime.Db.Select(&a, s.Bind(`
|
||||
SELECT id, c_refid AS refid,
|
||||
c_orgid AS orgid, c_docid AS documentid, c_job AS job, c_fileid AS fileid,
|
||||
c_orgid AS orgid, c_docid AS documentid, c_sectionid AS sectionid, c_job AS job, c_fileid AS fileid,
|
||||
c_filename AS filename, c_extension AS extension,
|
||||
c_created AS created, c_revised AS revised
|
||||
FROM dmz_doc_attachment
|
||||
|
@ -92,7 +92,7 @@ func (s Store) GetAttachments(ctx domain.RequestContext, docID string) (a []atta
|
|||
func (s Store) GetAttachmentsWithData(ctx domain.RequestContext, docID string) (a []attachment.Attachment, err error) {
|
||||
err = s.Runtime.Db.Select(&a, s.Bind(`
|
||||
SELECT id, c_refid AS refid,
|
||||
c_orgid AS orgid, c_docid AS documentid, c_job AS job, c_fileid AS fileid,
|
||||
c_orgid AS orgid, c_docid AS documentid, c_sectionid AS sectionid, c_job AS job, c_fileid AS fileid,
|
||||
c_filename AS filename, c_data AS data, c_extension AS extension,
|
||||
c_created AS created, c_revised AS revised
|
||||
FROM dmz_doc_attachment
|
||||
|
|
|
@ -30,6 +30,7 @@ import (
|
|||
indexer "github.com/documize/community/domain/search"
|
||||
"github.com/documize/community/domain/store"
|
||||
"github.com/documize/community/model/activity"
|
||||
"github.com/documize/community/model/attachment"
|
||||
"github.com/documize/community/model/audit"
|
||||
"github.com/documize/community/model/doc"
|
||||
"github.com/documize/community/model/link"
|
||||
|
@ -661,6 +662,14 @@ func (h *Handler) FetchDocumentData(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
}
|
||||
|
||||
// Attachments.
|
||||
a, err := h.Store.Attachment.GetAttachments(ctx, id)
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
h.Runtime.Log.Error("get attachment", err)
|
||||
response.WriteServerError(w, method, err)
|
||||
return
|
||||
}
|
||||
|
||||
// Prepare response.
|
||||
data := BulkDocumentData{}
|
||||
data.Document = document
|
||||
|
@ -669,6 +678,7 @@ func (h *Handler) FetchDocumentData(w http.ResponseWriter, r *http.Request) {
|
|||
data.Links = l
|
||||
data.Spaces = sp
|
||||
data.Versions = v
|
||||
data.Attachments = a
|
||||
|
||||
ctx.Transaction, err = h.Runtime.Db.Beginx()
|
||||
if err != nil {
|
||||
|
@ -700,12 +710,13 @@ func (h *Handler) FetchDocumentData(w http.ResponseWriter, r *http.Request) {
|
|||
// BulkDocumentData represents all data associated for a single document.
|
||||
// Used by FetchDocumentData() bulk data load call.
|
||||
type BulkDocumentData struct {
|
||||
Document doc.Document `json:"document"`
|
||||
Permissions pm.Record `json:"permissions"`
|
||||
Roles pm.DocumentRecord `json:"roles"`
|
||||
Spaces []space.Space `json:"folders"`
|
||||
Links []link.Link `json:"links"`
|
||||
Versions []doc.Version `json:"versions"`
|
||||
Document doc.Document `json:"document"`
|
||||
Permissions pm.Record `json:"permissions"`
|
||||
Roles pm.DocumentRecord `json:"roles"`
|
||||
Spaces []space.Space `json:"folders"`
|
||||
Links []link.Link `json:"links"`
|
||||
Versions []doc.Version `json:"versions"`
|
||||
Attachments []attachment.Attachment `json:"attachments"`
|
||||
}
|
||||
|
||||
// Export returns content as self-enclosed HTML file.
|
||||
|
|
55
domain/section/pdfjs/pdfjs.go
Normal file
55
domain/section/pdfjs/pdfjs.go
Normal file
|
@ -0,0 +1,55 @@
|
|||
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
|
||||
//
|
||||
// This software (Documize Community Edition) is licensed under
|
||||
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
|
||||
//
|
||||
// You can operate outside the AGPL restrictions by purchasing
|
||||
// Documize Enterprise Edition and obtaining a commercial license
|
||||
// by contacting <sales@documize.com>.
|
||||
//
|
||||
// https://documize.com
|
||||
|
||||
package pdfjs
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/documize/community/core/env"
|
||||
"github.com/documize/community/domain/section/provider"
|
||||
"github.com/documize/community/domain/store"
|
||||
)
|
||||
|
||||
// Provider represents PDF viewer
|
||||
type Provider struct {
|
||||
Runtime *env.Runtime
|
||||
Store *store.Store
|
||||
}
|
||||
|
||||
// Meta describes us.
|
||||
func (*Provider) Meta() provider.TypeMeta {
|
||||
section := provider.TypeMeta{}
|
||||
|
||||
section.ID = "d54b0b89-6a91-460b-885d-95518b3dfdca"
|
||||
section.Title = "PDF Viewer"
|
||||
section.Description = "View PDF file"
|
||||
section.ContentType = "pdf"
|
||||
section.PageType = "section"
|
||||
section.Order = 9995
|
||||
|
||||
return section
|
||||
}
|
||||
|
||||
// Command stub.
|
||||
func (*Provider) Command(ctx *provider.Context, w http.ResponseWriter, r *http.Request) {
|
||||
provider.WriteEmpty(w)
|
||||
}
|
||||
|
||||
// Render just sends back HMTL as-is.
|
||||
func (*Provider) Render(ctx *provider.Context, config, data string) string {
|
||||
return data
|
||||
}
|
||||
|
||||
// Refresh just sends back data as-is.
|
||||
func (*Provider) Refresh(ctx *provider.Context, config, data string) string {
|
||||
return data
|
||||
}
|
|
@ -22,6 +22,7 @@ import (
|
|||
"github.com/documize/community/domain/section/jira"
|
||||
"github.com/documize/community/domain/section/markdown"
|
||||
"github.com/documize/community/domain/section/papertrail"
|
||||
"github.com/documize/community/domain/section/pdfjs"
|
||||
"github.com/documize/community/domain/section/plantuml"
|
||||
"github.com/documize/community/domain/section/provider"
|
||||
"github.com/documize/community/domain/section/table"
|
||||
|
@ -46,6 +47,7 @@ func Register(rt *env.Runtime, s *store.Store) {
|
|||
provider.Register("airtable", &airtable.Provider{Runtime: rt, Store: s})
|
||||
provider.Register("plantuml", &plantuml.Provider{Runtime: rt, Store: s})
|
||||
provider.Register("flowchart", &flowchart.Provider{Runtime: rt, Store: s})
|
||||
provider.Register("pdf", &pdfjs.Provider{Runtime: rt, Store: s})
|
||||
|
||||
p := provider.List()
|
||||
rt.Log.Info(fmt.Sprintf("Extensions: registered %d section types", len(p)))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue