diff --git a/frontend/src/app/config/api.config.ts b/frontend/src/app/config/api.config.ts index 62b1527e..4c81ed75 100644 --- a/frontend/src/app/config/api.config.ts +++ b/frontend/src/app/config/api.config.ts @@ -15,3 +15,14 @@ export const MY_FORMATS = { monthYearA11yLabel: 'MMMM YYYY', }, }; +export const EXPORT_CENTER = '/v1/company/export/list'; +export const EXPORT_AVG = '/v1/company/export/mean_cost'; +export const EXPORT_EXCESS = '/v1/company/export/over_limit'; +export const EXPORT_PREDICTION = '/v1/company/export/proyection'; +export const EXPORT_EQUIPMENT = '/v1/equipment/export'; +export const EXPORT_OFFICE = '/v1/office/export'; +export const EXPORT_COMPARISON = '/v1/policy/export/comparison'; +export const EXPORT_POLICY = '/v1/policy/export/list'; +export const EXPORT_REGISTER = '/v1/register/export'; +export const EXPORT_USER = '/v1/user/export'; +export const EXPORT_ALERT = '/v1/warning/export'; diff --git a/frontend/src/app/modules/global/components/menu/menu.component.css b/frontend/src/app/modules/global/components/menu/menu.component.css index 8f0558c6..8fe29334 100644 --- a/frontend/src/app/modules/global/components/menu/menu.component.css +++ b/frontend/src/app/modules/global/components/menu/menu.component.css @@ -250,7 +250,7 @@ border-radius: 4px; padding: 0.8rem; min-width: 200px; - z-index: 1000; + z-index: 99999; font-family: 'Inter', 'Roboto', sans-serif; } .user-section, diff --git a/frontend/src/app/modules/global/global.module.ts b/frontend/src/app/modules/global/global.module.ts index aee64a92..e5238d68 100644 --- a/frontend/src/app/modules/global/global.module.ts +++ b/frontend/src/app/modules/global/global.module.ts @@ -16,6 +16,7 @@ import { LoginComponent } from './components/login/login.component'; //global services import { WorkCenterService } from '../../services/workCenter/work-center.service'; import { OfficeService } from '../../services/office/office.service'; +import { ExportService } from '../../services/export/export.service'; //global directives import { PasswordValidatorDirective } from '../../directives/password/password.directive'; @@ -90,10 +91,16 @@ import { Observable } from 'rxjs'; export class GlobalModule { workCenters: Item[] = []; offices: Item[] = []; + formatMapper: Map = new Map([ + ["pdf", "application/pdf"], + ["docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document"], + ["csv", "text/csv"] + ]) constructor( public httpCenter: WorkCenterService, public httpOffice: OfficeService, + private httpExport: ExportService, public dialog: MatDialog ) { } @@ -212,6 +219,37 @@ export class GlobalModule { return `${year}-${month}-${day}T${hours}:${minutes}:${seconds}.${milliseconds}`; } + export(route: string, name: string, format: string): void { + this.httpExport.getDocument(route).subscribe({ + next: (response) => { + + if (!response) { + throw new Error("Descarga fallida"); + } + + const binaryString = atob(response); + const bytes = new Uint8Array(binaryString.length); + for (let i = 0; i < binaryString.length; i++) { + bytes[i] = binaryString.charCodeAt(i); + } + + const blob = new Blob([bytes], { type: this.formatMapper.get(format) }); + const url = window.URL.createObjectURL(blob); + const link = document.createElement("a"); + link.href = url; + link.download = `${name}.${format}`; + document.body.appendChild(link); + link.click(); + + window.URL.revokeObjectURL(url); + document.body.removeChild(link); + }, + error: (error) => { + console.error("Error durante la descarga: ", error); + } + }); + } + /** * This function resets all variables * to their initial default values. Use this function to diff --git a/frontend/src/app/modules/office/components/equipment/index/equipment.component.html b/frontend/src/app/modules/office/components/equipment/index/equipment.component.html index cb30732b..c73745cd 100644 --- a/frontend/src/app/modules/office/components/equipment/index/equipment.component.html +++ b/frontend/src/app/modules/office/components/equipment/index/equipment.component.html @@ -31,7 +31,11 @@ [label]="'Consultar'" [function]="onConsultClick.bind(this)"> - +
= new Map([ @@ -184,6 +186,14 @@ export class EquipmentComponent implements OnInit, OnDestroy { } } + exportFunction(): void { + const userId = this.global.getUserInfo().id; + const officeId = this.global.getControlValue(this.form, 'office').id; + const format = this.export.value; + const route = `${API_URL}${EXPORT_EQUIPMENT}?userId=${userId}&officeId=${officeId}&format=%22${format}%22`; + this.global.export(route, "Exceso_de_Cosumo", format); + } + /** * This function is used to handle the "Add" button click event. * It retrieves the values of 'workCenter' and 'office' from the form controls, diff --git a/frontend/src/app/modules/office/components/manage/index/manage.component.html b/frontend/src/app/modules/office/components/manage/index/manage.component.html index 3da520bb..dfeb85a6 100644 --- a/frontend/src/app/modules/office/components/manage/index/manage.component.html +++ b/frontend/src/app/modules/office/components/manage/index/manage.component.html @@ -22,7 +22,11 @@ [label]="'Consultar'" [function]="onConsultClick.bind(this)"> - +
{ await TestBed.configureTestingModule({ declarations: [ ManageComponent, - ManageFormComponent + ManageFormComponent ], imports: [ ReactiveFormsModule, diff --git a/frontend/src/app/modules/office/components/manage/index/manage.component.ts b/frontend/src/app/modules/office/components/manage/index/manage.component.ts index 4f2bab3f..269ec511 100644 --- a/frontend/src/app/modules/office/components/manage/index/manage.component.ts +++ b/frontend/src/app/modules/office/components/manage/index/manage.component.ts @@ -7,6 +7,7 @@ import { FormBuilder, FormControl, FormGroup } from '@angular/forms'; import { Subscription } from 'rxjs'; import { Item } from '../../../../../shared/shared.module'; import { SnackbarService } from '../../../../../services/snackbar/snackbar.service'; +import { API_URL, EXPORT_OFFICE } from '../../../../../config/api.config'; declare var bootstrap: any; @Component({ @@ -19,6 +20,7 @@ export class ManageComponent implements OnInit, OnDestroy { form: FormGroup; showTable: boolean = false; noResults: boolean = false; + export: FormControl = [][0]; dataSource: MatTableDataSource = new MatTableDataSource(); displayedColumns: ConfigColumn[] = [ { @@ -108,6 +110,14 @@ export class ManageComponent implements OnInit, OnDestroy { modal.show(); } + exportFunction(): void { + const userId = this.global.getUserInfo().id; + const centerId = this.global.getControlValue(this.form, "workCenter").id; + const format = this.export.value; + const route = `${API_URL}${EXPORT_OFFICE}?userId=${userId}&companyId=${centerId}&format=%22${format}%22`; + this.global.export(route, "Oficinas", format); + } + /** * Handles the "Consultar" button click event. * Checks if both center and office are selected before showing the table. diff --git a/frontend/src/app/modules/policy/components/comparison/index/comparison.component.html b/frontend/src/app/modules/policy/components/comparison/index/comparison.component.html index 0f9534a1..5f096ffe 100644 --- a/frontend/src/app/modules/policy/components/comparison/index/comparison.component.html +++ b/frontend/src/app/modules/policy/components/comparison/index/comparison.component.html @@ -23,7 +23,11 @@ > - +
diff --git a/frontend/src/app/modules/policy/components/comparison/index/comparison.component.ts b/frontend/src/app/modules/policy/components/comparison/index/comparison.component.ts index 26035acb..d853060f 100644 --- a/frontend/src/app/modules/policy/components/comparison/index/comparison.component.ts +++ b/frontend/src/app/modules/policy/components/comparison/index/comparison.component.ts @@ -3,11 +3,12 @@ import { Component, OnInit } from '@angular/core'; import { MatTableDataSource } from '@angular/material/table'; import { ConfigColumn } from '../../../../../shared/components/table/table.component'; import { PolicyService } from '../../../../../services/policy/policy.service'; -import { FormBuilder, FormGroup } from '@angular/forms'; +import { FormBuilder, FormControl, FormGroup } from '@angular/forms'; import { Item } from '../../../../../shared/shared.module'; import { PolicyComparison } from '../../../../../models/policy.interface'; import { RegisterByDay } from '../../../../../models/register.interface'; import { Chart } from 'chart.js/auto'; +import { API_URL, EXPORT_COMPARISON } from '../../../../../config/api.config'; @Component({ selector: 'app-comparison', @@ -22,6 +23,7 @@ export class ComparisonComponent implements OnInit { registersAfter: RegisterByDay[] = []; noResultsBefore: boolean = false; noResultsAfter: boolean = false; + export: FormControl = [][0]; footerTableBefore: any[] = []; footerTableAfter: any[] = []; dataSourceBefore: MatTableDataSource = new MatTableDataSource(); @@ -132,6 +134,18 @@ export class ComparisonComponent implements OnInit { } } + exportFunction(): void { + const userId = this.global.getUserInfo().id; + const centerId = this.global.getControlValue(this.form, "workCenter").id; + const policy = this.global.getControlValue(this.form, "policy"); + const len = policy.name.length; + const date = policy.name.substring(len - 11, len - 1); + const format = this.export.value; + const params = `?userId=${userId}&companyId=${centerId}&policyId=${policy.id}&applyingDate=%22${date}%22&format=%22${format}%22`; + const route = `${API_URL}${EXPORT_COMPARISON}${params}`; + this.global.export(route, "Comparación_de_Política", format); + } + /** * Retrieves policies based on the selected center ID. * Updates the optionsPolicy array with the names of the policies. diff --git a/frontend/src/app/modules/policy/components/manage/index/manage.component.css b/frontend/src/app/modules/policy/components/manage/index/manage.component.css index c0b6f688..eaabc10a 100644 --- a/frontend/src/app/modules/policy/components/manage/index/manage.component.css +++ b/frontend/src/app/modules/policy/components/manage/index/manage.component.css @@ -2,9 +2,13 @@ padding: 1rem; } .form-buttons { + width: 100%; display: flex; - flex-direction: row; - width: 20%; - align-items: center; - align-content: left; + flex-wrap: wrap; + justify-content: right; + position: relative; + top: 3px; + left: 0; + margin-top: 5px; + gap: 8px; } diff --git a/frontend/src/app/modules/policy/components/manage/index/manage.component.html b/frontend/src/app/modules/policy/components/manage/index/manage.component.html index c364c0eb..427fb9be 100644 --- a/frontend/src/app/modules/policy/components/manage/index/manage.component.html +++ b/frontend/src/app/modules/policy/components/manage/index/manage.component.html @@ -9,6 +9,10 @@ [icon]="'add'" > +
diff --git a/frontend/src/app/modules/policy/components/manage/index/manage.component.ts b/frontend/src/app/modules/policy/components/manage/index/manage.component.ts index 0c415edb..e9a60f61 100644 --- a/frontend/src/app/modules/policy/components/manage/index/manage.component.ts +++ b/frontend/src/app/modules/policy/components/manage/index/manage.component.ts @@ -8,6 +8,8 @@ import { PolicyInfo } from '../../../../../models/policy.interface'; import { Subscription } from 'rxjs'; import { Item } from '../../../../../shared/shared.module'; import { SnackbarService } from '../../../../../services/snackbar/snackbar.service'; +import { FormControl } from '@angular/forms'; +import { API_URL, EXPORT_POLICY } from '../../../../../config/api.config'; declare var bootstrap: any; @Component({ @@ -18,6 +20,7 @@ declare var bootstrap: any; export class ManageComponent implements OnInit, OnDestroy { private subscriptions: Subscription = new Subscription(); noResults: boolean = false; + export: FormControl = [][0]; policyStringArray: string[] = []; policyArray: Item[] = []; policyObjectArray: PolicyInfo[] = []; @@ -63,6 +66,13 @@ export class ManageComponent implements OnInit, OnDestroy { modal.show(); } + exportFunction(): void { + const userId = this.global.getUserInfo().id; + const format = this.export.value; + const route = `${API_URL}${EXPORT_POLICY}?userId=${userId}&format=%22${format}%22`; + this.global.export(route, "Políticas_de_Eficiencia_Energética", format); + } + /** * Deletes a policy from the system. * This function prompts the user for confirmation before deleting the selected policy. diff --git a/frontend/src/app/modules/user/components/manage/index/manage.component.css b/frontend/src/app/modules/user/components/manage/index/manage.component.css index c0b6f688..eaabc10a 100644 --- a/frontend/src/app/modules/user/components/manage/index/manage.component.css +++ b/frontend/src/app/modules/user/components/manage/index/manage.component.css @@ -2,9 +2,13 @@ padding: 1rem; } .form-buttons { + width: 100%; display: flex; - flex-direction: row; - width: 20%; - align-items: center; - align-content: left; + flex-wrap: wrap; + justify-content: right; + position: relative; + top: 3px; + left: 0; + margin-top: 5px; + gap: 8px; } diff --git a/frontend/src/app/modules/user/components/manage/index/manage.component.html b/frontend/src/app/modules/user/components/manage/index/manage.component.html index 4a7724e0..23bb8d8d 100644 --- a/frontend/src/app/modules/user/components/manage/index/manage.component.html +++ b/frontend/src/app/modules/user/components/manage/index/manage.component.html @@ -9,6 +9,10 @@ [icon]="'add'" > +
diff --git a/frontend/src/app/modules/user/components/manage/index/manage.component.ts b/frontend/src/app/modules/user/components/manage/index/manage.component.ts index ef4c894d..b428215c 100644 --- a/frontend/src/app/modules/user/components/manage/index/manage.component.ts +++ b/frontend/src/app/modules/user/components/manage/index/manage.component.ts @@ -6,6 +6,8 @@ import { GlobalModule } from '../../../../global/global.module'; import { DataService } from '../../../../../services/data/data.service'; import { SnackbarService } from '../../../../../services/snackbar/snackbar.service'; import { UserLogged } from '../../../../../models/credential.interface'; +import { FormControl } from '@angular/forms'; +import { API_URL, EXPORT_USER } from '../../../../../config/api.config'; declare var bootstrap: any; @@ -16,6 +18,7 @@ declare var bootstrap: any; }) export class ManageComponent implements OnInit { noResults: boolean = false; + export: FormControl = [][0] dataSource: MatTableDataSource = new MatTableDataSource([0]); displayedColumns: ConfigColumn[] = [ { @@ -62,6 +65,13 @@ export class ManageComponent implements OnInit { modal.show(); } + exportFunction(): void { + const userId = this.global.getUserInfo().id; + const format = this.export.value; + const route = `${API_URL}${EXPORT_USER}?userId=${userId}&format=%22${format}%22`; + this.global.export(route, "Usuarios", format); + } + /** * Initiates the deletion process for a user. * Opens a dialog to confirm the deletion, and if confirmed, opens another dialog to notify the user of the deletion. diff --git a/frontend/src/app/modules/workCenter/components/alert/index/alert.component.html b/frontend/src/app/modules/workCenter/components/alert/index/alert.component.html index 84f30578..a2eb0d9f 100644 --- a/frontend/src/app/modules/workCenter/components/alert/index/alert.component.html +++ b/frontend/src/app/modules/workCenter/components/alert/index/alert.component.html @@ -16,7 +16,11 @@ > - +
diff --git a/frontend/src/app/modules/workCenter/components/alert/index/alert.component.ts b/frontend/src/app/modules/workCenter/components/alert/index/alert.component.ts index bbc0cf1b..b4f7ffee 100644 --- a/frontend/src/app/modules/workCenter/components/alert/index/alert.component.ts +++ b/frontend/src/app/modules/workCenter/components/alert/index/alert.component.ts @@ -4,6 +4,7 @@ import { ConfigColumn } from '../../../../../shared/components/table/table.compo import { GlobalModule } from '../../../../global/global.module'; import { FormBuilder, FormControl, FormGroup } from '@angular/forms'; import { Item } from '../../../../../shared/shared.module'; +import { API_URL, EXPORT_ALERT } from '../../../../../config/api.config'; @Component({ selector: 'app-alert', @@ -14,6 +15,7 @@ export class AlertComponent implements OnInit { form: FormGroup; showTable: boolean = false; noResults: boolean = false; + export: FormControl = [][0]; dataSource: MatTableDataSource = new MatTableDataSource(); displayedColumns: ConfigColumn[] = [ { @@ -81,6 +83,14 @@ export class AlertComponent implements OnInit { } } + exportFunction(): void { + const userId = this.global.getUserInfo().id; + const centerId = this.global.getControlValue(this.form, 'workCenter').id; + const format = this.export.value; + const route = `${API_URL}${EXPORT_ALERT}?companyId=${centerId}&userId=${userId}&format=%22${format}%22`; + this.global.export(route, "Registros_de_consumo", format); + } + /** * Fetches alerts for the specified center ID and updates the data source for the table. * @param centerID The ID of the center for which to fetch alerts. diff --git a/frontend/src/app/modules/workCenter/components/avg-consumption/index/avg-consumption.component.html b/frontend/src/app/modules/workCenter/components/avg-consumption/index/avg-consumption.component.html index 6bb213f1..4a33bb50 100644 --- a/frontend/src/app/modules/workCenter/components/avg-consumption/index/avg-consumption.component.html +++ b/frontend/src/app/modules/workCenter/components/avg-consumption/index/avg-consumption.component.html @@ -17,7 +17,11 @@ [label]="'Predecir'" [function]="onPredictionClick.bind(this)"> - +
diff --git a/frontend/src/app/modules/workCenter/components/avg-consumption/index/avg-consumption.component.ts b/frontend/src/app/modules/workCenter/components/avg-consumption/index/avg-consumption.component.ts index 9d1e6235..d39fa7b6 100644 --- a/frontend/src/app/modules/workCenter/components/avg-consumption/index/avg-consumption.component.ts +++ b/frontend/src/app/modules/workCenter/components/avg-consumption/index/avg-consumption.component.ts @@ -3,9 +3,10 @@ import { ConfigColumn } from '../../../../../shared/components/table/table.compo import { MatTableDataSource } from '@angular/material/table'; import { animate, state, style, transition, trigger } from '@angular/animations'; import { GlobalModule } from '../../../../global/global.module'; -import { FormBuilder, FormGroup } from '@angular/forms'; +import { FormBuilder, FormControl, FormGroup } from '@angular/forms'; import { Item } from '../../../../../shared/shared.module'; import { Chart } from 'chart.js/auto'; +import { API_URL, EXPORT_AVG, EXPORT_PREDICTION } from '../../../../../config/api.config'; @Component({ selector: 'app-avg-consumption', @@ -28,6 +29,7 @@ export class AvgConsumptionComponent implements OnInit { expandedElements: string[] = []; showConsultTable: boolean = false; showPredictTable: boolean = false; + export: FormControl = [][0]; /** * Maps month numbers to their Spanish names. @@ -114,6 +116,29 @@ export class AvgConsumptionComponent implements OnInit { } } + exportFunction(): void { + let route = `${API_URL}`; + const userId = this.global.getUserInfo().id; + this.findCenterIds(); + let centers = ""; + this.selectedOptionsIds.forEach(id => { + centers += `companyIds=${id}&` + }); + const format = this.export.value; + + if (this.showConsultTable) { + route += `${EXPORT_AVG}?userId=3&${centers}format=%22${format}%22`; + this.global.export(route, "Consumo_promedio", format); + } else if (this.showPredictTable) { + centers = ""; + this.selectedOptionsIds.forEach(id => { + centers += `companiesIds=${id}&` + }); + route += `${EXPORT_PREDICTION}?userId=${userId}&${centers}format=%22${format}%22`; + this.global.export(route, "Predicción_de_Consumo_Trimestre", format); + } + } + /** * Finds the IDs of the selected work centers */ diff --git a/frontend/src/app/modules/workCenter/components/excess/index/excess.component.html b/frontend/src/app/modules/workCenter/components/excess/index/excess.component.html index c9fd06ef..d232df80 100644 --- a/frontend/src/app/modules/workCenter/components/excess/index/excess.component.html +++ b/frontend/src/app/modules/workCenter/components/excess/index/excess.component.html @@ -19,7 +19,11 @@ [function]="onConsultClick.bind(this)" > - +
diff --git a/frontend/src/app/modules/workCenter/components/excess/index/excess.component.ts b/frontend/src/app/modules/workCenter/components/excess/index/excess.component.ts index e3e3e375..8f423ac4 100644 --- a/frontend/src/app/modules/workCenter/components/excess/index/excess.component.ts +++ b/frontend/src/app/modules/workCenter/components/excess/index/excess.component.ts @@ -7,7 +7,7 @@ import {default as _rollupMoment, Moment} from 'moment'; import { MatTableDataSource } from '@angular/material/table'; import { ConfigColumn } from '../../../../../shared/components/table/table.component'; import { GlobalModule } from '../../../../global/global.module'; -import { MY_FORMATS } from '../../../../../config/api.config'; +import { API_URL, EXPORT_EXCESS, MY_FORMATS } from '../../../../../config/api.config'; const moment = _rollupMoment || _moment; @@ -27,6 +27,7 @@ export class ExcessComponent { readonly date = new FormControl(this.dateInitialize); showTable: boolean = false; noResults: boolean = false; + export: FormControl = [][0]; dataSource: MatTableDataSource = new MatTableDataSource(); displayedColumns: ConfigColumn[] = [ { @@ -109,6 +110,15 @@ export class ExcessComponent { } } + exportFunction(): void { + const userId = this.global.getUserInfo().id; + const month = this.monthMapper.get(this.global.getControlValue(this.form, 'month')); + const year = this.global.getControlValue(this.form, 'year'); + const format = this.export.value; + const route = `${API_URL}${EXPORT_EXCESS}?userId=${userId}&date=%22${month}%20${year}%22&format=%22${format}%22`; + this.global.export(route, "Exceso_de_Cosumo", format); + } + /** * Opens the datepicker and hides the table. * @param datepicker The datepicker instance to open. diff --git a/frontend/src/app/modules/workCenter/components/manage/index/manage.component.css b/frontend/src/app/modules/workCenter/components/manage/index/manage.component.css index c0b6f688..eaabc10a 100644 --- a/frontend/src/app/modules/workCenter/components/manage/index/manage.component.css +++ b/frontend/src/app/modules/workCenter/components/manage/index/manage.component.css @@ -2,9 +2,13 @@ padding: 1rem; } .form-buttons { + width: 100%; display: flex; - flex-direction: row; - width: 20%; - align-items: center; - align-content: left; + flex-wrap: wrap; + justify-content: right; + position: relative; + top: 3px; + left: 0; + margin-top: 5px; + gap: 8px; } diff --git a/frontend/src/app/modules/workCenter/components/manage/index/manage.component.html b/frontend/src/app/modules/workCenter/components/manage/index/manage.component.html index ebc52131..8ab6a625 100644 --- a/frontend/src/app/modules/workCenter/components/manage/index/manage.component.html +++ b/frontend/src/app/modules/workCenter/components/manage/index/manage.component.html @@ -16,6 +16,10 @@ [icon]="'edit'" > +
diff --git a/frontend/src/app/modules/workCenter/components/manage/index/manage.component.ts b/frontend/src/app/modules/workCenter/components/manage/index/manage.component.ts index 45869489..1ea21501 100644 --- a/frontend/src/app/modules/workCenter/components/manage/index/manage.component.ts +++ b/frontend/src/app/modules/workCenter/components/manage/index/manage.component.ts @@ -8,6 +8,8 @@ import { CenterDetails } from '../../../../../models/workCenter.interface'; import { Subscription } from 'rxjs'; import { UserLogged } from '../../../../../models/credential.interface'; import { UserService } from '../../../../../services/user/user.service'; +import { FormControl } from '@angular/forms'; +import { API_URL, EXPORT_CENTER } from '../../../../../config/api.config'; declare var bootstrap: any; @@ -20,6 +22,7 @@ export class ManageComponent implements OnInit, OnDestroy { private subscriptions: Subscription = new Subscription(); centerObjectArray: CenterDetails[] = []; noResults: boolean = false; + export: FormControl = [][0]; dataSource: MatTableDataSource = new MatTableDataSource(); displayedColumns: ConfigColumn[] = [ { @@ -93,6 +96,13 @@ export class ManageComponent implements OnInit, OnDestroy { modal.show(); } + exportFunction(): void { + const userId = this.global.getUserInfo().id; + const format = this.export.value; + const route = `${API_URL}${EXPORT_CENTER}?userId=${userId}&format=%22${format}%22`; + this.global.export(route, "Centros_de_Trabajo", format); + } + /** * Deletes a work center and its associated data. * diff --git a/frontend/src/app/modules/workCenter/components/register/index/register.component.html b/frontend/src/app/modules/workCenter/components/register/index/register.component.html index aba9a3be..f40b4756 100644 --- a/frontend/src/app/modules/workCenter/components/register/index/register.component.html +++ b/frontend/src/app/modules/workCenter/components/register/index/register.component.html @@ -35,6 +35,7 @@
diff --git a/frontend/src/app/modules/workCenter/components/register/index/register.component.ts b/frontend/src/app/modules/workCenter/components/register/index/register.component.ts index dd46fef1..f8e35cff 100644 --- a/frontend/src/app/modules/workCenter/components/register/index/register.component.ts +++ b/frontend/src/app/modules/workCenter/components/register/index/register.component.ts @@ -9,6 +9,7 @@ import { SnackbarService } from '../../../../../services/snackbar/snackbar.servi import { Register, RegisterByDay, TotalConsumptionData } from '../../../../../models/register.interface'; import { Subscription } from 'rxjs'; import { RegisterService } from '../../../../../services/register/register.service'; +import { API_URL, EXPORT_REGISTER } from '../../../../../config/api.config'; declare var bootstrap: any; @@ -92,7 +93,16 @@ export class RegisterComponent implements OnInit, OnDestroy { } exportFunction(): void { - console.log(this.export.value.name); + const userId = this.global.getUserInfo().id; + const centerId = this.global.getControlValue(this.form, 'workCenter').id; + const initDate = this.global.getControlValue(this.form, 'startDate'); + const endDate = this.global.getControlValue(this.form, 'endDate'); + const dateParams = `start=%22${initDate}%22&end=%22${endDate}%22`; + const userCenterParam = `userId=${userId}&companyId=${centerId}`; + const format = this.export.value; + + const route = `${API_URL}${EXPORT_REGISTER}?${userCenterParam}&${dateParams}&format=%22${format}%22`; + this.global.export(route, "Registros_de_consumo", format); } /** diff --git a/frontend/src/app/services/export/export.service.spec.ts b/frontend/src/app/services/export/export.service.spec.ts new file mode 100644 index 00000000..9cd0ee20 --- /dev/null +++ b/frontend/src/app/services/export/export.service.spec.ts @@ -0,0 +1,16 @@ +import { TestBed } from '@angular/core/testing'; + +import { ExportService } from './export.service'; + +describe('ExportService', () => { + let service: ExportService; + + beforeEach(() => { + TestBed.configureTestingModule({}); + service = TestBed.inject(ExportService); + }); + + it('should be created', () => { + expect(service).toBeTruthy(); + }); +}); diff --git a/frontend/src/app/services/export/export.service.ts b/frontend/src/app/services/export/export.service.ts new file mode 100644 index 00000000..7380fb01 --- /dev/null +++ b/frontend/src/app/services/export/export.service.ts @@ -0,0 +1,19 @@ +import { Injectable } from '@angular/core'; +import { HttpClient } from '@angular/common/http'; +import { Observable } from 'rxjs'; +import { MENU_OPTIONS_URL } from '../../config/api.config'; + +@Injectable({ + providedIn: 'root' +}) +export class ExportService { + constructor(private http: HttpClient) { } + + /** + * gets the pdf to download. + * @returns A string with de pdf encoded. + */ + getDocument(route: string): Observable { + return this.http.get(route); + } +} diff --git a/frontend/src/app/shared/components/button/button.component.ts b/frontend/src/app/shared/components/button/button.component.ts index a3f3a1e2..0ff408a8 100644 --- a/frontend/src/app/shared/components/button/button.component.ts +++ b/frontend/src/app/shared/components/button/button.component.ts @@ -20,15 +20,15 @@ export class ButtonComponent { @Input() options: Item[] = [ { id: 1, - name: ".pdf" + name: "pdf" }, { id: 2, - name: ".docx" + name: "docx" }, { id: 3, - name: ".csv" + name: "csv" } ];