You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
84 lines
2.5 KiB
TypeScript
84 lines
2.5 KiB
TypeScript
import { Component, OnInit } from '@angular/core';
|
|
import { Router, ActivatedRoute } from '@angular/router';
|
|
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
|
|
|
@Component({
|
|
selector: 'app-main',
|
|
templateUrl: './main.component.html',
|
|
styleUrls: ['./main.component.scss']
|
|
})
|
|
export class MainComponent implements OnInit {
|
|
httpOptions: any;
|
|
allUserAppFolder: any;
|
|
allUserAppFile: any;
|
|
mainFolder: any;
|
|
currentUser: any;
|
|
|
|
constructor(private router: Router, private route: ActivatedRoute, private http: HttpClient) { }
|
|
|
|
logout() {
|
|
localStorage.removeItem('jwtToken');
|
|
this.router.navigate(['home']);
|
|
}
|
|
|
|
ngOnInit() {
|
|
|
|
this.httpOptions = {
|
|
headers: new HttpHeaders({ 'Authorization': localStorage.getItem('jwtToken'), 'Access-Control-Allow-Origin' : '*'}),
|
|
pathFolder: ''
|
|
};
|
|
|
|
this.http.get('/api/getCurrentUser', this.httpOptions).subscribe(user => {
|
|
this.currentUser = user;
|
|
if (user) {
|
|
this.getAllUserAppFolder();
|
|
}
|
|
}, err => {
|
|
if (err.status === 401) {
|
|
this.router.navigate(['login']);
|
|
}
|
|
});
|
|
|
|
}
|
|
getAllUserAppFiles() {
|
|
console.log(this.currentUser.username.toString());
|
|
this.http.post('/api/getFileAppList', {owner: this.currentUser.username.toString()}).subscribe(files => {
|
|
if (files) {
|
|
this.allUserAppFile = files;
|
|
for (let f of this.allUserAppFile){
|
|
console.log(f.name);
|
|
//f.fileTab = this.getfiles(f);
|
|
}
|
|
// return files;
|
|
} else {
|
|
this.allUserAppFile = [];
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
getItems(path) {
|
|
var test = [];
|
|
if(this.allUserAppFile !== undefined){
|
|
test = this.allUserAppFile.filter((file) => file.path === path);
|
|
}
|
|
return test;
|
|
}
|
|
getAllUserAppFolder(){
|
|
|
|
this.http.post('/api/getFolderAppList', {owner: this.currentUser.username.toString()}).subscribe(folders => {
|
|
if (folders) {
|
|
this.allUserAppFolder = folders;
|
|
this.getAllUserAppFiles();
|
|
// for (let f of this.allUserAppFolder){
|
|
// console.log(f.name);
|
|
// //f.fileTab = this.getfiles(f);
|
|
// console.log(f.fileTab);
|
|
// }
|
|
} else {
|
|
this.allUserAppFolder = [];
|
|
}
|
|
});
|
|
}
|
|
}
|