Esempio n. 1
0
func (this *MonthController) Get() {
	y, m, d := time.Now().Date()
	persons := make([]models.Person, 0)
	admin := this.IsAdmin()
	if admin {
		persons = models.NewPersonOption().ReadAll()
	} else {
		persons = models.NewPersonOption().ReadByGroup(this.user.Group)
	}
	outputPersons := make([]models.Person, len(persons))
	for index, person := range persons {
		person.LoginPass = "******"
		outputPersons[index] = person
	}
	cy, cm, cd := y, int(m), d
	pm, _ := this.GetInt("m")
	if pm > 0 {
		if pm > cm {
			cy -= 1
		}
		cm = pm
		cd = 1
	}
	this.Data["Y"] = cy
	this.Data["M"] = cm
	this.Data["D"] = cd
	this.Data["PageMonth"] = true
	this.Data["Group"] = models.GroupConfig
	this.Data["Persons"] = outputPersons
	this.Data["Script"] = []string{"app/app", "app/directives/tip", "app/directives/plan", "app/services/month", "app/services/time", "app/controllers/month/monthCtrl"}
	this.TplNames = "month.html"
}
Esempio n. 2
0
func (this *PersonController) Update() {
	if !this.prefixCheck() {
		return
	}
	id, _ := this.GetInt("id")
	if id == 0 {
		this.error("nouser")
		return
	}
	personOption := models.NewPersonOption()
	person, err := personOption.ReadById(id)
	if err != nil {
		this.error("nouser")
		return
	}
	person.Name = this.Name
	person.LoginName = this.LoginName
	person.LoginPass = this.LoginPass
	person.Color = this.Color
	person.Group = this.Group
	_, err = personOption.Update(person)
	if err != nil {
		this.error("err")
		return
	}
	this.success("ok")
}
Esempio n. 3
0
File: tb.go Progetto: tangseng/gtt
func (this *TBController) get(key string, columns map[string]string, offset int) ([]models.Tb, map[string]string) {
	tbs := make([]models.Tb, 0)
	if len(key) > 0 || len(columns) > 0 {
		tbs = models.NewTbOption().Search(key, columns, offset, PAGENUM)
	} else {
		tbs = models.NewTbOption().ReadMore(offset, PAGENUM)
	}
	pids := make([]int, 0)
	pidsCheck := make(map[string]bool)
	for _, tb := range tbs {
		if tb.Uid != -1 {
			if _, ok := pidsCheck[strconv.Itoa(tb.Uid)]; !ok {
				pidsCheck[strconv.Itoa(tb.Uid)] = true
				pids = append(pids, tb.Uid)
			}
		}
	}
	outPersons := make(map[string]string)
	if len(pids) > 0 {
		persons := models.NewPersonOption().ReadByIds(pids)
		for _, person := range persons {
			outPersons[strconv.Itoa(person.Id)] = person.Name
		}
	}
	outPersons["-1"] = "管理员"
	return tbs, outPersons
}
Esempio n. 4
0
func (this *LoginController) DoLogin() {
	if !this.check() {
		return
	}
	this.info = &map[string]string{
		"success": "登录成功",
		"login":   "******",
	}
	name := this.GetString("name")
	pass := this.GetString("pass")
	person, err := CheckAdmin(name, pass)
	if err != nil {
		person, err = models.NewPersonOption().Read(name, pass)
		if err != nil {
			this.error("login")
			return
		}
	}
	sess := this.StartSession()
	err = sess.Set("user", *person)
	if err != nil {
		this.error("login")
		return
	}
	this.success(map[string]int{"id": person.Id})
}
Esempio n. 5
0
func (this *MonthController) Plan() {
	this.info = &map[string]string{
		"diff": "所请求的时间大于一个月的时间",
	}
	startTime, _ := this.GetInt64("start")
	endTime, _ := this.GetInt64("end")
	if endTime-startTime > 32*24*3600 {
		this.error("diff")
		return
	}
	isAdmin := this.IsAdmin()
	planOption := models.NewPlanOption()
	var plans []models.Plan
	if isAdmin {
		plans = planOption.ReadInMonth(startTime, endTime)
	} else {
		persons := models.NewPersonOption().ReadByGroup(this.user.Group)
		uids := make([]int, 0)
		for _, person := range persons {
			uids = append(uids, person.Id)
		}
		plans = planOption.ReadByUidsInMonth(uids, startTime, endTime)
	}
	this.success(plans)
}
Esempio n. 6
0
File: jx.go Progetto: tangseng/gtt
func (this *JXController) Get() {
	this.prefixInit()
	cy, cm, cd := this.Y, this.M, this.D
	pm, _ := this.GetInt("m")
	if pm > 0 {
		if pm > cm {
			cy -= 1
		}
		cm = pm
		cd = 1
	}
	this.Data["PageJx"] = true
	this.Data["Y"] = cy
	this.Data["M"] = cm
	this.Data["D"] = cd
	admin := this.IsAdmin()
	if admin {
		persons := models.NewPersonOption().ReadAll()
		outPersons := map[string]string{}
		for _, person := range persons {
			outPersons[strconv.Itoa(person.Id)] = person.Name
		}
		this.Data["Persons"] = outPersons
		this.Data["Script"] = []string{"app/app", "app/directives/tip", "app/directives/date", "app/services/month", "app/services/time", "app/controllers/jx/jxAdminCtrl"}
		this.TplNames = "jx.admin.html"
	} else {
		this.Data["Script"] = []string{"app/app", "app/directives/tip", "app/services/month", "app/services/time", "app/controllers/jx/jxCtrl"}
		this.TplNames = "jx.html"
	}
}
Esempio n. 7
0
func (this *PersonController) Get() {
	if !this.check() {
		return
	}
	persons := models.NewPersonOption().ReadAll()
	this.Data["PagePerson"] = true
	this.Data["Group"] = models.GroupConfig
	this.Data["Persons"] = persons
	this.Data["Css"] = []string{"colorpicker"}
	this.Data["Script"] = []string{"app/app", "app/directives/tip", "app/controllers/person/personCtrl", "colorpicker", "app/directives/color"}
	this.TplNames = "person.html"
}
Esempio n. 8
0
func (this *PersonController) Delete() {
	if !this.check() {
		return
	}
	this.info = &map[string]string{
		"err": "操作失败",
		"ok":  "操作成功",
	}
	id, _ := this.GetInt("id")
	if id == 0 {
		this.error("nouser")
		return
	}
	err := models.NewPersonOption().Delete(id)
	if err != nil {
		this.error("err")
		return
	}
	this.success("ok")
}
Esempio n. 9
0
func (this *PersonController) Add() {
	if !this.prefixCheck() {
		return
	}
	personOption := models.NewPersonOption()
	person, err := personOption.ReadByName(this.Name)
	if err == nil && person.Id > 0 {
		this.error("user")
		return
	}
	person, err = personOption.ReadByLoginName(this.LoginName)
	if err == nil && person.Id > 0 {
		this.error("login")
		return
	}
	id, err := personOption.Insert(models.NewPerson(this.Name, this.LoginName, this.LoginPass, this.Color, this.Group))
	if err != nil {
		this.error("err")
		return
	}
	this.success(map[string]interface{}{"id": id})
}
Esempio n. 10
0
File: app.go Progetto: tangseng/gtt
func (this *AppController) get(appid, page, offset int) ([]models.App, map[string]string) {
	logs := models.NewAppOption().ReadMore(appid, offset, page)
	pids := make([]int, 0)
	pidsCheck := make(map[string]bool)
	for _, tb := range logs {
		if tb.Uid != -1 {
			if _, ok := pidsCheck[strconv.Itoa(tb.Uid)]; !ok {
				pidsCheck[strconv.Itoa(tb.Uid)] = true
				pids = append(pids, tb.Uid)
			}
		}
	}
	outPersons := make(map[string]string)
	if len(pids) > 0 {
		persons := models.NewPersonOption().ReadByIds(pids)
		for _, person := range persons {
			outPersons[strconv.Itoa(person.Id)] = person.Name
		}
	}
	if len(outPersons) > 0 {
		outPersons["-1"] = "管理员"
	}
	return logs, outPersons
}
Esempio n. 11
0
File: jx.go Progetto: tangseng/gtt
func (this *JXController) allPersons(only bool) (map[string]map[string]string, []int) {
	ids := make([]int, 0)
	persons := models.NewPersonOption().ReadAll()
	if only {
		for _, person := range persons {
			if person.Group != "zj" {
				ids = append(ids, person.Id)
			}
		}
		return nil, ids
	} else {
		outPersons := map[string]map[string]string{}
		for _, person := range persons {
			if person.Group != "zj" {
				outPersons[strconv.Itoa(person.Id)] = map[string]string{
					"name":  person.Name,
					"color": person.Color,
				}
				ids = append(ids, person.Id)
			}
		}
		return outPersons, ids
	}
}