2022-03-22 14:09:54 +01:00
|
|
|
class CCPMethodList extends HTMLElement{
|
|
|
|
|
|
|
|
#boot;
|
|
|
|
#rootdoc;
|
|
|
|
#data;
|
|
|
|
#filtered;
|
2022-03-25 15:39:39 +01:00
|
|
|
#dragged = null;
|
2022-03-22 14:09:54 +01:00
|
|
|
|
2022-07-18 18:08:53 +02:00
|
|
|
#serviceurl;
|
|
|
|
|
2022-03-22 14:09:54 +01:00
|
|
|
constructor(){
|
|
|
|
super()
|
|
|
|
this.#boot = document.querySelector("d4s-boot-2")
|
2022-07-18 18:08:53 +02:00
|
|
|
this.#serviceurl = this.getAttribute("serviceurl")
|
2022-03-22 14:09:54 +01:00
|
|
|
this.#rootdoc = this.attachShadow({ "mode" : "open"})
|
2022-07-18 18:08:53 +02:00
|
|
|
this.render()
|
|
|
|
this.fetchProcesses()
|
2022-03-22 14:09:54 +01:00
|
|
|
}
|
|
|
|
|
2022-07-18 18:08:53 +02:00
|
|
|
render(){
|
|
|
|
this.#rootdoc.innerHTML = `
|
|
|
|
<div>
|
|
|
|
<style>
|
|
|
|
.process_container{
|
|
|
|
display: flex;
|
|
|
|
flex-direction:column;
|
|
|
|
}
|
|
|
|
input[name=search]{
|
|
|
|
display: block;
|
|
|
|
padding: 0.375rem 0.75rem;
|
|
|
|
color: #495057;
|
|
|
|
background-color: #fff;
|
|
|
|
background-clip: padding-box;
|
|
|
|
border: 1px solid #ced4da;
|
|
|
|
border-radius: 0.25rem;
|
|
|
|
transition: border-color .15s ease-in-out,box-shadow .15s ease-in-out;
|
|
|
|
}
|
|
|
|
input:focus{
|
|
|
|
border-color: #80bdff;
|
|
|
|
outline: 0;
|
|
|
|
box-shadow: 0 0 0 0.2rem rgb(0 123 255 / 25%);
|
|
|
|
}
|
|
|
|
ul.process_list{
|
|
|
|
list-style: none;
|
|
|
|
padding-left: 0;
|
|
|
|
color: #495057;
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
gap: .25rem;
|
|
|
|
user-select: none;
|
|
|
|
}
|
|
|
|
li.process_list_item{
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
gap: 0.25rem;
|
|
|
|
cursor: pointer;
|
|
|
|
border: solid 1px rgba(0,0,0,.3);
|
|
|
|
padding: 0.3rem;
|
|
|
|
border-radius: 0.3rem;
|
|
|
|
box-shadow: #333333 1px 1px 4px;
|
|
|
|
background: #eeeeee;
|
|
|
|
transition: background .3s;
|
|
|
|
}
|
|
|
|
li.process_list_item:hover{
|
|
|
|
background: #ffffff;
|
|
|
|
}
|
|
|
|
ul.keyword_list{
|
|
|
|
list-style: none;
|
|
|
|
display: flex;
|
|
|
|
flex-direction: row;
|
|
|
|
gap:2px;
|
|
|
|
padding-left: 0;
|
|
|
|
font-size: x-small;
|
|
|
|
font-weight: 300;
|
|
|
|
}
|
|
|
|
li.keyword_list_item{
|
|
|
|
display: inline-block;
|
|
|
|
padding: 0.25em 0.4em;
|
|
|
|
line-height: 1;
|
|
|
|
text-align: center;
|
|
|
|
white-space: nowrap;
|
|
|
|
vertical-align: baseline;
|
|
|
|
border-radius: 0.25rem;
|
|
|
|
background-color: #eeffff;
|
|
|
|
color: #0099CC;
|
|
|
|
border: solid 1px #0099CC;
|
|
|
|
}
|
|
|
|
.process_list_item_header{
|
|
|
|
margin: 0;
|
|
|
|
}
|
2022-07-21 12:35:21 +02:00
|
|
|
ul.author_list{
|
|
|
|
list-style: none;
|
|
|
|
display: flex;
|
|
|
|
flex-direction: row;
|
|
|
|
gap:2px;
|
|
|
|
padding-left: 0;
|
|
|
|
font-size: small;
|
|
|
|
font-weight: 300;
|
|
|
|
}
|
|
|
|
li.author_list_item{
|
|
|
|
display: inline-block;
|
|
|
|
padding: 0.25em 0.4em;
|
|
|
|
line-height: 1;
|
|
|
|
text-align: center;
|
|
|
|
white-space: nowrap;
|
|
|
|
vertical-align: baseline;
|
|
|
|
border-radius: 0.25rem;
|
|
|
|
background-color: #eeffff;
|
|
|
|
color: #9900CC;
|
|
|
|
border: solid 1px #9900CC;
|
|
|
|
}
|
2022-07-18 18:08:53 +02:00
|
|
|
</style>
|
|
|
|
<template id="PROCESS_LIST_TEMPLATE">
|
|
|
|
<ul class="process_list" name="process_list">
|
|
|
|
<li class="process_list_item" draggable="true">
|
|
|
|
<h4 class="process_list_item_header"></h4>
|
2022-07-21 12:35:21 +02:00
|
|
|
<i></i>
|
|
|
|
<ul name="authors" class="author_list">
|
|
|
|
<li class="author_list_item"></li>
|
|
|
|
</ul>
|
2022-07-18 18:08:53 +02:00
|
|
|
<ul name="keywords" class="keyword_list">
|
|
|
|
<li class="keyword_list_item"></li>
|
|
|
|
</ul>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</template>
|
|
|
|
<div class="process_container">
|
2022-07-19 09:54:40 +02:00
|
|
|
<input name="search" type="text" placeholder="Search ..."/>
|
2022-07-18 18:08:53 +02:00
|
|
|
<ul name="process_list"></ul>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
`
|
2022-03-22 14:09:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
connectedCallback(){
|
2022-04-12 19:51:38 +02:00
|
|
|
|
2022-03-22 14:09:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
fetchProcesses(){
|
2022-04-12 19:51:38 +02:00
|
|
|
console.log("Calling fetch processes")
|
2022-07-21 15:42:55 +02:00
|
|
|
this.#boot.secureFetch(this.#serviceurl + "/methods").
|
2022-04-12 19:51:38 +02:00
|
|
|
then(resp=>{
|
|
|
|
console.log("Received resp for processes ", resp.status)
|
|
|
|
return resp.json()
|
|
|
|
}).then(data=>{
|
|
|
|
console.log("Processes parsed to json", data)
|
|
|
|
this.#data = data
|
|
|
|
this.showList()
|
|
|
|
}).catch(err=>{
|
|
|
|
alert("Error while downloading methods: ", err)
|
|
|
|
})
|
2022-03-22 14:09:54 +01:00
|
|
|
}
|
|
|
|
|
2022-04-12 19:51:38 +02:00
|
|
|
showList(){
|
2022-03-22 14:09:54 +01:00
|
|
|
this.enableSearch()
|
|
|
|
this.updateList()
|
|
|
|
}
|
|
|
|
|
|
|
|
updateList(filter){
|
|
|
|
if(filter === "" || filter == null || filter == undefined){
|
|
|
|
this.#filtered = []
|
|
|
|
}else{
|
|
|
|
const f = filter.toLowerCase()
|
2022-07-21 15:42:55 +02:00
|
|
|
this.#filtered = this.#data.filter(d=>{
|
2022-03-22 14:09:54 +01:00
|
|
|
return false ||
|
|
|
|
(d.title.toLowerCase().indexOf(f) !== -1)||
|
|
|
|
(d.description.indexOf(f) !== -1) ||
|
|
|
|
(d.keywords.map(k=>k.toLowerCase()).indexOf(f) !== -1)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
BSS.apply(this.#process_list_bss, this.#rootdoc)
|
|
|
|
}
|
|
|
|
|
|
|
|
enableSearch(){
|
|
|
|
const search = this.#rootdoc.querySelector("input[name=search]")
|
|
|
|
search.addEventListener("input", ev=>{
|
|
|
|
this.updateList(ev.currentTarget.value)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#process_list_bss = {
|
2022-03-25 15:39:39 +01:00
|
|
|
template : "#PROCESS_LIST_TEMPLATE",
|
|
|
|
target : "ul[name=process_list]",
|
2022-03-22 14:09:54 +01:00
|
|
|
"in" : this,
|
2022-03-25 15:39:39 +01:00
|
|
|
recurse : [
|
2022-03-22 14:09:54 +01:00
|
|
|
{
|
2022-03-25 15:39:39 +01:00
|
|
|
target : "li",
|
2022-03-22 14:09:54 +01:00
|
|
|
"in" : (e,d)=>this.#filtered,
|
2022-03-25 15:39:39 +01:00
|
|
|
on_dragstart : ev=>{
|
|
|
|
ev.dataTransfer.effectAllowed = 'move'
|
|
|
|
ev.dataTransfer.setData('text/html', ev.currentTarget.innerHTML)
|
|
|
|
ev.dataTransfer.setData('text/plain+ccpmethod', ev.currentTarget.bss_input.data.id)
|
2022-07-21 18:57:22 +02:00
|
|
|
ev.dataTransfer.setData('application/json+ccpmethod', JSON.stringify(ev.currentTarget.bss_input.data))
|
2022-03-25 15:39:39 +01:00
|
|
|
},
|
|
|
|
on_dragend : ev=>{
|
|
|
|
ev.preventDefault()
|
|
|
|
},
|
|
|
|
recurse : [
|
2022-03-22 14:09:54 +01:00
|
|
|
{
|
2022-03-25 15:39:39 +01:00
|
|
|
target : "h4",
|
2022-07-21 12:35:21 +02:00
|
|
|
apply : (e,d)=>{ e.textContent = `${d.title} v. ${d.version}` }
|
2022-03-22 14:09:54 +01:00
|
|
|
},
|
|
|
|
{
|
2022-03-25 15:39:39 +01:00
|
|
|
target : "i",
|
|
|
|
apply : (e,d)=>{ e.textContent = d.description }
|
2022-03-22 14:09:54 +01:00
|
|
|
},
|
|
|
|
{
|
2022-07-21 12:35:21 +02:00
|
|
|
target : "ul[name=authors]",
|
|
|
|
recurse : {
|
|
|
|
target : "li",
|
|
|
|
"in" : (e,d)=>d.metadata.filter(md=>md.role === "author"),
|
|
|
|
apply : (e,d)=>{ e.textContent = d.title }
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
target : "ul[name=keywords]",
|
2022-03-25 15:39:39 +01:00
|
|
|
recurse : {
|
|
|
|
target : "li",
|
2022-03-22 14:09:54 +01:00
|
|
|
"in" : (e,d)=>d.keywords,
|
2022-03-25 15:39:39 +01:00
|
|
|
apply : (e,d)=>{ e.alt = e.title = e.textContent = d }
|
2022-03-22 14:09:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-03-22 19:03:42 +01:00
|
|
|
window.customElements.define('d4s-ccp-methodlist', CCPMethodList);
|