forked from rosa/hakurei
Compare commits
2 Commits
52a4e5b87d
...
b104ad6e2d
| Author | SHA1 | Date | |
|---|---|---|---|
| b104ad6e2d | |||
| 469bd1ee99 |
@@ -8,9 +8,9 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"path"
|
"path"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"hakurei.app/internal/info"
|
"hakurei.app/internal/info"
|
||||||
|
"hakurei.app/internal/pkg"
|
||||||
"hakurei.app/internal/rosa"
|
"hakurei.app/internal/rosa"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -36,14 +36,14 @@ func serveInfo(index *PackageIndex) func(http.ResponseWriter, *http.Request) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func serveStatus(index *PackageIndex) func(w http.ResponseWriter, r *http.Request) {
|
func serveStatus(index *PackageIndex, cache *pkg.Cache) func(w http.ResponseWriter, r *http.Request) {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
download := path.Dir(r.URL.Path) == "/status"
|
||||||
if index == nil {
|
if index == nil {
|
||||||
http.Error(w, "index is nil", http.StatusInternalServerError)
|
http.Error(w, "index is nil", http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
base := path.Base(r.URL.Path)
|
name := path.Base(r.URL.Path)
|
||||||
name := strings.TrimSuffix(base, ".log")
|
|
||||||
p, ok := rosa.ResolveName(name)
|
p, ok := rosa.ResolveName(name)
|
||||||
if !ok {
|
if !ok {
|
||||||
http.NotFound(w, r)
|
http.NotFound(w, r)
|
||||||
@@ -56,7 +56,21 @@ func serveStatus(index *PackageIndex) func(w http.ResponseWriter, r *http.Reques
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if len(pk.status) > 0 {
|
if len(pk.status) > 0 {
|
||||||
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
|
if download {
|
||||||
|
w.Header().Set("Content-Type", "application/octet-stream")
|
||||||
|
} else {
|
||||||
|
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
|
||||||
|
}
|
||||||
|
if download {
|
||||||
|
var version string
|
||||||
|
if pk.Version != "\u0000" {
|
||||||
|
version = pk.Version
|
||||||
|
} else {
|
||||||
|
version = "unknown"
|
||||||
|
}
|
||||||
|
w.Header().Set("Content-Disposition", fmt.Sprintf("attachment; filename=\"%s-%s-%s.log\"", pk.Name, version, pkg.Encode(pk.ident.Value())))
|
||||||
|
}
|
||||||
|
|
||||||
w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
|
w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
_, err := io.Copy(w, bytes.NewReader(pk.status))
|
_, err := io.Copy(w, bytes.NewReader(pk.status))
|
||||||
@@ -111,10 +125,11 @@ func serveGet(index *PackageIndex) func(http.ResponseWriter, *http.Request) {
|
|||||||
|
|
||||||
const ApiVersion = "v1"
|
const ApiVersion = "v1"
|
||||||
|
|
||||||
func apiRoutes(index *PackageIndex) {
|
func apiRoutes(index *PackageIndex, cache *pkg.Cache) {
|
||||||
http.HandleFunc(fmt.Sprintf("GET /api/%s/info", ApiVersion), serveInfo(index))
|
http.HandleFunc(fmt.Sprintf("GET /api/%s/info", ApiVersion), serveInfo(index))
|
||||||
http.HandleFunc(fmt.Sprintf("GET /api/%s/get", ApiVersion), serveGet(index))
|
http.HandleFunc(fmt.Sprintf("GET /api/%s/get", ApiVersion), serveGet(index))
|
||||||
http.HandleFunc(fmt.Sprintf("GET /api/%s/status/", ApiVersion), serveStatus(index))
|
http.HandleFunc(fmt.Sprintf("GET /api/%s/status/", ApiVersion), serveStatus(index, cache))
|
||||||
|
http.HandleFunc("GET /status/", serveStatus(index, cache))
|
||||||
}
|
}
|
||||||
|
|
||||||
func WritePayload(w http.ResponseWriter, payload any) {
|
func WritePayload(w http.ResponseWriter, payload any) {
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"cmp"
|
"cmp"
|
||||||
"fmt"
|
|
||||||
"slices"
|
"slices"
|
||||||
|
"unique"
|
||||||
|
|
||||||
"hakurei.app/internal/pkg"
|
"hakurei.app/internal/pkg"
|
||||||
"hakurei.app/internal/rosa"
|
"hakurei.app/internal/rosa"
|
||||||
@@ -25,12 +25,13 @@ type PackageIndex struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type PackageIndexEntry struct {
|
type PackageIndexEntry struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Description string `json:"description,omitempty"`
|
Description string `json:"description,omitempty"`
|
||||||
Website string `json:"website,omitempty"`
|
Website string `json:"website,omitempty"`
|
||||||
Version string `json:"version"`
|
Version string `json:"version"`
|
||||||
Status string `json:"report,omitempty"`
|
HasReport bool `json:"report,omitempty"`
|
||||||
status []byte `json:"-"`
|
ident unique.Handle[pkg.ID] `json:"-"`
|
||||||
|
status []byte `json:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func createPackageIndex(cache *pkg.Cache, report *rosa.Report) (_ *PackageIndex, err error) {
|
func createPackageIndex(cache *pkg.Cache, report *rosa.Report) (_ *PackageIndex, err error) {
|
||||||
@@ -45,20 +46,18 @@ func createPackageIndex(cache *pkg.Cache, report *rosa.Report) (_ *PackageIndex,
|
|||||||
id := cache.Ident(a)
|
id := cache.Ident(a)
|
||||||
st, n := report.ArtifactOf(id)
|
st, n := report.ArtifactOf(id)
|
||||||
var status []byte
|
var status []byte
|
||||||
var statusUrl string
|
|
||||||
if n < 1 {
|
if n < 1 {
|
||||||
status = nil
|
status = nil
|
||||||
statusUrl = ""
|
|
||||||
} else {
|
} else {
|
||||||
status = st
|
status = st
|
||||||
statusUrl = fmt.Sprintf("/api/%s/status/%s.log", ApiVersion, m.Name)
|
|
||||||
}
|
}
|
||||||
entry := PackageIndexEntry{
|
entry := PackageIndexEntry{
|
||||||
Name: m.Name,
|
Name: m.Name,
|
||||||
Description: m.Description,
|
Description: m.Description,
|
||||||
Website: m.Website,
|
Website: m.Website,
|
||||||
Version: v,
|
Version: v,
|
||||||
Status: statusUrl,
|
HasReport: len(status) > 0,
|
||||||
|
ident: id,
|
||||||
status: status,
|
status: status,
|
||||||
}
|
}
|
||||||
work[p] = entry
|
work[p] = entry
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ func main() {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
uiRoutes()
|
uiRoutes()
|
||||||
apiRoutes(index)
|
apiRoutes(index, cache)
|
||||||
err = http.ListenAndServe(fmt.Sprintf(":%d", flagPort), nil)
|
err = http.ListenAndServe(fmt.Sprintf(":%d", flagPort), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -14,12 +14,18 @@
|
|||||||
</table>
|
</table>
|
||||||
<p>Showing entries <span id="entry-counter"></span>.</p>
|
<p>Showing entries <span id="entry-counter"></span>.</p>
|
||||||
<span class="bottom-nav"><a href="javascript:prevPage()">« Previous</a> <span id="page-number">1</span> <a href="javascript:nextPage()">Next »</a></span>
|
<span class="bottom-nav"><a href="javascript:prevPage()">« Previous</a> <span id="page-number">1</span> <a href="javascript:nextPage()">Next »</a></span>
|
||||||
<span><label for="count">Entries per page:</label><select name="count" id="count">
|
<span><label for="count">Entries per page: </label><select name="count" id="count">
|
||||||
<option value="10">10</option>
|
<option value="10">10</option>
|
||||||
<option value="25">25</option>
|
<option value="25">25</option>
|
||||||
<option value="50">50</option>
|
<option value="50">50</option>
|
||||||
<option value="100">100</option>
|
<option value="100">100</option>
|
||||||
</select></span>
|
</select></span>
|
||||||
|
<span><label for="sort">Sort by: </label><select name="sort" id="sort">
|
||||||
|
<option value="0">Definition (ascending)</option>
|
||||||
|
<option value="1">Definition (descending)</option>
|
||||||
|
<option value="2">Name (ascending)</option>
|
||||||
|
<option value="3">Name (descending)</option>
|
||||||
|
</select></span>
|
||||||
</body>
|
</body>
|
||||||
<footer>
|
<footer>
|
||||||
<p>©<a href="https://hakurei.app/">Hakurei</a> (<span id="hakurei-version">unknown</span>). Licensed under the MIT license.</p>
|
<p>©<a href="https://hakurei.app/">Hakurei</a> (<span id="hakurei-version">unknown</span>). Licensed under the MIT license.</p>
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ function toHTML(entry) {
|
|||||||
let v = entry.version != null ? `<span>${escapeHtml(entry.version)}</span>` : "";
|
let v = entry.version != null ? `<span>${escapeHtml(entry.version)}</span>` : "";
|
||||||
let d = entry.description != null ? `<p>${escapeHtml(entry.description)}</p>` : "";
|
let d = entry.description != null ? `<p>${escapeHtml(entry.description)}</p>` : "";
|
||||||
let w = entry.website != null ? `<a href="${encodeURI(entry.website)}">Website</a>` : "";
|
let w = entry.website != null ? `<a href="${encodeURI(entry.website)}">Website</a>` : "";
|
||||||
let r = entry.report != null ? `<a href="${encodeURI(entry.report)}">Log</a>` : "";
|
let r = entry.report ? `Log (<a href=\"${encodeURI('/api/v1/status/' + entry.name)}\">View</a> | <a href=\"${encodeURI('/status/' + entry.name)}\">Download</a>)` : "";
|
||||||
let row = (document.createElement('tr'));
|
let row = (document.createElement('tr'));
|
||||||
row.innerHTML = `<td>
|
row.innerHTML = `<td>
|
||||||
<h2>${escapeHtml(entry.name)} ${v}</h2>
|
<h2>${escapeHtml(entry.name)} ${v}</h2>
|
||||||
@@ -27,8 +27,8 @@ class InfoPayload {
|
|||||||
}
|
}
|
||||||
async function infoRequest() {
|
async function infoRequest() {
|
||||||
const res = await fetch(`${ENDPOINT}/info`);
|
const res = await fetch(`${ENDPOINT}/info`);
|
||||||
const res_1 = await res.json();
|
const payload = await res.json();
|
||||||
return res_1;
|
return payload;
|
||||||
}
|
}
|
||||||
class GetPayload {
|
class GetPayload {
|
||||||
count;
|
count;
|
||||||
@@ -43,36 +43,27 @@ var SortOrders;
|
|||||||
})(SortOrders || (SortOrders = {}));
|
})(SortOrders || (SortOrders = {}));
|
||||||
async function getRequest(limit, index, sort) {
|
async function getRequest(limit, index, sort) {
|
||||||
const res = await fetch(`${ENDPOINT}/get?limit=${limit}&index=${index}&sort=${sort.valueOf()}`);
|
const res = await fetch(`${ENDPOINT}/get?limit=${limit}&index=${index}&sort=${sort.valueOf()}`);
|
||||||
const res_1 = await res.json();
|
const payload = await res.json();
|
||||||
return res_1;
|
return payload;
|
||||||
}
|
}
|
||||||
class State {
|
class State {
|
||||||
entriesPerPage = 10;
|
entriesPerPage = 10;
|
||||||
currentPage = 1;
|
|
||||||
entryIndex = 0;
|
entryIndex = 0;
|
||||||
maxEntries = 100;
|
maxEntries = 0;
|
||||||
|
sort = SortOrders.DeclarationAscending;
|
||||||
getEntriesPerPage() {
|
getEntriesPerPage() {
|
||||||
return this.entriesPerPage;
|
return this.entriesPerPage;
|
||||||
}
|
}
|
||||||
setEntriesPerPage(entriesPerPage) {
|
setEntriesPerPage(entriesPerPage) {
|
||||||
this.entriesPerPage = entriesPerPage;
|
this.entriesPerPage = entriesPerPage;
|
||||||
if (this.currentPage > this.getMaxPage()) {
|
this.setEntryIndex(Math.floor(this.getEntryIndex() / entriesPerPage) * entriesPerPage);
|
||||||
this.setCurrentPage(this.getMaxPage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
getCurrentPage() {
|
|
||||||
return this.currentPage;
|
|
||||||
}
|
|
||||||
setCurrentPage(page) {
|
|
||||||
this.currentPage = page;
|
|
||||||
this.setEntryIndex((this.getCurrentPage() - 1) * this.getEntriesPerPage());
|
|
||||||
document.getElementById("page-number").innerText = String(this.getCurrentPage());
|
|
||||||
}
|
}
|
||||||
getEntryIndex() {
|
getEntryIndex() {
|
||||||
return this.entryIndex;
|
return this.entryIndex;
|
||||||
}
|
}
|
||||||
setEntryIndex(entryIndex) {
|
setEntryIndex(entryIndex) {
|
||||||
this.entryIndex = entryIndex;
|
this.entryIndex = entryIndex;
|
||||||
|
this.updatePage();
|
||||||
this.updateRange();
|
this.updateRange();
|
||||||
this.updateListings();
|
this.updateListings();
|
||||||
}
|
}
|
||||||
@@ -82,15 +73,23 @@ class State {
|
|||||||
setMaxEntries(max) {
|
setMaxEntries(max) {
|
||||||
this.maxEntries = max;
|
this.maxEntries = max;
|
||||||
}
|
}
|
||||||
getMaxPage() {
|
getSortOrder() {
|
||||||
return Math.ceil(this.getMaxEntries() / this.getEntriesPerPage());
|
return this.sort;
|
||||||
|
}
|
||||||
|
setSortOrder(sortOrder) {
|
||||||
|
this.sort = sortOrder;
|
||||||
|
this.setEntryIndex(0);
|
||||||
|
}
|
||||||
|
updatePage() {
|
||||||
|
let page = Math.ceil(((this.getEntryIndex() + this.getEntriesPerPage()) - 1) / this.getEntriesPerPage());
|
||||||
|
document.getElementById("page-number").innerText = String(page);
|
||||||
}
|
}
|
||||||
updateRange() {
|
updateRange() {
|
||||||
let max = Math.min(this.getEntryIndex() + this.getEntriesPerPage(), this.getMaxEntries());
|
let max = Math.min(this.getEntryIndex() + this.getEntriesPerPage(), this.getMaxEntries());
|
||||||
document.getElementById("entry-counter").innerText = `${this.getEntryIndex() + 1}-${max} of ${this.getMaxEntries()}`;
|
document.getElementById("entry-counter").innerText = `${this.getEntryIndex() + 1}-${max} of ${this.getMaxEntries()}`;
|
||||||
}
|
}
|
||||||
updateListings() {
|
updateListings() {
|
||||||
getRequest(this.getEntriesPerPage(), this.entryIndex, 0)
|
getRequest(this.getEntriesPerPage(), this.getEntryIndex(), this.getSortOrder())
|
||||||
.then(res => {
|
.then(res => {
|
||||||
let table = document.getElementById("pkg-list");
|
let table = document.getElementById("pkg-list");
|
||||||
table.innerHTML = '';
|
table.innerHTML = '';
|
||||||
@@ -102,16 +101,12 @@ class State {
|
|||||||
}
|
}
|
||||||
let STATE;
|
let STATE;
|
||||||
function prevPage() {
|
function prevPage() {
|
||||||
let current = STATE.getCurrentPage();
|
let index = STATE.getEntryIndex();
|
||||||
if (current > 1) {
|
STATE.setEntryIndex(Math.max(0, index - STATE.getEntriesPerPage()));
|
||||||
STATE.setCurrentPage(STATE.getCurrentPage() - 1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
function nextPage() {
|
function nextPage() {
|
||||||
let current = STATE.getCurrentPage();
|
let index = STATE.getEntryIndex();
|
||||||
if (current < STATE.getMaxPage()) {
|
STATE.setEntryIndex(Math.min((Math.ceil(STATE.getMaxEntries() / STATE.getEntriesPerPage()) * STATE.getEntriesPerPage()) - STATE.getEntriesPerPage(), index + STATE.getEntriesPerPage()));
|
||||||
STATE.setCurrentPage(STATE.getCurrentPage() + 1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
function escapeHtml(str) {
|
function escapeHtml(str) {
|
||||||
return str
|
return str
|
||||||
@@ -133,4 +128,7 @@ document.addEventListener("DOMContentLoaded", () => {
|
|||||||
document.getElementById("count").addEventListener("change", (event) => {
|
document.getElementById("count").addEventListener("change", (event) => {
|
||||||
STATE.setEntriesPerPage(parseInt(event.target.value));
|
STATE.setEntriesPerPage(parseInt(event.target.value));
|
||||||
});
|
});
|
||||||
|
document.getElementById("sort").addEventListener("change", (event) => {
|
||||||
|
STATE.setSortOrder(parseInt(event.target.value));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -3,13 +3,13 @@ class PackageIndexEntry {
|
|||||||
description: string | null
|
description: string | null
|
||||||
website: string | null
|
website: string | null
|
||||||
version: string | null
|
version: string | null
|
||||||
report: string | null
|
report: boolean
|
||||||
}
|
}
|
||||||
function toHTML(entry: PackageIndexEntry): HTMLTableRowElement {
|
function toHTML(entry: PackageIndexEntry): HTMLTableRowElement {
|
||||||
let v = entry.version != null ? `<span>${escapeHtml(entry.version)}</span>` : ""
|
let v = entry.version != null ? `<span>${escapeHtml(entry.version)}</span>` : ""
|
||||||
let d = entry.description != null ? `<p>${escapeHtml(entry.description)}</p>` : ""
|
let d = entry.description != null ? `<p>${escapeHtml(entry.description)}</p>` : ""
|
||||||
let w = entry.website != null ? `<a href="${encodeURI(entry.website)}">Website</a>` : ""
|
let w = entry.website != null ? `<a href="${encodeURI(entry.website)}">Website</a>` : ""
|
||||||
let r = entry.report != null ? `<a href="${encodeURI(entry.report)}">Log</a>` : ""
|
let r = entry.report ? `Log (<a href=\"${encodeURI('/api/v1/status/' + entry.name)}\">View</a> | <a href=\"${encodeURI('/status/' + entry.name)}\">Download</a>)` : ""
|
||||||
let row = <HTMLTableRowElement>(document.createElement('tr'))
|
let row = <HTMLTableRowElement>(document.createElement('tr'))
|
||||||
row.innerHTML = `<td>
|
row.innerHTML = `<td>
|
||||||
<h2>${escapeHtml(entry.name)} ${v}</h2>
|
<h2>${escapeHtml(entry.name)} ${v}</h2>
|
||||||
@@ -29,8 +29,8 @@ class InfoPayload {
|
|||||||
|
|
||||||
async function infoRequest(): Promise<InfoPayload> {
|
async function infoRequest(): Promise<InfoPayload> {
|
||||||
const res = await fetch(`${ENDPOINT}/info`)
|
const res = await fetch(`${ENDPOINT}/info`)
|
||||||
const res_1 = await res.json()
|
const payload = await res.json()
|
||||||
return res_1 as InfoPayload
|
return payload as InfoPayload
|
||||||
}
|
}
|
||||||
class GetPayload {
|
class GetPayload {
|
||||||
count: number
|
count: number
|
||||||
@@ -45,36 +45,28 @@ enum SortOrders {
|
|||||||
}
|
}
|
||||||
async function getRequest(limit: number, index: number, sort: SortOrders): Promise<GetPayload> {
|
async function getRequest(limit: number, index: number, sort: SortOrders): Promise<GetPayload> {
|
||||||
const res = await fetch(`${ENDPOINT}/get?limit=${limit}&index=${index}&sort=${sort.valueOf()}`)
|
const res = await fetch(`${ENDPOINT}/get?limit=${limit}&index=${index}&sort=${sort.valueOf()}`)
|
||||||
const res_1 = await res.json()
|
const payload = await res.json()
|
||||||
return res_1 as GetPayload
|
return payload as GetPayload
|
||||||
}
|
}
|
||||||
class State {
|
class State {
|
||||||
entriesPerPage: number = 10
|
entriesPerPage: number = 10
|
||||||
currentPage: number = 1
|
|
||||||
entryIndex: number = 0
|
entryIndex: number = 0
|
||||||
maxEntries: number = 0
|
maxEntries: number = 0
|
||||||
|
sort: SortOrders = SortOrders.DeclarationAscending
|
||||||
|
|
||||||
getEntriesPerPage(): number {
|
getEntriesPerPage(): number {
|
||||||
return this.entriesPerPage
|
return this.entriesPerPage
|
||||||
}
|
}
|
||||||
setEntriesPerPage(entriesPerPage: number) {
|
setEntriesPerPage(entriesPerPage: number) {
|
||||||
this.entriesPerPage = entriesPerPage
|
this.entriesPerPage = entriesPerPage
|
||||||
if (this.currentPage > this.getMaxPage()) {
|
this.setEntryIndex(Math.floor(this.getEntryIndex() / entriesPerPage) * entriesPerPage)
|
||||||
this.setCurrentPage(this.getMaxPage())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
getCurrentPage(): number {
|
|
||||||
return this.currentPage
|
|
||||||
}
|
|
||||||
setCurrentPage(page: number) {
|
|
||||||
this.currentPage = page
|
|
||||||
this.setEntryIndex((this.getCurrentPage() - 1) * this.getEntriesPerPage())
|
|
||||||
document.getElementById("page-number").innerText = String(this.getCurrentPage())
|
|
||||||
}
|
}
|
||||||
getEntryIndex(): number {
|
getEntryIndex(): number {
|
||||||
return this.entryIndex
|
return this.entryIndex
|
||||||
}
|
}
|
||||||
setEntryIndex(entryIndex: number) {
|
setEntryIndex(entryIndex: number) {
|
||||||
this.entryIndex = entryIndex
|
this.entryIndex = entryIndex
|
||||||
|
this.updatePage()
|
||||||
this.updateRange()
|
this.updateRange()
|
||||||
this.updateListings()
|
this.updateListings()
|
||||||
}
|
}
|
||||||
@@ -84,15 +76,23 @@ class State {
|
|||||||
setMaxEntries(max: number) {
|
setMaxEntries(max: number) {
|
||||||
this.maxEntries = max
|
this.maxEntries = max
|
||||||
}
|
}
|
||||||
getMaxPage(): number {
|
getSortOrder(): SortOrders {
|
||||||
return Math.ceil(this.getMaxEntries() / this.getEntriesPerPage())
|
return this.sort
|
||||||
|
}
|
||||||
|
setSortOrder(sortOrder: SortOrders) {
|
||||||
|
this.sort = sortOrder
|
||||||
|
this.setEntryIndex(0)
|
||||||
|
}
|
||||||
|
updatePage() {
|
||||||
|
let page = Math.ceil(((this.getEntryIndex() + this.getEntriesPerPage()) - 1) / this.getEntriesPerPage())
|
||||||
|
document.getElementById("page-number").innerText = String(page)
|
||||||
}
|
}
|
||||||
updateRange() {
|
updateRange() {
|
||||||
let max = Math.min(this.getEntryIndex() + this.getEntriesPerPage(), this.getMaxEntries())
|
let max = Math.min(this.getEntryIndex() + this.getEntriesPerPage(), this.getMaxEntries())
|
||||||
document.getElementById("entry-counter").innerText = `${this.getEntryIndex() + 1}-${max} of ${this.getMaxEntries()}`
|
document.getElementById("entry-counter").innerText = `${this.getEntryIndex() + 1}-${max} of ${this.getMaxEntries()}`
|
||||||
}
|
}
|
||||||
updateListings() {
|
updateListings() {
|
||||||
getRequest(this.getEntriesPerPage(), this.entryIndex, 0)
|
getRequest(this.getEntriesPerPage(), this.getEntryIndex(), this.getSortOrder())
|
||||||
.then(res => {
|
.then(res => {
|
||||||
let table = document.getElementById("pkg-list")
|
let table = document.getElementById("pkg-list")
|
||||||
table.innerHTML = ''
|
table.innerHTML = ''
|
||||||
@@ -107,16 +107,12 @@ class State {
|
|||||||
let STATE: State
|
let STATE: State
|
||||||
|
|
||||||
function prevPage() {
|
function prevPage() {
|
||||||
let current = STATE.getCurrentPage()
|
let index = STATE.getEntryIndex()
|
||||||
if (current > 1) {
|
STATE.setEntryIndex(Math.max(0, index - STATE.getEntriesPerPage()))
|
||||||
STATE.setCurrentPage(STATE.getCurrentPage() - 1)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
function nextPage() {
|
function nextPage() {
|
||||||
let current = STATE.getCurrentPage()
|
let index = STATE.getEntryIndex()
|
||||||
if (current < STATE.getMaxPage()) {
|
STATE.setEntryIndex(Math.min((Math.ceil(STATE.getMaxEntries() / STATE.getEntriesPerPage()) * STATE.getEntriesPerPage()) - STATE.getEntriesPerPage(), index + STATE.getEntriesPerPage()))
|
||||||
STATE.setCurrentPage(STATE.getCurrentPage() + 1)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function escapeHtml(str: string): string {
|
function escapeHtml(str: string): string {
|
||||||
@@ -141,4 +137,7 @@ document.addEventListener("DOMContentLoaded", () => {
|
|||||||
document.getElementById("count").addEventListener("change", (event) => {
|
document.getElementById("count").addEventListener("change", (event) => {
|
||||||
STATE.setEntriesPerPage(parseInt((event.target as HTMLSelectElement).value))
|
STATE.setEntriesPerPage(parseInt((event.target as HTMLSelectElement).value))
|
||||||
})
|
})
|
||||||
|
document.getElementById("sort").addEventListener("change", (event) => {
|
||||||
|
STATE.setSortOrder(parseInt((event.target as HTMLSelectElement).value))
|
||||||
|
})
|
||||||
})
|
})
|
||||||
Reference in New Issue
Block a user