Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,10 @@ describe('ClarinLicenseTableComponent', () => {
expect((component as ClarinLicenseTableComponent).licensesRD$).not.toBeNull();
});

it('should not create new clarin license label when icon image is null', () => {
it('should create new clarin license label when icon image is null', () => {
// non extended ll has no icon
(component as ClarinLicenseTableComponent).defineLicenseLabel(mockNonExtendedLicenseLabel);
expect((component as any).notificationService.error).toHaveBeenCalled();
expect((component as any).notificationService.success).toHaveBeenCalled();
});

it('should create new clarin license label and load table data', fakeAsync(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,13 @@ export class ClarinLicenseTableComponent implements OnInit {
try {
reader.readAsArrayBuffer(clarinLicenseLabel.icon?.[0]);
} catch (error) {
this.notifyOperationStatus(null, successfulMessageContentDef, errorMessageContentDef);
// Cannot read any icon that means there is no icon
// Create license label without icon
this.createClarinLicenseLabel(clarinLicenseLabel, [], successfulMessageContentDef, errorMessageContentDef);
return;
}

// Create license label with icon
reader.onerror = (evt) => {
this.notifyOperationStatus(null, successfulMessageContentDef, errorMessageContentDef);
};
Expand All @@ -240,22 +244,31 @@ export class ClarinLicenseTableComponent implements OnInit {
fileByteArray.push(item);
}
}
clarinLicenseLabel.icon = fileByteArray;
// convert string value from the form to the boolean
clarinLicenseLabel.extended = ClarinLicenseLabelExtendedSerializer.Serialize(clarinLicenseLabel.extended);

// create
this.clarinLicenseLabelService.create(clarinLicenseLabel)
.pipe(getFirstCompletedRemoteData())
.subscribe((defineLicenseLabelResponse: RemoteData<ClarinLicenseLabel>) => {
// check payload and show error or successful
this.notifyOperationStatus(defineLicenseLabelResponse, successfulMessageContentDef, errorMessageContentDef);
this.loadAllLicenses();
});
this.createClarinLicenseLabel(clarinLicenseLabel, fileByteArray, successfulMessageContentDef, errorMessageContentDef);
}
};
}

/**
* Call BE request to create a clarin license label with or without icon.
* Show response in the notification popup.
*/
createClarinLicenseLabel(clarinLicenseLabel: ClarinLicenseLabel, fileByteArray: any[] = [],
successfulMessageContentDef: any, errorMessageContentDef: any) {
clarinLicenseLabel.icon = fileByteArray;
// convert string value from the form to the boolean
clarinLicenseLabel.extended = ClarinLicenseLabelExtendedSerializer.Serialize(clarinLicenseLabel.extended);

// create
this.clarinLicenseLabelService.create(clarinLicenseLabel)
.pipe(getFirstCompletedRemoteData())
.subscribe((defineLicenseLabelResponse: RemoteData<ClarinLicenseLabel>) => {
// check payload and show error or successful
this.notifyOperationStatus(defineLicenseLabelResponse, successfulMessageContentDef, errorMessageContentDef);
this.loadAllLicenses();
});
}

// delete license
/**
* Delete selected license. If none license is selected do nothing.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ export class DefineLicenseFormComponent implements OnInit {
* @private
*/
private loadAndAssignClarinLicenseLabels() {
this.clarinLicenseLabelService.findAll({}, false)
this.clarinLicenseLabelService.findAll({ elementsPerPage: 100 }, false)
.pipe(getFirstSucceededRemoteListPayload())
.subscribe(res => {
res.forEach(clarinLicenseLabel => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ <h4 class="modal-title">{{'clarin-license.define-license-form.form-name' | trans
</select>
</div>
<div class="form-group mt-4">
<label id="icon" for="icon">{{'clarin-license-label.define-license-label.input-icon' | translate | dsAddChar: '*'}}</label>
<label id="icon" for="icon">{{'clarin-license-label.define-license-label.input-icon' | translate}}</label>
<input type="file" class="form-control" formControlName="icon"/>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Component, Input, OnInit } from '@angular/core';
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { validateLicenseLabel } from '../define-license-form/define-license-form-validator';
import { isNotEmpty } from '../../../../shared/empty.util';

/**
Expand Down Expand Up @@ -64,7 +63,7 @@ export class DefineLicenseLabelFormComponent implements OnInit {
label: [this.label, [Validators.required, Validators.maxLength(5)]],
title: [this.title, Validators.required],
extended: isNotEmpty(this.extended) ? this.extended : this.extendedOptions[0],
icon: [this.icon, validateLicenseLabel()],
icon: [this.icon],
});
}

Expand Down
5 changes: 2 additions & 3 deletions src/app/shared/utils/clarin-license-checked.pipe.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Pipe, PipeTransform } from '@angular/core';
import { ClarinLicenseLabel } from '../../core/shared/clarin/clarin-license-label.model';
import { isEmpty } from '../empty.util';
import { ClarinLicenseRequiredInfo } from '../../core/shared/clarin/clarin-license.resource-type';

Expand All @@ -18,13 +17,13 @@ export class ClarinLicenseCheckedPipe implements PipeTransform {
* @param clarinLicenseProp to compare
* @param clarinLicenseProps all extended clarin license labels or non extended clarin license label in array
*/
transform(clarinLicenseProp: ClarinLicenseLabel | ClarinLicenseRequiredInfo, clarinLicenseProps: any[]): boolean {
transform(clarinLicenseProp: any | ClarinLicenseRequiredInfo, clarinLicenseProps: any[]): boolean {
let contains = false;
if (isEmpty(clarinLicenseProp) || isEmpty(clarinLicenseProps)) {
return contains;
}
clarinLicenseProps.forEach(cll => {
if (cll.id === clarinLicenseProp.id) {
if (cll.name === clarinLicenseProp.name) {
contains = true;
}
});
Expand Down