@@ -75,7 +75,6 @@ export default class DeployLabelController {
75
75
addIfNeeded_ ( ) {
76
76
/** @type {!DeployLabel } */
77
77
let lastLabel = this . labels [ this . labels . length - 1 ] ;
78
-
79
78
if ( this . isFilled_ ( lastLabel ) ) {
80
79
this . addNewLabel_ ( ) ;
81
80
}
@@ -91,41 +90,18 @@ export default class DeployLabelController {
91
90
* Validates label within label form.
92
91
* Current checks:
93
92
* - duplicated key
94
- * - key prefix pattern
95
- * - key name pattern
96
- * - key prefix length
97
- * - key name length
98
93
* @param {!angular.FormController|undefined } labelForm
99
94
* @private
100
95
*/
101
- // TODO: @digitalfishpond Move these validations to directives
102
96
validateKey_ ( labelForm ) {
103
97
if ( angular . isDefined ( labelForm ) ) {
104
98
/** @type {!angular.NgModelController } */
105
99
let elem = labelForm . key ;
106
- /** @type {!RegExp } */
107
- let PrefixPattern = / ^ ( .* \/ .* ) $ / ;
108
- /** @type {boolean } */
109
- let isPrefixed = PrefixPattern . test ( this . label . key ) ;
110
- /** @type {number } */
111
- let slashPosition = isPrefixed ? this . label . key . indexOf ( '/' ) : - 1 ;
112
100
113
101
/** @type {boolean } */
114
102
let isUnique = ! this . isKeyDuplicated_ ( ) ;
115
- /** @type {boolean } */
116
- let isKeyPrefixPatternOk = this . matchesKeyPrefixPattern_ ( isPrefixed , slashPosition ) ;
117
- /** @type {boolean } */
118
- let isKeyNamePatternOk = this . matchesKeyNamePattern_ ( isPrefixed , slashPosition ) ;
119
- /** @type {boolean } */
120
- let isKeyPrefixLengthOk = this . matchesKeyPrefixLength_ ( isPrefixed , slashPosition ) ;
121
- /** @type {boolean } */
122
- let isKeyNameLengthOk = this . matchesKeyNameLength_ ( isPrefixed , slashPosition ) ;
123
103
124
104
elem . $setValidity ( 'unique' , isUnique ) ;
125
- elem . $setValidity ( 'prefixPattern' , isKeyPrefixPatternOk ) ;
126
- elem . $setValidity ( 'namePattern' , isKeyNamePatternOk ) ;
127
- elem . $setValidity ( 'prefixLength' , isKeyPrefixLengthOk ) ;
128
- elem . $setValidity ( 'nameLength' , isKeyNameLengthOk ) ;
129
105
}
130
106
}
131
107
@@ -148,84 +124,6 @@ export default class DeployLabelController {
148
124
return duplications > 1 ;
149
125
}
150
126
151
- /**
152
- * Returns true if the label key prefix (before the "/" if there is one) matches a lowercase
153
- * alphanumeric character
154
- * optionally followed by lowercase alphanumeric or '-' or '.' and ending with a lower case
155
- * alphanumeric character,
156
- * with '.' only permitted if surrounded by lowercase alphanumeric characters (eg:
157
- * 'good.prefix-pattern',
158
- * otherwise returns false.
159
- * @return {boolean }
160
- * @param {boolean } isPrefixed
161
- * @param {number } slashPosition
162
- * @private
163
- */
164
- matchesKeyPrefixPattern_ ( isPrefixed , slashPosition ) {
165
- /** @type {!RegExp } */
166
- let labelKeyPrefixPattern = / ^ [ a - z 0 - 9 ] ( [ - a - z 0 - 9 ] * [ a - z 0 - 9 ] ) ? ( \. [ a - z 0 - 9 ] ( [ - a - z 0 - 9 ] * [ a - z 0 - 9 ] ) ? ) * $ / ;
167
- /** @type {string } */
168
- let labelPrefix = isPrefixed ? this . label . key . substring ( 0 , slashPosition ) : 'valid-pattern' ;
169
-
170
- return ( labelKeyPrefixPattern . test ( labelPrefix ) ) ;
171
- }
172
-
173
- /**
174
- * Returns true if the label key name (after the "/" if there is one) matches an alphanumeric
175
- * character (upper
176
- * or lower case) optionally followed by alphanumeric or -_. and ending with an alphanumeric
177
- * character
178
- * (upper or lower case), otherwise returns false.
179
- * @return {boolean }
180
- * @param {boolean } isPrefixed
181
- * @param {number } slashPosition
182
- * @private
183
- */
184
- matchesKeyNamePattern_ ( isPrefixed , slashPosition ) {
185
- /** @type {!RegExp } */
186
- let labelKeyNamePattern = / ^ ( [ A - Z a - z 0 - 9 ] [ - A - Z a - z 0 - 9 _ . ] * ) ? [ A - Z a - z 0 - 9 ] $ / ;
187
- /** @type {string } */
188
- let labelName = isPrefixed ? this . label . key . substring ( slashPosition + 1 ) : this . label . key ;
189
-
190
- return ( labelKeyNamePattern . test ( labelName ) ) ;
191
- }
192
-
193
- /**
194
- * Returns true if the label key name (after the "/" if there is one) is equal or shorter than 253
195
- * characters,
196
- * otherwise returns false.
197
- * @return {boolean }
198
- * @param {boolean } isPrefixed
199
- * @param {number } slashPosition
200
- * @private
201
- */
202
- matchesKeyPrefixLength_ ( isPrefixed , slashPosition ) {
203
- /** @type {number } */
204
- let maxLength = 253 ;
205
- /** @type {string } */
206
- let labelPrefix = isPrefixed ? this . label . key . substring ( 0 , slashPosition ) : '' ;
207
-
208
- return ( labelPrefix . length <= maxLength ) ;
209
- }
210
-
211
- /**
212
- * Returns true if the label key name (after the "/" if there is one) is equal or shorter than 63
213
- * characters,
214
- * otherwise returns false.
215
- * @return {boolean }
216
- * @param {boolean } isPrefixed
217
- * @param {number } slashPosition
218
- * @private
219
- */
220
- matchesKeyNameLength_ ( isPrefixed , slashPosition ) {
221
- /** @type {number } */
222
- let maxLength = 63 ;
223
- /** @type {string } */
224
- let labelName = isPrefixed ? this . label . key . substring ( slashPosition + 1 ) : this . label . key ;
225
-
226
- return ( labelName . length <= maxLength ) ;
227
- }
228
-
229
127
/**
230
128
* Returns true if label key and value are not empty, false otherwise.
231
129
* @param {!DeployLabel } label
0 commit comments