mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-01-20 06:08:21 +00:00
improve local UI testing and ability for pluggable UI
This commit is contained in:
parent
c867bcaf3c
commit
39b74e172e
3 changed files with 67 additions and 17 deletions
9
server/template/files/script.html
Normal file
9
server/template/files/script.html
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
|
||||||
|
<script>
|
||||||
|
window.ENV = {};
|
||||||
|
window.ENV.server = window.location.protocol+"//"+window.location.host;
|
||||||
|
{{ if .csrf }}window.ENV.csrf = "{{ .csrf }}"{{ end }}
|
||||||
|
{{ if .user }}
|
||||||
|
window.USER = {{ json .user }};
|
||||||
|
{{ end }}
|
||||||
|
</script>
|
|
@ -22,6 +22,9 @@ var files = []struct {
|
||||||
}, {
|
}, {
|
||||||
name: "logout.html",
|
name: "logout.html",
|
||||||
data: logout,
|
data: logout,
|
||||||
|
}, {
|
||||||
|
name: "script.html",
|
||||||
|
data: script,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,25 +66,39 @@ var error = `<!DOCTYPE html>
|
||||||
|
|
||||||
// files/index.html
|
// files/index.html
|
||||||
var index = `<!DOCTYPE html>
|
var index = `<!DOCTYPE html>
|
||||||
<html>
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8"/>
|
<meta charset="utf-8">
|
||||||
<meta content="width=device-width, initial-scale=1" name="viewport"/>
|
<meta name="author" content="bradrydzewski">
|
||||||
<meta content="ie=edge" http-equiv="x-ua-compatible"/>
|
<meta name="viewport" content="width=device-width, minimum-scale=1, initial-scale=1, user-scalable=yes">
|
||||||
{{ if .csrf }}<meta name="csrf-token" content="{{ .csrf }}" />{{ end }}
|
|
||||||
<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet"/>
|
<link rel="shortcut icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
|
||||||
<link href="https://fonts.googleapis.com/css?family=Roboto+Mono" rel="stylesheet"/>
|
<link rel="shortcut icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
|
||||||
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet"/>
|
|
||||||
<link href="/static/app.css" rel="stylesheet"/>
|
<title></title>
|
||||||
<link href="/static/favicon.ico" rel="icon" type="image/x-icon"/>
|
<script>
|
||||||
|
window.ENV = {};
|
||||||
|
window.ENV.server = window.location.protocol+"//"+window.location.host;
|
||||||
|
{{ if .csrf }}window.ENV.csrf = "{{ .csrf }}"{{ end }}
|
||||||
|
{{ if .user }}
|
||||||
|
window.USER = {{ json .user }};
|
||||||
|
{{ end }}
|
||||||
|
</script>
|
||||||
|
<script src="/bower_components/webcomponentsjs/webcomponents-loader.js"></script>
|
||||||
|
|
||||||
|
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto">
|
||||||
|
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto+Mono">
|
||||||
|
<link rel="import" href="/src/drone/drone-app.html">
|
||||||
|
|
||||||
|
<style>
|
||||||
|
html, body {
|
||||||
|
padding:0px;
|
||||||
|
margin:0px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="app"></div>
|
<drone-app></drone-app>
|
||||||
<script>
|
|
||||||
window.STATE_FROM_SERVER={{ . | json }};
|
|
||||||
</script>
|
|
||||||
<script src="https://code.getmdl.io/1.1.3/material.min.js"></script>
|
|
||||||
<script src="/static/app.js"></script>
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
`
|
`
|
||||||
|
@ -167,3 +184,15 @@ var login = `<!DOCTYPE html>
|
||||||
// files/logout.html
|
// files/logout.html
|
||||||
var logout = `LOGOUT
|
var logout = `LOGOUT
|
||||||
`
|
`
|
||||||
|
|
||||||
|
// files/script.html
|
||||||
|
var script = `
|
||||||
|
<script>
|
||||||
|
window.ENV = {};
|
||||||
|
window.ENV.server = window.location.protocol+"//"+window.location.host;
|
||||||
|
{{ if .csrf }}window.ENV.csrf = "{{ .csrf }}"{{ end }}
|
||||||
|
{{ if .user }}
|
||||||
|
window.USER = {{ json .user }};
|
||||||
|
{{ end }}
|
||||||
|
</script>
|
||||||
|
`
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/drone/drone/model"
|
"github.com/drone/drone/model"
|
||||||
"github.com/drone/drone/server/template"
|
"github.com/drone/drone/server/template"
|
||||||
|
@ -49,7 +52,15 @@ func (w *local) Page(rw http.ResponseWriter, r *http.Request, u *model.User) {
|
||||||
"csrf": csrf,
|
"csrf": csrf,
|
||||||
}
|
}
|
||||||
|
|
||||||
template.T.ExecuteTemplate(rw, "index_polymer.html", params)
|
index, err := ioutil.ReadFile(filepath.Join(w.dir, "index.html"))
|
||||||
|
if err != nil {
|
||||||
|
rw.WriteHeader(404)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var buf bytes.Buffer
|
||||||
|
template.T.ExecuteTemplate(&buf, "script.html", params)
|
||||||
|
index = bytes.Replace(index, []byte("<!-- inject:js -->"), buf.Bytes(), 1)
|
||||||
|
rw.Write(index)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,5 +75,6 @@ func (w *local) Routes() []string {
|
||||||
"/favicon-16x16.png",
|
"/favicon-16x16.png",
|
||||||
"/src/*filepath",
|
"/src/*filepath",
|
||||||
"/bower_components/*filepath",
|
"/bower_components/*filepath",
|
||||||
|
"/static/*filepath",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue