예제 #1
0
파일: index.go 프로젝트: intfrr/sendto
// HandleIndex displays a list of files
func HandleIndex(context router.Context) error {

	// Authorise
	err := authorise.Path(context)
	if err != nil {
		return router.NotAuthorizedError(err)
	}

	// Find the current user and check status
	u := authorise.CurrentUser(context)
	if u.Anon() {
		//	return router.NotAuthorizedError(err)
	}

	// For admins, show all files, order by date desc
	q := files.Query().Order("updated_at desc")

	// otherwise show just the logged in user's files
	if !u.Admin() {
		// Find the files for this user, unless
		q = files.Where("user_id=?", u.Id)
	}

	// Fetch the files
	results, err := files.FindAll(q)
	if err != nil {
		return router.InternalError(err)
	}

	// Render the template
	view := view.New(context)
	view.AddKey("files", results)
	return view.Render()

}
예제 #2
0
파일: index.go 프로젝트: intfrr/sendto
// HandleIndex displays a list of pages
func HandleIndex(context router.Context) error {

	// Authorise
	err := authorise.Path(context)
	if err != nil {
		return router.NotAuthorizedError(err)
	}

	// Build a query
	q := pages.Query()

	// Order by required order, or default to id asc
	switch context.Param("order") {

	case "1":
		q.Order("created desc")

	case "2":
		q.Order("updated desc")

	case "3":
		q.Order("name asc")

	default:
		q.Order("id asc")

	}

	// Filter if necessary - this assumes name and summary cols
	filter := context.Param("filter")
	if len(filter) > 0 {
		filter = strings.Replace(filter, "&", "", -1)
		filter = strings.Replace(filter, " ", "", -1)
		filter = strings.Replace(filter, " ", " & ", -1)
		q.Where("( to_tsvector(name) || to_tsvector(summary) @@ to_tsquery(?) )", filter)
	}

	// Fetch the pages
	results, err := pages.FindAll(q)
	if err != nil {
		return router.InternalError(err)
	}

	// Render the template
	view := view.New(context)
	view.AddKey("filter", filter)
	view.AddKey("pages", results)
	return view.Render()

}
예제 #3
0
파일: create.go 프로젝트: intfrr/sendto
// HandleCreateShow serves the create form via GET for pages
func HandleCreateShow(context router.Context) error {

	// Authorise
	err := authorise.Path(context)
	if err != nil {
		return router.NotAuthorizedError(err)
	}

	// Render the template
	view := view.New(context)
	page := pages.New()
	view.AddKey("page", page)

	return view.Render()
}