Adds file field

This commit is contained in:
Aaron Louie 2020-03-24 14:33:45 -04:00
parent 19931973f0
commit 4deb25eef7
4 changed files with 36 additions and 15 deletions

6
package-lock.json generated
View File

@ -12171,9 +12171,9 @@
"integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg=="
},
"sartography-workflow-lib": {
"version": "0.0.72",
"resolved": "https://registry.npmjs.org/sartography-workflow-lib/-/sartography-workflow-lib-0.0.72.tgz",
"integrity": "sha512-l6153jMOkKPgi2dOODOdTSHdPyyZpYjuylkPt38ct4XYaaF+kiT3GadhZli3sxg8KRkYfiaJ5krZRgl3adNu7A=="
"version": "0.0.73",
"resolved": "https://registry.npmjs.org/sartography-workflow-lib/-/sartography-workflow-lib-0.0.73.tgz",
"integrity": "sha512-GE+kB9018IWgUIBGv/5E4eoybnTmm8fz4kbES42LT6buAqNMtnvzVEt/XZKGAt78sM78Jc/CugrQFFxVFW/xxg=="
},
"sass": {
"version": "1.23.3",

View File

@ -49,7 +49,7 @@
"ngx-file-drop": "^8.0.8",
"ngx-markdown": "^9.0.0",
"rxjs": "~6.5.4",
"sartography-workflow-lib": "^0.0.72",
"sartography-workflow-lib": "^0.0.73",
"tslib": "^1.11.1",
"uuid": "^7.0.2",
"zone.js": "^0.10.3"

View File

@ -1,6 +1,12 @@
<div mat-dialog-content>
<form [formGroup]="form">
<formly-form [model]="model" [fields]="fields" [options]="options" [form]="form"></formly-form>
<formly-form
[model]="model"
[fields]="fields"
[options]="options"
[form]="form"
(modelChange)="onModelChange($event)"
></formly-form>
</form>
</div>

View File

@ -1,5 +1,5 @@
import {Component, Inject} from '@angular/core';
import {FormGroup} from '@angular/forms';
import {FormControl, FormGroup} from '@angular/forms';
import {MAT_DIALOG_DATA, MatDialogRef} from '@angular/material/dialog';
import {FormlyFieldConfig, FormlyFormOptions} from '@ngx-formly/core';
import {cleanUpFilename, FileType} from 'sartography-workflow-lib';
@ -51,15 +51,18 @@ export class FileMetaDialogComponent {
options: fileTypeOptions,
},
},
// {
// key: 'file',
// type: 'file',
// defaultValue: this.data.file,
// templateOptions: {
// label: 'File',
// required: true,
// },
// }
{
key: 'file',
type: 'file',
defaultValue: this.data.file,
templateOptions: {
label: 'File',
required: true,
},
modelOptions: {
updateOn: 'change'
},
}
];
}
@ -72,4 +75,16 @@ export class FileMetaDialogComponent {
this.dialogRef.close(this.model);
}
onModelChange(model: any) {
console.log('model', model);
if (model.file && typeof model.file === 'object' && model.file instanceof Blob) {
// Upload file
const fileReader = new (window as any).FileReader();
fileReader.onload = (event: ProgressEvent) => {
const stringContent = (event.target as FileReader).result.toString();
console.log(stringContent);
};
fileReader.readAsText(model.file);
}
}
}