Exemplo n.º 1
0
Arquivo: base.go Projeto: grr89/hrkb
func LoadLangs() {
	var langs []M.Lang
	l := &Lang{}
	err := DM.FindAll(&M.Lang{}, &langs, M.Sf{"Code"}, M.Where{}, M.NewParams(M.Params{Sort: "Code ASC"}))
	if err != nil {
		beego.Error(err)
		return
	}
	for _, v := range langs {
		i18n.MustLoadTranslationFile(l.langFileName("lang::folder", v.Code))
	}
}
Exemplo n.º 2
0
Arquivo: cand.go Projeto: grr89/hrkb
//list of candidates
func (c *Cand) Index() {
	var cands []M.Cand
	var deps []M.Dep
	var wF M.Where

	depF, err := strconv.Atoi(c.Input().Get("dep"))

	if depF > 0 {
		wF = M.Where{And: M.W{"Dep": depF}}
	}

	cnt, err := DM.Count(&M.Cand{}, wF)
	if err != nil {
		beego.Error(err)
	}

	perPage := 10
	paginator := pagination.SetPaginator(c.Ctx, perPage, cnt)

	//TODO properly handle db errors
	err = DM.FindAll(&M.Cand{}, &cands, M.Sf{}, wF, M.NewParams(M.Params{Offset: paginator.Offset(), Limit: perPage, Sort: "Name,LName ASC"}))
	if err != nil {
		beego.Error(err)
		return
	}
	err = DM.FindAll(&M.Dep{}, &deps, M.Sf{}, M.Where{}, M.NewParams(M.Params{Sort: "Title ASC"}))
	if err != nil {
		beego.Error(err)
		return
	}
	m := make(map[int]string)
	for _, v := range deps {
		m[v.Id] = v.Title
	}
	c.Data["deps"] = m
	c.Data["depFilter"] = depF
	c.Data["cands"] = cands
	c.Data["title"] = T("cand", 2)
}
Exemplo n.º 3
0
Arquivo: user.go Projeto: grr89/hrkb
//list of users
func (c *User) Index() {

	var users []M.User

	err := DM.FindAll(&M.User{}, &users, M.Sf{}, M.Where{}, M.NewParams(M.Params{Sort: "Login ASC"}))
	if err != nil {
		beego.Error(err)
	}
	c.Data["users"] = users

	r := c.rolesList()
	m := make(map[int]string)
	for _, v := range r {
		m[v.Id] = v.Name
	}
	c.Data["roles"] = m
	c.Data["title"] = T("user", 2)
}
Exemplo n.º 4
0
Arquivo: base.go Projeto: grr89/hrkb
func (c *BaseController) Prepare() {

	var lang string
	var langs []M.Lang
	var dLang string
	langTypes := make(map[string]string)

	c.Data["title"] = "Human Resource Management"
	c.Data["scripts"] = []string{}
	c.Data["styles"] = []string{}
	c.Data["url"] = c.Ctx.Request.RequestURI
	c.Layout = "layout.tpl"

	if c.IsAjax() {
		c.EnableRender = false
	}

	if uid := c.GetSession("uid"); uid != nil {
		c.Data["gitlabToken"] = c.GetSession("gitlabToken")
		c.Data["UserName"] = c.GetSession("name")
		c.Data["UserIsAdmin"] = c.GetSession("role").(int) == M.RoleAdmin
		c.Data["UserId"] = uid.(int)
	}

	flash := beego.ReadFromRequest(&c.Controller)

	if n, ok := flash.Data["notice"]; ok {
		c.Data["notice"] = n
	}

	c.Data["rUrl"] = c.Ctx.Request.RequestURI

	err := DM.FindAll(&M.Lang{}, &langs, M.Sf{"Code", "IsDefault"}, M.Where{}, M.NewParams(M.Params{Sort: "Code ASC"}))
	if err != nil {
		beego.Error(err)
	}
	for _, v := range langs {
		if v.IsDefault {
			dLang = v.Code
		}
		s := v.Code[:2]
		langTypes[v.Code] = s
	}

	uLang := c.Input().Get("lang")

	if uLang != "" && langTypes[uLang] != "" {
		c.SetSession("lang", uLang)
	} else if s := c.GetSession("lang"); s != nil && langTypes[s.(string)] != "" {
		uLang = s.(string)
	}

	aLang := c.Ctx.Request.Header.Get("Accept-Language")

	if len(aLang) > 4 {
		aLang = strings.ToLower(aLang[:3]) + strings.ToUpper(aLang[3:5])
		if _, ok := langTypes[aLang]; !ok {
			aLang = ""
		}
	} else {
		aLang = ""
	}

	Tfn, err := i18n.Tfunc(uLang, aLang, dLang)
	T = Tfn
	M.T = Tfn
	if err != nil {
		beego.Error(err)
	}

	beego.AddFuncMap("T", Tfn)

	switch {
	case langTypes[uLang] != "":
		lang = uLang
	case langTypes[aLang] != "":
		lang = aLang
	default:
		lang = dLang
	}

	c.Data["Langs"] = langTypes
	c.Data["CurrentLang"] = lang
}
Exemplo n.º 5
0
Arquivo: models.go Projeto: grr89/hrkb
func (s *MailStore) GetFailed(mails interface{}, limit int) error {

	if limit <= 0 {
		return errors.New(ErrLimit)
	}

	err := s.db.FindAll(&M.Mail{}, mails, M.Sf{}, M.Where{And: M.W{"Status": false, "Try<": s.retry}}, M.NewParams(M.Params{Limit: limit}))

	if err != nil {
		return err
	}

	return nil
}