Skip to content

Commit 9593412

Browse files
jhonyeduardoalinelariguet
authored andcommitted
feat(upload): utiliza o componente progress como barra de progresso
Atualiza a identidade visual da barra de progresso no componente upload e também utiliza a ideia de componentização Fixes DTHFUI-1587
1 parent 3e11fe7 commit 9593412

File tree

8 files changed

+357
-357
lines changed

8 files changed

+357
-357
lines changed

projects/ui/src/lib/components/po-field/po-field.module.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ import { FormsModule } from '@angular/forms';
44
import { HttpClientModule } from '@angular/common/http';
55

66
import { PoButtonGroupModule } from '../po-button-group/index';
7-
import { PoButtonModule } from '../../components/po-button/index';
7+
import { PoButtonModule } from '../po-button/index';
88
import { PoDisclaimerModule } from './../po-disclaimer/po-disclaimer.module';
9-
import { PoLoadingModule } from '../../components/po-loading/index';
10-
import { PoModalModule } from '../../components/po-modal/po-modal.module';
11-
import { PoTableModule } from '../../components/po-table/po-table.module';
9+
import { PoLoadingModule } from '../po-loading/index';
10+
import { PoModalModule } from '../po-modal/po-modal.module';
11+
import { PoProgressModule } from './../po-progress/po-progress.module';
12+
import { PoServicesModule } from '../../services/services.module';
13+
import { PoTableModule } from '../po-table/po-table.module';
1214
import { PoTooltipModule } from './../../directives/po-tooltip/po-tooltip.module';
1315

1416
import { PoCalendarComponent } from './po-datepicker/po-calendar/po-calendar.component';
@@ -37,7 +39,6 @@ import { PoPasswordComponent } from './po-password/po-password.component';
3739
import { PoRadioGroupComponent } from './po-radio-group/po-radio-group.component';
3840
import { PoSelectComponent } from './po-select/po-select.component';
3941
import { PoSelectOptionTemplateDirective } from './po-select/po-select-option-template/po-select-option-template.directive';
40-
import { PoServicesModule } from '../../services/services.module';
4142
import { PoSwitchComponent } from './po-switch/po-switch.component';
4243
import { PoTextareaComponent } from './po-textarea/po-textarea.component';
4344
import { PoUploadComponent } from './po-upload/po-upload.component';
@@ -66,6 +67,7 @@ import { PoUrlComponent } from './po-url/po-url.component';
6667
PoDisclaimerModule,
6768
PoLoadingModule,
6869
PoModalModule,
70+
PoProgressModule,
6971
PoServicesModule,
7072
PoTableModule,
7173
PoTooltipModule

projects/ui/src/lib/components/po-field/po-upload/interfaces/po-upload-literals.interface.ts

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,24 @@
77
*/
88
export interface PoUploadLiterals {
99

10-
/** Texto exibido no label para cancelar o envio. */
10+
/**
11+
* @deprecated 3.X.X
12+
* @description
13+
*
14+
* **Deprecated**
15+
*
16+
* Texto exibido no label para cancelar o envio.
17+
*/
1118
cancel?: string;
1219

13-
/** Texto exibido no label para excluir o arquivo. */
20+
/**
21+
* @deprecated 3.X.X
22+
* @description
23+
*
24+
* **Deprecated**
25+
*
26+
* Texto exibido no label para excluir o arquivo.
27+
*/
1428
deleteFile?: string;
1529

1630
/** Texto exibido na área onde podem ser arrastados os arquivos ao utilizar a opção de *dragDrop*. */
@@ -34,7 +48,20 @@ export interface PoUploadLiterals {
3448
/** Texto exibido no label do botão para iniciar o envio dos arquivos. */
3549
startSending?: string;
3650

37-
/** Texto exibido no label para tentar novamente. */
51+
/**
52+
* @deprecated 3.X.X
53+
* @description
54+
*
55+
* **Deprecated**
56+
*
57+
* Texto exibido no label para tentar novamente.
58+
*/
3859
tryAgain?: string;
3960

61+
/** Texto a ser exibido quando ocorrer erro no envio do arquivo. */
62+
errorOccurred?: string;
63+
64+
/** Texto a ser exibido quando o envio do arquivo for realizado com sucesso. */
65+
sentWithSuccess?: string;
66+
4067
}

projects/ui/src/lib/components/po-field/po-upload/po-upload-base.component.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ export const poUploadLiteralsDefault = {
2828
allowedFormats: 'Accepted file formats: {0}.',
2929
allowedFileSizeRange: 'Size limit per file: from {0} to {1}',
3030
maxFileSizeAllowed: 'Size limit per file: {0} maximum',
31-
minFileSizeAllowed: 'Size limit per file: {0} minimum'
31+
minFileSizeAllowed: 'Size limit per file: {0} minimum',
32+
errorOccurred: 'An error has occurred',
33+
sentWithSuccess: 'Sent with success'
3234
},
3335
es: <PoUploadLiterals> {
3436
selectFile: 'Seleccionar archivo',
@@ -47,7 +49,9 @@ export const poUploadLiteralsDefault = {
4749
allowedFormats: 'Formatos aceptados: {0}.',
4850
allowedFileSizeRange: 'Limite de tamaño de archivo: desde {0} hasta {1}',
4951
maxFileSizeAllowed: 'Limite de tamaño de archivo: hasta {0}',
50-
minFileSizeAllowed: 'Limite de tamaño de archivo: minimo {0}'
52+
minFileSizeAllowed: 'Limite de tamaño de archivo: minimo {0}',
53+
errorOccurred: 'Ocurrio un error',
54+
sentWithSuccess: 'Enviado con éxito'
5155
},
5256
pt: <PoUploadLiterals> {
5357
selectFile: 'Selecionar arquivo',
@@ -66,7 +70,9 @@ export const poUploadLiteralsDefault = {
6670
allowedFormats: 'Formatos adotados: {0}.',
6771
allowedFileSizeRange: 'Limite de tamanho por arquivo: de {0} até {1}',
6872
maxFileSizeAllowed: 'Limite de tamanho por arquivo: até {0}',
69-
minFileSizeAllowed: 'Limite de tamanho por arquivo: no mínimo {0}'
73+
minFileSizeAllowed: 'Limite de tamanho por arquivo: no mínimo {0}',
74+
errorOccurred: 'Ocorreu um erro',
75+
sentWithSuccess: 'Enviado com sucesso'
7076
}
7177
};
7278

projects/ui/src/lib/components/po-field/po-upload/po-upload-file.spec.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,20 @@ describe('PoUploadFile', () => {
3939
expect(poUploadFile.extension).toEqual('');
4040
});
4141

42+
describe('Methods:', () => {
43+
44+
it('getFileSize: should return the size in kbytes', () => {
45+
poUploadFile = new PoUploadFile(null);
46+
47+
let kbSize = poUploadFile['getFileSize'](3000);
48+
49+
expect(kbSize).toEqual('3 KB');
50+
51+
kbSize = poUploadFile['getFileSize'](0);
52+
53+
expect(kbSize).toEqual('0 KB');
54+
});
55+
56+
});
57+
4258
});

projects/ui/src/lib/components/po-field/po-upload/po-upload-file.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,16 @@ export class PoUploadFile {
1515
// Tamanho do arquivo em bytes;
1616
public size: number;
1717

18+
// propriedade para auxiliar a exibição do texto no componente progress
19+
displayName?: string;
20+
21+
// porcentagem utilizada para repassar ao componente progress
22+
percent?: number;
23+
1824
constructor(file: any) {
1925
if (file) {
2026
this.name = file.name;
27+
this.displayName = `${file.name} - ${this.getFileSize(file.size)}`;
2128
this.extension = this.getExtension(file.name);
2229
this.size = file.size;
2330
this.rawFile = file;
@@ -45,4 +52,16 @@ export class PoUploadFile {
4552
return s4() + s4() + '-' + s4() + '-' + s4() + '-' +
4653
s4() + '-' + s4() + s4() + s4();
4754
}
55+
56+
// Retorna o tamanho do arquivo em KBytes.
57+
private getFileSize(size: number): string {
58+
let kbSize = 0;
59+
60+
if (size) {
61+
kbSize = Math.ceil(size / 1024);
62+
}
63+
64+
return `${kbSize} KB`;
65+
}
66+
4867
}

projects/ui/src/lib/components/po-field/po-upload/po-upload.component.html

Lines changed: 12 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -40,49 +40,27 @@
4040
[p-min-file-size]="fileRestrictions?.minFileSize">
4141
</po-upload-file-restrictions>
4242

43-
<div class="po-upload-progress" *ngFor="let file of currentFiles" [id]="file.uid">
44-
<div class="po-upload-progress-status"></div>
45-
<div class="po-upload-filename-foreground">
46-
47-
<div class="po-upload-filename">
48-
<span class="po-icon {{ getPoIcon(file) }}"></span> {{ file.name }} - {{ getFileSize(file.size) }}
49-
</div>
50-
51-
<div class="po-upload-group-actions">
52-
<span
53-
*ngIf="isStatusFile('None', file) || isStatusFile('Error', file)"
54-
class="po-upload-action"
55-
(click)="removeFile(file)">
56-
{{ literals.deleteFile }}
57-
</span>
58-
59-
<span
60-
*ngIf="isStatusFile('Uploading', file)"
61-
class="po-upload-action"
62-
(click)="stopUpload(file)">
63-
{{ literals.cancel }}
64-
</span>
65-
66-
<span
67-
*ngIf="isStatusFile('Error', file)"
68-
class="po-upload-action"
69-
(click)="uploadFiles([file])">
70-
71-
{{ literals.tryAgain }}
72-
</span>
73-
</div>
74-
75-
</div>
43+
<div *ngIf="currentFiles && currentFiles.length" class="po-upload-progress-container">
44+
<po-progress
45+
*ngFor="let file of currentFiles; trackBy: trackByFn"
46+
[p-info]="infoByUploadStatus[file.status]?.text(file.percent)"
47+
[p-info-icon]="infoByUploadStatus[file.status]?.icon"
48+
[p-status]="progressStatusByFileStatus[file.status]"
49+
[p-text]="file.displayName"
50+
[p-value]="file.percent"
51+
(p-cancel)="cancel(file)"
52+
(p-retry)="uploadFiles([file])">
53+
</po-progress>
7654
</div>
7755

7856
<po-button
7957
*ngIf="displaySendButton"
58+
class="po-upload-send-button"
8059
p-type="primary"
8160
[p-disabled]="hasAnyFileUploading(currentFiles)"
8261
[p-label]="literals.startSending"
8362
(p-click)="uploadFiles(currentFiles)">
8463
</po-button>
85-
8664
</div>
8765

8866
</po-field-container>

0 commit comments

Comments
 (0)