diff --git a/kernel/av/attribute_view.go b/kernel/av/attribute_view.go index b7c2408dd..7d6056366 100644 --- a/kernel/av/attribute_view.go +++ b/kernel/av/attribute_view.go @@ -168,13 +168,14 @@ func SaveAttributeView(av *AttributeView) (err error) { return } -func (av *AttributeView) GetView(viewID string) (ret *View) { +func (av *AttributeView) GetView(viewID string) (ret *View, err error) { for _, v := range av.Views { if v.ID == viewID { ret = v return } } + err = ErrViewNotFound return } diff --git a/kernel/model/attribute_view.go b/kernel/model/attribute_view.go index 7310861f0..3fae15d28 100644 --- a/kernel/model/attribute_view.go +++ b/kernel/model/attribute_view.go @@ -123,9 +123,8 @@ func setAttributeViewFilters(operation *Operation) (err error) { return } - view := attrView.GetView(operation.ViewID) - if nil == view { - err = av.ErrViewNotFound + view, err := attrView.GetView(operation.ViewID) + if nil != err { return } @@ -158,9 +157,8 @@ func setAttributeViewSorts(operation *Operation) (err error) { return } - view := attrView.GetView(operation.ViewID) - if nil == view { - err = av.ErrViewNotFound + view, err := attrView.GetView(operation.ViewID) + if nil != err { return } @@ -316,9 +314,8 @@ func setAttributeViewColWidth(operation *Operation) (err error) { return } - view := attrView.GetView(operation.ViewID) - if nil == view { - err = av.ErrViewNotFound + view, err := attrView.GetView(operation.ViewID) + if nil != err { return } @@ -347,9 +344,8 @@ func setAttributeViewColWrap(operation *Operation) (err error) { return } - view := attrView.GetView(operation.ViewID) - if nil == view { - err = av.ErrViewNotFound + view, err := attrView.GetView(operation.ViewID) + if nil != err { return } @@ -378,9 +374,8 @@ func setAttributeViewColHidden(operation *Operation) (err error) { return } - view := attrView.GetView(operation.ViewID) - if nil == view { - err = av.ErrViewNotFound + view, err := attrView.GetView(operation.ViewID) + if nil != err { return } @@ -495,9 +490,8 @@ func addAttributeViewColumn(operation *Operation) (err error) { return } - view := attrView.GetView(operation.ViewID) - if nil == view { - err = av.ErrViewNotFound + view, err := attrView.GetView(operation.ViewID) + if nil != err { return } @@ -522,6 +516,51 @@ func addAttributeViewColumn(operation *Operation) (err error) { return } +func (tx *Transaction) doUpdateAttrViewColumn(operation *Operation) (ret *TxErr) { + err := updateAttributeViewColumn(operation) + if nil != err { + return &TxErr{code: TxErrWriteAttributeView, id: operation.ParentID, msg: err.Error()} + } + return +} + +func updateAttributeViewColumn(operation *Operation) (err error) { + attrView, err := av.ParseAttributeView(operation.AvID) + if nil != err { + return + } + + colType := av.ColumnType(operation.Typ) + switch colType { + case av.ColumnTypeText, av.ColumnTypeNumber, av.ColumnTypeDate, av.ColumnTypeSelect, av.ColumnTypeMSelect: + for _, col := range attrView.Columns { + if col.ID == operation.ID { + col.Name = operation.Name + col.Type = colType + break + } + } + + for _, view := range attrView.Views { + for _, col := range view.Table.Columns { + if col.ID == operation.ID { + col.Name = operation.Name + col.Type = colType + break + } + } + } + default: + msg := fmt.Sprintf("invalid column type [%s]", operation.Typ) + logging.LogErrorf(msg) + err = errors.New(msg) + return + } + + err = av.SaveAttributeView(attrView) + return +} + // TODO 下面的方法要重写 func (tx *Transaction) doUpdateAttrViewCell(operation *Operation) (ret *TxErr) { @@ -613,14 +652,6 @@ func (tx *Transaction) doUpdateAttrViewColOptions(operation *Operation) (ret *Tx return } -func (tx *Transaction) doUpdateAttrViewColumn(operation *Operation) (ret *TxErr) { - err := updateAttributeViewColumn(operation.ID, operation.Name, operation.Typ, operation.ParentID) - if nil != err { - return &TxErr{code: TxErrWriteAttributeView, id: operation.ParentID, msg: err.Error()} - } - return -} - func (tx *Transaction) doRemoveAttrViewColumn(operation *Operation) (ret *TxErr) { err := removeAttributeViewColumn(operation.ID, operation.ParentID) if nil != err { @@ -637,33 +668,6 @@ func (tx *Transaction) doSetAttrView(operation *Operation) (ret *TxErr) { return } -func updateAttributeViewColumn(id, name string, typ string, avID string) (err error) { - attrView, err := av.ParseAttributeView(avID) - if nil != err { - return - } - - colType := av.ColumnType(typ) - switch colType { - case av.ColumnTypeText, av.ColumnTypeNumber, av.ColumnTypeDate, av.ColumnTypeSelect, av.ColumnTypeMSelect: - for _, col := range attrView.Columns { - if col.ID == id { - col.Name = name - col.Type = colType - break - } - } - default: - msg := fmt.Sprintf("invalid column type [%s]", typ) - logging.LogErrorf(msg) - err = errors.New(msg) - return - } - - err = av.SaveAttributeView(attrView) - return -} - func updateAttributeViewColumnOption(operation *Operation) (err error) { avID := operation.ParentID attrView, err := av.ParseAttributeView(avID) diff --git a/kernel/model/transaction.go b/kernel/model/transaction.go index 8afb19039..a3c4f4a9f 100644 --- a/kernel/model/transaction.go +++ b/kernel/model/transaction.go @@ -239,9 +239,9 @@ func performTx(tx *Transaction) (ret *TxErr) { ret = tx.doRemoveAttrViewBlock(op) case "addAttrViewCol": ret = tx.doAddAttrViewColumn(op) - // TODO 下面的方法要重写 case "updateAttrViewCol": ret = tx.doUpdateAttrViewColumn(op) + // TODO 下面的方法要重写 case "removeAttrViewCol": ret = tx.doRemoveAttrViewColumn(op) case "updateAttrViewCell":