Commit cf6a5617 authored by MAGHOUZ's avatar MAGHOUZ
Browse files

removing unused and problematic component: app/message/*

parent 8b693b40
import { Component, OnInit } from '@angular/core';
import {MessageListComponent} from '../../messages/message-list.component';
declare const $: any;
declare interface RouteInfo {
......@@ -16,7 +15,6 @@ export const ROUTES: RouteInfo[] = [
//{ path: '/icons', title: 'Icons', icon:'bubble_chart', class: '' },
//{ path: '/maps', title: 'Maps', icon:'location_on', class: '' },
//{ path: '/notifications', title: 'Notifications', icon:'notifications', class: '' },
{ path: '/cops/items_xml', title: 'Monitored Items', icon:'content_paste', class: '' },
{ path: '/cops/items', title: 'Monitored Items', icon:'content_paste', class: '' },
];
......
......@@ -17,7 +17,6 @@ import {MatRippleModule} from '@angular/material/core';
import {MatFormFieldModule} from '@angular/material/form-field';
import {MatTooltipModule} from '@angular/material/tooltip';
import {MatSelectModule} from '@angular/material/select';
import {MessageListComponent} from '../../messages/message-list.component';
import {Monitored_items_listComponent} from '../../monitored_items/monitored_items_list.component';
import {Monitored_events_listComponent} from '../../monitored_events/monitored_events_list.component';
import {Monitored_Item_Details_Component} from '../../monitored_events/monitored_item_details/monitored_item_details.component';
......@@ -64,7 +63,6 @@ import {MatMenuModule} from '@angular/material/menu';
MapsComponent,
NotificationsComponent,
UpgradeComponent,
MessageListComponent,
Monitored_items_listComponent,
Monitored_events_listComponent,
Monitored_Item_Details_Component,
......
......@@ -8,7 +8,6 @@ import { IconsComponent } from '../../icons/icons.component';
import { MapsComponent } from '../../maps/maps.component';
import { NotificationsComponent } from '../../notifications/notifications.component';
import { UpgradeComponent } from '../../upgrade/upgrade.component';
import {MessageListComponent} from '../../messages/message-list.component';
import {Monitored_items_listComponent} from '../../monitored_items/monitored_items_list.component';
import {Monitored_events_listComponent} from '../../monitored_events/monitored_events_list.component';
......@@ -64,7 +63,6 @@ export const AdminLayoutRoutes: Routes = [
//{ path: 'maps', component: MapsComponent },
//{ path: 'notifications', component: NotificationsComponent },
//{ path: 'upgrade', component: UpgradeComponent },
{ path: 'cops/items_xml', component: MessageListComponent },
{ path: 'cops/items', component: Monitored_items_listComponent },
{ path: 'cops/monitored_item/:monitored_item_id', component: Monitored_events_listComponent },
......
<div class="main-content">
<div class="container-fluid">
<div class="row">
<div class="col-md-12">
<ag-grid-angular
#agGrid
class="ag-theme-material"
rowHeight="40"
headerHeight="50"
[rowData]="rowData"
[columnDefs]="columnDefs"
[defaultColDef]="defaultColDef"
domLayout='autoHeight'
rowSelection="multiple"
enableRangeSelection="true"
></ag-grid-angular>
</div>
<div class="col-md-4">
<div class="table-toolbar">
<button mat-flat-button color="accent" (click)="displaySelectedRows()">Pending</button>
<button mat-flat-button color="warn" (click)="displaySelectedRows()">Acknowledge</button>
</div>
</div>
</div>
</div>
</div>
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { MessageListComponent } from './message-list.component';
describe('ReportsComponent', () => {
let component: MessageListComponent;
let fixture: ComponentFixture<MessageListComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ MessageListComponent ]
})
.compileComponents();
});
beforeEach(() => {
fixture = TestBed.createComponent(MessageListComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
import {Component, OnInit, ViewChild} from '@angular/core';
import { HttpClient } from '@angular/common/http';
import {AgGridAngular} from 'ag-grid-angular';
import { MessageService } from './message.service';
import {MessageSummary} from './message.model';
@Component({
selector: 'app-reports',
templateUrl: './message-list.component.html',
styleUrls: ['./message-list.component.css']
})
export class MessageListComponent implements OnInit {
@ViewChild('agGrid') agGrid: AgGridAngular;
columnDefs = [
{
field: 'id',
headerName: '',
sortable: false,
filter: false,
checkboxSelection: true,
headerCheckboxSelection: true,
headerCheckboxSelectionFilteredOnly: true,
maxWidth: 60
},
{ field: 'origin', headerName: 'Origine', maxWidth: 250 },
{ field: 'date', headerName: 'Date', filter: 'agDateColumnFilter', maxWidth: 200 },
{
field: 'level',
headerName: 'Statut',
filter: 'agSetColumnFilter',
filterParams: {
values: ['Australia', 'China', 'Sweden']
},
menuTabs: ['filterMenuTab'],
maxWidth: 120
},
{ field: 'project', headerName: 'Projet', maxWidth: 200 },
{ field: 'type', headerName: 'Type', maxWidth: 100 },
{ field: 'summary', headerName: 'Sujet' }
];
defaultColDef = {
flex: 1,
minWidth: 100,
sortable: true,
filter: true,
resizable: true
};
defaultColGroupDef: {};
rowData: any;
messageType = '1';
selectedRows: string[];
constructor(private http: HttpClient, private reportService: MessageService) { }
ngOnInit(): void {
this.getMessages();
}
updateSelectedRows(): void {
const selectedNodes = this.agGrid.api.getSelectedNodes();
const selectedData = selectedNodes.map(node => node.data);
this.selectedRows = selectedData.map(node => node.id);
}
displaySelectedRows(): void {
this.updateSelectedRows();
alert(`Selected nodes: ${this.selectedRows.join(', ')}`);
}
getMessages(): void {
this.reportService.searchMessages(this.messageType)
.subscribe(messages => this.rowData = messages);
}
}
export class MessageSummary {
id: number;
filepath: string;
date: Date;
level: string;
project: string;
origin: string;
summary: string;
reference: string;
type: string;
constructor(id, filepath, level, project, origin, summary, reference, type, date) {
this.id = id;
this.filepath = filepath;
this.level = level;
this.project = project;
this.origin = origin;
this.summary = summary;
this.reference = reference;
this.type = type;
this.date = date;
}
}
import { TestBed } from '@angular/core/testing';
import { MessageService } from './message.service';
describe('ReportService', () => {
let service: MessageService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(MessageService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});
import { Injectable } from '@angular/core';
import {HttpClient, HttpHeaders} from '@angular/common/http';
import {Observable, of} from 'rxjs';
import {catchError, map, tap} from 'rxjs/operators';
import * as converter from 'xml-js';
import {MessageSummary} from './message.model';
@Injectable({
providedIn: 'root'
})
export class MessageService {
constructor(private http: HttpClient) { }
searchMessages(type: string): Observable<MessageSummary[]> {
// tslint:disable-next-line:ban-types
const requestOptions: Object = {
/* other options here */
responseType: 'text',
headers: new HttpHeaders()
.set('Content-Type', 'text/xml')
.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/message.json';
const url = 'assets/messages.xml';
// const url = 'https://cersat-console-exp.ifremer.fr/emm/messages/search?date_min=2020-11-01T00:00:00Z&operator_state=2';
// const url = '/emm/messages/search?date_min=2020-11-01T00:00:00Z&operator_state=2';
// url += '&ticket=' + window.sessionStorage.getItem('ticketUser');
return this.http.get<MessageSummary[]>(url, requestOptions)
.pipe(
map(response => this.xml2MessageSummary(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> {
return (error: any): Observable<T> => {
// TODO: send the error to remote logging infrastructure
console.error(error); // log to console instead
// TODO: better job of transforming error for user consumption
console.log(`${operation} failed: ${error.message}`);
// Let the app keep running by returning an empty result.
return of(result as T);
};
}
private xml2MessageSummary(xml: string): MessageSummary[] {
const messageSummaryList: MessageSummary[] = [];
const json = JSON.parse(converter.xml2json(xml, {
compact: true,
spaces: 2,
ignoreComment: true,
ignoreDoctype: true
}));
json.MessageListSummary.MessageSummary.map(msg => {
let message: MessageSummary;
let msgElement: any;
if (msg.hasOwnProperty('processingMessage')) {
msgElement = msg.processingMessage;
} else if (msg.hasOwnProperty('downloadMessage')) {
msgElement = msg.downloadMessage;
} else {
msgElement = msg.message;
}
message = new MessageSummary(
msg._attributes.id,
msg.filepath._text,
msgElement.level._text,
msgElement.project._text,
msgElement.hasOwnProperty('type') ? msgElement.type._text : '',
msgElement.summary._text,
msgElement.reference.hasOwnProperty('_text') ? msgElement.reference._text : '',
msgElement.reference.hasOwnProperty('_attributes') ? msgElement.reference._attributes.type : '',
msgElement.date._text
);
messageSummaryList.push(message);
});
return messageSummaryList;
}
private json2MessageSummary(messageIn: string): MessageSummary[] {
const messageSummaryList: MessageSummary[] = [];
const json = JSON.parse(messageIn);
json.MessageListSummary.MessageSummary.map(msg => {
let message: MessageSummary;
let msgElement: any;
if (msg.hasOwnProperty('processingMessage')) {
msgElement = msg.processingMessage;
} else if (msg.hasOwnProperty('downloadMessage')) {
msgElement = msg.downloadMessage;
} else {
msgElement = msg.message;
}
message = new MessageSummary(
msg.id,
msg.filepath,
msgElement.level,
msgElement.project,
msgElement.hasOwnProperty('type') ? msgElement.type : '',
msgElement.summary,
msgElement.hasOwnProperty('reference') ? msgElement.reference.hasOwnProperty('_text') ? msgElement.reference._text : '' : '',
msgElement.hasOwnProperty('reference') ? msgElement.reference.hasOwnProperty('_type') ? msgElement.reference._type : '' : '',
msgElement.date
);
messageSummaryList.push(message);
});
return messageSummaryList;
}
}
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