-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchunk-MNF43IBW.js
1 lines (1 loc) · 4.51 KB
/
chunk-MNF43IBW.js
1
import{a as b,b as L}from"./chunk-3MICEEYE.js";import{a as p,y as x}from"./chunk-TL3SOKZG.js";import{a as y,b as v}from"./chunk-FB7CDEED.js";import{Ia as l,L as w,Q as u,c as A,k as m,n as g,v as h}from"./chunk-XIWENJHJ.js";import{i as a}from"./chunk-BL3FZZIZ.js";var I=(()=>{let o=class o extends b{constructor(t,e,i){super(),this._httpClient=t,this.groupService=e,this.store=i,this.search=l(""),this.filtered=l([]),this.agentics=l([]),this.agentic=l(void 0),this.httpOptions={headers:new y({"Content-Type":"application/json"})}}refresh(){return a(this,null,function*(){if(this.useLocalDb){let t=yield this.getLocalAgentics();this.agentics.set(t),this.setupFilters(),this.doFilter()}else this.getAgentics().subscribe(t=>{this.agentics.update(e=>e=t),this.setupFilters(),this.doFilter()})})}setupFilters(){return a(this,null,function*(){this.assignValuesToFilters()})}assignValuesToFilters(){}setFiltersForCurrent(){var t=this.agentic()}reset(){this.doFilter()}setCurrent(t){this.agentic.set(t)}doSearch(){this.doFilter()}doFilter(){var t=new Array;t=this.agentics();var e=this.search();e.length>0&&(t=t.filter(i=>i.key.toLowerCase().includes(e.toLowerCase()))),t.sort((i,s)=>i.key>s.key?1:-1),this.filtered.update(i=>i=t)}data(){return(this.agentics()===void 0||this.agentics()===null||this.agentics().length===0)&&this.getAgentics().subscribe(t=>{this.agentics.update(e=>e=t)}),this.agentics()}getLocalAgentics(){return a(this,null,function*(){return yield this.store.readAgentics()})}getLocalAgentic(t){return a(this,null,function*(){let e=yield this.store.getAgentic(t);this.agentic.set(e);var i=this.agentics();let s=i.find(r=>r.id===t);if(s){let r=i.indexOf(s);i.splice(r,1,e),this.agentics.update(n=>n=i)}return e})}createLocalAgentic(t){return a(this,null,function*(){yield this.store.createAgentic(t);let e=yield this.store.readAgentics();return this.agentics.set(e),t})}updateLocalAgentic(t){return a(this,null,function*(){yield this.store.updateAgentic(t);var e=this.agentics();let i=e.find(s=>s.id===t.id);if(i){let s=e.indexOf(i);e.splice(s,1,t),this.agentics.update(r=>r=e)}return t})}deleteLocalAgentic(t){return a(this,null,function*(){yield this.store.deleteAgentic(t);var e=this.agentics();let i=e.find(s=>s.id===t);if(i){let s=e.indexOf(i);e.splice(s,1),this.agentics.update(r=>r=e)}return!0})}getAgentics(){return this._httpClient.get("api/agentic").pipe(h(this.handleError),g(e=>{var i=new Array;for(let r=0;r<e.length;r++){var s=e[r];i.push(new p().fromJson(s))}return i}))}getAgentic(t){if(this.useLocalDb)return new A(e=>{this.getLocalAgentic(t).then(i=>{e.next(i)})});{let e="api/agentic/"+t;return this._httpClient.get(e).pipe(h(this.handleError),g(i=>{var s=new p().fromJson(i);this.agentic.set(s);var r=this.agentics();let n=r.find(c=>c.id===t);if(n){let c=r.indexOf(n);r.splice(c,1,s),this.agentics.update(f=>f=r)}return s}))}}createAgentic(t){return a(this,null,function*(){if(this.useLocalDb)return yield this.createLocalAgentic(t),t;{let e=JSON.stringify(t.toJson());return this._httpClient.post("api/agentic/create",e,this.httpOptions).pipe(h(this.handleError),g(s=>{var r=new p().fromJson(s);return this.agentics.update(n=>n=[...n,r]),r}))}})}updateAgentic(t){return a(this,null,function*(){if(this.useLocalDb)return yield this.updateLocalAgentic(t),t;{let e=JSON.stringify(t.toJson()),i="api/agentic/edit/"+t.id;return this._httpClient.put(i,e,this.httpOptions).pipe(h(this.handleError),g(s=>{if(!s)return;var r=this.agentics();let n=r.find(c=>c.id===t.id);if(n){let c=r.indexOf(n);r.splice(c,1,t),this.agentics.update(f=>f=r)}return t}))}})}deleteAgentic(t){return a(this,null,function*(){if(this.useLocalDb)return yield this.deleteLocalAgentic(t),!0;{let e="api/agentic/delete/"+t;return this._httpClient.delete(e).pipe(h(this.handleError)),g(i=>{if(!i)return!1;var s=this.agentics();let r=s.find(n=>n.id===t);if(r){let n=s.indexOf(r);s.splice(n,1),this.agentics.update(c=>c=s)}return!0})}})}handleError(t){return t.error instanceof ErrorEvent?alert("An error occurred:"+t.error.message):alert(`Backend returned code ${t.status}, body was: ${t.error}`),alert(" return an observable with a user-facing error message"),m(()=>new Error("Something bad happened; please try again later."))}groups(){return[]}flatten(t){let e=new Array;for(let i of t)this.recurse(i,e);return e}recurse(t,e){let i=t;if(i&&((i.groups===void 0||i.groups.length===0)&&e.push(i),!!i.groups&&i.groups.length))for(let s of i.groups)this.recurse(s,e)}};o.\u0275fac=function(e){return new(e||o)(u(v),u(L),u(x))},o.\u0275prov=w({token:o,factory:o.\u0275fac,providedIn:"root"});let d=o;return d})();export{I as a};