cdn-experiments/ccp/js/methodlistcontroller.js

122 lines
3.1 KiB
JavaScript
Raw Normal View History

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-03-22 19:03:42 +01:00
#serviceurl = "https://nubis1.int.d4science.net:8080"
2022-05-06 11:51:03 +02:00
#cdnurl = "https://cdn.dev.d4science.org/ccp/methodlistfragment.html"
2022-03-22 14:09:54 +01:00
constructor(){
super()
this.#boot = document.querySelector("d4s-boot-2")
this.#rootdoc = this.attachShadow({ "mode" : "open"})
this.fetchMarkup()
}
fetchMarkup(){
2022-03-22 19:03:42 +01:00
return fetch(this.#cdnurl).then(
2022-03-22 14:09:54 +01:00
(reply)=>{
if(reply.status === 200){
return reply.text()
2022-03-25 15:39:39 +01:00
}else{ throw new Exception("Unable to fetch markup") }
2022-03-22 14:09:54 +01:00
}).then(data=>{
this.#rootdoc.innerHTML = data
console.log(this.#boot)
this.fetchProcesses()
}).catch(err=>{
console.error(err)
})
}
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")
this.#boot.secureFetch(this.#serviceurl + "/processes?limit=1000").
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(){
//this.#data = JSON.parse(resp)
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()
this.#filtered = this.#data["processes"].filter(d=>{
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)
},
on_dragend : ev=>{
ev.preventDefault()
},
recurse : [
2022-03-22 14:09:54 +01:00
{
2022-03-25 15:39:39 +01:00
target : "h4",
apply : (e,d)=>{ e.textContent = d.title }
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-03-25 15:39:39 +01:00
target : "ul",
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);