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
43 changes: 6 additions & 37 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -31,7 +31,7 @@
"@angular/platform-browser-dynamic": "~9.1.12",
"@angular/router": "~9.1.12",
"@ckeditor/ckeditor5-angular": "^1.2.3",
"@dasch-swiss/dsp-js": "^1.1.0",
"@dasch-swiss/dsp-js": "^1.2.0",
"@dasch-swiss/dsp-ui": "^1.1.1",
"@ngx-translate/core": "^13.0.0",
"@ngx-translate/http-loader": "^6.0.0",
Expand Down
Expand Up @@ -18,11 +18,7 @@ import {
StoredProject,
UserResponse
} from '@dasch-swiss/dsp-js';
import {
DspApiConnectionToken,
Session,
SessionService
} from '@dasch-swiss/dsp-ui';
import { DspApiConnectionToken, Session, SessionService } from '@dasch-swiss/dsp-ui';
import { Subscription } from 'rxjs';
import { CacheService } from 'src/app/main/cache/cache.service';
import { ErrorHandlerService } from 'src/app/main/error/error-handler.service';
Expand Down Expand Up @@ -160,6 +156,17 @@ export class ResourceInstanceFormComponent implements OnInit, OnDestroy {

createResource.properties = this.propertiesObj;

// check for file values
if (this.selectPropertiesComponent.hasFileValue.length === 1) {

const fileValue = this.selectPropertiesComponent.uploadFileComponent.getNewValue();

if (fileValue instanceof CreateValue) {
createResource.properties[this.selectPropertiesComponent.hasFileValue[0].id] = [fileValue];
}

}

this._dspApiConnection.v2.res.createResource(createResource).subscribe(
(res: ReadResource) => {
this.resource = res;
Expand Down
@@ -1,5 +1,10 @@
<div class="properties-container">
<div class="properties">

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

<div *ngFor="let prop of properties; let last = last;" [class.border-bottom]="!last">
<div class="property" *ngIf="!prop.isLinkProperty || prop">
<div class="property-label">
Expand Down
@@ -1,7 +1,7 @@
import { AfterViewInit, Component, Input, OnInit, QueryList, ViewChildren } from '@angular/core';
import { AfterViewInit, Component, Input, OnInit, QueryList, ViewChild, ViewChildren } from '@angular/core';
import { FormGroup } from '@angular/forms';
import { Cardinality, CardinalityUtil, IHasProperty, ReadResource, ResourceClassAndPropertyDefinitions, ResourceClassDefinition, ResourcePropertyDefinition } from '@dasch-swiss/dsp-js';
import { ValueService } from '@dasch-swiss/dsp-ui';
import { Cardinality, CardinalityUtil, Constants, IHasProperty, ReadResource, ResourceClassAndPropertyDefinitions, ResourceClassDefinition, ResourcePropertyDefinition } from '@dasch-swiss/dsp-js';
import { UploadFileComponent, ValueService } from '@dasch-swiss/dsp-ui';
import { SwitchPropertiesComponent } from './switch-properties/switch-properties.component';

@Component({
Expand All @@ -11,6 +11,8 @@ import { SwitchPropertiesComponent } from './switch-properties/switch-properties
})
export class SelectPropertiesComponent implements OnInit {

@ViewChild('upload') uploadFileComponent?: UploadFileComponent;

@ViewChildren('switchProp') switchPropertiesComponent: QueryList<SwitchPropertiesComponent>;

@Input() properties: ResourcePropertyDefinition[];
Expand All @@ -31,9 +33,14 @@ export class SelectPropertiesComponent implements OnInit {

isRequiredProp: boolean;

hasFileValue: ResourcePropertyDefinition[] = [];

constructor(private _valueService: ValueService) { }

ngOnInit() {

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

if (this.properties) {
for (const prop of this.properties) {
if (prop) {
Expand Down Expand Up @@ -139,4 +146,28 @@ export class SelectPropertiesComponent implements OnInit {
return arrayToFilter;

}

/**
*
* 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[]): ResourcePropertyDefinition[] {

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)
);

// return the file value property, if any
return properties.filter(
prop => binaryTypes.includes(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/"
}