]> source.dussan.org Git - archiva.git/blob
28e5b9562a83fc0e7a4ca670d4233e51932819b0
[archiva.git] /
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements.  See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership.  The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License.  You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  * Unless required by applicable law or agreed to in writing,
12  * software distributed under the License is distributed on an
13  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14  * KIND, either express or implied.  See the License for the
15  * specific language governing permissions and limitations
16  * under the License.
17  */
18
19 import {Component, OnInit} from '@angular/core';
20 import {SortedTableComponent} from "@app/modules/shared/sorted-table-component";
21 import {PropertyEntry} from '@app/model/property-entry';
22 import {TranslateService} from "@ngx-translate/core";
23 import {Observable} from "rxjs";
24 import {PagedResult} from "@app/model/paged-result";
25 import {SecurityService} from "@app/services/security.service";
26 import {ToastService} from "@app/services/toast.service";
27 import {ErrorResult} from "@app/model/error-result";
28
29 @Component({
30     selector: 'app-security-properties',
31     templateUrl: './security-properties.component.html',
32     styleUrls: ['./security-properties.component.scss']
33 })
34 export class SecurityPropertiesComponent extends SortedTableComponent<PropertyEntry> implements OnInit {
35
36     editProperty:string='';
37     propertyValue:string='';
38
39     constructor(translator: TranslateService, private securityService: SecurityService, private toastService: ToastService) {
40         super(translator, function (searchTerm: string, offset: number, limit: number, orderBy: string[], order: string): Observable<PagedResult<PropertyEntry>> {
41             // console.log("Retrieving data " + searchTerm + "," + offset + "," + limit + "," + orderBy + "," + order);
42             return securityService.queryProperties(searchTerm, offset, limit, orderBy, order);
43         });
44         super.sortField=['key']
45     }
46
47     ngOnInit(): void {
48     }
49
50     isEdit(key:string) : boolean {
51         return this.editProperty == key;
52     }
53
54     updateProperty(key:string, value:string) {
55         console.log("Updating "+key+"="+value)
56         this.securityService.updateProperty(key, value).subscribe(
57             ()=>{
58                 this.toastService.showSuccessByKey('security-properties', 'security.config.properties.edit_success')
59             },
60             (error: ErrorResult) => {
61                 this.toastService.showErrorByKey('security-properties', 'security.config.properties.edit_failure', {error:error.firstMessageString()})
62             }
63         );
64     }
65
66     toggleEditProperty(propertyEntry:PropertyEntry) : void {
67         if (this.editProperty==propertyEntry.key) {
68             propertyEntry.value=this.propertyValue
69             this.editProperty='';
70             this.updateProperty(propertyEntry.key, this.propertyValue);
71             this.propertyValue = '';
72         } else {
73             this.editProperty = propertyEntry.key;
74             this.propertyValue = propertyEntry.value;
75         }
76     }
77 }