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

Templates document carry forward categories

This commit is contained in:
Harvey Kandola 2018-07-18 17:57:17 -04:00
parent f884926df7
commit 743eae5aad
2 changed files with 47 additions and 1 deletions

View file

@ -424,7 +424,6 @@ func (h *Handler) GetDocumentCategoryMembership(w http.ResponseWriter, r *http.R
response.WriteServerError(w, method, err)
return
}
if len(cat) == 0 {
cat = []category.Category{}
}

View file

@ -15,6 +15,7 @@ import (
"database/sql"
"encoding/json"
"fmt"
"github.com/documize/community/model/category"
"io/ioutil"
"net/http"
@ -197,6 +198,7 @@ func (h *Handler) SaveAs(w http.ResponseWriter, r *http.Request) {
return
}
// Clone attachments.
for _, a := range attachments {
err = h.Store.Attachment.Add(ctx, a)
@ -208,6 +210,7 @@ func (h *Handler) SaveAs(w http.ResponseWriter, r *http.Request) {
}
}
// Clone sections.
for _, m := range pageModel {
err = h.Store.Page.Add(ctx, m)
@ -219,6 +222,28 @@ func (h *Handler) SaveAs(w http.ResponseWriter, r *http.Request) {
}
}
// Clone categories.
cats, err := h.Store.Category.GetDocumentCategoryMembership(ctx, model.DocumentID)
if err != nil && err != sql.ErrNoRows {
response.WriteServerError(w, method, err)
h.Runtime.Log.Error(method, err)
return
}
for _, c := range cats {
var cc category.Member
cc.OrgID = c.OrgID
cc.CategoryID = c.RefID
cc.RefID = uniqueid.Generate()
cc.DocumentID = docID
cc.LabelID = doc.LabelID
err = h.Store.Category.AssociateDocument(ctx, cc)
if err != nil && err != sql.ErrNoRows {
response.WriteServerError(w, method, err)
h.Runtime.Log.Error(method, err)
return
}
}
// Commit and return new document template
ctx.Transaction.Commit()
@ -380,6 +405,28 @@ func (h *Handler) Use(w http.ResponseWriter, r *http.Request) {
}
}
// Clone categories.
cats, err := h.Store.Category.GetDocumentCategoryMembership(ctx, templateID)
if err != nil && err != sql.ErrNoRows {
response.WriteServerError(w, method, err)
h.Runtime.Log.Error(method, err)
return
}
for _, c := range cats {
var cc category.Member
cc.OrgID = c.OrgID
cc.CategoryID = c.RefID
cc.RefID = uniqueid.Generate()
cc.DocumentID = d.RefID
cc.LabelID = d.LabelID
err = h.Store.Category.AssociateDocument(ctx, cc)
if err != nil && err != sql.ErrNoRows {
response.WriteServerError(w, method, err)
h.Runtime.Log.Error(method, err)
return
}
}
ctx.Transaction.Commit()
h.Store.Audit.Record(ctx, audit.EventTypeTemplateUse)