Commit 0f54208a authored by Paarth's avatar Paarth

delete service added

parent f799d0c7
...@@ -13,6 +13,7 @@ export class FileService { ...@@ -13,6 +13,7 @@ export class FileService {
saveUrl = 'http://localhost/sfcode/backend/filesave.php'; saveUrl = 'http://localhost/sfcode/backend/filesave.php';
uploadUrl = 'http://localhost/sfcode/backend/fileupload.php'; uploadUrl = 'http://localhost/sfcode/backend/fileupload.php';
filelistUrl = 'http://localhost/sfcode/backend/list_files.php' filelistUrl = 'http://localhost/sfcode/backend/list_files.php'
deleteUrl = 'http://localhost/sfcode/backend/filedelete.php';
constructor(private http: HttpClient) { constructor(private http: HttpClient) {
} }
...@@ -44,5 +45,8 @@ export class FileService { ...@@ -44,5 +45,8 @@ export class FileService {
formData.append('file', file, file.name); formData.append('file', file, file.name);
return this.http.post(this.uploadUrl, formData); return this.http.post(this.uploadUrl, formData);
} }
delete(file): Observable<any> {
return this.http.post(this.deleteUrl,file);
}
} }
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
<div *ngFor="let file of files" class="card"> <div *ngFor="let file of files" class="card">
<span class="title">{{file.filename}}{{file.language}}</span> <span class="title">{{file.filename}}{{file.language}}</span>
<button>Delete</button> <button (click)="onDelete()" [disabled]="deleting">Delete</button>
<button>Edit</button> <button>Edit</button>
<button>Run</button> <button>Run</button>
......
...@@ -14,7 +14,8 @@ export class FileComponent implements OnInit { ...@@ -14,7 +14,8 @@ export class FileComponent implements OnInit {
user: User; user: User;
files: File[]; files: File[];
shortLink = ''; shortLink = '';
loading = false; loading = false; // Flag variable
deleting = false; //Flag variable
fileToUpload: File = null; fileToUpload: File = null;
uploadPopupActive = false; uploadPopupActive = false;
...@@ -56,4 +57,18 @@ export class FileComponent implements OnInit { ...@@ -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