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