Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(file value uploads): use upload from for file value types #361

Closed
wants to merge 10 commits into from
Expand Up @@ -66,6 +66,10 @@
<!-- Step2: create property values and submit data -->
<form *ngIf="propertiesParentForm && !showNextStepForm" [formGroup]="propertiesParentForm" class="resource-instance-form stepTwo form-content" (ngSubmit)="submitData()" appInvalidControlScroll>

<div *ngIf="hasFileValue?.length > 0">
<dsp-upload-file #upload [representation]="hasFileValue[0]"></dsp-upload-file>
</div>

<!-- create property values -->
<app-select-properties
#selectProps
Expand Down
Expand Up @@ -13,15 +13,15 @@ import {
ReadOntology,
ReadResource,
ResourceClassAndPropertyDefinitions,
ResourceClassDefinition,
ResourceClassDefinition, ResourceClassDefinitionWithPropertyDefinition,
ResourcePropertyDefinition,
StoredProject,
UserResponse
} from '@dasch-swiss/dsp-js';
import {
DspApiConnectionToken,
Session,
SessionService
SessionService, UploadFileComponent
} from '@dasch-swiss/dsp-ui';
import { Subscription } from 'rxjs';
import { CacheService } from 'src/app/main/cache/cache.service';
Expand All @@ -48,6 +48,7 @@ export class ResourceInstanceFormComponent implements OnInit, OnDestroy {
@ViewChild('selectProps') selectPropertiesComponent: SelectPropertiesComponent;
@ViewChild('selectResourceClass') selectResourceClassComponent: SelectResourceClassComponent;
@ViewChild('selectOntology') selectOntologyComponent: SelectOntologyComponent;
@ViewChild('upload') uploadFileComponent?: UploadFileComponent;

// forms
selectResourceForm: FormGroup;
Expand All @@ -71,6 +72,7 @@ export class ResourceInstanceFormComponent implements OnInit, OnDestroy {
resourceLabel: string;
properties: ResourcePropertyDefinition[];
ontologyInfo: ResourceClassAndPropertyDefinitions;
hasFileValue: string[] = [];

valueOperationEventSubscription: Subscription;

Expand Down Expand Up @@ -357,6 +359,10 @@ export class ResourceInstanceFormComponent implements OnInit, OnDestroy {
// filter out all props that cannot be edited or are link props
this.properties = onto.getPropertyDefinitionsByType(ResourcePropertyDefinition).filter(prop => prop.isEditable && !prop.isLinkProperty);

this.hasFileValue = this._hasBinaryRepresentation(this.properties);

console.log(this);

// notifies the user that the selected resource does not have any properties defined yet.
if (!this.selectPropertiesComponent && this.properties.length === 0) {
this.errorMessage = 'No properties defined for the selected resource.';
Expand All @@ -372,4 +378,34 @@ export class ResourceInstanceFormComponent implements OnInit, OnDestroy {

}

/**
*
* Determines whether the selected resource class has a binary Representation (image etc.).
*
* Returns the file value type or an empty array.
*
* @param properties the properties to check for binary file value types.
*/
private _hasBinaryRepresentation(properties: ResourcePropertyDefinition[]): string[] {

const binaryTypes = [Constants.StillImageFileValue, Constants.AudioFileValue, Constants.DocumentFileValue, Constants.MovingImageFileValue];

// remove file value properties from property list
this.properties = properties.filter(
prop => !binaryTypes.includes(prop.objectType)
);

// TODO: add a FormControl representing the file value to propertiesParentForm
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@flavens @mpro7 I added Outputs to the upload file component.

My idea is that on a successful file upload, a CreateStillImageFileValue can be created. However, I am not sure where this should happen. Would SelectPropertiesComponent be the right place to handle this?

I have added some logic for the upload to ResourceInstanceFormComponent, but maybe this should be moved to SelectPropertiesComponent.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or maybe instead of the Outputs, UploadFileComponent's form could be used: as long as there is no successful upload to Sipi, the form is invalid. UploadFileComponent would have to be added to propertiesParentForm then.

But then instead of the binary file (File), the UploadedFileResponse obtained from Sipi should be stored in the FormControl.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tobiasschweizer IMO FormControl has to be used anyway, so second options sounds good for me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I'll try that approach next week.

// TODO: react to UploadFileComponent's Outputs: fileUpload and cancelUpload (see https://github.com/dasch-swiss/dsp-ui-lib/pull/264)
// TODO: add a CreateStillImageFileValue on fileUpload and remove it on cancelUpload

// return the file value property, if any
return properties.filter(
prop => binaryTypes.includes(prop.objectType)
).map(
prop => prop.objectType
);

}

}
3 changes: 2 additions & 1 deletion src/config/config.dev.json
Expand Up @@ -4,5 +4,6 @@
"apiPort": 3333,
"apiPath": "",
"jsonWebToken": "",
"logErrors": true
"logErrors": true,
"sipiUrl": "http://localhost:1024/"
}
3 changes: 2 additions & 1 deletion src/config/config.prod.json
Expand Up @@ -4,5 +4,6 @@
"apiPort": 443,
"apiPath": "",
"jsonWebToken": "",
"logErrors": false
"logErrors": false,
"sipiUrl": "http://localhost:1024/"
}