-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathpublisheddata-details.component.ts
73 lines (64 loc) · 2.14 KB
/
publisheddata-details.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
import { Component, OnInit, OnDestroy } from "@angular/core";
import { PublishedData } from "shared/sdk";
import { Store } from "@ngrx/store";
import { ActivatedRoute, Router } from "@angular/router";
import {
fetchPublishedDataAction,
registerPublishedDataAction,
} from "state-management/actions/published-data.actions";
import { Subscription } from "rxjs";
import { pluck } from "rxjs/operators";
import { selectCurrentPublishedData } from "state-management/selectors/published-data.selectors";
import { AppConfigService } from "app-config.service";
@Component({
selector: "publisheddata-details",
templateUrl: "./publisheddata-details.component.html",
styleUrls: ["./publisheddata-details.component.scss"],
})
export class PublisheddataDetailsComponent implements OnInit, OnDestroy {
currentData$ = this.store.select(selectCurrentPublishedData);
publishedData: PublishedData = new PublishedData();
subscriptions: Subscription[] = [];
appConfig = this.appConfigService.getConfig();
show = false;
landingPageUrl = "";
doi = "";
constructor(
private appConfigService: AppConfigService,
private route: ActivatedRoute,
private router: Router,
private store: Store,
) {}
ngOnInit() {
this.subscriptions.push(
this.route.params.pipe(pluck("id")).subscribe((id: string) => {
this.doi = id;
this.store.dispatch(fetchPublishedDataAction({ id }));
}),
);
this.subscriptions.push(
this.currentData$.subscribe((data) => {
if (data) {
this.publishedData = data;
if (this.appConfig.landingPage) {
this.landingPageUrl =
this.appConfig.landingPage + encodeURIComponent(data.doi);
}
}
}),
);
}
ngOnDestroy() {
this.subscriptions.forEach((subscription) => subscription.unsubscribe());
}
onRegisterClick(doi: string) {
this.store.dispatch(registerPublishedDataAction({ doi }));
}
onEditClick() {
const id = encodeURIComponent(this.doi);
this.router.navigateByUrl("/publishedDatasets/" + id + "/edit");
}
isUrl(dataDescription: string): boolean {
return dataDescription.includes("http");
}
}