diff --git a/ui/admin/app/components/form/auth-method/index.hbs b/ui/admin/app/components/form/auth-method/index.hbs index b90392ee01..1b49fc1dfa 100644 --- a/ui/admin/app/components/form/auth-method/index.hbs +++ b/ui/admin/app/components/form/auth-method/index.hbs @@ -11,5 +11,8 @@ @removeItemByIndex={{@removeItemByIndex}} @addStringItem={{@addStringItem}} @addAccountMapItem={{@addAccountMapItem}} + @addRow={{this.addRow}} + @removeRow={{this.removeRow}} + @updateRow={{this.updateRow}} /> {{/if}} \ No newline at end of file diff --git a/ui/admin/app/components/form/auth-method/index.js b/ui/admin/app/components/form/auth-method/index.js index 168acb9f39..d8379c6378 100644 --- a/ui/admin/app/components/form/auth-method/index.js +++ b/ui/admin/app/components/form/auth-method/index.js @@ -5,6 +5,7 @@ import Component from '@glimmer/component'; import { assert } from '@ember/debug'; +import { action } from '@ember/object'; import oidc from './oidc'; import ldap from './ldap'; import password from './password'; @@ -24,4 +25,47 @@ export default class FormAuthMethodIndex extends Component { ); return component; } + + /** + * Adds a new empty row to the specified field + * @param {string} field - The field name to add a row to + * @param {Array} properties - Array of property names for the empty row (e.g., ['value'] or ['key', 'value']) + */ + @action + addRow(field, properties) { + const emptyRow = Object.fromEntries(properties.map((prop) => [prop, ''])); + this.args.model[field] = [...this.args.model[field], emptyRow]; + } + + /** + * Removes a row from the specified field + * @param {string} field - The field name to remove a row from + * @param {object} rowData - The row data to remove + */ + @action + removeRow(field, rowData) { + let rows = this.args.model[field].filter((item) => item !== rowData); + // Ensure at least one empty row exists for editing + if (rows.length === 0) { + const emptyRow = Object.fromEntries( + Object.keys(rowData).map((key) => [key, '']), + ); + rows = [emptyRow]; + } + + this.args.model[field] = rows; + } + + /** + * Updates a specific property in a row + * @param {string} field - The field name containing the row + * @param {object} rowData - The row object to update + * @param {string} property - The property name to update + * @param {object} event - The DOM event containing the new value + */ + @action + updateRow(field, rowData, property, { target: { value } }) { + rowData[property] = value; + this.args.model[field] = [...this.args.model[field]]; + } } diff --git a/ui/admin/app/components/form/auth-method/ldap/index.hbs b/ui/admin/app/components/form/auth-method/ldap/index.hbs index 15b7bf96c0..ee144ce8ba 100644 --- a/ui/admin/app/components/form/auth-method/ldap/index.hbs +++ b/ui/admin/app/components/form/auth-method/ldap/index.hbs @@ -82,37 +82,31 @@ {{/if}} - - <:fieldset as |F|> - - {{t 'resources.auth-method.form.certificates.label'}} - - - {{t 'resources.auth-method.form.certificates.help'}} - - - {{#if @model.errors.certificates}} - - {{#each @model.errors.certificates as |error|}} - {{error.message}} - {{/each}} - + <:row as |R|> + + + + {{#if R.canDelete}} + {{/if}} - - - <:field as |F|> - - - - + + {{#if @model.isNew}} - - <:fieldset as |F|> - - {{t 'resources.auth-method.form.account_attribute_maps.label'}} - - - {{t 'resources.auth-method.form.account_attribute_maps.help'}} - - - {{#if @model.errors.account_attribute_maps}} - - {{#each @model.errors.account_attribute_maps as |error|}} - {{error.message}} + <:row as |R|> + + {{t 'resources.auth-method.titles.from-attr'}} + + + + {{t 'resources.auth-method.titles.to-attr'}} + + + {{#each this.toAttributes as |attr|}} + {{/each}} - + + + {{#if R.canDelete}} + {{/if}} - - <:field as |F|> - - <:key as |K|> - - - <:value as |V|> - - - - - + +