Newer
Older
import { Component, OnInit, AfterViewInit, QueryList, ViewChildren } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { TranslateService } from '@ngx-translate/core';
import { DashboardService } from './dashboard.service';
import { FunctionsService } from '@service/functions.service';
@Component({
selector: 'app-dashboard',
templateUrl: 'dashboard.component.html',
styleUrls: ['dashboard.component.scss'],
providers: [DashboardService]
})
export class DashboardComponent implements OnInit, AfterViewInit {
tiles: any = [];
hoveredTool: boolean = false;
@ViewChildren('tileComponent') tileComponent: QueryList<any>;
constructor(
public translate: TranslateService,
public http: HttpClient,
private dashboardService: DashboardService,
private functionsService: FunctionsService
ngOnInit(): void {
this.getDashboardConfig();
}
ngAfterViewInit(): void { }
enterTile(tile: any, index: number) {
this.tiles.forEach((element: any, indexTile: number) => {
element.editMode = indexTile === index ? true : false;
});
}
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
leaveTile(tile: any) {
if (!this.hoveredTool) {
tile.editMode = false;
}
}
getDashboardConfig() {
const test: any = [
{
id: 1,
type: 'lastViewMails',
view: 'resume',
sequence: 0
},
{
id: 1,
type: 'lastViewMails',
view: 'list',
sequence: 3
},
{
id: 1,
type: 'lastViewMails',
view: 'chart',
sequence: 5
}
];
for (let index = 0; index < 6; index++) {
const tmpTile = test.find((tile: any) => tile.sequence === index);
if (!this.functionsService.empty(tmpTile)) {
const objTile = {...this.dashboardService.getTile(tmpTile.type), ...tmpTile};
this.tiles.push(objTile);
} else {
this.tiles.push({
id: null,
sequence: index,
editMode: false
});
}
}
}
changeView(tile: any, view: string) {
const indexTile = this.tiles.filter((tileItem: any) => tileItem.id !== null).map((tileItem: any) => tileItem.sequence).indexOf(tile.sequence);
this.tileComponent.toArray()[indexTile].changeView(view);
}
transferDataSuccess() {
this.tiles.forEach((tile: any, index: number) => {
tile.sequence = index;
});
// TO DO : SAVE IN BACK
}