How to do if not repeat the function for those who already reached a number

0

I make a call in the DB from the API to see the sales percentage data for a store's branches, and if the percentage is greater than or equal to 100% I should play a song and change its color to green.

And I use the schedule ( link ) > to reload the content.

But every time the content is reloaded it plays the song again for the branch that has already reached the goal, being only to play the song only once for the branch, it has to play again if another branch reach the goal.

Method that lists the branches, changes color, plays music and percentage of them:

 ListaFiliaisDiaria() {

    this.MetaService.FiliaisMetaDiarias().subscribe(
      data => {
        const response = (data as any)
        this.objeto_retorno = JSON.parse(response._body);

        this.fil.length = 0;
        this.filMetade.length = 0
        this.filNaoAtingida.length = 0

        this.objeto_retorno.forEach(element => {

          this.tots = element.TOTAL
          element.TOTAL = (element.TOTAL * 100).toFixed(3) + '%'
          element.TOTAL = element.TOTAL.toString().replace(".", ",")


          if (this.tots >= this.MetaAtingida) {

            this.audio = new Audio();
            this.audio.src = "../../../assets/music/SupermanCorrect.mp3";
            this.audio.load();
            this.audio.play();

            this.fil.push({
              FI: element.FILIAL,
              porc: element.TOTAL             
            });

            this.mainColor = 'MetaAtingida'          

          }
          else if (this.tots >= this.MetaMetade && this.tots < this.MetaAtingida) {

            this.filMetade.push({
              filialMetade: element.FILIAL,
              porcMetade: element.TOTAL
            });

            this.mainColorTwo = 'MetaOitenta'

          }

          else if (this.tots < this.MetaMetade) {

            this.filNaoAtingida.push({
              FilialNaoAtingida: element.FILIAL,
              MetaNaoAtingida: element.TOTAL
            });
            this.mainColorThree = 'MetaNaoAtingida'

          }

        })

      }
}

and ngOnInit ():

  ngOnInit() {
    schedule.scheduleJob(' 15 * * * * * ', () => {         
      this.ListaFiliaisDiaria()
    });
}

HTML that lists the branches:

<p [class]="mainColor + ' teste' " *ngFor="let element of fil" id="fi">Filial {{ element.FI }} = {{ element.porc }}</p>

<p [class]="mainColorTwo + ' teste' " *ngFor="let element of filMetade">Filial {{ element.filialMetade }} = {{ element.porcMetade }}</p>

<p [class]="mainColorThree + ' teste '" *ngFor="let element of filNaoAtingida">Filial {{ element.FilialNaoAtingida }} = {{ element.MetaNaoAtingida }}</p>

How do I get to play the song just once for that branch? Can anyone help me?

    
asked by anonymous 23.08.2018 / 17:34

0 answers