feat: support for European numeric formats

This commit is contained in:
Mihajlo Medjedovic 2023-07-28 20:03:41 +02:00
parent c74378423d
commit e48e47bc63
8 changed files with 406 additions and 349 deletions

719
client/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -69,7 +69,6 @@
"ngx-clipboard": "^16.0.0",
"ngx-json-viewer": "file:libraries/ngx-json-viewer-3.2.1.tgz",
"nodejs": "0.0.0",
"numbro": "^2.1.1",
"os-browserify": "0.3.0",
"rxjs": "^7.8.0",
"save-svg-as-png": "^1.4.17",

View File

@ -1,5 +1,5 @@
declare module 'save-svg-as-png'
declare module 'numbro/dist/languages.min'
declare interface Navigator {
msSaveBlob: (blob: any, defaultName?: string) => boolean
}

View File

@ -385,7 +385,6 @@
[class.hidden]="hotTable.hidden"
[licenseKey]="hotTable.licenseKey"
>
<!--[licenseKey]=""-->
</hot-table>
</div>

View File

@ -63,6 +63,8 @@ import {
} from './utils/renderers.utils'
import { isStringDecimal, isStringNumber } from './utils/types.utils'
import { LicenceService } from '../services/licence.service'
import * as numbro from 'numbro';
import * as languages from 'numbro/dist/languages.min';
@Component({
selector: 'app-editor',
@ -362,6 +364,9 @@ export class EditorComponent implements OnInit, AfterViewInit {
private cdf: ChangeDetectorRef,
private hotRegisterer: HotTableRegisterer
) {
const lang = languages[window.navigator.language]
if (lang) numbro.default.registerLanguage(languages[window.navigator.language])
this.hotRegisterer = new HotTableRegisterer()
this.parseRestrictions()

View File

@ -19,6 +19,7 @@ import { mergeColsRules } from './utils/mergeColsRules'
import { parseColType } from './utils/parseColType'
import { dqValidate } from './validations/dq-validation'
import { specialMissingNumericValidator } from './validations/hot-custom-validators'
import { applyNumericFormats } from './utils/applyNumericFormats'
export class DcValidator {
private rules: DcValidation[] = []
@ -41,6 +42,7 @@ export class DcValidator {
this.hotInstance = hotInstance
this.rules = parseColType(sasparams.COLTYPE)
this.rules = mergeColsRules(cols, this.rules, $dataFormats)
this.rules = applyNumericFormats(this.rules)
this.dqrules = dqRules
this.dqdata = dqData
this.primaryKeys = sasparams.PK.split(' ')

View File

@ -0,0 +1,23 @@
import { DcValidation } from '../models/dc-validation.model'
import * as languages from 'numbro/dist/languages.min';
/**
* Applying the numeric formats based on the browser locale/language
* @param rules rules to be updated
*/
export const applyNumericFormats = (
rules: DcValidation[]
): DcValidation[] => {
const lang = languages[window.navigator.language]
if (!lang) return rules
for (let rule of rules) {
if (rule.type === 'numeric') rule.numericFormat = {
pattern: '0,0',
culture: window.navigator.language // use this for EUR (German),
// more cultures available on http://numbrojs.com/languages.html
}
}
return rules
}

View File

@ -18,4 +18,4 @@ In any case, you must not make any such use of this software as to develop softw
UNLESS EXPRESSLY AGREED OTHERWISE, 4GL APPS PROVIDES THIS SOFTWARE ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, AND IN NO EVENT AND UNDER NO LEGAL THEORY, SHALL 4GL APPS BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES OF ANY CHARACTER ARISING FROM USE OR INABILITY TO USE THIS SOFTWARE.
`
`