File

src/app/modules/shared/components/system-warning/system-warning.component.ts

Implements

OnInit OnDestroy

Metadata

Index

Properties
Methods

Constructor

constructor(resourceService: ResourceService, systemInfoService: SystemInfoService)
Parameters :
Name Type Optional
resourceService ResourceService No
systemInfoService SystemInfoService No

Methods

Private getSystemInfo
getSystemInfo()
Returns : void
ngOnDestroy
ngOnDestroy()
Returns : void
ngOnInit
ngOnInit()
Returns : void

Properties

Readonly MAXIMUM_CPU_LOAD
Type : number
Default value : 90
Readonly MINIMUM_REQUIRED_RAM
Type : number
Default value : 100
Public resourceService
Type : ResourceService
showCpuLoadWarning
Default value : false
showMinimumRAMWarning
Default value : false
unsubscribe$
Default value : new Subject<void>()
import { Component, OnDestroy, OnInit } from '@angular/core';
import * as _ from 'lodash-es';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import { SystemInfoService } from '../../../public/module/offline/services/system-info/system-info.service';
import { ResourceService } from '../../services/resource/resource.service';

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

  readonly MAXIMUM_CPU_LOAD = 90;
  readonly MINIMUM_REQUIRED_RAM = 100;

  showMinimumRAMWarning = false;
  showCpuLoadWarning = false;
  unsubscribe$ = new Subject<void>();
  constructor(
    public resourceService: ResourceService,
    private systemInfoService: SystemInfoService
  ) { }

  ngOnInit() {
    this.getSystemInfo();
  }

  private getSystemInfo() {
    this.systemInfoService.getSystemInfo().pipe(takeUntil(this.unsubscribe$)).subscribe(data => {
      let { availableMemory } = data.result;
      availableMemory = Math.floor(availableMemory / (1024 * 1024));
      const availableCpuLoad = _.get(data.result, 'cpuLoad');
      this.showCpuLoadWarning = availableCpuLoad ? Boolean(availableCpuLoad > this.MAXIMUM_CPU_LOAD) : false;
      this.showMinimumRAMWarning = availableMemory ? Boolean(availableMemory < this.MINIMUM_REQUIRED_RAM) : false;
    }, error => {
      this.showCpuLoadWarning = false;
      this.showMinimumRAMWarning = false;
    });
  }

  ngOnDestroy() {
    this.unsubscribe$.next();
    this.unsubscribe$.complete();
  }
}
<div class="system-warning-section mr-16 p-24 mb-24" *ngIf="showMinimumRAMWarning || showCpuLoadWarning ">
  <div class="sb-bg-color-white my-16"
    *ngIf="showMinimumRAMWarning">
    <div class="d-flex">
      <div>
        <img src="assets/images/alert.svg" width="22px" height="22px" alt="Low Memory">
      </div>
      <div class="fs-0-785 ml-16 text-left">{{resourceService?.frmelmnts?.lbl?.desktop?.lowMemory}}</div>
    </div>
  </div>

  <div class="sb-bg-color-white my-16"
    *ngIf="showCpuLoadWarning">
    <div class="d-flex">
      <div>
        <img src="assets/images/alert.svg" width="22px" height="22px" alt="Cpu load warning">
      </div>
      <div class="fs-0-785 ml-16 text-left">{{resourceService?.frmelmnts?.lbl?.maxCpuLoadWaring}}</div>
    </div>
  </div>
</div>

./system-warning.component.scss

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

.system-warning-section {
  border-radius: calculateRem(24px);
  background-color: var(--white);
  position: relative;
  z-index: 9;
}
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""