File

src/app/modules/notification/components/in-app-notification/in-app-notification.component.ts

Implements

OnInit OnDestroy

Metadata

Index

Properties
Methods
Inputs

Constructor

constructor(notificationService: NotificationServiceImpl, router: Router, resourceService: ResourceService, telemetryService: TelemetryService, activatedRoute: ActivatedRoute, connectionService: ConnectionService)
Parameters :
Name Type Optional
notificationService NotificationServiceImpl No
router Router No
resourceService ResourceService No
telemetryService TelemetryService No
activatedRoute ActivatedRoute No
connectionService ConnectionService No

Inputs

layoutConfiguration
Type : any

Methods

Async fetchNotificationList
fetchNotificationList()
Returns : any
generateInteractEvent
generateInteractEvent(id)
Parameters :
Name Optional
id No
Returns : void
handleShowLess
handleShowLess(event)
Parameters :
Name Optional
event No
Returns : void
handleShowMore
handleShowMore(event)
Parameters :
Name Optional
event No
Returns : void
ngOnDestroy
ngOnDestroy()
Returns : void
ngOnInit
ngOnInit()
Returns : void
toggleInAppNotifications
toggleInAppNotifications()
Returns : void

Properties

inAppNotificationConfig
Type : NotificationViewConfig
isConnected
Default value : false
notificationCount
Type : number
Default value : 0
notificationList
Type : []
Default value : []
Public resourceService
Type : ResourceService
showNotificationModel
Default value : false
unsubscribe$
Default value : new Subject<void>()
import { Component, Inject, Input, OnDestroy, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { NotificationServiceImpl } from '../../services/notification/notification-service-impl';
import * as _ from 'lodash-es';
import { UserFeedStatus } from '@project-sunbird/client-services/models';
import { NotificationViewConfig } from '@project-sunbird/common-consumption';
import { ResourceService } from '@sunbird/shared';
import { TelemetryService } from '@sunbird/telemetry';
import { takeUntil, delay } from 'rxjs/operators';
import { Subject } from 'rxjs';
import { ConnectionService } from '../../../shared/services/connection-service/connection.service';

@Component({
  selector: 'app-in-app-notification',
  templateUrl: './in-app-notification.component.html',
  styleUrls: ['./in-app-notification.component.scss']
})
export class InAppNotificationComponent implements OnInit, OnDestroy {

  @Input() layoutConfiguration: any;

  showNotificationModel = false;
  notificationList = [];
  notificationCount = 0;
  inAppNotificationConfig: NotificationViewConfig;
  isConnected = false;
  unsubscribe$ = new Subject<void>();

  constructor(
    @Inject('SB_NOTIFICATION_SERVICE') private notificationService: NotificationServiceImpl,
    private router: Router,
    public resourceService: ResourceService,
    private telemetryService: TelemetryService,
    private activatedRoute: ActivatedRoute,
    private connectionService: ConnectionService
  ) {
    this.inAppNotificationConfig = {
      title: _.get(this.resourceService, 'frmelmnts.lbl.notification'),
      subTitle: _.get(this.resourceService, 'frmelmnts.lbl.newNotification'),
      clearText: _.get(this.resourceService, 'frmelmnts.btn.clear'),
      moreText: _.get(this.resourceService, 'frmelmnts.btn.seeMore'),
      lessText: _.get(this.resourceService, 'frmelmnts.btn.seeLess'),
      minNotificationViewCount: 5
    };
  }

  ngOnInit() {
    this.connectionService.monitor()
    .pipe(takeUntil(this.unsubscribe$), delay(2000)).subscribe(isConnected => {
      this.isConnected = isConnected;
      if (this.isConnected) {
        this.notificationService.fetchNotificationList();
      }
    });

    this.fetchNotificationList();
  }

  async fetchNotificationList() {
    this.notificationService.showNotificationModel$.subscribe(data => {
      this.showNotificationModel = data;
    });
    this.notificationService.notificationList$
      .subscribe(notificationListData => {
        this.notificationCount = 0;
        this.notificationList = notificationListData;
        this.notificationList.forEach(e => this.notificationCount += (e.status === UserFeedStatus.UNREAD) ? 1 : 0);
        this.inAppNotificationConfig['subTitle'] = `${this.notificationCount} ${_.get(this.resourceService, 'frmelmnts.lbl.newNotification')}`;
      });
  }

  toggleInAppNotifications() {
    if (!this.showNotificationModel && !this.notificationList.length) {
      return;
    }
    this.generateInteractEvent('show-in-app-notifications');
    this.showNotificationModel = !this.showNotificationModel;
  }

  generateInteractEvent(id) {
    const data = {
      context: {
        env: _.get(this.activatedRoute, 'snapshot.data.telemetry.env') || 'main-header',
        cdata: []
      },
      edata: {
        id,
        type: 'click',
        pageid: 'in-app-notification',
      }
    };
    this.telemetryService.interact(data);
  }

  ngOnDestroy() {
    this.unsubscribe$.next();
    this.unsubscribe$.complete();
  }

  handleShowMore(event) {
    if (event) {
      this.generateInteractEvent('see-more');
    }
  }

  handleShowLess(event) {
    if (event) {
      this.generateInteractEvent('see-less');
    }
  }
}
<div class="ui dropdown right top pointing" [ngClass]="{'notification-disable': !notificationList?.length}" tabindex="0" role="list" aria-label="Notifications" (click)="toggleInAppNotifications()" title="{{notificationList?.length ? '' : resourceService.frmelmnts?.lbl?.noNotificationsToDisplay}}">
  <div class="notification-bell d-flex flex-ai-center flex-jc-center" name="Guest">
    <!-- <img src="./assets/images/notification.svg" alt="In App Notification"> -->
    <i class="icon-svg icon-svg--sm icon-manage"><svg class="icon bell-icon">
      <use xlink:href="./assets/images/sprite.svg#notification"></use>
    </svg></i>
  </div>
  <div class="notification-count" *ngIf="notificationCount">{{notificationCount}}</div>
</div>

<app-modal-wrapper *ngIf="showNotificationModel" [config]="{disableClose: false, size: 'small', panelClass: 'material-modal'}"
  (dismiss)="showNotificationModel=false">
  <ng-template sbModalContent let-data>
    <div class="sb-mat__modal sb-notification-modal">
      <div mat-dialog-title class="mb-0">
        <button aria-label="close dialog" mat-dialog-close class="close-btn"></button>
      </div>
      <div class="sb-mat__modal__content" tabindex="0">
        <sb-notification tabindex="0" [notificationList]="notificationList"
          [inAppNotificationConfig]="inAppNotificationConfig" (showMore)="handleShowMore($event)"
          (showLess)="handleShowLess($event)"></sb-notification>
      </div>
      <div class="sb-mat__modal__actions"></div>
    </div>
  </ng-template>
</app-modal-wrapper>

./in-app-notification.component.scss

@use "@project-sunbird/sb-styles/assets/mixins/mixins" as *;

.notification-bell{
  box-shadow: var(--sbt-box-shadow-6px);
  border-radius: 50%;
  background-color: var(--sb-notification-bg);
  width: calculateRem(40px);
  height: calculateRem(40px);
  .icon-svg{
    width: 1.5rem;
  }
  .bell-icon{
    fill: var(--bell-icon);
  }
}
.notification-count{
  font-size: calculateRem(11px);
  color: var(--white);
  position: absolute;
  width: calculateRem(18px);
  height: calculateRem(18px);
  border-radius: 50%;
  background: var(--orange);
  top: calculateRem(5px);
  left: calculateRem(2px);
  text-align: center;
}
.notification-disable{
  opacity: 0.5;
}
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""