//GotConfig is called by clients to announce that //they have downloaded the broadcast. func GotConfig(c util.Context) (err error) { conf, err := config.Get(c) if err != nil { return } action.Log(conf, action.Activated, c.R.FormValue("client"), c) return }
//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 }
//Status returns information about active broadcasts and //config. It returns a JSON like: // { // "Broadcasts": [ // { // "Key": "aghkZXZ-Tm9uZXIZCxIMUHJlc2VudGF0aW9uGICAgICAgIAKDA", // "FileType": "pptx" // }, // { // "Key": "aghkZXZ-Tm9uZXIZCxIMUHJlc2VudGF0aW9uGICAgICAwO8KDA", // "FileType": "ppt" // } // ] // "Config": 1383212550 // } func Status(c util.Context) (err error) { type broadcastInfo struct { Key string FileType string } type updateInfo struct { Broadcasts []broadcastInfo Config int64 } ui := updateInfo{} ps, err := presentation.GetActive(c) if err != nil { return } ui.Broadcasts = make([]broadcastInfo, len(ps)) for i, p := range ps { ui.Broadcasts[i] = broadcastInfo{Key: p.Key().Encode(), FileType: p.FileType} } conf, err := config.Get(c) if err != nil { return } ui.Config = conf.Timestamp data, err := json.Marshal(ui) if err != nil { return } fmt.Fprint(c.W, string(data)) return }
//SetConfig handles saving the new configuration to Datastore. func SetConfig(c util.Context) (err error) { conf, err := config.Get(c) if err != nil { return } on, err := time.Parse(timeFormat, c.R.FormValue("standardOn")) if err != nil { return } off, err := time.Parse(timeFormat, c.R.FormValue("standardOff")) if err != nil { return } conf.OverrideState, err = strconv.Atoi(c.R.FormValue("overrideState")) if err != nil { return } conf.UpdateInterval, err = strconv.Atoi(c.R.FormValue("updateInterval")) if err != nil { return } if c.R.FormValue("weekends") == "true" { conf.Weekends = true } conf.StandardOn = util.NormalizeTime(on) conf.StandardOff = util.NormalizeTime(off) err = conf.Save(c) if err != nil { return } http.Redirect(c.W, c.R, "/admin/config", 303) return }
//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 }