-
Notifications
You must be signed in to change notification settings - Fork 536
[DSpace-CRIS] Share links via social networks #5112
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
Merged
tdonohue
merged 10 commits into
DSpace:main
from
pzlakowski:feature/cris-share-links-via-social-networks
Mar 25, 2026
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
6e9f8cf
Merge branch 'main' of dspace:pzlakowski/dspace-angular
PawelZlakowski 1aac6a2
Merge branch 'main' of dspace:pzlakowski/dspace-angular
PawelZlakowski a6f4807
feature: backport social share links from cris
PawelZlakowski 6d77523
remove ref to cris in default config
PawelZlakowski 8d564bc
remove destroyref since it is route observable
PawelZlakowski 8838185
lint ficx
PawelZlakowski c346b53
document AddToAny in config.example.yml
PawelZlakowski eda87d6
add typedocs and make feature disabled as default
PawelZlakowski 407f4b3
disable the feature & and move enable flag as the first option
PawelZlakowski da9ca9e
move enable flag in application code too
PawelZlakowski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,7 @@ | ||
| <ds-root | ||
| [shouldShowFullscreenLoader]="(isAuthBlocking$ | async) || (isThemeLoading$ | async)" | ||
| [shouldShowRouteLoader]="isRouteLoading$ | async"></ds-root> | ||
|
|
||
| @if (browserPlatform) { | ||
| <ds-social></ds-social> | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| <div id="dspace-a2a" [class.d-none]="(showOnCurrentRoute$ | async) !== true" data-a2a-scroll-show="0,60" | ||
| class="a2a_kit a2a_kit_size_32 a2a_floating_style a2a_default_style" [attr.data-a2a-title]="title" [attr.data-a2a-url]="url"> | ||
| @for (button of buttonList; track button) { | ||
| <a [class]="'a2a_button_' + button" [class.a2a_counter]="showCounters && button !== 'facebook'"></a> | ||
| } | ||
| @if (showPlusButton) { | ||
| <a class="a2a_dd" href="https://www.addtoany.com/share"></a> | ||
| } | ||
| </div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| ::ng-deep { | ||
| div#dspace-a2a { | ||
| bottom: 0; | ||
| right: 0; | ||
| z-index: 998; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| import { DOCUMENT } from '@angular/common'; | ||
| import { | ||
| ComponentFixture, | ||
| TestBed, | ||
| } from '@angular/core/testing'; | ||
| import { ActivatedRoute } from '@angular/router'; | ||
| import { StoreModule } from '@ngrx/store'; | ||
|
|
||
| import { SocialComponent } from './social.component'; | ||
| import { SocialService } from './social.service'; | ||
|
|
||
| describe('SocialComponent', () => { | ||
| let component: SocialComponent; | ||
| let fixture: ComponentFixture<SocialComponent>; | ||
| let document: Document; | ||
|
|
||
| const socialServiceStub = {}; | ||
|
|
||
| const activatedRouteStub = {} as ActivatedRoute; | ||
|
|
||
| beforeEach(async () => { | ||
| await TestBed.configureTestingModule({ | ||
| imports: [StoreModule.forRoot({}), SocialComponent], | ||
| providers: [ | ||
| { provide: ActivatedRoute, useValue: activatedRouteStub }, | ||
| { provide: SocialService, useValue: socialServiceStub }, | ||
| ], | ||
| }).compileComponents(); | ||
| fixture = TestBed.createComponent(SocialComponent); | ||
| component = fixture.componentInstance; | ||
| document = TestBed.inject(DOCUMENT) as any; | ||
| fixture.detectChanges(); | ||
| }); | ||
|
|
||
| it('should create socialComponent', () => { | ||
| expect(component).toBeTruthy(); | ||
| }); | ||
|
|
||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| import { AsyncPipe } from '@angular/common'; | ||
| import { | ||
| ChangeDetectionStrategy, | ||
| Component, | ||
| OnInit, | ||
| } from '@angular/core'; | ||
| import { Observable } from 'rxjs'; | ||
|
|
||
| import { SocialService } from './social.service'; | ||
|
|
||
| @Component({ | ||
| selector: 'ds-social', | ||
| templateUrl: './social.component.html', | ||
| styleUrls: ['./social.component.scss'], | ||
| changeDetection: ChangeDetectionStrategy.OnPush, | ||
| imports: [ | ||
| AsyncPipe, | ||
| ], | ||
| }) | ||
| /** | ||
| * Component to render dynamically the social2 buttons using addToAny plugin | ||
| */ | ||
| export class SocialComponent implements OnInit { | ||
|
|
||
| /** | ||
| * The script containing the profile ID | ||
| */ | ||
| script: HTMLScriptElement; | ||
|
|
||
| showOnCurrentRoute$: Observable<boolean>; | ||
|
|
||
| buttonList: string[]; | ||
| showPlusButton: boolean; | ||
| title: string; | ||
| url: string; | ||
| showCounters: boolean; | ||
|
|
||
| constructor( | ||
| private socialService: SocialService, | ||
| ) {} | ||
|
|
||
| ngOnInit() { | ||
| if (this.socialService.enabled) { | ||
| this.buttonList = this.socialService.configuration.buttons; | ||
| this.showPlusButton = this.socialService.configuration.showPlusButton; | ||
| this.showCounters = this.socialService.configuration.showCounters; | ||
| this.title = this.socialService.configuration.title; | ||
| this.socialService.initializeAddToAnyScript(); | ||
| this.showOnCurrentRoute$ = this.socialService.showOnCurrentRoute$; | ||
| } | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| import { | ||
| DOCUMENT, | ||
| isPlatformBrowser, | ||
| } from '@angular/common'; | ||
| import { | ||
| Inject, | ||
| Injectable, | ||
| PLATFORM_ID, | ||
| } from '@angular/core'; | ||
| import { | ||
| ChildActivationEnd, | ||
| Router, | ||
| } from '@angular/router'; | ||
| import { BehaviorSubject } from 'rxjs'; | ||
| import { | ||
| distinctUntilChanged, | ||
| filter, | ||
| map, | ||
| } from 'rxjs/operators'; | ||
|
|
||
| import { environment } from '../../environments/environment'; | ||
|
|
||
| /** | ||
| * Singleton service responsible for integration with AddToAny plugin to initialize 3rd party script and hold state | ||
| * Bootstrap with Angular start in {@link AppComponent} which initializess route subscription | ||
| * Bootstrap of integration starts at clientside with {@link SocialComponent} which loads 3rd party script | ||
| */ | ||
| @Injectable( { providedIn: 'root' } ) | ||
| export class SocialService { | ||
| private showOnCurrentRouteSubject = new BehaviorSubject(false); | ||
|
|
||
| /** | ||
| * Show/hide the social buttons according to the activated route | ||
| */ | ||
| showOnCurrentRoute$ = this.showOnCurrentRouteSubject.asObservable(); | ||
|
|
||
| private readonly isSocialEnabled: boolean; | ||
|
|
||
| constructor( | ||
| @Inject(PLATFORM_ID) protected platformId: any, | ||
| @Inject(DOCUMENT) private _document: Document, | ||
| private router: Router, | ||
| ) { | ||
| this.isSocialEnabled = isPlatformBrowser(this.platformId) && environment.addToAnyPlugin.socialNetworksEnabled; | ||
| } | ||
|
|
||
| /** | ||
| * Traverse tree from bottom to parent in route definition to get whenever feature is enabled via *showSocialButtons* | ||
| */ | ||
| private activatedRouteDataChanges$ = this.router.events.pipe( | ||
| filter(events => events instanceof ChildActivationEnd), | ||
| map((event: ChildActivationEnd) => event.snapshot), | ||
| map(route => { | ||
| while (route.firstChild) { | ||
| route = route.firstChild; | ||
| } | ||
| return route; | ||
| }), | ||
| filter(route => route.outlet === 'primary'), | ||
| map(route => route.data), | ||
| ); | ||
|
|
||
| /** | ||
| * Returns whether the social network buttons are enabled | ||
| */ | ||
| get enabled() { | ||
| return this.isSocialEnabled; | ||
| } | ||
|
|
||
| /** | ||
| * Returns the list of available buttons | ||
| */ | ||
| get configuration() { | ||
| return environment.addToAnyPlugin; | ||
| } | ||
|
|
||
| /** | ||
| * Import the AddToAny JavaScript | ||
| */ | ||
| initializeAddToAnyScript(): any { | ||
| // Initializing the addToAny script | ||
| const script = this._document.createElement('script'); | ||
| script.type = 'text/javascript'; | ||
| script.src = environment.addToAnyPlugin.scriptUrl; | ||
| script.async = true; | ||
|
|
||
| // Wait for document to finish grow vertically so that script listener handles properly body height changes | ||
| let lastBodyHeight = 0; | ||
| const documentBody = this._document.body; | ||
|
|
||
| const bodyHeightInterval = setInterval(() => { | ||
| const currentBodyHeight = documentBody.getBoundingClientRect().height; | ||
|
|
||
| if (currentBodyHeight > lastBodyHeight) { | ||
| lastBodyHeight = currentBodyHeight; | ||
| } else { | ||
| this._document.head.appendChild(script); | ||
| clearInterval(bodyHeightInterval); | ||
| } | ||
| }, 200); | ||
| } | ||
|
|
||
| /** | ||
| * Initialize the Social service. This method must be called only inside app component. | ||
| */ | ||
| initialize() { | ||
| if (!this.enabled) { | ||
| return; | ||
| } | ||
|
|
||
| const showSocialButtons = this.activatedRouteDataChanges$.pipe( | ||
| map(data => data?.showSocialButtons === true), | ||
| distinctUntilChanged(), | ||
| ); | ||
|
|
||
| showSocialButtons.subscribe(this.showOnCurrentRouteSubject); | ||
| } | ||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import { Config } from './config.interface'; | ||
|
|
||
| /** | ||
| * Configuration interface for AddToAny plugin to display social links | ||
| */ | ||
| export interface AddToAnyPluginConfig extends Config { | ||
|
pzlakowski marked this conversation as resolved.
|
||
| /** | ||
| * Script URL to AddToAny plugin, defaults to AddToAny CDN | ||
| */ | ||
| scriptUrl: string; | ||
| /** | ||
| * Enable feature flag | ||
| */ | ||
| socialNetworksEnabled: boolean; | ||
| /** | ||
| * Mandatory parameter for AddToAny(data-a2a-title). It will be included as part of social link share | ||
| */ | ||
| title: string; | ||
| /** | ||
| * Listed elements will be rendered with their respective icon | ||
| * List of the integrations, you can check these at https://www.addtoany.com/buttons/for/website | ||
| */ | ||
| buttons: string[]; | ||
| /** | ||
| * Shows plus button which allows to share with different integrations which were not listed in buttons | ||
| */ | ||
| showPlusButton: boolean; | ||
| /** | ||
| * Shows counter for the integration https://www.addtoany.com/buttons/customize/share_counters where it is allowed | ||
| */ | ||
| showCounters: boolean; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.