@sunbird-cb/utils 1.0.4 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,10 +1,11 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/material/dialog'), require('@angular/material/snack-bar'), require('rxjs'), require('@angular/cdk/layout'), require('rxjs/operators'), require('@angular/common'), require('@angular/material'), require('ngx-image-cropper'), require('keycloak-angular'), require('@angular/common/http'), require('@angular/cdk/platform'), require('moment'), require('lodash'), require('@angular/platform-browser'), require('@angular/router')) :
3
- typeof define === 'function' && define.amd ? define('@sunbird-cb/utils', ['exports', '@angular/core', '@angular/material/dialog', '@angular/material/snack-bar', 'rxjs', '@angular/cdk/layout', 'rxjs/operators', '@angular/common', '@angular/material', 'ngx-image-cropper', 'keycloak-angular', '@angular/common/http', '@angular/cdk/platform', 'moment', 'lodash', '@angular/platform-browser', '@angular/router'], factory) :
4
- (global = global || self, factory((global['sunbird-cb'] = global['sunbird-cb'] || {}, global['sunbird-cb'].utils = {}), global.ng.core, global.ng.material.dialog, global.ng.material['snack-bar'], global.rxjs, global.ng.cdk.layout, global.rxjs.operators, global.ng.common, global.ng.material, global.ngxImageCropper, global['keycloak-angular'], global.ng.common.http, global.ng.cdk.platform, global.moment, global._, global.ng.platformBrowser, global.ng.router));
5
- }(this, (function (exports, core, dialog, snackBar, rxjs, layout, operators, common, material, ngxImageCropper, keycloakAngular, http, platform, moment, lodash, platformBrowser, router) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/material/dialog'), require('@angular/material/snack-bar'), require('rxjs'), require('@angular/cdk/layout'), require('rxjs/operators'), require('@angular/common'), require('@angular/material'), require('ngx-image-cropper'), require('keycloak-angular'), require('@angular/common/http'), require('@angular/cdk/platform'), require('@angular/router'), require('moment'), require('lodash'), require('@angular/platform-browser')) :
3
+ typeof define === 'function' && define.amd ? define('@sunbird-cb/utils', ['exports', '@angular/core', '@angular/material/dialog', '@angular/material/snack-bar', 'rxjs', '@angular/cdk/layout', 'rxjs/operators', '@angular/common', '@angular/material', 'ngx-image-cropper', 'keycloak-angular', '@angular/common/http', '@angular/cdk/platform', '@angular/router', 'moment', 'lodash', '@angular/platform-browser'], factory) :
4
+ (global = global || self, factory((global['sunbird-cb'] = global['sunbird-cb'] || {}, global['sunbird-cb'].utils = {}), global.ng.core, global.ng.material.dialog, global.ng.material['snack-bar'], global.rxjs, global.ng.cdk.layout, global.rxjs.operators, global.ng.common, global.ng.material, global.ngxImageCropper, global['keycloak-angular'], global.ng.common.http, global.ng.cdk.platform, global.ng.router, global.moment, global._, global.ng.platformBrowser));
5
+ }(this, (function (exports, core, dialog, snackBar, rxjs, layout, operators, common, material, ngxImageCropper, keycloakAngular, http, platform, router, moment, _, platformBrowser) { 'use strict';
6
6
 
7
7
  moment = moment && moment.hasOwnProperty('default') ? moment['default'] : moment;
8
+ var ___default = 'default' in _ ? _['default'] : _;
8
9
 
9
10
  /*! *****************************************************************************
10
11
  Copyright (c) Microsoft Corporation.
@@ -2299,10 +2300,31 @@
2299
2300
  IRecursiveData.prototype.children;
2300
2301
  }
2301
2302
  var UtilityService = (function () {
2302
- function UtilityService(http, platform) {
2303
+ function UtilityService(http, platform, router$1, route) {
2304
+ var _this = this;
2303
2305
  this.http = http;
2304
2306
  this.platform = platform;
2307
+ this.router = router$1;
2308
+ this.route = route;
2309
+ this.currentRouteData = [];
2310
+ this.router.events.subscribe((function (event) {
2311
+ if (event instanceof router.NavigationEnd) {
2312
+ var snapshot = _this.route.snapshot;
2313
+ var firstChild = snapshot.root.firstChild;
2314
+ _this.getChildRouteData(snapshot, firstChild);
2315
+ }
2316
+ }));
2305
2317
  }
2318
+ UtilityService.prototype.getChildRouteData = function (snapshot, firstChild) {
2319
+ if (firstChild) {
2320
+ if (firstChild.data) {
2321
+ this.currentRouteData.push(firstChild.data);
2322
+ }
2323
+ if (firstChild.firstChild) {
2324
+ this.getChildRouteData(snapshot, firstChild.firstChild);
2325
+ }
2326
+ }
2327
+ };
2306
2328
  Object.defineProperty(UtilityService.prototype, "randomId", {
2307
2329
  get: function () {
2308
2330
  return RANDOM_ID_PER_USER + 1;
@@ -2391,6 +2413,28 @@
2391
2413
  enumerable: true,
2392
2414
  configurable: true
2393
2415
  });
2416
+ UtilityService.prototype.setRouteData = function (data) {
2417
+ this.currentRouteData = data;
2418
+ };
2419
+ Object.defineProperty(UtilityService.prototype, "routeData", {
2420
+ get: function () {
2421
+ var data = {
2422
+ module: '',
2423
+ pageId: '',
2424
+ };
2425
+ this.currentRouteData.map((function (rd) {
2426
+ if (rd.pageId) {
2427
+ data.pageId = data.pageId + "/" + rd.pageId;
2428
+ }
2429
+ if (rd.module) {
2430
+ data.module = rd.module;
2431
+ }
2432
+ }));
2433
+ return data;
2434
+ },
2435
+ enumerable: true,
2436
+ configurable: true
2437
+ });
2394
2438
  UtilityService.decorators = [
2395
2439
  { type: core.Injectable, args: [{
2396
2440
  providedIn: 'root',
@@ -2398,14 +2442,19 @@
2398
2442
  ];
2399
2443
  UtilityService.ctorParameters = function () { return [
2400
2444
  { type: http.HttpClient },
2401
- { type: platform.Platform }
2445
+ { type: platform.Platform },
2446
+ { type: router.Router },
2447
+ { type: router.ActivatedRoute }
2402
2448
  ]; };
2403
- /** @nocollapse */ UtilityService.ngInjectableDef = core.ɵɵdefineInjectable({ factory: function UtilityService_Factory() { return new UtilityService(core.ɵɵinject(http.HttpClient), core.ɵɵinject(platform.Platform)); }, token: UtilityService, providedIn: "root" });
2449
+ /** @nocollapse */ UtilityService.ngInjectableDef = core.ɵɵdefineInjectable({ factory: function UtilityService_Factory() { return new UtilityService(core.ɵɵinject(http.HttpClient), core.ɵɵinject(platform.Platform), core.ɵɵinject(router.Router), core.ɵɵinject(router.ActivatedRoute)); }, token: UtilityService, providedIn: "root" });
2404
2450
  return UtilityService;
2405
2451
  }());
2406
2452
  if (false) {
2453
+ UtilityService.prototype.currentRouteData;
2407
2454
  UtilityService.prototype.http;
2408
2455
  UtilityService.prototype.platform;
2456
+ UtilityService.prototype.router;
2457
+ UtilityService.prototype.route;
2409
2458
  }
2410
2459
 
2411
2460
  var LogoutComponent = (function () {
@@ -2921,7 +2970,7 @@
2921
2970
 
2922
2971
  var OrderByPipe = (function () {
2923
2972
  function OrderByPipe() {
2924
- this.transform = lodash.orderBy;
2973
+ this.transform = _.orderBy;
2925
2974
  }
2926
2975
  OrderByPipe.decorators = [
2927
2976
  { type: core.Pipe, args: [{
@@ -3980,11 +4029,26 @@
3980
4029
  EnumTelemetrySubType["HeartBeat"] = "HeartBeat";
3981
4030
  EnumTelemetrySubType["Search"] = "Search";
3982
4031
  EnumTelemetrySubType["Feedback"] = "Feedback";
4032
+ EnumTelemetrySubType["Impression"] = "Impression";
3983
4033
  })(EnumTelemetrySubType = WsEvents.EnumTelemetrySubType || (WsEvents.EnumTelemetrySubType = {}));
4034
+ function ITelemetryContext() { }
4035
+ WsEvents.ITelemetryContext = ITelemetryContext;
4036
+ if (false) {
4037
+ ITelemetryContext.prototype.pageId;
4038
+ ITelemetryContext.prototype.module;
4039
+ ITelemetryContext.prototype.pageIdExt;
4040
+ }
4041
+ function ITelemetryTabData() { }
4042
+ WsEvents.ITelemetryTabData = ITelemetryTabData;
4043
+ if (false) {
4044
+ ITelemetryTabData.prototype.label;
4045
+ ITelemetryTabData.prototype.index;
4046
+ }
3984
4047
  function IWsEventTelemetry() { }
3985
4048
  WsEvents.IWsEventTelemetry = IWsEventTelemetry;
3986
4049
  if (false) {
3987
4050
  IWsEventTelemetry.prototype.eventSubType;
4051
+ IWsEventTelemetry.prototype.context;
3988
4052
  }
3989
4053
  var EnumTelemetryPdfActivity;
3990
4054
  (function (EnumTelemetryPdfActivity) {
@@ -4009,6 +4073,7 @@
4009
4073
  IWsEventTelemetryInteract.prototype.type;
4010
4074
  IWsEventTelemetryInteract.prototype.subType;
4011
4075
  IWsEventTelemetryInteract.prototype.object;
4076
+ IWsEventTelemetryInteract.prototype.context;
4012
4077
  }
4013
4078
  function IWsEventTelemetryFeedback() { }
4014
4079
  WsEvents.IWsEventTelemetryFeedback = IWsEventTelemetryFeedback;
@@ -4016,6 +4081,15 @@
4016
4081
  IWsEventTelemetryFeedback.prototype.type;
4017
4082
  IWsEventTelemetryFeedback.prototype.subType;
4018
4083
  IWsEventTelemetryFeedback.prototype.object;
4084
+ IWsEventTelemetryFeedback.prototype.context;
4085
+ }
4086
+ function IWsEventTelemetryImpression() { }
4087
+ WsEvents.IWsEventTelemetryImpression = IWsEventTelemetryImpression;
4088
+ if (false) {
4089
+ IWsEventTelemetryImpression.prototype.type;
4090
+ IWsEventTelemetryImpression.prototype.subType;
4091
+ IWsEventTelemetryImpression.prototype.object;
4092
+ IWsEventTelemetryImpression.prototype.context;
4019
4093
  }
4020
4094
  function IWsEventTelemetrySearch() { }
4021
4095
  WsEvents.IWsEventTelemetrySearch = IWsEventTelemetrySearch;
@@ -4067,17 +4141,47 @@
4067
4141
  IWsEventTelemetryMediaData.prototype.maxedSeekedTime;
4068
4142
  IWsEventTelemetryMediaData.prototype.activityStartedAt;
4069
4143
  }
4144
+ var EnumTelemetrymodules;
4145
+ (function (EnumTelemetrymodules) {
4146
+ EnumTelemetrymodules["CONTENT"] = "content";
4147
+ EnumTelemetrymodules["FEEDBACK"] = "feedback";
4148
+ EnumTelemetrymodules["COURSE"] = "course";
4149
+ EnumTelemetrymodules["PROGRAM"] = "program";
4150
+ EnumTelemetrymodules["EXPLORE"] = "explore";
4151
+ EnumTelemetrymodules["LEARN"] = "learn";
4152
+ EnumTelemetrymodules["HOME"] = "home";
4153
+ EnumTelemetrymodules["DASHBOARD"] = "dashboard";
4154
+ EnumTelemetrymodules["SEARCH"] = "search";
4155
+ EnumTelemetrymodules["DISCUSS"] = "discuss";
4156
+ EnumTelemetrymodules["COMPETENCY"] = "competency";
4157
+ EnumTelemetrymodules["EVENTS"] = "events";
4158
+ EnumTelemetrymodules["CAREER"] = "career";
4159
+ EnumTelemetrymodules["PROFILE"] = "profile";
4160
+ EnumTelemetrymodules["NETWORK"] = "network";
4161
+ EnumTelemetrymodules["SUPPORT"] = "support";
4162
+ })(EnumTelemetrymodules = WsEvents.EnumTelemetrymodules || (WsEvents.EnumTelemetrymodules = {}));
4163
+ var EnumInteractTypes;
4164
+ (function (EnumInteractTypes) {
4165
+ EnumInteractTypes["CLICK"] = "click";
4166
+ })(EnumInteractTypes = WsEvents.EnumInteractTypes || (WsEvents.EnumInteractTypes = {}));
4167
+ var EnumInteractSubTypes;
4168
+ (function (EnumInteractSubTypes) {
4169
+ EnumInteractSubTypes["COURSE_TAB"] = "course-tab";
4170
+ EnumInteractSubTypes["CAREER_TAB"] = "career-tab";
4171
+ EnumInteractSubTypes["PROFILE_EDIT_TAB"] = "profile-edit-tab";
4172
+ })(EnumInteractSubTypes = WsEvents.EnumInteractSubTypes || (WsEvents.EnumInteractSubTypes = {}));
4070
4173
  })(exports.WsEvents || (exports.WsEvents = {}));
4071
4174
 
4072
4175
  var EventService = (function () {
4073
- function EventService() {
4176
+ function EventService(utilitySvc) {
4177
+ this.utilitySvc = utilitySvc;
4074
4178
  this.eventsSubject = new rxjs.Subject();
4075
4179
  this.events$ = this.eventsSubject.asObservable();
4076
4180
  }
4077
4181
  EventService.prototype.dispatchEvent = function (event) {
4078
4182
  this.eventsSubject.next(event);
4079
4183
  };
4080
- EventService.prototype.raiseInteractTelemetry = function (type, subType, object, from) {
4184
+ EventService.prototype.raiseInteractTelemetry = function (type, subType, object, context) {
4081
4185
  this.dispatchEvent({
4082
4186
  eventType: exports.WsEvents.WsEventType.Telemetry,
4083
4187
  eventLogLevel: exports.WsEvents.WsEventLogLevel.Info,
@@ -4085,9 +4189,10 @@
4085
4189
  type: type,
4086
4190
  subType: subType,
4087
4191
  object: object,
4192
+ context: this.getContext(context),
4088
4193
  eventSubType: exports.WsEvents.EnumTelemetrySubType.Interact,
4089
4194
  },
4090
- from: from || '',
4195
+ from: '',
4091
4196
  to: 'Telemetry',
4092
4197
  });
4093
4198
  };
@@ -4105,18 +4210,65 @@
4105
4210
  to: 'Telemetry',
4106
4211
  });
4107
4212
  };
4213
+ EventService.prototype.raiseCustomImpression = function (context) {
4214
+ this.dispatchEvent({
4215
+ eventType: exports.WsEvents.WsEventType.Telemetry,
4216
+ eventLogLevel: exports.WsEvents.WsEventLogLevel.Info,
4217
+ data: {
4218
+ context: this.getContext(context),
4219
+ eventSubType: exports.WsEvents.EnumTelemetrySubType.Impression,
4220
+ },
4221
+ from: '',
4222
+ to: 'Telemetry',
4223
+ });
4224
+ };
4225
+ EventService.prototype.getContext = function (context) {
4226
+ var routeDataContext = this.utilitySvc.routeData;
4227
+ var finalContext = {
4228
+ pageId: routeDataContext.pageId,
4229
+ module: routeDataContext.module,
4230
+ };
4231
+ if (context) {
4232
+ if (context.pageIdExt) {
4233
+ finalContext.pageId = routeDataContext.pageId + "_" + context.pageIdExt;
4234
+ }
4235
+ else if (context.pageId) {
4236
+ finalContext.pageId = context.pageId;
4237
+ }
4238
+ if (context.module) {
4239
+ finalContext.module = context.module;
4240
+ }
4241
+ }
4242
+ return finalContext;
4243
+ };
4244
+ EventService.prototype.handleTabTelemetry = function (subType, data) {
4245
+ this.raiseInteractTelemetry(exports.WsEvents.EnumInteractTypes.CLICK, subType, {
4246
+ id: "" + ___default.camelCase(data.label),
4247
+ context: {
4248
+ position: data.index,
4249
+ },
4250
+ }, {
4251
+ pageIdExt: ___default.camelCase(data.label) + "-tab",
4252
+ });
4253
+ this.raiseCustomImpression({
4254
+ pageIdExt: ___default.camelCase(data.label) + "-tab",
4255
+ });
4256
+ };
4108
4257
  EventService.decorators = [
4109
4258
  { type: core.Injectable, args: [{
4110
4259
  providedIn: 'root',
4111
4260
  },] }
4112
4261
  ];
4113
- EventService.ctorParameters = function () { return []; };
4114
- /** @nocollapse */ EventService.ngInjectableDef = core.ɵɵdefineInjectable({ factory: function EventService_Factory() { return new EventService(); }, token: EventService, providedIn: "root" });
4262
+ EventService.ctorParameters = function () { return [
4263
+ { type: UtilityService }
4264
+ ]; };
4265
+ /** @nocollapse */ EventService.ngInjectableDef = core.ɵɵdefineInjectable({ factory: function EventService_Factory() { return new EventService(core.ɵɵinject(UtilityService)); }, token: EventService, providedIn: "root" });
4115
4266
  return EventService;
4116
4267
  }());
4117
4268
  if (false) {
4118
4269
  EventService.prototype.eventsSubject;
4119
4270
  EventService.prototype.events$;
4271
+ EventService.prototype.utilitySvc;
4120
4272
  }
4121
4273
 
4122
4274
  function IWsMsTokenModelResponse() { }
@@ -4342,10 +4494,10 @@
4342
4494
  this.externalApps = {
4343
4495
  RBCP: 'rbcp-web-ui',
4344
4496
  };
4497
+ this.environment = environment;
4345
4498
  var instanceConfig = this.configSvc.instanceConfig;
4346
4499
  if (instanceConfig) {
4347
4500
  this.telemetryConfig = instanceConfig.telemetryConfig;
4348
- this.environment = environment;
4349
4501
  this.telemetryConfig = __assign({}, this.telemetryConfig, { pdata: __assign({}, this.telemetryConfig.pdata, { id: environment.name + "." + this.telemetryConfig.pdata.id }), uid: this.configSvc.userProfile && this.configSvc.userProfile.userId, channel: this.rootOrgId || this.telemetryConfig.channel, sid: this.getTelemetrySessionId });
4350
4502
  this.pData = this.telemetryConfig.pdata;
4351
4503
  this.addPlayerListener();
@@ -4354,6 +4506,7 @@
4354
4506
  this.addTimeSpentListener();
4355
4507
  this.addSearchListener();
4356
4508
  this.addHearbeatListener();
4509
+ this.addCustomImpressionListener();
4357
4510
  }
4358
4511
  }
4359
4512
  Object.defineProperty(TelemetryService.prototype, "getTelemetrySessionId", {
@@ -4380,9 +4533,11 @@
4380
4533
  type: type,
4381
4534
  mode: mode,
4382
4535
  pageid: id,
4536
+ duration: 1,
4383
4537
  }, {
4384
4538
  context: {
4385
4539
  pdata: __assign({}, this.pData, { id: this.pData.id }),
4540
+ env: 'home',
4386
4541
  },
4387
4542
  object: __assign({}, (data) && data),
4388
4543
  });
@@ -4446,7 +4601,7 @@
4446
4601
  var page = this.getPageDetails();
4447
4602
  if (data) {
4448
4603
  page.pageid = data.pageId;
4449
- page.module = data.pageModule;
4604
+ page.module = data.module;
4450
4605
  }
4451
4606
  var edata = {
4452
4607
  pageid: page.pageid,
@@ -4469,7 +4624,7 @@
4469
4624
  $t.impression(edata, {
4470
4625
  context: {
4471
4626
  pdata: __assign({}, this.pData, { id: this.pData.id }),
4472
- env: page.module,
4627
+ env: page.module || '',
4473
4628
  },
4474
4629
  });
4475
4630
  }
@@ -4581,11 +4736,9 @@
4581
4736
  type: event.data.type,
4582
4737
  subtype: event.data.subType,
4583
4738
  id: (event.data.object) ? event.data.object.contentId || event.data.object.id || interactid || '' : '',
4584
- pageid: page.pageid,
4739
+ pageid: event.data.context && event.data.context.pageId || page.pageid,
4585
4740
  }, {
4586
- context: {
4587
- pdata: __assign({}, _this.pData, { id: _this.pData.id }),
4588
- },
4741
+ context: __assign({ pdata: __assign({}, _this.pData, { id: _this.pData.id }) }, (event.data.context && event.data.context.module ? { env: event.data.context.module } : null)),
4589
4742
  object: __assign({}, event.data.object),
4590
4743
  });
4591
4744
  }
@@ -4629,6 +4782,24 @@
4629
4782
  }
4630
4783
  }));
4631
4784
  };
4785
+ TelemetryService.prototype.addCustomImpressionListener = function () {
4786
+ var _this = this;
4787
+ this.eventsSvc.events$
4788
+ .pipe(operators.filter((function (event) {
4789
+ return event &&
4790
+ event.data &&
4791
+ event.eventType === exports.WsEvents.WsEventType.Telemetry &&
4792
+ event.data.eventSubType === exports.WsEvents.EnumTelemetrySubType.Impression;
4793
+ })))
4794
+ .subscribe((function (event) {
4795
+ try {
4796
+ _this.impression(event.data.context);
4797
+ }
4798
+ catch (e) {
4799
+ console.log('Error in telemetry impression', e);
4800
+ }
4801
+ }));
4802
+ };
4632
4803
  TelemetryService.prototype.addHearbeatListener = function () {
4633
4804
  var _this = this;
4634
4805
  this.eventsSvc.events$
@@ -4739,9 +4910,9 @@
4739
4910
  TelemetryService.prototype.previousUrl;
4740
4911
  TelemetryService.prototype.telemetryConfig;
4741
4912
  TelemetryService.prototype.pData;
4913
+ TelemetryService.prototype.environment;
4742
4914
  TelemetryService.prototype.contextCdata;
4743
4915
  TelemetryService.prototype.externalApps;
4744
- TelemetryService.prototype.environment;
4745
4916
  TelemetryService.prototype.configSvc;
4746
4917
  TelemetryService.prototype.eventsSvc;
4747
4918
  TelemetryService.prototype.logger;