Beispiel #1
0
func (e *Entries) Init(ctx iface.Context) {
	e.db = ctx.Db()
	e.userId = ctx.User().Id()
	e.userIsProfessional = isProfessional(ctx.User())
	e.optDoc = ctx.Options().Document()
	e.timeTableColl = "timeTables"
	e.intervalColl = "intervals"
}
Beispiel #2
0
func (tt *TimeTable) Init(ctx iface.Context) {
	tt.db = ctx.Db()
	tt.userId = ctx.User().Id()
	tt.userIsProfessional = isProfessional(ctx.User())
	tt.optDoc = ctx.Options().Document()
	tt.timeTableColl = "timeTables"
	tt.intervalColl = "intervals"
}
Beispiel #3
0
// We must recreate this map each time because map write is not threadsafe.
// Write will happen when a hook modifies the map (hook call is not implemented yet).
func builtins(ctx iface.Context) map[string]interface{} {
	viewCtx := ctx.ViewContext().Get()
	user := ctx.User()
	ret := map[string]interface{}{
		"get": func(s ...string) interface{} {
			return get(viewCtx, s...)
		},
		"date": date,
		"is_stranger": func() bool {
			return user.Level() == 0
		},
		"logged_in": func() bool {
			return user.Level() > 0
		},
		"is_moderator": func() bool {
			return user.Level() >= 200
		},
		"is_admin": func() bool {
			return user.Level() >= 300
		},
		"is_map":       isMap,
		"eq":           eq,
		"html":         html,
		"format_float": formatFloat,
		"fallback":     fallback,
		"type_of":      typeOf,
		"same_kind":    sameKind,
		"title":        strings.Title,
		"url": func(action_name string, i ...interface{}) string {
			return _url(ctx, action_name, i...)
		},
		"form": func(action_name string) *Form {
			return form(ctx, action_name)
		},
		"counter": newcounter,
		"get_sub": func(str string, params ...interface{}) []interface{} {
			return getSub(ctx, str, params...)
		},
		"get_list": func(str string, params ...interface{}) []interface{} {
			return getList(ctx, str, params...)
		},
		"elem": elem,
		"pager": func(pagesl []string, count, limited int) []paging.Pelem {
			var pagestr string
			if len(pagesl) == 0 {
				pagestr = "1"
			} else {
				pagestr = pagesl[0]
			}
			return pager(ctx, pagestr, count, limited)
		},
	}
	ctx.Conducting().Hooks().Select("AddTemplateBuiltin").Fire(ret)
	return ret
}
Beispiel #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
}
Beispiel #5
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
}
Beispiel #6
0
// We must recreate this map each time because map write is not threadsafe.
// Write will happen when a hook modifies the map (hook call is not implemented yet).
func builtins(ctx iface.Context) map[string]interface{} {
	viewCtx := ctx.ViewContext().Get()
	user := ctx.User()
	ret := map[string]interface{}{
		"get": func(s ...string) interface{} {
			return getMap(viewCtx, s...)
		},
		"getMap": getMap,
		"date":   date,
		"isStranger": func() bool {
			return user.Level() == 0
		},
		"loggedIn": func() bool {
			return user.Level() > 0
		},
		"isModerator": func() bool {
			return user.Level() >= 200
		},
		"isAdmin": func() bool {
			return user.Level() >= 300
		},
		"isMap":       isMap,
		"eq":          eq,
		"html":        html,
		"formatFloat": formatFloat,
		"newMap":      newMap,
		"newSlice":    newSlice,
		"fallback":    fallback,
		"typeOf":      typeOf,
		"sameKind":    sameKind,
		"title":       strings.Title,
		"url": func(action_name string, i ...interface{}) string {
			return _url(ctx, action_name, i...)
		},
		"form": func(action_name string) *Form {
			return form(ctx, action_name)
		},
		"counter": newcounter,
		"getSub": func(str string, params ...interface{}) []interface{} {
			return getSub(ctx, str, params...)
		},
		"getList": func(str string, params ...interface{}) []interface{} {
			return getList(ctx, str, params...)
		},
		"concat": concat,
		"index":  index,
		"pager": func(page interface{}, count, limited int) []paging.Pelem {
			var pagestr string
			if page == nil {
				pagestr = "1"
			} else {
				pagestr = page.(string)
			}
			return pager(ctx, pagestr, count, limited)
		},
		"len":     _len,
		"setMap":  setMap,
		"inSlice": inSlice,
		"hook": func(hookName string) *hook {
			return selectHook(ctx, hookName)
		},
		"indentedJSON": indentedJSON,
	}
	ctx.Conducting().Hooks().Select("AddTemplateBuiltin").Fire(ret)
	return ret
}