forked from DSpace/dspace-angular
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbulk-access.component.ts
More file actions
115 lines (101 loc) · 3.17 KB
/
bulk-access.component.ts
File metadata and controls
115 lines (101 loc) · 3.17 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
import {
ChangeDetectionStrategy,
Component,
OnInit,
ViewChild,
} from '@angular/core';
import { TranslateModule } from '@ngx-translate/core';
import {
BehaviorSubject,
Subscription,
} from 'rxjs';
import {
distinctUntilChanged,
map,
} from 'rxjs/operators';
import { BulkAccessControlService } from '../../shared/access-control-form-container/bulk-access-control.service';
import { BtnDisabledDirective } from '../../shared/btn-disabled.directive';
import { SelectableListState } from '../../shared/object-list/selectable-list/selectable-list.reducer';
import { SelectableListService } from '../../shared/object-list/selectable-list/selectable-list.service';
import { BulkAccessBrowseComponent } from './browse/bulk-access-browse.component';
import { BulkAccessSettingsComponent } from './settings/bulk-access-settings.component';
@Component({
selector: 'ds-bulk-access',
templateUrl: './bulk-access.component.html',
styleUrls: ['./bulk-access.component.scss'],
imports: [
TranslateModule,
BulkAccessSettingsComponent,
BulkAccessBrowseComponent,
BtnDisabledDirective,
],
standalone: true,
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class BulkAccessComponent implements OnInit {
/**
* The selection list id
*/
listId = 'bulk-access-list';
/**
* The list of the objects already selected
*/
objectsSelected$: BehaviorSubject<string[]> = new BehaviorSubject<string[]>([]);
/**
* Array to track all subscriptions and unsubscribe them onDestroy
*/
private subs: Subscription[] = [];
/**
* The SectionsDirective reference
*/
@ViewChild('dsBulkSettings') settings: BulkAccessSettingsComponent;
constructor(
private bulkAccessControlService: BulkAccessControlService,
private selectableListService: SelectableListService,
) {
}
ngOnInit(): void {
this.subs.push(
this.selectableListService.getSelectableList(this.listId).pipe(
distinctUntilChanged(),
map((list: SelectableListState) => this.generateIdListBySelectedElements(list)),
).subscribe(this.objectsSelected$),
);
}
canExport(): boolean {
return this.objectsSelected$.value?.length > 0 && this.settings?.isFormValid();
}
/**
* Reset the form to its initial state
* This will also reset the state of the child components (bitstream and item access)
*/
reset(): void {
this.settings.reset();
}
/**
* Submit the form
* This will create a payload file and execute the script
*/
submit(): void {
const settings = this.settings.getValue();
const bitstreamAccess = settings.bitstream;
const itemAccess = settings.item;
const { file } = this.bulkAccessControlService.createPayloadFile({
bitstreamAccess,
itemAccess,
state: settings.state,
});
this.bulkAccessControlService.executeScript(
this.objectsSelected$.value || [],
file,
).subscribe();
}
/**
* Generate The RemoteData object containing the list of the selected elements
* @param list
* @private
*/
private generateIdListBySelectedElements(list: SelectableListState): string[] {
return list?.selection?.map((entry: any) => entry.indexableObject.uuid);
}
}