-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add missing config-importer.component
- Loading branch information
Showing
4 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
dashboard/src/app/components/config/config-importer/config-importer.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
|
||
|
5 changes: 5 additions & 0 deletions
5
dashboard/src/app/components/config/config-importer/config-importer.component.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
25 changes: 25 additions & 0 deletions
25
dashboard/src/app/components/config/config-importer/config-importer.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); |
49 changes: 49 additions & 0 deletions
49
dashboard/src/app/components/config/config-importer/config-importer.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.`); | ||
} | ||
} | ||
|
||
} |