button for publishing, column in the shared files table

pull/42/head
Zlatin Balevsky 2020-03-10 01:39:55 +00:00
parent 17cd60afe3
commit 8798ea38e8
3 changed files with 44 additions and 4 deletions

View File

@ -505,6 +505,24 @@ class MainFrameController {
clipboard.setContents(selection, null)
}
@ControllerAction
void publish() {
def selectedFiles = view.selectedSharedFiles()
if (selectedFiles == null || selectedFiles.isEmpty())
return
if (model.publishButtonText == "Unpublish") {
selectedFiles.each {
it.unpublish()
}
} else {
long now = System.currentTimeMillis()
selectedFiles.stream().filter({!it.isPublished()}).forEach({it.publish(now)})
}
// TODO: issue event to core
view.refreshSharedFiles()
}
void startChat(Persona p) {
if (!mvcGroup.getChildrenGroups().containsKey(p.getHumanReadableName())) {
def params = [:]

View File

@ -103,6 +103,8 @@ class MainFrameModel {
@Observable boolean previewButtonEnabled
@Observable String resumeButtonText
@Observable boolean addCommentButtonEnabled
@Observable boolean publishButtonEnabled
@Observable String publishButtonText
@Observable boolean subscribeButtonEnabled
@Observable boolean markNeutralFromTrustedButtonEnabled
@Observable boolean markDistrustedButtonEnabled
@ -253,6 +255,7 @@ class MainFrameModel {
distrusted.addAll(core.trustService.bad.values())
resumeButtonText = "Retry"
publishButtonText = "Publish"
searchesPaneButtonEnabled = false
downloadsPaneButtonEnabled = true

View File

@ -292,6 +292,7 @@ class MainFrameView {
Core core = application.context.get("core")
core.certificateManager.hasLocalCertificate(new InfoHash(it.getRoot()))
})
closureColumn(header : "Published", preferredWidth : 50, type : Boolean, read : {row -> row.isPublished()})
closureColumn(header : "Search Hits", preferredWidth: 50, type : Integer, read : {it.getHits()})
closureColumn(header : "Downloaders", preferredWidth: 50, type : Integer, read : {it.getDownloaders().size()})
}
@ -316,9 +317,11 @@ class MainFrameView {
radioButton(text : "Table", selected : false, buttonGroup : sharedViewType, actionPerformed : showSharedFilesTable)
}
panel {
button(text : "Share", actionPerformed : shareFiles)
button(text : "Add Comment", enabled : bind {model.addCommentButtonEnabled}, addCommentAction)
button(text : "Certify", enabled : bind {model.addCommentButtonEnabled}, issueCertificateAction)
gridBagLayout()
button(text : "Share", constraints : gbc(gridx: 0), actionPerformed : shareFiles)
button(text : "Add Comment", enabled : bind {model.addCommentButtonEnabled}, constraints : gbc(gridx: 1), addCommentAction)
button(text : "Certify", enabled : bind {model.addCommentButtonEnabled}, constraints : gbc(gridx: 2), issueCertificateAction)
button(text : bind {model.publishButtonText}, enabled : bind {model.publishButtonEnabled}, constraints : gbc(gridx:3), publishAction)
}
panel {
panel {
@ -682,14 +685,30 @@ class MainFrameView {
if (selectedFiles == null || selectedFiles.isEmpty())
return
model.addCommentButtonEnabled = true
model.publishButtonEnabled = true
boolean unpublish = true
selectedFiles.each {
unpublish &= it.isPublished()
}
model.publishButtonText = unpublish ? "Unpublish" : "Publish"
})
def sharedFilesTree = builder.getVariable("shared-files-tree")
sharedFilesTree.addMouseListener(sharedFilesMouseListener)
sharedFilesTree.addTreeSelectionListener({
def selectedNode = sharedFilesTree.getLastSelectedPathComponent()
model.addCommentButtonEnabled = selectedNode != null
model.publishButtonEnabled = selectedNode != null
def selectedFiles = selectedSharedFiles()
if (selectedFiles == null || selectedFiles.isEmpty())
return
boolean unpublish = true
selectedFiles.each {
unpublish &= it.isPublished()
}
model.publishButtonText = unpublish ? "Unpublish" : "Publish"
})
sharedFilesTree.addTreeExpansionListener(expansionListener)