Commit 4b00232e authored by MAGHOUZ's avatar MAGHOUZ
Browse files

Adding tickets works (service using HttpClient + UI)

parent ef429b5b
......@@ -26,11 +26,7 @@ export class updateTicketsDialog {
addTickets() {
let tickets_to_add = this.tickets_to_add.split(",");
this.params.monitoreditemsService.addTicketsToMonitoredItem(
this.monitoredItem.id,tickets_to_add)
.subscribe(
() =>this.params.monitoreditemsService.searchMessages()
);
this.monitoredItem.id,tickets_to_add);
}
removeTickets() {
......
export class MonitoredItem {
id: number;
id: string;
type: string;
logicalPath: string;
logicalGroup: string;
......
import { Injectable } from '@angular/core';
import {HttpClient, HttpHeaders} from '@angular/common/http';
import {Observable, of} from 'rxjs';
import {Observable, of, Subject} from 'rxjs';
import {catchError, map} from 'rxjs/operators';
import {MonitoredItem} from './monitored_item.model';
import {Apollo, gql} from 'apollo-angular';
......@@ -11,11 +11,21 @@ import {Apollo, gql} from 'apollo-angular';
export class Monitored_itemsService {
private serverUrl = 'http://localhost/graphql'
// Observable string sources
private monitoredItemsSource = new Subject<MonitoredItem>();
// Observable string streams
monitoredItems$ = this.monitoredItemsSource.asObservable();
// Observable string sources
private updatedMonitoredItemsSource = new Subject<MonitoredItem>();
// Observable string streams
updatedMonitoredItems = this.updatedMonitoredItemsSource.asObservable();
constructor(private http: HttpClient, private apollo: Apollo) { }
searchMessages(type: string) {
console.log("searchMessages")
return this.apollo
console.log("searchMessages");
this.apollo
.watchQuery({
query: gql`
{
......@@ -34,7 +44,13 @@ export class Monitored_itemsService {
}
}`,
})
.valueChanges;
.valueChanges.subscribe((result: any) => {
console.log("after query",result?.data.allMonitoredItems)
for (var i = 0; i<this.result2MI(result?.data.allMonitoredItems).length; i++){
this.monitoredItemsSource.next(this.result2MI(result?.data.allMonitoredItems)[i])
}
})
;
}
/**
......@@ -93,7 +109,16 @@ export class Monitored_itemsService {
" {\n" +
" monitoredItem {\n" +
" id\n" +
" type\n" +
" logicalPath\n" +
" statusFk\n" +
" creationDate\n" +
" updateDate\n" +
" lastEventDate\n" +
" logicalGroup\n" +
" tickets\n" +
" labels\n" +
" data\n" +
" }\n" +
" }\n" +
"}"
......@@ -114,11 +139,28 @@ export class Monitored_itemsService {
withCredentials: true
};
//let json_query = JSON.parse(query)
return this.http.post(this.serverUrl, {"query":query}, requestOptions)
.pipe(
map(response => console.log(response)),
map(response => {
console.log(response)
// @ts-ignore
let mi = response.data.updateMonitoredItem.monitoredItem
let monitoredItem: MonitoredItem;
monitoredItem = new MonitoredItem(
mi.id,
mi.type,
mi.logicalPath,
mi.logicalGroup,
mi.statusFk,
mi.creationDate,
mi.updateDate,
mi.tickets,
);
this.updatedMonitoredItemsSource.next(monitoredItem)
}),
catchError(err => this.handleError('addTickets', err))
);
)
.subscribe();
}
}
......@@ -18,6 +18,7 @@
(firstDataRendered)="onFirstDataRendered($event)"
(gridReady)="onGridReady($event)"
[frameworkComponents]="frameworkComponents"
[getRowNodeId]="getRowNodeId"
></ag-grid-angular>
</div>
......
......@@ -6,6 +6,7 @@ import {MonitoredItem} from './monitored_item.model';
import {ActionsCellRenderer} from './actions-cell-renderer/actions-cell-renderer.component';
import {TicketsCellRenderer} from './tickets-cell-renderer/tickets-cell-renderer.component';
import {MatDialog} from '@angular/material/dialog';
import {Subscription} from 'rxjs/Subscription';
@Component({
selector: 'app-reports',
......@@ -117,10 +118,17 @@ export class Monitored_items_listComponent implements OnInit {
resizable: true
};
rowData: any;
rowData: MonitoredItem[] = [];
messageType = '1';
selectedRows: string[];
getRowNodeId = function(data) {
return data.id;
};
selectAllSubscription: Subscription;
updateOneSubscription: Subscription;
constructor(public monitoreditemsService: Monitored_itemsService,public dialog: MatDialog) {
this.monitored_itemsService = monitoreditemsService;
......@@ -129,8 +137,26 @@ export class Monitored_items_listComponent implements OnInit {
}
ngOnInit(): void {
this.getMessages();
this.actionsCellRenderer = new ActionsCellRenderer(this.dialog,this.monitored_itemsService);
this.selectAllSubscription = this.monitoreditemsService.monitoredItems$.subscribe(
monitored_item => {
this.agGrid.api.applyTransactionAsync({ add: [monitored_item] })
this.agGrid.api.refreshCells()
}
);
this.updateOneSubscription = this.monitoreditemsService.updatedMonitoredItems.subscribe(
monitored_item => {
var node = this.agGrid.api.getRowNode(monitored_item.id)
var data = node.data;
data.tickets = monitored_item.tickets;
data.updateDate = monitored_item.updateDate;
this.agGrid.api.applyTransactionAsync({ update: [data] })
this.agGrid.api.redrawRows({ rowNodes: [node] })
}
);
this.monitored_itemsService.searchMessages(this.messageType);
this.actionsCellRenderer = new ActionsCellRenderer(this.dialog, this.monitored_itemsService);
this.ticketsCellRenderer = new TicketsCellRenderer();
}
......@@ -156,14 +182,6 @@ export class Monitored_items_listComponent implements OnInit {
alert(`Selected nodes: ${this.selectedRows.join(', ')}`);
}
getMessages(): void {
this.monitored_itemsService.searchMessages(this.messageType).subscribe((result: any) => {
this.rowData = this.monitored_itemsService.result2MI(result?.data.allMonitoredItems);
});
console.log(this.rowData)
//.subscribe(messages => this.rowData = messages);
}
autoSizeAll(skipHeader) {
var allColumnIds = [];
this.gridColumnApi.getAllColumns().forEach(function (column) {
......@@ -175,4 +193,9 @@ export class Monitored_items_listComponent implements OnInit {
sizeToFit() {
this.gridApi.sizeColumnsToFit();
}
ngOnDestroy() {
this.selectAllSubscription.unsubscribe();
this.updateOneSubscription.unsubscribe();
}
}
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