File
Implements
Methods
Private
getSystemInfo
|
getSystemInfo()
|
|
|
ngOnDestroy
|
ngOnDestroy()
|
|
|
Readonly
MAXIMUM_CPU_LOAD
|
Type : number
|
Default value : 90
|
|
Readonly
MINIMUM_REQUIRED_RAM
|
Type : number
|
Default value : 100
|
|
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>
@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 with directive