(merge this second) (#1530)
* Update template_functions.go * Update template_test.go * Update admin.jet.html * Update template_test.go * right file * Update template_functions_test.go * forgot a } * Update admin.jet.html * Update template_functions_test.go * Update template_functions.go * Update template_functions.go
Cette révision appartient à :
Parent
ee61a9a54c
révision
548a0df333
3 fichiers modifiés avec 54 ajouts et 3 suppressions
|
@ -1,10 +1,10 @@
|
|||
<div id="admin-header">
|
||||
<a href="{{URL.Parse("/mod/")}}" class="nav-btn{{if URL.String() == "/mod/"}} active{{end}}">{{ T("moderation")}}</a>
|
||||
<a href="{{URL.Parse("/mod/torrents")}}" class="nav-btn{{if len(URL.String()) > 11}}{{if URL.String()[:12] == "/mod/torrent"}} active{{end}}{{end}}">{{ T("torrents")}}</a>
|
||||
<a href="{{URL.Parse("/mod/torrents")}}" class="nav-btn{{if kilo_strcmp(URL.String(), "/mod/torrent", 12,5) }} active{{end}}">{{ T("torrents")}}</a>
|
||||
<a href="{{URL.Parse("/mod/users")}}" class="nav-btn{{if URL.String() == "/mod/users"}} active{{end}}">{{ T("users")}}</a>
|
||||
<a href="{{URL.Parse("/mod/comments")}}" class="nav-btn{{if URL.String() == "/mod/comments"}} active{{end}}">{{ T("comments")}}</a>
|
||||
<a href="{{URL.Parse("/mod/oauth_client")}}" class="nav-btn{{if len(URL.String()) > 16}}{{ if URL.String()[:17] == "/mod/oauth_client"}} active{{end}}{{end}}">{{ T("oauth_clients_list")}}</a>
|
||||
<a href="{{URL.Parse("/mod/announcement")}}" class="nav-btn{{if len(URL.String()) > 16}}{{ if URL.String()[:17] == "/mod/announcement"}} active{{end}}{{end}}">{{ T("announcements")}}</a>
|
||||
<a href="{{URL.Parse("/mod/oauth_client")}}" class="nav-btn{{if kilo_strcmp(URL.String(), "/mod/oauth_client", 17, 5) }} active{{end}}">{{ T("oauth_clients_list")}}</a>
|
||||
<a href="{{URL.Parse("/mod/announcement")}}" class="nav-btn{{if kilo_strcmp(URL.String(), "/mod/announcement", 17, 5) }} active{{end}}">{{ T("announcements")}}</a>
|
||||
<a href="{{URL.Parse("/mod/reports")}}" class="nav-btn{{if URL.String() == "/mod/reports"}} active{{end}}">{{ T("torrent_reports")}}</a>
|
||||
<a href="{{URL.Parse("/mod/reassign")}}" class="nav-btn{{if URL.String() == "/mod/reassign"}} active{{end}}">{{ T("torrent_reassign")}}</a>
|
||||
</div>
|
||||
|
|
|
@ -49,6 +49,7 @@ func templateFunctions(vars jet.VarMap) jet.VarMap {
|
|||
vars.Set("genUploaderLink", genUploaderLink)
|
||||
vars.Set("genActivityContent", genActivityContent)
|
||||
vars.Set("contains", contains)
|
||||
vars.Set("kilo_strcmp", kilo_strcmp)
|
||||
return vars
|
||||
}
|
||||
func getRawQuery(currentURL *url.URL) string {
|
||||
|
@ -304,3 +305,27 @@ func torrentFileExists(hash string) bool {
|
|||
defer Openfile.Close()
|
||||
return true
|
||||
}
|
||||
|
||||
func kilo_strcmp(str1 string, str2 string, end int, start int) bool {
|
||||
//Compare two strings but has length arguments
|
||||
|
||||
len1 := len(str1)
|
||||
len2 := len(str2)
|
||||
|
||||
if end == -1 && len1 != len2 {
|
||||
return false
|
||||
}
|
||||
|
||||
if end == -1 || end > len1 {
|
||||
end = len1
|
||||
}
|
||||
if end > len2 {
|
||||
end = len2
|
||||
}
|
||||
|
||||
if start >= end {
|
||||
return false
|
||||
}
|
||||
|
||||
return strings.Compare(str1[start:end], str2[start:end]) == 0
|
||||
}
|
||||
|
|
|
@ -606,6 +606,31 @@ func testTorrentFileExists(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func Testkilo_strcmp(t *testing.T) {
|
||||
var tests = []struct {
|
||||
TestString string
|
||||
TestString2 string
|
||||
Expected bool
|
||||
}{
|
||||
{
|
||||
TestString: "kilo",
|
||||
TestString2: "kilo",
|
||||
Expected: true,
|
||||
},
|
||||
{
|
||||
TestString: "kilo",
|
||||
TestString2: "loki", // Clearly not the same level
|
||||
Expected: false,
|
||||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
value := kilo_strcmp(test.TestString, test.TestString2, -1, 0)
|
||||
if value != test.Expected {
|
||||
t.Errorf("Unexpected value from the function languageName, got '%t', wanted '%t'", value, test.Expected, test.TestString, test.TestString)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func mockupTemplateT(t *testing.T) publicSettings.TemplateTfunc {
|
||||
conf := config.Get().I18n
|
||||
conf.Directory = path.Join("..", conf.Directory)
|
||||
|
@ -626,3 +651,4 @@ func mockupTemplateT(t *testing.T) publicSettings.TemplateTfunc {
|
|||
}
|
||||
return T
|
||||
}
|
||||
|
||||
|
|
Référencer dans un nouveau ticket