src/app/modules/public/module/offline/components/telemetry/telemetry.component.ts
OnInit
OnDestroy
selector | app-telemetry |
styleUrls | ./telemetry.component.scss |
templateUrl | ./telemetry.component.html |
Properties |
Methods |
constructor(telemetryActionService: TelemetryActionsService, resourceService: ResourceService, toasterService: ToasterService, telemetryService: TelemetryService, activatedRoute: ActivatedRoute, router: Router, connectionService: ConnectionService)
|
||||||||||||||||||||||||
Parameters :
|
checkOnlineStatus |
checkOnlineStatus()
|
Returns :
void
|
exportTelemetry |
exportTelemetry()
|
Returns :
void
|
getSyncStatus |
getSyncStatus()
|
Returns :
void
|
getTelemetryInfo |
getTelemetryInfo()
|
Returns :
void
|
handleSyncStatus | ||||
handleSyncStatus(syncStatus)
|
||||
Parameters :
Returns :
void
|
logTelemetry | ||||
logTelemetry(id)
|
||||
Parameters :
Returns :
void
|
ngOnDestroy |
ngOnDestroy()
|
Returns :
void
|
ngOnInit |
ngOnInit()
|
Returns :
void
|
setPageExitTelemtry |
setPageExitTelemtry()
|
Returns :
void
|
setSyncTelemetry |
setSyncTelemetry()
|
Returns :
void
|
setTelemetryImpression |
setTelemetryImpression()
|
Returns :
void
|
setTelemetrySyncStatus | ||||
setTelemetrySyncStatus(syncStatus)
|
||||
Parameters :
Returns :
void
|
syncTelemetry |
syncTelemetry()
|
Returns :
void
|
Public connectionService |
Type : ConnectionService
|
disableExport |
Default value : true
|
disableSync |
Default value : true
|
exportedTime |
forceSyncInfo |
Type : any
|
isConnected |
Type : any
|
Public resourceService |
Type : ResourceService
|
showSyncStatus |
Default value : false
|
syncStatus |
Type : any
|
Public telemetryImpression |
Type : IImpressionEventInput
|
telemetryInfo |
Type : ITelemetryInfo
|
Public unsubscribe$ |
Default value : new Subject<void>()
|
import { takeUntil, filter } from 'rxjs/operators';
import { ActivatedRoute, Router, NavigationStart } from '@angular/router';
import { TelemetryService, IImpressionEventInput } from '@sunbird/telemetry';
import { ResourceService, ToasterService, ConnectionService } from '@sunbird/shared';
import { TelemetryActionsService } from './../../../offline/services';
import { Component, OnInit, OnDestroy } from '@angular/core';
import * as _ from 'lodash-es';
import { Subject } from 'rxjs';
import { ITelemetryInfo } from '../../interfaces';
import { debounceTime } from 'rxjs/operators';
@Component({
selector: 'app-telemetry',
templateUrl: './telemetry.component.html',
styleUrls: ['./telemetry.component.scss']
})
export class TelemetryComponent implements OnInit, OnDestroy {
telemetryInfo: ITelemetryInfo;
public telemetryImpression: IImpressionEventInput;
public unsubscribe$ = new Subject<void>();
disableExport = true;
syncStatus: any;
disableSync = true;
showSyncStatus = false;
isConnected: any;
exportedTime;
forceSyncInfo: any;
constructor(
private telemetryActionService: TelemetryActionsService,
public resourceService: ResourceService,
private toasterService: ToasterService,
private telemetryService: TelemetryService,
private activatedRoute: ActivatedRoute,
private router: Router,
public connectionService: ConnectionService
) { }
ngOnInit() {
this.router.events
.pipe(filter((event) => event instanceof NavigationStart), takeUntil(this.unsubscribe$))
.subscribe(x => { this.setPageExitTelemtry(); });
this.getTelemetryInfo();
this.setTelemetryImpression();
// this event will start when import new telemetry file and status is completed
this.telemetryActionService.telemetryImportEvent
.pipe(debounceTime(1000), takeUntil(this.unsubscribe$))
.subscribe(data => {
this.getTelemetryInfo();
});
this.getSyncStatus();
this.checkOnlineStatus();
}
getTelemetryInfo() {
this.telemetryActionService.getTelemetryInfo().pipe(takeUntil(this.unsubscribe$)).subscribe(data => {
this.telemetryInfo = _.get(data, 'result.response');
this.disableExport = !this.telemetryInfo['totalSize'];
this.disableSync = !this.telemetryInfo['totalSize'];
this.forceSyncInfo = _.find(_.get(data, 'result.response.networkInfo.forceSyncInfo'), { type: 'TELEMETRY' });
}, (err) => {
this.disableExport = true;
this.toasterService.error(this.resourceService.messages.emsg.desktop.telemetryInfoEMsg);
});
}
getSyncStatus() {
this.telemetryActionService.getSyncTelemetryStatus().pipe(takeUntil(this.unsubscribe$)).subscribe(data => {
this.syncStatus = _.get(data, 'result.enable');
});
}
exportTelemetry() {
this.disableExport = true;
this.logTelemetry('export-telemetry');
this.telemetryActionService.exportTelemetry().pipe(takeUntil(this.unsubscribe$)).subscribe(
(data) => {
this.getTelemetryInfo();
this.toasterService.success(this.resourceService.messages.smsg.desktop.telemetryExportSMsg);
},
(err) => {
this.disableExport = !this.telemetryInfo['totalSize'];
if (err.error.responseCode !== 'NO_DEST_FOLDER') {
this.toasterService.error(this.resourceService.messages.emsg.desktop.telemetryExportEMsg);
}
}
);
}
setTelemetrySyncStatus(syncStatus) {
const interactData = {
context: {
env: _.get(this.activatedRoute.snapshot.data.telemetry, 'env') || 'telemetry',
cdata: []
},
edata: {
id: 'telemetry_sync_status' + syncStatus,
type: 'click',
pageid: _.get(this.activatedRoute.snapshot.data.telemetry, 'pageid'),
extra: {}
}
};
this.telemetryService.interact(interactData);
}
handleSyncStatus(syncStatus) {
this.setTelemetrySyncStatus(syncStatus);
const data = {
'request': {
'enable': syncStatus
}
};
this.telemetryActionService.updateSyncStatus(data).pipe(takeUntil(this.unsubscribe$)).subscribe((response) => {});
}
checkOnlineStatus() {
this.connectionService.monitor().pipe(takeUntil(this.unsubscribe$)).subscribe(isConnected => {this.isConnected = isConnected; });
}
syncTelemetry() {
this.setSyncTelemetry();
if (this.isConnected) {
const data = {
'request': {
'type': ['TELEMETRY']
}
};
this.showSyncStatus = true;
this.disableSync = true;
this.telemetryActionService.syncTelemtry(data).pipe(takeUntil(this.unsubscribe$)).subscribe(response => {
this.showSyncStatus = false;
this.getTelemetryInfo();
}, (err) => {
this.showSyncStatus = false;
this.disableSync = false;
this.toasterService.error(this.resourceService.messages.emsg.desktop.telemetrySyncError);
});
} else {
this.toasterService.error(this.resourceService.messages.emsg.desktop.connectionError);
}
}
setSyncTelemetry() {
const interactData = {
context: {
env: _.get(this.activatedRoute.snapshot.data.telemetry, 'env') || 'telemetry',
cdata: []
},
edata: {
id: 'sync_telemetry',
type: 'click',
pageid: _.get(this.activatedRoute.snapshot.data.telemetry, 'pageid'),
extra: {
size: this.telemetryInfo['totalSize'],
}
}
};
this.telemetryService.interact(interactData);
}
setTelemetryImpression() {
this.telemetryImpression = {
context: {
env: _.get(this.activatedRoute.snapshot.data.telemetry, 'env') || 'telemetry'
},
edata: {
type: 'view',
pageid: _.get(this.activatedRoute.snapshot.data.telemetry, 'pageid'),
uri: this.router.url
}
};
}
setPageExitTelemtry() {
this.telemetryImpression.edata.subtype = 'pageexit';
}
logTelemetry(id) {
const interactData = {
context: {
env: _.get(this.activatedRoute.snapshot.data.telemetry, 'env') || 'telemetry',
cdata: []
},
edata: {
id: id,
type: 'click',
pageid: _.get(this.activatedRoute.snapshot.data.telemetry, 'pageid'),
extra: {
size: this.telemetryInfo['totalSize'],
}
}
};
this.telemetryService.interact(interactData);
}
ngOnDestroy() {
this.unsubscribe$.next();
this.unsubscribe$.complete();
}
}
<div class="sb-single-resource">
<div class="ui container" [appTelemetryImpression]="telemetryImpression">
<div class="my-16">
<div class="sb-bg-color-white py-16 relative9">
<div class="d-flex profile-telemetry-title sb-bg-color-white px-16 pb-8">
{{resourceService?.frmelmnts?.lbl?.desktop?.syncTelemetry}}</div>
<div class="d-flex flex-jc-space-between p-16">
<a
class="profile-telemetry-subtitle cursor-pointer">{{resourceService?.frmelmnts?.lbl?.desktop?.automaticSyncTelemetry}}</a>
</div>
<div class="d-flex flex-dc flex-w-wrap">
<div class="d-flex sb-radio-btn-checkbox sb-radio-btn-primary px-16 pb-8">
<input type="radio" id="alwaysOn" name="radio-group" [checked]="syncStatus" (change)="handleSyncStatus(true)">
<label for="alwaysOn">{{resourceService?.frmelmnts?.lbl?.desktop?.alwaysOn}}</label>
</div>
<div class="d-flex sb-radio-btn-checkbox sb-radio-btn-primary px-16 pb-8">
<input type="radio" id="off" name="radio-group" [checked]="!syncStatus" (change)="handleSyncStatus(false)" >
<label for="off">{{resourceService?.frmelmnts?.lbl?.desktop?.Off}}</label>
</div>
</div>
<div class="d-flex flex-w-wrap px-16">
<div>
<button type="button" class="sb-btn sb-btn-primary sb-btn-normal my-8" [ngClass]="disableSync || !isConnected ? 'sb-btn-disabled pointer-events-disabled': ''" [disabled]="disableSync || !isConnected" tabindex="0" (click)="syncTelemetry()">
{{resourceService?.frmelmnts?.lbl?.desktop?.syncTelemetry}} ({{telemetryInfo?.totalSize | filesize}})</button>
<dl class="my-0 profile-description">
<dd class="multiline-list-value profile-description-title" *ngIf="showSyncStatus">
{{resourceService?.messages?.imsg?.desktop?.m002}}</dd>
</dl>
<dl class="my-0" *ngIf="forceSyncInfo?.lastSyncedOn">
<dt class="multiline-list-key">{{resourceService?.frmelmnts?.lbl?.desktop?.lastSynced}}</dt>
<dd class="multiline-list-value">{{forceSyncInfo?.lastSyncedOn |
date: 'd MMMM y'}} at {{forceSyncInfo?.lastSyncedOn | date:
'h:mm a'}}</dd>
</dl>
</div>
<div class="share-tele-btn">
<button type="button" class="sb-btn sb-btn-secondary sb-btn-normal
my-8" tabindex="0" (click)="exportTelemetry()" [disabled]="disableExport" *ngIf="telemetryInfo?.totalSize">
{{resourceService?.frmelmnts?.btn?.desktop?.shareTelemetry}}
({{telemetryInfo?.totalSize | filesize}})
</button>
<button type="button" class="sb-btn sb-btn-secondary sb-btn-normal
my-8" tabindex="0" (click)="exportTelemetry()" [disabled]="disableExport" *ngIf="!telemetryInfo?.totalSize">
{{resourceService?.frmelmnts?.btn?.desktop?.shareTelemetry}}
({{telemetryInfo?.totalSize | filesize}})
</button>
<dl class="my-0 profile-description" *ngIf="telemetryInfo?.lastExportedOn">
<dt class="multiline-list-key">{{resourceService?.frmelmnts?.lbl?.desktop?.lastShared}}</dt>
<dd class="multiline-list-value"> {{telemetryInfo?.lastExportedOn |
date: 'd MMMM y'}} at {{telemetryInfo?.lastExportedOn | date:
'h:mm a'}}
</dd>
</dl>
<dl class="my-0 profile-description">
<dd class="multiline-list-value profile-description-title" *ngIf="!telemetryInfo?.totalSize">
{{resourceService?.messages?.imsg?.desktop?.m001}}</dd>
</dl>
</div>
</div>
</div>
</div>
<app-telemetry-import> </app-telemetry-import>
</div>
</div>
./telemetry.component.scss
@use "@project-sunbird/sb-styles/assets/mixins/mixins" as *;
.profile-telemetry-title {
font-size: calculateRem(16px);
font-weight: bold;
border-bottom: calculateRem(1px) solid var(--primary-color);
color: var(--primary-color);
}
.profile-telemetry-subtitle {
font-size: calculateRem(14px);
color: var(--primary-color) !important;
}
.share-tele-btn {
margin: 0px;
margin-left: calculateRem(16px);
@include respond-below(sm){
margin-left: calculateRem(0px);
}
}
.sb-checkbox label,
.sb-radio-btn-checkbox label {
color: var(--primary-color);
font-weight: normal;
}
.profile-description {
width: 100%;
max-width: calculateRem(160px);
}
.profile-description-title {
color: var(--primary-color) !important;
}
.sb-single-resource {
width: 100%;
height: 100%;
max-width: calculateRem(896px);
margin: 0 auto;
@include respond-above(lg) {
max-width: calculateRem(960px);
}
@include respond-above(xl) {
max-width: calculateRem(1024px);
}
@include respond-above(xxxl) {
max-width: calculateRem(1088px);
}
}