1 import { Component, EventEmitter, Output } from '@angular/core';
2 import { FormBuilder, FormGroup, Validators } from '@angular/forms';
4 import * as _ from 'lodash';
5 import { BsModalRef } from 'ngx-bootstrap/modal/bs-modal-ref.service';
7 import { RgwUserCapability } from '../models/rgw-user-capability';
10 selector: 'cd-rgw-user-capability-modal',
11 templateUrl: './rgw-user-capability-modal.component.html',
12 styleUrls: ['./rgw-user-capability-modal.component.scss']
14 export class RgwUserCapabilityModalComponent {
16 * The event that is triggered when the 'Add' or 'Update' button
19 @Output() submitAction = new EventEmitter();
25 constructor(private formBuilder: FormBuilder, public bsModalRef: BsModalRef) {
30 this.formGroup = this.formBuilder.group({
31 type: [null, [Validators.required]],
32 perm: [null, [Validators.required]]
37 * Set the 'editing' flag. If set to TRUE, the modal dialog is in 'Edit' mode,
38 * otherwise in 'Add' mode. According to the mode the dialog and its controls
40 * @param {boolean} viewing
42 setEditing(editing: boolean = true) {
43 this.editing = editing;
47 * Set the values displayed in the dialog.
49 setValues(type: string, perm: string) {
50 this.formGroup.setValue({
57 * Set the current capabilities of the user.
59 setCapabilities(capabilities: RgwUserCapability[]) {
60 // Parse the configured capabilities to get a list of types that
61 // should be displayed.
63 capabilities.forEach((capability) => {
64 usedTypes.push(capability.type);
67 ['users', 'buckets', 'metadata', 'usage', 'zone'].forEach((type) => {
68 if (_.indexOf(usedTypes, type) === -1) {
69 this.types.push(type);
75 const capability: RgwUserCapability = this.formGroup.value;
76 this.submitAction.emit(capability);
77 this.bsModalRef.hide();