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:
commit
8c2ee441fc
719
client/package-lock.json
generated
719
client/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -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",
|
||||
|
2
client/src/app/app.d.ts
vendored
2
client/src/app/app.d.ts
vendored
@ -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
|
||||
}
|
||||
|
@ -385,7 +385,6 @@
|
||||
[class.hidden]="hotTable.hidden"
|
||||
[licenseKey]="hotTable.licenseKey"
|
||||
>
|
||||
<!--[licenseKey]=""-->
|
||||
</hot-table>
|
||||
</div>
|
||||
|
||||
|
@ -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,10 @@ 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()
|
||||
|
@ -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(' ')
|
||||
|
@ -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
|
||||
}
|
@ -6,7 +6,8 @@ import { DcValidation } from '../models/dc-validation.model'
|
||||
* Merging old validation params from sasparams with cols params
|
||||
* @param sasparams sasparams 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
|
||||
*/
|
||||
export const mergeColsRules = (
|
||||
|
Loading…
Reference in New Issue
Block a user