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

make stats subscription with checkbox #18

Merged
merged 1 commit into from
Dec 12, 2024
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
29 changes: 12 additions & 17 deletions src/app/my-dspace-page/my-dspace-page.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,19 @@
<ds-my-dspace-new-submission *dsShowOnlyForRole="[roleTypeEnum.Submitter]"></ds-my-dspace-new-submission>
</div>

<div *ngIf="!subscribeStats">
<div id="aspect_submission_Submissions_div_subscribe-to-stats" class="container ng-tns-c141-24">
<p class="ds-paragraph">
<button (click)="subscribeToDepositStats()" style="background-color: #1d7491;" id="aspect_submission_Submissions_field_submit_stats_on" class="ds-button-field btn btn-default" name="submit_stats_on" type="submit">
<div style="color: white">Send Monthly Statistics On My Deposits</div>
</button>
</p>
</div>
</div>

<div *ngIf="subscribeStats">
<div id="aspect_submission_Submissions_div_subscribe-to-stats" class="container ng-tns-c141-24">
<p class="ds-paragraph">
<button (click)="unsubscribeToDepositStats()" style="background-color: #1d7491;" id="aspect_submission_Submissions_field_submit_stats_on" class="ds-button-field btn btn-default" name="submit_stats_on" type="submit">
<div style="color: white">Don't Send Monthly Statistics On My Deposits</div>
</button>
</p>
</div>
<p class="ds-paragraph">
<label for="subscribeCheckbox" style="color: white; white: flex; align-items: center;">
<input
type="checkbox"
id="subscribeCheckbox"
(change)="toggleSubscription()"
[checked]="subscribeStats"
style="margin-right: 10px;"
/>
<span style="color: black;">Send Monthly Statistics On My Deposits</span>
</label>
</p>
</div>

<ds-themed-search *ngIf="configuration && context"
Expand Down
36 changes: 18 additions & 18 deletions src/app/my-dspace-page/my-dspace-page.component.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { ChangeDetectionStrategy, Component, Inject, InjectionToken, OnInit } from '@angular/core';

import { HttpClient} from '@angular/common/http';

import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
import { take } from 'rxjs/operators';
import { SearchService } from '../core/shared/search/search.service';
Expand Down Expand Up @@ -37,7 +35,7 @@ export const SEARCH_CONFIG_SERVICE: InjectionToken<SearchConfigurationService> =
})
export class MyDSpacePageComponent implements OnInit {

subscribeStats: Boolean;
subscribeStats: boolean = false;

/**
* The list of available configuration options
Expand Down Expand Up @@ -67,8 +65,8 @@ export class MyDSpacePageComponent implements OnInit {
private serverLocation = environment.serverLocation;

constructor(private service: SearchService,
private http: HttpClient,
@Inject(SEARCH_CONFIG_SERVICE) public searchConfigService: MyDSpaceConfigurationService) {
private http: HttpClient,
@Inject(SEARCH_CONFIG_SERVICE) public searchConfigService: MyDSpaceConfigurationService) {
this.service.setServiceOptions(MyDSpaceResponseParsingService, MyDSpaceRequest);
}

Expand All @@ -93,25 +91,27 @@ export class MyDSpacePageComponent implements OnInit {
});

this.http.get(this.serverLocation + '/api/eperson/groups/issubscribed', {responseType: 'text'}).subscribe((data: any) => {
this.subscribeStats = false;
if ( data === "true")
{
this.subscribeStats = true;
}
this.subscribeStats = data === "true";
});
}

public toggleSubscription() {
if (this.subscribeStats) {
this.unsubscribeToDepositStats();
} else {
this.subscribeToDepositStats();
}
}

public subscribeToDepositStats() {
this.http.get(this.serverLocation + '/api/eperson/groups/subscribe', {responseType: 'text'}).subscribe((data: any) => {
});
this.subscribeStats = true;
this.http.get(this.serverLocation + '/api/eperson/groups/subscribe', {responseType: 'text'}).subscribe(() => {
this.subscribeStats = true;
});
}

public unsubscribeToDepositStats() {
this.http.get(this.serverLocation + '/api/eperson/groups/unsubscribe', {responseType: 'text'}).subscribe((data: any) => {
this.http.get(this.serverLocation + '/api/eperson/groups/unsubscribe', {responseType: 'text'}).subscribe(() => {
this.subscribeStats = false;
});
this.subscribeStats = false;
}

}
}
Original file line number Diff line number Diff line change
@@ -1,61 +1,38 @@
<div class="container">
<div class="row">
<div class="col-12">
<div class="d-flex justify-content-between border-bottom pb-3">
<h2>{{ type + '.edit.head' | translate }}</h2>


<!-- UM Change to get coll stats and to subscribe to collection stats -->

<!--
<span *ngVar="(dsoRD$ | async)?.payload.uuid as coll_uuid">
<div class="ds-form-item row">
<div class="control-group col-sm-12">
<button style="background-color: #1d7491;" (click)="goToCollectionAdminStats(coll_uuid)" id="aspect_administrative_collection_EditCollectionMetadataForm_field_submit_collection_stats" class="ds-button-field btn btn-default" name="submit_collection_stats" >
<div style="color: white">Get Collection Stats</div>
</button>
</div>
</div>
</span>
-->

<div>
<span *ngVar="(dsoRD$ | async)?.payload.uuid as coll_uuid">
<div *ngIf="!this.subscribeStats && this.type === 'collection'">
<div class="ds-form-item row">
<div class="control-group col-sm-12">

<button style="background-color: #1d7491;" (click)="subscribeToAdminStats(coll_uuid)" id="aspect_administrative_collection_EditCollectionMetadataForm_field_submit_collection_stats" class="ds-button-field btn btn-default" name="submit_collection_stats" >
<div style="color: white">Subscribe to Collection Statistics</div>
</button>
</div>
</div>
</div>
</span>

<span *ngVar="(dsoRD$ | async)?.payload.uuid as coll_uuid">

<div *ngIf="this.subscribeStats && this.type === 'collection'">
<div class="ds-form-item row">
<div class="control-group col-sm-12">

<button style="background-color: #1d7491;" (click)="unsubscribeToAdminStats(coll_uuid)"id="aspect_administrative_collection_EditCollectionMetadataForm_field_submit_collection_stats" class="ds-button-field btn btn-default" name="submit_collection_stats" >
<div style="color: white">Unsubscribe to Collection Stats</div>
</button>
</div>
</div>
</div>
</span>
</div>

<!-- END UM Change to get coll stats and to subscribe to collection stats -->
<h2>{{ type + '.edit.head' | translate }}</h2>

<div class="d-flex justify-content-between align-items-center mt-2">
<!-- Checkbox for subscribing to collection statistics -->
<div>
<span *ngIf="(dsoRD$ | async)?.payload.uuid as coll_uuid">
<div *ngIf="this.type === 'collection'">
<div class="ds-form-item row">
<div class="control-group col-sm-12">
<label>
<input
type="checkbox"
[checked]="subscribeStats"
(change)="toggleSubscription($event.target.checked, coll_uuid)"
/>
<span style="color: black"> Subscribe to Collection Statistics</span>
</label>
</div>
</div>
</div>
</span>
</div>
<!-- Delete button -->
<div class="mt-n10"> <!-- Adjust this margin as needed -->
<a class="btn btn-danger"
[routerLink]="((type === 'community') ? '/communities/' : '/collections/') + (dsoRD$ | async)?.payload.uuid + '/delete'">
<i class="fas fa-trash"></i> {{type + '.edit.delete' | translate}}</a>
</div>
</div>

<div class="border-bottom pb-3 mt-2"></div>

<div class="pt-2">
<ul class="nav nav-tabs justify-content-start mb-2">
<li *ngFor="let page of pages" class="nav-item">
Expand All @@ -79,4 +56,4 @@ <h2>{{ type + '.edit.head' | translate }}</h2>
</div>
</div>
</div>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import { Component, OnInit } from '@angular/core';

import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';

import { ActivatedRoute, Router } from '@angular/router';
import { RemoteData } from '../../../../core/data/remote-data';
import { isNotEmpty } from '../../../empty.util';
import { DSpaceObject } from '../../../../core/shared/dspace-object.model';

import { HttpClient} from '@angular/common/http';
import { HttpClient } from '@angular/common/http';
import { Collection } from '../../../../core/shared/collection.model';

import { ChangeDetectorRef } from '@angular/core';

// UM Used for global config paramter - location of backend.
Expand All @@ -21,17 +17,12 @@ import { environment } from '../../../../../environments/environment';
*/
@Component({
selector: 'ds-edit-comcol',
template: ''
templateUrl: './edit-comcol-page.component.html'
})
export class EditComColPageComponent<TDomain extends DSpaceObject> implements OnInit {

// public subscribeStats$: Promise<Boolean>;

subscribeStats: Boolean;
showContent: boolean;


cd: ChangeDetectorRef;
subscribeStats: boolean = false; // Ensure this reflects the current subscription state
showContent: boolean = false;

/**
* The type of DSpaceObject (used to create i18n messages)
Expand Down Expand Up @@ -64,7 +55,7 @@ cd: ChangeDetectorRef;
public hideReturnButton: boolean;

public constructor(
protected http: HttpClient,
protected http: HttpClient,
protected router: Router,
protected route: ActivatedRoute
) {
Expand All @@ -73,7 +64,6 @@ cd: ChangeDetectorRef;
}

ngOnInit(): void {

this.initPageParamsByRoute();

this.pages = this.route.routeConfig.children
Expand All @@ -85,38 +75,38 @@ cd: ChangeDetectorRef;
this.dsoRD$.subscribe((value: any) => {
let id = value.payload.uuid;
this.type = value.payload.type;

this.http.get(this.serverLocation + '/api/eperson/groups/issubscribed_admin/' + id, {responseType: 'text'}).subscribe((data: any) => {
if ( data === "true")
{
this.subscribeStats = true;
}
else {
this.subscribeStats = false;
}

this.http.get(this.serverLocation + '/api/eperson/groups/issubscribed_admin/' + id, { responseType: 'text' }).subscribe((data: any) => {
this.subscribeStats = data === "true";
});
});
}

public goToCollectionAdminStats(id: string) {
var link = document.createElement('a');
var working_href = 'https://angular.io/guide/router?restrict=1' + 'collid=' + id;
link.href = working_href;
link.click();
var link = document.createElement('a');
var working_href = 'https://angular.io/guide/router?restrict=1' + 'collid=' + id;
link.href = working_href;
link.click();
}

public subscribeToAdminStats(id: string) {
this.http.get(this.serverLocation + '/api/eperson/groups/subscribe_admin/' + id, {responseType: 'text'}).subscribe((data: any) => {
this.http.get(this.serverLocation + '/api/eperson/groups/subscribe_admin/' + id, { responseType: 'text' }).subscribe(() => {
this.subscribeStats = true;
});

this.subscribeStats = true;
}

public unsubscribeToAdminStats(id: string) {
this.http.get(this.serverLocation + '/api/eperson/groups/unsubscribe_admin/' + id, {responseType: 'text'}).subscribe((data: any) => {
this.http.get(this.serverLocation + '/api/eperson/groups/unsubscribe_admin/' + id, { responseType: 'text' }).subscribe(() => {
this.subscribeStats = false;
});
}

this.subscribeStats = false;
public toggleSubscription(isSubscribed: boolean, coll_uuid: string) {
if (isSubscribed) {
this.subscribeToAdminStats(coll_uuid);
} else {
this.unsubscribeToAdminStats(coll_uuid);
}
}

/**
Expand All @@ -136,4 +126,4 @@ cd: ChangeDetectorRef;
this.hideReturnButton = this.route.routeConfig.children
.find((child: any) => child.path === this.currentPage).data.hideReturnButton;
}
}
}
Loading