Skip to content

Commit 6538fd3

Browse files
FrancescoMolinarosteph-ieffam
authored andcommitted
Merged in task/dspace-cris-2023_02_x/DSC-1626-link-support (pull request DSpace#1619)
Task/dspace cris 2023 02 x/DSC-1626 link support Approved-by: Stefano Maffei
2 parents c550678 + 5c1cc4f commit 6538fd3

19 files changed

Lines changed: 320 additions & 9 deletions

File tree

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<div [class]="field.styleValue">
2+
<span>
3+
<a class="metadata-text" href="{{link.href}}" rel="noopener noreferrer" target="_blank">
4+
<i class="mr-2 fa-xl" [ngClass]="iconStyle"></i>
5+
{{ link.text }}
6+
</a>
7+
</span>
8+
</div>

src/app/cris-layout/cris-layout-matrix/cris-layout-box-container/boxes/metadata/rendering-types/link-authority/link-authority.component.scss

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import { Component, Inject, OnInit } from '@angular/core';
2+
3+
import { TranslateService } from '@ngx-translate/core';
4+
5+
import { FieldRenderingType, MetadataBoxFieldRendering } from '../metadata-box.decorator';
6+
import { MetadataLinkValue } from '../../../../../../models/cris-layout-metadata-link-value.model';
7+
import { RenderingTypeValueModelComponent } from '../rendering-type-value.model';
8+
import { Item } from '../../../../../../../core/shared/item.model';
9+
import { LayoutField } from '../../../../../../../core/layout/models/box.model';
10+
import { MetadataValue } from '../../../../../../../core/shared/metadata.models';
11+
12+
/**
13+
* This component renders the links metadata fields.
14+
* The metadata value is used for href and text
15+
*/
16+
@Component({
17+
// eslint-disable-next-line @angular-eslint/component-selector
18+
selector: 'span[ds-link-authority]',
19+
templateUrl: './link-authority.component.html',
20+
styleUrls: ['./link-authority.component.scss']
21+
})
22+
@MetadataBoxFieldRendering(FieldRenderingType.AUTHORITYLINK)
23+
export class LinkAuthorityComponent extends RenderingTypeValueModelComponent implements OnInit {
24+
25+
/**
26+
* The link to render
27+
*/
28+
link: MetadataLinkValue;
29+
iconStyle: string;
30+
31+
32+
constructor(
33+
@Inject('fieldProvider') public fieldProvider: LayoutField,
34+
@Inject('itemProvider') public itemProvider: Item,
35+
@Inject('metadataValueProvider') public metadataValueProvider: MetadataValue,
36+
@Inject('renderingSubTypeProvider') public renderingSubTypeProvider: string,
37+
@Inject('tabNameProvider') public tabNameProvider: string,
38+
protected translateService: TranslateService
39+
) {
40+
super(fieldProvider, itemProvider, metadataValueProvider, renderingSubTypeProvider, tabNameProvider, translateService);
41+
}
42+
43+
ngOnInit(): void {
44+
this.link = this.getLinkFromValue();
45+
this.iconStyle = this.getWebsiteIcon();
46+
}
47+
48+
/**
49+
* Get the link value to render
50+
*/
51+
getLinkFromValue(): MetadataLinkValue {
52+
return {
53+
href: this.metadataValue.authority,
54+
text: this.metadataValue.value
55+
};
56+
}
57+
58+
getWebsiteIcon(): string {
59+
const siteUrl = this.metadataValue.authority;
60+
let iconStyle = '';
61+
62+
if (siteUrl.includes('linkedin')) {
63+
iconStyle = 'fab fa-linkedin';
64+
} else if (siteUrl.includes('twitter')) {
65+
iconStyle = 'fa-brands fa-x-twitter';
66+
} else if (siteUrl.includes('instagram')) {
67+
iconStyle = 'fab fa-instagram';
68+
} else if (siteUrl.includes('facebook')) {
69+
iconStyle = 'fab fa-facebook';
70+
}
71+
return iconStyle;
72+
}
73+
}

src/app/cris-layout/cris-layout-matrix/cris-layout-box-container/boxes/metadata/rendering-types/metadata-box.decorator.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export enum FieldRenderingType {
1818
VALUEPAIR = 'VALUEPAIR',
1919
ADVANCEDATTACHMENT = 'ADVANCEDATTACHMENT',
2020
SIMPLEATTACHMENT = 'SIMPLEATTACHMENT',
21+
AUTHORITYLINK = 'AUTHORITYLINK',
2122
}
2223

2324
const fieldType = new Map();

src/app/cris-layout/cris-layout.module.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ import {
111111
} from './cris-layout-matrix/cris-layout-box-container/boxes/metadata/rendering-types/advanced-attachment/bitstream-attachment/attachment-render/attachment-rendering.module';
112112
import { FormModule } from '../shared/form/form.module';
113113
import { CrisLayoutCollectionBoxComponent } from './cris-layout-matrix/cris-layout-box-container/boxes/cris-layout-collection-box/cris-layout-collection-box.component';
114+
import {
115+
LinkAuthorityComponent
116+
} from './cris-layout-matrix/cris-layout-box-container/boxes/metadata/rendering-types/link-authority/link-authority.component';
114117

115118
const ENTRY_COMPONENTS = [
116119
// put only entry components that use custom decorator
@@ -135,7 +138,8 @@ const ENTRY_COMPONENTS = [
135138
OrcidComponent,
136139
ValuepairComponent,
137140
TagComponent,
138-
AdvancedAttachmentComponent
141+
AdvancedAttachmentComponent,
142+
LinkAuthorityComponent
139143
];
140144

141145
@NgModule({

src/app/dso-shared/dso-edit-metadata/dso-edit-metadata-form.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,10 @@ export class DsoEditMetadataValue {
7575
confirmChanges(finishEditing = false) {
7676
this.reordered = this.originalValue.place !== this.newValue.place;
7777
if (hasNoValue(this.change) || this.change === DsoEditMetadataChangeType.UPDATE) {
78-
if ((this.originalValue.value !== this.newValue.value || this.originalValue.language !== this.newValue.language)) {
78+
if ((this.originalValue.value !== this.newValue.value || this.originalValue.language !== this.newValue.language || this.originalValue.authority !== this.newValue.authority)) {
7979
this.change = DsoEditMetadataChangeType.UPDATE;
80-
} else {
81-
this.change = undefined;
80+
} else if (!hasValue(this.originalValue.authority) && hasValue(this.newValue.authority)) {
81+
this.change = DsoEditMetadataChangeType.ADD;
8282
}
8383
}
8484
if (finishEditing) {
@@ -419,10 +419,11 @@ export class DsoEditMetadataForm {
419419
if (hasValue(value.change)) {
420420
if (value.change === DsoEditMetadataChangeType.UPDATE) {
421421
// Only changes to value or language are considered "replace" operations. Changes to place are considered "move", which is processed below.
422-
if (value.originalValue.value !== value.newValue.value || value.originalValue.language !== value.newValue.language) {
422+
if (value.originalValue.value !== value.newValue.value || value.originalValue.language !== value.newValue.language || value.originalValue.authority !== value.newValue.authority) {
423423
replaceOperations.push(new MetadataPatchReplaceOperation(field, value.originalValue.place, {
424424
value: value.newValue.value,
425425
language: value.newValue.language,
426+
authority: value.newValue.authority,
426427
}));
427428
}
428429
// "replace" the security level value
@@ -431,6 +432,7 @@ export class DsoEditMetadataForm {
431432
securityLevel: value.newValue.securityLevel,
432433
value: value.newValue.value,
433434
language: value.newValue.language,
435+
authority: value.newValue.authority,
434436
}));
435437
}
436438
} else if (value.change === DsoEditMetadataChangeType.REMOVE) {
@@ -440,7 +442,8 @@ export class DsoEditMetadataForm {
440442
addOperations.push(new MetadataPatchAddOperation(field, {
441443
value: value.newValue.value,
442444
language: value.newValue.language,
443-
securityLevel: value.newValue.securityLevel
445+
securityLevel: value.newValue.securityLevel,
446+
authority: value.newValue.authority,
444447
}));
445448
} else {
446449
console.warn('Illegal metadata change state detected for', value);

src/app/dso-shared/dso-edit-metadata/dso-edit-metadata-headers/dso-edit-metadata-headers.component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<div class="d-flex flex-row">
55
<div class="flex-grow-1 ds-flex-cell ds-value-cell"><b class="dont-break-out preserve-line-breaks">{{ dsoType + '.edit.metadata.headers.value' | translate }}</b></div>
66
<div class="ds-flex-cell ds-lang-cell"><b>{{ dsoType + '.edit.metadata.headers.language' | translate }}</b></div>
7+
<div class="ds-flex-cell ds-authority-cell"><b>{{ dsoType + '.edit.metadata.headers.authority' | translate }}</b></div>
78
<div class="ds-flex-cell ds-security-cell"><b>{{'item.edit.metadata.headers.security'| translate}}</b></div>
89
<div class="text-center ds-flex-cell ds-edit-cell"><b>{{ dsoType + '.edit.metadata.headers.edit' | translate }}</b></div>
910
</div>

src/app/dso-shared/dso-edit-metadata/dso-edit-metadata-headers/dso-edit-metadata-headers.component.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ describe('DsoEditMetadataHeadersComponent', () => {
2727
});
2828

2929
it('should display three headers', () => {
30-
expect(fixture.debugElement.queryAll(By.css('.ds-flex-cell')).length).toEqual(4);
30+
expect(fixture.debugElement.queryAll(By.css('.ds-flex-cell')).length).toEqual(5);
3131
});
3232
});

src/app/dso-shared/dso-edit-metadata/dso-edit-metadata-shared/dso-edit-metadata-cells.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
max-width: var(--ds-dso-edit-lang-width);
1313
}
1414

15+
.ds-authority-cell {
16+
min-width: var(--ds-dso-edit-authority-width);
17+
max-width: var(--ds-dso-edit-authority-width);
18+
}
19+
1520
.ds-security-cell {
1621
min-width: var(--ds-dso-edit-security-width);
1722
max-width: var(--ds-dso-edit-security-width);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<div role="row" class="visually-hidden">
22
<div role="columnheader">{{ dsoType + '.edit.metadata.headers.value' | translate }}</div>
33
<div role="columnheader">{{ dsoType + '.edit.metadata.headers.language' | translate }}</div>
4+
<div role="columnheader">{{ dsoType + '.edit.metadata.headers.authority' | translate }}</div>
45
<div role="columnheader">{{ dsoType + '.edit.metadata.headers.edit' | translate }}</div>
56
</div>

0 commit comments

Comments
 (0)