Skip to content

Commit c020f2c

Browse files
authored
Schema type: File (#5095)
1 parent 11ec232 commit c020f2c

File tree

5 files changed

+25
-11
lines changed

5 files changed

+25
-11
lines changed

frontend/src/app/modules/schema-engine/schema-form-view/schema-form-view.component.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@
3838
class="guardian-button guardian-button-secondary">Copy CID</button>
3939
</div>
4040
</div>
41-
<div class="form-field-img">
41+
42+
<div *ngIf="item?.customType !== 'file'" class="form-field-img">
4243
<img *ngIf="!item.loading; else loading" class="ipfs-image" [src]="item.imgSrc" [alt]="item.value">
4344
<ng-template #loading>
4445
<div class="guardian-loading">
@@ -69,8 +70,8 @@
6970
<div
7071
*ngIf="isFormulas(item) as formulas"
7172
class="form-field-formula">
72-
<button
73-
class="guardian-icon-button guardian-icon-button-secondary"
73+
<button
74+
class="guardian-icon-button guardian-icon-button-secondary"
7475
(click)="showFormulas(formulas)">
7576
<svg-icon
7677
src="/assets/images/icons/function.svg"

frontend/src/app/modules/schema-engine/schema-form-view/schema-form-view.component.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ export class SchemaFormViewComponent implements OnInit {
156156
|| this.values[item.name] === undefined
157157
? ""
158158
: this.values[item.name];
159-
if (this.isIPFS(field)) {
159+
if (this.isIPFS(field) && field.customType !== 'file') {
160160
this.loadImg(item)
161161
}
162162
}
@@ -188,7 +188,7 @@ export class SchemaFormViewComponent implements OnInit {
188188
}]
189189
item.isInvalidType = true;
190190
}
191-
if (this.isIPFS(field)) {
191+
if (this.isIPFS(field) && field.customType !== 'file') {
192192
this.loadImgs(value);
193193
}
194194
}
@@ -361,4 +361,4 @@ export class SchemaFormViewComponent implements OnInit {
361361
});
362362
dialogRef.onClose.subscribe((result: any) => { });
363363
}
364-
}
364+
}

frontend/src/app/modules/schema-engine/schema-form/schema-form.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
</p-progressSpinner>
6161

6262
<button mat-icon-button *ngSwitchCase="false" class="upload-btn"
63-
(click)="uploadFile(item)">
63+
(click)="uploadFile(item, isFile(item))">
6464
<i class="pi pi-paperclip"></i>
6565
</button>
6666
</ng-container>
@@ -204,7 +204,7 @@
204204
[style]="{ width: '38px', height: '38px' }">
205205
</p-progressSpinner>
206206
<button *ngSwitchCase="false" class="upload-btn"
207-
(click)="uploadFile(listItem)">
207+
(click)="uploadFile(listItem, isFile(item))">
208208
<i class="pi pi-paperclip"></i>
209209
</button>
210210
</ng-container>

frontend/src/app/modules/schema-engine/schema-form/schema-form.component.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ interface IFieldIndexControl<T extends UntypedFormControl | UntypedFormGroup> {
8484
open: boolean
8585
}
8686

87+
const FILE_EXTENSIONS = '.txt, .pdf, .doc, .docx, .xls, .csv, .kml, .geoJSON';
8788
/**
8889
* Form built by schema
8990
*/
@@ -387,13 +388,13 @@ export class SchemaFormComponent implements OnInit {
387388
);
388389
}
389390

390-
uploadFile(item: any): void {
391+
uploadFile(item: any, isFile: boolean): void {
391392
const input = document.createElement('input');
392393

393394
const control = item.control;
394395

395396
input.type = 'file';
396-
input.accept = 'image/*';
397+
input.accept = isFile ? FILE_EXTENSIONS : 'image/*' ;
397398
input.onchange = (event) => {
398399
const file = input.files ? input.files[0] : undefined;
399400
if (!file) {
@@ -713,6 +714,10 @@ export class SchemaFormComponent implements OnInit {
713714
|| item.pattern === '^ipfs:\/\/.+';
714715
}
715716

717+
public isFile(item: SchemaField): boolean {
718+
return item.customType === 'file';
719+
}
720+
716721
private postFormat(item: any, control: UntypedFormControl): any {
717722
const format = item.format;
718723
const type = item.type;

interfaces/src/helpers/field-types-dictionary.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,14 @@ export class FieldTypesDictionary {
9595
pattern: '^ipfs:\/\/.+',
9696
isRef: false
9797
},
98+
{
99+
name: 'File',
100+
type: 'string',
101+
format: undefined,
102+
pattern: '^ipfs:\/\/.+',
103+
isRef: false,
104+
customType: 'file'
105+
},
98106
{
99107
name: 'Enum',
100108
type: 'string',
@@ -236,4 +244,4 @@ export class DefaultFieldDictionary {
236244
}
237245
return [];
238246
}
239-
}
247+
}

0 commit comments

Comments
 (0)