15
15
*/
16
16
17
17
import { Flo , Constants , Properties } from 'spring-flo' ;
18
- import { Validators } from '@angular/forms' ;
19
18
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 ;
23
21
24
22
/**
25
23
* @author Alex Boyko
@@ -44,7 +42,7 @@ export class Editor implements Flo.Editor {
44
42
} ;
45
43
}
46
44
47
- constructor ( private modelService : BsModalService ) { }
45
+ constructor ( private propertiesEditor : PropertiesEditorService ) { }
48
46
49
47
createHandles ( context : Flo . EditorContext , createHandle : ( owner : dia . CellView , kind : string , action : ( ) => void , location : dia . Point ) => void , owner : dia . CellView ) {
50
48
if ( owner . model instanceof joint . dia . Element ) {
@@ -55,20 +53,11 @@ export class Editor implements Flo.Editor {
55
53
56
54
// Properties handle
57
55
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 ) ) ;
59
57
}
60
58
}
61
59
}
62
60
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
-
72
61
validatePort ( context : Flo . EditorContext , view : dia . ElementView , magnet : SVGElement ) {
73
62
return true ;
74
63
}
@@ -561,65 +550,3 @@ export class Editor implements Flo.Editor {
561
550
}
562
551
563
552
}
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
-
0 commit comments