mirror of
https://github.com/documize/community.git
synced 2025-07-24 15:49:44 +02:00
reusable content block editing completed
This commit is contained in:
parent
bbc2237ef7
commit
2493a09ba9
15 changed files with 307 additions and 23 deletions
|
@ -308,14 +308,6 @@ func DeleteDocumentPage(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
p.Context.Transaction = tx
|
||||
|
||||
_, err = p.DeletePage(documentID, pageID)
|
||||
|
||||
if err != nil {
|
||||
log.IfErr(tx.Rollback())
|
||||
writeGeneralSQLError(w, method, err)
|
||||
return
|
||||
}
|
||||
|
||||
page, err := p.GetPage(pageID)
|
||||
if err != nil {
|
||||
log.IfErr(tx.Rollback())
|
||||
|
@ -327,6 +319,14 @@ func DeleteDocumentPage(w http.ResponseWriter, r *http.Request) {
|
|||
p.DecrementBlockUsage(page.BlockID)
|
||||
}
|
||||
|
||||
_, err = p.DeletePage(documentID, pageID)
|
||||
|
||||
if err != nil {
|
||||
log.IfErr(tx.Rollback())
|
||||
writeGeneralSQLError(w, method, err)
|
||||
return
|
||||
}
|
||||
|
||||
log.IfErr(tx.Commit())
|
||||
|
||||
writeSuccessEmptyJSON(w)
|
||||
|
@ -376,13 +376,6 @@ func DeleteDocumentPages(w http.ResponseWriter, r *http.Request) {
|
|||
p.Context.Transaction = tx
|
||||
|
||||
for _, page := range *model {
|
||||
_, err = p.DeletePage(documentID, page.PageID)
|
||||
if err != nil {
|
||||
log.IfErr(tx.Rollback())
|
||||
writeGeneralSQLError(w, method, err)
|
||||
return
|
||||
}
|
||||
|
||||
pageData, err := p.GetPage(page.PageID)
|
||||
if err != nil {
|
||||
log.IfErr(tx.Rollback())
|
||||
|
@ -393,6 +386,13 @@ func DeleteDocumentPages(w http.ResponseWriter, r *http.Request) {
|
|||
if len(pageData.BlockID) > 0 {
|
||||
p.DecrementBlockUsage(pageData.BlockID)
|
||||
}
|
||||
|
||||
_, err = p.DeletePage(documentID, page.PageID)
|
||||
if err != nil {
|
||||
log.IfErr(tx.Rollback())
|
||||
writeGeneralSQLError(w, method, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
log.IfErr(tx.Commit())
|
||||
|
|
|
@ -216,7 +216,9 @@ func init() {
|
|||
log.IfErr(Add(RoutePrefixPrivate, "sections", []string{"GET", "OPTIONS"}, nil, GetSections))
|
||||
log.IfErr(Add(RoutePrefixPrivate, "sections", []string{"POST", "OPTIONS"}, nil, RunSectionCommand))
|
||||
log.IfErr(Add(RoutePrefixPrivate, "sections/refresh", []string{"GET", "OPTIONS"}, nil, RefreshSections))
|
||||
log.IfErr(Add(RoutePrefixPrivate, "sections/blocks/{folderID}", []string{"GET", "OPTIONS"}, nil, GetBlocksForSpace))
|
||||
log.IfErr(Add(RoutePrefixPrivate, "sections/blocks/space/{folderID}", []string{"GET", "OPTIONS"}, nil, GetBlocksForSpace))
|
||||
log.IfErr(Add(RoutePrefixPrivate, "sections/blocks/{blockID}", []string{"GET", "OPTIONS"}, nil, GetBlock))
|
||||
log.IfErr(Add(RoutePrefixPrivate, "sections/blocks/{blockID}", []string{"PUT", "OPTIONS"}, nil, UpdateBlock))
|
||||
log.IfErr(Add(RoutePrefixPrivate, "sections/blocks", []string{"POST", "OPTIONS"}, nil, AddBlock))
|
||||
|
||||
// Links
|
||||
|
|
|
@ -229,6 +229,34 @@ func AddBlock(w http.ResponseWriter, r *http.Request) {
|
|||
writeSuccessEmptyJSON(w)
|
||||
}
|
||||
|
||||
// GetBlock returns requested reusable content block.
|
||||
func GetBlock(w http.ResponseWriter, r *http.Request) {
|
||||
method := "GetBlock"
|
||||
p := request.GetPersister(r)
|
||||
|
||||
params := mux.Vars(r)
|
||||
blockID := params["blockID"]
|
||||
|
||||
if len(blockID) == 0 {
|
||||
writeMissingDataError(w, method, "blockID")
|
||||
return
|
||||
}
|
||||
|
||||
b, err := p.GetBlock(blockID)
|
||||
if err != nil {
|
||||
writeGeneralSQLError(w, method, err)
|
||||
return
|
||||
}
|
||||
|
||||
json, err := json.Marshal(b)
|
||||
if err != nil {
|
||||
writeJSONMarshalError(w, method, "block", err)
|
||||
return
|
||||
}
|
||||
|
||||
writeSuccessBytes(w, json)
|
||||
}
|
||||
|
||||
// GetBlocksForSpace returns available reusable content blocks for the space.
|
||||
func GetBlocksForSpace(w http.ResponseWriter, r *http.Request) {
|
||||
method := "GetBlocksForSpace"
|
||||
|
@ -264,3 +292,48 @@ func GetBlocksForSpace(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
writeSuccessBytes(w, json)
|
||||
}
|
||||
|
||||
// UpdateBlock inserts new reusable content block into database.
|
||||
func UpdateBlock(w http.ResponseWriter, r *http.Request) {
|
||||
method := "UpdateBlock"
|
||||
p := request.GetPersister(r)
|
||||
|
||||
defer utility.Close(r.Body)
|
||||
body, err := ioutil.ReadAll(r.Body)
|
||||
|
||||
if err != nil {
|
||||
writeBadRequestError(w, method, "Bad payload")
|
||||
return
|
||||
}
|
||||
|
||||
b := entity.Block{}
|
||||
err = json.Unmarshal(body, &b)
|
||||
if err != nil {
|
||||
writePayloadError(w, method, err)
|
||||
return
|
||||
}
|
||||
|
||||
if !p.CanUploadDocument(b.LabelID) {
|
||||
writeForbiddenError(w)
|
||||
return
|
||||
}
|
||||
|
||||
tx, err := request.Db.Beginx()
|
||||
if err != nil {
|
||||
writeTransactionError(w, method, err)
|
||||
return
|
||||
}
|
||||
|
||||
p.Context.Transaction = tx
|
||||
|
||||
err = p.UpdateBlock(b)
|
||||
if err != nil {
|
||||
log.IfErr(tx.Rollback())
|
||||
writeGeneralSQLError(w, method, err)
|
||||
return
|
||||
}
|
||||
|
||||
log.IfErr(tx.Commit())
|
||||
|
||||
writeSuccessEmptyJSON(w)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue