1
- import { Component , Input , OnChanges } from '@angular/core' ;
1
+ import { Component , Input , OnChanges , OnInit } from '@angular/core' ;
2
2
import { ConnectMethod , ConnectOption , Protocol , Setting } from '@app/model' ;
3
3
import { resolutionsChoices } from '@app/globals' ;
4
4
import { SettingService } from '@app/services' ;
@@ -8,24 +8,22 @@ import {SettingService} from '@app/services';
8
8
templateUrl : './advanced-option.component.html' ,
9
9
styleUrls : [ './advanced-option.component.scss' ] ,
10
10
} )
11
- export class ElementAdvancedOptionComponent implements OnChanges {
11
+ export class ElementAdvancedOptionComponent implements OnChanges , OnInit {
12
12
@Input ( ) protocol : Protocol ;
13
13
@Input ( ) connectMethod : ConnectMethod ;
14
- @Input ( ) connectOption : Object = { } ;
14
+ @Input ( ) connectOption : any = { } ;
15
15
public advancedOptions : ConnectOption [ ] = [ ] ;
16
16
public isShowAdvancedOption = false ;
17
17
public setting : Setting ;
18
+ private allOptions : ConnectOption [ ] = [ ] ;
18
19
private boolChoices = [
19
20
{ label : 'Yes' , value : true } ,
20
21
{ label : 'No' , value : false } ,
21
22
] ;
22
23
23
24
constructor ( public _settingSvc : SettingService ) {
24
25
this . setting = _settingSvc . setting ;
25
- }
26
-
27
- ngOnChanges ( ) {
28
- this . advancedOptions = [
26
+ this . allOptions = [
29
27
{
30
28
type : 'select' ,
31
29
field : 'charset' ,
@@ -96,7 +94,6 @@ export class ElementAdvancedOptionComponent implements OnChanges {
96
94
if ( ! this . _settingSvc . hasXPack ( ) ) {
97
95
return true ;
98
96
}
99
-
100
97
return ! this . connectMethod || this . connectMethod . component !== 'tinker' ;
101
98
}
102
99
} ,
@@ -113,20 +110,40 @@ export class ElementAdvancedOptionComponent implements OnChanges {
113
110
if ( ! this . _settingSvc . globalSetting . CONNECTION_TOKEN_REUSABLE ) {
114
111
return true ;
115
112
}
116
- return this . connectMethod . component !== 'tinker' && this . connectMethod . component !== 'razor' ;
113
+ if ( this . connectMethod . component === 'razor' ) {
114
+ return false ;
115
+ }
116
+ if ( this . connectMethod . component === 'tinker' ) {
117
+ return this . connectOption . appletConnectMethod !== 'client' ;
118
+ }
119
+ return true ;
117
120
}
118
121
}
119
122
] ;
123
+ }
124
+
125
+ ngOnInit ( ) {
126
+ }
127
+
128
+ checkOptions ( ) {
120
129
const onlyUsingDefaultFields = [ 'reusable' ] ;
121
- onlyUsingDefaultFields . forEach ( i => {
122
- this . connectOption [ i ] = this . advancedOptions . find ( j => j . field === i ) . value ;
123
- } ) ;
124
- this . advancedOptions = this . advancedOptions . filter ( i => ! i . hidden ( ) ) ;
125
- this . advancedOptions . forEach ( i => {
130
+ this . allOptions . forEach ( i => {
126
131
if ( this . connectOption [ i . field ] === undefined ) {
127
132
this . connectOption [ i . field ] = i . value ;
128
133
}
134
+ if ( onlyUsingDefaultFields . includes ( i . field ) ) {
135
+ i . value = this . connectOption [ i . field ] ;
136
+ }
129
137
} ) ;
138
+ this . advancedOptions = this . allOptions . filter ( i => ! i . hidden ( ) ) ;
130
139
this . isShowAdvancedOption = this . advancedOptions . length > 0 ;
131
140
}
141
+
142
+ onChange ( ) {
143
+ this . checkOptions ( ) ;
144
+ }
145
+
146
+ ngOnChanges ( ) {
147
+ this . checkOptions ( ) ;
148
+ }
132
149
}
0 commit comments