Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- export class AcqRequestsComponent extends AdminPageComponent implements OnInit {
- //Removed a bunch of stuff here with the inputs and declarations
- constructor(
- route: ActivatedRoute,
- ngLocation: Location,
- format: FormatService,
- idl: IdlService,
- org: OrgService,
- auth: AuthService,
- pcrud: PcrudService,
- perm: PermService,
- toast: ToastService,
- private ngLocation2: Location,
- private org2: OrgService,
- private route2: ActivatedRoute,
- private router: Router,
- private localStore: StoreService,
- private store: ServerStoreService,
- private evt: EventService,
- private net: NetService,
- private ReqService: RequestsService,
- ) {
- super(route, ngLocation, format, idl, org, auth, pcrud, perm, toast);
- this.dataSource = new GridDataSource();
- }
- ngOnInit() {
- this.contextOrg = this.org2.get(this.contextOrgId);
- this.cellTextGenerator = {
- usr: row => row.usr().card().barcode(),
- jub: row => row.lineitem().state()
- };
- this.notOneSelectedRow = (rows: IdlObject[]) => (rows.length !== 1);
- this.showCanceledRequests = this.localStore.getLocalItem('eg.acq.requests.show_canceled');
- this.markedLineitemId = this.localStore.getLocalItem('eg.acq.requests.marked_lineitem') || null;
- this.requestsEnabled;
- this.defaultNewRecord = this.idl.create('aur');
- this.cellTextGenerator = {
- user: row => row.usr().card().barcode(),
- lineitem: row => row.lineitem().state()
- }
- this.dataSource.getRows = (pager: Pager, sort: any[]) => {
- const orderBy: any = {};
- if (sort.length) {
- // Sort specified from grid
- orderBy[this.idlClass] = sort[0].name + ' ' + sort[0].dir;
- } else if (this.sortField) {
- // Default sort field
- orderBy[this.idlClass] = this.sortField;
- }
- const searchOps = {
- offset: pager.offset,
- limit: pager.limit,
- order_by: orderBy,
- flesh: 3,
- flesh_fields: {
- aur: ['usr','status'],
- au: ['card'],
- jub: ['lineitem','state']
- }
- };
- const reqOps = {
- fleshSelectors: true,
- };
- if (!this.contextOrg && !Object.keys(this.dataSource.filters).length) {
- // No org filter -- fetch all rows
- return this.pcrud.retrieveAll(
- this.idlClass, searchOps, reqOps);
- }
- const search: any = new Array();
- const orgFilter: any = {};
- if (this.orgField && (this.searchOrgs || this.contextOrg)) {
- orgFilter[this.orgField] =
- this.searchOrgs.orgIds || [this.contextOrg.id()];
- search.push(orgFilter);
- }
- if (this.showCanceledRequests === false) {
- search.push({cancel_reason: null});
- console.log('evaluated as true');
- }
- this.route2.queryParamMap.subscribe((params: ParamMap) => {
- let val;
- if (val = params.get('lineitem')) {
- search.push({lineitem: val});
- }
- if (val = params.get('usr')) {
- search.push({usr: val});
- }
- })
- Object.keys(this.dataSource.filters).forEach(key => {
- Object.keys(this.dataSource.filters[key]).forEach(key2 => {
- search.push(this.dataSource.filters[key][key2]);
- });
- });
- return this.pcrud.search(
- this.idlClass, search, searchOps, reqOps);
- }
- super.ngOnInit();
- this.classLabel = this.idlClassDef.label;
- this.includeOrgDescendants = true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement