From 2cd2ee75e05bb11c1da6e1317b12455dc2d9a1fa Mon Sep 17 00:00:00 2001 From: Tmadkaud Date: Thu, 31 May 2018 15:25:36 +0200 Subject: [PATCH] menu folder file v1 --- routes/api.js | 11 +++++- src/app/book/book.component.ts | 22 ++++++++++-- src/app/home/home.component.html | 2 ++ src/app/main/main.component.html | 17 +++++---- src/app/main/main.component.ts | 61 ++++++++++++++++++++++++++++++-- 5 files changed, 98 insertions(+), 15 deletions(-) diff --git a/routes/api.js b/routes/api.js index 3cbbd56..8140cb4 100644 --- a/routes/api.js +++ b/routes/api.js @@ -226,6 +226,15 @@ router.post('/getFolderAppList', function(req, res) { }); }); +/* Get tout les files du user */ +router.post('/getFileAppList', function(req, res) { + FileMongo.find({ + owner: req.body.owner + }, function(err, file) { + res.json(file); + }); +}); + /* Get tout les files du mainFolder */ router.post('/getFileList', function(req, res) { FileMongo.find({ @@ -263,7 +272,7 @@ router.post('/signin', function(req, res) { }); }); - +////////// /* Multer upload */ router.post('/upload' , multer({storage: storage, limits: {fileSize: 30000000000}}).array("public[]", 12) ,function(req,res,next){ res.send(req.files); diff --git a/src/app/book/book.component.ts b/src/app/book/book.component.ts index cdcb6f4..2c9a64a 100644 --- a/src/app/book/book.component.ts +++ b/src/app/book/book.component.ts @@ -1,4 +1,4 @@ -import { Component, OnInit, OnDestroy, ViewChild } from '@angular/core'; +import { Component, OnInit, OnDestroy, ViewChild, Output, EventEmitter } from '@angular/core'; import { HttpClient, HttpHeaders } from '@angular/common/http'; import { Router, ActivatedRoute } from '@angular/router'; import { Observable } from 'rxjs/Observable'; @@ -10,7 +10,7 @@ import * as formData from 'form-data'; import {forEach} from '@angular/router/src/utils/collection'; import {type} from 'os'; import { DomSanitizer } from '@angular/platform-browser'; -//import { Dropzone } from 'dropzone'; +// import { Dropzone } from 'dropzone'; import { DropzoneComponent , DropzoneDirective, DropzoneConfigInterface } from 'ngx-dropzone-wrapper'; @@ -22,6 +22,11 @@ import { DropzoneComponent , DropzoneDirective, styleUrls: ['./book.component.css'] }) export class BookComponent implements OnInit, OnDestroy { + @Output() setAllUserAppFolder = new EventEmitter(); + + message: string = 'Hola Mundo!'; + + @Output() messageEvent = new EventEmitter(); currentUser: any; allUserFile: any; allUserFolder: any; @@ -63,7 +68,10 @@ export class BookComponent implements OnInit, OnDestroy { this.filesToUpload = []; this.test = ''; } - + sendMessage() { + console.log('caca'); + this.messageEvent.emit('caca') + } public toggleType(): void { this.type = (this.type === 'component') ? 'directive' : 'component'; } @@ -204,9 +212,14 @@ export class BookComponent implements OnInit, OnDestroy { }); } getAllUserAppFolder(){ + this.message = 'caca'; + this.sendMessage(); this.http.post('/api/getFolderAppList', {owner: this.currentUser.username.toString()}).subscribe(folders => { if (folders) { this.allUserAppFolder = folders; + console.log('yuuuuuuuuuu' + this.currentUser.username.toString()); + + this.setAllUserAppFolder.emit(this.currentUser.username.toString()); } else { this.allUserAppFolder = []; } @@ -297,6 +310,9 @@ export class BookComponent implements OnInit, OnDestroy { this.http.post('api/uploadFileMongo', { name: this.fileChooseName.toString(), path: this.mainFolder.path.toString(), type: this.filesToUpload[0].type.toString(), taille: this.filesToUpload[0].size.toString(), idUser: this.currentUser._id.toString(), owner: this.currentUser.username.toString(), lastDate: Date.now().toString(), url: ''}).subscribe(resp => { me.saveURLFileMongo(resp); var mee = this; + + + //////// me.makeFileRequest('http://localhost:3000/api/upload', [], this.filesToUpload, resp).then((result) => { mee.getfiles(); mee.filesToUpload = null; diff --git a/src/app/home/home.component.html b/src/app/home/home.component.html index 38b7884..c3aa8a0 100644 --- a/src/app/home/home.component.html +++ b/src/app/home/home.component.html @@ -50,6 +50,8 @@

Log in:

+ titi@caille.com + caille
diff --git a/src/app/main/main.component.html b/src/app/main/main.component.html index b350571..6d23e03 100644 --- a/src/app/main/main.component.html +++ b/src/app/main/main.component.html @@ -42,24 +42,23 @@
    - - - Collapsible menu + + + {{folder.name}} - + + Collapsible menu 2 @@ -70,11 +69,11 @@ - + Simple link 2 - + -->
diff --git a/src/app/main/main.component.ts b/src/app/main/main.component.ts index 4dd1b33..3572fe5 100644 --- a/src/app/main/main.component.ts +++ b/src/app/main/main.component.ts @@ -1,5 +1,6 @@ import { Component, OnInit } from '@angular/core'; import { Router, ActivatedRoute } from '@angular/router'; +import { HttpClient, HttpHeaders } from '@angular/common/http'; @Component({ selector: 'app-main', @@ -7,8 +8,12 @@ import { Router, ActivatedRoute } from '@angular/router'; styleUrls: ['./main.component.scss'] }) export class MainComponent implements OnInit { - - constructor(private router: Router, private route: ActivatedRoute) { } + httpOptions: any; + allUserAppFolder: any; + allUserAppFile: any; + mainFolder: any; + currentUser: any; + constructor(private router: Router, private route: ActivatedRoute, private http: HttpClient) { } logout() { localStorage.removeItem('jwtToken'); @@ -16,6 +21,58 @@ export class MainComponent implements OnInit { } 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() { + + 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) { + return this.allUserAppFile.filter((file) => file.path === path); + } + 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 = []; + } + }); + } }