| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- import { Component, OnInit } from '@angular/core';
- import { FormBuilder, FormGroup, Validators } from '@angular/forms';
- import { PlantsService } from '@app/services/plants.service';
- import { ActivatedRoute } from '@angular/router';
- import Swal from 'sweetalert2';
- @Component({
- selector: 'app-edit-plant',
- templateUrl: './edit-plant.component.html',
- styleUrls: ['./edit-plant.component.scss']
- })
- export class EditPlantComponent implements OnInit {
- title:string = "Editar planta";
- listPlant: any;
- organizationExists:boolean;
- assetForm: FormGroup;
- assetID:any;
- role_number: any;
- assetExists:boolean;
- distributor = ["EEO","CAESS","DELSUR","CLESA","DEUSEM","ABRUZZO","EDESAL","B&D","DEL SUR"];
- categoria_tarifaria = ["PD", "MD", "GD"];
- codigo_tarifa = ["R","G","AP","MD CMP - BT","MD CMP - MT","MD CMH - BT","MD CMH - MT","GD CMH - BT", "GD CMH - MT"];
- constructor(private plantsService: PlantsService, private formBuilder: FormBuilder, private route: ActivatedRoute) {
-
- this.route.params.subscribe(params => {
- this.assetID = params['id'];
- });
- this.plantsService.getAssetById(this.assetID).subscribe(res => {
- this.listPlant = res["data"]["asset"];
- this.organizationExists = true;
- this.assetForm = this.formBuilder.group({
- name: [this.listPlant.name],
- country: [this.listPlant.country],
- city: [this.listPlant.city],
- address: [this.listPlant.address],
- distribuidora: [this.listPlant.distribuidora],
- categoria_tarifaria: [this.listPlant.categoria_tarifaria],
- cod_tarifa: [this.listPlant.cod_tarifa],
- });
- this.assetExists = true;
- }, (err) => {
- Swal.fire({
- type: 'error',
- title: 'Error en el servidor',
- text: err.message
- });
- });
- }
- ngOnInit() {
-
- }
- get f() { return this.assetForm.controls; }
- editAsset() {
- this.plantsService.updatePlant(this.assetID,
- {
- name: this.f.name.value,
- country: this.f.country.value,
- city: this.f.city.value,
- address: this.f.address.value,
- distribuidora: this.f.distribuidora.value,
- categoria_tarifaria: this.f.categoria_tarifaria.value,
- cod_tarifa: this.f.cod_tarifa.value,
- meters_installed: this.listPlant.meters_installed
- }
- )
- .subscribe(success => {
- if (success) {
- Swal.fire({
- allowOutsideClick: false,
- type: 'success',
- text: 'Informacion actualizada con exito'
- });
- //window.location.href="#/dashboard";
- }
-
- });
- }
- }
|