### File

`src/app/configuration/config-detail/config-detail.component.ts`

### Implements

`OnInit`

### Metadata

providers | `ConfigurationService`
selector | `hi-config-detail`
styleUrls | `./config-detail.component.scss`
templateUrl | `./config-detail.component.html`

### Index

###### Properties
can clusterName instanceName isLoading obj resourceName
###### Methods
deleteConfig loadConfig ngOnInit updateConfig

### Constructor

`constructor(route: ActivatedRoute, service: ConfigurationService, helper: HelperService)`
Defined in src/app/configuration/config-detail/config-detail.component.ts:19
Parameters :
Name | Type | Optional
route | `ActivatedRoute` | No
service | `ConfigurationService` | No
helper | `HelperService` | No

### Methods

deleteConfig
`deleteConfig(value: any)`
Defined in src/app/configuration/config-detail/config-detail.component.ts:107
Parameters :
Name | Type | Optional
value | `any` | No
Returns : `void`

loadConfig
`loadConfig()`
Defined in src/app/configuration/config-detail/config-detail.component.ts:41
Returns : `void`

ngOnInit
`ngOnInit()`
Defined in src/app/configuration/config-detail/config-detail.component.ts:27
Returns : `void`

updateConfig
`updateConfig(value: any)`
Defined in src/app/configuration/config-detail/config-detail.component.ts:75
Parameters :
Name | Type | Optional
value | `any` | No
Returns : `void`

### Properties

can
Default value : `false`
Defined in src/app/configuration/config-detail/config-detail.component.ts:19

clusterName
Type : `string`
Defined in src/app/configuration/config-detail/config-detail.component.ts:16

instanceName
Type : `string`
Defined in src/app/configuration/config-detail/config-detail.component.ts:17

isLoading
Default value : `true`
Defined in src/app/configuration/config-detail/config-detail.component.ts:14

obj
Type : `any`
Default value : `{}`
Defined in src/app/configuration/config-detail/config-detail.component.ts:15

resourceName
Type : `string`
Defined in src/app/configuration/config-detail/config-detail.component.ts:18

    import { Component, OnInit } from '@angular/core';
    import { ActivatedRoute } from '@angular/router';

    import { ConfigurationService } from '../shared/configuration.service';
    import { HelperService } from '../../shared/helper.service';

    @Component({
      selector: 'hi-config-detail',
      templateUrl: './config-detail.component.html',
      styleUrls: ['./config-detail.component.scss'],
      providers: [ConfigurationService],
    })
    export class ConfigDetailComponent implements OnInit {
      isLoading = true;
      obj: any = {};
      clusterName: string;
      instanceName: string;
      resourceName: string;
      can = false;

      constructor(
        protected route: ActivatedRoute,
        protected service: ConfigurationService,
        protected helper: HelperService
      ) {}

      ngOnInit() {
        if (this.route.parent) {
          this.clusterName =
            this.route.parent.snapshot.params.name ||
            this.route.parent.snapshot.params.cluster_name;
          this.instanceName = this.route.parent.snapshot.params.instance_name;
          this.resourceName = this.route.parent.snapshot.params.resource_name;
        }

        this.loadConfig();

        this.service.can().subscribe((data) => (this.can = data));
      }

      loadConfig() {
        let observer: any;

        if (this.clusterName && this.instanceName) {
          observer = this.service.getInstanceConfig(
            this.clusterName,
            this.instanceName
          );
        } else if (this.clusterName && this.resourceName) {
          observer = this.service.getResourceConfig(
            this.clusterName,
            this.resourceName
          );
        } else {
          observer = this.service.getClusterConfig(this.clusterName);
        }

        if (observer) {
          this.isLoading = true;
          observer.subscribe(
            (config) => (this.obj = config),
            (error) => {
              // since rest API simply throws 404 instead of empty config when config is not initialized yet
              // frontend has to treat 404 as normal result
              if (error != 'Not Found') {
                this.helper.showError(error);
              }
              this.isLoading = false;
            },
            () => (this.isLoading = false)
          );
        }
      }

      updateConfig(value: any) {
        let observer: any;

        if (this.clusterName && this.instanceName) {
          observer = this.service.setInstanceConfig(
            this.clusterName,
            this.instanceName,
            value
          );
        } else if (this.clusterName && this.resourceName) {
          observer = this.service.setResourceConfig(
            this.clusterName,
            this.resourceName,
            value
          );
        } else {
          observer = this.service.setClusterConfig(this.clusterName, value);
        }

        if (observer) {
          this.isLoading = true;
          observer.subscribe(
            () => {
              this.helper.showSnackBar('Configuration updated!');
              this.loadConfig();
            },
            (error) => this.helper.showError(error),
            () => (this.isLoading = false)
          );
        }
      }

      deleteConfig(value: any) {
        let observer: any;

        if (this.clusterName && this.instanceName) {
          observer = this.service.deleteInstanceConfig(
            this.clusterName,
            this.instanceName,
            value
          );
        } else if (this.clusterName && this.resourceName) {
          observer = this.service.deleteResourceConfig(
            this.clusterName,
            this.resourceName,
            value
          );
        } else {
          observer = this.service.deleteClusterConfig(this.clusterName, value);
        }

        if (observer) {
          this.isLoading = true;
          observer.subscribe(
            () => {
              this.helper.showSnackBar('Configuration deleted!');
              this.loadConfig();
            },
            (error) => this.helper.showError(error),
            () => (this.isLoading = false)
          );
        }
      }
    }

    <!--
      ~ Licensed to the Apache Software Foundation (ASF) under one
      ~ or more contributor license agreements.  See the NOTICE file
      ~ distributed with this work for additional information
      ~ regarding copyright ownership.  The ASF licenses this file
      ~ to you under the Apache License, Version 2.0 (the
      ~ "License"); you may not use this file except in compliance
      ~ with the License.  You may obtain a copy of the License at
      ~
      ~     http://www.apache.org/licenses/LICENSE-2.0
      ~
      ~ Unless required by applicable law or agreed to in writing,
      ~ software distributed under the License is distributed on an
      ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
      ~ KIND, either express or implied.  See the License for the
      ~ specific language governing permissions and limitations
      ~ under the License.
      -->

    <section>
      <hi-node-viewer
        [loadingIndicator]="isLoading"
        [obj]="obj"
        [unlockable]="can && instanceName == null"
        (update)="updateConfig($event)"
        (create)="updateConfig($event)"
        (delete)="deleteConfig($event)"
      >
      </hi-node-viewer>
    </section>

`./config-detail.component.scss`

Legend
Html element
Component
Html element with directive

# results matching ""

# No results matching ""