Example #1
0
//JSON returns JSON representation of config and time override settings
//for use in clients.
func JSON(c appengine.Context) (js []byte, err error) {
	j := make(map[string]interface{})
	conf, err := config.Get(c)
	if err != nil {
		return
	}

	tcs, err := timeConfig.GetAll(c)
	if err != nil {
		return
	}

	j["StandardTimeSettings"] = map[string]string{
		"TurnOn":  conf.StandardOn.Format(jsonTimeFormat),
		"TurnOff": conf.StandardOff.Format(jsonTimeFormat),
	}
	j["UpdateInterval"] = conf.UpdateInterval
	switch conf.OverrideState {
	case config.NoOverride:
		j["OverrideOn"] = false
		j["OverrideOff"] = false
	case config.OverrideOn:
		j["OverrideOn"] = true
		j["OverrideOff"] = false
	case config.OverrideOff:
		j["OverrideOn"] = false
		j["OverrideOff"] = true
	}

	j["Weekends"] = conf.Weekends

	j["OverrideDays"] = make(map[string]map[string]string)
	for _, tc := range tcs {
		timeMap := make(map[string]string)
		timeMap["TurnOn"] = tc.On.Format(jsonTimeFormat)
		timeMap["TurnOff"] = tc.Off.Format(jsonTimeFormat)

		j["OverrideDays"].(map[string]map[string]string)[tc.Date.Format(jsonDateFormat)] = timeMap
	}

	j["Timestamp"] = conf.Timestamp

	js, err = json.Marshal(j)
	return
}
Example #2
0
//ShowConfig handles showing the page where user can see and edit
//the central configuration for clients.
func ShowConfig(c util.Context) (err error) {
	conf, err := config.Get(c)
	if err != nil {
		if err == datastore.Done {
			conf, err = mkConfig(c)
			if err != nil {
				c.Errorf("Error when creating new config: %v", err)
			}
			http.Redirect(c.W, c.R, "/admin/config", 303)
			err = nil
			return
		} else {
			return
		}
	}

	as, err := action.GetFor(conf, c)
	if err != nil {
		return
	}

	tcs, err := timeConfig.GetAll(c)
	if err != nil {
		return
	}

	a := prepareActions(as)

	util.RenderLayout("config.html", "Všeobecné nastavenia", struct {
		Conf     *config.Config
		A        map[string][]time.Time
		ZeroTime time.Time
		Tz       *time.Location
		Tcs      []*timeConfig.TimeConfig
	}{conf, a, time.Date(0001, 01, 01, 00, 00, 00, 00, utc), util.Tz, tcs}, c, "/static/js/config.js")
	return
}