Commit 45579dc3 by Ooh-Ao

app api

parent 6c305bb6
...@@ -2,11 +2,12 @@ import { Component } from '@angular/core'; ...@@ -2,11 +2,12 @@ import { Component } from '@angular/core';
import { RouterOutlet } from '@angular/router'; import { RouterOutlet } from '@angular/router';
import { NgxEchartsDirective, provideEcharts } from 'ngx-echarts'; import { NgxEchartsDirective, provideEcharts } from 'ngx-echarts';
import { ConsultancyComponent } from './components'; import { ConsultancyComponent } from './components';
import { HttpClient, HttpClientModule } from '@angular/common/http';
@Component({ @Component({
selector: 'app-root', selector: 'app-root',
standalone: true, standalone: true,
imports: [RouterOutlet, NgxEchartsDirective], imports: [RouterOutlet, NgxEchartsDirective, HttpClientModule],
templateUrl: './app.component.html', templateUrl: './app.component.html',
styleUrl: './app.component.scss', styleUrl: './app.component.scss',
providers: [ providers: [
......
import { Component } from "@angular/core"; import { Component, EventEmitter, OnInit, Output, SimpleChanges } from "@angular/core";
import { EChartsOption } from 'echarts'; import { EChartsOption } from 'echarts';
import { NgxEchartsModule } from 'ngx-echarts'; import { NgxEchartsModule } from 'ngx-echarts';
import * as echarts from 'echarts'; import * as echarts from 'echarts';
import { HttpClient, HttpClientModule, HttpHeaders } from "@angular/common/http";
export interface Service { export interface Service {
id: number; id: number;
title: string; title: string;
description: string; description: string;
dataModel : any; dataModel: any;
dataSoure : any; dataSoure: any;
api: string;
} }
export enum ServiceTypes { export enum ServiceTypes {
consultancy, // 0 consultancy, // 0
trainings, // 1 trainings, // 1
engineering, // 2 engineering, // 2
statistic, //3
} }
@Component({ @Component({
...@@ -23,12 +26,11 @@ export enum ServiceTypes { ...@@ -23,12 +26,11 @@ export enum ServiceTypes {
imports: [NgxEchartsModule], imports: [NgxEchartsModule],
template: ` template: `
<div>{{model}}</div> <div>{{model}}</div>
<div echarts [options]="chartOption" class="demo-chart"></div> <div echarts [options]="model" class="demo-chart"></div>
`, `,
}) })
export class ConsultancyComponent { export class ConsultancyComponent {
model: any model: any = {
chartOption: EChartsOption = {
xAxis: { xAxis: {
type: 'category', type: 'category',
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'], data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
...@@ -50,12 +52,11 @@ export class ConsultancyComponent { ...@@ -50,12 +52,11 @@ export class ConsultancyComponent {
standalone: true, standalone: true,
imports: [NgxEchartsModule], imports: [NgxEchartsModule],
template: ` template: `
<div echarts [options]="chartOption" class="demo-chart"></div> <div echarts [options]="model" class="demo-chart"></div>
`, `,
}) })
export class SoftwareEngineeringComponent { export class SoftwareEngineeringComponent {
model: any model: any = {
chartOption: EChartsOption = {
legend: {}, legend: {},
tooltip: {}, tooltip: {},
dataset: { dataset: {
...@@ -84,12 +85,11 @@ export class SoftwareEngineeringComponent { ...@@ -84,12 +85,11 @@ export class SoftwareEngineeringComponent {
imports: [NgxEchartsModule], imports: [NgxEchartsModule],
template: ` template: `
<div>{{model}}</div> <div>{{model}}</div>
<div echarts [options]="chartOption" class="demo-chart"></div> <div echarts [options]="model" class="demo-chart"></div>
`, `,
}) })
export class TrainingsComponent { export class TrainingsComponent {
model: any model: any = {
chartOption: EChartsOption = {
legend: {}, legend: {},
tooltip: {}, tooltip: {},
dataset: { dataset: {
...@@ -140,3 +140,42 @@ export class TrainingsComponent { ...@@ -140,3 +140,42 @@ export class TrainingsComponent {
} }
@Component({
selector: 'statistic',
standalone: true,
imports: [NgxEchartsModule],
template: `
<div echarts [options]="model" class="demo-chart"></div>
`,
})
export class StatisticComponent {
model: any = {
legend: {},
tooltip: {},
dataset: {
dimensions: ['product', '2015', '2016', '2017'],
source: [
{ product: 'Matcha Latte', '2015': 43.3, '2016': 85.8, '2017': 93.7 },
{ product: 'Milk Tea', '2015': 83.1, '2016': 73.4, '2017': 55.1 },
{ product: 'Cheese Cocoa', '2015': 86.4, '2016': 65.2, '2017': 82.5 },
{ product: 'Walnut Brownie', '2015': 72.4, '2016': 53.9, '2017': 39.1 }
]
},
xAxis: { type: 'category' },
yAxis: {},
// Declare several bar series, each will be mapped
// to a column of dataset.source by default.
series: [{ type: 'bar' }, { type: 'bar' }, { type: 'bar' }]
};
constructor(private http: HttpClient) {
}
ngOnInit(): void {
}
}
...@@ -2,13 +2,14 @@ import { ...@@ -2,13 +2,14 @@ import {
ConsultancyComponent, ConsultancyComponent,
ServiceTypes, ServiceTypes,
SoftwareEngineeringComponent, SoftwareEngineeringComponent,
StatisticComponent,
TrainingsComponent, TrainingsComponent,
} from './components'; } from './components';
import { Type } from '@angular/core'; import { Type } from '@angular/core';
export type ServiceComponentType = ConsultancyComponent export type ServiceComponentType = ConsultancyComponent
| TrainingsComponent | TrainingsComponent
| SoftwareEngineeringComponent; | SoftwareEngineeringComponent | StatisticComponent;
export const servicesComponentFactory: export const servicesComponentFactory:
Record<ServiceTypes, Type<ServiceComponentType>> Record<ServiceTypes, Type<ServiceComponentType>>
...@@ -16,4 +17,6 @@ export const servicesComponentFactory: ...@@ -16,4 +17,6 @@ export const servicesComponentFactory:
[ServiceTypes.consultancy]: ConsultancyComponent, [ServiceTypes.consultancy]: ConsultancyComponent,
[ServiceTypes.trainings]: TrainingsComponent, [ServiceTypes.trainings]: TrainingsComponent,
[ServiceTypes.engineering]: SoftwareEngineeringComponent, [ServiceTypes.engineering]: SoftwareEngineeringComponent,
[ServiceTypes.statistic]: StatisticComponent,
}; };
...@@ -4,42 +4,55 @@ import { Observable, Subject, from, mergeMap, of, switchMap, takeUntil, tap } fr ...@@ -4,42 +4,55 @@ import { Observable, Subject, from, mergeMap, of, switchMap, takeUntil, tap } fr
import { ComponentHostDirective } from '../directives/component-host.directive'; import { ComponentHostDirective } from '../directives/component-host.directive';
import { ServiceComponentType, servicesComponentFactory } from '../services-factory'; import { ServiceComponentType, servicesComponentFactory } from '../services-factory';
import { Service, ServiceTypes } from '../components'; import { Service, ServiceTypes } from '../components';
import { HttpClient, HttpClientModule, HttpHeaders } from '@angular/common/http';
@Component({ @Component({
selector: 'app-services', selector: 'app-services',
standalone: true, standalone: true,
imports: [ComponentHostDirective], imports: [ComponentHostDirective, HttpClientModule],
templateUrl: './services.component.html', templateUrl: './services.component.html',
styleUrls: ['./services.component.scss'], styleUrls: ['./services.component.scss'],
}) })
export class ServicesComponent implements OnInit { export class ServicesComponent implements OnInit {
@Input() id?: number; @Input() id?: number;
@Output() valueChange: EventEmitter<Service> = new EventEmitter<Service>(); @Output() valueChange: EventEmitter<Service> = new EventEmitter<Service>();
componentList: Service[] = [{ componentList: Service[] = [{
id: 0, id: 0,
title: "11111", title: "11111",
description: "111", description: "111",
dataModel: "ss", dataModel: "ss",
dataSoure: "sss" dataSoure: "sss",
api: ""
}, },
{ {
id: 1, id: 1,
title: "222", title: "222",
description: "222", description: "222",
dataModel: "ss", dataModel: "ss",
dataSoure: "sss" dataSoure: "sss",
api: ""
}, },
{ {
id: 2, id: 2,
title: "3333", title: "3333",
description: "33333", description: "33333",
dataModel: "ss", dataModel: "ss",
dataSoure: "sss" dataSoure: "sss",
api: ""
},
{
id: 3,
title: "4444",
description: "4444",
dataModel: "4444",
dataSoure: "4444",
api: "https://hrplus.myhr.co.th/hr/taapi/leave/statistic?yearId=2024"
}] }]
@ViewChild(ComponentHostDirective, { static: true }) componentHost!: ComponentHostDirective; @ViewChild(ComponentHostDirective, { static: true }) componentHost!: ComponentHostDirective;
constructor(private readonly route: ActivatedRoute) { } constructor(private readonly route: ActivatedRoute, private http: HttpClient) { }
destroy: Subject<void> = new Subject<void>(); destroy: Subject<void> = new Subject<void>();
...@@ -84,8 +97,24 @@ export class ServicesComponent implements OnInit { ...@@ -84,8 +97,24 @@ export class ServicesComponent implements OnInit {
const { instance } = viewContainerRef.createComponent<ServiceComponentType>( const { instance } = viewContainerRef.createComponent<ServiceComponentType>(
servicesComponentFactory[service.id as ServiceTypes] servicesComponentFactory[service.id as ServiceTypes]
); );
instance.model = service.dataModel; if (service.api!="") {
this.valueChange.emit(service); const options = {
headers: new HttpHeaders({
"Authorization": "Bearer eyJhbGciOiJIUzI1NiJ9.eyJzY2hlbWEiOiJkYm8iLCJlbmNvZGUiOiIyIiwic3ViIjoiQXV0aCIsImNvbXBhbnlOYW1lIjoi4Lia4Lij4Li04Lip4Lix4LiXIOC4oeC4suC4ouC5gOC4reC4iuC4reC4suC4o-C5jCDguIjguLPguIHguLHguJQiLCJkYk5hbWUiOiJIUlBsdXMiLCJyb2xlcyI6WyJVU0VSIl0sIndvcmthcmVhIjoiTk9ORSIsImlzcyI6IkNvbXB1dGVyIFNjaWVuY2UgQ29ycG9yYXRpb24gTGltaXRlZCIsInptbG9naW4iOiJmYWxzZSIsInJvbGVfbGV2ZWwiOiIiLCJlbXBsb3llZWlkIjoiMjAxODAyMTAiLCJicmFuY2giOiIxMDAiLCJlbXBfcG9zaXRpb24iOiJQLVJELTIyMDEiLCJ1c2VyX3JvbGUiOiIiLCJ1aWQiOiIyMDE4MDIxMCIsImNvbXBhbnlpZCI6IjEwMCIsImFjdG9yaWQiOiIyMDE4MDIxMCIsImxhbmciOiJ0aCIsImFkIjoiZmFsc2UiLCJmaXJzdGxvZ2luIjoiZmFsc2UiLCJ1cmxfbXlociI6Imh0dHA6Ly9ocnBsdXMubXloci5jby50aC9ociIsImFwcF9uYW1lIjoibXlociIsInJlZ2lvbmFsbHR5IjoiRU5HIiwidG9rZW5femVlbWUiOiIiLCJ1c2VyX2xldmVsIjoiRW1wLVVzZXIiLCJmdWxsbmFtZSI6IuC4meC4suC4ouC4iuC4meC4sOC4iuC4seC4oiAg4LmC4Lit4LiU4Lie4Li04Lih4Lie4LmMIiwiY29taWQiOiIiLCJqb2IiOiJKLVJELTIyMDEiLCJ1c2VyIjoiQ2hhbmFjaGFpLm8iLCJ6bV91c2VyIjoiIiwidXNlcm5hbWUiOiJjaGFuYWNoYWkubyIsIm1lbWJlcmlkIjoiIn0.5BgyoT-lLs9qFDj3iIizzYNeA0vWd9nTU8QHpzxMF7A",
}),
};
this.http.get(service.api, options).subscribe(result => {
service.dataModel = result
this.valueChange.emit(service);
})
} else {
service.dataModel = instance.model
this.valueChange.emit(service);
}
// instance.model = service.dataModel;
} }
......
<div id="loginform" style="background-color: gray;"> <div id="loginform" style="background-color: gray;">
<div class="position-relative overflow-hidden radial-gradient min-vh-100 w-100"> <div class="position-relative overflow-hidden radial-gradient min-vh-100 w-100">
<div class="position-relative z-index-5" style="z-index: 5 !important;"> <div class="position-relative z-index-5" style="z-index: 5 !important;">
<div class="row justify-content-center align-items-center "> <div class="row p-4">
<div class="col-xl-7 col-xxl-8"> <div class="col-xl-7 col-xxl-8">
<div class="card"> <div class="card">
<app-services [id]="widjetId" (valueChange)="onValueChange($event)"></app-services> <app-services [id]="widjetId" (valueChange)="onValueChange($event)"></app-services>
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
Please enter a Username Please enter a Username
</div> </div>
</div> </div>
<div class="alert alert-danger" style="word-break: break-all;">{{model?.dataModel}}</div> <div class="alert alert-danger" style="word-break: break-all;">{{model | json}}</div>
<button type="submit" class="btn btn-primary w-100 py-8 mb-4 rounded-2">Save</button> <button type="submit" class="btn btn-primary w-100 py-8 mb-4 rounded-2">Save</button>
<button type="submit" class="btn btn-success w-100 py-8 mb-4 rounded-2">Preview</button> <button type="submit" class="btn btn-success w-100 py-8 mb-4 rounded-2">Preview</button>
</form> </form>
......
...@@ -11,9 +11,10 @@ import { Service } from '../components'; ...@@ -11,9 +11,10 @@ import { Service } from '../components';
styleUrls: ['./setting-widget.component.css'] styleUrls: ['./setting-widget.component.css']
}) })
export class SettingWidgetComponent implements OnInit { export class SettingWidgetComponent implements OnInit {
model?: Service widgetModel?: Service
widjetId = 0 widjetId = 0
dataSoure: string = ""; dataSoure: string = "";
model : string = "";
constructor() { } constructor() { }
ngOnInit() { ngOnInit() {
...@@ -21,8 +22,9 @@ export class SettingWidgetComponent implements OnInit { ...@@ -21,8 +22,9 @@ export class SettingWidgetComponent implements OnInit {
onValueChange(value: Service) { onValueChange(value: Service) {
console.log("value",value) console.log("value",value)
this.model = value this.widgetModel = value
this.dataSoure = this.model.dataSoure this.dataSoure = value.api
this.model = value.dataModel
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment