mirror of
https://github.com/wavetermdev/backup.git
synced 2026-08-05 13:57:07 -07:00
add lines/cmds to historyview data. fix bug with lineid not getting added for comment commands
This commit is contained in:
@@ -1454,6 +1454,7 @@ func CommentCommand(ctx context.Context, pk *scpacket.FeCommandPacketType) (ssto
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
updateHistoryContext(ctx, rtnLine, nil)
|
||||
updateMap := make(map[string]interface{})
|
||||
updateMap[sstore.SWField_SelectedLine] = rtnLine.LineNum
|
||||
updateMap[sstore.SWField_Focus] = sstore.SWFocusInput
|
||||
@@ -1810,6 +1811,8 @@ func ClearCommand(ctx context.Context, pk *scpacket.FeCommandPacketType) (sstore
|
||||
|
||||
}
|
||||
|
||||
const HistoryViewPageSize = 50
|
||||
|
||||
func HistoryViewAllCommand(ctx context.Context, pk *scpacket.FeCommandPacketType) (sstore.UpdatePacket, error) {
|
||||
_, err := resolveUiIds(ctx, pk, 0)
|
||||
if err != nil {
|
||||
@@ -1819,7 +1822,7 @@ func HistoryViewAllCommand(ctx context.Context, pk *scpacket.FeCommandPacketType
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
opts := sstore.HistoryQueryOpts{MaxItems: 51, Offset: offset}
|
||||
opts := sstore.HistoryQueryOpts{MaxItems: HistoryViewPageSize + 1, Offset: offset}
|
||||
if pk.Kwargs["text"] != "" {
|
||||
opts.SearchText = pk.Kwargs["text"]
|
||||
}
|
||||
@@ -1827,11 +1830,20 @@ func HistoryViewAllCommand(ctx context.Context, pk *scpacket.FeCommandPacketType
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
hvdata := &sstore.HistoryViewData{
|
||||
TotalCount: 0,
|
||||
Offset: offset,
|
||||
Items: hitems,
|
||||
hvdata := &sstore.HistoryViewData{Offset: offset}
|
||||
if len(hitems) > HistoryViewPageSize {
|
||||
hvdata.HasMore = true
|
||||
hvdata.Items = hitems[0:HistoryViewPageSize]
|
||||
} else {
|
||||
hvdata.HasMore = false
|
||||
hvdata.Items = hitems
|
||||
}
|
||||
lines, cmds, err := sstore.GetLineCmdsFromHistoryItems(ctx, hvdata.Items)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
hvdata.Lines = lines
|
||||
hvdata.Cmds = cmds
|
||||
update := sstore.ModelUpdate{
|
||||
HistoryViewData: hvdata,
|
||||
MainView: sstore.MainViewHistory,
|
||||
|
||||
@@ -2343,3 +2343,48 @@ func GetPlaybookById(ctx context.Context, playbookId string) (*PlaybookType, err
|
||||
}
|
||||
return rtn, nil
|
||||
}
|
||||
|
||||
func getLineIdsFromHistoryItems(historyItems []*HistoryItemType) []string {
|
||||
var rtn []string
|
||||
for _, hitem := range historyItems {
|
||||
if hitem.LineId != "" {
|
||||
rtn = append(rtn, hitem.LineId)
|
||||
}
|
||||
}
|
||||
return rtn
|
||||
}
|
||||
|
||||
func getCmdIdsFromHistoryItems(historyItems []*HistoryItemType) []string {
|
||||
var rtn []string
|
||||
for _, hitem := range historyItems {
|
||||
if hitem.CmdId != "" {
|
||||
rtn = append(rtn, hitem.CmdId)
|
||||
}
|
||||
}
|
||||
return rtn
|
||||
}
|
||||
|
||||
func GetLineCmdsFromHistoryItems(ctx context.Context, historyItems []*HistoryItemType) ([]*LineType, []*CmdType, error) {
|
||||
var lineArr []*LineType
|
||||
var cmdArr []*CmdType
|
||||
if len(historyItems) == 0 {
|
||||
return nil, nil, nil
|
||||
}
|
||||
txErr := WithTx(ctx, func(tx *TxWrap) error {
|
||||
query := `SELECT * FROM line WHERE lineid IN (SELECT value FROM json_each(?))`
|
||||
tx.Select(&lineArr, query, quickJsonArr(getLineIdsFromHistoryItems(historyItems)))
|
||||
query = `SELECT * FROM cmd WHERE cmdid IN (SELECT value FROM json_each(?))`
|
||||
marr := tx.SelectMaps(query, quickJsonArr(getCmdIdsFromHistoryItems(historyItems)))
|
||||
for _, m := range marr {
|
||||
cmd := CmdFromMap(m)
|
||||
if cmd != nil {
|
||||
cmdArr = append(cmdArr, cmd)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if txErr != nil {
|
||||
return nil, nil, txErr
|
||||
}
|
||||
return lineArr, cmdArr, nil
|
||||
}
|
||||
|
||||
@@ -79,6 +79,9 @@ type HistoryViewData struct {
|
||||
TotalCount int `json:"totalcount"`
|
||||
Offset int `json:"offset"`
|
||||
Items []*HistoryItemType `json:"items"`
|
||||
Lines []*LineType `json:"lines"`
|
||||
Cmds []*CmdType `json:"cmds"`
|
||||
HasMore bool `json:"hasmore"`
|
||||
}
|
||||
|
||||
type RemoteEditType struct {
|
||||
|
||||
Reference in New Issue
Block a user