diff --git a/ccp/js/methodlistcontroller.js b/ccp/js/methodlistcontroller.js index 70368c9..e459787 100644 --- a/ccp/js/methodlistcontroller.js +++ b/ccp/js/methodlistcontroller.js @@ -83,6 +83,9 @@ class CCPMethodList extends HTMLElement{ ` : `` } +

@@ -300,7 +303,7 @@ class CCPMethodList extends HTMLElement{ toArchive(id){ this.#boot.secureFetch(`${this.#serviceurl}/methods/${id}/archive`, { method: "POST" }) .then(reply =>{ - if (reply.status !== 200) { + if (!reply.ok) { throw "Unable to archive" } }).catch(err=>{ alert(err)}) @@ -310,7 +313,7 @@ class CCPMethodList extends HTMLElement{ if(url){ this.#boot.secureFetch(`${this.#serviceurl}/methods/archive?url=${url}`) .then(reply =>{ - if (reply.status !== 200) { + if (!reply.ok) { throw "Unable to fetch from archive" } return reply.text() @@ -320,6 +323,21 @@ class CCPMethodList extends HTMLElement{ } } + publish(id){ + this.#boot.secureFetch(`${this.#serviceurl}/methods/${id}/publish`, { method: "POST" }) + .then(reply =>{ + if (!reply.ok) { + throw `Unable to archive (${reply.status})` + } + }).catch(err=>{ alert(err)}) + } + + isAuthor(m){ + const href = `${this.#boot.url}/admin/realms/${this.#boot.realm}/users/${this.#boot.subject}` + const found = m.metadata.filter(md=>{return md.role === "author" && md.href === href}) + return found.length > 0 + } + #process_list_bss = { template : "#PROCESS_LIST_TEMPLATE", target : "ul[name=process_category_list]", @@ -380,7 +398,7 @@ class CCPMethodList extends HTMLElement{ { target : "li.ccp-process", "in" : (e,d)=>this.#filtered[d], - apply : (e,d)=>{ e.alt = e.title = d.title }, + apply : (e,d)=>{ e.alt = e.title = `${d.title} (${d.id})` }, on_click : ev=>{ const id = ev.currentTarget.bss_input.data.id if(ev.target.getAttribute("name") === "export_method"){ @@ -395,6 +413,10 @@ class CCPMethodList extends HTMLElement{ if(confirm("Please confirm archiving of method to workspace?")){ this.toArchive(id) } + }else if(ev.target.getAttribute("name") === "publish"){ + if(confirm("Please confirm publication of method to VRE?")){ + this.publish(id) + } } }, on_dragstart : ev=>{ @@ -423,6 +445,10 @@ class CCPMethodList extends HTMLElement{ target: "button[name=edit]", apply : (e,d)=>{ e.style.display = this.#allowedit ? "revert" : "none" } }, + { + target: "button[name=publish]", + apply : (e,d)=>{ e.style.display = this.isAuthor(d) ? "revert" : "none" } + }, { target : "span[name=author]", "in" : (e,d)=>d.metadata.filter(md=>md.role === "author"),