This is an automated email from the ASF dual-hosted git repository.

martin_s pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/archiva.git

commit d2a8a4f4f891c495b9e9b4c44c23686b0b16fffc
Author: Martin Stockhammer <[email protected]>
AuthorDate: Mon Jan 11 23:38:14 2021 +0100

    Adding property edit
---
 .../services/v2/SecurityConfigurationService.java  |  2 +-
 .../security-properties.component.html             |  7 ++---
 .../security-properties.component.ts               | 34 +++++++++++++++++++++-
 .../src/app/services/security.service.ts           |  7 +++++
 .../src/main/archiva-web/src/assets/i18n/en.json   |  4 ++-
 5 files changed, 47 insertions(+), 7 deletions(-)

diff --git 
a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/v2/SecurityConfigurationService.java
 
b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/v2/SecurityConfigurationService.java
index 9471649..341b6b7 100644
--- 
a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/v2/SecurityConfigurationService.java
+++ 
b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/v2/SecurityConfigurationService.java
@@ -37,6 +37,7 @@ import 
org.apache.archiva.rest.api.model.v2.SecurityConfiguration;
 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 @@ public interface SecurityConfigurationService
     Response updateConfigurationProperty( @PathParam ( "propertyName" )  
String propertyName, PropertyEntry propertyValue)
         throws ArchivaRestServiceException;
 
-
     @Path("config/ldap")
     @GET
     @Produces({ APPLICATION_JSON })
diff --git 
a/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/security/security-configuration/security-properties/security-properties.component.html
 
b/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/security/security-configuration/security-properties/security-properties.component.html
index 59bcdef..22acf82 100644
--- 
a/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/security/security-configuration/security-properties/security-properties.component.html
+++ 
b/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/security/security-configuration/security-properties/security-properties.component.html
@@ -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>
diff --git 
a/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/security/security-configuration/security-properties/security-properties.component.ts
 
b/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/security/security-configuration/security-properties/security-properties.component.ts
index 961866a..c714d5a 100644
--- 
a/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/security/security-configuration/security-properties/security-properties.component.ts
+++ 
b/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/security/security-configuration/security-properties/security-properties.component.ts
@@ -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;
+        }
+    }
 }
diff --git 
a/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/services/security.service.ts
 
b/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/services/security.service.ts
index 8902341..aef5127 100644
--- 
a/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/services/security.service.ts
+++ 
b/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/services/security.service.ts
@@ -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));
+          }))
+    }
+
 }
diff --git 
a/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/assets/i18n/en.json
 
b/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/assets/i18n/en.json
index 18074b7..3e415b2 100644
--- 
a/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/assets/i18n/en.json
+++ 
b/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/assets/i18n/en.json
@@ -249,7 +249,9 @@
         "attributes": {
           "key": "Key",
           "value": "Value"
-        }
+        },
+        "edit_success": "Property has been updated",
+        "edit_error": "Could not save the property value: {error}"
       }
     }
   },

Reply via email to