/
main.component.ts
125 lines (103 loc) · 4.12 KB
/
main.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
import { Component, Inject, OnInit } from '@angular/core';
import { Title } from '@angular/platform-browser';
import { Router } from '@angular/router';
import { ApiResponseData, ApiResponseError, Constants, KnoraApiConnection, ProjectsResponse } from '@dasch-swiss/dsp-js';
import { DspApiConnectionToken, SessionService } from '@dasch-swiss/dsp-ui';
import { ErrorHandlerService } from './error/error-handler.service';
import { GridItem } from './grid/grid.component';
@Component({
selector: 'app-main',
templateUrl: './main.component.html',
styleUrls: ['./main.component.scss']
})
export class MainComponent implements OnInit {
loading: boolean;
showCookieBanner = true;
researchField = 'qualitative';
session = false;
disabledProjects: string[] = [
Constants.SystemProjectIRI,
Constants.DefaultSharedOntologyIRI,
'http://rdfh.ch/projects/0001'
];
projects: GridItem[] = [];
features: GridItem[] = [
{
icon: 'all_inclusive',
title: 'Longevity of Humanities Data',
text: 'DSP-API keeps data accessible, citable, and reusable, even as technologies change.'
},
{
icon: 'search',
title: 'Powerful Searches',
text: 'Search for relationships between text, metadata, annotations, markup, links, and more.'
},
{
icon: 'share',
title: 'Ensures Consistency',
text: 'You define your data model, and DSP-API ensures that your data is consistent with it.'
},
{
icon: 'history',
title: 'History',
text: 'When data changes, DSP-API preserves past versions, so you can still view and cite them.'
},
{
icon: 'lock',
title: 'Control Access',
text: 'You decide who can view and change each item of data in your project.'
},
{
icon: 'group',
title: 'Project members',
text: 'Form your team and let the knowledge grow out of your data and resources.'
}
];
constructor(
@Inject(DspApiConnectionToken) private _dspApiConnection: KnoraApiConnection,
private _errorHandler: ErrorHandlerService,
private _session: SessionService,
private _router: Router,
private _titleService: Title
) {
// set the page title
this._titleService.setTitle('DaSCH Service Platform');
// check if a session is active
if (this._session.getSession()) {
this._router.navigate(['dashboard']);
} else {
// if session does not exist, redirect to login page
// --> NOTE: this is a temporary solution for DSP-ADMIN-APP
this._router.navigate(['login']);
}
}
ngOnInit() {
this.loadProjects();
}
loadProjects() {
this.loading = true;
this._dspApiConnection.admin.projectsEndpoint.getProjects().subscribe(
(response: ApiResponseData<ProjectsResponse>) => {
const sliceLength = 160;
for (const project of response.body.projects) {
// disable default test projects
if (!this.disabledProjects.includes(project.id) && project.status) {
const projectItem: GridItem = <GridItem>{};
projectItem.title = project.longname;
const preview: string = project.description[0].value.replace(/(<([^>]+)>)/ig, '');
projectItem.text = preview.substring(0, sliceLength).trim() +
(preview.length > sliceLength ? '...' : '');
projectItem.url = 'project/' + project.shortcode;
this.projects.push(projectItem);
}
}
this.projects.sort((a, b) => (a.title > b.title) ? 1 : -1);
this.loading = false;
},
(error: ApiResponseError) => {
this._errorHandler.showMessage(error);
this.loading = false;
}
);
}
}