| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- import {
- Component,
- OnInit,
- Input,
- ViewChild,
- ComponentFactoryResolver
- } from "@angular/core";
- import { Router } from "@angular/router";
- import { FormInvestmentProposalService } from "@app/services/form-investment-proposal.service";
- import { Instrument } from "@app/models/instrument";
- import { InvestmentProposalWorkflowService } from "@app/services/investment-proposal-workflow.service";
- import { InstrumentDirective } from "../instrument/instrument.directive";
- import { InstrumentComponent } from "../instrument/instrument.component";
- import { InvestmentProposalForm } from "@app/models/investment-proposal-form";
- @Component({
- selector: "mt-wizard-work",
- templateUrl: "./work.component.html"
- /*template: `
- <div>
- <h2>TEST</h2>
-
- </div>
- `*/
- })
- export class WorkComponent implements OnInit {
- title = "Formulario propuesta de inversión";
- workType: string;
- form: any;
- @Input() ads: Instrument[];
- currentAdIndex = -1;
- @ViewChild(InstrumentDirective, { static: true })
- adHost: InstrumentDirective;
- interval: any;
- @Input() formData: InvestmentProposalForm;
- indexDynamicComponent: number;
- constructor(
- private router: Router,
- private formDataService: FormInvestmentProposalService,
- private componentFactoryResolver: ComponentFactoryResolver,
- private instrumentService: InvestmentProposalWorkflowService
- ) {}
- ngOnInit() {
- this.formData = this.formDataService.getFormData();
- console.log("form data:");
- console.log(this.formData);
- this.ads = this.instrumentService.getInstruments();
- this.formData = this.formDataService.getFormData();
- this.formData.instrumentos;
- console.log("instrumentos: ");
- console.log(this.formData.instrumentos);
- this.indexDynamicComponent = this.ads.findIndex(
- x => x.component.name == this.formData.instrumentos
- );
- console.log(this.indexDynamicComponent);
- if (this.indexDynamicComponent >= 0) {
- this.loadComponent();
- } else {
- console.log("No existe el componente");
- }
- //this.workType = this.formDataService.getWork();
- }
- loadComponent() {
- this.currentAdIndex = this.indexDynamicComponent % this.ads.length;
- const adItem = this.ads[this.currentAdIndex];
- const componentFactory = this.componentFactoryResolver.resolveComponentFactory(
- adItem.component
- );
- console.log(adItem.component);
- const viewContainerRef = this.adHost.viewContainerRef;
- viewContainerRef.clear();
- const componentRef = viewContainerRef.createComponent(componentFactory);
- (<InstrumentComponent>componentRef.instance).data = adItem.data;
- }
- save(form: any): boolean {
- if (!form.valid) {
- return false;
- }
- this.formDataService.setWork(this.workType);
- return true;
- }
- goToPrevious(form: any) {
- if (this.save(form)) {
- // Navigate to the personal page
- this.router.navigate(["/investment-proposals/general-info"]);
- }
- }
- goToNext(form: any) {
- if (this.save(form)) {
- // Navigate to the address page
- this.router.navigate(["/address"]);
- }
- }
- }
|