|
|
@@ -1,10 +1,61 @@
|
|
|
-import { Component } from '@angular/core';
|
|
|
+import { Component, OnInit } from '@angular/core';
|
|
|
+import { ActivatedRoute } from '@angular/router';
|
|
|
+import { lastValueFrom } from 'rxjs';
|
|
|
+import { ControlPanelService } from 'src/app/services/control-panel.service';
|
|
|
+import { ResourcesService } from 'src/app/services/resources/resources.service';
|
|
|
|
|
|
@Component({
|
|
|
selector: 'app-control-panel-preview',
|
|
|
templateUrl: './control-panel-preview.component.html',
|
|
|
styleUrl: './control-panel-preview.component.css'
|
|
|
})
|
|
|
-export class ControlPanelPreviewComponent {
|
|
|
+export class ControlPanelPreviewComponent implements OnInit {
|
|
|
+ isLoading: boolean;
|
|
|
+ hasError: boolean;
|
|
|
+ errorStr: string;
|
|
|
|
|
|
+ constructor(
|
|
|
+ private _activatedRoute: ActivatedRoute,
|
|
|
+ private _resourcesService: ResourcesService,
|
|
|
+ private _controlPanelService: ControlPanelService,
|
|
|
+ ) {
|
|
|
+ this.isLoading = true;
|
|
|
+ this.hasError = false;
|
|
|
+ this.errorStr = '';
|
|
|
+ }
|
|
|
+
|
|
|
+ ngOnInit(): void {
|
|
|
+ this._activatedRoute.queryParams.subscribe(params => {
|
|
|
+ let data = params['data'];
|
|
|
+ if(data == undefined){
|
|
|
+ this._resourcesService.openSnackBar('No se envió información.');
|
|
|
+ this.goBack(1);
|
|
|
+ }else{
|
|
|
+ this.getPanel(data);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ goBack(steps: number){
|
|
|
+ window.history.go(steps * -1);
|
|
|
+ }
|
|
|
+
|
|
|
+ async getPanel(idPanel: string){
|
|
|
+ try{
|
|
|
+ let idUser = localStorage.getItem('idusuario')!;
|
|
|
+ let panel = await lastValueFrom(this._controlPanelService.getPanel(idPanel, idUser, 1));
|
|
|
+ console.log(panel);
|
|
|
+ }catch(error: any){
|
|
|
+ if(error.error == undefined){
|
|
|
+ this.errorStr = 'Ocurrió un error inesperado.';
|
|
|
+ }else if(error.error.msg == undefined){
|
|
|
+ this.errorStr = 'Ocurrió un error inesperado.';
|
|
|
+ }else{
|
|
|
+ this.errorStr = error.error.msg;
|
|
|
+ }
|
|
|
+
|
|
|
+ this.hasError = true;
|
|
|
+ this.isLoading = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|