Merge pull request 'Added support for European numeric formats' (#16) from issue-1 into development

Reviewed-on: #16
Reviewed-by: allan <allan@4gl.io>
This commit is contained in:
allan 2023-08-23 14:46:37 +00:00
commit 8c2ee441fc
8 changed files with 411 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-clipboard": "^16.0.0",
"ngx-json-viewer": "file:libraries/ngx-json-viewer-3.2.1.tgz", "ngx-json-viewer": "file:libraries/ngx-json-viewer-3.2.1.tgz",
"nodejs": "0.0.0", "nodejs": "0.0.0",
"numbro": "^2.1.1",
"os-browserify": "0.3.0", "os-browserify": "0.3.0",
"rxjs": "^7.8.0", "rxjs": "^7.8.0",
"save-svg-as-png": "^1.4.17", "save-svg-as-png": "^1.4.17",

View File

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

View File

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

View File

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

View File

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

View File

@ -0,0 +1,26 @@
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
* So that correct decimal separators are applied.
* For example european format (thousand dot, decimal comma): 1.000,00
*
* @param rules Cell Validation rules to be updated
* Those rules are passed in the `columns` property Of handsontable settings.
*/
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

@ -6,7 +6,8 @@ import { DcValidation } from '../models/dc-validation.model'
* Merging old validation params from sasparams with cols params * Merging old validation params from sasparams with cols params
* @param sasparams sasparams coming from SAS * @param sasparams sasparams coming from SAS
* @param cols cols coming from SAS * @param cols cols coming from SAS
* @param rules rules to be updated * @param rules Cell Validation rules to be updated
* Those rules are passed in the `columns` property Of handsontable settings.
* @returns * @returns
*/ */
export const mergeColsRules = ( export const mergeColsRules = (