rebuilding js

Former-commit-id: 027e2f6546614d28750e437b9a3545cb95235d9d [formerly 6dbfe621a5774304295c17f216b5c96beaaaa95a] [formerly d44822f30d9a3649b20daa7a3cdbf86c87e63c99 [formerly 3258552349]]
Former-commit-id: 7f34ddc1b32076c6ad2c2a4374b170b7f5d84000 [formerly aaafd299a933d25ebcb5fdebe1b00cb9e8309d7a]
Former-commit-id: 7bb183c165ba2c9711ba1c04e3af6e2048245ded
This commit is contained in:
Henrique Dias
2017-06-27 19:00:58 +01:00
parent 1e99d3d7c1
commit 826d491ff1
20 changed files with 11576 additions and 1816 deletions

73
page.go
View File

@@ -7,6 +7,7 @@ import (
"html/template"
"log"
"net/http"
"strconv"
"strings"
rice "github.com/GeertJohan/go.rice"
@@ -32,16 +33,13 @@ var functions = template.FuncMap{
// page contains the information needed to fill a page template.
type page struct {
minimal bool
User *User
Name string
Path string
IsDir bool
User *User
PrefixURL string
BaseURL string
WebDavURL string
IsEditor bool
Data interface{}
Editor bool
Display string
}
// breadcrumbItem contains the Name and the URL of a breadcrumb piece.
@@ -53,6 +51,7 @@ type breadcrumbItem struct {
// BreadcrumbMap returns p.Path where every element is a map
// of URLs and path segment names.
func (p page) BreadcrumbMap() []breadcrumbItem {
// TODO: when it is preview alongside with listing!!!!!!!!!!
result := []breadcrumbItem{}
if len(p.Path) == 0 {
@@ -102,8 +101,8 @@ func (p page) PreviousLink() string {
return path
}
// PrintAsHTML formats the page in HTML and executes the template
func (p page) PrintAsHTML(w http.ResponseWriter, box *rice.Box, templates ...string) (int, error) {
// PrintHTML formats the page in HTML and executes the template
func (p page) PrintHTML(w http.ResponseWriter, box *rice.Box, templates ...string) (int, error) {
templates = append(templates, "actions")
templates = append(templates, "templates")
@@ -153,7 +152,7 @@ func (p page) PrintAsHTML(w http.ResponseWriter, box *rice.Box, templates ...str
}
// PrintAsJSON prints the current Page information in JSON
func (p page) PrintAsJSON(w http.ResponseWriter) (int, error) {
func (p page) PrintJSON(w http.ResponseWriter) (int, error) {
marsh, err := json.MarshalIndent(p.Data, "", " ")
if err != nil {
return http.StatusInternalServerError, err
@@ -166,3 +165,61 @@ func (p page) PrintAsJSON(w http.ResponseWriter) (int, error) {
return http.StatusOK, nil
}
// htmlError prints the error page
func htmlError(w http.ResponseWriter, code int, err error) (int, error) {
tpl := errTemplate
tpl = strings.Replace(tpl, "TITLE", strconv.Itoa(code)+" "+http.StatusText(code), -1)
tpl = strings.Replace(tpl, "CODE", err.Error(), -1)
_, err = w.Write([]byte(tpl))
if err != nil {
return http.StatusInternalServerError, err
}
return http.StatusOK, nil
}
const errTemplate = `<!DOCTYPE html>
<html>
<head>
<title>TITLE</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta charset="utf-8">
<style>
html {
background-color: #2196f3;
color: #fff;
font-family: sans-serif;
}
code {
background-color: rgba(0,0,0,0.1);
border-radius: 5px;
padding: 1em;
display: block;
box-sizing: border-box;
}
.center {
max-width: 40em;
margin: 2em auto 0;
}
a {
text-decoration: none;
color: #eee;
font-weight: bold;
}
p {
line-height: 1.3;
}
</style>
</head>
<body>
<div class="center">
<h1>TITLE</h1>
<p>Try reloading the page or hitting the back button. If this error persists, it seems that you may have found a bug! Please create an issue at <a href="https://github.com/hacdias/caddy-filemanager/issues">hacdias/caddy-filemanager</a> repository on GitHub with the code below.</p>
<code>CODE</code>
</div>
</html>`