Example #1
0
File: top.go Project: Laller/nocrud
func (t *Top) route() (err error) {
	defer func() {
		if r := recover(); r != nil {
			err = fmt.Errorf(fmt.Sprint(r) + string(debug.Stack()))
		}
	}()
	ctx := t.ctx
	odoc := ctx.Options().Document()
	nouns := scut.GetNouns(odoc)
	np := ctx.NonPortable()
	hl, err := highlev.New(ctx.Conducting().Hooks(), np.Resource(), nouns, np.Params())
	if err != nil {
		display.New(ctx).Do(nil)
		return nil
	}
	deflev_i, _ := odoc.Get("default_level")
	deflev, _ := numcon.Int(deflev_i)
	ret, err := hl.Run(ctx.Db(), ctx.User(), deflev)
	if err != nil {
		return err
	}
	if ctx.NonPortable().View() {
		ctx.ViewContext().Publish("main_noun", hl.Noun())
		files := []string{
			hl.Noun() + "/" + hl.Verb(),
			hl.VerbLocation() + "/" + hl.Verb(),
		}
		return t.Get(ret, files)
	} else {
		return t.Post(ret, hl.Verb())
	}
	return nil
}
Example #2
0
func form(ctx iface.Context, action_name string) *Form {
	nouns := scut.GetNouns(ctx.Options().Document())
	np := ctx.NonPortable()
	hl, err := highlev.New(ctx.Conducting().Hooks(), np.Resource(), nouns, np.Params())
	if err != nil {
		panic(err)
	}
	f := hl.URLE().Form(action_name)
	return &Form{
		f,
	}
}
Example #3
0
func _url(ctx iface.Context, action_name string, i ...interface{}) string {
	if len(i)%2 == 1 {
		panic("Must be even.")
	}
	nouns := scut.GetNouns(ctx.Options().Document())
	np := ctx.NonPortable()
	hl, err := highlev.New(ctx.Conducting().Hooks(), np.Resource(), nouns, np.Params())
	if err != nil {
		panic(err)
	}
	f := hl.URLE()
	inp := convert.ListToMap(i...)
	return f.UrlString(action_name, inp)
}
Example #4
0
func getList(ctx iface.Context, noun string, params ...interface{}) []interface{} {
	nouns, ok := ctx.Options().Document().GetM("nouns")
	if !ok {
		panic("Can't find nouns.")
	}
	inp := convert.ListToMap(params...)
	hl, err := highlev.New(ctx.Conducting().Hooks(), "/"+noun, nouns, inp)
	if err != nil {
		panic(err)
	}
	deflev_i, _ := ctx.Options().Document().Get("default_level")
	deflev, _ := numcon.Int(deflev_i)
	ret, err := hl.Run(ctx.Db(), ctx.User(), deflev)
	if err != nil {
		panic(err)
	}
	return ret
}
Example #5
0
File: top.go Project: Laller/nocrud
func (t *Top) routeWS() (err error) {
	defer func() {
		if r := recover(); r != nil {
			err = fmt.Errorf(fmt.Sprint(r) + string(debug.Stack()))
		}
	}()
	ctx := t.ctx
	odoc := ctx.Options().Document()
	nouns, ok := odoc.GetM("nouns")
	if !ok {
		return fmt.Errorf("No nouns, cant route websocket.")
	}
	np := ctx.NonPortable()
	hl, err := highlev.New(ctx.Conducting().Hooks(), np.Resource(), nouns, np.Params())
	if err != nil {
		return err
	}
	deflev_i, _ := odoc.Get("default_level")
	deflev, _ := numcon.Int(deflev_i)
	_, err = hl.Run(ctx.Db(), ctx.User(), deflev)
	return err
}
Example #6
0
// Works from Get or GetSingle only.
func getSub(ctx iface.Context, noun string, params ...interface{}) []interface{} {
	nouns, ok := ctx.Options().Document().GetM("nouns")
	if !ok {
		panic("Can't find nouns.")
	}
	np := ctx.NonPortable()
	hl, err := highlev.New(ctx.Conducting().Hooks(), np.Resource(), nouns, np.Params())
	if err != nil {
		panic(err)
	}
	inp := convert.ListToMap(params...)
	subhl, err := hl.Sub(noun, inp)
	if err != nil {
		panic(err)
	}
	deflev_i, _ := ctx.Options().Document().Get("defaultLevel")
	deflev, _ := numcon.Int(deflev_i)
	ret, err := subhl.Run(ctx.Db(), ctx.User(), deflev)
	if err != nil {
		panic(err)
	}
	return ret
}