From a44b2ea816b621c09960db278ed9aae4780d465b Mon Sep 17 00:00:00 2001 From: Sipachev Igor Date: Tue, 9 Mar 2021 12:52:49 +0700 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=B2=D1=8B=D0=B1=D0=BE=D1=80=20=D0=B4=D0=BD=D1=8F=20=D1=80?= =?UTF-8?q?=D0=BE=D0=B6=D0=B4=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- popup/src/classes/DTO/Birthday.ts | 5 ++ popup/src/classes/DTO/Person.ts | 2 + .../Service/Generators/PersonalIdGenerator.ts | 50 +++++++++---------- popup/src/components/script.ts | 22 ++++++-- popup/src/components/style.scss | 5 ++ popup/src/components/template.html | 15 ++++++ 6 files changed, 70 insertions(+), 29 deletions(-) create mode 100644 popup/src/classes/DTO/Birthday.ts diff --git a/popup/src/classes/DTO/Birthday.ts b/popup/src/classes/DTO/Birthday.ts new file mode 100644 index 0000000..b8260cc --- /dev/null +++ b/popup/src/classes/DTO/Birthday.ts @@ -0,0 +1,5 @@ +export class Birthday { + day: bigint | null = null + month: bigint | null = null + year: bigint | null = null +} diff --git a/popup/src/classes/DTO/Person.ts b/popup/src/classes/DTO/Person.ts index 84677fc..7706b13 100644 --- a/popup/src/classes/DTO/Person.ts +++ b/popup/src/classes/DTO/Person.ts @@ -1,7 +1,9 @@ import { Country } from '@/classes/Enum/Country' import { Gender } from '@/classes/Enum/Gender' +import { Birthday } from '@/classes/DTO/Birthday' export class Person { + birthday: Birthday = new Birthday() country: Country = Country.ESTONIA gender: Gender = Gender.RANDOM } diff --git a/popup/src/classes/Service/Generators/PersonalIdGenerator.ts b/popup/src/classes/Service/Generators/PersonalIdGenerator.ts index 26489b7..4b832e8 100644 --- a/popup/src/classes/Service/Generators/PersonalIdGenerator.ts +++ b/popup/src/classes/Service/Generators/PersonalIdGenerator.ts @@ -1,29 +1,19 @@ import randomGenerator from './RandomGenerator' import { Country } from '../../Enum/Country' import { Gender } from '../../Enum/Gender' +import { Person } from '@/classes/DTO/Person' export class PersonalIdGenerator { /** - * return e.generate = function (e, t) { - var - n = this.getYearPart(), - r = this.getMonthPart(), - i = this.getDayPart(), - o = this.getIdNumPart(), - a = this.getGenderPart(e, t), - l = this.getControlSum(e, n, r, i, o, a); - return "pl" === e ? n + r + i + o + a + l : a + n + r + i + o + l - }, - * @param country - * @param gender + * @param person */ - generate (country: Country, gender: Gender) { - const year = this.getYearPart() - const month = this.getMonthPart() - const day = this.getDayPart() + generate (person: Person) { + const year = this.getYearPart(person.birthday.year) + const month = this.getMonthPart(person.birthday.month) + const day = this.getDayPart(person.birthday.day) const o = this.getIdNumPart() - const a = this.getGenderPart(country, gender) - const l = this.getControlSum(country, year, month, day, o, a) + const a = this.getGenderPart(person.country, person.gender) + const l = this.getControlSum(person.country, year, month, day, o, a) const l2 = this.getChecksum(a + year + month + day + o) return a + year + month + day + o + l2 @@ -35,9 +25,13 @@ export class PersonalIdGenerator { return String(Iu.generate(e - 25, e - 55)).substring(2, 4) }, */ - getYearPart () { - const e = (new Date()).getFullYear() - return String(randomGenerator.generate(e - 25, e - 55)).substring(2, 4) + getYearPart (year: bigint | null) { + if (!year) { + const e = (new Date()).getFullYear() + year = BigInt(randomGenerator.generate(e - 25, e - 55)) + } + + return String(year).substring(2, 4) } /** @@ -45,8 +39,11 @@ export class PersonalIdGenerator { return Iu.generate(1, 12).toString().padStart(2, "0") }, */ - getMonthPart () { - return randomGenerator.generate(1, 12).toString().padStart(2, '0') + getMonthPart (month: bigint | null) { + if (!month) { + month = BigInt(randomGenerator.generate(1, 12)) + } + return month.toString().padStart(2, '0') } /** @@ -54,8 +51,11 @@ export class PersonalIdGenerator { return Iu.generate(1, 28).toString().padStart(2, "0") }, */ - getDayPart () { - return randomGenerator.generate(1, 28).toString().padStart(2, '0') + getDayPart (day: bigint | null) { + if (!day) { + day = BigInt(randomGenerator.generate(1, 28)) + } + return day.toString().padStart(2, '0') } /** diff --git a/popup/src/components/script.ts b/popup/src/components/script.ts index 9a17ae8..f082c6a 100644 --- a/popup/src/components/script.ts +++ b/popup/src/components/script.ts @@ -18,20 +18,34 @@ export default class HelloWorld extends Vue { person = new Person() copyText = '' + get allowedMonths () { + const result = [] + for (let i = 1; i <= 12; i++) { + result.push(i) + } + return result + } + + get allowedYears () { + const result = [] + const currentYear = (new Date()).getFullYear() + for (let i = 1960; i <= currentYear; i++) { + result.push(i) + } + return result + } + copyPersonalId () { - console.log(JSON.stringify(this.person)) - const personalId = personalIdGenerator.generate(this.person.country, this.person.gender) + const personalId = personalIdGenerator.generate(this.person) this.copy(personalId) } copyIban () { - console.log(JSON.stringify(this.person)) const iban = ibanGenerator.generate(this.person.country) this.copy(iban) } copyPhone () { - console.log(JSON.stringify(this.person)) const phone = phoneGenerator.generate(this.person.country) this.copy(phone) } diff --git a/popup/src/components/style.scss b/popup/src/components/style.scss index d679eb2..43e8ca0 100644 --- a/popup/src/components/style.scss +++ b/popup/src/components/style.scss @@ -42,6 +42,11 @@ &__item { flex-grow: 1; + margin-right: 10px; + + &-input { + width: 100%; + } } &:last-child { diff --git a/popup/src/components/template.html b/popup/src/components/template.html index 3846c7c..ef31a6e 100644 --- a/popup/src/components/template.html +++ b/popup/src/components/template.html @@ -10,6 +10,21 @@
+
+
+ +
+
+ +
+
+ +
+