mirror of
https://github.com/mattermost/focalboard.git
synced 2024-12-21 13:38:56 +02:00
f915a20c64
* Working in the new content block editor * Moving blocksEditor content block into its own component * Initial integration with quick development flow * More WIP * Adding drag and drop support with server side help * Some extra work around the styles * Adding image support * Adding video and attachments, and fixing edit * Putting everything behind a feature flag * Adding support for download attachments * Fixing compilation error * Fixing linter errors * Fixing javascript tests * Fixing a typescript error * Moving the move block to an action with undo support * Fixing ci * Fixing post merge errors * Moving to more specific content-blocks api * Apply suggestions from code review Co-authored-by: Doug Lauder <wiggin77@warpmail.net> * Fixing the behavior of certain blocks * Fixing linter error * Fixing javascript linter errors * Adding permission testing for the new move content block api * Adding some unit tests * Improving a bit the tests * Adding more unit tests to the backend * Fixed PR suggestion * Adding h1, h2 and h3 tests * Adding image tests * Adding video tests * Adding attachment tests * Adding quote block tests * Adding divider tests * Adding checkbox tests * Adding list item block tests * Adding text block tests * Reorganizing a bit the code to support deveditor eagain * Fixing dark theme on editor view * Fixing linter errors * Fixing tests and removing unneeded data-testid * Adding root input tests * Fixing some merge problems * Fixing text/text.test.tsx test * Adding more unit tests to the blocks editor * Fix linter error * Adding blocksEditor tests * Fixing linter errors * Adding tests for blockContent * Update webapp/src/components/blocksEditor/blockContent.test.tsx Fix linter warning * Update webapp/src/components/blocksEditor/blockContent.test.tsx Fix linter warning * Update webapp/src/components/blocksEditor/blockContent.test.tsx Fix linter error * Fixing test * Removing unneeded TODO Co-authored-by: Doug Lauder <wiggin77@warpmail.net>
82 lines
1.8 KiB
Go
82 lines
1.8 KiB
Go
package app
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/mattermost/focalboard/server/model"
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
func (a *App) MoveContentBlock(block *model.Block, dstBlock *model.Block, where string, userID string) error {
|
|
if block.ParentID != dstBlock.ParentID {
|
|
message := fmt.Sprintf("not matching parent %s and %s", block.ParentID, dstBlock.ParentID)
|
|
return model.NewErrBadRequest(message)
|
|
}
|
|
|
|
card, err := a.GetBlockByID(block.ParentID)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
contentOrderData, ok := card.Fields["contentOrder"]
|
|
var contentOrder []interface{}
|
|
if ok {
|
|
contentOrder = contentOrderData.([]interface{})
|
|
}
|
|
|
|
newContentOrder := []interface{}{}
|
|
foundDst := false
|
|
foundSrc := false
|
|
for _, id := range contentOrder {
|
|
stringID, ok := id.(string)
|
|
if !ok {
|
|
newContentOrder = append(newContentOrder, id)
|
|
continue
|
|
}
|
|
|
|
if dstBlock.ID == stringID {
|
|
foundDst = true
|
|
if where == "after" {
|
|
newContentOrder = append(newContentOrder, id)
|
|
newContentOrder = append(newContentOrder, block.ID)
|
|
} else {
|
|
newContentOrder = append(newContentOrder, block.ID)
|
|
newContentOrder = append(newContentOrder, id)
|
|
}
|
|
continue
|
|
}
|
|
|
|
if block.ID == stringID {
|
|
foundSrc = true
|
|
continue
|
|
}
|
|
|
|
newContentOrder = append(newContentOrder, id)
|
|
}
|
|
|
|
if !foundSrc {
|
|
message := fmt.Sprintf("source block %s not found", block.ID)
|
|
return model.NewErrBadRequest(message)
|
|
}
|
|
|
|
if !foundDst {
|
|
message := fmt.Sprintf("destination block %s not found", dstBlock.ID)
|
|
return model.NewErrBadRequest(message)
|
|
}
|
|
|
|
patch := &model.BlockPatch{
|
|
UpdatedFields: map[string]interface{}{
|
|
"contentOrder": newContentOrder,
|
|
},
|
|
}
|
|
|
|
_, err = a.PatchBlock(block.ParentID, patch, userID)
|
|
if errors.Is(err, model.ErrPatchUpdatesLimitedCards) {
|
|
return err
|
|
}
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|