mirror of
https://github.com/fabioformosa/quartz-manager.git
synced 2025-12-28 05:03:15 +09:00
#66 fixed lint errors
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
"projects": {
|
||||
"angular-spring-starter": {
|
||||
"root": "",
|
||||
"prefix": "qrzmng",
|
||||
"sourceRoot": "src",
|
||||
"projectType": "application",
|
||||
"architect": {
|
||||
|
||||
@@ -3,7 +3,7 @@ import { NgModule, APP_INITIALIZER} from '@angular/core';
|
||||
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
|
||||
import { HttpClientModule } from '@angular/common/http';
|
||||
|
||||
import {JWT_OPTIONS, JwtModule} from "@auth0/angular-jwt";
|
||||
import {JWT_OPTIONS, JwtModule} from '@auth0/angular-jwt';
|
||||
|
||||
// material
|
||||
import {MatIconRegistry} from '@angular/material/icon';
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
|
||||
import {Component, OnInit, Input, Output, EventEmitter} from '@angular/core';
|
||||
|
||||
import { LogsWebsocketService, ApiService } from '../../services';
|
||||
import { Observable } from 'rxjs';
|
||||
import {LogsWebsocketService, ApiService} from '../../services';
|
||||
import {Observable} from 'rxjs';
|
||||
|
||||
@Component({
|
||||
selector: 'logs-panel',
|
||||
@@ -10,39 +10,44 @@ import { Observable } from 'rxjs';
|
||||
})
|
||||
export class LogsPanelComponent implements OnInit {
|
||||
|
||||
MAX_LOGS : number = 30;
|
||||
MAX_LOGS = 30;
|
||||
|
||||
logs : Array<any> = new Array();
|
||||
logs = new Array();
|
||||
|
||||
constructor(
|
||||
private logsWebsocketService: LogsWebsocketService,
|
||||
private apiService : ApiService
|
||||
) { }
|
||||
private apiService: ApiService
|
||||
) {
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
const obs = this.logsWebsocketService.getObservable()
|
||||
obs.subscribe({
|
||||
'next' : this.onNewLogMsg,
|
||||
'error' : (err) => {console.log(err)}
|
||||
'next': this.onNewLogMsg,
|
||||
'error': (err) => {
|
||||
console.log(err)
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
onNewLogMsg = (receivedMsg) => {
|
||||
if(receivedMsg.type == 'SUCCESS')
|
||||
if (receivedMsg.type === 'SUCCESS') {
|
||||
this._showNewLog(receivedMsg.message);
|
||||
else if(receivedMsg.type == 'ERROR')
|
||||
this._refreshSession(); //if websocket has been closed for session expiration, try to refresh it
|
||||
} else if (receivedMsg.type === 'ERROR') {
|
||||
this._refreshSession();
|
||||
} // if websocket has been closed for session expiration, try to refresh it
|
||||
};
|
||||
|
||||
_showNewLog = (logRecord) => {
|
||||
if(this.logs.length > this.MAX_LOGS)
|
||||
if (this.logs.length > this.MAX_LOGS) {
|
||||
this.logs.pop();
|
||||
}
|
||||
|
||||
this.logs.unshift({
|
||||
time : logRecord.date,
|
||||
type : logRecord.type,
|
||||
msg : logRecord.message,
|
||||
threadName : logRecord.threadName
|
||||
time: logRecord.date,
|
||||
type: logRecord.type,
|
||||
msg: logRecord.message,
|
||||
threadName: logRecord.threadName
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -19,8 +19,8 @@ import { Observable } from 'rxjs';
|
||||
})
|
||||
export class ProgressPanelComponent implements OnInit {
|
||||
|
||||
progress : any = {}
|
||||
percentageStr : string
|
||||
progress = {};
|
||||
percentageStr: string;
|
||||
|
||||
// // Stream of messages
|
||||
// private subscription: Subscription;
|
||||
@@ -31,7 +31,7 @@ export class ProgressPanelComponent implements OnInit {
|
||||
// public mq: Array<string> = [];
|
||||
|
||||
|
||||
// private socketSubscription
|
||||
// private socketSubscription
|
||||
|
||||
constructor(
|
||||
private progressWebsocketService: ProgressWebsocketService,
|
||||
@@ -40,15 +40,15 @@ export class ProgressPanelComponent implements OnInit {
|
||||
) { }
|
||||
|
||||
onNewProgressMsg = (receivedMsg) => {
|
||||
if (receivedMsg.type == 'SUCCESS') {
|
||||
var newStatus = receivedMsg.message;
|
||||
if (receivedMsg.type === 'SUCCESS') {
|
||||
const newStatus = receivedMsg.message;
|
||||
this.progress = newStatus;
|
||||
this.percentageStr = this.progress.percentage + '%';
|
||||
}
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
let obs = this.progressWebsocketService.getObservable()
|
||||
const obs = this.progressWebsocketService.getObservable()
|
||||
obs.subscribe({
|
||||
'next' : this.onNewProgressMsg,
|
||||
'error' : (err) => {console.log(err)}
|
||||
|
||||
@@ -23,7 +23,8 @@ describe('TriggerListComponent', () => {
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [MatCardModule, MatDialogModule, MatDividerModule, MatIconModule, MatListModule, HttpClientTestingModule, RouterTestingModule],
|
||||
imports: [MatCardModule, MatDialogModule, MatDividerModule,
|
||||
MatIconModule, MatListModule, HttpClientTestingModule, RouterTestingModule],
|
||||
declarations: [TriggerListComponent],
|
||||
providers: [TriggerService, ApiService, ConfigService]
|
||||
}).compileComponents();
|
||||
|
||||
@@ -4,6 +4,13 @@ import {TriggerKey} from '../../model/triggerKey.model';
|
||||
import {SimpleTrigger} from '../../model/simple-trigger.model';
|
||||
import {MatDialog} from '@angular/material/dialog';
|
||||
|
||||
@Component({
|
||||
template: 'Multiple jobs not supported yet - Coming Soon...',
|
||||
})
|
||||
// tslint:disable-next-line:component-class-suffix
|
||||
export class UnsupportedMultipleJobsDialog {
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'qrzmng-trigger-list',
|
||||
templateUrl: './trigger-list.component.html',
|
||||
@@ -26,7 +33,8 @@ export class TriggerListComponent implements OnInit {
|
||||
constructor(
|
||||
private triggerService: TriggerService,
|
||||
public dialog: MatDialog
|
||||
) { }
|
||||
) {
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.loading = true;
|
||||
@@ -34,7 +42,7 @@ export class TriggerListComponent implements OnInit {
|
||||
}
|
||||
|
||||
@Input()
|
||||
set openedNewTriggerForm(triggerFormIsOpen: boolean){
|
||||
set openedNewTriggerForm(triggerFormIsOpen: boolean) {
|
||||
this.triggerFormIsOpen = triggerFormIsOpen;
|
||||
}
|
||||
|
||||
@@ -61,20 +69,17 @@ export class TriggerListComponent implements OnInit {
|
||||
}
|
||||
|
||||
onNewTriggerBtnClicked() {
|
||||
if (this.triggerKeys && this.triggerKeys.length > 0)
|
||||
if (this.triggerKeys && this.triggerKeys.length > 0) {
|
||||
this.dialog.open(UnsupportedMultipleJobsDialog)
|
||||
else
|
||||
} else {
|
||||
this.onNewTriggerClicked.emit();
|
||||
}
|
||||
}
|
||||
|
||||
onNewTrigger(newTrigger: SimpleTrigger) {
|
||||
this.newTriggers = [newTrigger, ...this.newTriggers];
|
||||
this.selectedTrigger = newTrigger.triggerKeyDTO;
|
||||
this.newTriggers = [newTrigger, ...this.newTriggers];
|
||||
this.selectedTrigger = newTrigger.triggerKeyDTO;
|
||||
}
|
||||
}
|
||||
|
||||
@Component({
|
||||
template: 'Multiple jobs not supported yet - Coming Soon...',
|
||||
})
|
||||
// tslint:disable-next-line:component-class-suffix
|
||||
export class UnsupportedMultipleJobsDialog {}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
export class SocketEndpoint{
|
||||
client : any
|
||||
stomp : any
|
||||
}
|
||||
export class SocketEndpoint {
|
||||
client: any
|
||||
stomp: any
|
||||
}
|
||||
|
||||
@@ -1,17 +1,20 @@
|
||||
export class SocketOption{
|
||||
socketUrl : string;
|
||||
topicName : string;
|
||||
brokerName : string;
|
||||
reconnectionTimeout : number = 30000
|
||||
export class SocketOption {
|
||||
socketUrl: string;
|
||||
topicName: string;
|
||||
brokerName: string;
|
||||
reconnectionTimeout = 30000
|
||||
|
||||
getAccessToken: Function = () => null;
|
||||
getAccessToken: Function = () => null;
|
||||
|
||||
constructor(socketUrl : string, topicName : string, getAccessToken?: Function, brokerName : string = null, reconnectionTimeout : number = 30000){
|
||||
this.socketUrl = socketUrl;
|
||||
this.topicName = topicName;
|
||||
this.brokerName = brokerName;
|
||||
this.reconnectionTimeout = reconnectionTimeout;
|
||||
this.getAccessToken = getAccessToken || (() => null);
|
||||
}
|
||||
|
||||
}
|
||||
constructor(socketUrl: string,
|
||||
topicName: string,
|
||||
getAccessToken?: Function,
|
||||
brokerName: string = null,
|
||||
reconnectionTimeout: number = 30000) {
|
||||
this.socketUrl = socketUrl;
|
||||
this.topicName = topicName;
|
||||
this.brokerName = brokerName;
|
||||
this.reconnectionTimeout = reconnectionTimeout;
|
||||
this.getAccessToken = getAccessToken || (() => null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,83 +1,83 @@
|
||||
import { TestBed } from "@angular/core/testing";
|
||||
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
|
||||
import { ApiService } from './api.service';
|
||||
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
||||
import { Router} from '@angular/router';
|
||||
import {TestBed} from '@angular/core/testing';
|
||||
import {HttpClientTestingModule, HttpTestingController} from '@angular/common/http/testing';
|
||||
import {ApiService} from './api.service';
|
||||
import {HttpClient, HttpHeaders} from '@angular/common/http';
|
||||
import {Router} from '@angular/router';
|
||||
import {jest} from '@jest/globals'
|
||||
|
||||
class Data{
|
||||
name: string
|
||||
class Data {
|
||||
name: string
|
||||
}
|
||||
|
||||
class HttpResponseMock {
|
||||
constructor(
|
||||
public body: unknown,
|
||||
public opts?: {
|
||||
headers?:
|
||||
| HttpHeaders
|
||||
| {
|
||||
[name: string]: string | string[];
|
||||
};
|
||||
status?: number;
|
||||
statusText?: string;
|
||||
}
|
||||
) {}
|
||||
constructor(
|
||||
public body: unknown,
|
||||
public opts?: {
|
||||
headers?:
|
||||
| HttpHeaders
|
||||
| {
|
||||
[name: string]: string | string[];
|
||||
};
|
||||
status?: number;
|
||||
statusText?: string;
|
||||
}
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
||||
const routerSpy = jest.spyOn(Router.prototype, 'navigateByUrl');
|
||||
|
||||
describe('ApiServiceTest', () => {
|
||||
|
||||
let apiService: ApiService;
|
||||
let httpClient: HttpClient;
|
||||
let httpTestingController: HttpTestingController;
|
||||
let apiService: ApiService;
|
||||
let httpClient: HttpClient;
|
||||
let httpTestingController: HttpTestingController;
|
||||
|
||||
const SAMPLE_URL = '/sample-url';
|
||||
const URL_401 = '/url-response-401';
|
||||
const testData: Data = {name: 'Test Data'};
|
||||
const SAMPLE_URL = '/sample-url';
|
||||
const URL_401 = '/url-response-401';
|
||||
const testData: Data = {name: 'Test Data'};
|
||||
|
||||
beforeEach(() => {
|
||||
beforeEach(() => {
|
||||
|
||||
TestBed.configureTestingModule({
|
||||
imports: [HttpClientTestingModule],
|
||||
providers: [ApiService, {provide: Router, useValue: routerSpy}]
|
||||
});
|
||||
apiService = TestBed.inject(ApiService);
|
||||
TestBed.configureTestingModule({
|
||||
imports: [HttpClientTestingModule],
|
||||
providers: [ApiService, {provide: Router, useValue: routerSpy}]
|
||||
});
|
||||
apiService = TestBed.inject(ApiService);
|
||||
|
||||
httpClient = TestBed.inject(HttpClient);
|
||||
httpTestingController = TestBed.inject(HttpTestingController);
|
||||
httpClient = TestBed.inject(HttpClient);
|
||||
httpTestingController = TestBed.inject(HttpTestingController);
|
||||
});
|
||||
|
||||
it('should be created', (): void => {
|
||||
expect(apiService).toBeTruthy();
|
||||
});
|
||||
|
||||
it('can test HttpClient.get', (): void => {
|
||||
|
||||
apiService.get(SAMPLE_URL).subscribe((res: Data) => {
|
||||
expect(res).toEqual(testData);
|
||||
});
|
||||
|
||||
it('should be created', (): void => {
|
||||
expect(apiService).toBeTruthy();
|
||||
const req = httpTestingController.expectOne(SAMPLE_URL)
|
||||
expect(req.request.method).toEqual('GET');
|
||||
req.flush(new HttpResponseMock(testData));
|
||||
httpTestingController.verify();
|
||||
});
|
||||
|
||||
it('doesn\'t do anything if 401 is received', (): void => {
|
||||
|
||||
apiService.get(URL_401).subscribe((res: Data) => {
|
||||
expect(false);
|
||||
}, (error) => {
|
||||
expect(error.status).toBe(401);
|
||||
expect(routerSpy).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('can test HttpClient.get', (): void => {
|
||||
const req = httpTestingController.expectOne(URL_401)
|
||||
expect(req.request.method).toEqual('GET');
|
||||
req.flush(null, {status: 401, statusText: 'unauthenticated'});
|
||||
httpTestingController.verify();
|
||||
});
|
||||
|
||||
apiService.get(SAMPLE_URL).subscribe((res: Data) => {
|
||||
expect(res).toEqual(testData);
|
||||
});
|
||||
|
||||
const req = httpTestingController.expectOne(SAMPLE_URL)
|
||||
expect(req.request.method).toEqual('GET');
|
||||
req.flush(new HttpResponseMock(testData));
|
||||
httpTestingController.verify();
|
||||
});
|
||||
|
||||
it('doesn\'t do anything if 401 is received', (): void => {
|
||||
|
||||
apiService.get(URL_401).subscribe((res: Data) => {
|
||||
expect(false);
|
||||
}, (error) =>
|
||||
{
|
||||
expect(error.status).toBe(401);
|
||||
expect(routerSpy).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
const req = httpTestingController.expectOne(URL_401)
|
||||
expect(req.request.method).toEqual('GET');
|
||||
req.flush(null, {status: 401, statusText: 'unauthenticated'});
|
||||
httpTestingController.verify();
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
@@ -18,9 +18,16 @@ export enum RequestMethod {
|
||||
@Injectable()
|
||||
export class ApiService {
|
||||
|
||||
headers = new HttpHeaders({
|
||||
'Accept': 'application/json',
|
||||
'Content-Type': 'application/json'
|
||||
});
|
||||
|
||||
private jwtToken: string;
|
||||
|
||||
private static extractTokenFromHttpResponse(res: HttpResponse<any>): string {
|
||||
let authorization: string = null;
|
||||
let headers: HttpHeaders = res.headers;
|
||||
const headers: HttpHeaders = res.headers;
|
||||
if (headers && headers.has('Authorization')) {
|
||||
authorization = headers.get('Authorization');
|
||||
if (authorization.startsWith('Bearer ')) {
|
||||
@@ -30,13 +37,6 @@ export class ApiService {
|
||||
return authorization;
|
||||
}
|
||||
|
||||
headers = new HttpHeaders({
|
||||
'Accept': 'application/json',
|
||||
'Content-Type': 'application/json'
|
||||
});
|
||||
|
||||
private jwtToken: string;
|
||||
|
||||
constructor(private http: HttpClient, private router: Router) {
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ export class WebsocketService {
|
||||
|
||||
observableStompConnection: Observable<any>;
|
||||
subscribers: Array<any> = [];
|
||||
subscriberIndex: number = 0;
|
||||
subscriberIndex = 0;
|
||||
|
||||
_messageIds: Array<any> = [];
|
||||
|
||||
@@ -26,9 +26,7 @@ export class WebsocketService {
|
||||
this.connect();
|
||||
}
|
||||
|
||||
//TO BE OVERRIDEN
|
||||
getOptions = () => {
|
||||
return {}
|
||||
}
|
||||
|
||||
private createObservableSocket = () => {
|
||||
@@ -45,6 +43,7 @@ export class WebsocketService {
|
||||
|
||||
removeFromSubscribers = (index) => {
|
||||
if (index > this.subscribers.length) {
|
||||
// tslint:disable-next-line:max-line-length
|
||||
throw new Error(`Unexpected error removing subscriber from websocket, because index ${index} is greater than subscriber length ${this.subscribers.length}`);
|
||||
}
|
||||
this.subscribers.splice(index, 1);
|
||||
@@ -101,7 +100,7 @@ export class WebsocketService {
|
||||
};
|
||||
|
||||
send = (message) => {
|
||||
var id = Math.floor(Math.random() * 1000000);
|
||||
const id = Math.floor(Math.random() * 1000000);
|
||||
this._socket.stomp.send(this._options.brokerName, {
|
||||
priority: 9
|
||||
}, JSON.stringify({
|
||||
|
||||
Reference in New Issue
Block a user