Skip to content

Commit

Permalink
refactor_api(fe):added some docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
Joel0347 authored and Javi111003 committed Nov 24, 2024
1 parent 9ccc9cf commit 3d5360a
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 36 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { AfterViewInit, Component, OnInit, ViewChild } from '@angular/core';
import { Component, OnInit } from '@angular/core';
import { FormGroup, FormBuilder } from '@angular/forms';
import { ConfigColumn } from '../../../../shared/components/table/table.component';
import { MatTableDataSource } from '@angular/material/table';
import { MatPaginator } from '@angular/material/paginator';

@Component({
selector: 'app-equipment',
Expand Down Expand Up @@ -117,6 +116,12 @@ export class EquipmentComponent implements OnInit {
];
}

/**
* Handles the selection of an office option.
* Updates the officeSelected property and checks if both office and center are selected.
* If both are selected, it shows the table and retrieves the equipment for the selected office.
* @param option The selected office option.
*/
handleOptionSelected(option: string) {
this.officeSelected = option;
if (this.officeSelected && this.centerSelected) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component } from '@angular/core';
import { Component, OnInit } from '@angular/core';
import { ConfigColumn } from '../../../../shared/components/table/table.component';

import { MatTableDataSource } from '@angular/material/table';
Expand All @@ -8,31 +8,74 @@ import { MatTableDataSource } from '@angular/material/table';
templateUrl: './total-consumption.component.html',
styleUrl: './total-consumption.component.css'
})
export class TotalConsumptionComponent {
dataSource: MatTableDataSource<any> = new MatTableDataSource([
{position: 1, name: 'Hydrogen'},
{position: 2, name: 'Helium'},
{position: 3, name: 'Lithium'},
{position: 4, name: 'Beryllium'},
{position: 5, name: 'Boron'},
{position: 6, name: 'Carbon'},
{position: 7, name: 'Nitrogen'},
{position: 8, name: 'Oxygen'},
{position: 9, name: 'Fluorine'},
{position: 10, name: 'Neon'},
]);
export class TotalConsumptionComponent implements OnInit {

receivedDate: Date = [][0];
isTableActive: boolean = false;
options: string[] = [];
optionSelected: string = '';
dataSource: MatTableDataSource<any> = new MatTableDataSource([0]);
displayedColumns: ConfigColumn[] = [
{
title: 'No.',
field: 'position'
title: 'Día',
field: 'day'
},
{
title: 'Consumo',
field: 'consumption'
},
{
title: 'Name',
field: 'name'
title: 'Costo',
field: 'cost'
}
];


ngOnInit(): void {
this.getWorkCenters();
}

/**
* This function retrieves the list of work centers.
* It updates the options array with the list of available work centers.
*/
getWorkCenters(): void {
this.options = [
'Centro 1',
'Centro 2',
'Centro 3',
'Cento 4',
'Cento 5',
'Cento 6',
'Casa'
];
}

/**
* This function generates the table data source.
* It updates the MatTableDataSource with data from backend.
*/
generateTable(): void {
this.dataSource.data = [
{position: 1, name: 'Hydrogen'},
{position: 2, name: 'Helium'},
{position: 3, name: 'Lithium'},
{position: 4, name: 'Beryllium'},
{position: 5, name: 'Boron'},
{position: 6, name: 'Carbon'},
{position: 7, name: 'Nitrogen'},
{position: 8, name: 'Oxygen'},
{position: 9, name: 'Fluorine'},
{position: 10, name: 'Neon'},
];
}

/**
* This function is used to filter the start date.
* It checks if the selected date is before the current date.
* @param d The selected date.
* @returns A boolean value indicating if the date is valid.
*/
filterStartDate = (d: Date | null): boolean => {
const today = new Date();
const Tday = today.getDate();
Expand All @@ -50,9 +93,14 @@ export class TotalConsumptionComponent {
return false
};

receivedDate: Date = [][0];

/**
* This function is used to filter the end date.
* It checks if the selected date is after the received date and before the current date.
* @param d The selected date.
* @returns A boolean value indicating if the date is valid.
*/
filterEndDate = (d: Date | null): boolean => {
console.log(this.receivedDate);
let dateSelected = this.receivedDate;
const DSday = dateSelected.getDate();
const DSmonth = dateSelected.getMonth();
Expand All @@ -75,29 +123,31 @@ export class TotalConsumptionComponent {
return false
};

isTableActive: boolean = false;

options: string[] = [
'Centro 1',
'Centro 2',
'Centro 3',
'Cento 4',
'Cento 5',
'Cento 6',
'Casa'
];

optionSelected: string = '';

/**
* Handles the selection of an option.
* Updates the optionSelected property with the selected option.
* @param option The selected option.
*/
handleOptionSelected(option: string) {
this.optionSelected = option;
}

/**
* Handles the selection of a date.
* Updates the receivedDate property with the selected date.
* @param date The selected date.
*/
handleDateSelected(date: Date) {
this.receivedDate = date;
console.log(this.receivedDate);
}

/**
* Handles the click event on the table toggle button.
* Toggles the visibility of the table based on the current state.
*/
onClick() {
this.generateTable();
this.isTableActive = !this.isTableActive;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export class AutocompleteComponent implements OnInit {
map(value => this._filter(value || '')),
);
}

ngOnChanges(changes: SimpleChanges) {
if (changes['options']) {
// Si las opciones cambian, actualiza los filtros o realiza cualquier acción adicional si es necesario
Expand Down

0 comments on commit 3d5360a

Please sign in to comment.