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 {
17 * The event that is triggered when the 'Add' or 'Update' button
20 @Output() submitAction = new EventEmitter();
26 constructor(private formBuilder: FormBuilder,
27 public bsModalRef: BsModalRef) {
32 this.formGroup = this.formBuilder.group({
45 * Set the 'editing' flag. If set to TRUE, the modal dialog is in 'Edit' mode,
46 * otherwise in 'Add' mode. According to the mode the dialog and its controls
48 * @param {boolean} viewing
50 setEditing(editing: boolean = true) {
51 this.editing = editing;
55 * Set the values displayed in the dialog.
57 setValues(type: string, perm: string) {
58 this.formGroup.setValue({
65 * Set the current capabilities of the user.
67 setCapabilities(capabilities: RgwUserCapability[]) {
68 // Parse the configured capabilities to get a list of types that
69 // should be displayed.
71 capabilities.forEach((capability) => {
72 usedTypes.push(capability.type);
75 ['users', 'buckets', 'metadata', 'usage', 'zone'].forEach((type) => {
76 if (_.indexOf(usedTypes, type) === -1) {
77 this.types.push(type);
83 const capability: RgwUserCapability = this.formGroup.value;
84 this.submitAction.emit(capability);
85 this.bsModalRef.hide();