-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
IMP-67: Core 16.1: File Upload, Select Field, New form validation (#28)
- Loading branch information
Showing
53 changed files
with
509 additions
and
89 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
# Angular Core | ||
|
||
Core is a custom library designed to enhance and streamline Angular application development. It provides a set of reusable components, directives, and services that can be easily integrated into your Angular projects. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
projects/ng-core/src/lib/components/date-range-field/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
export * from './date-range-field.module'; | ||
export * from './date-range-field.component'; | ||
export * from './types/date-range'; | ||
export * from './utils/is-equal-date-range'; | ||
export * from './utils/create-date-range-to-today'; |
15 changes: 15 additions & 0 deletions
15
projects/ng-core/src/lib/components/date-range-field/utils/create-date-range-to-today.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { subDays, startOfDay, endOfDay } from 'date-fns'; | ||
|
||
import { DateRange } from '../types/date-range'; | ||
|
||
export function createDateRangeToToday(minDays: number = 1): DateRange { | ||
return { | ||
/** | ||
* If we take the beginning of the previous day to the end of the current one, | ||
* then it is guaranteed that there will be an interval of one day, | ||
* as a maximum of two days | ||
*/ | ||
start: subDays(startOfDay(new Date()), minDays), | ||
end: endOfDay(new Date()), | ||
}; | ||
} |
7 changes: 7 additions & 0 deletions
7
projects/ng-core/src/lib/components/date-range-field/utils/is-equal-date-range.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { isEqual } from 'date-fns'; | ||
|
||
import { DateRange } from '../types/date-range'; | ||
|
||
export function isEqualDateRange(a: DateRange, b: DateRange) { | ||
return isEqual(a.start, b.start) && isEqual(a.end, b.end); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
projects/ng-core/src/lib/components/file-upload/file-upload.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<div class="wrapper"> | ||
<button mat-button type="button" (click)="fileInput.click()"> | ||
{{ label ?? 'Choose File' }} | ||
</button> | ||
|
||
<div class="mat-body-2 mat-secondary-text mat-no-margin"> | ||
{{ file?.name }} | ||
</div> | ||
</div> | ||
|
||
<input #fileInput hidden type="file" (change)="loadFile($event)" /> |
12 changes: 12 additions & 0 deletions
12
projects/ng-core/src/lib/components/file-upload/file-upload.component.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
.wrapper { | ||
display: grid; | ||
grid-template-columns: min-content auto; | ||
align-items: center; | ||
grid-gap: 16px; | ||
|
||
& > * { | ||
white-space: nowrap; | ||
text-overflow: ellipsis; | ||
overflow: hidden; | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
projects/ng-core/src/lib/components/file-upload/file-upload.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { Component, EventEmitter, Input, Output } from '@angular/core'; | ||
|
||
import { NotifyLogService } from '../../services'; | ||
|
||
function hasExtension(fileName: string, extensions: string[]) { | ||
return ( | ||
!extensions?.length || | ||
new RegExp('(' + extensions.join('|').replace(/\./g, '\\.') + ')$').test(fileName) | ||
); | ||
} | ||
|
||
@Component({ | ||
selector: 'v-file-upload', | ||
templateUrl: './file-upload.component.html', | ||
styleUrls: ['./file-upload.component.scss'], | ||
}) | ||
export class FileUploadComponent { | ||
@Input() label?: string; | ||
@Input() extensions: string[] = []; | ||
|
||
@Output() upload = new EventEmitter<File | null>(); | ||
|
||
protected file?: File | null; | ||
|
||
constructor(private log: NotifyLogService) {} | ||
|
||
loadFile(event: Event) { | ||
const file = (event.target as HTMLInputElement)?.files?.[0] ?? null; | ||
if (!file) { | ||
this.log.error(new Error('File upload error')); | ||
return; | ||
} | ||
if (!hasExtension(file.name, this.extensions)) { | ||
this.log.error(new Error(`Supported file types: ${this.extensions.join(', ')}`)); | ||
return; | ||
} | ||
this.file = file; | ||
this.upload.emit(this.file); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
projects/ng-core/src/lib/components/file-upload/file-upload.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { CommonModule } from '@angular/common'; | ||
import { NgModule } from '@angular/core'; | ||
import { MatButtonModule } from '@angular/material/button'; | ||
|
||
import { FileUploadComponent } from './file-upload.component'; | ||
|
||
@NgModule({ | ||
declarations: [FileUploadComponent], | ||
exports: [FileUploadComponent], | ||
imports: [CommonModule, MatButtonModule], | ||
}) | ||
export class FileUploadModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './file-upload.module'; | ||
export * from './file-upload.component'; | ||
export * from './utils/load-file-content'; |
14 changes: 14 additions & 0 deletions
14
projects/ng-core/src/lib/components/file-upload/utils/load-file-content.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { Observable } from 'rxjs'; | ||
|
||
export function loadFileContent(file: File): Observable<string> { | ||
return new Observable((subscriber) => { | ||
if (!file) return file; | ||
const read = new FileReader(); | ||
read.readAsBinaryString(file); | ||
read.onloadend = function () { | ||
if (read.error) return subscriber.error(read.error); | ||
else subscriber.next((read.result as string) || ''); | ||
subscriber.complete(); | ||
}; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './progress.module'; | ||
export * from './progress.component'; | ||
export * from './utils/get-progress-by-count'; |
1 change: 1 addition & 0 deletions
1
projects/ng-core/src/lib/components/progress/progress.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<mat-progress-bar *ngIf="!!mode" [mode]="mode" [value]="value"></mat-progress-bar> |
25 changes: 25 additions & 0 deletions
25
projects/ng-core/src/lib/components/progress/progress.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { Component, Input } from '@angular/core'; | ||
|
||
import { Progressable } from '../../types/progressable'; | ||
|
||
@Component({ | ||
selector: 'v-progress', | ||
templateUrl: './progress.component.html', | ||
}) | ||
export class ProgressComponent implements Progressable { | ||
@Input() progress: Progressable['progress']; | ||
|
||
get mode() { | ||
return typeof this.progress === 'number' && this.progress <= 1 && this.progress > 0 | ||
? 'determinate' | ||
: !!this.progress || this.progress === '' | ||
? 'indeterminate' | ||
: undefined; | ||
} | ||
|
||
get value(): number { | ||
return this.mode === 'determinate' | ||
? Math.max(Math.min((1 - (this.progress as number)) * 100, 100), 0) | ||
: (undefined as never); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
projects/ng-core/src/lib/components/progress/progress.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { CommonModule } from '@angular/common'; | ||
import { NgModule } from '@angular/core'; | ||
import { MatProgressBarModule } from '@angular/material/progress-bar'; | ||
|
||
import { ProgressComponent } from './progress.component'; | ||
|
||
@NgModule({ | ||
declarations: [ProgressComponent], | ||
imports: [CommonModule, MatProgressBarModule], | ||
exports: [ProgressComponent], | ||
}) | ||
export class ProgressModule {} |
3 changes: 3 additions & 0 deletions
3
projects/ng-core/src/lib/components/progress/utils/get-progress-by-count.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export function getProgressByCount(count: number, completedCount: number = Number.MIN_VALUE) { | ||
return 1 - completedCount / count; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './select-field.module'; | ||
export * from './select-field.component'; | ||
export * from './types/option'; |
Oops, something went wrong.