Advertisement
Guest User

Untitled

a guest
Nov 16th, 2022
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. export class AcqRequestsComponent extends AdminPageComponent implements OnInit {
  2.  
  3. //Removed a bunch of stuff here with the inputs and declarations
  4.  
  5.   constructor(
  6.         route: ActivatedRoute,
  7.         ngLocation: Location,
  8.         format: FormatService,
  9.         idl: IdlService,
  10.         org: OrgService,
  11.         auth: AuthService,
  12.         pcrud: PcrudService,
  13.         perm: PermService,
  14.         toast: ToastService,
  15.         private ngLocation2: Location,
  16.         private org2: OrgService,
  17.         private route2: ActivatedRoute,
  18.         private router: Router,    
  19.         private localStore: StoreService,
  20.         private store: ServerStoreService,
  21.         private evt: EventService,
  22.         private net: NetService,
  23.         private ReqService: RequestsService,
  24.   ) {
  25.     super(route, ngLocation, format, idl, org, auth, pcrud, perm, toast);
  26.     this.dataSource = new GridDataSource();
  27.   }
  28.  
  29.  
  30. ngOnInit() {
  31.   this.contextOrg = this.org2.get(this.contextOrgId);
  32.  
  33.   this.cellTextGenerator = {
  34.       usr: row => row.usr().card().barcode(),
  35.       jub: row => row.lineitem().state()
  36.   };
  37.   this.notOneSelectedRow = (rows: IdlObject[]) => (rows.length !== 1);
  38.   this.showCanceledRequests = this.localStore.getLocalItem('eg.acq.requests.show_canceled');
  39.   this.markedLineitemId = this.localStore.getLocalItem('eg.acq.requests.marked_lineitem') || null;
  40.   this.requestsEnabled;
  41.  
  42.  
  43.   this.defaultNewRecord = this.idl.create('aur');
  44.  
  45.   this.cellTextGenerator = {
  46.     user: row => row.usr().card().barcode(),
  47.     lineitem: row => row.lineitem().state()
  48.   }
  49.  
  50.  
  51.   this.dataSource.getRows = (pager: Pager, sort: any[]) => {
  52.       const orderBy: any = {};
  53.       if (sort.length) {
  54.           // Sort specified from grid
  55.           orderBy[this.idlClass] = sort[0].name + ' ' + sort[0].dir;
  56.       } else if (this.sortField) {
  57.           // Default sort field
  58.           orderBy[this.idlClass] = this.sortField;
  59.       }
  60.  
  61.       const searchOps = {
  62.           offset: pager.offset,
  63.           limit: pager.limit,
  64.           order_by: orderBy,
  65.           flesh: 3,
  66.           flesh_fields: {
  67.             aur: ['usr','status'],
  68.             au: ['card'],
  69.             jub: ['lineitem','state']
  70.           }
  71.       };
  72.  
  73.       const reqOps = {
  74.         fleshSelectors: true,
  75.       };
  76.  
  77.       if (!this.contextOrg && !Object.keys(this.dataSource.filters).length) {
  78.         // No org filter -- fetch all rows
  79.         return this.pcrud.retrieveAll(
  80.             this.idlClass, searchOps, reqOps);
  81.     }
  82.  
  83.     const search: any = new Array();
  84.     const orgFilter: any = {};
  85.  
  86.     if (this.orgField && (this.searchOrgs || this.contextOrg)) {
  87.         orgFilter[this.orgField] =
  88.             this.searchOrgs.orgIds || [this.contextOrg.id()];
  89.         search.push(orgFilter);
  90.     }
  91.  
  92.  
  93.       if (this.showCanceledRequests === false) {
  94.         search.push({cancel_reason: null});
  95.         console.log('evaluated as true');
  96.       }
  97.  
  98.  
  99.       this.route2.queryParamMap.subscribe((params: ParamMap) => {
  100.         let val;
  101.         if (val = params.get('lineitem')) {
  102.              search.push({lineitem: val});
  103.         }
  104.         if (val = params.get('usr')) {
  105.             search.push({usr: val});
  106.         }
  107.        })
  108.  
  109.     Object.keys(this.dataSource.filters).forEach(key => {
  110.         Object.keys(this.dataSource.filters[key]).forEach(key2 => {
  111.             search.push(this.dataSource.filters[key][key2]);
  112.         });
  113.     });
  114.  
  115.     return this.pcrud.search(
  116.         this.idlClass, search, searchOps, reqOps);
  117. }
  118.  
  119. super.ngOnInit();
  120.  
  121. this.classLabel = this.idlClassDef.label;
  122. this.includeOrgDescendants = true;
  123.  
  124.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement