SHARE
TWEET

Untitled

a guest Aug 23rd, 2019 88 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { Component, OnInit } from '@angular/core';
  2. import { Forecast } from '../../forecast';
  3. import { ForecastService } from '../../forecast.service';
  4. import { DynamicScriptLoaderService } from '../../dynamic-script-loader-service.service';
  5. declare const $: any;
  6. @Component({
  7.   selector: 'app-blank',
  8.   templateUrl: './blank.component.html',
  9.   styleUrls: ['./blank.component.scss']
  10. })
  11. export class BlankComponent implements OnInit {
  12.   dados: any;
  13.   forecast: Forecast = new Forecast();
  14.   submitted = false;
  15.  
  16.   constructor(private forecastService: ForecastService, private dynamicScriptLoader: DynamicScriptLoaderService) { }
  17.  
  18.   ngOnInit() {
  19.     // this.startScript()
  20.   }
  21.  
  22.   async startScript(datas) {
  23.     await this.dynamicScriptLoader.load('dataTables.buttons','buttons.flash','jszip','pdfmake','vfs_fonts','pdfmake','buttons.html5','buttons.print').then( data => {
  24.       this.loadData(datas);
  25.       console.log(datas);
  26.     }).catch(error => console.log(error));
  27.   }
  28.  
  29.   private loadData(dats){
  30.     $('#tableExport').DataTable({
  31.       "aaData": dats,
  32.       dom: 'Bfrtip',
  33.       buttons: [
  34.         'copy', 'csv', 'excel', 'pdf', 'print'
  35.       ]
  36.     });
  37.     console.log(dats);
  38.   }
  39.  
  40.   // async startScript() {
  41.   //   await this.dynamicScriptLoader.load('dataTables.buttons','buttons.flash','jszip','pdfmake','vfs_fonts','pdfmake','buttons.html5','buttons.print').then( data => {
  42.   //     this.loadData();
  43.   //   }).catch(error => console.log(error));
  44.   // }
  45.   //
  46.   // private loadData(){
  47.   //   $('tableExport').DataTable({
  48.   //     "aaData": this.dados,
  49.   //       dom: 'Bfrtip',
  50.   //       buttons: [
  51.   //         'copy', 'csv', 'excel', 'pdf', 'print'
  52.   //       ]
  53.   //     });
  54.   //     console.log(this.dados)
  55.   // }
  56.  
  57.   newForecast(): void {
  58.     // this.submitted = false;
  59.     // this.forecast = new Forecast();
  60.   }
  61.  
  62.   save() {
  63.     this.forecastService.createForecast(this.forecast)
  64.       .subscribe(
  65.         data => {
  66.           this.dados = JSON.parse(data);
  67.           console.log(this.dados);
  68.           this.startScript(this.dados);
  69.           this.submitted = true;
  70.         },
  71.         error => console.log(error));
  72.     this.forecast = new Forecast();
  73.   }
  74.  
  75. //   save() {
  76. //   this.forecastService.createForecast(this.forecast)
  77. //     .subscribe(
  78. //       data => {
  79. //         //console.log(data);
  80. //         //this.dados = JSON.stringify(data);
  81. //         //this.dados = data.toString();
  82. //         this.dados = JSON.parse(data);
  83. //         console.log(this.dados.columns);
  84. //         // console.log(this.dados.data);
  85. //
  86. //         // this.loadData();
  87. //         this.submitted = true;
  88. //       },
  89. //       error => console.log(error)
  90. //       // checar se data é diferente de código de erro
  91. //       // chamar newjuanito usando o bang da tabela
  92. //       );
  93. //     this.forecast = new Forecast();
  94. // }
  95.  
  96.   onSubmit() {
  97.     this.save();
  98.   }
  99.  
  100. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top