11
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
12
// See the License for the specific language governing permissions and
13
13
// limitations under the License.
14
- import { Component , OnInit } from '@angular/core' ;
14
+ import { Component , OnInit , ViewChild } from '@angular/core' ;
15
15
import { TranslateService } from '@ngx-translate/core' ;
16
16
import {
17
17
getContainerRuntime ,
18
+ getCustomContainerRuntime ,
18
19
getDatetimeRendering ,
19
20
} from 'src/app/shared/units/shared.utils' ;
20
21
import { registerLocaleData } from '@angular/common' ;
@@ -23,6 +24,7 @@ import { map } from 'rxjs/operators';
23
24
import { ClrCommonStrings } from '@clr/angular/utils/i18n/common-strings.interface' ;
24
25
import { ClrCommonStringsService } from '@clr/angular' ;
25
26
import {
27
+ CUSTOM_RUNTIME_LOCALSTORAGE_KEY ,
26
28
DATETIME_RENDERINGS ,
27
29
DatetimeRendering ,
28
30
DEFAULT_DATETIME_RENDERING_LOCALSTORAGE_KEY ,
@@ -37,6 +39,8 @@ import {
37
39
SupportedLanguage ,
38
40
SupportedRuntime ,
39
41
} from '../../shared/entities/shared.const' ;
42
+ import { NgForm } from '@angular/forms' ;
43
+ import { InlineAlertComponent } from 'src/app/shared/components/inline-alert/inline-alert.component' ;
40
44
41
45
@Component ( {
42
46
selector : 'preference-settings' ,
@@ -45,12 +49,21 @@ import {
45
49
} )
46
50
export class PreferenceSettingsComponent implements OnInit {
47
51
readonly guiLanguages = Object . entries ( LANGUAGES ) ;
48
- readonly guiRuntimes = Object . entries ( RUNTIMES ) ;
52
+ readonly guiRuntimes = Object . entries ( RUNTIMES ) . filter (
53
+ ( [ _ , value ] ) => value !== RUNTIMES . custom
54
+ ) ;
49
55
readonly guiDatetimeRenderings = Object . entries ( DATETIME_RENDERINGS ) ;
50
56
selectedLang : SupportedLanguage = DeFaultLang ;
51
57
selectedRuntime : SupportedRuntime = DeFaultRuntime ;
52
58
selectedDatetimeRendering : DatetimeRendering = DefaultDatetimeRendering ;
53
59
opened : boolean = false ;
60
+ error : any = null ;
61
+ customRuntime : string = '' ;
62
+
63
+ @ViewChild ( 'customruntimeForm' , { static : false } )
64
+ customRuntimeForm : NgForm ;
65
+ @ViewChild ( InlineAlertComponent , { static : true } )
66
+ inlineAlert : InlineAlertComponent ;
54
67
55
68
constructor (
56
69
private translate : TranslateService ,
@@ -68,6 +81,27 @@ export class PreferenceSettingsComponent implements OnInit {
68
81
}
69
82
this . selectedDatetimeRendering = getDatetimeRendering ( ) ;
70
83
this . selectedRuntime = getContainerRuntime ( ) ;
84
+ this . customRuntime = getCustomContainerRuntime ( ) ;
85
+ }
86
+
87
+ // Check If form is valid
88
+ public get isValid ( ) : boolean {
89
+ const customPrefixControl =
90
+ this . customRuntimeForm ?. form . get ( 'customPrefix' ) ;
91
+
92
+ return (
93
+ customPrefixControl ?. valid &&
94
+ customPrefixControl ?. value ?. trim ( ) !== '' &&
95
+ this . error === null
96
+ ) ;
97
+ }
98
+
99
+ addCustomRuntime ( ) {
100
+ if ( this . customRuntime . trim ( ) ) {
101
+ const customRuntimeValue = this . customRuntime . trim ( ) ;
102
+ this . switchRuntime ( 'custom' ) ;
103
+ this . switchCustomRuntime ( customRuntimeValue ) ;
104
+ }
71
105
}
72
106
73
107
//Internationalization for Clarity components, refer to https://clarity.design/documentation/internationalization
@@ -137,6 +171,10 @@ export class PreferenceSettingsComponent implements OnInit {
137
171
localStorage . setItem ( DEFAULT_RUNTIME_LOCALSTORAGE_KEY , runtime ) ;
138
172
}
139
173
174
+ switchCustomRuntime ( runtime : SupportedRuntime ) : void {
175
+ localStorage . setItem ( CUSTOM_RUNTIME_LOCALSTORAGE_KEY , runtime ) ;
176
+ }
177
+
140
178
switchDatetimeRendering ( datetime : DatetimeRendering ) : void {
141
179
this . selectedDatetimeRendering = datetime ;
142
180
localStorage . setItem (
0 commit comments