forked from DSpace/dspace-angular
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathemail-request-copy.component.ts
More file actions
125 lines (109 loc) · 3.06 KB
/
email-request-copy.component.ts
File metadata and controls
125 lines (109 loc) · 3.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import {
AsyncPipe,
Location,
NgClass,
} from '@angular/common';
import {
Component,
EventEmitter,
Input,
OnDestroy,
OnInit,
Output,
} from '@angular/core';
import { FormsModule } from '@angular/forms';
import { NgbDropdownModule } from '@ng-bootstrap/ng-bootstrap';
import { TranslateModule } from '@ngx-translate/core';
import {
Observable,
Subject,
} from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import { BtnDisabledDirective } from '../../shared/btn-disabled.directive';
import { hasValue } from '../../shared/empty.util';
import { RequestCopyEmail } from './request-copy-email.model';
@Component({
selector: 'ds-base-email-request-copy',
styleUrls: ['./email-request-copy.component.scss'],
templateUrl: './email-request-copy.component.html',
standalone: true,
imports: [FormsModule, NgClass, TranslateModule, BtnDisabledDirective, NgbDropdownModule, AsyncPipe],
})
/**
* A form component for an email to send back to the user requesting an item
*/
export class EmailRequestCopyComponent implements OnInit, OnDestroy {
/**
* Event emitter for sending the email
*/
@Output() send: EventEmitter<RequestCopyEmail> = new EventEmitter<RequestCopyEmail>();
/**
* Selected access period emmitter, sending the new period up to the parent component
*/
@Output() selectedAccessPeriod: EventEmitter<string> = new EventEmitter();
/**
* The subject of the email
*/
@Input() subject: string;
/**
* The contents of the email
*/
@Input() message: string;
/**
* A list of valid access periods to render in a drop-down menu
*/
@Input() validAccessPeriods$: Observable<string[]>;
/**
* The selected access period, e.g. +7DAYS, +12MONTHS, FOREVER. These will be
* calculated as a timestamp to store as the access expiry date for the requested item
*/
accessPeriod = 'FOREVER';
/**
* Destroy subject for unsubscribing from observables
* @private
*/
private destroy$ = new Subject<void>();
protected readonly hasValue = hasValue;
constructor(protected location: Location) {
}
/**
* Initialise subscription to async valid access periods (from configuration service)
*/
ngOnInit(): void {
this.validAccessPeriods$.pipe(
takeUntil(this.destroy$),
).subscribe((validAccessPeriods) => {
if (hasValue(validAccessPeriods) && validAccessPeriods.length > 0) {
this.selectAccessPeriod(validAccessPeriods[0]);
}
});
}
/**
* Clean up subscriptions and selectors
*/
ngOnDestroy(): void {
this.selectedAccessPeriod.complete();
this.destroy$.next();
this.destroy$.complete();
}
/**
* Submit the email
*/
submit() {
this.send.emit(new RequestCopyEmail(this.subject, this.message));
}
/**
* Return to the previous page
*/
return() {
this.location.back();
}
/**
* Update the access period when a dropdown menu button is clicked for a value
* @param accessPeriod
*/
selectAccessPeriod(accessPeriod: string) {
this.accessPeriod = accessPeriod;
this.selectedAccessPeriod.emit(accessPeriod);
}
}