Adding property edit

This commit is contained in:
Martin Stockhammer 2021-01-11 23:38:14 +01:00
parent 27c81c6abe
commit d2a8a4f4f8
5 changed files with 47 additions and 7 deletions

View File

@ -37,6 +37,7 @@
import org.apache.archiva.security.common.ArchivaRoleConstants;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
@ -199,7 +200,6 @@ PropertyEntry getConfigurationProperty( @PathParam ( "propertyName" ) String pr
Response updateConfigurationProperty( @PathParam ( "propertyName" ) String propertyName, PropertyEntry propertyValue)
throws ArchivaRestServiceException;
@Path("config/ldap")
@GET
@Produces({ APPLICATION_JSON })

View File

@ -22,12 +22,11 @@
<tbody>
<tr *ngFor="let propertyEntry of propertyItem.data" >
<td>{{propertyEntry.key}}</td>
<td>{{propertyEntry.value}}</td>
<td *ngIf="isEdit(propertyEntry.key)"><input class="form-control" type="text" [(ngModel)]="propertyValue"></td>
<td *ngIf="!isEdit(propertyEntry.key)">{{propertyEntry.value}}</td>
<td>
<a [routerLink]="['..','edit', propertyEntry.key]"
<a [routerLink]="" (click)="toggleEditProperty(propertyEntry)"
[attr.title]="'security.config.properties.edit' |translate"><span class="fas fa-edit"></span></a>
<a class="ml-2" [routerLink]="['..','delete', propertyEntry.key]"
[attr.title]="'security.config.properties.delete' |translate"><span class="fas fa-trash-alt"></span></a>
</td>
</tr>
</tbody>

View File

@ -5,6 +5,8 @@ import {TranslateService} from "@ngx-translate/core";
import {Observable} from "rxjs";
import {PagedResult} from "@app/model/paged-result";
import {SecurityService} from "@app/services/security.service";
import {ToastService} from "@app/services/toast.service";
import {ErrorResult} from "@app/model/error-result";
@Component({
selector: 'app-security-properties',
@ -13,7 +15,10 @@ import {SecurityService} from "@app/services/security.service";
})
export class SecurityPropertiesComponent extends SortedTableComponent<PropertyEntry> implements OnInit {
constructor(translator: TranslateService, securityService: SecurityService) {
editProperty:string='';
propertyValue:string='';
constructor(translator: TranslateService, private securityService: SecurityService, private toastService: ToastService) {
super(translator, function (searchTerm: string, offset: number, limit: number, orderBy: string[], order: string): Observable<PagedResult<PropertyEntry>> {
// console.log("Retrieving data " + searchTerm + "," + offset + "," + limit + "," + orderBy + "," + order);
return securityService.queryProperties(searchTerm, offset, limit, orderBy, order);
@ -24,4 +29,31 @@ export class SecurityPropertiesComponent extends SortedTableComponent<PropertyEn
ngOnInit(): void {
}
isEdit(key:string) : boolean {
return this.editProperty == key;
}
updateProperty(key:string, value:string) {
console.log("Updating "+key+"="+value)
this.securityService.updateProperty(key, value).subscribe(
()=>{
this.toastService.showSuccessByKey('security-properties', 'security.config.properties.edit_success')
},
(error: ErrorResult) => {
this.toastService.showErrorByKey('security-properties', 'security.config.properties.edit_failure', {error:error.firstMessageString()})
}
);
}
toggleEditProperty(propertyEntry:PropertyEntry) : void {
if (this.editProperty==propertyEntry.key) {
propertyEntry.value=this.propertyValue
this.editProperty='';
this.updateProperty(propertyEntry.key, this.propertyValue);
this.propertyValue = '';
} else {
this.editProperty = propertyEntry.key;
this.propertyValue = propertyEntry.value;
}
}
}

View File

@ -116,4 +116,11 @@ export class SecurityService {
}));
}
updateProperty(propKey:string, propValue:string) : Observable<HttpResponse<any>> {
return this.rest.executeResponseCall('put', 'archiva','security/config/properties/'+encodeURI(propKey), {key:propKey, value:propValue})
.pipe(catchError((error: HttpErrorResponse) => {
return throwError(this.rest.getTranslatedErrorResult(error));
}))
}
}

View File

@ -249,7 +249,9 @@
"attributes": {
"key": "Key",
"value": "Value"
}
},
"edit_success": "Property has been updated",
"edit_error": "Could not save the property value: {error}"
}
}
},