diff options
Diffstat (limited to 'app/components')
-rw-r--r-- | app/components/plan-new/plan-new.html | 1 | ||||
-rw-r--r-- | app/components/plan-new/plan-new.ts | 21 |
2 files changed, 16 insertions, 6 deletions
diff --git a/app/components/plan-new/plan-new.html b/app/components/plan-new/plan-new.html index f27037d..f150969 100644 --- a/app/components/plan-new/plan-new.html +++ b/app/components/plan-new/plan-new.html @@ -9,6 +9,7 @@ <button class="btn btn-default btn-lg pad-top pull-right" (click)="submitPlan()">submit</button> </div> + <p *ngIf="validationMessage" class="error-message">{{validationMessage}}</p> <textarea placeholder="paste execution plan" class="input-box input-box-lg" [(ngModel)]="newPlanContent"></textarea> <textarea placeholder="paste corresponding SQL query" class="input-box input-box-lg" [(ngModel)]="newPlanQuery"></textarea> </div> diff --git a/app/components/plan-new/plan-new.ts b/app/components/plan-new/plan-new.ts index 93149e2..115fa82 100644 --- a/app/components/plan-new/plan-new.ts +++ b/app/components/plan-new/plan-new.ts @@ -16,19 +16,28 @@ export class PlanNew { newPlanContent: string; newPlanQuery: string; newPlan: IPlan; + validationMessage: string; - constructor( private _router: Router, private _planService: PlanService) { } + constructor(private _router: Router, private _planService: PlanService) { } submitPlan() { + // remove psql generated header + this.newPlanContent = this.newPlanContent.replace('QUERY PLAN', ''); + + if (!this._planService.isJsonString(this.newPlanContent)) { + this.validationMessage = 'The string you submitted is not valid JSON' + return; + } + this.newPlan = this._planService.createPlan(this.newPlanName, this.newPlanContent, this.newPlanQuery); - this._router.navigate( ['PlanView', { id: this.newPlan.id }] ); + this._router.navigate(['PlanView', { id: this.newPlan.id }]); } prefill() { - this.newPlanName = 'Sample plan'; - this.newPlanContent = SAMPLE_JSON; - this.newPlanQuery = SAMPLE_QUERY; - } + this.newPlanName = 'Sample plan'; + this.newPlanContent = SAMPLE_JSON; + this.newPlanQuery = SAMPLE_QUERY; + } } export var SAMPLE_JSON = `[ { |