Пример #1
0
//Upload renders the new presentation upload page.
func Upload(c util.Context) (err error) {
	uploadURL, err := blobstore.UploadURL(c, "/admin/presentation/upload", nil)
	if err != nil {
		return
	}

	acts, err := activation.GetAfterTime(time.Now(), c)
	if err != nil {
		return
	}

	type actWithName struct {
		A *activation.Activation
		P *presentation.Presentation
	}

	ans := make([]actWithName, len(acts))

	for i, a := range acts {
		pk := a.Presentation
		var p *presentation.Presentation
		p, err = presentation.GetByKey(pk, c)
		if err != nil {
			c.Errorf("Could not load presentation: %v", err)
			continue
		}
		ans[i] = actWithName{a, p}
	}

	util.RenderLayout("upload.html", "Nahrať prezentáciu", struct {
		UploadURL *url.URL
		Ans       []actWithName
	}{uploadURL, ans}, c)
	return
}
Пример #2
0
//Presentation handles showing page with details about a presentation.
func Presentation(c util.Context) (err error) {
	pk, err := datastore.DecodeKey(c.Vars["id"])
	if err != nil {
		return
	}

	p, err := presentation.GetByKey(pk, c)
	if err != nil {
		return
	}
	as, err := action.GetFor(p, c)
	if err != nil {
		return
	}

	a := prepareActions(as)

	desc := blackfriday.MarkdownCommon(p.Description)

	acts, err := activation.GetForPresentation(pk, c)
	if err != nil {
		return
	}

	util.RenderLayout("presentation.html", "Info o prezentácií", struct {
		P           *presentation.Presentation
		A           map[string][]time.Time
		Desc        template.HTML
		ZeroTime    time.Time
		Domain      string
		Activations []*activation.Activation
		Tz          *time.Location
	}{p, a, template.HTML(desc), time.Date(0001, 01, 01, 00, 00, 00, 00, utc), appengine.DefaultVersionHostname(c), acts, util.Tz}, c, "/static/js/underscore-min.js", "/static/js/presentation.js")
	return
}
Пример #3
0
//TimeOverrideEdit handles editing of existing time overrides.
//If it doesn't find id value in the path, it adds a new override.
func TimeOverrideEdit(c util.Context) (err error) {
	var tc *timeConfig.TimeConfig
	if key := c.Vars["id"]; key == "" {
		tc = nil
	} else {
		var k *datastore.Key
		k, err = datastore.DecodeKey(key)
		if err != nil {
			return
		}

		tc, err = timeConfig.GetByKey(k, c)
		if err != nil {
			return
		}
	}
	c.Infof("%+v", tc)
	util.RenderLayout("timeConfigEdit.html", "Úprava výnimky", tc, c, "/static/js/editTC.js")
	return
}
Пример #4
0
//Archive handles showing listing of presentations.
func Archive(c util.Context) (err error) {
	page, err := strconv.Atoi(c.Vars["page"])
	if err != nil {
		return
	}

	type tmplData struct {
		P *presentation.Presentation
		C int
	}
	ps, err := presentation.GetListing(page, 10, c)
	if err != nil {
		return
	}

	downloads := make([]tmplData, 0)
	for _, p := range ps {
		count, err := action.GetCountFor(action.Activated, p, c)
		if err != nil {
			c.Infof("Error when getting download count: %v", err)
			count = -1
		}
		downloads = append(downloads, tmplData{p, count})
	}

	maxPages, err := presentation.PageCount(10, c)
	if err != nil {
		return
	}

	util.RenderLayout("archive.html", "Archív prezentácií", struct {
		Data     []tmplData
		Page     int
		MaxPages int
		Tz       *time.Location
	}{downloads, page, maxPages, util.Tz}, c)
	return
}
Пример #5
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
}
Пример #6
0
//Presentations shows listing of presentations in paginated form.
func Presentations(c util.Context) (err error) {
	page, err := strconv.Atoi(c.R.FormValue("p"))
	if err != nil {
		return
	}
	ps, err := presentation.GetListing(page, perPage, c)
	if err != nil {
		return
	}

	type templateData struct {
		P presentation.Presentation
		D template.HTML
	}

	data := make([]templateData, len(ps), len(ps))

	for _, p := range ps {
		data = append(data, templateData{P: *p, D: template.HTML(blackfriday.MarkdownCommon(p.Description))})
	}

	maxPages, err := presentation.PageCount(perPage, c)
	if err != nil {
		return
	}

	c.Infof("Hostname: %v", appengine.DefaultVersionHostname(c))

	util.RenderLayout("index.html", "Zoznam vysielaní", struct {
		Page     int
		MaxPages int
		Data     []templateData
		Domain   string
	}{Page: page, MaxPages: maxPages, Data: data, Domain: appengine.DefaultVersionHostname(c)}, c, "/static/js/index.js")
	return
}