const mdEndpoint = environment.urls.api.getMetaData;
let totalCount = 0;
return this.client.put(mdEndpoint, null)
.pipe(map((data: any) => {
if (data === null) {
this.toaster.error('Operation failed.', 'Oops!!');
console.error('Operation failed.', 'Oops!!');
return [];
}
console.log('Response Payload: ' + JSON.stringify(data));
// process paging...
totalCount = data.length;
let sliced = [];
if (data.length > state.skip + state.take) {
sliced = data.slice(state.skip, state.skip + state.take);
} else {
sliced = data.slice(state.skip, data.length);
}
console.log('After Paging:: start: ' + state.skip + ', end: ' + state.take +
', pageSize: ' + sliced.length + ', totalCount: ' + totalCount);
// process grouping...
let finalResult: any;
console.log('Check stateData:: grouping: ' + JSON.stringify(state.group)
+ ', dataSource: ' + state.dataSource + ', action: ' + !isNullOrUndefined(state.action));
if (isNullOrUndefined(state.dataSource)) {
if (!isNullOrUndefined(state.group) &&
(isNullOrUndefined(state.action) || !isNullOrUndefined(state.action[ConfigService.ROWS]))) {
let groupedResults = sliced;
state.group.forEach(grouping => { groupedResults = DataUtil.group(groupedResults, grouping); });
console.log('Returning filtered config (dS:undef, group:y, action:undef) : ' + JSON.stringify(groupedResults));
finalResult = { result: groupedResults, count: totalCount } as DataResult;
} else {
console.log('Returning filtered config (dS:undef, group:undef, action:na) : ' + JSON.stringify(sliced));
finalResult = { result: sliced, count: totalCount } as DataResult;
}
} else {
console.log('Returning filtered config (dS:y, group:na, action:na) : ' + JSON.stringify(sliced));
finalResult = sliced;
}
console.log('cfg dataSource notified: ' + JSON.stringify(finalResult));
return finalResult;
}))
.pipe(map((data: any) => data));
}