File
Metadata
selector |
app-save-file |
styleUrls |
save-file.component.scss |
templateUrl |
save-file.component.html |
Methods
setState
|
setState(value: boolean)
|
Sets the open/closed state of the popup and is deployed by the parent component.
Parameters :
-
value
- The boolean value representing the required state.
Returns: void
|
submitFile
|
submitFile()
|
Submits the data obtained from the IDE (the parent component) in the form of a File interface and reloads the parent component with the new filepath.
Returns: void
|
isActive
|
isActive: boolean
|
Default value: false
|
isUploading
|
isUploading: boolean
|
Default value: false
|
import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core';
import {FileService} from '../file.service';
import {File} from '../file';
import {Router} from '@angular/router';
@Component({
selector: 'app-save-file',
templateUrl: './save-file.component.html',
styleUrls: ['./save-file.component.scss']
})
export class SaveFileComponent implements OnInit {
isActive = false;
@Output() savedFile = new EventEmitter<boolean>();
@Input() file: File;
isUploading = false;
constructor(public fileService: FileService, private router: Router) {
}
ngOnInit(): void {
}
/**
* Sets the open/closed state of the popup and is deployed by the parent component.
* @param value - The boolean value representing the required state.
*/
setState(value: boolean): void {
const text = document.getElementById('filenameInput') as HTMLTextAreaElement;
this.isActive = value;
if (value) {
text.focus();
}
}
/**
* Submits the data obtained from the IDE (the parent component) in the form of a File interface and reloads the parent component with
* the new filepath.
*/
submitFile(): void {
this.isUploading = true;
this.fileService.upload(this.file, false)
.subscribe((response) => {
this.isUploading = false;
this.savedFile.emit(true);
this.isActive = false;
this.router.navigate(['/arena/file/', this.file.filename + this.file.language]).then();
console.log(response);
}, (error) => {
console.log(error);
this.isUploading = false;
});
}
}