focalboard/server/app/blocks.go

102 lines
2.6 KiB
Go
Raw Normal View History

package app
import (
2021-01-26 23:13:46 +01:00
"github.com/mattermost/focalboard/server/model"
2021-03-26 19:01:54 +01:00
"github.com/mattermost/focalboard/server/services/store"
)
2021-03-26 19:01:54 +01:00
func (a *App) GetBlocks(c store.Container, parentID string, blockType string) ([]model.Block, error) {
Migrate webapp global state to redux (#737) * Migrating workspace tree to redux * More changes for use the redux store for boads and views * Taking into account the templates on websocket event updates * Fixing bug on boardTree maintenance * Websocket client now connects once and subscribe/desubscribe on the fly * Including usage of the new websocket client * More work around migrating to redux * WIP * WIP * WIP * WIP * WIP * WIP * Fixing some things * WIP * WIP * Another small fix * Restoring filtering, sorting and grouping * Fixing some other bugs * Add search text reducer * Fixing another drag and drop problem * Improve store names and api * Fixing small bgus * Some small fixes * fixing login * Fixing register page * Some other improvements * Removing unneeded old files * Removing the need of userCache * Fixing comments and fixing content ordering * Fixing sort * Fixing some TODOs * Fixing tests * Fixing snapshot * Fixing cypress tests * Fix eslint * Fixing server tests * Updating the add cards actions * Fixing some tiny navigation problems * Mocking the api calls to pass the tests * Migrating a new test to redux * Adding the card right after the insert of the block (not wait for ws event) * Showing the ws disconnect banner only after 5 seconds of disconnection * Fixing share view * Fix eslint * Fixing problem with sort/groupby modifications * Fixing some details on redirections and templates creation * Fixing small bugs around undo * Fix update properties on click outside the dialog * Improving the column resize look and feel * Removing the class based objects from the store (now they are all plain objects * Fix eslint * Fixing tests * Removing unneeded code
2021-08-02 17:46:00 +02:00
if blockType != "" && parentID != "" {
2021-03-26 19:01:54 +01:00
return a.store.GetBlocksWithParentAndType(c, parentID, blockType)
}
Migrate webapp global state to redux (#737) * Migrating workspace tree to redux * More changes for use the redux store for boads and views * Taking into account the templates on websocket event updates * Fixing bug on boardTree maintenance * Websocket client now connects once and subscribe/desubscribe on the fly * Including usage of the new websocket client * More work around migrating to redux * WIP * WIP * WIP * WIP * WIP * WIP * Fixing some things * WIP * WIP * Another small fix * Restoring filtering, sorting and grouping * Fixing some other bugs * Add search text reducer * Fixing another drag and drop problem * Improve store names and api * Fixing small bgus * Some small fixes * fixing login * Fixing register page * Some other improvements * Removing unneeded old files * Removing the need of userCache * Fixing comments and fixing content ordering * Fixing sort * Fixing some TODOs * Fixing tests * Fixing snapshot * Fixing cypress tests * Fix eslint * Fixing server tests * Updating the add cards actions * Fixing some tiny navigation problems * Mocking the api calls to pass the tests * Migrating a new test to redux * Adding the card right after the insert of the block (not wait for ws event) * Showing the ws disconnect banner only after 5 seconds of disconnection * Fixing share view * Fix eslint * Fixing problem with sort/groupby modifications * Fixing some details on redirections and templates creation * Fixing small bugs around undo * Fix update properties on click outside the dialog * Improving the column resize look and feel * Removing the class based objects from the store (now they are all plain objects * Fix eslint * Fixing tests * Removing unneeded code
2021-08-02 17:46:00 +02:00
if blockType != "" {
2021-03-26 19:01:54 +01:00
return a.store.GetBlocksWithType(c, blockType)
}
2021-03-26 19:01:54 +01:00
return a.store.GetBlocksWithParent(c, parentID)
}
func (a *App) GetBlocksWithRootID(c store.Container, rootID string) ([]model.Block, error) {
return a.store.GetBlocksWithRootID(c, rootID)
}
2021-03-26 19:01:54 +01:00
func (a *App) GetRootID(c store.Container, blockID string) (string, error) {
return a.store.GetRootID(c, blockID)
2021-01-13 03:49:08 +01:00
}
2021-03-26 19:01:54 +01:00
func (a *App) GetParentID(c store.Container, blockID string) (string, error) {
return a.store.GetParentID(c, blockID)
}
func (a *App) PatchBlock(c store.Container, blockID string, blockPatch *model.BlockPatch, userID string) error {
err := a.store.PatchBlock(c, blockID, blockPatch, userID)
if err != nil {
return err
}
a.metrics.IncrementBlocksPatched(1)
block, err := a.store.GetBlock(c, blockID)
if err != nil {
return nil
}
a.wsServer.BroadcastBlockChange(c.WorkspaceID, *block)
go a.webhook.NotifyUpdate(*block)
return nil
}
func (a *App) InsertBlock(c store.Container, block model.Block, userID string) error {
err := a.store.InsertBlock(c, &block, userID)
if err == nil {
a.metrics.IncrementBlocksInserted(1)
}
return err
}
func (a *App) InsertBlocks(c store.Container, blocks []model.Block, userID string) error {
for i := range blocks {
err := a.store.InsertBlock(c, &blocks[i], userID)
if err != nil {
return err
}
2020-10-29 21:09:02 +01:00
a.wsServer.BroadcastBlockChange(c.WorkspaceID, blocks[i])
a.metrics.IncrementBlocksInserted(len(blocks))
go a.webhook.NotifyUpdate(blocks[i])
}
return nil
}
2021-03-26 19:01:54 +01:00
func (a *App) GetSubTree(c store.Container, blockID string, levels int) ([]model.Block, error) {
2020-11-12 19:16:59 +01:00
// Only 2 or 3 levels are supported for now
if levels >= 3 {
2021-03-26 19:01:54 +01:00
return a.store.GetSubTree3(c, blockID)
2020-11-12 19:16:59 +01:00
}
2021-03-26 19:01:54 +01:00
return a.store.GetSubTree2(c, blockID)
}
2021-03-26 19:01:54 +01:00
func (a *App) GetAllBlocks(c store.Container) ([]model.Block, error) {
return a.store.GetAllBlocks(c)
}
2021-03-26 19:01:54 +01:00
func (a *App) DeleteBlock(c store.Container, blockID string, modifiedBy string) error {
parentID, err := a.GetParentID(c, blockID)
if err != nil {
return err
}
2021-03-26 19:01:54 +01:00
err = a.store.DeleteBlock(c, blockID, modifiedBy)
if err != nil {
return err
}
2021-03-27 02:04:23 +01:00
a.wsServer.BroadcastBlockDelete(c.WorkspaceID, blockID, parentID)
a.metrics.IncrementBlocksDeleted(1)
return nil
}
func (a *App) GetBlockCountsByType() (map[string]int64, error) {
return a.store.GetBlockCountsByType()
}