File

src/app/Views/bot-settings/bot-settings.component.ts

Metadata

selector app-bot-settings
styleUrls bot-settings.component.scss
templateUrl bot-settings.component.html

Constructor

constructor(botService: any, helper: any, profileService: any)

Methods

addKeyword
addKeyword(event: MatChipInputEvent)
Returns: any
removeKeyword
removeKeyword(keyword: Keyword)
Returns: any
addShare
addShare(event: MatChipInputEvent)
Returns: any
removeShare
removeShare(share: Share)
Returns: any
setCronString
setCronString()
Returns: void

Properties

addOnBlur
addOnBlur: boolean
Default value: true
const
const: any
cronForm
cronForm: FormControl
Public cronOptions
cronOptions: CronOptions
keywords
keywords: Keyword[]
separatorKeysCodes
separatorKeysCodes: any
shares
shares: Share[]
import { Component, OnInit } from '@angular/core';
import { C, COMMA, ENTER, F } from '@angular/cdk/keycodes';
import { MatChipInputEvent } from '@angular/material/chips';

import { CronOptions } from 'ngx-cron-editor';

import { BotService } from 'src/app/Services/bot.service';
import { HelperService } from 'src/app/Helpers/helper.service';
import { ProfileService } from 'src/app/Services/profile.service';
import { FormControl } from '@angular/forms';

export interface Share {
  isin: string;
}

export interface Keyword {
  name: string;
}

@Component({
  selector: 'app-bot-settings',
  templateUrl: './bot-settings.component.html',
  styleUrls: ['./bot-settings.component.scss'],
})
export class BotSettingsComponent implements OnInit {
  keywords: Keyword[] = [];
  shares: Share[] = [];

  constructor(
    private botService: BotService,
    private helper: HelperService,
    private profileService: ProfileService
  ) {}

  ngOnInit(): void {
    this.shares = this.helper.formatShareData();
    this.keywords = this.helper.formatKeywordsData();
  }

  addOnBlur = true;
  readonly separatorKeysCodes = [ENTER, COMMA] as const;

  async addKeyword(event: MatChipInputEvent): Promise<void> {
    const value = (event.value || '').trim();

    // Add keyword to database
    if (value && !this.keywords.includes({ name: value })) {
      console.log('Added: ' + value);
      this.botService.createKeyword(value.toLowerCase()).subscribe((result) => {
        console.log(result);
      });
    }

    // Clear the input value
    event.chipInput!.clear();

    if (value) {
      await this.helper.delay(1000);
      this.keywords = [];
      this.keywords = this.helper.formatKeywordsData();
    }
  }

  async removeKeyword(keyword: Keyword): Promise<void> {
    this.botService.deleteKeyword(keyword.name).subscribe((result) => {
      console.log(result);
    });

    await this.helper.delay(1000);

    this.keywords = [];
    this.keywords = this.helper.formatKeywordsData();
  }

  async addShare(event: MatChipInputEvent): Promise<void> {
    const value = (event.value || '').trim();

    // Add share to database
    if (value && !this.shares.includes({ isin: value.toLowerCase() })) {
      console.log('Added: ' + value);
      this.botService.createShare(value, 'Comment').subscribe((result) => {
        console.log(result);
      });
    }

    // Clear the input value
    event.chipInput!.clear();

    if (value) {
      await this.helper.delay(1000);

      this.shares = [];
      this.shares = this.helper.formatShareData();
    }
  }

  async removeShare(share: Share): Promise<void> {
    this.botService.deleteShare(share.isin).subscribe((result) => {
      console.log(result);
    });

    await this.helper.delay(1000);

    this.shares = [];
    this.shares = this.helper.formatShareData();
  }

  setCronString() {
    this.profileService
      .addCronString(this.cronForm.value)
      .subscribe((result) => {
        console.log(result);
      });
  }

  cronForm = new FormControl('0 0 1/1 * *');
  public cronOptions: CronOptions = {
    defaultTime: '00:00:00',

    hideMinutesTab: true,
    hideHourlyTab: true,
    hideDailyTab: false,
    hideWeeklyTab: true,
    hideMonthlyTab: true,
    hideYearlyTab: true,
    hideAdvancedTab: true,
    hideSpecificWeekDayTab: true,
    hideSpecificMonthWeekTab: true,

    use24HourTime: true,
    hideSeconds: true,

    cronFlavor: 'quartz', //standard or quartz
  };
}

results matching ""

    No results matching ""