11import { Component , ElementRef , Input , ViewChild } from '@angular/core' ;
22
33import { FileService } from '@services/file.service' ;
4+ import { ModalService } from '@services/modal.service' ;
45
56import { File } from '@models/file.model' ;
67import { Folder } from '@models/folder.model' ;
@@ -13,13 +14,21 @@ import { Folder } from '@models/folder.model';
1314export class DotsDropdownComponent {
1415 @Input ( ) file : File | Folder ;
1516 @ViewChild ( 'dropdown' ) dropdown : ElementRef ;
16-
17+ @Input ( ) id : string ;
18+ dropdowns : HTMLUListElement [ ] = [ ] ;
1719 constructor (
1820 private fileService : FileService ,
21+ private modalService : ModalService ,
1922 ) { }
2023
2124 changeVisibility ( ) {
2225 this . dropdown . nativeElement . classList . toggle ( 'show' ) ;
26+ this . dropdowns = Array . from ( document . querySelectorAll ( '.dropdown-list' ) ) ;
27+ this . dropdowns . forEach ( ( dropdown ) => {
28+ if ( dropdown . id !== this . buildId ( ) ) {
29+ dropdown . classList . remove ( 'show' ) ;
30+ }
31+ } ) ;
2332 }
2433
2534 downloadFile ( ) : void {
@@ -37,7 +46,22 @@ export class DotsDropdownComponent {
3746 } ) ;
3847 }
3948
49+ buildId ( ) : string {
50+ const length = this . file . _id ?. length as number ;
51+ const id = this . file . _id ?. substring ( length - 10 ) ;
52+ return id as string ;
53+ }
54+
4055 hideDropdown ( ) : void {
4156 this . dropdown . nativeElement . classList . remove ( 'show' ) ;
4257 }
58+
59+ isFile ( ) : boolean {
60+ return this . file . type === 'file' ;
61+ }
62+
63+ openRenameModal ( ) : void {
64+ this . hideDropdown ( ) ;
65+ this . modalService . openUpdateName ( this . file . _id as string , this . file . name ) ;
66+ }
4367}
0 commit comments