1 import { Component, EventEmitter, Output } from '@angular/core';
2 import { Validators } from '@angular/forms';
4 import * as _ from 'lodash';
5 import { BsModalRef } from 'ngx-bootstrap/modal';
7 import { CdFormBuilder } from '../../../shared/forms/cd-form-builder';
8 import { CdFormGroup } from '../../../shared/forms/cd-form-group';
9 import { RgwUserCapability } from '../models/rgw-user-capability';
12 selector: 'cd-rgw-user-capability-modal',
13 templateUrl: './rgw-user-capability-modal.component.html',
14 styleUrls: ['./rgw-user-capability-modal.component.scss']
16 export class RgwUserCapabilityModalComponent {
18 * The event that is triggered when the 'Add' or 'Update' button
22 submitAction = new EventEmitter();
24 formGroup: CdFormGroup;
28 constructor(private formBuilder: CdFormBuilder, public bsModalRef: BsModalRef) {
33 this.formGroup = this.formBuilder.group({
34 type: [null, [Validators.required]],
35 perm: [null, [Validators.required]]
40 * Set the 'editing' flag. If set to TRUE, the modal dialog is in 'Edit' mode,
41 * otherwise in 'Add' mode. According to the mode the dialog and its controls
43 * @param {boolean} viewing
45 setEditing(editing: boolean = true) {
46 this.editing = editing;
50 * Set the values displayed in the dialog.
52 setValues(type: string, perm: string) {
53 this.formGroup.setValue({
60 * Set the current capabilities of the user.
62 setCapabilities(capabilities: RgwUserCapability[]) {
63 // Parse the configured capabilities to get a list of types that
64 // should be displayed.
66 capabilities.forEach((capability) => {
67 usedTypes.push(capability.type);
70 ['users', 'buckets', 'metadata', 'usage', 'zone'].forEach((type) => {
71 if (_.indexOf(usedTypes, type) === -1) {
72 this.types.push(type);
78 const capability: RgwUserCapability = this.formGroup.value;
79 this.submitAction.emit(capability);
80 this.bsModalRef.hide();