diff --git a/package-lock.json b/package-lock.json index 9c99b645a..9ba78a261 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,6 +11,7 @@ "license": "AGPL-3.0-only", "dependencies": { "@angular/animations": "^14.2.6", + "@angular/cdk": "^14.2.7", "@angular/common": "^14.2.6", "@angular/compiler": "^14.2.6", "@angular/core": "^14.2.6", @@ -34,6 +35,7 @@ "easymde": "^2.18.0", "font-awesome": "^4.7.0", "issn": "^1.0.6", + "js-generate-password": "^0.1.7", "lodash-es": "^4.17.21", "marked": "^4.1.1", "moment": "^2.29.1", @@ -506,6 +508,28 @@ "@angular/core": "14.2.6" } }, + "node_modules/@angular/cdk": { + "version": "14.2.7", + "resolved": "https://registry.npmjs.org/@angular/cdk/-/cdk-14.2.7.tgz", + "integrity": "sha512-/tEsYaUbDSnfEmKVvAMramIptmhI67O+9STjOV0i+74XR2NospeK0fkbywIANu1n3w6AHGMotvRWJrjmbCElFg==", + "dependencies": { + "tslib": "^2.3.0" + }, + "optionalDependencies": { + "parse5": "^5.0.0" + }, + "peerDependencies": { + "@angular/common": "^14.0.0 || ^15.0.0", + "@angular/core": "^14.0.0 || ^15.0.0", + "rxjs": "^6.5.3 || ^7.4.0" + } + }, + "node_modules/@angular/cdk/node_modules/parse5": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/parse5/-/parse5-5.1.1.tgz", + "integrity": "sha512-ugq4DFI0Ptb+WWjAdOK16+u/nHfiIrcE+sh8kZMaM0WllQKLI9rOUq6c2b7cwPkXdzfQESqvoqK6ug7U/Yyzug==", + "optional": true + }, "node_modules/@angular/cli": { "version": "14.2.6", "resolved": "https://registry.npmjs.org/@angular/cli/-/cli-14.2.6.tgz", @@ -8684,6 +8708,14 @@ "integrity": "sha512-JVzAR/AjBvVt2BmYhxRCSYysDsPcssdmTFnzyLEts9qNwmjmu4JTAMYubEfwVOSwpQ1I1sKKFcxhZCI2buerfw==", "peer": true }, + "node_modules/js-generate-password": { + "version": "0.1.7", + "resolved": "https://registry.npmjs.org/js-generate-password/-/js-generate-password-0.1.7.tgz", + "integrity": "sha512-O2fTDgD2DSf4mnuTKO0rZ2DMgv/CkWvdboKzV5XDDLsUrmFQppbMtMkbLIEHiiXSsIdMcFdr/OAN+CXqc7TdTQ==", + "bin": { + "js-generate-password": "dist/index.js" + } + }, "node_modules/js-sdsl": { "version": "4.1.5", "resolved": "https://registry.npmjs.org/js-sdsl/-/js-sdsl-4.1.5.tgz", @@ -14149,6 +14181,23 @@ "tslib": "^2.3.0" } }, + "@angular/cdk": { + "version": "14.2.7", + "resolved": "https://registry.npmjs.org/@angular/cdk/-/cdk-14.2.7.tgz", + "integrity": "sha512-/tEsYaUbDSnfEmKVvAMramIptmhI67O+9STjOV0i+74XR2NospeK0fkbywIANu1n3w6AHGMotvRWJrjmbCElFg==", + "requires": { + "parse5": "^5.0.0", + "tslib": "^2.3.0" + }, + "dependencies": { + "parse5": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/parse5/-/parse5-5.1.1.tgz", + "integrity": "sha512-ugq4DFI0Ptb+WWjAdOK16+u/nHfiIrcE+sh8kZMaM0WllQKLI9rOUq6c2b7cwPkXdzfQESqvoqK6ug7U/Yyzug==", + "optional": true + } + } + }, "@angular/cli": { "version": "14.2.6", "resolved": "https://registry.npmjs.org/@angular/cli/-/cli-14.2.6.tgz", @@ -19845,6 +19894,11 @@ "integrity": "sha512-JVzAR/AjBvVt2BmYhxRCSYysDsPcssdmTFnzyLEts9qNwmjmu4JTAMYubEfwVOSwpQ1I1sKKFcxhZCI2buerfw==", "peer": true }, + "js-generate-password": { + "version": "0.1.7", + "resolved": "https://registry.npmjs.org/js-generate-password/-/js-generate-password-0.1.7.tgz", + "integrity": "sha512-O2fTDgD2DSf4mnuTKO0rZ2DMgv/CkWvdboKzV5XDDLsUrmFQppbMtMkbLIEHiiXSsIdMcFdr/OAN+CXqc7TdTQ==" + }, "js-sdsl": { "version": "4.1.5", "resolved": "https://registry.npmjs.org/js-sdsl/-/js-sdsl-4.1.5.tgz", diff --git a/package.json b/package.json index 5b5dccbe2..d0b2f4f7e 100644 --- a/package.json +++ b/package.json @@ -67,6 +67,7 @@ }, "dependencies": { "@angular/animations": "^14.2.6", + "@angular/cdk": "^14.2.7", "@angular/common": "^14.2.6", "@angular/compiler": "^14.2.6", "@angular/core": "^14.2.6", @@ -90,6 +91,7 @@ "easymde": "^2.18.0", "font-awesome": "^4.7.0", "issn": "^1.0.6", + "js-generate-password": "^0.1.7", "lodash-es": "^4.17.21", "marked": "^4.1.1", "moment": "^2.29.1", diff --git a/projects/admin/src/app/record/custom-editor/user-id-editor/user-id-editor.component.ts b/projects/admin/src/app/record/custom-editor/user-id-editor/user-id-editor.component.ts index d40d79855..392d94ebe 100644 --- a/projects/admin/src/app/record/custom-editor/user-id-editor/user-id-editor.component.ts +++ b/projects/admin/src/app/record/custom-editor/user-id-editor/user-id-editor.component.ts @@ -16,7 +16,7 @@ */ import { Component, OnInit } from '@angular/core'; -import { UntypedFormControl, UntypedFormGroup } from '@angular/forms'; +import { UntypedFormControl, UntypedFormGroup, Validators } from '@angular/forms'; import { FormlyFieldConfig } from '@ngx-formly/core'; import { FormlyJsonschema } from '@ngx-formly/core/json-schema'; import { TranslateService } from '@ngx-translate/core'; @@ -54,6 +54,9 @@ export class UserIdEditorComponent implements OnInit { /** Formly fields configuration populate by the JSONSchema */ fields: FormlyFieldConfig[]; + /** Password field */ + passwordField: FormlyFieldConfig; + /** * Constructor * @@ -106,6 +109,12 @@ export class UserIdEditorComponent implements OnInit { } field.asyncValidators.uniqueUsername = this.getUniqueValidator('username'); } + if (field.key === 'password') { + if (!this.userID) { + field.templateOptions.required = true; + } + this.passwordField = field; + } // remove Message suffix to the message validation key // (required for backend translations) if (field.validation) { @@ -142,6 +151,7 @@ export class UserIdEditorComponent implements OnInit { searchValueUpdated(query: (string | null)): void { if (!query) { this.loadedUserID = null; + this.passwordField.templateOptions.required = true; this.form.reset(); this.model = {}; return; @@ -179,6 +189,7 @@ export class UserIdEditorComponent implements OnInit { this._translateService.instant('The personal data has been successfully linked to this patron.') ); this.loadedUserID = model.id; + this.passwordField.templateOptions.required = false; this.form.reset(); return this.model = model.metadata ? model.metadata : null; }),