setting-widget.component.ts 1.75 KB
Newer Older
Ooh-Ao committed
1 2
import { CommonModule } from '@angular/common';
import { Component, OnInit } from '@angular/core';
Ooh-Ao committed
3 4
import { ServicesComponent } from '../services/services.component';
import { FormsModule } from '@angular/forms';
Ooh-Ao committed
5
import { Service, WidjetService } from '../services/widjet.service';
Ooh-Ao committed
6
import { HttpClient, HttpHeaders } from '@angular/common/http';
Ooh-Ao committed
7 8 9
@Component({
  selector: 'app-setting-widget',
  standalone: true,
Ooh-Ao committed
10
  imports: [CommonModule, ServicesComponent, FormsModule],
Ooh-Ao committed
11 12 13 14
  templateUrl: './setting-widget.component.html',
  styleUrls: ['./setting-widget.component.css']
})
export class SettingWidgetComponent implements OnInit {
Ooh-Ao committed
15
  widgetModel: Service
Ooh-Ao committed
16
  widjetId = 0
Ooh-Ao committed
17
  api: string = "";
Ooh-Ao committed
18 19
  model: string = "";
  resp: string = ""
Ooh-Ao committed
20 21 22 23 24
  widgetList: Service[] = []
  constructor(private widjectService: WidjetService, private http: HttpClient) {
    this.widgetList = this.widjectService.widjetList
    this.widgetModel = this.widgetList[0]
  }
Ooh-Ao committed
25 26 27 28

  ngOnInit() {
  }

Ooh-Ao committed
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
  // onValueChange(value: Service) {
  //   console.log("value", value)
  //   if (value) {
  //     this.widgetModel = value
  //     this.api = value.api
  //     this.resp = value.api
  //     this.model = value.dataModel
  //   } else {
  //     this.widgetModel = undefined
  //     this.api = ""
  //     this.resp = ""
  //     this.model = ""
  //   }

  // }

  changeComponent() {
    console.log("changeComponent", this.widgetModel)
    this.widjetId = this.widgetModel?.id!
    this.api = this.widgetModel?.api!
Ooh-Ao committed
49
    // this.loadData()
Ooh-Ao committed
50
  }
Ooh-Ao committed
51

Ooh-Ao committed
52 53 54
  loadData() {
    const options = {
      headers: new HttpHeaders({
Ooh-Ao committed
55
        "Authorization": "Bearer " + sessionStorage.getItem("token"),
Ooh-Ao committed
56 57 58 59 60
      }),
    };
    this.http.get(this.widgetModel.api, options).subscribe(result => {
      this.widgetModel.dataSoure = result
    })
Ooh-Ao committed
61 62
  }

Ooh-Ao committed
63
}