-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhandlers.html.go
82 lines (74 loc) · 1.9 KB
/
handlers.html.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package main
import (
"net/http"
"strconv"
"github.com/gin-gonic/gin"
)
/**
* Main page
*/
func MainPage(c *gin.Context) {
c.HTML(http.StatusOK, "index.tmpl", gin.H{
"title": "Pojects",
"projects": GetProjects(dbFile),
"wasProjectDeleted": len(c.Query("projectdeleted")) > 0,
"is_logged_in": IsLoggedIn(c),
})
}
/**
* "Add new project" page
*/
func AddNewProjectForm(c *gin.Context) {
c.HTML(http.StatusOK, "add-new-project.tmpl", gin.H{})
}
/**
* Create new Project
*/
func PostCreateNewProject(c *gin.Context) {
name := c.PostForm("name")
country := c.PostForm("country")
project := CreateNewProject(dbFile, name, country)
c.Redirect(http.StatusMovedPermanently, "/project/"+strconv.Itoa(project.ID))
}
/**
* Get one given project
*/
func GetOneProject(c *gin.Context) {
id, _ := strconv.Atoi(c.Param("id"))
project := FindOneProject(dbFile, id, "")
c.HTML(http.StatusOK, "project.tmpl", gin.H{
"title": "Poject " + project.Name,
"projectId": id,
"currentLang": "all",
"project": project,
"wasTermDeleted": len(c.Query("termDeleted")) > 0,
"is_logged_in": IsLoggedIn(c),
})
}
/**
* Get one project with only untranslated terms
*/
func GetOneProjectUntranslated(c *gin.Context) {
id, _ := strconv.Atoi(c.Param("id"))
countryCode := c.Param("lang")
c.HTML(http.StatusOK, "project.tmpl", gin.H{
"title": "Untranslated from " + countryCode,
"currentLang": countryCode,
"projectId": id,
"project": FindOneProject(dbFile, id, countryCode),
"wasTermDeleted": len(c.Query("termDeleted")) > 0,
"is_logged_in": IsLoggedIn(c),
})
}
/**
* Get all the translations for given term
*/
func GetAllTranslations(c *gin.Context) {
id, _ := strconv.Atoi(c.Param("id"))
term := GetTerm(dbFile, id)
c.HTML(http.StatusOK, "term.tmpl", gin.H{
"title": "All translations",
"term": term,
"termId": id,
})
}