added triggers for archiving and unarchiving methods and for uploading from file
This commit is contained in:
parent
cb51f396fe
commit
73b80a4567
|
@ -8,6 +8,9 @@ class CCPMethodList extends HTMLElement{
|
|||
#searchfield = null;
|
||||
#allowedit = false;
|
||||
#allowexecute = false;
|
||||
#archive = false;
|
||||
#fileupload = null;
|
||||
#archiveupload = null;
|
||||
|
||||
#serviceurl;
|
||||
|
||||
|
@ -16,6 +19,7 @@ class CCPMethodList extends HTMLElement{
|
|||
this.#boot = document.querySelector("d4s-boot-2")
|
||||
this.#serviceurl = this.getAttribute("serviceurl")
|
||||
this.#rootdoc = this.attachShadow({ "mode" : "open"})
|
||||
this.#archive = this.getAttribute("archive")
|
||||
this.render()
|
||||
this.fetchProcesses()
|
||||
}
|
||||
|
@ -73,6 +77,12 @@ class CCPMethodList extends HTMLElement{
|
|||
<path d="M9 39h2.2l22.15-22.15-2.2-2.2L9 36.8Zm30.7-24.3-6.4-6.4 2.1-2.1q.85-.85 2.1-.85t2.1.85l2.2 2.2q.85.85.85 2.1t-.85 2.1Zm-2.1 2.1L12.4 42H6v-6.4l25.2-25.2Zm-5.35-1.05-1.1-1.1 2.2 2.2Z"/>
|
||||
</svg>
|
||||
</button>
|
||||
${ this.#archive ? `
|
||||
<button data-index="0" name="archive" title="Archive to workspace" class="btn btn-primary ccp-toolbar-button ccp-toolbar-button-small">
|
||||
<svg viewBox="0 96 960 960"><path d="M140 796h680V516H140v280Zm540.118-90Q701 706 715.5 691.382q14.5-14.617 14.5-35.5Q730 635 715.382 620.5q-14.617-14.5-35.5-14.5Q659 606 644.5 620.618q-14.5 14.617-14.5 35.5Q630 677 644.618 691.5q14.617 14.5 35.5 14.5ZM880 456h-85L695 356H265L165 456H80l142-142q8-8 19.278-13 11.278-5 23.722-5h430q12.444 0 23.722 5T738 314l142 142ZM140 856q-24.75 0-42.375-17.625T80 796V456h800v340q0 24.75-17.625 42.375T820 856H140Z"/></svg>
|
||||
</button>`
|
||||
: ``
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
<p class="m-0 p-0 small" name="description"></p>
|
||||
|
@ -89,15 +99,25 @@ class CCPMethodList extends HTMLElement{
|
|||
</ul>
|
||||
</template>
|
||||
<div class="card">
|
||||
<div class="card-header" style="padding:0.5rem">
|
||||
<div class="card-header" style="min-width:600px">
|
||||
<div class="ccp-toolbar-header">
|
||||
<div>
|
||||
<span name="header" class="mr-2">List of available methods</span>
|
||||
<span name="header" class="mr-2">Methods</span>
|
||||
</div>
|
||||
<div class="ccp-toolbar-right">
|
||||
<div class="ccp-toolbar-right d-flex" style="gap:2px">
|
||||
<button name="refresh" class="btn btn-primary ccp-toolbar-button" title="Refresh">
|
||||
<svg viewBox="0 0 48 48"><path d="M24 40q-6.65 0-11.325-4.675Q8 30.65 8 24q0-6.65 4.675-11.325Q17.35 8 24 8q4.25 0 7.45 1.725T37 14.45V8h3v12.7H27.3v-3h8.4q-1.9-3-4.85-4.85Q27.9 11 24 11q-5.45 0-9.225 3.775Q11 18.55 11 24q0 5.45 3.775 9.225Q18.55 37 24 37q4.15 0 7.6-2.375 3.45-2.375 4.8-6.275h3.1q-1.45 5.25-5.75 8.45Q29.45 40 24 40Z"/></svg>
|
||||
</button>
|
||||
</button>
|
||||
<label name="fileupload" class="btn btn-primary ccp-toolbar-button m-0" title="Upload from file">
|
||||
<svg viewBox="0 96 960 960"><path d="M452 854h60V653l82 82 42-42-156-152-154 154 42 42 84-84v201ZM220 976q-24 0-42-18t-18-42V236q0-24 18-42t42-18h361l219 219v521q0 24-18 42t-42 18H220Zm331-554V236H220v680h520V422H551ZM220 236v186-186 680-680Z"/></svg>
|
||||
<input type="file" class="d-none" multiple="multiple"/>
|
||||
</label>
|
||||
<div class="d-flex ml-2" style="gap:2px">
|
||||
<input type="text" class="form-control" placeholder="Paste link here"/>
|
||||
<button name="archive" class="btn btn-primary ccp-toolbar-button m-0" title="Upload from link">
|
||||
<svg viewBox="0 96 960 960"><path d="M450 776H280q-83 0-141.5-58.5T80 576q0-83 58.5-141.5T280 376h170v60H280q-58.333 0-99.167 40.765-40.833 40.764-40.833 99Q140 634 180.833 675q40.834 41 99.167 41h170v60ZM324 606v-60h310v60H324Zm556-30h-60q0-58-40.833-99-40.834-41-99.167-41H510v-60h170q83 0 141.5 58.5T880 576ZM699 896V776H579v-60h120V596h60v120h120v60H759v120h-60Z"/></svg>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -120,6 +140,25 @@ class CCPMethodList extends HTMLElement{
|
|||
this.#searchfield.addEventListener("input", ev=>{
|
||||
this.updateList()
|
||||
})
|
||||
|
||||
this.#fileupload = this.#rootdoc.querySelector("label[name=fileupload] > input[type=file]")
|
||||
this.#fileupload.addEventListener("change", ev=>{
|
||||
const filelist = ev.target.files;
|
||||
if (filelist.length > 0) {
|
||||
const files = Array.prototype.slice.call(filelist)
|
||||
this.importMethods(files)
|
||||
}
|
||||
})
|
||||
|
||||
this.#archiveupload = this.#rootdoc.querySelector("button[name=archive]")
|
||||
this.#archiveupload.addEventListener("click", ev=>{
|
||||
const link = ev.target.parentElement.querySelector("input").value
|
||||
if(link){
|
||||
if(confirm("Confirm importing of method from link?")){
|
||||
this.fromArchive(link)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
connectedCallback(){
|
||||
|
@ -258,6 +297,29 @@ class CCPMethodList extends HTMLElement{
|
|||
}
|
||||
}
|
||||
|
||||
toArchive(id){
|
||||
this.#boot.secureFetch(`${this.#serviceurl}/methods/${id}/archive`, { method: "POST" })
|
||||
.then(reply =>{
|
||||
if (reply.status !== 200) {
|
||||
throw "Unable to archive"
|
||||
}
|
||||
}).catch(err=>{ alert(err)})
|
||||
}
|
||||
|
||||
fromArchive(url){
|
||||
if(url){
|
||||
this.#boot.secureFetch(`${this.#serviceurl}/methods/archive?url=${url}`)
|
||||
.then(reply =>{
|
||||
if (reply.status !== 200) {
|
||||
throw "Unable to fetch from archive"
|
||||
}
|
||||
return reply.text()
|
||||
}).then(data=>{
|
||||
this.fetchProcesses()
|
||||
}).catch(err=>{ alert(err)})
|
||||
}
|
||||
}
|
||||
|
||||
#process_list_bss = {
|
||||
template : "#PROCESS_LIST_TEMPLATE",
|
||||
target : "ul[name=process_category_list]",
|
||||
|
@ -329,6 +391,10 @@ class CCPMethodList extends HTMLElement{
|
|||
}else if(ev.target.getAttribute("name") === "edit"){
|
||||
const event = new CustomEvent('neweditrequest', { detail: ev.currentTarget.bss_input.data });
|
||||
document.dispatchEvent(event)
|
||||
}else if(ev.target.getAttribute("name") === "archive"){
|
||||
if(confirm("Confirm archiving of method to workspace?")){
|
||||
this.toArchive(id)
|
||||
}
|
||||
}
|
||||
},
|
||||
on_dragstart : ev=>{
|
||||
|
@ -386,4 +452,4 @@ class CCPMethodList extends HTMLElement{
|
|||
}
|
||||
}
|
||||
|
||||
window.customElements.define('d4s-ccp-methodlist', CCPMethodList);
|
||||
window.customElements.define('d4s-ccp-methodlist', CCPMethodList);
|
Loading…
Reference in New Issue