-
Notifications
You must be signed in to change notification settings - Fork 0
/
pagelist.go
79 lines (61 loc) · 2.22 KB
/
pagelist.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
package pagelist
import (
"html/template"
"net/http"
"github.com/dekoch/gouniversal/module/s7backup/global"
"github.com/dekoch/gouniversal/module/s7backup/lang"
"github.com/dekoch/gouniversal/module/s7backup/plcconfig"
"github.com/dekoch/gouniversal/module/s7backup/typemd"
"github.com/dekoch/gouniversal/program/usermanagement"
"github.com/dekoch/gouniversal/shared/alert"
"github.com/dekoch/gouniversal/shared/functions"
"github.com/dekoch/gouniversal/shared/navigation"
)
func RegisterPage(page *typemd.Page, nav *navigation.Navigation) {
nav.Sitemap.Register(page.Lang.BackupList.Menu, "App:S7Backup:Backup:List", page.Lang.BackupList.Title)
}
func Render(page *typemd.Page, nav *navigation.Navigation, r *http.Request) {
type Content struct {
Lang lang.BackupList
PLCList template.HTML
}
var c Content
c.Lang = page.Lang.BackupList
var (
backupDisabled string
restoreDisabled string
)
if usermanagement.IsPageAllowed("App:S7Backup:Backup:Backup", nav.User) == false {
backupDisabled = " disabled"
}
if usermanagement.IsPageAllowed("App:S7Backup:Backup:Restore", nav.User) == false {
restoreDisabled = " disabled"
}
files, err := plcconfig.GetPLCList(global.Config.GetFileRoot())
if err != nil {
alert.Message(alert.ERROR, page.Lang.Alert.Error, err, "", nav.User.UUID)
}
tbody := ""
for _, file := range files {
var pc plcconfig.PLCConfig
_, err := pc.Load(global.Config.GetFileRoot(), file)
if err != nil {
continue
}
if len(pc.DB) == 0 {
continue
}
tbody += "<tr>"
tbody += "<td>" + pc.Name + "</td>"
tbody += "<td><button class=\"btn btn-default fa fa-database\" type=\"submit\" name=\"navigation\" value=\"App:S7Backup:Backup:Backup$UUID=" + pc.UUID + "\" title=\"" + c.Lang.Backup + "\"" + backupDisabled + "></button></td>"
tbody += "<td><button class=\"btn btn-default fa fa-microchip\" type=\"submit\" name=\"navigation\" value=\"App:S7Backup:Backup:Restore$UUID=" + pc.UUID + "\" title=\"" + c.Lang.Restore + "\"" + restoreDisabled + "></button></td>"
tbody += "</tr>"
}
c.PLCList = template.HTML(tbody)
p, err := functions.PageToString(global.Config.UIFileRoot+"backuplist.html", c)
if err == nil {
page.Content += p
} else {
nav.RedirectPath("404", true)
}
}