-
Notifications
You must be signed in to change notification settings - Fork 29
/
publisheddata-dashboard.component.ts
157 lines (146 loc) · 4.54 KB
/
publisheddata-dashboard.component.ts
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import { Component, OnInit, OnDestroy, Inject } from "@angular/core";
import { Store } from "@ngrx/store";
import { PublishedData } from "shared/sdk";
import { Router } from "@angular/router";
import { selectPublishedDataDashboardPageViewModel } from "state-management/selectors/published-data.selectors";
import { CheckboxEvent } from "shared/modules/table/table.component";
import { Subscription } from "rxjs";
import { MatCheckboxChange } from "@angular/material/checkbox";
import { DOCUMENT } from "@angular/common";
import { Message, MessageType } from "state-management/models";
import { showMessageAction } from "state-management/actions/user.actions";
import { Column } from "shared/modules/shared-table/shared-table.module";
import { SciCatDataSource } from "shared/services/scicat.datasource";
import { AppConfigService } from "app-config.service";
import { ScicatDataService } from "shared/services/scicat-data-service";
import { ExportExcelService } from "shared/services/export-excel.service";
import { SelectionModel } from "@angular/cdk/collections";
@Component({
selector: "app-publisheddata-dashboard",
templateUrl: "./publisheddata-dashboard.component.html",
styleUrls: ["./publisheddata-dashboard.component.scss"],
})
export class PublisheddataDashboardComponent implements OnInit, OnDestroy {
public vm$ = this.store.select(selectPublishedDataDashboardPageViewModel);
columns: Column[] = [
{
id: "doi",
label: "DOI",
canSort: true,
icon: "fingerprint",
matchMode: "contains",
hideOrder: 0,
},
{
id: "title",
label: "Title",
icon: "description",
canSort: true,
matchMode: "contains",
hideOrder: 1,
},
{
id: "creator",
label: "Creator",
icon: "face",
canSort: true,
matchMode: "contains",
hideOrder: 2,
},
{
id: "createdBy",
icon: "account_circle",
label: "Created by",
canSort: true,
matchMode: "contains",
hideOrder: 4,
},
{
id: "createdAt",
icon: "date_range",
label: "Created at",
format: "date",
canSort: true,
matchMode: "between",
hideOrder: 5,
},
];
tableDefinition = {
collection: "publishedData",
columns: this.columns,
};
dataSource: SciCatDataSource;
select = true;
doiBaseUrl = "https://doi.org/";
selectedDOIs: string[] = [];
filtersSubscription: Subscription = new Subscription();
constructor(
@Inject(DOCUMENT) private document: Document,
private router: Router,
private store: Store,
private appConfigService: AppConfigService,
private dataService: ScicatDataService,
private exportService: ExportExcelService,
) {
this.dataSource = new SciCatDataSource(
this.appConfigService,
this.dataService,
this.exportService,
this.tableDefinition,
);
}
onShareClick() {
const selectionBox = this.document.createElement("textarea");
selectionBox.style.position = "fixed";
selectionBox.style.left = "0";
selectionBox.style.top = "0";
selectionBox.style.opacity = "0";
selectionBox.value = this.selectedDOIs.join("\n");
this.document.body.appendChild(selectionBox);
selectionBox.focus();
selectionBox.select();
this.document.execCommand("copy");
this.document.body.removeChild(selectionBox);
const message = new Message(
"The selected DOI's have been copied to your clipboard",
MessageType.Success,
5000,
);
this.store.dispatch(showMessageAction({ message }));
}
onRowClick(published: PublishedData) {
const id = encodeURIComponent(published.doi);
this.router.navigateByUrl("/publishedDatasets/" + id);
}
onSelectAll(event: {
event: MatCheckboxChange;
selection: SelectionModel<any>;
}) {
if (event.event.checked) {
this.selectedDOIs = event.selection.selected.map(
({ doi }) => this.doiBaseUrl + encodeURIComponent(doi),
);
} else {
this.selectedDOIs = [];
}
}
onSelectOne(checkboxEvent: CheckboxEvent) {
const { event, row } = checkboxEvent;
const doiUrl = this.doiBaseUrl + encodeURIComponent(row.doi);
if (event.checked) {
this.selectedDOIs.push(doiUrl);
} else {
this.selectedDOIs.splice(this.selectedDOIs.indexOf(doiUrl), 1);
}
}
ngOnInit() {
this.filtersSubscription = this.vm$.subscribe((vm) => {
this.router.navigate(["/publishedDatasets"], {
queryParams: { args: JSON.stringify(vm.filters) },
});
});
}
ngOnDestroy() {
this.filtersSubscription.unsubscribe();
}
}