This is the codeAbility Sharing Platform! Learn more about the codeAbility Sharing Platform.

Skip to content
Snippets Groups Projects
achievements.component.ts 1.8 KiB
Newer Older
import { Component, OnInit } from '@angular/core';
import { Injectable } from '@angular/core';
import { SearchService } from 'app/search/service/search-service';
import { HttpClient } from '@angular/common/http';

import { AccountService } from 'app/core/auth/account.service';
import { Account } from 'app/core/user/account.model';
import { Statistics } from 'app/shared/model/statistics.model';

@Component({
  selector: 'jhi-achievements',
  templateUrl: './achievements.component.html',
  styleUrls: ['./achievements.component.scss'],
})
@Injectable({ providedIn: 'root' })
export class AchievementsComponent implements OnInit {
  account!: Account;
  statistics!: Statistics;
  config = require('./achievements_config.json');
  constructor(private accountService: AccountService, protected searchService: SearchService, private httpClient: HttpClient) {}

  public getTotalNumberOfViews(): void {
    // eslint-disable-next-line no-console
    console.log('I have been called');
    this.searchService.getStatisticsForUser(this.account.firstName + ' ' + this.account.lastName).subscribe(
      (data: Statistics) => {
        if (data) {
          this.statistics = data;

          // eslint-disable-next-line no-console
          console.log(
            'Data: Number of Downloads: ' +
              data.downloads +
              ' Number of views: ' +
              data.views +
              ' for account ' +
              this.account.firstName +
              ' ' +
              this.account.lastName +
              this.config.views[0]
      },
      () => alert('Could not load statistics for User')
    );
  }

  ngOnInit(): void {
    this.accountService.identity().subscribe(account => {
      if (account) {
        this.account = account;
      }
    });
    this.getTotalNumberOfViews();