github.com/insionng/yougam@v0.0.0-20170714101924-2bc18d833463/routers/root/RReadNode.go (about)

     1  package root
     2  
     3  import (
     4  	"github.com/insionng/makross"
     5  	"github.com/insionng/yougam/models"
     6  )
     7  
     8  func GetRReadNodeHandler(self *makross.Context) error {
     9  
    10  	TplNames := ""
    11  	self.Set("catpage", "RReadNodeHandler")
    12  	switch nid := self.Param("nid").MustInt64(); {
    13  	//单独模式
    14  	case nid > 0:
    15  		{
    16  			TplNames = "root/read_node"
    17  
    18  			if nd, err := models.GetNode(nid); nd != nil && err == nil {
    19  				self.Set("node", *nd)
    20  
    21  				if nodes, err := models.GetNodes(0, 0, "id"); nodes != nil && err == nil {
    22  					self.Set("nodes", *nodes)
    23  				}
    24  
    25  			} else {
    26  				self.Flash.Error(err.Error())
    27  				return self.Render(TplNames)
    28  
    29  			}
    30  		}
    31  	//列表模式
    32  	case nid <= 0:
    33  		{
    34  			TplNames = "root/node_table"
    35  			offset := self.Args("offset").MustInt64()
    36  			limit := self.Args("limit").MustInt64()
    37  			field := self.FormValue("field")
    38  
    39  			if limit == 0 {
    40  				limit = 1000 //默认限制显示最近1000条,需要显示全部请在提交请求的时候设置limit字段为-1
    41  			}
    42  
    43  			if field == "" {
    44  				field = "id"
    45  			}
    46  
    47  			if nds, err := models.GetNodes(int(offset), int(limit), field); err == nil && nds != nil {
    48  				self.Set("nodes", *nds)
    49  			}
    50  		}
    51  	}
    52  
    53  	return self.Render(TplNames)
    54  
    55  }