Sorry for the roughness of the code. It's a work in progress. While I believe it's almost working, I'm struggling to complete it. My goal is to display 10% of the results from an HTTP POST request in a material table. Any tips would be appreciated.
RandomSample() {
const headers = { 'content-type': 'application/json' };
var userId, roleId, eventTypeIds: any[];
if (this.selectedUser == undefined) {
userId = 0;
}
else {
userId = this.selectedUser.id;
}
if (this.selectedEventTypes == undefined) {
eventTypeIds = [-1];
}
else {
eventTypeIds = this.selectedEventTypes.map(selectedEventTypes => selectedEventTypes.id);
}
var SearchStart, SearchEnd
if (this.searchStartDate == undefined) {
var ssd = new Date();
ssd.setDate(ssd.getDate() - 14);
SearchStart = ssd;
}
else {
SearchStart = this.searchStartDate;
}
if (this.searchEndDate == undefined) {
SearchEnd = new Date();
}
else {
SearchEnd = this.searchEndDate;
}
var body = JSON.stringify({ UserId: userId, EventTypeIds: eventTypeIds, SearchStartDate: SearchStart, SearchEndDate: SearchEnd });
console.log(body);
this.http.post(environment.BASE_URL + 'useractivity/getloginsoverfourteendays', body, { 'headers': headers }).subscribe((selectedUser: any) => {
var random = Math.floor(Math.random() * selectedUser.length);
this.dataSource = new MatTableDataSource(selectedUser[random]);
console.log();
}, (error: any) => {
console.error(error);
})
}