Skip to content

Commit f8a7693

Browse files
authored
Merge pull request #4 from marcode24/dev
💄 add UI for specific folder
2 parents e0ef9b5 + cefa943 commit f8a7693

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1006
-47
lines changed

src/app/app.module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { FeaturesModule } from './features/features.module';
99

1010
@NgModule({
1111
declarations: [
12-
AppComponent
12+
AppComponent,
1313
],
1414
imports: [
1515
BrowserModule,

src/app/core/components/header/header.component.scss

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ header {
3333

3434
& input.icon {
3535
background: var(--bg-sidebar);
36-
border: var(--border-input);
36+
border: 1px solid transparent;
3737
border-radius: 1rem;
3838
width: 100%;
3939
min-width: 0;
@@ -43,6 +43,13 @@ header {
4343
transition: 0.2s;
4444
box-shadow: var(--box-shadow);
4545

46+
&:focus {
47+
border: 1px solid var(--border-input);
48+
background: var(--bg-2);
49+
color: var(--fc-primary);
50+
outline: 0;
51+
}
52+
4653
& ~ i {
4754
top: 15px;
4855
left: 20px;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
export const MAX_FILE_SIZE = 2000000;
2+
export const ALLOWED_FILE_TYPES = [
3+
'image/png',
4+
'image/jpeg',
5+
'image/jpg',
6+
'application/pdf',
7+
'application/vnd.openxmlformats-officedocument.wordprocessingml.document', // .docx
8+
];
9+
10+
export const ICONS = {
11+
png: 'bxs-file-png',
12+
jpg: 'bxs-file-jpg',
13+
jpeg: 'bxs-file-image',
14+
pdf: 'bxs-file-pdf',
15+
docx: 'bxs-file',
16+
} as const;
17+
18+
export const ALLOWED_FILE_EXTENSIONS = [
19+
'png',
20+
'jpg',
21+
'jpeg',
22+
'pdf',
23+
'docx',
24+
];
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { TestBed } from '@angular/core/testing';
2+
3+
import { FolderGuard } from './folder.guard';
4+
5+
describe('FolderGuard', () => {
6+
let guard: FolderGuard;
7+
8+
beforeEach(() => {
9+
TestBed.configureTestingModule({});
10+
guard = TestBed.inject(FolderGuard);
11+
});
12+
13+
it('should be created', () => {
14+
expect(guard).toBeTruthy();
15+
});
16+
});

src/app/core/guards/folder.guard.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { Injectable } from '@angular/core';
2+
import { ActivatedRouteSnapshot, CanActivate, Router, UrlTree } from '@angular/router';
3+
4+
import { Observable, tap } from 'rxjs';
5+
6+
import { FolderService } from '@services/folder.service';
7+
8+
import { isMongoId } from '@utils/mongo.util';
9+
10+
@Injectable({
11+
providedIn: 'root'
12+
})
13+
export class FolderGuard implements CanActivate {
14+
15+
constructor(
16+
private folderService: FolderService,
17+
private router: Router
18+
) {}
19+
20+
canActivate(route: ActivatedRouteSnapshot)
21+
: Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
22+
const folderId = route.params['folderId'];
23+
if(!isMongoId(folderId)) return this.router.navigate(['/']);
24+
return this.folderService.getFolder(folderId).pipe(tap((hasAccess: boolean) => {
25+
if(!hasAccess) {
26+
return this.router.navigate(['/']);
27+
}
28+
}));
29+
}
30+
}

src/app/core/interfaces/response.interface.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { File } from "@models/file.model";
12
import { Folder } from "@models/folder.model";
23
import { User } from "@models/user.model";
34

@@ -15,3 +16,14 @@ export interface IFolderCreated {
1516
folder: Folder;
1617
msg: string;
1718
}
19+
20+
export interface IFolderResponse {
21+
ok: boolean,
22+
folder: Folder,
23+
}
24+
25+
export interface IFileResponse {
26+
ok: boolean,
27+
msg: string,
28+
files: File[]
29+
}

src/app/core/models/file.model.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ export class File {
1212
createdAt: Date;
1313
updatedAt: Date;
1414
folder: Folder;
15+
type: string;
1516
_id?: string;
1617
}

src/app/core/models/folder.model.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export class Folder {
1111
createdAt: Date;
1212
updatedAt: Date;
1313
parent: Folder;
14+
type: string;
1415
folders: Folder[];
1516
files: File[];
1617
color: string;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { FileSizePipe } from './file-size.pipe';
2+
3+
describe('FileSizePipe', () => {
4+
it('create an instance', () => {
5+
const pipe = new FileSizePipe();
6+
7+
expect(pipe).toBeTruthy();
8+
});
9+
});

src/app/core/pipes/file-size.pipe.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { Pipe, PipeTransform } from '@angular/core';
2+
3+
@Pipe({
4+
name: 'fileSize'
5+
})
6+
export class FileSizePipe implements PipeTransform {
7+
8+
transform(value: string | number): string {
9+
return this.formatBytes(+value);
10+
}
11+
12+
private formatBytes(bytes: number, decimals = 2): string {
13+
if (bytes === 0) {
14+
return '0 Bytes';
15+
}
16+
const k = 1024;
17+
const dm = decimals < 0 ? 0 : decimals;
18+
const sizes = ['Bytes', 'KB', 'MB'];
19+
const i = Math.floor(Math.log(bytes) / Math.log(k));
20+
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
21+
}
22+
23+
}

0 commit comments

Comments
 (0)