component.ts 2.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
// Copyright 2017 The Kubernetes Authors.
//
// Licensed 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.

15 16 17
import {Component, OnDestroy, OnInit} from '@angular/core';
import {ActivatedRoute} from '@angular/router';
import {PersistentVolumeClaimDetail} from '@api/backendapi';
18 19
import {Subject} from 'rxjs';
import {takeUntil} from 'rxjs/operators';
20

S
Shu Muto 已提交
21
import {ActionbarService, ResourceMeta} from '../../../../common/services/global/actionbar';
22
import {NotificationsService} from '../../../../common/services/global/notifications';
S
Shu Muto 已提交
23
import {EndpointManager, Resource} from '../../../../common/services/resource/endpoint';
24
import {NamespacedResourceService} from '../../../../common/services/resource/resource';
25 26 27 28 29 30

@Component({
  selector: 'kd-persistent-volume-claim-detail',
  templateUrl: './template.html',
})
export class PersistentVolumeClaimDetailComponent implements OnInit, OnDestroy {
31
  private readonly endpoint_ = EndpointManager.resource(Resource.persistentVolumeClaim, true);
32 33
  private readonly unsubscribe_ = new Subject<void>();

34 35 36 37
  persistentVolumeClaim: PersistentVolumeClaimDetail;
  isInitialized = false;

  constructor(
S
Shu Muto 已提交
38 39 40
    private readonly persistentVolumeClaim_: NamespacedResourceService<PersistentVolumeClaimDetail>,
    private readonly actionbar_: ActionbarService,
    private readonly activatedRoute_: ActivatedRoute,
41
    private readonly notifications_: NotificationsService
S
Shu Muto 已提交
42
  ) {}
43 44

  ngOnInit(): void {
45
    const resourceName = this.activatedRoute_.snapshot.params.resourceName;
46
    const resourceNamespace = this.activatedRoute_.snapshot.params.resourceNamespace;
47

48
    this.persistentVolumeClaim_
S
Shu Muto 已提交
49
      .get(this.endpoint_.detail(), resourceName, resourceNamespace)
50
      .pipe(takeUntil(this.unsubscribe_))
S
Shu Muto 已提交
51 52 53
      .subscribe((d: PersistentVolumeClaimDetail) => {
        this.persistentVolumeClaim = d;
        this.notifications_.pushErrors(d.errors);
M
Marcin Maciaszczyk 已提交
54
        this.actionbar_.onInit.emit(new ResourceMeta('Persistent Volume Claim', d.objectMeta, d.typeMeta));
S
Shu Muto 已提交
55 56
        this.isInitialized = true;
      });
57 58 59
  }

  ngOnDestroy(): void {
60 61
    this.unsubscribe_.next();
    this.unsubscribe_.complete();
S
Sebastian Florek 已提交
62
    this.actionbar_.onDetailsLeave.emit();
63 64
  }
}