src/app/modules/workspace/components/batch-list/batch-list.component.ts
The batch list component
selector | app-batch-list |
templateUrl | batch-list.component.html |
constructor(modalService: SuiModalService, searchService: any, batchService: BatchService, workSpaceService: WorkSpaceService, paginationService: any, activatedRoute: ActivatedRoute, route: Router, userService: any, toasterService: any, resourceService: any, config: any, navigationhelperService: any)
|
Constructor to create injected service(s) object
Parameters :
|
manipulateQueryParam |
manipulateQueryParam()
|
This method sets the make an api call to get all batch with page No and offset
Returns:
void
|
fetchBatchList |
fetchBatchList()
|
Returns:
void
|
onCardClick |
onCardClick(event: any)
|
Returns:
void
|
navigateToPage |
navigateToPage(page: number)
|
This method helps to navigate to different pages.
Parameters :
navigateToPage(1)
Returns:
void
|
Public updateBatch |
updateBatch()
|
processing batch for userlist to make an api call for userlist .
Returns:
void
|
setTelemetryImpressionData |
setTelemetryImpressionData()
|
Returns:
void
|
setInteractEventData |
setInteractEventData()
|
Returns:
void
|
inview |
inview(event: any)
|
get inview Data
Returns:
void
|
Public activatedRoute |
activatedRoute: |
To send activatedRoute.snapshot to router navigation |
batchList |
batchList: |
Contains list of batchList of logged-in user |
category |
category: |
category of the list 'assigned' or 'created'; |
Public closeIntractEdata |
closeIntractEdata: |
closeUrl |
closeUrl: |
on click of close icon in the list page |
Public config |
config: |
to get url app config |
filters |
filters: |
search filters |
inviewLogs |
inviewLogs: |
inviewLogs |
loaderMessage |
loaderMessage: |
loader message |
modalService |
modalService: |
navigationhelperService |
navigationhelperService: |
noResult |
noResult: |
Default value: false
|
To show / hide no result message when no result found |
noResultMessage |
noResultMessage: |
no result message |
pageLimit |
pageLimit: |
Contains page limit of batch list |
pageNumber |
pageNumber: |
Default value: 1
|
Current page number of batch list |
pager |
pager: |
Contains returned object of the pagination service |
Private paginationService |
paginationService: |
For showing pagination on draft list |
queryParams |
queryParams: |
url value |
Public resourceService |
resourceService: |
To call resource service which helps to use language constant |
route |
route: |
To navigate to other pages |
searchService |
searchService: |
Public sectionName |
sectionName: |
showError |
showError: |
Default value: false
|
To show / hide error |
showLoader |
showLoader: |
Default value: true
|
To show / hide loader |
status |
status: |
status for preselection; |
telemetryImpression |
telemetryImpression: |
telemetryImpression |
Private toasterService |
toasterService: |
To show toaster(error, success etc) after any API calls |
totalCount |
totalCount: |
totalCount of the list |
Public unsubscribe |
unsubscribe: |
workSpaceService |
workSpaceService: |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
import { Component, OnInit, ViewChild, OnDestroy, AfterViewInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { WorkSpace } from '../../classes/workspace';
import { SearchService, UserService } from '@sunbird/core';
import {
ServerResponse, PaginationService, ConfigService, ToasterService,
ResourceService, ILoaderMessage, INoResultMessage, NavigationHelperService
} from '@sunbird/shared';
import { combineLatest, Subject } from 'rxjs';
import { takeUntil, map, filter } from 'rxjs/operators';
import { Ibatch } from './../../interfaces/';
import { WorkSpaceService, BatchService } from '../../services';
import * as _ from 'lodash-es';
import { SuiModalService, TemplateModalConfig, ModalTemplate } from 'ng2-semantic-ui-v9';
import { IInteractEventInput, IImpressionEventInput, IInteractEventEdata } from '@sunbird/telemetry';
/**
* The batch list component
*/
@Component({
selector: 'app-batch-list',
templateUrl: './batch-list.component.html'
})
export class BatchListComponent extends WorkSpace implements OnInit, OnDestroy, AfterViewInit {
/**
* To navigate to other pages
*/
route: Router;
/**
*url value
*/
queryParams: any;
/**
* To send activatedRoute.snapshot to router navigation
* service for redirection to draft component
*/
public activatedRoute: ActivatedRoute;
public closeIntractEdata: IInteractEventEdata;
/**
* Contains list of batchList of logged-in user
*/
batchList: Array<Ibatch> = [];
/**
status for preselection;
*/
status: number;
/**
on click of close icon in the list page
*/
closeUrl: string;
/**
category of the list 'assigned' or 'created';
*/
category: string;
/**
* To show / hide loader
*/
showLoader = true;
/**
* loader message
*/
loaderMessage: ILoaderMessage;
/**
* To show / hide no result message when no result found
*/
noResult = false;
/**
* To show / hide error
*/
showError = false;
/**
* no result message
*/
noResultMessage: INoResultMessage;
/**
* For showing pagination on draft list
*/
private paginationService: PaginationService;
/**
* to get url app config
*/
public config: ConfigService;
/**
* Contains page limit of batch list
*/
pageLimit: number;
/**
* Current page number of batch list
*/
pageNumber = 1;
/**
* totalCount of the list
*/
totalCount: Number;
/**
* Contains returned object of the pagination service
* which is needed to show the pagination on inbox view
*/
pager;
/**
* To show toaster(error, success etc) after any API calls
*/
private toasterService: ToasterService;
/**
*search filters
*/
filters: any;
/**
* To call resource service which helps to use language constant
*/
public resourceService: ResourceService;
/**
* telemetryImpression
*/
telemetryImpression: IImpressionEventInput;
/**
* inviewLogs
*/
inviewLogs = [];
public sectionName: string;
public unsubscribe = new Subject<void>();
/**
* Constructor to create injected service(s) object
Default method of Draft Component class
* @param {SearchService} SearchService Reference of SearchService
* @param {UserService} UserService Reference of UserService
* @param {Router} route Reference of Router
* @param {PaginationService} paginationService Reference of PaginationService
* @param {ActivatedRoute} activatedRoute Reference of ActivatedRoute
* @param {ConfigService} config Reference of ConfigService
*/
constructor(public modalService: SuiModalService, public searchService: SearchService,
private batchService: BatchService,
public workSpaceService: WorkSpaceService,
paginationService: PaginationService,
activatedRoute: ActivatedRoute,
route: Router, userService: UserService,
toasterService: ToasterService, resourceService: ResourceService,
config: ConfigService, public navigationhelperService: NavigationHelperService) {
super(searchService, workSpaceService, userService);
this.paginationService = paginationService;
this.route = route;
this.activatedRoute = activatedRoute;
this.toasterService = toasterService;
this.resourceService = resourceService;
this.config = config;
this.loaderMessage = {
'loaderMessage': this.resourceService.messages.stmsg.m0108,
};
this.noResultMessage = {
'message': 'messages.stmsg.m0020',
'messageText': 'messages.stmsg.m0008'
};
}
ngOnInit() {
combineLatest(this.activatedRoute.params, this.activatedRoute.queryParams).pipe(
map(results => ({ params: results[0], queryParams: results[1] })),
filter(res => this.pageNumber !== Number(res.params.pageNumber) || !_.isEqual(this.queryParams, res.queryParams)),
takeUntil(this.unsubscribe)
).subscribe((res: any) => {
this.queryParams = res.queryParams;
this.manipulateQueryParam();
const route = this.route.url.split('/view-all');
this.closeUrl = '/workspace/content/batches/' + (this.queryParams.mentors ? 'assigned' : 'created');
this.sectionName = res.params.section.replace(/\-/g, ' ');
this.pageNumber = Number(res.params.pageNumber);
this.fetchBatchList();
this.setInteractEventData();
this.batchService.updateEvent
.subscribe((data) => {
this.fetchBatchList();
});
}, (error) => {
this.showLoader = false;
this.noResult = true;
this.toasterService.error(this.resourceService.messages.fmsg.m0051);
});
}
/**
* This method sets the make an api call to get all batch with page No and offset
*/
manipulateQueryParam() {
this.filters = {};
const queryFilters = _.omit(this.queryParams, ['key', 'softConstraintsFilter', 'appliedFilters',
'sort_by', 'sortType', 'defaultSortBy', 'exists', 'dynamic']);
if (!_.isEmpty(queryFilters)) {
_.forOwn(queryFilters, (queryValue, queryKey) => {
this.filters[queryKey] = queryValue;
});
}
}
fetchBatchList() {
this.showLoader = true;
this.pageLimit = this.config.appConfig.WORKSPACE.courseBatch.PAGE_LIMIT;
const searchParams = {
filters: this.filters,
limit: this.pageLimit,
pageNumber: this.pageNumber,
sort_by: { createdDate: this.config.appConfig.WORKSPACE.createdDate }
};
this.getBatches(searchParams).subscribe(
(data: ServerResponse) => {
if (data.result.response.count && data.result.response.content.length > 0) {
this.noResult = false;
this.batchList = [];
this.batchList = data.result.response.content;
this.totalCount = data.result.response.count;
this.pager = this.paginationService.getPager(data.result.response.count, this.pageNumber, this.pageLimit);
this.updateBatch();
} else {
this.showError = false;
this.noResult = true;
this.showLoader = false;
}
},
(err: ServerResponse) => {
this.batchList = [];
this.showLoader = false;
this.noResult = false;
this.showError = true;
this.toasterService.error(this.resourceService.messages.fmsg.m0004);
}
);
}
onCardClick (event) {
const batchData = event.data;
if (batchData.enrollmentType === 'open') {
this.batchService.setBatchData(batchData);
}
this.route.navigate(['update/batch', batchData.identifier], {queryParamsHandling: 'merge', relativeTo: this.activatedRoute});
}
/**
* This method helps to navigate to different pages.
* If page number is less than 1 or page number is greater than total number
* of pages is less which is not possible, then it returns.
*
* @param {number} page Variable to know which page has been clicked
*
* @example navigateToPage(1)
*/
navigateToPage(page: number): undefined | void {
const route = this.route.url.split('?');
const url = route[0].substring(0, route[0].lastIndexOf('/'));
if (page < 1 || page > this.pager.totalPages) {
return;
}
this.route.navigate([url, page], {
queryParams: this.queryParams,
relativeTo: this.activatedRoute
});
}
/**
* processing batch for userlist to make an api call for userlist .
*/
public updateBatch() {
let userList = [];
const participants = [];
const userName = [];
_.forEach(this.batchList, (item, key) => {
participants[item.id] = !_.isUndefined(item.participant) ? _.size(item.participant) : 0;
userList.push(item.createdBy);
this.batchList[key].label = item.participantCount || 0;
});
userList = _.compact(_.uniq(userList));
const req = {
filters: { identifier: userList }
};
this.UserList(req).subscribe((res: ServerResponse) => {
if (res.result.response.count && res.result.response.content.length > 0) {
_.forEach(res.result.response.content, (val, key) => {
userName[val.identifier] = (val.firstName || '') + ' ' + (val.lastName || '');
});
_.forEach(this.batchList, (item, key) => {
this.batchList[key].userName = userName[item.createdBy];
});
} else {
this.toasterService.error(this.resourceService.messages.fmsg.m0056);
}
this.showLoader = false;
},
(err: ServerResponse) => {
this.showLoader = false;
this.noResult = false;
this.showError = true;
this.toasterService.error(this.resourceService.messages.fmsg.m0056);
}
);
}
setTelemetryImpressionData () {
this.telemetryImpression = {
context: {
env: this.activatedRoute.snapshot.data.telemetry.env
},
edata: {
type: this.activatedRoute.snapshot.data.telemetry.type,
pageid: this.activatedRoute.snapshot.data.telemetry.pageid,
subtype: this.activatedRoute.snapshot.data.telemetry.subtype,
uri: this.activatedRoute.snapshot.data.telemetry.uri + '/' + this.activatedRoute.snapshot.params.pageNumber,
visits: this.inviewLogs,
duration: this.navigationhelperService.getPageLoadTime()
}
};
}
setInteractEventData() {
this.closeIntractEdata = {
id: 'close',
type: 'click',
pageid: _.get(this.activatedRoute.snapshot, 'data.telemetry.pageid'),
};
}
/**
* get inview Data
*/
inview(event) {
_.forEach(event.inview, (inview, key) => {
const obj = _.find(this.inviewLogs, (o) => {
return o.objid === inview.data.identifier;
});
if (obj === undefined) {
this.inviewLogs.push({
objid: inview.data.identifier,
objtype: 'batch',
index: inview.id
});
}
});
this.telemetryImpression.edata.visits = this.inviewLogs;
this.telemetryImpression.edata.subtype = 'pageexit';
this.telemetryImpression = Object.assign({}, this.telemetryImpression);
}
ngAfterViewInit () {
setTimeout(() => {
this.setTelemetryImpressionData();
this.inview({ inview: [] });
});
}
ngOnDestroy() {
this.unsubscribe.next();
this.unsubscribe.complete();
}
}