guiLocalSettings.setIfNotExists('guiApi.real_query_timeout',100);class ApiConnector{constructor(config){this.config=config;this.api=axios.create(config);this.bulk_collector={timeout_id:undefined,bulk_parts:[],};}
loadSchema(){let schema_url="/openapi/?format=openapi";return this.query('get',schema_url).then(response=>{return this.openapi=response.data;}).catch(error=>{debugger;throw new Error(error);});}
_getSchema(){return this.loadSchema();}
getSchema(){return this._getSchema().then(openapi=>{tabSignal.emit("openapi.loaded",openapi);return openapi;}).catch(error=>{throw error;})}
query(method,url="",data={}){let with_data_methods=["post","put","patch"];let without_data_methods=["get","delete"];if(with_data_methods.includes(method)){return this.api[method](url,data);}else if(without_data_methods.includes(method)){return this.api[method](url);}}
bulkQuery(data){if(this.bulk_collector.timeout_id){clearTimeout(this.bulk_collector.timeout_id);}
let callbacks={resolve:undefined,reject:undefined,};let promise=new Promise((resolve,reject)=>{callbacks.resolve=resolve;callbacks.reject=reject;});this.bulk_collector.bulk_parts.push({data:data,promise:promise,callbacks:callbacks,});let bulk_timeout=guiLocalSettings.get('guiApi.real_query_timeout')||100;this.bulk_collector.timeout_id=setTimeout(()=>this.sendBulk(),bulk_timeout);return promise;}
sendBulk(){let url="/"+api_version+"/_bulk/";let collector=$.extend(true,{},this.bulk_collector);this.bulk_collector.bulk_parts=[];let bulk_data=[];for(let item in collector.bulk_parts){bulk_data.push(collector.bulk_parts[item].data);}
return this.query("put",url,bulk_data).then(response=>{let result=response.data;for(let index in result){let item=result[index];let method="resolve";if(!(item.status>=200&&item.status<400)){debugger;method="reject";}
collector.bulk_parts[index].callbacks[method](result[index]);}}).catch(error=>{debugger;throw new StatusError(error.status,error.data);});}}
class StatusError extends Error{constructor(status,data){super();this.status=status;this.message;if(typeof data=="string"){this.message=data;}
if(typeof data=="object"&&data.detail){this.message=data.detail;}}}
var api_connector_config={headers:{'content-type':'application/json','X-CSRFToken':csrf_data.token,},baseURL:hostname+"/api",};var openapi_dictionary={models:{name:"definitions",fields:{name:"properties",},required_fields:{name:"required",},ref_names:["$ref","definition_ref"],filters_to_delete:["limit","offset"],},paths:{name:"paths",operation_id:{name:"operationId",},operations:{base:{remove:{name:'remove',title:'Remove',icon_classes:['fa','fa-times'],title_classes:['d-none','d-lg-inline-block'],classes:['btn-danger','danger-right'],},},list:{new:{name:'new',title:'Create',},add:{name:'add',title:'Add',component:'gui_add_child_modal',},},page:{edit:{name:'edit',title:'Edit',},},page_new:{save_new:{name:'save',title:'Save',},},page_edit:{save:{name:'save',title:'Save',},reload:{name:'reload',title:'Reload',},},action:{execute:{name:'execute',title:'Execute',}},},multi_actions:['remove'],types_operations_always_to_add:['page_new','page_edit','action'],},schema_types:{"_add":{query_type:"post",url_postfix:"new/",type:"page_new",},"_list":{query_type:"get",url_postfix:"",filters:{name:"parameters"},type:"list",autoupdate:true,},"_get":{query_type:"get",url_postfix:"",type:"page",autoupdate:true,},"_edit":{query_type:"patch",url_postfix:"edit/",type:"page_edit",},"_update":{query_type:"put",url_postfix:"edit/",type:"page_edit",},"_remove":{query_type:"delete",url_postfix:"remove/",type:"page_remove",hidden:true,},}};