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.
119 lines
3.4 KiB
TypeScript
119 lines
3.4 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']);
|
|
}
|
|
});
|
|
|
|
}
|
|
|
|
|
|
getItems(path) {
|
|
var test = [];
|
|
if(this.allUserAppFile !== undefined){
|
|
test = this.allUserAppFile.filter((file) => file.path === path);
|
|
}
|
|
return test;
|
|
}
|
|
|
|
setOriginFolder(path) {
|
|
//console.log( ' path : ' + path);
|
|
//var origin = [];
|
|
|
|
//for (let f of this.allUserAppFolder){
|
|
var pathChunk = path.split('/');
|
|
|
|
var origin = pathChunk.length === 1 ? pathChunk[0] : pathChunk[pathChunk.length - 2]
|
|
//console.log( ' origin : ' + origin);
|
|
// for (var i = 0; i < pathChunk.length; i++) {
|
|
// console.log(i + ' pathChunk[i] : ' + pathChunk[i]);
|
|
// var temp = (pathChunk.length === 1 ? pathChunk[0] : pathChunk[pathChunk.length - 2]);
|
|
// console.log(i + ' temp : ' + temp);
|
|
// }
|
|
|
|
//}
|
|
return origin;
|
|
}
|
|
|
|
getItemsFolder(name) {
|
|
var tempp;
|
|
var test = [];
|
|
if(this.allUserAppFolder !== undefined) {
|
|
tempp = this.allUserAppFolder;
|
|
test = tempp.filter((folder) => folder.origin === name);
|
|
|
|
}
|
|
return test;
|
|
}
|
|
|
|
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 = [];
|
|
}
|
|
});
|
|
}
|
|
|
|
getAllUserAppFolder(){
|
|
|
|
this.http.post('/api/getFolderAppList', {owner: this.currentUser.username.toString()}).subscribe(folders => {
|
|
if (folders) {
|
|
|
|
this.allUserAppFolder = folders;
|
|
for (let f of this.allUserAppFolder){
|
|
f.origin = this.setOriginFolder(f.path);
|
|
//console.log('origin : ' + f.origin);
|
|
}
|
|
this.getAllUserAppFiles();
|
|
|
|
} else {
|
|
this.allUserAppFolder = [];
|
|
}
|
|
});
|
|
|
|
|
|
}
|
|
}
|