Commit e04e7b6a authored by MAGHOUZ's avatar MAGHOUZ
Browse files

Adding tickets works (service using apollo + UI) and deleting tickets works using apollo

parent 4b00232e
<button
(click)="updateTicketsDialog()"
mat-raised-button type="button"
type="button"
mat-raised-button
class="btn btn-primary btn-link btn-sm btn-just-icon"
matTooltip="Remove tickets"
[matTooltipPosition]="'above'"
>
<i class="material-icons">edit</i>
Update tickets
<i class="material-icons">bug_report</i>
</button>
\ No newline at end of file
......@@ -25,12 +25,15 @@ export class updateTicketsDialog {
addTickets() {
let tickets_to_add = this.tickets_to_add.split(",");
//this.params.monitoreditemsService.addTicketsToMonitoredItem(
// this.monitoredItem.id,tickets_to_add);
this.params.monitoreditemsService.addTicketsToMonitoredItem(
this.monitoredItem.id,tickets_to_add);
}
removeTickets() {
alert(this.list_tickets)
this.params.monitoreditemsService.searchMessages();
let tickets_to_delete = this.list_tickets;
this.params.monitoreditemsService.deleteTicketsFromMonitoredItem(
this.monitoredItem.id,tickets_to_delete);
}
}
\ No newline at end of file
......@@ -21,12 +21,16 @@ export class Monitored_itemsService {
// Observable string streams
updatedMonitoredItems = this.updatedMonitoredItemsSource.asObservable();
// Observable string sources
private deletedMonitoredItemsSource = new Subject<MonitoredItem>();
// Observable string streams
deletedMonitoredItems = this.deletedMonitoredItemsSource.asObservable();
constructor(private http: HttpClient, private apollo: Apollo) { }
searchMessages(type: string) {
console.log("searchMessages");
this.apollo
.watchQuery({
.query({
query: gql`
{
allMonitoredItems {
......@@ -44,8 +48,7 @@ export class Monitored_itemsService {
}
}`,
})
.valueChanges.subscribe((result: any) => {
console.log("after query",result?.data.allMonitoredItems)
.subscribe((result: any) => {
for (var i = 0; i<this.result2MI(result?.data.allMonitoredItems).length; i++){
this.monitoredItemsSource.next(this.result2MI(result?.data.allMonitoredItems)[i])
}
......@@ -95,72 +98,102 @@ export class Monitored_itemsService {
return resultMonitoredItemsList;
}
addTicketsToMonitoredItem(monitoredItemId, tickets: string[]){
let formatted_tickets = ""
for(var i = 0;i<tickets.length;i++) {
formatted_tickets += "\""+tickets[i]+"\",";
}
const query = "mutation {\n" +
" updateMonitoredItem (\n" +
" id: \"" + monitoredItemId + "\", \n" +
" tickets: [" + formatted_tickets + "]\n" +
" ) \n" +
" {\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" +
"}"
//const url = this.serverUrl + "?query=mutation%20%7BupdateMonitoredItem(id%3A%22"+monitoredItemId+"%22%2Ctickets%3A%5B\""+encodeURIComponent(tickets.toString())+"\"%5D)%7BmonitoredItem%7Bid%7D%7D%7D%0A";
const requestOptions: Object = {
/* other options here */
responseType: "json",
headers: new HttpHeaders()
.set('Content-Type', 'application/json')
.append('Access-Control-Allow-Methods', 'POST')
.append('Access-Control-Allow-Origin', '*')
.append(
'Access-Control-Allow-Headers',
'Access-Control-Allow-Headers, Access-Control-Allow-Origin, Access-Control-Request-Method'
),
withCredentials: true
};
addTicketsToMonitoredItem(monitoredItemId, tickets: string[]) {
const ADD_TICKETS_TO_MONITORED_ITEM_POST = gql`
mutation updateMonitoredItem($id: String!, $tickets: [String!]) {
updateMonitoredItem (id: $id, tickets: $tickets)
{
monitoredItem {
id
type
logicalPath
statusFk
creationDate
updateDate
lastEventDate
logicalGroup
tickets
labels
data
}
}
}
`;
this.apollo.mutate({
mutation: ADD_TICKETS_TO_MONITORED_ITEM_POST,
variables: {
id: monitoredItemId,
tickets: tickets
}
}).subscribe(({ data }) => {
// @ts-ignore
let mi = 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)
},(error) => {
console.log('there was an error sending the query', error);
});
}
deleteTicketsFromMonitoredItem(monitoredItemId, tickets: string[]) {
const DELETE_TICKETS_FROM_MONITORED_ITEM_POST = gql`
mutation removeTicketsFromMonitoredItem($id: String!, $tickets: [String!]) {
removeTicketsFromMonitoredItem (id: $id, tickets: $tickets)
{
monitoredItem {
id
type
logicalPath
statusFk
creationDate
updateDate
lastEventDate
logicalGroup
tickets
labels
data
}
}
}
`;
this.apollo.mutate({
mutation: DELETE_TICKETS_FROM_MONITORED_ITEM_POST,
variables: {
id: monitoredItemId,
tickets: tickets
}
}).subscribe(({ data }) => {
// @ts-ignore
let mi = data.removeTicketsFromMonitoredItem.monitoredItem
let monitoredItem: MonitoredItem;
return this.http.post(this.serverUrl, {"query":query}, requestOptions)
.pipe(
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();
monitoredItem = new MonitoredItem(
mi.id,
mi.type,
mi.logicalPath,
mi.logicalGroup,
mi.statusFk,
mi.creationDate,
mi.updateDate,
mi.tickets,
);
this.deletedMonitoredItemsSource.next(monitoredItem)
},(error) => {
console.log('there was an error sending the query', error);
});
}
}
......@@ -128,6 +128,7 @@ export class Monitored_items_listComponent implements OnInit {
selectAllSubscription: Subscription;
updateOneSubscription: Subscription;
deleteTicketsSubscription: Subscription;
constructor(public monitoreditemsService: Monitored_itemsService,public dialog: MatDialog) {
......@@ -140,7 +141,6 @@ export class Monitored_items_listComponent implements OnInit {
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(
......@@ -155,6 +155,18 @@ export class Monitored_items_listComponent implements OnInit {
this.agGrid.api.redrawRows({ rowNodes: [node] })
}
);
this.deleteTicketsSubscription = this.monitoreditemsService.deletedMonitoredItems.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();
......
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