File tree Expand file tree Collapse file tree 6 files changed +99
-3
lines changed Expand file tree Collapse file tree 6 files changed +99
-3
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,8 @@ import { CommonModule } from '@angular/common';
2
2
import { NgModule } from '@angular/core' ;
3
3
import { RouterModule } from '@angular/router' ;
4
4
5
+ import { PipesModule } from '@pipes/pipes.module' ;
6
+
5
7
import { HeaderComponent } from './header/header.component' ;
6
8
import { SidebarComponent } from './sidebar/sidebar.component' ;
7
9
@@ -12,7 +14,8 @@ import { SidebarComponent } from './sidebar/sidebar.component';
12
14
] ,
13
15
imports : [
14
16
CommonModule ,
15
- RouterModule
17
+ RouterModule ,
18
+ PipesModule
16
19
] ,
17
20
exports : [
18
21
SidebarComponent ,
Original file line number Diff line number Diff line change 23
23
< span class ="name "> Deleted</ span >
24
24
</ a >
25
25
</ li >
26
+ < li class ="item space ">
27
+ < div class ="used-space ">
28
+ < span class ="name "> Espacio utilizado</ span >
29
+ < div class ="progress-bar ">
30
+ < div class ="progress "
31
+ #progress
32
+ [ngStyle] ="{'width': getProgress() } ">
33
+ </ div >
34
+ </ div >
35
+ < div class ="percentage ">
36
+ < span class ="used "> {{ userActive.usedSpace | fileSize }}</ span >
37
+ < span class ="slash "> /</ span >
38
+ < span class ="remaining "> {{ userActive.totalSpace | fileSize }}</ span >
39
+ </ div >
40
+ </ div >
41
+ </ li >
26
42
</ ul >
27
43
</ nav >
Original file line number Diff line number Diff line change 65
65
}
66
66
}
67
67
}
68
+
69
+ .space {
70
+ margin-top : 1.5rem ;
71
+
72
+ & .used-space {
73
+ padding : 0 0.5rem ;
74
+ display : flex ;
75
+ flex-direction : column ;
76
+
77
+ & .name {
78
+ @include fs-5 ;
79
+ @include fw-500 ;
80
+ color : var (--fc-primary );
81
+ text-align : center ;
82
+ margin-bottom : 0.8rem ;
83
+ }
84
+
85
+ & .progress-bar {
86
+ width : 100% ;
87
+ height : 10px ;
88
+ border-radius : 1rem ;
89
+ background : var (--bg-hover-2 );
90
+ overflow : hidden ;
91
+
92
+ & .progress {
93
+ height : 100% ;
94
+ background : var (--fc-purple );
95
+ width : 0% ;
96
+ border-radius : 1rem ;
97
+ }
98
+ }
99
+
100
+ & .percentage {
101
+ @include fs-6 ;
102
+ @include fw-500 ;
103
+ color : var (--fc-primary );
104
+ margin-top : 0.5rem ;
105
+ display : flex ;
106
+ align-items : center ;
107
+ justify-content : center ;
108
+ gap : 0.2rem ;
109
+ }
110
+ }
111
+ }
112
+
Original file line number Diff line number Diff line change 1
- import { Component } from '@angular/core' ;
1
+ import { Component , OnDestroy , OnInit } from '@angular/core' ;
2
+
3
+ import { Subscription } from 'rxjs' ;
4
+
5
+ import { AuthService } from '@services/auth.service' ;
6
+ import { FileService } from '@services/file.service' ;
2
7
3
8
@Component ( {
4
9
selector : 'app-sidebar' ,
5
10
templateUrl : './sidebar.component.html' ,
6
11
styleUrls : [ './sidebar.component.scss' ]
7
12
} )
8
- export class SidebarComponent { }
13
+ export class SidebarComponent implements OnDestroy , OnInit {
14
+ userActive = this . authService . userActive ;
15
+ private totalSizeSubscription : Subscription ;
16
+ constructor (
17
+ private authService : AuthService ,
18
+ private fileService : FileService
19
+ ) { }
20
+ ngOnInit ( ) : void {
21
+ this . totalSizeSubscription = this . fileService . updateTotalSize
22
+ . subscribe ( ( totalSize ) => {
23
+ this . userActive . usedSpace += totalSize ;
24
+ } ) ;
25
+ }
26
+
27
+ ngOnDestroy ( ) : void {
28
+ this . totalSizeSubscription . unsubscribe ( ) ;
29
+ }
30
+
31
+ getProgress ( ) : string {
32
+ const percentage = this . userActive . usedSpace / this . userActive . totalSpace * 100 ;
33
+ return `${ percentage } %` ;
34
+ }
35
+ }
Original file line number Diff line number Diff line change @@ -11,5 +11,7 @@ export class User {
11
11
createdAt : Date ;
12
12
updatedAt : Date ;
13
13
rootFolder : Folder ;
14
+ totalSpace : number ;
15
+ usedSpace : number ;
14
16
_id ?: string ;
15
17
}
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ const base_url = environment.base_url;
17
17
} )
18
18
export class FileService {
19
19
filesCreated : EventEmitter < FileModel [ ] > = new EventEmitter ( ) ;
20
+ updateTotalSize : EventEmitter < number > = new EventEmitter ( ) ;
20
21
21
22
get headers ( ) {
22
23
return {
@@ -36,6 +37,8 @@ export class FileService {
36
37
files . forEach ( ( file ) => formData . append ( 'file' , file ) ) ;
37
38
return this . http . post < IFileResponse > ( url , formData , this . headers ) . pipe ( map ( resp => {
38
39
this . filesCreated . emit ( resp . files ) ;
40
+ const total = resp . files . reduce ( ( acc , file ) => acc + file . size , 0 ) ;
41
+ this . updateTotalSize . emit ( total ) ;
39
42
return resp . ok ;
40
43
} ) ) ;
41
44
}
You can’t perform that action at this time.
0 commit comments