Commit 0f54208a authored by Paarth's avatar Paarth

delete service added

parent f799d0c7
......@@ -13,6 +13,7 @@ export class FileService {
saveUrl = 'http://localhost/sfcode/backend/filesave.php';
uploadUrl = 'http://localhost/sfcode/backend/fileupload.php';
filelistUrl = 'http://localhost/sfcode/backend/list_files.php'
deleteUrl = 'http://localhost/sfcode/backend/filedelete.php';
constructor(private http: HttpClient) {
}
......@@ -44,5 +45,8 @@ export class FileService {
formData.append('file', file, file.name);
return this.http.post(this.uploadUrl, formData);
}
delete(file): Observable<any> {
return this.http.post(this.deleteUrl,file);
}
}
......@@ -10,7 +10,7 @@
<div *ngFor="let file of files" class="card">
<span class="title">{{file.filename}}{{file.language}}</span>
<button>Delete</button>
<button (click)="onDelete()" [disabled]="deleting">Delete</button>
<button>Edit</button>
<button>Run</button>
......
......@@ -14,7 +14,8 @@ export class FileComponent implements OnInit {
user: User;
files: File[];
shortLink = '';
loading = false;
loading = false; // Flag variable
deleting = false; //Flag variable
fileToUpload: File = null;
uploadPopupActive = false;
......@@ -56,4 +57,18 @@ export class FileComponent implements OnInit {
);
}
onDelete(file): void {
this.deleting = true;
this.fileService.delete(file).subscribe(
() => {
this.deleting = false;
this.files.forEach((element,index)=>{
if(element==file){
this.files.splice(index,1);
}
});
}
);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment