Fix chart upload related issues

1. Chart will reset when open modal
2. Empty chart shouldn't trigger upload action

Signed-off-by: Qian Deng <dengq@vmware.com>
This commit is contained in:
Qian Deng 2018-08-15 17:15:57 +08:00
parent 4ecea1f5ad
commit b98af169af
4 changed files with 18 additions and 1 deletions

View File

@ -24,7 +24,7 @@
<div *ngIf="!isCardView" class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<clr-datagrid (clrDgRefresh)="refresh($event)" [clrDgLoading]="loading" [(clrDgSelected)]="selectedRows">
<clr-dg-action-bar>
<button type="button" class="btn btn-sm btn-secondary" [disabled]="!hasProjectAdminRole" (click)="onChartUpload($event)">
<button type="button" class="btn btn-sm btn-secondary" [disabled]="!developerRoleOrAbove" (click)="onChartUpload($event)">
<clr-icon shape="upload" size="16"></clr-icon>&nbsp;{{'HELM_CHART.UPLOAD' | translate}}
</button>
</clr-dg-action-bar>

View File

@ -5,8 +5,10 @@ import {
ChangeDetectionStrategy,
Output,
EventEmitter,
ViewChild,
ChangeDetectorRef
} from "@angular/core";
import { NgForm } from '@angular/forms';
import { TranslateService } from "@ngx-translate/core";
import { State } from "clarity-angular";
@ -28,6 +30,7 @@ export class HelmChartComponent implements OnInit {
@Input() projectName = "unknown";
@Input() urlPrefix: string;
@Input() hasSignedIn: boolean;
@Input() projectRoleID = 0;
@Input() hasProjectAdminRole: boolean;
@Output() chartClickEvt = new EventEmitter<any>();
@Output() chartDownloadEve = new EventEmitter<string>();
@ -56,6 +59,8 @@ export class HelmChartComponent implements OnInit {
totalCount = 0;
currentState: State;
@ViewChild('chartUploadForm') uploadForm: NgForm;
constructor(
private errorHandler: ErrorHandler,
private translateService: TranslateService,
@ -68,6 +73,11 @@ export class HelmChartComponent implements OnInit {
return this.systemInfo ? this.systemInfo.registry_url : "";
}
public get developerRoleOrAbove(): boolean {
// 1: admin, 2: developer, 3: guest
return this.projectRoleID === 2 || this.hasProjectAdminRole;
}
ngOnInit(): void {
// Get system info for tag views
toPromise<SystemInfo>(this.systemInfoService.getSystemInfo())
@ -107,6 +117,9 @@ export class HelmChartComponent implements OnInit {
}
onChartUpload() {
this.chartFile = null;
this.provFile = null;
this.uploadForm.reset();
this.isUploadModalOpen = true;
}

View File

@ -3,6 +3,7 @@
[projectName]='projectName'
[urlPrefix]='urlPrefix'
[hasSignedIn]='hasSignedIn'
[projectRoleID]='project_member_role_id'
[hasProjectAdminRole]='hasProjectAdminRole'
(chartClickEvt)='onChartClick($event)'>
</hbr-helm-chart>

View File

@ -18,6 +18,7 @@ export class ListChartsComponent implements OnInit {
urlPrefix: string;
hasSignedIn: boolean;
hasProjectAdminRole: boolean;
project_member_role_id: number;
currentUser: SessionUser;
constructor(
@ -35,6 +36,8 @@ export class ListChartsComponent implements OnInit {
let project = <Project>(resolverData["projectResolver"]);
this.projectName = project.name;
this.hasProjectAdminRole = project.has_project_admin_role;
this.project_member_role_id = project.current_user_role_id;
console.log(this.project_member_role_id);
}
}