@WidgetComponent

nm-job-settings

File

src/app/shared/widgets/jobs/settings/job-settings.component.ts

Description

This class represents the job settings widget.

Metadata

selector nm-job-settings
styleUrls job-settings.component.scss
templateUrl ./job-settings.component.html

Index

Widget inputs
Widget outputs
Properties
Methods

Constructor

constructor(widgetFrameService: WidgetframeService, translateService: TranslateService)
Parameters :
Name Type Optional
widgetFrameService WidgetframeService no
translateService TranslateService no

Methods

Private adjustToDailyTrigger
adjustToDailyTrigger()
Returns : void
Private adjustToHourlyTrigger
adjustToHourlyTrigger()
Returns : void
Private adjustToManuallyTrigger
adjustToManuallyTrigger()
Returns : void
Private adjustToMinutlyTrigger
adjustToMinutlyTrigger()
Returns : void
Private adjustToMonthlyTrigger
adjustToMonthlyTrigger()
Returns : void
Private adjustToSecondlyTrigger
adjustToSecondlyTrigger()
Returns : void
Private adjustToWeeklyTrigger
adjustToWeeklyTrigger()
Returns : void
Private adjustTriggerInputs
adjustTriggerInputs()
Returns : void
Public checkValidInputs
checkValidInputs()
Returns : void
Protected configureWidget
configureWidget(configuration: WidgetConfig)
Decorators : WidgetConfigure
Parameters :
Name Type Optional
configuration WidgetConfig no
Returns : void
Private filterOptions
filterOptions()
Returns : void
Private getInterval
getInterval()
Returns : any
getSelectedDay
getSelectedDay(day: )
Parameters :
Name Optional
day no
Returns : void
Private getTime
getTime()
Returns : string
Public onChange
onChange()
Returns : void
Public onChangeInput
onChangeInput(event: )
Parameters :
Name Optional
event no
Returns : void
Private resetValues
resetValues()
Returns : void
Public validateDayOfMonth
validateDayOfMonth()
Returns : void
Public validateHours
validateHours()
Returns : void
Private validateIntervalJobs
validateIntervalJobs()
Returns : void
Public validateMinutes
validateMinutes()
Returns : void
Private validateMonthlyJobs
validateMonthlyJobs()
Returns : void
Private validateWeeklyJobs
validateWeeklyJobs()
Returns : void

Properties

Public _id
_id: string
Type : string
Decorators : WidgetId
Public configuration
configuration: WidgetConfig
Type : WidgetConfig
Decorators : WidgetConfiguration
Public disableHours
disableHours:
Default value : true
Public disableMinutes
disableMinutes:
Default value : true
Public disableMonthDays
disableMonthDays:
Default value : true
Public disableSlider
disableSlider:
Default value : true
Public disableWeekDays
disableWeekDays:
Default value : true
Public fetchSettingsConfig
fetchSettingsConfig:
Default value : new Subject<boolean>()
Decorators : WidgetInput

Channel to get cuurent job settings configurations

Public filterCtrl
filterCtrl: FormControl
Type : FormControl
Default value : new FormControl()
Public hourValue
hourValue:
Public initialOptions
initialOptions: any
Type : any
Public interval
interval: any
Type : any
Default value : 1
Public isValidData
isValidData:
Default value : new ReplaySubject<any>()
Decorators : WidgetOutput

Emits the data validity based on job type

Public jobSettingsConfig
jobSettingsConfig:
Default value : new Subject<any>()
Decorators : WidgetOutput

Emits cuurent job settings configurations

Public jobType
jobType: string
Type : string
Public jobTypes
jobTypes: any[]
Type : any[]
Public loadSettingsUriChannel
loadSettingsUriChannel:
Default value : new Subject<any>()
Decorators : WidgetInput

Sets loaded settings

Public maxValue
maxValue: number
Type : number
Default value : 23
Public minutValue
minutValue:
Public monthDay
monthDay:
Public resetSelection
resetSelection:
Default value : new Subject<any>()
Public selectDays
selectDays:
Default value : new ReplaySubject<any>(1)
Public selectedDay
selectedDay: WeekDay[]
Type : WeekDay[]
Default value : []
Public selectedDayObservable
selectedDayObservable:
Default value : new Subject<any>()
Public settingsConfig
settingsConfig: any
Type : any
Default value : {}
Private unsubscribe
unsubscribe:
Default value : NgUnsubscribe.create()
import { Component } from "@angular/core";
import { Subject, ReplaySubject } from "rxjs";
import { TranslateService } from "@ngx-translate/core";
import { FormControl } from "@angular/forms";
import { takeUntil } from "rxjs/operators";
import {
  WidgetComponent,
  WidgetConfiguration,
  WidgetId,
  WidgetInput,
  WidgetOutput,
  WidgetConfigure,
} from "../../widget.metadata";
import { NgUnsubscribe } from "../../../../shared/ng-unsubscribe";
import { WidgetConfig } from "../../widget.configuration";
import { WeekDay } from "../../../components/week-day-selector/week-day-selector.component";
import { WidgetframeService } from "../../widgetframe/widgetframe.service";
import { UtilService } from "../../../components/util/util.service";

const MAX_MONTH_DAYS = "31";
const MAX_HOURS = "23";
const MAX_MINUTES = "59";
const MIN_VALUE = "0";

export enum JobTypes {
  MANUALLY = "IMMEDIATE",
  EVERY_MONTH = "MONTHLY",
  EVERY_WEEK = "WEEKLY",
  EVERY_DAY = "DAILY",
  EVERY_HOUR = "HOURLY",
  EVERY_MINUTE = "MINUTELY",
  EVERY_SECOND = "SECONDLY",
}

/**
 * This class represents the job settings widget.
 */
@WidgetComponent("nm-job-settings")
@Component({
  selector: "nm-job-settings",
  templateUrl: "./job-settings.component.html",
  styleUrls: ["./job-settings.component.scss"],
})
export class JobSettingsWidget {
  private unsubscribe = NgUnsubscribe.create();

  @WidgetConfiguration()
  public configuration: WidgetConfig;

  @WidgetId()
  public _id: string;

  /**
   * Channel to get cuurent job settings configurations
   */
  @WidgetInput("fetchJobSettings")
  public fetchSettingsConfig = new Subject<boolean>();

  /**
   * Emits cuurent job settings configurations
   */
  @WidgetOutput("jobSettings")
  public jobSettingsConfig = new Subject<any>();

  /**
   * Emits the data validity based on job type
   */
  @WidgetOutput("isValidData")
  public isValidData = new ReplaySubject<any>();

  /**
   * Sets loaded settings
   */
  @WidgetInput("loadSettings")
  public loadSettingsUriChannel = new Subject<any>();

  public selectedDayObservable = new Subject<any>();
  public filterCtrl: FormControl = new FormControl();
  public resetSelection = new Subject<any>();

  public jobTypes: any[];

  public initialOptions: any;

  public disableSlider = true;
  public disableWeekDays = true;
  public disableMonthDays = true;
  public disableHours = true;
  public disableMinutes = true;

  public selectedDay: WeekDay[] = [];
  public jobType: string;
  public interval: any = 1;
  public monthDay;
  public hourValue;
  public minutValue;
  public maxValue = 23;
  public settingsConfig: any = {};
  public selectDays = new ReplaySubject<any>(1);

  constructor(
    private widgetFrameService: WidgetframeService,
    private translateService: TranslateService
  ) {}

  @WidgetConfigure()
  protected configureWidget(configuration: WidgetConfig) {
    this.widgetFrameService
      .getData(this.configuration.configuration.jobTypeUrl)
      .subscribe((response) => {
        this.jobTypes = response._embedded["job-types"];
        this.initialOptions = this.jobTypes;
      });

    this.filterCtrl.valueChanges
      .pipe(takeUntil(this.unsubscribe))
      .subscribe(() => {
        this.filterOptions();
      });

    this.selectedDayObservable
      .pipe(takeUntil(this.unsubscribe))
      .subscribe((value) => {
        this.selectedDay = value.index;
      });

    this.fetchSettingsConfig.pipe(takeUntil(this.unsubscribe)).subscribe(() => {
      this.settingsConfig.jobType = this.jobType;
      this.settingsConfig.interval = this.getInterval();
      this.settingsConfig.minutes = this.minutValue;
      this.settingsConfig.hours = this.hourValue;
      this.settingsConfig.time = this.getTime();
      this.settingsConfig.weekDay = this.selectedDay[0];
      this.settingsConfig.dayOfMonth = this.monthDay;

      this.jobSettingsConfig.next(this.settingsConfig);
    });

    this.loadSettingsUriChannel
      .pipe(takeUntil(this.unsubscribe))
      .subscribe((setting) => {
        if (!setting) {
          return;
        }
        this.monthDay = setting.dayOfMonth;
        this.interval = setting.interval;
        this.jobType = setting.jobType;
        this.hourValue = setting.hours;
        this.minutValue = setting.minutes;
        if (this.jobType === JobTypes.EVERY_WEEK) {
          this.selectDays.next([{ index: Number(setting.weekDay.index) }]);
        }
        this.checkValidInputs();
        this.adjustTriggerInputs();
      });
  }

  getSelectedDay(day) {
    this.selectedDay = [];
    this.selectedDay.push(day);
    this.checkValidInputs();
  }

  public onChange() {
    this.resetValues();
    this.checkValidInputs();
    this.settingsConfig = {};
    this.adjustTriggerInputs();
  }

  private adjustTriggerInputs() {
    switch (this.jobType) {
      case JobTypes.MANUALLY:
        this.adjustToManuallyTrigger();
        break;
      case JobTypes.EVERY_SECOND:
        this.adjustToSecondlyTrigger();
        break;
      case JobTypes.EVERY_MINUTE:
        this.adjustToMinutlyTrigger();
        break;
      case JobTypes.EVERY_HOUR:
        this.adjustToHourlyTrigger();
        break;
      case JobTypes.EVERY_DAY:
        this.adjustToDailyTrigger();
        break;
      case JobTypes.EVERY_WEEK:
        this.adjustToWeeklyTrigger();
        break;
      case JobTypes.EVERY_MONTH:
        this.adjustToMonthlyTrigger();
        break;
    }
  }

  private getInterval(): any {
    switch (this.jobType) {
      case JobTypes.EVERY_SECOND:
      case JobTypes.EVERY_MINUTE:
      case JobTypes.EVERY_HOUR:
        return this.interval;
      default:
        return null;
    }
  }
  public checkValidInputs() {
    switch (this.jobType) {
      case JobTypes.MANUALLY:
        this.isValidData.next(true);
        break;

      case JobTypes.EVERY_SECOND:
      case JobTypes.EVERY_MINUTE:
      case JobTypes.EVERY_HOUR:
      case JobTypes.EVERY_DAY:
        this.validateIntervalJobs();
        break;

      case JobTypes.EVERY_WEEK:
        this.validateWeeklyJobs();
        break;

      case JobTypes.EVERY_MONTH:
        this.validateMonthlyJobs();
        break;
    }
  }

  private validateMonthlyJobs() {
    if (
      this.monthDay &&
      (this.hourValue || this.hourValue === 0) &&
      (this.minutValue || this.minutValue === 0)
    ) {
      this.isValidData.next(true);
      return;
    }
    this.isValidData.next(false);
  }

  private validateWeeklyJobs() {
    if (
      this.selectedDay[0] &&
      (this.hourValue || this.hourValue === 0) &&
      (this.minutValue || this.minutValue === 0)
    ) {
      this.isValidData.next(true);
      return;
    }
    this.isValidData.next(false);
  }

  private validateIntervalJobs() {
    if (
      (this.hourValue || this.hourValue === 0) &&
      (this.minutValue || this.minutValue === 0)
    ) {
      this.isValidData.next(true);
      return;
    }
    this.isValidData.next(false);
  }

  private adjustToMonthlyTrigger() {
    this.disableWeekDays = true;
    this.disableMonthDays = false;
    this.disableSlider = true;
    this.disableHours = false;
    this.disableMinutes = false;
  }

  private adjustToWeeklyTrigger() {
    this.disableWeekDays = false;
    this.disableMonthDays = true;
    this.disableSlider = true;
    this.disableHours = false;
    this.disableMinutes = false;
  }

  private adjustToDailyTrigger() {
    this.disableWeekDays = true;
    this.disableMonthDays = true;
    this.disableSlider = true;
    this.disableHours = false;
    this.disableMinutes = false;
  }

  private adjustToHourlyTrigger() {
    this.maxValue = 23;
    this.disableWeekDays = true;
    this.disableMonthDays = true;
    this.disableSlider = false;
    this.disableHours = false;
    this.disableMinutes = false;
  }

  private adjustToMinutlyTrigger() {
    this.maxValue = 59;
    this.disableWeekDays = true;
    this.disableMonthDays = true;
    this.disableSlider = false;
    this.disableHours = false;
    this.disableMinutes = false;
  }

  private adjustToSecondlyTrigger() {
    this.maxValue = 59;
    this.disableWeekDays = true;
    this.disableMonthDays = true;
    this.disableSlider = false;
    this.disableHours = false;
    this.disableMinutes = false;
  }

  private adjustToManuallyTrigger() {
    this.disableWeekDays = true;
    this.disableMonthDays = true;
    this.disableSlider = true;
    this.disableHours = true;
    this.disableMinutes = true;
    this.hourValue = null;
    this.minutValue = null;
    this.interval = null;
  }

  private resetValues() {
    this.monthDay = null;
    this.interval = 1;
    this.selectedDay = [];
    this.hourValue = null;
    this.minutValue = null;
    this.resetSelection.next();
    this.isValidData.next(false);
  }

  private filterOptions() {
    if (!this.jobTypes) {
      return;
    }
    // get the search keyword
    let search = this.filterCtrl.value;

    this.jobTypes = search
      ? this.initialOptions.filter((option) => {
          var key = this.translateService.instant(option.messageKey);
          return key.toLowerCase().indexOf(search.toLowerCase()) > -1;
        })
      : this.initialOptions.slice();
  }

  public validateDayOfMonth() {
    var max = parseInt(MAX_MONTH_DAYS);

    if (parseInt(this.monthDay) < 1) {
      this.monthDay = 1;
    }

    if (parseInt(this.monthDay) > max) {
      this.monthDay = max;
    }

    this.checkValidInputs();
  }

  public validateHours() {
    this.hourValue = UtilService.validateTime(
      this.hourValue,
      MIN_VALUE,
      MAX_HOURS
    );
    this.checkValidInputs();
  }

  public validateMinutes() {
    this.minutValue = UtilService.validateTime(
      this.minutValue,
      MIN_VALUE,
      MAX_MINUTES
    );
    this.checkValidInputs();
  }

  private getTime(): string {
    if (this.hourValue || this.minutValue) {
      return (
        UtilService.formatTime(+this.hourValue) +
        ":" +
        UtilService.formatTime(+this.minutValue)
      );
    }
    return null;
  }

  public onChangeInput(event) {
    alert(event);
  }
}
<mat-dialog-content class="nm-dialog__content">
  <mat-form-field id="jobType" [floatLabel]="true">
    <mat-select
      class="nm-full-width"
      [(ngModel)]="jobType"
      (selectionChange)="onChange()"
      shouldLabelFloat="true"
      [name]="jobType"
      disabled="false"
      [placeholder]="
        'web.processes.jobs.settings.jobtype.placeholder' | translate
      "
      [nmAutofocus]="true"
    >
      <mat-option>
        <ngx-mat-select-search
          placeholderLabel="{{ 'placeholder.search' | translate }}"
          [formControl]="filterCtrl"
          noEntriesFoundLabel="{{ 'select.no.options' | translate }}"
        >
        </ngx-mat-select-search>
      </mat-option>
      <mat-option *ngFor="let type of jobTypes" [value]="type.identifier">
        {{ type.messageKey | translate }}
      </mat-option>
    </mat-select>
  </mat-form-field>

  <nm-week-day-selector
    [disabled]="disableWeekDays"
    [selectDays]="selectDays"
    (selectedDays)="getSelectedDay($event)"
    [reset]="resetSelection"
  >
  </nm-week-day-selector>

  <br />
  <h6 id="interval-lable">
    {{ "web.processes.jobs.settings.interval.placeholder" | translate }}
  </h6>

  <div>
    <mat-slider
      thumbLabel
      id="interval-slider"
      min="1"
      [max]="maxValue"
      [(ngModel)]="interval"
      [disabled]="disableSlider"
      (change)="checkValidInputs()"
      [value]="interval"
    ></mat-slider>

    <mat-form-field id="intervalValue">
      <input type="text" matInput disabled [(ngModel)]="interval" />
    </mat-form-field>
  </div>

  <mat-form-field id="monthPicker" class="full-width">
    <mat-label>{{
      "web.processes.jobs.settings.monthDay.placeholder" | translate
    }}</mat-label>
    <input
      matInput
      type="number"
      min="1"
      max="31"
      autocomplete="off"
      [disabled]="disableMonthDays"
      [(ngModel)]="monthDay"
      (change)="validateDayOfMonth()"
    />
  </mat-form-field>

  <h6 class="nm-start-lable">
    {{ "web.processes.jobs.settings.startAt.placeholder" | translate }}
  </h6>

  <mat-form-field id="hours" class="nm-margin">
    <mat-label>HH</mat-label>
    <input
      matInput
      type="number"
      min="0"
      max="23"
      autocomplete="off"
      [(ngModel)]="hourValue"
      [disabled]="disableHours"
      (change)="validateHours()"
    />
  </mat-form-field>

  <mat-form-field id="minuts">
    <mat-label>MM</mat-label>
    <input
      matInput
      type="number"
      min="0"
      max="59"
      autocomplete="off"
      [(ngModel)]="minutValue"
      [disabled]="disableMinutes"
      (change)="validateMinutes()"
    />
  </mat-form-field>
</mat-dialog-content>
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""