setting-widget.component.ts 2.73 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 49 50
  // 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!
    this.loadData()
  }
Ooh-Ao committed
51

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

Ooh-Ao committed
63
}