Merge branch 'thierry' of ssh://git.marbelium.com:10023/Viiciouss/Sup_File into anis

This commit is contained in:
Viiciouss 2018-06-04 21:07:04 +02:00
commit f0bc36a327
5 changed files with 99 additions and 16 deletions

View File

@ -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 */ /* Get tout les files du mainFolder */
router.post('/getFileList', function(req, res) { router.post('/getFileList', function(req, res) {
FileMongo.find({ FileMongo.find({
@ -263,7 +272,7 @@ router.post('/signin', function(req, res) {
}); });
}); });
//////////
/* Multer upload */ /* Multer upload */
router.post('/upload' , multer({storage: storage, limits: {fileSize: 30000000000}}).array("public[]", 12) ,function(req,res,next){ router.post('/upload' , multer({storage: storage, limits: {fileSize: 30000000000}}).array("public[]", 12) ,function(req,res,next){
res.send(req.files); res.send(req.files);

View File

@ -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 { HttpClient, HttpHeaders } from '@angular/common/http';
import { Router, ActivatedRoute } from '@angular/router'; import { Router, ActivatedRoute } from '@angular/router';
import { Observable } from 'rxjs/Observable'; import { Observable } from 'rxjs/Observable';
@ -10,7 +10,7 @@ import * as formData from 'form-data';
import {forEach} from '@angular/router/src/utils/collection'; import {forEach} from '@angular/router/src/utils/collection';
import {type} from 'os'; import {type} from 'os';
import { DomSanitizer } from '@angular/platform-browser'; import { DomSanitizer } from '@angular/platform-browser';
//import { Dropzone } from 'dropzone'; // import { Dropzone } from 'dropzone';
import { DropzoneComponent , DropzoneDirective, import { DropzoneComponent , DropzoneDirective,
DropzoneConfigInterface } from 'ngx-dropzone-wrapper'; DropzoneConfigInterface } from 'ngx-dropzone-wrapper';
@ -22,6 +22,11 @@ import { DropzoneComponent , DropzoneDirective,
styleUrls: ['./book.component.css'] styleUrls: ['./book.component.css']
}) })
export class BookComponent implements OnInit, OnDestroy { export class BookComponent implements OnInit, OnDestroy {
@Output() setAllUserAppFolder = new EventEmitter<String>();
message: string = 'Hola Mundo!';
@Output() messageEvent = new EventEmitter<string>();
currentUser: any; currentUser: any;
allUserFile: any; allUserFile: any;
allUserFolder: any; allUserFolder: any;
@ -63,7 +68,10 @@ export class BookComponent implements OnInit, OnDestroy {
this.filesToUpload = []; this.filesToUpload = [];
this.test = ''; this.test = '';
} }
sendMessage() {
console.log('caca');
this.messageEvent.emit('caca')
}
public toggleType(): void { public toggleType(): void {
this.type = (this.type === 'component') ? 'directive' : 'component'; this.type = (this.type === 'component') ? 'directive' : 'component';
} }
@ -204,9 +212,14 @@ export class BookComponent implements OnInit, OnDestroy {
}); });
} }
getAllUserAppFolder(){ getAllUserAppFolder(){
this.message = 'caca';
this.sendMessage();
this.http.post('/api/getFolderAppList', {owner: this.currentUser.username.toString()}).subscribe(folders => { this.http.post('/api/getFolderAppList', {owner: this.currentUser.username.toString()}).subscribe(folders => {
if (folders) { if (folders) {
this.allUserAppFolder = folders; this.allUserAppFolder = folders;
console.log('yuuuuuuuuuu' + this.currentUser.username.toString());
this.setAllUserAppFolder.emit(this.currentUser.username.toString());
} else { } else {
this.allUserAppFolder = []; 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 => { 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); me.saveURLFileMongo(resp);
var mee = this; var mee = this;
////////
me.makeFileRequest('http://localhost:3000/api/upload', [], this.filesToUpload, resp).then((result) => { me.makeFileRequest('http://localhost:3000/api/upload', [], this.filesToUpload, resp).then((result) => {
mee.getfiles(); mee.getfiles();
mee.filesToUpload = null; mee.filesToUpload = null;

View File

@ -50,6 +50,8 @@
<!--Header--> <!--Header-->
<div class="text-center"> <div class="text-center">
<h3 class="white-text"><i class="fa fa-user white-text"></i> Log in:</h3> <h3 class="white-text"><i class="fa fa-user white-text"></i> Log in:</h3>
titi@caille.com
caille
<hr class="hr-light"> <hr class="hr-light">
</div> </div>

View File

@ -42,24 +42,23 @@
<ul class="collapsible collapsible-accordion"> <ul class="collapsible collapsible-accordion">
<mdb-squeezebox [multiple]="false" aria-multiselectable="false"> <mdb-squeezebox [multiple]="false" aria-multiselectable="false">
<!-- Collapsible link --> <!-- Collapsible link onclick="function(){ getAllUserAppFolder(); }" -->
<mdb-item> <mdb-item *ngFor="let folder of allUserAppFolder; let i = index;">
<mdb-item-head mdbWavesEffect><i class="fa fa-chevron-right"></i> Collapsible menu</mdb-item-head> <mdb-item-head mdbWavesEffect><i class="fa fa-chevron-right"></i>{{folder.name}}</mdb-item-head>
<mdb-item-body> <mdb-item-body>
<ul> <ul>
<li><a href="#" class="waves-effect" mdbWavesEffect>Link 1</a></li> <li><a class="waves-effect" *ngFor="let file of getItems(folder.path); let i = index;" mdbWavesEffect>{{file.name}}</a></li>
<li><a href="#" class="waves-effect" mdbWavesEffect>Link 2</a></li>
</ul> </ul>
</mdb-item-body> </mdb-item-body>
</mdb-item> </mdb-item>
<!-- Simple link --> <!-- Simple link
<mdb-item class="no-collase"> <mdb-item class="no-collase">
<mdb-item-head mdbWavesEffect><i class="fa fa-hand-pointer-o"></i> Simple link</mdb-item-head> <mdb-item-head mdbWavesEffect><i class="fa fa-hand-pointer-o"></i> Simple link</mdb-item-head>
<mdb-item-body></mdb-item-body> <mdb-item-body></mdb-item-body>
</mdb-item> </mdb-item>
<!-- Collapsible link -->
<mdb-item> <mdb-item>
<mdb-item-head mdbWavesEffect><i class="fa fa-eye"></i> Collapsible menu 2</mdb-item-head> <mdb-item-head mdbWavesEffect><i class="fa fa-eye"></i> Collapsible menu 2</mdb-item-head>
<mdb-item-body> <mdb-item-body>
@ -70,11 +69,11 @@
</mdb-item-body> </mdb-item-body>
</mdb-item> </mdb-item>
<!-- Simple link -->
<mdb-item class="no-collase"> <mdb-item class="no-collase">
<mdb-item-head mdbWavesEffect><i class="fa fa-diamond"></i> Simple link 2</mdb-item-head> <mdb-item-head mdbWavesEffect><i class="fa fa-diamond"></i> Simple link 2</mdb-item-head>
<mdb-item-body></mdb-item-body> <mdb-item-body></mdb-item-body>
</mdb-item> </mdb-item>-->
</mdb-squeezebox> </mdb-squeezebox>
</ul> </ul>

View File

@ -1,5 +1,6 @@
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { Router, ActivatedRoute } from '@angular/router'; import { Router, ActivatedRoute } from '@angular/router';
import { HttpClient, HttpHeaders } from '@angular/common/http';
@Component({ @Component({
selector: 'app-main', selector: 'app-main',
@ -7,8 +8,12 @@ import { Router, ActivatedRoute } from '@angular/router';
styleUrls: ['./main.component.scss'] styleUrls: ['./main.component.scss']
}) })
export class MainComponent implements OnInit { export class MainComponent implements OnInit {
httpOptions: any;
constructor(private router: Router, private route: ActivatedRoute) { } allUserAppFolder: any;
allUserAppFile: any;
mainFolder: any;
currentUser: any;
constructor(private router: Router, private route: ActivatedRoute, private http: HttpClient) { }
logout() { logout() {
localStorage.removeItem('jwtToken'); localStorage.removeItem('jwtToken');
@ -16,6 +21,58 @@ export class MainComponent implements OnInit {
} }
ngOnInit() { 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 = [];
}
});
}
} }