Commit ef429b5b authored by MAGHOUZ's avatar MAGHOUZ
Browse files

Select all monitored items works using apollo

parent 044f2a0b
......@@ -621,6 +621,33 @@
}
}
},
"@apollo/client": {
"version": "3.3.11",
"resolved": "https://registry.npmjs.org/@apollo/client/-/client-3.3.11.tgz",
"integrity": "sha512-54+D5FB6RJlQ+g37f432gaexnyvDsG5X6L9VO5kqN54HJlbF8hCf/8CXtAQEHCWodAwZhy6kOLp2RM96829q3A==",
"requires": {
"@graphql-typed-document-node/core": "^3.0.0",
"@types/zen-observable": "^0.8.0",
"@wry/context": "^0.5.2",
"@wry/equality": "^0.3.0",
"fast-json-stable-stringify": "^2.0.0",
"graphql-tag": "^2.12.0",
"hoist-non-react-statics": "^3.3.2",
"optimism": "^0.14.0",
"prop-types": "^15.7.2",
"symbol-observable": "^2.0.0",
"ts-invariant": "^0.6.0",
"tslib": "^1.10.0",
"zen-observable": "^0.8.14"
},
"dependencies": {
"symbol-observable": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/symbol-observable/-/symbol-observable-2.0.3.tgz",
"integrity": "sha512-sQV7phh2WCYAn81oAkakC5qjq2Ml0g8ozqz03wOGnx9dDlG1de6yrF+0RAzSJD8fPUow3PTSMf2SAbOGxb93BA=="
}
}
},
"@babel/code-frame": {
"version": "7.12.11",
"resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.12.11.tgz",
......@@ -1816,6 +1843,11 @@
"strip-json-comments": "^3.1.1"
}
},
"@graphql-typed-document-node/core": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/@graphql-typed-document-node/core/-/core-3.1.0.tgz",
"integrity": "sha512-wYn6r8zVZyQJ6rQaALBEln5B1pzxb9shV5Ef97kTvn6yVGrqyXVnDqnU24MXnFubR+rZjBY9NWuxX3FB2sTsjg=="
},
"@istanbuljs/schema": {
"version": "0.1.3",
"resolved": "https://registry.npmjs.org/@istanbuljs/schema/-/schema-0.1.3.tgz",
......@@ -2150,6 +2182,11 @@
"integrity": "sha512-K5K+yml8LTo9bWJI/rECfIPrGgxdpeNbj+d53lwN4QjW1MCwlkhUms+gtdzigTeUyBr09+u8BwOIY3MXvHdcsA==",
"dev": true
},
"@types/ungap__global-this": {
"version": "0.3.1",
"resolved": "https://registry.npmjs.org/@types/ungap__global-this/-/ungap__global-this-0.3.1.tgz",
"integrity": "sha512-+/DsiV4CxXl6ZWefwHZDXSe1Slitz21tom38qPCaG0DYCS1NnDPIQDTKcmQ/tvK/edJUKkmuIDBJbmKDiB0r/g=="
},
"@types/webpack-sources": {
"version": "0.1.8",
"resolved": "https://registry.npmjs.org/@types/webpack-sources/-/webpack-sources-0.1.8.tgz",
......@@ -2169,6 +2206,16 @@
}
}
},
"@types/zen-observable": {
"version": "0.8.2",
"resolved": "https://registry.npmjs.org/@types/zen-observable/-/zen-observable-0.8.2.tgz",
"integrity": "sha512-HrCIVMLjE1MOozVoD86622S7aunluLb2PJdPfb3nYiEtohm8mIB/vyv0Fd37AdeMFrTUQXEunw78YloMA3Qilg=="
},
"@ungap/global-this": {
"version": "0.4.4",
"resolved": "https://registry.npmjs.org/@ungap/global-this/-/global-this-0.4.4.tgz",
"integrity": "sha512-mHkm6FvepJECMNthFuIgpAEFmPOk71UyXuIxYfjytvFTnSDBIz7jmViO+LfHI/AjrazWije0PnSP3+/NlwzqtA=="
},
"@webassemblyjs/ast": {
"version": "1.9.0",
"resolved": "https://registry.npmjs.org/@webassemblyjs/ast/-/ast-1.9.0.tgz",
......@@ -2344,6 +2391,30 @@
"@xtuc/long": "4.2.2"
}
},
"@wry/context": {
"version": "0.5.4",
"resolved": "https://registry.npmjs.org/@wry/context/-/context-0.5.4.tgz",
"integrity": "sha512-/pktJKHUXDr4D6TJqWgudOPJW2Z+Nb+bqk40jufA3uTkLbnCRKdJPiYDIa/c7mfcPH8Hr6O8zjCERpg5Sq04Zg==",
"requires": {
"tslib": "^1.14.1"
}
},
"@wry/equality": {
"version": "0.3.4",
"resolved": "https://registry.npmjs.org/@wry/equality/-/equality-0.3.4.tgz",
"integrity": "sha512-1gQQhCPenzxw/1HzLlvSIs/59eBHJf9ZDIussjjZhqNSqQuPKQIzN6SWt4kemvlBPDi7RqMuUa03pId7MAE93g==",
"requires": {
"tslib": "^1.14.1"
}
},
"@wry/trie": {
"version": "0.2.2",
"resolved": "https://registry.npmjs.org/@wry/trie/-/trie-0.2.2.tgz",
"integrity": "sha512-OxqBB39x6MfHaa2HpMiRMfhuUnQTddD32Ko020eBeJXq87ivX6xnSSnzKHVbA21p7iqBASz8n/07b6W5wW1BVQ==",
"requires": {
"tslib": "^1.14.1"
}
},
"@xtuc/ieee754": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/@xtuc/ieee754/-/ieee754-1.2.0.tgz",
......@@ -2546,9 +2617,9 @@
}
},
"apollo-angular": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/apollo-angular/-/apollo-angular-2.3.0.tgz",
"integrity": "sha512-eFr1H22A/VDKKBP5piRZVm4mu65qwZjUuoqhxN1ZtW45d/h7STPIhwTwQheWuJ/nzU2opocLQ8udpBycFRucUw==",
"version": "2.4.0",
"resolved": "https://registry.npmjs.org/apollo-angular/-/apollo-angular-2.4.0.tgz",
"integrity": "sha512-pgxd+3el59T/KAwkNzHTLxlwh+aHBQqtJqnAk91DBiBP6LILlTC1VwOkBhJ4KjYcdsDAgA0Usq4sezyAwxbnLw==",
"requires": {
"extract-files": "^9.0.0",
"semver": "^7.0.0",
......@@ -6666,6 +6737,19 @@
"integrity": "sha512-nTnJ528pbqxYanhpDYsi4Rd8MAeaBA67+RZ10CM1m3bTAVFEDcd5AuA4a6W5YkGZ1iNXHzZz8T6TBKLeBuNriQ==",
"dev": true
},
"graphql": {
"version": "15.5.0",
"resolved": "https://registry.npmjs.org/graphql/-/graphql-15.5.0.tgz",
"integrity": "sha512-OmaM7y0kaK31NKG31q4YbD2beNYa6jBBKtMFT6gLYJljHLJr42IqJ8KX08u3Li/0ifzTU5HjmoOOrwa5BRLeDA=="
},
"graphql-tag": {
"version": "2.12.1",
"resolved": "https://registry.npmjs.org/graphql-tag/-/graphql-tag-2.12.1.tgz",
"integrity": "sha512-LPewEE1vzGkHnCO8zdOGogKsHHBdtpGyihow1UuMwp6RnZa0lAS7NcbvltLOuo4pi5diQCPASAXZkQq44ffixA==",
"requires": {
"tslib": "^1.14.1"
}
},
"gtoken": {
"version": "5.2.1",
"resolved": "https://registry.npmjs.org/gtoken/-/gtoken-5.2.1.tgz",
......@@ -6867,6 +6951,14 @@
"minimalistic-crypto-utils": "^1.0.1"
}
},
"hoist-non-react-statics": {
"version": "3.3.2",
"resolved": "https://registry.npmjs.org/hoist-non-react-statics/-/hoist-non-react-statics-3.3.2.tgz",
"integrity": "sha512-/gGivxi8JPKWNm/W0jSmzcMPpfpPLc3dY/6GxhX2hQ9iGj3aDfklV4ET7NjKpSinLpJ5vafa9iiGIEZg10SfBw==",
"requires": {
"react-is": "^16.7.0"
}
},
"hosted-git-info": {
"version": "3.0.8",
"resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-3.0.8.tgz",
......@@ -8474,6 +8566,14 @@
"integrity": "sha512-Hesni4s5UkWkwCGJMQGAh71PaLUmKFM60dHvq0zi/vDhhrzuk+4GgNbTXJ12YYQJn6ZKBDNIjYcuQGKudvqrIw==",
"dev": true
},
"loose-envify": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.4.0.tgz",
"integrity": "sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==",
"requires": {
"js-tokens": "^3.0.0 || ^4.0.0"
}
},
"lru-cache": {
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz",
......@@ -9308,8 +9408,7 @@
"object-assign": {
"version": "4.1.1",
"resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz",
"integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=",
"dev": true
"integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM="
},
"object-copy": {
"version": "0.1.0",
......@@ -9481,6 +9580,15 @@
}
}
},
"optimism": {
"version": "0.14.1",
"resolved": "https://registry.npmjs.org/optimism/-/optimism-0.14.1.tgz",
"integrity": "sha512-7+1lSN+LJEtaj3uBLLFk8uFCFKy3txLvcvln5Dh1szXjF9yghEMeWclmnk0qdtYZ+lcMNyu48RmQQRw+LRYKSQ==",
"requires": {
"@wry/context": "^0.5.2",
"@wry/trie": "^0.2.1"
}
},
"optionator": {
"version": "0.9.1",
"resolved": "https://registry.npmjs.org/optionator/-/optionator-0.9.1.tgz",
......@@ -11896,6 +12004,16 @@
}
}
},
"prop-types": {
"version": "15.7.2",
"resolved": "https://registry.npmjs.org/prop-types/-/prop-types-15.7.2.tgz",
"integrity": "sha512-8QQikdH7//R2vurIJSutZ1smHYTcLpRWEOlHnzcWHmBYrOGUysKwSsrC89BCiFj3CbrfJ/nXFdJepOVrY1GCHQ==",
"requires": {
"loose-envify": "^1.4.0",
"object-assign": "^4.1.1",
"react-is": "^16.8.1"
}
},
"protractor": {
"version": "7.0.0",
"resolved": "https://registry.npmjs.org/protractor/-/protractor-7.0.0.tgz",
......@@ -12403,6 +12521,11 @@
}
}
},
"react-is": {
"version": "16.13.1",
"resolved": "https://registry.npmjs.org/react-is/-/react-is-16.13.1.tgz",
"integrity": "sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ=="
},
"read-cache": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/read-cache/-/read-cache-1.0.0.tgz",
......@@ -14617,6 +14740,16 @@
"integrity": "sha512-L0Orpi8qGpRG//Nd+H90vFB+3iHnue1zSSGmNOOCh1GLJ7rUKVwV2HvijphGQS2UmhUZewS9VgvxYIdgr+fG1A==",
"dev": true
},
"ts-invariant": {
"version": "0.6.1",
"resolved": "https://registry.npmjs.org/ts-invariant/-/ts-invariant-0.6.1.tgz",
"integrity": "sha512-QQgN33g8E8yrdDuH29HASveLtbzMnRRgWh0i/JNTW4+zcLsdIOnfsgEDi/NKx4UckQyuMFt9Ujm6TWLWQ58Kvg==",
"requires": {
"@types/ungap__global-this": "^0.3.1",
"@ungap/global-this": "^0.4.2",
"tslib": "^1.9.3"
}
},
"ts-node": {
"version": "9.0.0",
"resolved": "https://registry.npmjs.org/ts-node/-/ts-node-9.0.0.tgz",
......@@ -16620,6 +16753,11 @@
"integrity": "sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==",
"dev": true
},
"zen-observable": {
"version": "0.8.15",
"resolved": "https://registry.npmjs.org/zen-observable/-/zen-observable-0.8.15.tgz",
"integrity": "sha512-PQ2PC7R9rslx84ndNBZB/Dkv8V8fZEpk83RLgXtYd0fwUgEjseMn1Dgajh2x6S8QbZAFa9p2qVCEuYZNgve0dQ=="
},
"zone.js": {
"version": "0.11.3",
"resolved": "https://registry.npmjs.org/zone.js/-/zone.js-0.11.3.tgz",
......
......@@ -30,10 +30,15 @@ import {MatFormFieldModule} from '@angular/material/form-field';
import {MatInputModule} from '@angular/material/input';
import {MatTabsModule} from '@angular/material/tabs';
import {updateTicketsDialog} from './monitored_items/monitored-items-dialogs/update-tickets-dialog.component';
import {BrowserModule} from '@angular/platform-browser';
import {APOLLO_OPTIONS} from 'apollo-angular';
import {HttpLink} from 'apollo-angular/http';
import {InMemoryCache} from '@apollo/client/core';
@NgModule({
imports: [
BrowserAnimationsModule,
BrowserModule,
FormsModule,
ReactiveFormsModule,
HttpClientModule,
......@@ -56,7 +61,20 @@ import {updateTicketsDialog} from './monitored_items/monitored-items-dialogs/upd
AdminLayoutComponent,
updateTicketsDialog,
],
providers: [],
providers: [
{
provide: APOLLO_OPTIONS,
useFactory: (httpLink: HttpLink) => {
return {
cache: new InMemoryCache(),
link: httpLink.create({
uri: 'http://localhost/graphql',
}),
};
},
deps: [HttpLink],
},
],
entryComponents: [],
bootstrap: [AppComponent]
})
......
......@@ -34,7 +34,12 @@ export class ActionsCellRenderer implements AgRendererComponent {
dialogConfig.autoFocus = true;
dialogConfig.data = this.params
this.dialog.open(updateTicketsDialog,dialogConfig);
const dialogRef = this.dialog.open(updateTicketsDialog,dialogConfig);
dialogRef.afterClosed().subscribe(result => {
console.log('The dialog was closed',result);
//this.animal = result;
});
}
ngOnDestroy() {
......
export class MonitoredItem {
id: number;
type: string;
element: string;
group: string;
status: string;
creation_date: Date;
update_date: Date;
logicalPath: string;
logicalGroup: string;
statusFk: string;
creationDate: Date;
updateDate: Date;
tickets: Array<string>;
constructor(id, type, element, group, status, creation_date, update_date, tickets) {
constructor(id, type, logicalPath, logicalGroup, statusFk, creationDate, updateDate, tickets) {
this.id = id;
this.type = type;
this.element = element;
this.group = group;
this.status = status;
this.creation_date = creation_date;
this.update_date = update_date;
this.logicalPath = logicalPath;
this.logicalGroup = logicalGroup;
this.statusFk = statusFk;
this.creationDate = creationDate;
this.updateDate = updateDate;
this.tickets = tickets;
}
}
......@@ -3,142 +3,122 @@ import {HttpClient, HttpHeaders} from '@angular/common/http';
import {Observable, of} from 'rxjs';
import {catchError, map} from 'rxjs/operators';
import {MonitoredItem} from './monitored_item.model';
import {Apollo, gql} from 'apollo-angular';
@Injectable({
providedIn: 'root'
providedIn: 'root'
})
export class Monitored_itemsService {
private serverUrl = 'http://localhost/graphql'
constructor(private http: HttpClient) { }
searchMessages(type: string): Observable<MonitoredItem[]> {
console.log("searchMessages")
const requestOptions: Object = {
/* other options here */
responseType: 'text',
headers: new HttpHeaders()
.set('Content-Type', 'text/json')
.append('Access-Control-Allow-Methods', 'GET')
.append('Access-Control-Allow-Origin', '*')
.append(
'Access-Control-Allow-Headers',
'Access-Control-Allow-Headers, Access-Control-Allow-Origin, Access-Control-Request-Method'
),
withCredentials: true
};
//const url = 'assets/all_monitored_items.json';
const query = "{\n" +
" allMonitoredItems {\n" +
" id \n" +
" type \n" +
" logicalPath \n" +
" statusFk \n" +
" creationDate \n" +
" updateDate \n" +
" lastEventDate \n" +
" logicalGroup \n" +
" tickets \n" +
" labels \n" +
" data\n" +
" }\n" +
"}"
const url = this.serverUrl + '?query=' + query;
console.log("searchMessages")
return this.http.get<MonitoredItem[]>(url, requestOptions)
.pipe(
map(response => this.json2MI(response.toString()))
// ,tap(messages => console.log(messages))
);
}
/**
* Handle Http operation that failed.
* Let the app continue.
* @param operation - name of the operation that failed
* @param result - optional value to return as the observable result
*/
private handleError<T>(operation = 'operation', result?: T): (error: any) => Observable<T> {
console.log("handleError",result)
return (error: any): Observable<T> => {
// TODO: send the error to remote logging infrastructure
console.error(error); // log to console instead
constructor(private http: HttpClient, private apollo: Apollo) { }
searchMessages(type: string) {
console.log("searchMessages")
return this.apollo
.watchQuery({
query: gql`
{
allMonitoredItems {
id
type
logicalPath
statusFk
creationDate
updateDate
lastEventDate
logicalGroup
tickets
labels
data
}
}`,
})
.valueChanges;
}
// TODO: better job of transforming error for user consumption
console.log(`${operation} failed: ${error.message}`);
/**
* Handle Http operation that failed.
* Let the app continue.
* @param operation - name of the operation that failed
* @param result - optional value to return as the observable result
*/
private handleError<T>(operation = 'operation', result?: T): (error: any) => Observable<T> {
console.log("handleError",result)
// Let the app keep running by returning an empty result.
return of(result as T);
};
}
return (error: any): Observable<T> => {
private json2MI(messageIn: string): MonitoredItem[] {
const monitoredItemsList: MonitoredItem[] = [];
const json = JSON.parse(messageIn);
//console.log(json)
json.data.allMonitoredItems.map(mi => {
let monitoredItem: MonitoredItem;
// TODO: send the error to remote logging infrastructure
console.error(error); // log to console instead
monitoredItem = new MonitoredItem(
mi.id,
mi.type,
mi.logicalPath,
mi.logicalGroup,
mi.statusFk,
mi.creationDate,
mi.updateDate,
mi.tickets,
);
monitoredItemsList.push(monitoredItem);
});
return monitoredItemsList;
}
// TODO: better job of transforming error for user consumption
console.log(`${operation} failed: ${error.message}`);
addTicketsToMonitoredItem(monitoredItemId, tickets: string[]){
let formatted_tickets = ""
for(var i = 0;i<tickets.length;i++) {
formatted_tickets += "\""+tickets[i]+"\",";
// Let the app keep running by returning an empty result.
return of(result as T);
};
}
const query = "mutation {\n" +
" updateMonitoredItem (\n" +
" id: \"" + monitoredItemId + "\", \n" +
" tickets: [" + formatted_tickets + "]\n" +
" ) \n" +
" {\n" +
" monitoredItem {\n" +
" id\n" +
" tickets\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
};
result2MI(monitoredItemsList: Array<any>): MonitoredItem[] {
let resultMonitoredItemsList: MonitoredItem[] = [];
for(let i = 0; i<monitoredItemsList.length; i++) {
let monitoredItem: MonitoredItem;
monitoredItem = new MonitoredItem(
monitoredItemsList[i].id,
monitoredItemsList[i].type,
monitoredItemsList[i].logicalPath,
monitoredItemsList[i].logicalGroup,
monitoredItemsList[i].statusFk,
monitoredItemsList[i].creationDate,
monitoredItemsList[i].updateDate,
monitoredItemsList[i].tickets,
);
resultMonitoredItemsList.push(monitoredItem);
};
return resultMonitoredItemsList;
}
//let json_query = JSON.parse(query)
return this.http.post(this.serverUrl, {"query":query}, requestOptions)
.pipe(
map(response => console.log(response)),
catchError(err => this.handleError('addTickets', err))
);
}
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" +
" tickets\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
};
//let json_query = JSON.parse(query)
return this.http.post(this.serverUrl, {"query":query}, requestOptions)
.pipe(
map(response => console.log(response)),
catchError(err => this.handleError('addTickets', err))
);
}
}
......@@ -54,20 +54,20 @@ export class Monitored_items_listComponent implements OnInit {
maxWidth: 200
},
{
field: 'element',
field: 'logicalPath',
headerName: 'Element',
sortable: true,
filter: 'agTextColumnFilter',
},
{
field: 'group',
field: 'logicalGroup',
headerName: 'Group',
sortable: true,
filter: 'agTextColumnFilter',
maxWidth: 200
},
{
field: 'status',