mirror of
https://github.com/GNS3/gns3-web-ui.git
synced 2025-06-01 23:10:47 +00:00
1. Improve progress bar and I used common progress bar.
2. Added cancel button 3. And modified the unit test cases
This commit is contained in:
parent
379a39a98f
commit
9381578657
@ -1,4 +1,4 @@
|
|||||||
<p>Image Uploading please wait .... {{uploadProgress}}%</p>
|
<p>{{upload_file_type}} Uploading please wait .... {{uploadProgress}}%</p>
|
||||||
<div class="row proccessBar-row ">
|
<div class="row proccessBar-row ">
|
||||||
<div class="col-md-9 proccessBar-col">
|
<div class="col-md-9 proccessBar-col">
|
||||||
<mat-progress-bar mode="determinate" [value]="uploadProgress" aria-valuemin="0" aria-valuemax="100">
|
<mat-progress-bar mode="determinate" [value]="uploadProgress" aria-valuemin="0" aria-valuemax="100">
|
||||||
|
@ -13,7 +13,7 @@ import { UploadServiceService } from './upload-service.service';
|
|||||||
export class UploadingProcessbarComponent implements OnInit {
|
export class UploadingProcessbarComponent implements OnInit {
|
||||||
uploadProgress: number = 0
|
uploadProgress: number = 0
|
||||||
subscription: Subscription;
|
subscription: Subscription;
|
||||||
|
upload_file_type:string
|
||||||
constructor(
|
constructor(
|
||||||
@Inject(MAT_SNACK_BAR_DATA) public data,
|
@Inject(MAT_SNACK_BAR_DATA) public data,
|
||||||
private _snackRef: MatSnackBarRef<UploadingProcessbarComponent>,
|
private _snackRef: MatSnackBarRef<UploadingProcessbarComponent>,
|
||||||
@ -21,6 +21,8 @@ export class UploadingProcessbarComponent implements OnInit {
|
|||||||
) { }
|
) { }
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
|
this.upload_file_type = this.data.upload_file_type
|
||||||
|
debugger
|
||||||
this.subscription = this._US.currentCount.subscribe((count:number) => {
|
this.subscription = this._US.currentCount.subscribe((count:number) => {
|
||||||
this.uploadProgress = count;
|
this.uploadProgress = count;
|
||||||
if (this.uploadProgress === 100 || this.uploadProgress == null ) {
|
if (this.uploadProgress === 100 || this.uploadProgress == null ) {
|
||||||
|
@ -158,6 +158,7 @@ export class AddIosTemplateComponent implements OnInit, OnDestroy {
|
|||||||
this.uploader.uploadItem(itemToUpload);
|
this.uploader.uploadItem(itemToUpload);
|
||||||
this.snackBar.openFromComponent(UploadingProcessbarComponent, {
|
this.snackBar.openFromComponent(UploadingProcessbarComponent, {
|
||||||
panelClass: 'uplaoding-file-snackabar',
|
panelClass: 'uplaoding-file-snackabar',
|
||||||
|
data:{upload_file_type:'Image'}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,6 +129,7 @@ export class AddIouTemplateComponent implements OnInit, OnDestroy {
|
|||||||
this.uploader.uploadItem(itemToUpload);
|
this.uploader.uploadItem(itemToUpload);
|
||||||
this.snackBar.openFromComponent(UploadingProcessbarComponent, {
|
this.snackBar.openFromComponent(UploadingProcessbarComponent, {
|
||||||
panelClass: 'uplaoding-file-snackabar',
|
panelClass: 'uplaoding-file-snackabar',
|
||||||
|
data:{upload_file_type:'Image'}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -157,7 +157,7 @@ export class AddQemuVmTemplateComponent implements OnInit {
|
|||||||
|
|
||||||
if ((itemToUpload as any).options) (itemToUpload as any).options.disableMultipart = true; ((itemToUpload as any).options.headers =[{name:'Authorization',value:'Bearer ' + this.server.authToken}])
|
if ((itemToUpload as any).options) (itemToUpload as any).options.disableMultipart = true; ((itemToUpload as any).options.headers =[{name:'Authorization',value:'Bearer ' + this.server.authToken}])
|
||||||
this.uploader.uploadItem(itemToUpload);
|
this.uploader.uploadItem(itemToUpload);
|
||||||
this.snackBar.openFromComponent(UploadingProcessbarComponent,{panelClass: 'uplaoding-file-snackabar',});
|
this.snackBar.openFromComponent(UploadingProcessbarComponent,{panelClass: 'uplaoding-file-snackabar', data:{upload_file_type:'Image'}});
|
||||||
}
|
}
|
||||||
|
|
||||||
cancelUploading() {
|
cancelUploading() {
|
||||||
|
@ -728,6 +728,7 @@ export class NewTemplateDialogComponent implements OnInit {
|
|||||||
openSnackBar() {
|
openSnackBar() {
|
||||||
this.snackBar.openFromComponent(UploadingProcessbarComponent, {
|
this.snackBar.openFromComponent(UploadingProcessbarComponent, {
|
||||||
panelClass: 'uplaoding-file-snackabar',
|
panelClass: 'uplaoding-file-snackabar',
|
||||||
|
data:{upload_file_type:'Image'}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -943,6 +943,7 @@ export class ProjectMapComponent implements OnInit, OnDestroy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
importProject() {
|
importProject() {
|
||||||
|
debugger
|
||||||
let uuid: string = '';
|
let uuid: string = '';
|
||||||
const dialogRef = this.dialog.open(ImportProjectDialogComponent, {
|
const dialogRef = this.dialog.open(ImportProjectDialogComponent, {
|
||||||
width: '400px',
|
width: '400px',
|
||||||
@ -955,9 +956,9 @@ export class ProjectMapComponent implements OnInit, OnDestroy {
|
|||||||
uuid = projectId;
|
uuid = projectId;
|
||||||
});
|
});
|
||||||
|
|
||||||
dialogRef.afterClosed().subscribe(() => {
|
dialogRef.afterClosed().subscribe((isCancel:boolean) => {
|
||||||
subscription.unsubscribe();
|
subscription.unsubscribe();
|
||||||
if (uuid) {
|
if (uuid && !isCancel) {
|
||||||
this.bottomSheet.open(NavigationDialogComponent);
|
this.bottomSheet.open(NavigationDialogComponent);
|
||||||
let bottomSheetRef = this.bottomSheet._openedBottomSheetRef;
|
let bottomSheetRef = this.bottomSheet._openedBottomSheetRef;
|
||||||
bottomSheetRef.instance.projectMessage = 'imported project';
|
bottomSheetRef.instance.projectMessage = 'imported project';
|
||||||
|
@ -38,7 +38,7 @@
|
|||||||
<button class="delete-button" [hidden]="!isDeleteVisible">
|
<button class="delete-button" [hidden]="!isDeleteVisible">
|
||||||
<mat-icon color="primary" (click)="onDeleteClick()" class="delete-icon">clear</mat-icon>
|
<mat-icon color="primary" (click)="onDeleteClick()" class="delete-icon">clear</mat-icon>
|
||||||
</button>
|
</button>
|
||||||
<div mat-dialog-actions>
|
<div mat-dialog-actions align="end">
|
||||||
<button mat-button (click)="onNoClick()" color="accent">Cancel</button>
|
<button mat-button (click)="onNoClick()" color="accent">Cancel</button>
|
||||||
<button
|
<button
|
||||||
mat-button
|
mat-button
|
||||||
@ -54,13 +54,13 @@
|
|||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
<div [hidden]="!isFirstStepCompleted">
|
<div [hidden]="!isFirstStepCompleted">
|
||||||
<div class="progress">
|
<!-- <div class="progress">
|
||||||
<div class="progress-bar" role="progressbar" [ngStyle]="{ width: uploader.progress + '%' }"></div>
|
<div class="progress-bar" role="progressbar" [ngStyle]="{ width: uploader.progress + '%' }"></div>
|
||||||
</div>
|
</div> -->
|
||||||
<div class="result-message-box">
|
<div class="">
|
||||||
<span>{{ resultMessage }}</span>
|
<span>{{ resultMessage }}</span>
|
||||||
</div>
|
</div>
|
||||||
<div mat-dialog-actions>
|
<div mat-dialog-actions align="end">
|
||||||
<button
|
<button
|
||||||
mat-button
|
mat-button
|
||||||
[disabled]="!isFinishEnabled"
|
[disabled]="!isFinishEnabled"
|
||||||
|
@ -18,6 +18,10 @@ import { Project } from '../../../models/project';
|
|||||||
import { Server } from '../../../models/server';
|
import { Server } from '../../../models/server';
|
||||||
import { ProjectService } from '../../../services/project.service';
|
import { ProjectService } from '../../../services/project.service';
|
||||||
import { ImportProjectDialogComponent } from './import-project-dialog.component';
|
import { ImportProjectDialogComponent } from './import-project-dialog.component';
|
||||||
|
import { ToasterService } from '../../../services/toaster.service';
|
||||||
|
import { MockedToasterService } from '../../../services/toaster.service.spec';
|
||||||
|
import { MatSnackBarModule } from '@angular/material/snack-bar';
|
||||||
|
|
||||||
|
|
||||||
export class MockedProjectService {
|
export class MockedProjectService {
|
||||||
public projects: Project[] = [
|
public projects: Project[] = [
|
||||||
@ -62,6 +66,7 @@ describe('ImportProjectDialogComponent', () => {
|
|||||||
let server: Server;
|
let server: Server;
|
||||||
let debugElement: DebugElement;
|
let debugElement: DebugElement;
|
||||||
let fileSelectDirective: FileSelectDirective;
|
let fileSelectDirective: FileSelectDirective;
|
||||||
|
let mockedToasterService = new MockedToasterService()
|
||||||
|
|
||||||
let dialogRef = {
|
let dialogRef = {
|
||||||
close: jasmine.createSpy('close'),
|
close: jasmine.createSpy('close'),
|
||||||
@ -77,6 +82,7 @@ describe('ImportProjectDialogComponent', () => {
|
|||||||
MatDialogModule,
|
MatDialogModule,
|
||||||
MatFormFieldModule,
|
MatFormFieldModule,
|
||||||
MatInputModule,
|
MatInputModule,
|
||||||
|
MatSnackBarModule,
|
||||||
NoopAnimationsModule,
|
NoopAnimationsModule,
|
||||||
FileUploadModule,
|
FileUploadModule,
|
||||||
FormsModule,
|
FormsModule,
|
||||||
@ -87,6 +93,8 @@ describe('ImportProjectDialogComponent', () => {
|
|||||||
{ provide: MatDialogRef, useValue: dialogRef },
|
{ provide: MatDialogRef, useValue: dialogRef },
|
||||||
{ provide: MAT_DIALOG_DATA, useValue: [] },
|
{ provide: MAT_DIALOG_DATA, useValue: [] },
|
||||||
{ provide: ProjectService, useClass: MockedProjectService },
|
{ provide: ProjectService, useClass: MockedProjectService },
|
||||||
|
{ provide: ToasterService, useValue: mockedToasterService },
|
||||||
|
|
||||||
],
|
],
|
||||||
declarations: [ImportProjectDialogComponent],
|
declarations: [ImportProjectDialogComponent],
|
||||||
}).compileComponents();
|
}).compileComponents();
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { Component, EventEmitter, Inject, OnInit } from '@angular/core';
|
import { Component, EventEmitter, Inject, OnInit } from '@angular/core';
|
||||||
import { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms';
|
import { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms';
|
||||||
import { MatDialog, MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
|
import { MatDialog, MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
|
||||||
|
import { ToasterService } from '../../../services/toaster.service';
|
||||||
import { FileItem, FileUploader, ParsedResponseHeaders } from 'ng2-file-upload';
|
import { FileItem, FileUploader, ParsedResponseHeaders } from 'ng2-file-upload';
|
||||||
import { v4 as uuid } from 'uuid';
|
import { v4 as uuid } from 'uuid';
|
||||||
import { Project } from '../../../models/project';
|
import { Project } from '../../../models/project';
|
||||||
@ -9,6 +10,9 @@ import { ServerResponse } from '../../../models/serverResponse';
|
|||||||
import { ProjectService } from '../../../services/project.service';
|
import { ProjectService } from '../../../services/project.service';
|
||||||
import { ConfirmationDialogComponent } from '../confirmation-dialog/confirmation-dialog.component';
|
import { ConfirmationDialogComponent } from '../confirmation-dialog/confirmation-dialog.component';
|
||||||
import { ProjectNameValidator } from '../models/projectNameValidator';
|
import { ProjectNameValidator } from '../models/projectNameValidator';
|
||||||
|
import { UploadServiceService } from '../../../common/uploading-processbar/upload-service.service';
|
||||||
|
import { UploadingProcessbarComponent } from '../../../common/uploading-processbar/uploading-processbar.component';
|
||||||
|
import { MatSnackBar } from '@angular/material/snack-bar';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-import-project-dialog',
|
selector: 'app-import-project-dialog',
|
||||||
@ -18,6 +22,7 @@ import { ProjectNameValidator } from '../models/projectNameValidator';
|
|||||||
})
|
})
|
||||||
export class ImportProjectDialogComponent implements OnInit {
|
export class ImportProjectDialogComponent implements OnInit {
|
||||||
uploader: FileUploader;
|
uploader: FileUploader;
|
||||||
|
uploadProgress: number = 0;
|
||||||
server: Server;
|
server: Server;
|
||||||
isImportEnabled: boolean = false;
|
isImportEnabled: boolean = false;
|
||||||
isFinishEnabled: boolean = false;
|
isFinishEnabled: boolean = false;
|
||||||
@ -35,7 +40,11 @@ export class ImportProjectDialogComponent implements OnInit {
|
|||||||
@Inject(MAT_DIALOG_DATA) public data: any,
|
@Inject(MAT_DIALOG_DATA) public data: any,
|
||||||
private formBuilder: FormBuilder,
|
private formBuilder: FormBuilder,
|
||||||
private projectService: ProjectService,
|
private projectService: ProjectService,
|
||||||
private projectNameValidator: ProjectNameValidator
|
private projectNameValidator: ProjectNameValidator,
|
||||||
|
private toasterService : ToasterService,
|
||||||
|
private uploadServiceService: UploadServiceService,
|
||||||
|
private snackBar : MatSnackBar,
|
||||||
|
|
||||||
) {
|
) {
|
||||||
this.projectNameForm = this.formBuilder.group({
|
this.projectNameForm = this.formBuilder.group({
|
||||||
projectName: new FormControl(null, [Validators.required, projectNameValidator.get]),
|
projectName: new FormControl(null, [Validators.required, projectNameValidator.get]),
|
||||||
@ -64,6 +73,16 @@ export class ImportProjectDialogComponent implements OnInit {
|
|||||||
this.resultMessage = 'Project was imported succesfully!';
|
this.resultMessage = 'Project was imported succesfully!';
|
||||||
this.isFinishEnabled = true;
|
this.isFinishEnabled = true;
|
||||||
};
|
};
|
||||||
|
this.uploader.onProgressItem = (progress: any) => {
|
||||||
|
this.uploadProgress = progress['progress'];
|
||||||
|
this.uploadServiceService.processBarCount(this.uploadProgress)
|
||||||
|
};
|
||||||
|
|
||||||
|
this.uploadServiceService.currentCancelItemDetails.subscribe((isCancel) => {
|
||||||
|
if (isCancel) {
|
||||||
|
this.cancelUploading()
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
get form() {
|
get form() {
|
||||||
@ -96,10 +115,12 @@ export class ImportProjectDialogComponent implements OnInit {
|
|||||||
importProject() {
|
importProject() {
|
||||||
const url = this.prepareUploadPath();
|
const url = this.prepareUploadPath();
|
||||||
this.uploader.queue.forEach((elem) => (elem.url = url));
|
this.uploader.queue.forEach((elem) => (elem.url = url));
|
||||||
this.uploader.authToken = `Bearer ${this.server.authToken.toString()}`
|
this.uploader.authToken = `Bearer ${this.server.authToken}`
|
||||||
this.isFirstStepCompleted = true;
|
this.isFirstStepCompleted = true;
|
||||||
const itemToUpload = this.uploader.queue[0];
|
const itemToUpload = this.uploader.queue[0];
|
||||||
this.uploader.uploadItem(itemToUpload);
|
this.uploader.uploadItem(itemToUpload);
|
||||||
|
this.snackBar.openFromComponent(UploadingProcessbarComponent,{panelClass: 'uplaoding-file-snackabar',data:{upload_file_type:'Project'}});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
openConfirmationDialog(existingProject: Project) {
|
openConfirmationDialog(existingProject: Project) {
|
||||||
@ -126,11 +147,11 @@ export class ImportProjectDialogComponent implements OnInit {
|
|||||||
|
|
||||||
onNoClick(): void {
|
onNoClick(): void {
|
||||||
this.uploader.cancelAll();
|
this.uploader.cancelAll();
|
||||||
this.dialogRef.close();
|
this.dialogRef.close(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
onFinishClick(): void {
|
onFinishClick(): void {
|
||||||
this.dialogRef.close();
|
this.dialogRef.close(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
onDeleteClick(): void {
|
onDeleteClick(): void {
|
||||||
@ -145,4 +166,14 @@ export class ImportProjectDialogComponent implements OnInit {
|
|||||||
const projectName = this.projectNameForm.controls['projectName'].value;
|
const projectName = this.projectNameForm.controls['projectName'].value;
|
||||||
return this.projectService.getUploadPath(this.server, this.uuid, projectName);
|
return this.projectService.getUploadPath(this.server, this.uuid, projectName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cancelUploading() {
|
||||||
|
this.uploader.clearQueue();
|
||||||
|
this.uploadServiceService.processBarCount(null)
|
||||||
|
this.toasterService.warning('Image upload cancelled');
|
||||||
|
this.uploadServiceService.cancelFileUploading(false)
|
||||||
|
this.isFirstStepCompleted = false
|
||||||
|
this.uploader.cancelAll();
|
||||||
|
this.dialogRef.close(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user