admin time series
This commit is contained in:
16
pixelapi/admin.go
Normal file
16
pixelapi/admin.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package pixelapi
|
||||
|
||||
// IsAdmin is the response to the /admin/is_admin API
|
||||
type IsAdmin struct {
|
||||
Success bool `json:"success"`
|
||||
IsAdmin bool `json:"is_admin"`
|
||||
}
|
||||
|
||||
// UserIsAdmin returns if the logged in user is an admin user
|
||||
func (p *PixelAPI) UserIsAdmin() (resp IsAdmin, err error) {
|
||||
err = p.jsonRequest("GET", p.apiEndpoint+"/admin/is_admin", &resp)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
@@ -249,7 +249,28 @@ var DetailsWindow = {
|
||||
document.getElementById('bandwidth_chart'),
|
||||
{
|
||||
type: 'line',
|
||||
data: response,
|
||||
data: {
|
||||
labels: response.labels,
|
||||
datasets: [
|
||||
{
|
||||
label: "Downloads",
|
||||
backgroundColor: "rgba(100, 255, 100, .4)",
|
||||
borderColor: "rgba(100, 255, 100, .8)",
|
||||
borderWidth: 2,
|
||||
fill: false,
|
||||
yAxisID: "y_bandwidth",
|
||||
data: response.downloads
|
||||
}, {
|
||||
label: "Views",
|
||||
backgroundColor: "rgba(128, 128, 255, .4)",
|
||||
borderColor: "rgba(128, 128, 255, .8)",
|
||||
borderWidth: 2,
|
||||
fill: false,
|
||||
yAxisID: "y_views",
|
||||
data: response.views
|
||||
}
|
||||
]
|
||||
},
|
||||
options: {
|
||||
stacked: false,
|
||||
aspectRatio: 2.5,
|
||||
@@ -271,7 +292,7 @@ var DetailsWindow = {
|
||||
}
|
||||
}, {
|
||||
type: "linear",
|
||||
display: true,
|
||||
display: false,
|
||||
position: "right",
|
||||
id: "y_views",
|
||||
scaleLabel: {
|
||||
|
@@ -7,13 +7,96 @@
|
||||
<script type="text/javascript">var apiEndpoint = '{{.APIEndpoint}}';</script>
|
||||
</head>
|
||||
<body>
|
||||
<img id="header_image" class="header_image" src="/res/img/header_neuropol.png" alt="Header image"/>
|
||||
<br/>
|
||||
<div id="body" class="body">
|
||||
{{$isAdmin := .PixelAPI.UserIsAdmin}}
|
||||
<div id="body" class="body" style="max-width: 100%">
|
||||
{{template "menu" .}}
|
||||
{{if $isAdmin.IsAdmin}}
|
||||
|
||||
<h1>System statistics</h1>
|
||||
<h3>Bandwidth and views</h3>
|
||||
<div id="chart_container" class="chart-container" style="position: relative; width: 100%; height: auto;">
|
||||
<canvas id="bandwidth_chart"></canvas>
|
||||
</div>
|
||||
|
||||
<script src="/res/script/jquery.js"></script>
|
||||
<script src="/res/misc/chartjs/Chart.min.js"></script>
|
||||
<script>
|
||||
$.get(apiEndpoint+"/admin/files/timeseries", function(response){
|
||||
console.log(response);
|
||||
if (response.success) {
|
||||
var ctx = document.getElementById('bandwidth_chart');
|
||||
Chart.defaults.global.defaultFontColor = "#b3b3b3";
|
||||
Chart.defaults.global.defaultFontSize = 16;
|
||||
Chart.defaults.global.defaultFontFamily = "Ubuntu";
|
||||
new Chart(
|
||||
document.getElementById('bandwidth_chart'),
|
||||
{
|
||||
type: 'line',
|
||||
data: {
|
||||
labels: response.labels,
|
||||
datasets: [
|
||||
{
|
||||
label: "Downloads",
|
||||
backgroundColor: "rgba(100, 255, 100, .4)",
|
||||
borderColor: "rgba(100, 255, 100, .8)",
|
||||
borderWidth: 2,
|
||||
fill: false,
|
||||
yAxisID: "y_bandwidth",
|
||||
data: response.downloads
|
||||
}, {
|
||||
label: "Views",
|
||||
backgroundColor: "rgba(128, 128, 255, .4)",
|
||||
borderColor: "rgba(128, 128, 255, .8)",
|
||||
borderWidth: 2,
|
||||
fill: false,
|
||||
yAxisID: "y_views",
|
||||
data: response.views
|
||||
}
|
||||
]
|
||||
},
|
||||
options: {
|
||||
stacked: false,
|
||||
aspectRatio: 3,
|
||||
tooltips: {
|
||||
mode: "index",
|
||||
intersect: false,
|
||||
axis: "x"
|
||||
},
|
||||
scales: {
|
||||
yAxes: [
|
||||
{
|
||||
type: "linear",
|
||||
display: true,
|
||||
position: "left",
|
||||
id: "y_bandwidth",
|
||||
scaleLabel: {
|
||||
display: true,
|
||||
labelString: "Downloads"
|
||||
}
|
||||
}, {
|
||||
type: "linear",
|
||||
display: false,
|
||||
position: "right",
|
||||
id: "y_views",
|
||||
scaleLabel: {
|
||||
display: true,
|
||||
labelString: "Views"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
elements: {
|
||||
point: {
|
||||
radius: 0
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
{{end}}
|
||||
{{template "footer"}}
|
||||
</div>
|
||||
</body>
|
||||
|
@@ -114,6 +114,10 @@
|
||||
</div>
|
||||
<span id="info_file_details"></span>
|
||||
<span id="info_about">
|
||||
<h3>Bandwidth and views</h3>
|
||||
<div id="chart_container" class="chart-container" style="position: relative; width: 100%; height: auto;">
|
||||
<canvas id="bandwidth_chart"></canvas>
|
||||
</div>
|
||||
<h3>About</h3>
|
||||
Pixeldrain is a file sharing platform.
|
||||
<a href="/" target="_blank">Visit the home page for more information.</a>
|
||||
@@ -131,11 +135,6 @@
|
||||
<tr><td>SHIFT + s</td><td> = Download all the files in the list as a zip archive</td></tr>
|
||||
</table>
|
||||
|
||||
<h3>Bandwidth and views</h3>
|
||||
<div id="chart_container" class="chart-container" style="position: relative; width: 100%; height: auto;">
|
||||
<canvas id="bandwidth_chart"></canvas>
|
||||
</div>
|
||||
|
||||
<h3>Credits</h3>
|
||||
All server side code written by
|
||||
<a target="_blank" href="https://fornaxian.com/">Fornax (me)</a>.
|
||||
|
@@ -77,7 +77,6 @@ func New(r *httprouter.Router, prefix string, conf *conf.PixelWebConfig) *WebCon
|
||||
r.POST(p+"/register" /* */, wc.serveForm(wc.registerForm, false))
|
||||
r.GET(p+"/login" /* */, wc.serveForm(wc.loginForm, false))
|
||||
r.POST(p+"/login" /* */, wc.serveForm(wc.loginForm, false))
|
||||
// r.GET(p+"/login" /* */, wc.serveTemplate("login", false))
|
||||
r.GET(p+"/logout" /* */, wc.serveTemplate("logout", true))
|
||||
r.POST(p+"/logout" /* */, wc.serveLogout)
|
||||
r.GET(p+"/user" /* */, wc.serveTemplate("user_home", true))
|
||||
@@ -90,6 +89,8 @@ func New(r *httprouter.Router, prefix string, conf *conf.PixelWebConfig) *WebCon
|
||||
r.GET(p+"/user/change_password" /* */, wc.serveForm(wc.passwordForm, true))
|
||||
r.POST(p+"/user/change_password" /**/, wc.serveForm(wc.passwordForm, true))
|
||||
|
||||
r.GET(p+"/admin", wc.serveTemplate("admin_panel", true))
|
||||
|
||||
r.NotFound = http.HandlerFunc(wc.serveNotFound)
|
||||
|
||||
return wc
|
||||
|
Reference in New Issue
Block a user