|
|
|
@ -1,4 +1,4 @@
|
|
|
|
|
import { Component, OnInit, OnDestroy, ViewChild, Output, EventEmitter } from '@angular/core';
|
|
|
|
|
import { Component, OnInit, OnDestroy, ViewChild, Output, Input, EventEmitter } from '@angular/core';
|
|
|
|
|
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
|
|
|
|
import { Router, ActivatedRoute } from '@angular/router';
|
|
|
|
|
import { Observable } from 'rxjs/Observable';
|
|
|
|
@ -18,12 +18,15 @@ import { DropzoneComponent , DropzoneDirective,
|
|
|
|
|
|
|
|
|
|
import { CompleterService } from '../typescripts/pro';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'app-book',
|
|
|
|
|
templateUrl: './book.component.html',
|
|
|
|
|
styleUrls: ['./book.component.css']
|
|
|
|
|
})
|
|
|
|
|
export class BookComponent implements OnInit, OnDestroy {
|
|
|
|
|
@Input() socialIdUser: String;
|
|
|
|
|
@Output() setAllUserAppFolder = new EventEmitter<String>();
|
|
|
|
|
|
|
|
|
|
message: string = 'Hola Mundo!';
|
|
|
|
@ -32,6 +35,7 @@ export class BookComponent implements OnInit, OnDestroy {
|
|
|
|
|
currentUser: any;
|
|
|
|
|
allUserFile: any;
|
|
|
|
|
allUserFolder: any;
|
|
|
|
|
//socialIdUser: String;
|
|
|
|
|
filterAllUserFolder: any;
|
|
|
|
|
allUserAppFolder: any;
|
|
|
|
|
allUserAppFile: any;
|
|
|
|
@ -55,18 +59,6 @@ export class BookComponent implements OnInit, OnDestroy {
|
|
|
|
|
searchStr: String;
|
|
|
|
|
dataService: any;
|
|
|
|
|
|
|
|
|
|
protected searchData = [
|
|
|
|
|
{ color: 'red'},
|
|
|
|
|
{ color: 'green'},
|
|
|
|
|
{ color: 'blue'},
|
|
|
|
|
{ color: 'cyan'},
|
|
|
|
|
{ color: 'magenta'},
|
|
|
|
|
{ color: 'yellow'},
|
|
|
|
|
{ color: 'black'},
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public type: string = 'component';
|
|
|
|
|
|
|
|
|
|
public disabled: boolean = false;
|
|
|
|
@ -84,19 +76,9 @@ export class BookComponent implements OnInit, OnDestroy {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
constructor(private completerService: CompleterService, private http: HttpClient, private router: Router, private route: ActivatedRoute, public sanitizer: DomSanitizer) {
|
|
|
|
|
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;
|
|
|
|
|
this.openFolder('Home');
|
|
|
|
|
}, err => {
|
|
|
|
|
if (err.status === 401) {
|
|
|
|
|
this.router.navigate(['Home']);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.isClickCreateFolder = false;
|
|
|
|
|
this.fileChooseName = 'None';
|
|
|
|
|
this.filesToUpload = [];
|
|
|
|
@ -105,7 +87,6 @@ export class BookComponent implements OnInit, OnDestroy {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
sendMessage() {
|
|
|
|
|
console.log('caca');
|
|
|
|
|
this.messageEvent.emit('caca')
|
|
|
|
|
}
|
|
|
|
|
public toggleType(): void {
|
|
|
|
@ -150,13 +131,12 @@ export class BookComponent implements OnInit, OnDestroy {
|
|
|
|
|
this.filesToUpload = args;
|
|
|
|
|
this.fileChooseName = args[0].name;
|
|
|
|
|
|
|
|
|
|
var reader = new FileReader();
|
|
|
|
|
reader.onload = function() {
|
|
|
|
|
alert(reader.result);
|
|
|
|
|
};
|
|
|
|
|
reader.readAsText(args[0]);
|
|
|
|
|
// var reader = new FileReader();
|
|
|
|
|
// reader.onload = function() {
|
|
|
|
|
// alert(reader.result);
|
|
|
|
|
// };
|
|
|
|
|
// reader.readAsText(args[0]);
|
|
|
|
|
|
|
|
|
|
console.log('ggguu :' + JSON.stringify(args));
|
|
|
|
|
this.upload();
|
|
|
|
|
this.resetDropzoneUploads();
|
|
|
|
|
this.openFolder(this.mainFolder.path);
|
|
|
|
@ -164,12 +144,32 @@ export class BookComponent implements OnInit, OnDestroy {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
|
this.httpOptions = {
|
|
|
|
|
headers: new HttpHeaders({
|
|
|
|
|
'Authorization': localStorage.getItem('jwtToken'),
|
|
|
|
|
'Access-Control-Allow-Origin' : '*',
|
|
|
|
|
'Access-Control-Allow-Methods' : 'GET, POST, OPTIONS, PUT, PATCH, DELETE',
|
|
|
|
|
'Access-Control-Allow-Headers' : 'Origin, X-Requested-With, Content-Type, Accept'
|
|
|
|
|
}),
|
|
|
|
|
pathFolder: ''
|
|
|
|
|
};
|
|
|
|
|
// 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;
|
|
|
|
|
this.openFolder('Home');
|
|
|
|
|
}, err => {
|
|
|
|
|
if (err.status === 401) {
|
|
|
|
|
this.router.navigate(['login']);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
deleteFile(fileToDelete) {
|
|
|
|
|
this.http.post('/api/deleteFileMongo', fileToDelete).subscribe(file => {
|
|
|
|
|
console.log('this.mainFolder.path : ' + this.mainFolder.path);
|
|
|
|
|
this.openFolder(this.mainFolder.path);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
@ -203,7 +203,6 @@ export class BookComponent implements OnInit, OnDestroy {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getAllUserAppFiles() {
|
|
|
|
|
console.log(this.currentUser.username.toString());
|
|
|
|
|
this.http.post('/api/getFileAppList', {owner: this.currentUser.username.toString()}).subscribe(files => {
|
|
|
|
|
if (files) {
|
|
|
|
|
this.allUserAppFile = files;
|
|
|
|
@ -213,7 +212,7 @@ export class BookComponent implements OnInit, OnDestroy {
|
|
|
|
|
this.dataService = this.completerService.local(this.allItems, 'name', 'path');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (let f of this.allUserAppFile){
|
|
|
|
|
for (let f of this.allItems){
|
|
|
|
|
console.log(f.name);
|
|
|
|
|
//f.fileTab = this.getfiles(f);
|
|
|
|
|
}
|
|
|
|
@ -239,7 +238,6 @@ export class BookComponent implements OnInit, OnDestroy {
|
|
|
|
|
for (let f of this.allUserFile) {
|
|
|
|
|
|
|
|
|
|
this.sizeFile += +f.taille;
|
|
|
|
|
console.log('this.sizeFile : ' + this.sizeFile);
|
|
|
|
|
if(f.type === ('image/jpeg') || f.type === ('image/png')){
|
|
|
|
|
f.data = f.url;
|
|
|
|
|
f.urlSafe = this.sanitizer.bypassSecurityTrustUrl(f.url);
|
|
|
|
@ -270,7 +268,6 @@ export class BookComponent implements OnInit, OnDestroy {
|
|
|
|
|
this.http.post('/api/getFolderAppList', {owner: this.currentUser.username.toString()}).subscribe(folders => {
|
|
|
|
|
if (folders) {
|
|
|
|
|
this.allUserAppFolder = folders;
|
|
|
|
|
console.log(this.currentUser.username.toString());
|
|
|
|
|
|
|
|
|
|
this.setAllUserAppFolder.emit(this.currentUser.username.toString());
|
|
|
|
|
|
|
|
|
@ -320,13 +317,11 @@ export class BookComponent implements OnInit, OnDestroy {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.httpOptions.pathFolder = path;
|
|
|
|
|
|
|
|
|
|
this.isClickCreateFolder = false;
|
|
|
|
|
|
|
|
|
|
this.http.post('/api/getMainFolder', {path: path, owner: this.currentUser.username.toString()}).subscribe(folder => {
|
|
|
|
|
if (folder) {
|
|
|
|
|
this.mainFolder = folder;
|
|
|
|
|
console.log('folder : ' + folder);
|
|
|
|
|
this.getfolders();
|
|
|
|
|
this.getAllUserAppFolder();
|
|
|
|
|
this.getfiles();
|
|
|
|
@ -368,7 +363,6 @@ export class BookComponent implements OnInit, OnDestroy {
|
|
|
|
|
upload() {
|
|
|
|
|
var me = this;
|
|
|
|
|
if(this.mainFolder !== undefined){
|
|
|
|
|
console.log('this.filesToUpload[0] : ' + JSON.stringify(this.filesToUpload[0]));
|
|
|
|
|
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;
|
|
|
|
|