Skip to content

Commit

Permalink
spring-cloudgh-714 Show DSL validation errors in the CTR UI
Browse files Browse the repository at this point in the history
  • Loading branch information
BoykoAlex authored and ghillert committed Apr 16, 2018
1 parent b8ae583 commit 04760df
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
2 changes: 1 addition & 1 deletion ui/src/app/tasks/flo/tools.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export class ToolsService {
graph = new Graph(nodes, links);
}

return new TaskConversion(body.dsl, null, graph);
return new TaskConversion(body.dsl, body.errors, graph);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ import { NgBusyModule } from 'ng-busy';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { MockSharedAppService } from '../../tests/mocks/shared-app';
import { MockToolsService } from '../../tests/mocks/mock-tools';
import { ToolsService } from '../flo/tools.service';

/**
/**cc
* Test {@link TaskCreateComposedTaskComponent}.
*
* @author Janne Valkealahti
Expand All @@ -23,6 +24,7 @@ describe('TaskCreateComposedTaskComponent', () => {
let fixture: ComponentFixture<TaskCreateComposedTaskComponent>;
let activeRoute: MockActivatedRoute;
const metamodelService = new MetamodelService(new MockSharedAppService(), new MockToolsService());
const toolsService = new MockToolsService();

const commonTestParams = { id: '1' };

Expand All @@ -45,7 +47,8 @@ describe('TaskCreateComposedTaskComponent', () => {
{provide: RenderService},
{provide: EditorService},
{provide: BsModalService},
{provide: ContentAssistService}
{provide: ContentAssistService},
{provide: ToolsService, useValue: toolsService}
]
})
.compileComponents();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { RenderService } from '../flo/render.service';
import { EditorService } from '../flo/editor.service';
import { TaskCreateComposedTaskDialogComponent } from './task-create-composed-task-dialog.component';
import * as CodeMirror from 'codemirror';
import {ToolsService} from "../flo/tools.service";

/**
* Component handling a creation of a composed task.
Expand Down Expand Up @@ -35,7 +36,8 @@ export class TaskCreateComposedTaskComponent implements OnInit, OnDestroy {
constructor(public metamodelService: MetamodelService,
public renderService: RenderService,
public editorService: EditorService,
private bsModalService: BsModalService) {
private bsModalService: BsModalService,
private toolsService: ToolsService) {

this.validationMarkers = new Map();

Expand Down Expand Up @@ -101,7 +103,34 @@ export class TaskCreateComposedTaskComponent implements OnInit, OnDestroy {
severity: Flo.Severity[m.severity].toLowerCase()
}))
);
updateLintingCallback(editor, annotations);
const dslText = this.dsl;
this.toolsService.parseTaskTextToGraph(dslText).toPromise().then(taskConversion => {
if (taskConversion.errors) {
taskConversion.errors.forEach(e => annotations.push({
from: this.getPosition(dslText, e['position']),
to: e['length'] ? this.getPosition(dslText, e['position'] + e['length'])
: this.getPosition(dslText, e['position'] + 1),
message: e['message'],
severity: 'error'
}));
}
updateLintingCallback(editor, annotations);
}).catch(error => updateLintingCallback(editor, annotations));
}

getPosition(text: string, offset: number): CodeMirror.Position {
let lineStartPosition = 0;
let lineNumber = 0;
for (let p = 0; p < offset; p++) {
if (text.charAt(p) === '\n') {
lineNumber++;
lineStartPosition = p + 1;
}
}
return {
line: lineNumber,
ch: offset - lineStartPosition
};
}

get isCreateComposedTaskDisabled(): boolean {
Expand Down

0 comments on commit 04760df

Please sign in to comment.