From 781479ea7f793c8d075caee53f6413a1d2e85307 Mon Sep 17 00:00:00 2001 From: Alex Tatiyants Date: Fri, 29 Jan 2016 21:33:19 -0800 Subject: add plan validation --- app/components/plan-new/plan-new.html | 1 + app/components/plan-new/plan-new.ts | 21 +++++++++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) (limited to 'app/components/plan-new') 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 @@ +

{{validationMessage}}

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 = `[ { -- cgit v1.2.3