@@ -9,6 +9,7 @@ interface AdminUser {
99 username : string ;
1010 role : string ;
1111 class : string ;
12+ profile : string ;
1213}
1314
1415interface UsersContract {
@@ -48,7 +49,7 @@ interface UsersContract {
4849 <tr *ngFor="let user of visibleUsers()">
4950 <td><strong>{{ user.username }}</strong></td>
5051 <td><span class="role-badge" [class]="'role-badge role-badge--' + user.class">{{ user.role }}</span></td>
51- <td class="table-actions"><button type="button" class="button button--danger button--small" [disabled]="saving()" (click)="remove(user.username)">Eliminar</button></td>
52+ <td class="table-actions"><button type="button" class="button button--secondary button--small" [disabled]="saving()" (click)="edit(user)">Editar</button><button type="button" class="button button-- danger button--small" [disabled]="saving()" (click)="remove(user.username)">Eliminar</button></td>
5253 </tr>
5354 </tbody>
5455 </table>
@@ -61,9 +62,9 @@ interface UsersContract {
6162 <ng-template #emptyUsers><p class="empty-state">No hay usuarios configurados todavía.</p></ng-template>
6263 </div>
6364
64- <section class="panel users-create" *ngIf="schema () as form">
65- <div class="panel-heading"><div><h2>Nuevo usuario</h2><p>Define alias, contraseña y rol.</p></div></div>
66- <psfs-dynamic-form [schema]="form" [errors]="fieldErrors()" [disabled]="saving()" submitLabel=" Crear usuario" (submitted)="create ($event)" />
65+ <section class="panel users-create" *ngIf="activeSchema () as form">
66+ <div class="panel-heading"><div><h2>{{ editing() ? 'Editar usuario' : ' Nuevo usuario' }} </h2><p>{{ editing() ? 'La contraseña se sustituirá al guardar.' : ' Define alias, contraseña y rol.' }} </p></div><button *ngIf="editing()" class="button button--secondary" type="button" (click)="cancelEdit()">Cancelar</button ></div>
67+ <psfs-dynamic-form [schema]="form" [errors]="fieldErrors()" [disabled]="saving()" [ submitLabel]="editing() ? 'Actualizar usuario' : ' Crear usuario' " (submitted)="save ($event)" />
6768 </section>
6869 </section>
6970 </article>
@@ -81,6 +82,21 @@ export class UsersPageComponent {
8182 readonly failure = signal < AdminEnvelope < null > | null > ( null ) ;
8283 readonly fieldErrors = signal < Record < string , string [ ] > > ( { } ) ;
8384 readonly pendingDelete = signal ( '' ) ;
85+ readonly editing = signal < AdminUser | null > ( null ) ;
86+ readonly activeSchema = computed < AdminFormSchema | null > ( ( ) => {
87+ const form = this . schema ( ) ;
88+ const user = this . editing ( ) ;
89+ if ( ! form || ! user ) return form ;
90+ return {
91+ ...form ,
92+ fields : {
93+ ...form . fields ,
94+ username : { ...form . fields [ 'username' ] , value : user . username } ,
95+ password : { ...form . fields [ 'password' ] , value : '' } ,
96+ profile : { ...form . fields [ 'profile' ] , value : user . profile } ,
97+ }
98+ } ;
99+ } ) ;
84100 readonly filter = signal ( '' ) ;
85101 readonly page = signal ( 0 ) ;
86102 readonly filteredUsers = computed ( ( ) => {
@@ -98,13 +114,18 @@ export class UsersPageComponent {
98114 this . load ( ) ;
99115 }
100116
101- create ( submission : DynamicFormSubmission ) : void {
117+ save ( submission : DynamicFormSubmission ) : void {
102118 this . saving . set ( true ) ;
103119 this . resetFeedback ( ) ;
104- this . api . post < Record < string , never > > ( 'users' , submission ) . subscribe ( {
120+ const current = this . editing ( ) ;
121+ const request = current
122+ ? this . api . put < Record < string , never > > ( `users/${ encodeURIComponent ( current . username ) } ` , submission )
123+ : this . api . post < Record < string , never > > ( 'users' , submission ) ;
124+ request . subscribe ( {
105125 next : ( response ) => {
106126 this . saving . set ( false ) ;
107- this . message . set ( response . message ?? 'Usuario creado correctamente.' ) ;
127+ this . message . set ( response . message ?? ( current ? 'Usuario actualizado correctamente.' : 'Usuario creado correctamente.' ) ) ;
128+ this . editing . set ( null ) ;
108129 this . load ( ) ;
109130 } ,
110131 error : ( failure : unknown ) => {
@@ -118,6 +139,16 @@ export class UsersPageComponent {
118139 this . pendingDelete . set ( username ) ;
119140 }
120141
142+ edit ( user : AdminUser ) : void {
143+ this . editing . set ( user ) ;
144+ this . resetFeedback ( ) ;
145+ }
146+
147+ cancelEdit ( ) : void {
148+ this . editing . set ( null ) ;
149+ this . resetFeedback ( ) ;
150+ }
151+
121152 setFilter ( value : string ) : void {
122153 this . filter . set ( value ) ;
123154 this . page . set ( 0 ) ;
0 commit comments