File

src/app/user-dashboard/user-dashboard.component.ts

Implements

OnInit

Metadata

Index

Properties
Methods

Constructor

constructor(router: Router, authenticationService: AuthenticationService, toastr: ToastrService, spinner: NgxSpinnerService, apiService: ApiService)
Parameters :
Name Type Optional
router Router No
authenticationService AuthenticationService No
toastr ToastrService No
spinner NgxSpinnerService No
apiService ApiService No

Methods

logout
logout()
Returns : void
mapStatus
mapStatus(status: string)
Parameters :
Name Type Optional
status string No
Returns : string
ngOnInit
ngOnInit()
Returns : void
onGridReady
onGridReady(params: GridReadyEvent<ManagerTable>)
Parameters :
Name Type Optional
params GridReadyEvent<ManagerTable> No
Returns : void
onSelect
onSelect(event)
Parameters :
Name Optional
event No
Returns : void

Properties

chartData
Type : ChartData[]
chartData2
Type : ChartData[]
Public columnDefs
Type : ColDef[]
Default value : [ { field: 'userId' }, { field: 'firstName' }, { field: 'lastName' }, { field: 'role' }, { field: 'timesheetID' }, { field: 'month' }, { field: 'year' }, { field: 'createdOn' }, { field: 'timesheetStatus' }, ]
currentUser
Type : User
Public defaultColDef
Type : ColDef
Default value : { flex: 1, minWidth: 100, sortable: true, resizable: true, }
defaultProject
Type : Project
gradient
Default value : false
gradient2
Default value : false
gridApi
Type : GridApi
projectForm
Type : FormGroup
Public rowData
Type : ManagerTable[]
showLegend
Default value : true
showLegend2
Default value : true
showXAxis
Default value : true
showXAxis2
Default value : true
showXAxisLabel
Default value : true
showXAxisLabel2
Default value : true
showYAxis
Default value : true
showYAxis2
Default value : true
showYAxisLabel
Default value : true
showYAxisLabel2
Default value : true
title
Type : string
xAxisLabel
Type : string
Default value : 'Date'
xAxisLabel2
Type : string
Default value : 'Project'
yAxisLabel
Type : string
Default value : 'Registered hours'
yAxisLabel2
Type : string
Default value : 'Registered hours'
import { Component, OnInit, ViewChild } from '@angular/core';
import { AuthenticationService } from '../services/authentication.service';
import { User } from '../models/user';
import { Router } from '@angular/router';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { ToastrService } from 'ngx-toastr';
import { NgxSpinnerService } from 'ngx-spinner';
import { ApiService } from '../services/api.service';
import { Project } from '../models/Project';
import { ColDef, GridApi, GridReadyEvent } from 'ag-grid-community';
import { ManagerTable } from '../models/manager-table';
import { mapStatus } from '../timesheets-list/timesheet-list.utils';
import { ChartData } from '../models/chart-data';


@Component({
  selector: 'app-dashboard',
  templateUrl: './user-dashboard.component.html',
  styleUrls: ['./user-dashboard.component.css']
})
export class UserDashboardComponent implements OnInit {

  currentUser: User;
  projectForm: FormGroup;
  title: string;
  defaultProject: Project;
  gridApi: GridApi;
  chartData: ChartData[];
  chartData2: ChartData[];
  
  // options
  showXAxis = true;
  showYAxis = true;
  gradient = false;
  showLegend = true;
  showXAxisLabel = true;
  xAxisLabel = 'Date';
  showYAxisLabel = true;
  yAxisLabel = 'Registered hours';

  showXAxis2 = true;
  showYAxis2 = true;
  gradient2 = false;
  showLegend2 = true;
  showXAxisLabel2 = true;
  xAxisLabel2 = 'Project';
  showYAxisLabel2 = true;
  yAxisLabel2 = 'Registered hours';

  constructor(private router: Router,
              private authenticationService: AuthenticationService,
              private toastr: ToastrService,
              private spinner: NgxSpinnerService,
              private apiService: ApiService) {
    this.authenticationService.currentUser.subscribe(x => this.currentUser = x);
  }

  ngOnInit(): void {
    this.spinner.show();
    this.apiService.getUserChartDataTotalRegisteredHoursByDate((JSON.parse(localStorage.getItem("currentUser"))as unknown as User).id.toString()).subscribe(data => {
      this.chartData = data;
    })
    this.apiService.getUserChartDataTotalRegisteredHoursPerProject((JSON.parse(localStorage.getItem("currentUser"))as unknown as User).id.toString()).subscribe(data => {
      this.chartData2 = data;
      this.spinner.hide();
    })
  }

  public columnDefs: ColDef[] = [
    { field: 'userId' },
    { field: 'firstName' },
    { field: 'lastName' },
    { field: 'role' },
    { field: 'timesheetID' },
    { field: 'month' },
    { field: 'year' },
    { field: 'createdOn' },
    { field: 'timesheetStatus' },
  ];
  
  public defaultColDef: ColDef = {
    flex: 1,
    minWidth: 100,
    sortable: true,
    resizable: true,
  };

  public rowData!: ManagerTable[];

  onGridReady(params: GridReadyEvent<ManagerTable>) {
    this.gridApi = params.api;
    this.apiService.getManagerTable().subscribe((data) => {
      data.map(x => x.timesheetStatus = mapStatus(x.timesheetStatus));
      //data.map(x => Number(x.userId)).sort();
      this.gridApi.setRowData(data);
    })
  }

  logout() {
      this.authenticationService.logout();
      this.router.navigate(['/login']);
    }

  mapStatus(status: string): string {
    return mapStatus(status);
  }

  onSelect(event) {
    console.log(event);
  }
}
<div class="page-header pb-10 page-header-dark bg-primary">
    <div class="container-fluid">
        <div class="page-header-content">
            <h1 class="page-header-title">
                <div class="page-header-icon"><i class="fas fa-user-clock"></i></div>
                <span>Overview</span>
            </h1>
            <div class="page-header-subtitle">Your personal overview</div>
        </div>
    </div>
</div>
<div style="position: relative;">
    <ngx-spinner bdOpacity=0.5 bdColor="rgba(51,51,51,0.85)" size="medium" color="#fff" type="line-scale" [fullScreen]="true">
        <p style="color: white"> Openning connection to our database... </p>
    </ngx-spinner>
</div>
<div class="container-fluid mt-n10">
    <div class="card card-header-actions mx-auto">
        <div class="card-header">
            Registered hours per project
        </div>
        <div class="card-body">
            <ngx-charts-bar-vertical
            [results]="chartData2"
            [gradient]="gradient2"
            [xAxis]="showXAxis2"
            [yAxis]="showYAxis2"
            [legend]="showLegend2"
            [showXAxisLabel]="showXAxisLabel2"
            [showYAxisLabel]="showYAxisLabel2"
            [showGridLines]="false"
            [xAxisLabel]="xAxisLabel2"
            [yAxisLabel]="yAxisLabel2"
            (select)="onSelect($event)">
            </ngx-charts-bar-vertical>      
        </div>
    </div>
    <br>
    <div class="card card-header-actions mx-auto">
        <div class="card-header">
            Registered hours per timesheet
        </div>
        <div class="card-body">
            <ngx-charts-bar-vertical
            [results]="chartData"
            [gradient]="gradient"
            [xAxis]="showXAxis"
            [yAxis]="showYAxis"
            [legend]="showLegend"
            [showXAxisLabel]="showXAxisLabel"
            [showYAxisLabel]="showYAxisLabel"
            [showGridLines]="false"
            [xAxisLabel]="xAxisLabel"
            [yAxisLabel]="yAxisLabel"
            (select)="onSelect($event)">
            </ngx-charts-bar-vertical>                        
        </div>
    </div>          
</div>

./user-dashboard.component.css

Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""