Skip to content

Commit

Permalink
add missing config-importer.component
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahoo-Wang committed May 15, 2021
1 parent 362d1c4 commit 558c293
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<div nz-row>
<div nz-col [nzSpan]="4" style="font-size: 14px;height: 32px;line-height: 32px;">
<label>Import Policy :</label>
</div>
<div nz-col [nzSpan]="16">
<nz-select [(ngModel)]="importPolicy">
<nz-option nzValue="skip" nzLabel="skip"></nz-option>
<nz-option nzValue="overwrite" nzLabel="overwrite"></nz-option>
</nz-select>
</div>
</div>

<nz-card>
<nz-upload
nzAccept="application/zip"
nzType="drag"
nzFileType="application/zip"
[nzData]="getImportData"
nzName="importZip"
[nzAction]="getImportUrl()"
(nzChange)="handleChange($event)"
>
<p class="ant-upload-drag-icon">
<i nz-icon nzType="inbox"></i>
</p>
<p class="ant-upload-text">Click or drag ZIP-file to this area to upload</p>
</nz-upload>
</nz-card>


Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
nz-select {
margin: 0 8px 10px 0;
width: 160px;
text-align: center
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import {ComponentFixture, TestBed} from '@angular/core/testing';

import {ConfigImporterComponent} from './config-importer.component';

describe('ConfigImporterComponent', () => {
let component: ConfigImporterComponent;
let fixture: ComponentFixture<ConfigImporterComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ConfigImporterComponent]
})
.compileComponents();
});

beforeEach(() => {
fixture = TestBed.createComponent(ConfigImporterComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import {Component, EventEmitter, OnInit, Output} from '@angular/core';
import {ConfigClient, ImportPolicy} from '../../../api/config/ConfigClient';
import {NzUploadChangeParam, NzUploadFile} from 'ng-zorro-antd/upload';
import {NamespaceContext} from '../../../core/NamespaceContext';
import {NzMessageService} from 'ng-zorro-antd/message';


@Component({
selector: 'app-config-importer',
templateUrl: './config-importer.component.html',
styleUrls: ['./config-importer.component.scss']
})
export class ConfigImporterComponent implements OnInit {
@Output() afterImport: EventEmitter<boolean> = new EventEmitter<boolean>();
importPolicy: ImportPolicy = 'skip';

constructor(private namespaceContext: NamespaceContext,
private configClient: ConfigClient,
private messageService: NzMessageService) {
}

ngOnInit(): void {
}

getImportData = (file: NzUploadFile) => {
return {
policy: this.importPolicy
};
};

getImportUrl(): string {
return this.configClient.getImportUrl(this.namespaceContext.ensureCurrentNamespace());
}

handleChange({file, fileList}: NzUploadChangeParam): void {
const status = file.status;
if (status !== 'uploading') {
console.log(file, fileList);
}
if (status === 'done') {
this.afterImport.emit(true);
this.messageService.success(`${file.name} file uploaded successfully.`);
} else if (status === 'error') {
this.afterImport.emit(false);
this.messageService.error(`${file.name} file upload failed.`);
}
}

}

0 comments on commit 558c293

Please sign in to comment.