Skip to content

Commit f90ecab

Browse files
committed
Remove redundant api from Flo added in previous commit
1 parent c4388d3 commit f90ecab

File tree

6 files changed

+124
-104
lines changed

6 files changed

+124
-104
lines changed

package.json

+18-19
Original file line numberDiff line numberDiff line change
@@ -41,38 +41,37 @@
4141
"ts-disposables": "2.2.3"
4242
},
4343
"devDependencies": {
44-
"@angular-devkit/build-angular": "0.1102.6",
45-
"@angular-devkit/schematics": "~11.2.6",
46-
"@angular/animations": "~11.2.7",
47-
"@angular/cli": "~11.2.6",
48-
"@angular/common": "~11.2.7",
49-
"@angular/compiler": "~11.2.7",
50-
"@angular/compiler-cli": "~11.2.7",
51-
"@angular/core": "~11.2.7",
52-
"@angular/forms": "~11.2.7",
53-
"@angular/platform-browser": "~11.2.7",
54-
"@angular/platform-browser-dynamic": "~11.2.7",
55-
"@angular/platform-server": "~11.2.7",
44+
"@angular-devkit/build-angular": "~12.0.0",
45+
"@angular-devkit/schematics": "~12.0.0",
46+
"@angular/animations": "~12.0.0",
47+
"@angular/cli": "~12.0.0",
48+
"@angular/common": "~12.0.0",
49+
"@angular/compiler": "~12.0.0",
50+
"@angular/compiler-cli": "~12.0.0",
51+
"@angular/core": "~12.0.0",
52+
"@angular/forms": "~12.0.0",
53+
"@angular/platform-browser": "~12.0.0",
54+
"@angular/platform-browser-dynamic": "~12.0.0",
55+
"@angular/platform-server": "~12.0.0",
5656
"@types/backbone": "1.3.42",
5757
"@types/codemirror": "0.0.64",
5858
"@types/jasmine": "2.5.36",
5959
"@types/jquery": "3.5.4",
6060
"@types/lodash": "4.14.165",
6161
"@types/node": "12.11.1",
6262
"cpr": "^3.0.1",
63-
"fibers": "^4.0.2",
63+
"fibers": "^5.0.0",
6464
"html-webpack-plugin": "^3.2.0",
65-
"jshint": "2.10.2",
66-
"ng-packagr": "11.2.4",
67-
"ngx-bootstrap": "6.0.0",
65+
"ng-packagr": "^12.0.0",
66+
"ngx-bootstrap": "^6.2.0",
6867
"node-sass": "^4.13.1",
6968
"rimraf": "2.6.1",
70-
"rxjs": "~6.6.7",
69+
"rxjs": "~6.5.3",
7170
"scss-bundle": "^3.0.2",
7271
"standard-version": "^9.0.0",
7372
"tslib": "^2.0.3",
7473
"tslint": "^6.1.3",
75-
"typescript": "4.1.5",
76-
"zone.js": "~0.11.3"
74+
"typescript": "~4.2.4",
75+
"zone.js": "~0.11.4"
7776
}
7877
}

src/demo/app/app.component.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ <h3>Meaning is: {{meaning}}</h3>
1010
<flo-editor (floApi)="editorContext = $event" [metamodel]="metamodel" [renderer]="renderer" [editor]="editor"
1111
[paletteSize]="paletteSize" [paletteEntryPadding]="{width: 4, height: 4}" [(dsl)]="dsl"
1212
[paperPadding]="20" (validationMarkers)="markersChanged($event)" searchFilterPlaceHolder="Apps..."
13-
(onProperties)="editor.openPropertiesDialog($event)">
13+
(onProperties)="openPropertiesDialog($event)">
1414
<div header>
1515
<div id="controls" class="controls">
1616
<button class="button" id="clearGraph" (click)="editorContext.clearGraph()">Create New Flow</button>

src/demo/app/app.component.ts

+12-6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import 'codemirror-minified/mode/javascript/javascript';
1010
import 'codemirror-minified/mode/ruby/ruby';
1111
import 'codemirror-minified/mode/clike/clike';
1212
import 'codemirror-minified/addon/lint/javascript-lint';
13+
import {PropertiesEditorService} from './properties-editor.service';
14+
import {dia} from 'jointjs';
1315

1416
@Component({
1517
selector: 'demo-app',
@@ -19,20 +21,20 @@ import 'codemirror-minified/addon/lint/javascript-lint';
1921
})
2022
export class AppComponent {
2123

22-
metamodel : Flo.Metamodel;
23-
renderer : Flo.Renderer;
24-
editor : Flo.Editor;
25-
dsl : string;
24+
metamodel: Flo.Metamodel;
25+
renderer: Flo.Renderer;
26+
editor: Flo.Editor;
27+
dsl: string;
2628
dslEditor = false;
2729

2830
editorContext: Flo.EditorContext;
2931

3032
paletteSize = 170;
3133

32-
constructor(private modelService : BsModalService) {
34+
constructor(private propertiesEditor: PropertiesEditorService) {
3335
this.metamodel = new Metamodel();
3436
this.renderer = new Renderer();
35-
this.editor = new Editor(modelService);
37+
this.editor = new Editor(propertiesEditor);
3638
this.dsl = '';
3739
}
3840

@@ -43,4 +45,8 @@ export class AppComponent {
4345
markersChanged(markers: Map<string, Array<Flo.Marker>>) {
4446
console.log('MARKERS: ' + JSON.stringify(markers));
4547
}
48+
49+
openPropertiesDialog(cell: dia.Cell) {
50+
this.propertiesEditor.openPropertiesDialog(cell)
51+
}
4652
}

src/demo/app/editor.ts

+4-77
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,9 @@
1515
*/
1616

1717
import { Flo, Constants, Properties } from 'spring-flo';
18-
import { Validators } from '@angular/forms';
1918
import { dia, g } from 'jointjs';
20-
import { BsModalService } from 'ngx-bootstrap/modal';
21-
import { PropertiesDialogComponent } from './properties.dialog.component';
22-
const joint : any = Flo.joint;
19+
import {PropertiesEditorService} from './properties-editor.service';
20+
const joint: any = Flo.joint;
2321

2422
/**
2523
* @author Alex Boyko
@@ -44,7 +42,7 @@ export class Editor implements Flo.Editor {
4442
};
4543
}
4644

47-
constructor(private modelService : BsModalService) {}
45+
constructor(private propertiesEditor: PropertiesEditorService) {}
4846

4947
createHandles(context : Flo.EditorContext, createHandle : (owner : dia.CellView, kind : string, action : () => void, location : dia.Point) => void, owner : dia.CellView) {
5048
if (owner.model instanceof joint.dia.Element) {
@@ -55,20 +53,11 @@ export class Editor implements Flo.Editor {
5553

5654
// Properties handle
5755
if (!owner.model.get('metadata')?.unresolved) {
58-
createHandle(owner, Constants.PROPERTIES_HANDLE_TYPE, () => this.openPropertiesDialog(owner.model), bbox.origin().offset(-14, bbox.height + 3));
56+
createHandle(owner, Constants.PROPERTIES_HANDLE_TYPE, () => this.propertiesEditor.openPropertiesDialog(owner.model), bbox.origin().offset(-14, bbox.height + 3));
5957
}
6058
}
6159
}
6260

63-
openPropertiesDialog(cell: dia.Cell) {
64-
let bsModalRef = this.modelService.show(PropertiesDialogComponent);
65-
let metadata : Flo.ElementMetadata = cell.get('metadata');
66-
bsModalRef.content.title = `Properties for ${metadata.name.toUpperCase()}`;
67-
let propertiesModel = new SamplePropertiesGroupModel(new Properties.DefaultCellPropertiesSource(cell));
68-
propertiesModel.load();
69-
bsModalRef.content.propertiesGroupModel = propertiesModel;
70-
}
71-
7261
validatePort(context: Flo.EditorContext, view : dia.ElementView, magnet : SVGElement) {
7362
return true;
7463
}
@@ -561,65 +550,3 @@ export class Editor implements Flo.Editor {
561550
}
562551

563552
}
564-
565-
class SamplePropertiesGroupModel extends Properties.PropertiesGroupModel {
566-
protected createControlModel(property : Properties.Property) : Properties.ControlModel<any> {
567-
let inputType = Properties.InputType.TEXT;
568-
let validation : Properties.Validation;
569-
switch (property.type) {
570-
case 'number':
571-
inputType = Properties.InputType.NUMBER;
572-
break;
573-
case 'url':
574-
inputType = Properties.InputType.URL;
575-
break;
576-
case 'password':
577-
inputType = Properties.InputType.PASSWORD;
578-
break;
579-
case 'boolean':
580-
return new Properties.CheckBoxControlModel(property);
581-
case 'e-mail':
582-
inputType = Properties.InputType.EMAIL;
583-
break;
584-
case 'list':
585-
case 'list[number]':
586-
case 'list[boolean]':
587-
return new Properties.GenericListControlModel(property);
588-
case 'enum':
589-
if (Array.isArray(property.valueOptions)) {
590-
return new Properties.SelectControlModel(property, Properties.InputType.SELECT, (<Array<string>> property.valueOptions).map(o => {
591-
return {
592-
name: o,
593-
value: o === property.defaultValue ? undefined : o
594-
}
595-
}));
596-
}
597-
case 'code':
598-
return new Properties.CodeControlModelWithDynamicLanguageProperty(property, 'language', this, this.encodeTextToDSL, this.decodeTextFromDSL);
599-
default:
600-
if (property.name === 'name') {
601-
validation = {
602-
validator: Validators.required,
603-
errorData: [
604-
{ id: 'required', message: 'Name is required!' }
605-
]
606-
}
607-
}
608-
break;
609-
}
610-
return new Properties.GenericControlModel(property, inputType, validation);
611-
}
612-
613-
encodeTextToDSL(text: string): string {
614-
return '\"' + text.replace(/(?:\r\n|\r|\n)/g, '\\n').replace(/"/g, '""') + '\"';
615-
}
616-
617-
decodeTextFromDSL(dsl: string): string {
618-
if (dsl.charAt(0) === '\"' && dsl.charAt(dsl.length - 1) === '\"') {
619-
dsl = dsl.substr(1, dsl.length - 2);
620-
}
621-
return dsl.replace(/\\n/g, '\n').replace(/\"\"/g, '"');
622-
}
623-
624-
}
625-
+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import {Injectable} from '@angular/core';
2+
import {dia} from 'jointjs';
3+
import {PropertiesDialogComponent} from './properties.dialog.component';
4+
import {BsModalService} from 'ngx-bootstrap/modal';
5+
import {Flo, Properties} from '../../lib';
6+
import {Validators} from '@angular/forms';
7+
8+
9+
@Injectable({
10+
providedIn: 'root'
11+
})
12+
export class PropertiesEditorService {
13+
14+
constructor(private modalService: BsModalService) {}
15+
16+
openPropertiesDialog(cell: dia.Cell) {
17+
const bsModalRef = this.modalService.show(PropertiesDialogComponent);
18+
const metadata: Flo.ElementMetadata = cell.get('metadata');
19+
bsModalRef.content.title = `Properties for ${metadata.name.toUpperCase()}`;
20+
let propertiesModel = new SamplePropertiesGroupModel(new Properties.DefaultCellPropertiesSource(cell));
21+
propertiesModel.load();
22+
bsModalRef.content.propertiesGroupModel = propertiesModel;
23+
}
24+
25+
26+
}
27+
28+
class SamplePropertiesGroupModel extends Properties.PropertiesGroupModel {
29+
protected createControlModel(property: Properties.Property): Properties.ControlModel<any> {
30+
let inputType = Properties.InputType.TEXT;
31+
let validation: Properties.Validation;
32+
switch (property.type) {
33+
case 'number':
34+
inputType = Properties.InputType.NUMBER;
35+
break;
36+
case 'url':
37+
inputType = Properties.InputType.URL;
38+
break;
39+
case 'password':
40+
inputType = Properties.InputType.PASSWORD;
41+
break;
42+
case 'boolean':
43+
return new Properties.CheckBoxControlModel(property);
44+
case 'e-mail':
45+
inputType = Properties.InputType.EMAIL;
46+
break;
47+
case 'list':
48+
case 'list[number]':
49+
case 'list[boolean]':
50+
return new Properties.GenericListControlModel(property);
51+
case 'enum':
52+
if (Array.isArray(property.valueOptions)) {
53+
return new Properties.SelectControlModel(property, Properties.InputType.SELECT, (<Array<string>> property.valueOptions).map(o => {
54+
return {
55+
name: o,
56+
value: o === property.defaultValue ? undefined : o
57+
}
58+
}));
59+
}
60+
break;
61+
case 'code':
62+
return new Properties.CodeControlModelWithDynamicLanguageProperty(property, 'language', this, this.encodeTextToDSL, this.decodeTextFromDSL);
63+
default:
64+
if (property.name === 'name') {
65+
validation = {
66+
validator: Validators.required,
67+
errorData: [
68+
{ id: 'required', message: 'Name is required!' }
69+
]
70+
}
71+
}
72+
break;
73+
}
74+
return new Properties.GenericControlModel(property, inputType, validation);
75+
}
76+
77+
encodeTextToDSL(text: string): string {
78+
return '\"' + text.replace(/(?:\r\n|\r|\n)/g, '\\n').replace(/"/g, '""') + '\"';
79+
}
80+
81+
decodeTextFromDSL(dsl: string): string {
82+
if (dsl.charAt(0) === '\"' && dsl.charAt(dsl.length - 1) === '\"') {
83+
dsl = dsl.substr(1, dsl.length - 2);
84+
}
85+
return dsl.replace(/\\n/g, '\n').replace(/\"\"/g, '"');
86+
}
87+
88+
}
89+

src/lib/shared/flo-common.ts

-1
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,6 @@ export namespace Flo {
208208
validate?(graph: dia.Graph, dsl: string, flo: EditorContext): Promise<Map<string | number, Array<Marker>>>;
209209
preDelete?(context: EditorContext, deletedElement: dia.Cell): boolean;
210210
setDefaultContent?(editorContext: EditorContext, data: Map<string, Map<string, ElementMetadata>>): void;
211-
openPropertiesDialog(cell: dia.Cell): void;
212211
}
213212

214213
export function findMagnetByClass(view: dia.CellView, className: string): SVGElement | undefined {

0 commit comments

Comments
 (0)