コード例 #1
0
ファイル: server.go プロジェクト: sanjaysagarp/Co-Aud
func roleBrowseHandler(w http.ResponseWriter, r *http.Request) {
	data := setDefaultData(w, r)
	//params for pagination
	roleAmount := 16
	pageAmount := 5

	//pagination
	pageNumber, err := strconv.Atoi(r.URL.Query().Get("page")) //used for getting roles
	currentPage := pageNumber                                  //used for getting page list
	if currentPage <= 0 {
		currentPage = 1
	}
	data["currentPage"] = currentPage
	data["prevPage"] = currentPage - 1
	data["nextPage"] = currentPage + 1
	if err != nil {
		fmt.Println(err)
	}
	//zero index page number for skip calculation when querying mongo
	if pageNumber != 0 {
		pageNumber--
	}

	//get roles
	roleList, rolesCount := role.FindRoles(nil, (pageNumber)*roleAmount, roleAmount)

	//more params for pagination
	maxPage := int(math.Ceil(float64(rolesCount) / float64(roleAmount)))
	pageList := getPageList(maxPage, currentPage, pageAmount)

	data["roles"] = roleList
	data["maxPage"] = maxPage
	data["pageList"] = pageList
	display(w, "browseAuditions", &Page{Title: "Roles", Data: data})
}
コード例 #2
0
ファイル: server.go プロジェクト: sanjaysagarp/Co-Aud
func viewUserAuditions(w http.ResponseWriter, r *http.Request) {
	data := setDefaultData(w, r)
	userID := r.URL.Query().Get("id")
	user := user.FindUserById(userID)
	dbRefUser := &mgo.DBRef{Collection: "users", Id: user.Id, Database: "CoAud"}
	postedRoles, rolesCount := role.FindRoles(bson.M{"user": dbRefUser}, 0, 500)
	data["user"] = user
	data["postedRoles"] = postedRoles
	data["rolesCount"] = rolesCount
	display(w, "viewUserAuditions", &Page{Title: user.DisplayName, Data: data})
}
コード例 #3
0
ファイル: server.go プロジェクト: sanjaysagarp/Co-Aud
//The handlers.
func homeHandler(w http.ResponseWriter, r *http.Request) {
	data := setDefaultData(w, r)

	//get roles
	roleList, totalRolesCount := role.FindRoles(nil, 0, 16)
	projectList, totalProjectList := project.FindProjects(nil, 0, 6)

	fmt.Println("total number of projects: ", totalProjectList)
	data["totalRolesCount"] = totalRolesCount
	data["roles"] = roleList
	data["projects"] = projectList
	display(w, "home", &Page{Title: "Home!", Data: data})
}
コード例 #4
0
ファイル: server.go プロジェクト: sanjaysagarp/Co-Aud
func getRoleHandler(w http.ResponseWriter, r *http.Request) {
	//need to get form fields web page
	page, err := strconv.Atoi(r.FormValue("page"))
	fmt.Println(page)
	if err != nil {
		panic(err)
	}

	//create a new user struct
	roles, rolesCount := role.FindRoles(nil, page*16, 16)
	fmt.Println(rolesCount)
	var html string
	if len(roles) != 0 {
		for index, role := range roles {
			html += "<div class=\"thumbnail flex-item\"><a href=\"/role/?id=" + role.Id.Hex() + "\"><h2>" + role.Title + "</h2><img class=\"img-responsive\" src=\"/public/img/placeholder.png\"></a></div>"
			fmt.Println(index)
		}
	}
	w.Write([]byte(html))

}