updated htmlutils external
added temporary file generation when uploading a new package
This commit is contained in:
@@ -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 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")
|
val wildflyURL = SettingKey[String]("wildfly-url", "The username to use to connect to wildfly with jboss-cli.sh")
|
||||||
|
|
||||||
wildflyUsername := "root"
|
wildflyUsername := "admin"
|
||||||
wildflyPassword := "123456"
|
wildflyPassword := "123456"
|
||||||
wildflyURL := "localhost:1234"
|
wildflyURL := "localhost:1234"
|
||||||
|
|
||||||
|
Submodule nim/htmlutils updated: 12868f49c8...c57338fc27
191
nim/jpacrepo.nim
191
nim/jpacrepo.nim
@@ -1,4 +1,5 @@
|
|||||||
import dom
|
import dom
|
||||||
|
import htmlutils.tree
|
||||||
import htmlutils.utils
|
import htmlutils.utils
|
||||||
import json
|
import json
|
||||||
import streams
|
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")
|
proc formatByteSize(size : BiggestInt) : string = size.float64.formatEng(precision=1, siPrefix=true, unit = "B")
|
||||||
|
|
||||||
type DownloadPanel = ref object
|
type DownloadPanel = ref object
|
||||||
badge : Node
|
badge : Element
|
||||||
listgroup : Node
|
listgroup : Element
|
||||||
pkgs : HashSet[string]
|
pkgs : HashSet[string]
|
||||||
footer : Node
|
footer : Element
|
||||||
sizeLabel : Node
|
sizeLabel : Element
|
||||||
size : BiggestInt
|
size : BiggestInt
|
||||||
|
|
||||||
proc newDownloadPanel(parent : Node) : DownloadPanel =
|
proc newDownloadPanel(parent : Element) : DownloadPanel =
|
||||||
let dp = DownloadPanel()
|
let dp = DownloadPanel()
|
||||||
dp.pkgs = initSet[string]()
|
dp.pkgs = initSet[string]()
|
||||||
htmlDocument(document, parent):
|
htmlTreeAppend(parent):
|
||||||
"div":
|
"div":
|
||||||
class ["panel", "panel-default"]
|
classList = ["panel", "panel-default"]
|
||||||
"div":
|
"div":
|
||||||
class ["panel-heading"]
|
classList = ["panel-heading"]
|
||||||
"h3":
|
"h3":
|
||||||
class ["panel-title"]
|
classList = ["panel-title"]
|
||||||
"a":
|
"a":
|
||||||
text "Package list "
|
text = "Package list "
|
||||||
"span":
|
"span":
|
||||||
class ["badge", "pull-right"]
|
classList = ["badge", "pull-right"]
|
||||||
style {"display" :"none"}
|
style {"display" :"none"}
|
||||||
cb:
|
cb:
|
||||||
dp.badge = node
|
dp.badge = elem
|
||||||
|
|
||||||
"ul":
|
"ul":
|
||||||
class ["list-group"]
|
classList = ["list-group"]
|
||||||
cb:
|
cb:
|
||||||
dp.listgroup = node
|
dp.listgroup = elem
|
||||||
"div":
|
"div":
|
||||||
class ["panel-footer"]
|
classList = ["panel-footer"]
|
||||||
style {
|
style = {
|
||||||
"text-align" : "right",
|
"text-align" : "right",
|
||||||
"display" :"none"
|
"display" :"none"
|
||||||
}
|
}
|
||||||
"span":
|
"span":
|
||||||
style {
|
style = {
|
||||||
"font-weight" : "bold",
|
"font-weight" : "bold",
|
||||||
"padding-right" : "10px"
|
"padding-right" : "10px"
|
||||||
}
|
}
|
||||||
cb:
|
cb:
|
||||||
dp.sizeLabel = node
|
dp.sizeLabel = elem
|
||||||
"button":
|
"button":
|
||||||
class ["btn", "btn-primary"]
|
classList = ["btn", "btn-primary"]
|
||||||
attrs {"type" : "button"}
|
attrs = {"type" : "button"}
|
||||||
"span":
|
"span":
|
||||||
class ["glyphicon", "glyphicon-download"]
|
classList = ["glyphicon", "glyphicon-download"]
|
||||||
cb:
|
cb:
|
||||||
node.appendChild(document.createTextNode(" Download"))
|
elem.appendChild(document.createTextNode(" Download"))
|
||||||
let clickHandler = proc(e : Event) =
|
let clickHandler = proc(e : Event) =
|
||||||
let pkglist : seq[string] = sequtils.toSeq(dp.pkgs.items())
|
let pkglist : seq[string] = sequtils.toSeq(dp.pkgs.items())
|
||||||
let form = cast[Formelement](document.createElement("form"))
|
let form = cast[Formelement](document.createElement("form"))
|
||||||
@@ -78,9 +79,9 @@ proc newDownloadPanel(parent : Node) : DownloadPanel =
|
|||||||
form.appendChild(tf)
|
form.appendChild(tf)
|
||||||
document.body.appendChild(form)
|
document.body.appendChild(form)
|
||||||
form.submit()
|
form.submit()
|
||||||
node.addEventListener("click", clickHandler)
|
elem.addEventListener("click", clickHandler)
|
||||||
cb:
|
cb:
|
||||||
dp.footer = node
|
dp.footer = elem
|
||||||
dp
|
dp
|
||||||
|
|
||||||
|
|
||||||
@@ -101,13 +102,13 @@ proc addPkg(dp : DownloadPanel, pkgfile : string) =
|
|||||||
let sz = parseInt(req.responseText)
|
let sz = parseInt(req.responseText)
|
||||||
dp.size += sz
|
dp.size += sz
|
||||||
dp.updateSize
|
dp.updateSize
|
||||||
htmlDocument(document, dp.listgroup):
|
htmlTreeAppend(dp.listgroup):
|
||||||
"li":
|
"li":
|
||||||
var listElement : Node
|
var listElement : Element
|
||||||
class ["list-group-item"]
|
classList = ["list-group-item"]
|
||||||
text pkgfile
|
text = pkgfile
|
||||||
"span":
|
"span":
|
||||||
class ["glyphicon", "glyphicon-remove", "pull-right"]
|
classList = ["glyphicon", "glyphicon-remove", "pull-right"]
|
||||||
cb:
|
cb:
|
||||||
let fn = proc(e : Event) =
|
let fn = proc(e : Event) =
|
||||||
dp.pkgs.excl(pkgfile)
|
dp.pkgs.excl(pkgfile)
|
||||||
@@ -115,51 +116,51 @@ proc addPkg(dp : DownloadPanel, pkgfile : string) =
|
|||||||
dp.updateBadge
|
dp.updateBadge
|
||||||
dp.size -= sz
|
dp.size -= sz
|
||||||
dp.updateSize
|
dp.updateSize
|
||||||
node.addEventListener("click", fn)
|
elem.addEventListener("click", fn)
|
||||||
cb:
|
cb:
|
||||||
listElement = node
|
listElement = elem
|
||||||
req.addEventListener("load", load_cb)
|
req.addEventListener("load", load_cb)
|
||||||
req.open("get", serverURL & "rest/pkg/filesize/" & pkgfile)
|
req.open("get", serverURL & "rest/pkg/filesize/" & pkgfile)
|
||||||
req.setRequestHeader("Accept", "application/json")
|
req.setRequestHeader("Accept", "application/json")
|
||||||
req.send()
|
req.send()
|
||||||
dp.updateBadge
|
dp.updateBadge
|
||||||
|
|
||||||
proc readTableRow(row : Node) : JsonNode =
|
proc readTableRow(row : Element) : JsonNode =
|
||||||
let pkgname = $row.querySelector("td:nth-child(2)").textContent
|
let pkgname = $row.querySelector("td:nth-child(2)").textContent
|
||||||
let version = $row.querySelector("td:nth-child(3) button").textContent
|
let version = $row.querySelector("td:nth-child(3) button").textContent
|
||||||
let arch = $row.querySelector("td:nth-child(4) button").textContent
|
let arch = $row.querySelector("td:nth-child(4) button").textContent
|
||||||
pkgMap[pkgname][version][arch]
|
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":
|
"div":
|
||||||
var button : Node
|
var button : Element
|
||||||
class ["dropdown"]
|
classList = ["dropdown"]
|
||||||
"button":
|
"button":
|
||||||
class ["btn", "btn-default", "dropdown-toggle"]
|
classList = ["btn", "btn-default", "dropdown-toggle"]
|
||||||
attrs {"data-toggle": "dropdown", "type": "button"}
|
attrs = {"data-toggle": "dropdown", "type": "button"}
|
||||||
cb:
|
cb:
|
||||||
node.textContent = data.last
|
elem.textContent = data.last
|
||||||
button = node
|
button = elem
|
||||||
"ul":
|
"ul":
|
||||||
class ["dropdown-menu"]
|
classList = ["dropdown-menu"]
|
||||||
cb:
|
cb:
|
||||||
for line in data:
|
for line in data:
|
||||||
htmlDocument(document, node):
|
htmlTreeAppend(elem):
|
||||||
"li":
|
"li":
|
||||||
"a":
|
"a":
|
||||||
text line
|
text = line
|
||||||
cb:
|
cb:
|
||||||
let fn = proc(e: Event) =
|
let fn = proc(e: Event) =
|
||||||
button.textContent = node.textContent
|
button.textContent = elem.textContent
|
||||||
onchange($node.textContent)
|
onchange($elem.textContent)
|
||||||
node.addEventListener("click", fn)
|
elem.addEventListener("click", fn)
|
||||||
|
|
||||||
type PkgTable = ref object
|
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 pkgtable = PkgTable()
|
||||||
var fragments = newSeq[string]()
|
var fragments = newSeq[string]()
|
||||||
for fragment in searchString.splitWhitespace():
|
for fragment in searchString.splitWhitespace():
|
||||||
@@ -171,50 +172,50 @@ proc newPkgTable(parent: Node, searchString : string) : PkgTable =
|
|||||||
searchResult.add(key,value)
|
searchResult.add(key,value)
|
||||||
for table in document.querySelectorAll("table.pkgtable"):
|
for table in document.querySelectorAll("table.pkgtable"):
|
||||||
table.parentNode.removeChild(table)
|
table.parentNode.removeChild(table)
|
||||||
htmlDocument(document, parent):
|
htmlTreeAppend(parent):
|
||||||
"table":
|
"table":
|
||||||
class ["table", "table-striped","pkgtable"]
|
classList = ["table", "table-striped","pkgtable"]
|
||||||
"thead":
|
"thead":
|
||||||
"tr":
|
"tr":
|
||||||
"th":
|
"th":
|
||||||
"button":
|
"button":
|
||||||
class ["btn", "btn-default"]
|
classList = ["btn", "btn-default"]
|
||||||
attrs {"type": "button"}
|
attrs = {"type": "button"}
|
||||||
"span":
|
"span":
|
||||||
class ["glyphicon", "glyphicon-plus"]
|
classList = ["glyphicon", "glyphicon-plus"]
|
||||||
cb:
|
cb:
|
||||||
let txt = document.createTextNode(" Add")
|
let txt = document.createTextNode(" Add")
|
||||||
node.appendChild(txt)
|
elem.appendChild(txt)
|
||||||
pkgtable.addButton = node
|
pkgtable.addButton = elem
|
||||||
"th":
|
"th":
|
||||||
text "Name"
|
text = "Name"
|
||||||
"th":
|
"th":
|
||||||
text "Version"
|
text = "Version"
|
||||||
"th":
|
"th":
|
||||||
text "Arch"
|
text = "Arch"
|
||||||
"th":
|
"th":
|
||||||
text "Installed size"
|
text = "Installed size"
|
||||||
"tbody":
|
"tbody":
|
||||||
cb:
|
cb:
|
||||||
var i = 0
|
var i = 0
|
||||||
for name, versions in searchResult:
|
for name, versions in searchResult:
|
||||||
closureScope:
|
closureScope:
|
||||||
htmlDocument(document, node):
|
htmlTreeAppend(elem):
|
||||||
"tr":
|
"tr":
|
||||||
var row : Node
|
var row : Element
|
||||||
var archCell : Node
|
var archCell : Element
|
||||||
var sizeCell : Node
|
var sizeCell : Element
|
||||||
let size_change_callback = proc(newValue : string) =
|
let size_change_callback = proc(newValue : string) =
|
||||||
sizeCell.textContent = readTableRow(row)["size"].getNum.formatByteSize
|
sizeCell.textContent = readTableRow(row)["size"].getNum.formatByteSize
|
||||||
|
|
||||||
"td":
|
"td":
|
||||||
"div":
|
"div":
|
||||||
class ["checkbox"]
|
classList = ["checkbox"]
|
||||||
"label":
|
"label":
|
||||||
"input":
|
"input":
|
||||||
attrs {"type" : "checkbox"}
|
attrs = {"type" : "checkbox"}
|
||||||
"td":
|
"td":
|
||||||
text $name
|
text = $name
|
||||||
"td":
|
"td":
|
||||||
cb:
|
cb:
|
||||||
var data = newSeq[string]()
|
var data = newSeq[string]()
|
||||||
@@ -228,32 +229,32 @@ proc newPkgTable(parent: Node, searchString : string) : PkgTable =
|
|||||||
newdata.add(arch)
|
newdata.add(arch)
|
||||||
createDropdown(archCell, newdata, size_change_callback)
|
createDropdown(archCell, newdata, size_change_callback)
|
||||||
size_change_callback(newValue)
|
size_change_callback(newValue)
|
||||||
createDropdown(node, data, change_callback)
|
createDropdown(elem, data, change_callback)
|
||||||
"td":
|
"td":
|
||||||
cb:
|
cb:
|
||||||
archCell = node
|
archCell = elem
|
||||||
var data = newSeq[string]()
|
var data = newSeq[string]()
|
||||||
var arches : JsonNode
|
var arches : JsonNode
|
||||||
for v, a in versions:
|
for v, a in versions:
|
||||||
arches = a
|
arches = a
|
||||||
for arch, pkgname in arches:
|
for arch, pkgname in arches:
|
||||||
data.add(arch)
|
data.add(arch)
|
||||||
createDropdown(node, data, size_change_callback)
|
createDropdown(elem, data, size_change_callback)
|
||||||
"td":
|
"td":
|
||||||
cb:
|
cb:
|
||||||
sizeCell = node
|
sizeCell = elem
|
||||||
for v, arches in versions:
|
for v, arches in versions:
|
||||||
for key, value in arches:
|
for key, value in arches:
|
||||||
node.textContent = value["size"].getNum.formatByteSize
|
elem.textContent = value["size"].getNum.formatByteSize
|
||||||
return
|
return
|
||||||
cb:
|
cb:
|
||||||
row = node
|
row = elem
|
||||||
|
|
||||||
pkgtable
|
pkgtable
|
||||||
|
|
||||||
var dp : DownloadPanel
|
var dp : DownloadPanel
|
||||||
# var pkgTable : PkgTable
|
# var pkgTable : PkgTable
|
||||||
htmlDocument document, document.body:
|
htmlTreeappend document.body:
|
||||||
# "img":
|
# "img":
|
||||||
# attrs {"src" : "img/background.bpg"}
|
# attrs {"src" : "img/background.bpg"}
|
||||||
# style {
|
# style {
|
||||||
@@ -264,32 +265,32 @@ htmlDocument document, document.body:
|
|||||||
# "z-index" : "-10"
|
# "z-index" : "-10"
|
||||||
# }
|
# }
|
||||||
"div":
|
"div":
|
||||||
var table : Node
|
var table : Element
|
||||||
style {"background-color" : "rgba(255, 255, 255, 0.25)"}
|
style = {"background-color" : "rgba(255, 255, 255, 0.25)"}
|
||||||
class ["container"]
|
classList = ["container"]
|
||||||
"div":
|
"div":
|
||||||
style {
|
style = {
|
||||||
"margin-top" : "20px",
|
"margin-top" : "20px",
|
||||||
"background-color" : "rgba(224, 224, 224, 0.5)"
|
"background-color" : "rgba(224, 224, 224, 0.5)"
|
||||||
}
|
}
|
||||||
class ["jumbotron"]
|
classList = ["jumbotron"]
|
||||||
"h1":
|
"h1":
|
||||||
text "Jpacrepo"
|
text = "Jpacrepo"
|
||||||
"p":
|
"p":
|
||||||
text "Personal archlinux package repository"
|
text = "Personal archlinux package repository"
|
||||||
"div":
|
"div":
|
||||||
"form":
|
"form":
|
||||||
class ["form-horizontal"]
|
classList = ["form-horizontal"]
|
||||||
"div":
|
"div":
|
||||||
class ["form-group"]
|
classList = ["form-group"]
|
||||||
"label":
|
"label":
|
||||||
class ["control-label", "col-sm-2"]
|
classList = ["control-label", "col-sm-2"]
|
||||||
text " Search package"
|
text = " Search package"
|
||||||
"div":
|
"div":
|
||||||
class ["col-sm-10"]
|
classList = ["col-sm-10"]
|
||||||
"input":
|
"input":
|
||||||
class ["form-control"]
|
classList = ["form-control"]
|
||||||
attrs {"type" : "text"}
|
attrs = {"type" : "text"}
|
||||||
cb :
|
cb :
|
||||||
proc add2DownloadList(e : Event) =
|
proc add2DownloadList(e : Event) =
|
||||||
let rows = table.querySelectorAll("tbody tr")
|
let rows = table.querySelectorAll("tbody tr")
|
||||||
@@ -298,20 +299,20 @@ htmlDocument document, document.body:
|
|||||||
if cbox.checked:
|
if cbox.checked:
|
||||||
dp.addPkg(readTableRow(row)["filename"].getStr)
|
dp.addPkg(readTableRow(row)["filename"].getStr)
|
||||||
proc oninput(e : Event) =
|
proc oninput(e : Event) =
|
||||||
if pkgMap.len == 0 or node.value.len < 2: return
|
if pkgMap.len == 0 or elem.value.len < 2: return
|
||||||
let pkgtable = newPkgTable(table, $node.value)
|
let pkgtable = newPkgTable(table, $elem.value)
|
||||||
pkgtable.addButton.addEventListener("click", add2DownloadList)
|
pkgtable.addButton.addEventListener("click", add2DownloadList)
|
||||||
node.addEventListener("input", oninput)
|
elem.addEventListener("input", oninput)
|
||||||
"div":
|
"div":
|
||||||
class ["row"]
|
classList = ["row"]
|
||||||
"div":
|
"div":
|
||||||
class ["col-sm-3"]
|
classList = ["col-sm-3"]
|
||||||
cb:
|
cb:
|
||||||
dp = newDownloadPanel(node)
|
dp = newDownloadPanel(elem)
|
||||||
"div":
|
"div":
|
||||||
class ["col-sm-9"]
|
classList = ["col-sm-9"]
|
||||||
cb:
|
cb:
|
||||||
table = node
|
table = elem
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@@ -33,6 +33,8 @@ import java.util.*;
|
|||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import static java.nio.file.StandardCopyOption.ATOMIC_MOVE;
|
||||||
|
|
||||||
@XmlRootElement
|
@XmlRootElement
|
||||||
class PkgTuple
|
class PkgTuple
|
||||||
{
|
{
|
||||||
@@ -306,7 +308,7 @@ public class PacmanWebService
|
|||||||
if (filename == null)
|
if (filename == null)
|
||||||
throw new BadRequestException();
|
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);
|
TypedQuery<PkgData> fquery = em.createQuery(fileNameQuery, PkgData.class);
|
||||||
fquery.setParameter("fileName", filename);
|
fquery.setParameter("fileName", filename);
|
||||||
@@ -332,6 +334,7 @@ public class PacmanWebService
|
|||||||
|
|
||||||
ut.begin();
|
ut.begin();
|
||||||
PkgData pkg = Parser.parseFile(file);
|
PkgData pkg = Parser.parseFile(file);
|
||||||
|
pkg.fileName = filename;
|
||||||
|
|
||||||
TypedQuery<PkgName> nquery = em.createQuery(nameQuery, PkgName.class);
|
TypedQuery<PkgName> nquery = em.createQuery(nameQuery, PkgName.class);
|
||||||
nquery.setParameter("name", pkg.name.id);
|
nquery.setParameter("name", pkg.name.id);
|
||||||
@@ -345,6 +348,7 @@ public class PacmanWebService
|
|||||||
log.log(Level.INFO, String.format("Persisting package %s", pkg.fileName));
|
log.log(Level.INFO, String.format("Persisting package %s", pkg.fileName));
|
||||||
URI pkgUri = uriInfo.getAbsolutePathBuilder().path(pkg.fileName).build();
|
URI pkgUri = uriInfo.getAbsolutePathBuilder().path(pkg.fileName).build();
|
||||||
ut.commit();
|
ut.commit();
|
||||||
|
Files.move(file.toPath(), new File(ctx.getRepoFolder(), filename).toPath(), ATOMIC_MOVE);
|
||||||
ctx.invalidateCache = true;
|
ctx.invalidateCache = true;
|
||||||
cachedMap = null;
|
cachedMap = null;
|
||||||
return Response.created(pkgUri).build();
|
return Response.created(pkgUri).build();
|
||||||
|
Reference in New Issue
Block a user