I define a custom field on ng-admin to upload a file. I use the documentation here.
I include the repository admin-config.
Define my CustomeFileField as follows:
import Field from "./admin-config/lib/Field/Field.js";
class CustomFileField extends Field {
constructor(name) {
super(name);
this._type = 'customfile';
this._id = undefined;
this._entity_field = undefined;
this._upload_information = {};
}
uploadInformation(baseUrl) {
if(!argument.length) return this._upload_information;
if(typeof this._id === 'undefined') {
throw new Error('You must provide a valid id for the entity');
}
this._upload_information = {
'url': baseUrl + 'fr/media/upload?ref_id='+ this._id +'&ref=OpnRecipeBundle\\Entity\\Recipe',
'apifilename': 'files'
};
return this;
}
// value of the entity id
id(value) {
if(!argument.length) return this._id;
this._id = value;
return this;
}
//name of the field in the entity id
entityField(value) {
if(!argument.length) return this._entity_field;
this._entity_field = value;
return this;
}
}
export default CustomFileField;
And I defined the corresponding view accordind to the documentation.
I register both with the current:
nga.registerFieldType('customfile', require('./CustomFileField.js'));
fvp.registerFieldView('customfile', require('./CustomFileFieldView.js'));
Then I call my freshly new define type with:
nga.field('itsname','customfile');
Nevertheless I have the current error, after transpiling everything properly:
Error: [$injector:modulerr] Failed to instantiate module opnAdmin due to: this._fieldTypes[t] is not a constructor
When logging things carrefully, it seems that the field typeTypes collection has many entries, one for each type, for the native ng-admin types, it's a function, but for my new defined type ( 'customfile') it's an object, hence the call off the new operator throw an error. Any solution for that folks?