updated htmlutils external

added temporary file generation when uploading a new package
This commit is contained in:
2017-12-29 09:38:35 +01:00
parent 719230bb4e
commit 4a4c1cfc63
4 changed files with 103 additions and 98 deletions

View File

@@ -88,7 +88,7 @@ val wildflyUsername = SettingKey[String]("wildfly-username", "The account userna
val wildflyPassword = SettingKey[String]("wildfly-password", "The account password to use to connect to wildfly with jboss-cli.sh")
val wildflyURL = SettingKey[String]("wildfly-url", "The username to use to connect to wildfly with jboss-cli.sh")
wildflyUsername := "root"
wildflyUsername := "admin"
wildflyPassword := "123456"
wildflyURL := "localhost:1234"

View File

@@ -1,4 +1,5 @@
import dom
import htmlutils.tree
import htmlutils.utils
import json
import streams
@@ -15,55 +16,55 @@ proc last[T](s : seq[T]) : T = s[s.len - 1]
proc formatByteSize(size : BiggestInt) : string = size.float64.formatEng(precision=1, siPrefix=true, unit = "B")
type DownloadPanel = ref object
badge : Node
listgroup : Node
badge : Element
listgroup : Element
pkgs : HashSet[string]
footer : Node
sizeLabel : Node
footer : Element
sizeLabel : Element
size : BiggestInt
proc newDownloadPanel(parent : Node) : DownloadPanel =
proc newDownloadPanel(parent : Element) : DownloadPanel =
let dp = DownloadPanel()
dp.pkgs = initSet[string]()
htmlDocument(document, parent):
htmlTreeAppend(parent):
"div":
class ["panel", "panel-default"]
classList = ["panel", "panel-default"]
"div":
class ["panel-heading"]
classList = ["panel-heading"]
"h3":
class ["panel-title"]
classList = ["panel-title"]
"a":
text "Package list "
text = "Package list "
"span":
class ["badge", "pull-right"]
classList = ["badge", "pull-right"]
style {"display" :"none"}
cb:
dp.badge = node
dp.badge = elem
"ul":
class ["list-group"]
classList = ["list-group"]
cb:
dp.listgroup = node
dp.listgroup = elem
"div":
class ["panel-footer"]
style {
classList = ["panel-footer"]
style = {
"text-align" : "right",
"display" :"none"
}
"span":
style {
style = {
"font-weight" : "bold",
"padding-right" : "10px"
}
cb:
dp.sizeLabel = node
dp.sizeLabel = elem
"button":
class ["btn", "btn-primary"]
attrs {"type" : "button"}
classList = ["btn", "btn-primary"]
attrs = {"type" : "button"}
"span":
class ["glyphicon", "glyphicon-download"]
classList = ["glyphicon", "glyphicon-download"]
cb:
node.appendChild(document.createTextNode(" Download"))
elem.appendChild(document.createTextNode(" Download"))
let clickHandler = proc(e : Event) =
let pkglist : seq[string] = sequtils.toSeq(dp.pkgs.items())
let form = cast[Formelement](document.createElement("form"))
@@ -78,9 +79,9 @@ proc newDownloadPanel(parent : Node) : DownloadPanel =
form.appendChild(tf)
document.body.appendChild(form)
form.submit()
node.addEventListener("click", clickHandler)
elem.addEventListener("click", clickHandler)
cb:
dp.footer = node
dp.footer = elem
dp
@@ -101,13 +102,13 @@ proc addPkg(dp : DownloadPanel, pkgfile : string) =
let sz = parseInt(req.responseText)
dp.size += sz
dp.updateSize
htmlDocument(document, dp.listgroup):
htmlTreeAppend(dp.listgroup):
"li":
var listElement : Node
class ["list-group-item"]
text pkgfile
var listElement : Element
classList = ["list-group-item"]
text = pkgfile
"span":
class ["glyphicon", "glyphicon-remove", "pull-right"]
classList = ["glyphicon", "glyphicon-remove", "pull-right"]
cb:
let fn = proc(e : Event) =
dp.pkgs.excl(pkgfile)
@@ -115,51 +116,51 @@ proc addPkg(dp : DownloadPanel, pkgfile : string) =
dp.updateBadge
dp.size -= sz
dp.updateSize
node.addEventListener("click", fn)
elem.addEventListener("click", fn)
cb:
listElement = node
listElement = elem
req.addEventListener("load", load_cb)
req.open("get", serverURL & "rest/pkg/filesize/" & pkgfile)
req.setRequestHeader("Accept", "application/json")
req.send()
dp.updateBadge
proc readTableRow(row : Node) : JsonNode =
proc readTableRow(row : Element) : JsonNode =
let pkgname = $row.querySelector("td:nth-child(2)").textContent
let version = $row.querySelector("td:nth-child(3) button").textContent
let arch = $row.querySelector("td:nth-child(4) button").textContent
pkgMap[pkgname][version][arch]
proc createDropdown(parent : Node, data :seq[string], onchange : proc(value : string)) =
proc createDropdown(parent : Element, data :seq[string], onchange : proc(value : string)) =
htmlDocument(document, parent):
htmlTreeAppend(parent):
"div":
var button : Node
class ["dropdown"]
var button : Element
classList = ["dropdown"]
"button":
class ["btn", "btn-default", "dropdown-toggle"]
attrs {"data-toggle": "dropdown", "type": "button"}
classList = ["btn", "btn-default", "dropdown-toggle"]
attrs = {"data-toggle": "dropdown", "type": "button"}
cb:
node.textContent = data.last
button = node
elem.textContent = data.last
button = elem
"ul":
class ["dropdown-menu"]
classList = ["dropdown-menu"]
cb:
for line in data:
htmlDocument(document, node):
htmlTreeAppend(elem):
"li":
"a":
text line
text = line
cb:
let fn = proc(e: Event) =
button.textContent = node.textContent
onchange($node.textContent)
node.addEventListener("click", fn)
button.textContent = elem.textContent
onchange($elem.textContent)
elem.addEventListener("click", fn)
type PkgTable = ref object
addButton : Node
addButton : Element
proc newPkgTable(parent: Node, searchString : string) : PkgTable =
proc newPkgTable(parent: Element, searchString : string) : PkgTable =
var pkgtable = PkgTable()
var fragments = newSeq[string]()
for fragment in searchString.splitWhitespace():
@@ -171,50 +172,50 @@ proc newPkgTable(parent: Node, searchString : string) : PkgTable =
searchResult.add(key,value)
for table in document.querySelectorAll("table.pkgtable"):
table.parentNode.removeChild(table)
htmlDocument(document, parent):
htmlTreeAppend(parent):
"table":
class ["table", "table-striped","pkgtable"]
classList = ["table", "table-striped","pkgtable"]
"thead":
"tr":
"th":
"button":
class ["btn", "btn-default"]
attrs {"type": "button"}
classList = ["btn", "btn-default"]
attrs = {"type": "button"}
"span":
class ["glyphicon", "glyphicon-plus"]
classList = ["glyphicon", "glyphicon-plus"]
cb:
let txt = document.createTextNode(" Add")
node.appendChild(txt)
pkgtable.addButton = node
elem.appendChild(txt)
pkgtable.addButton = elem
"th":
text "Name"
text = "Name"
"th":
text "Version"
text = "Version"
"th":
text "Arch"
text = "Arch"
"th":
text "Installed size"
text = "Installed size"
"tbody":
cb:
var i = 0
for name, versions in searchResult:
closureScope:
htmlDocument(document, node):
htmlTreeAppend(elem):
"tr":
var row : Node
var archCell : Node
var sizeCell : Node
var row : Element
var archCell : Element
var sizeCell : Element
let size_change_callback = proc(newValue : string) =
sizeCell.textContent = readTableRow(row)["size"].getNum.formatByteSize
"td":
"div":
class ["checkbox"]
classList = ["checkbox"]
"label":
"input":
attrs {"type" : "checkbox"}
attrs = {"type" : "checkbox"}
"td":
text $name
text = $name
"td":
cb:
var data = newSeq[string]()
@@ -228,32 +229,32 @@ proc newPkgTable(parent: Node, searchString : string) : PkgTable =
newdata.add(arch)
createDropdown(archCell, newdata, size_change_callback)
size_change_callback(newValue)
createDropdown(node, data, change_callback)
createDropdown(elem, data, change_callback)
"td":
cb:
archCell = node
archCell = elem
var data = newSeq[string]()
var arches : JsonNode
for v, a in versions:
arches = a
for arch, pkgname in arches:
data.add(arch)
createDropdown(node, data, size_change_callback)
createDropdown(elem, data, size_change_callback)
"td":
cb:
sizeCell = node
sizeCell = elem
for v, arches in versions:
for key, value in arches:
node.textContent = value["size"].getNum.formatByteSize
elem.textContent = value["size"].getNum.formatByteSize
return
cb:
row = node
row = elem
pkgtable
var dp : DownloadPanel
# var pkgTable : PkgTable
htmlDocument document, document.body:
htmlTreeappend document.body:
# "img":
# attrs {"src" : "img/background.bpg"}
# style {
@@ -264,32 +265,32 @@ htmlDocument document, document.body:
# "z-index" : "-10"
# }
"div":
var table : Node
style {"background-color" : "rgba(255, 255, 255, 0.25)"}
class ["container"]
var table : Element
style = {"background-color" : "rgba(255, 255, 255, 0.25)"}
classList = ["container"]
"div":
style {
style = {
"margin-top" : "20px",
"background-color" : "rgba(224, 224, 224, 0.5)"
}
class ["jumbotron"]
classList = ["jumbotron"]
"h1":
text "Jpacrepo"
text = "Jpacrepo"
"p":
text "Personal archlinux package repository"
text = "Personal archlinux package repository"
"div":
"form":
class ["form-horizontal"]
classList = ["form-horizontal"]
"div":
class ["form-group"]
classList = ["form-group"]
"label":
class ["control-label", "col-sm-2"]
text " Search package"
classList = ["control-label", "col-sm-2"]
text = " Search package"
"div":
class ["col-sm-10"]
classList = ["col-sm-10"]
"input":
class ["form-control"]
attrs {"type" : "text"}
classList = ["form-control"]
attrs = {"type" : "text"}
cb :
proc add2DownloadList(e : Event) =
let rows = table.querySelectorAll("tbody tr")
@@ -298,20 +299,20 @@ htmlDocument document, document.body:
if cbox.checked:
dp.addPkg(readTableRow(row)["filename"].getStr)
proc oninput(e : Event) =
if pkgMap.len == 0 or node.value.len < 2: return
let pkgtable = newPkgTable(table, $node.value)
if pkgMap.len == 0 or elem.value.len < 2: return
let pkgtable = newPkgTable(table, $elem.value)
pkgtable.addButton.addEventListener("click", add2DownloadList)
node.addEventListener("input", oninput)
elem.addEventListener("input", oninput)
"div":
class ["row"]
classList = ["row"]
"div":
class ["col-sm-3"]
classList = ["col-sm-3"]
cb:
dp = newDownloadPanel(node)
dp = newDownloadPanel(elem)
"div":
class ["col-sm-9"]
classList = ["col-sm-9"]
cb:
table = node
table = elem

View File

@@ -33,6 +33,8 @@ import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import static java.nio.file.StandardCopyOption.ATOMIC_MOVE;
@XmlRootElement
class PkgTuple
{
@@ -306,7 +308,7 @@ public class PacmanWebService
if (filename == null)
throw new BadRequestException();
File file = new File(ctx.getRepoFolder(), filename);
File file = File.createTempFile(filename, "tmp", new File(ctx.getRepoFolder()));
TypedQuery<PkgData> fquery = em.createQuery(fileNameQuery, PkgData.class);
fquery.setParameter("fileName", filename);
@@ -332,6 +334,7 @@ public class PacmanWebService
ut.begin();
PkgData pkg = Parser.parseFile(file);
pkg.fileName = filename;
TypedQuery<PkgName> nquery = em.createQuery(nameQuery, PkgName.class);
nquery.setParameter("name", pkg.name.id);
@@ -345,6 +348,7 @@ public class PacmanWebService
log.log(Level.INFO, String.format("Persisting package %s", pkg.fileName));
URI pkgUri = uriInfo.getAbsolutePathBuilder().path(pkg.fileName).build();
ut.commit();
Files.move(file.toPath(), new File(ctx.getRepoFolder(), filename).toPath(), ATOMIC_MOVE);
ctx.invalidateCache = true;
cachedMap = null;
return Response.created(pkgUri).build();