-
Notifications
You must be signed in to change notification settings - Fork 89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Debug window console #470
Debug window console #470
Changes from 5 commits
a4307e7
343c599
97f604e
4c34903
73a6e22
b61359f
7518749
ecf4043
ffda25b
a6ec6de
35a3ddf
379e4e8
aa6d989
09d6551
79fef25
a94740b
bd53cbd
8d7152f
f48ecbf
2eeb9a4
f1cf3d3
389cf17
38206ba
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
export class Command { | ||
|
||
constructor(private type: number, private text: string, private time: string, private code?: number) { } | ||
|
||
public getType() { | ||
return this.type; | ||
} | ||
|
||
public getText() { | ||
return this.text; | ||
} | ||
|
||
public getCode() { | ||
return this.code; | ||
} | ||
|
||
public logTime() { | ||
return this.time; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<div class="containerX"> | ||
<div mat-dialog-container> | ||
<mat-tab-group> | ||
<mat-tab label="Console"> | ||
<div class="console-modal-form"> | ||
<div fxLayout="row" fxLayoutGap="10px" fxLayoutAlign="center center"> | ||
<div fxFlex="10"> | ||
{{currentTime}} | ||
</div> | ||
<div fxFlex="10"> | ||
<!-- @Todo Need to change icon --> | ||
<mat-icon fontSet="faIcon" fontIcon="fa-mars-stroke-v"></mat-icon> | ||
</div> | ||
<div fxFlex="80"> | ||
<p> | ||
<span>Welcome to the Particl Core RPC console.Use up and down arrows to navigate history, and Ctrl-L to clear screen.Type help for an overview of available commands.</span> | ||
</p> | ||
<p> | ||
<span class="warn-text">WARNING: Scammers have been active, telling users to type commands here, stealing their wallet contents. Do not use this console without fully understanding the ramification of a command.</span> | ||
</p> | ||
</div> | ||
</div> | ||
|
||
<div class="content-modal" fxLayout="row" fxLayoutGap="10px" fxLayoutAlign="center center" *ngFor="let list of commandList"> | ||
<div fxFlex="10"> | ||
{{list.time}} | ||
</div> | ||
<div fxFlex="10" fxLayoutAlign="top top"> | ||
<!-- @Todo Need to change icon --> | ||
<mat-icon fontSet="faIcon" fontIcon="fa-mars-stroke-h" *ngIf="list.getType() === 1"></mat-icon> | ||
<!-- @Todo Need to change icon --> | ||
<mat-icon fontSet="faIcon" fontIcon="fa-mars-stroke-v" *ngIf="list.getType() === 2"></mat-icon> | ||
</div> | ||
<div fxFlex="80"> | ||
<p [ngClass]="{'warn-text': list.getCode() === -1, 'space-text': list.getType() === 2 }"> | ||
{{list.getText()}} | ||
</p> | ||
</div> | ||
</div> | ||
</div> | ||
<div fxLayout="row" fxLayoutGap="5px" fxLayoutAlign="center center"> | ||
<mat-form-field fxFlex="1 1 100%"> | ||
<input matInput [(ngModel)]="command"> | ||
</mat-form-field> | ||
<span matTooltip="Enter"> | ||
<!-- @Todo Need to change icon --> | ||
<mat-icon fontSet="faIcon" fontIcon="fa-sign-in"></mat-icon> | ||
</span> | ||
<span matTooltip="Clear"> | ||
<!-- @Todo Need to change icon --> | ||
<mat-icon fontSet="faIcon" fontIcon="fa-times-circle-o" color="warn" (click)="clearCommands()"></mat-icon> | ||
</span> | ||
</div> | ||
</mat-tab> | ||
</mat-tab-group> | ||
</div> | ||
</div> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
.console-modal-form { | ||
width: 100%; | ||
height: 450px; | ||
overflow-y: scroll; | ||
} | ||
.warn-text { | ||
color: #f44336; | ||
} | ||
.content-modal { | ||
max-height: none !important; | ||
} | ||
|
||
.space-text { | ||
white-space: pre-line; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { MatDialogRef } from '@angular/material'; | ||
|
||
import { CoreModule } from '../../../../../core/core.module'; | ||
import { SharedModule } from '../../../../../wallet/shared/shared.module'; | ||
import { ModalsModule } from '../../../../../modals/modals.module'; | ||
import { CoreUiModule } from '../../../../core-ui.module'; | ||
|
||
import { ConsoleModalComponent } from './console-modal.component'; | ||
|
||
describe('ConsoleModalComponent', () => { | ||
let component: ConsoleModalComponent; | ||
let fixture: ComponentFixture<ConsoleModalComponent>; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [ | ||
SharedModule, | ||
CoreModule.forRoot(), | ||
ModalsModule, | ||
CoreUiModule.forRoot() | ||
], | ||
providers: [ | ||
/* deps */ | ||
{ provide: MatDialogRef} | ||
] | ||
}) | ||
.compileComponents(); | ||
})); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(ConsoleModalComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
|
||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import {Component, OnInit, HostListener } from '@angular/core'; | ||
import { MatDialog, MatDialogRef } from '@angular/material'; | ||
import { Log } from 'ng2-logger'; | ||
|
||
import { DateFormatter } from '../../../../../wallet/shared/util/utils'; | ||
|
||
import { RpcService } from '../../../../../core/core.module'; | ||
import { Command } from './command.model'; | ||
|
||
@Component({ | ||
selector: 'app-console-modal', | ||
templateUrl: './console-modal.component.html', | ||
styleUrls: ['./console-modal.component.scss'] | ||
}) | ||
export class ConsoleModalComponent implements OnInit { | ||
|
||
log: any = Log.create('app-console-modal'); | ||
public commandList: Array<any> = []; | ||
public command: string; | ||
public currentTime: string; | ||
|
||
|
||
constructor(public dialogRef: MatDialogRef<ConsoleModalComponent>, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yup we can remove it |
||
private _rpc: RpcService, | ||
private dialog: MatDialog) { | ||
} | ||
|
||
ngOnInit() { | ||
this.getCurrentTime(); | ||
} | ||
|
||
rpcCall() { | ||
const params = this.command.split(' '); | ||
this._rpc.call(params.shift(), params) | ||
.subscribe( | ||
response => this.formatSuccessResponse(response), | ||
error => this.formatErrorResponse(error)); | ||
} | ||
|
||
formatSuccessResponse(response: any) { | ||
let respText = ''; | ||
if (typeof response === 'object') { | ||
respText = JSON.stringify(response, null, 1); | ||
} else { | ||
respText = response; | ||
} | ||
this.commandList.push(new Command(1, this.command, this.getDateFormat()), | ||
new Command(2, respText, this.getDateFormat(), 200)); | ||
this.command = ''; | ||
} | ||
|
||
formatErrorResponse(error: any) { | ||
if (error.code === -1) { | ||
this.commandList.push(new Command(1, this.command, this.getDateFormat()), | ||
new Command(2, error.message, this.getDateFormat(), -1)); | ||
this.command = ''; | ||
} | ||
} | ||
|
||
clearCommands() { | ||
this.commandList = []; | ||
} | ||
|
||
/* Time stuff */ | ||
getCurrentTime() { | ||
this.currentTime = this.getDateFormat(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please use moment function for get current time or date etc.. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please check util we have global model class called 'DateFormatter' There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay perfect I can see |
||
} | ||
|
||
getDateFormat() { | ||
return new DateFormatter(new Date()).hourSecFormatter(); | ||
} | ||
|
||
// capture the enter button | ||
@HostListener('window:keydown', ['$event']) | ||
keyDownEvent(event: any) { | ||
if (event.keyCode === 13) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can also use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes we can but we are using hostlistener for clear console so no need :D There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah perfect |
||
this.rpcCall(); | ||
} | ||
if (event.ctrlKey && event.keyCode === 76) { | ||
this.clearCommands(); | ||
} | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,9 +5,10 @@ import { Log } from 'ng2-logger'; | |
import { MatDialog} from '@angular/material'; | ||
|
||
import { ModalsService } from '../../../modals/modals.service'; | ||
|
||
import { RpcService, StateService } from '../../../core/core.module'; | ||
|
||
import { ConsoleModalComponent } from './modal/help-modal/console-modal.component'; | ||
|
||
@Component({ | ||
selector: 'app-status', | ||
templateUrl: './status.component.html', | ||
|
@@ -26,7 +27,8 @@ export class StatusComponent implements OnInit { | |
constructor( | ||
private _rpc: RpcService, | ||
private _modalsService: ModalsService, | ||
private _stateService: StateService) { } | ||
private _stateService: StateService, | ||
private dialog: MatDialog) { } | ||
|
||
ngOnInit() { | ||
this._rpc.state.observe('connections') | ||
|
@@ -91,4 +93,9 @@ export class StatusComponent implements OnInit { | |
break; | ||
} | ||
} | ||
|
||
/* Open Debug Console Window */ | ||
openConsoleWindow() { | ||
const dialogRef = this.dialog.open(ConsoleModalComponent); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no need of dialogRef |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -166,3 +166,26 @@ export class AddressHelper { | |
'' : this.getAddress(event.clipboardData.getData('text')); | ||
} | ||
} | ||
|
||
export class DateFormatter { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you please use moment js for manage date related all functionality? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes we can I guess :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yup we can I guess |
||
|
||
constructor(private date: Date) { | ||
} | ||
|
||
public dateFormatter() { | ||
return ( | ||
(this.date.getDate() < 10 ? '0' + this.date.getDate() : this.date.getDate()) + '-' + | ||
((this.date.getMonth() + 1) < 10 ? '0' + (this.date.getMonth() + 1) : (this.date.getMonth() + 1)) + '-' + | ||
(this.date.getFullYear() < 10 ? '0' + this.date.getFullYear() : this.date.getFullYear()) + ' ' + | ||
this.hourSecFormatter() | ||
) | ||
} | ||
|
||
public hourSecFormatter() { | ||
return ( | ||
(this.date.getHours() < 10 ? '0' + this.date.getHours() : this.date.getHours()) + ':' + | ||
(this.date.getMinutes() < 10 ? '0' + this.date.getMinutes() : this.date.getMinutes()) + ':' + | ||
(this.date.getSeconds() < 10 ? '0' + this.date.getSeconds() : this.date.getSeconds()) | ||
) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All below model helper function is really required? as there is no manipulation in object
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
obviously it is required check console-modal.component.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can directly access any key of a model like if you want to get a type
list.getType()
list.type ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok make sense to me :)