Skip to content

Commit 1bb40d4

Browse files
committed
chore: update frontend to latest dsp-meta-svc state
1 parent ee0ccc3 commit 1bb40d4

File tree

5 files changed

+95
-25
lines changed

5 files changed

+95
-25
lines changed

web-frontend/public/global.css

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,6 @@ a.email {
4949
color: var(--dasch-primary) !important;
5050
font-size: 0.85rem;
5151
}
52-
a:visited {
53-
color: inherit;
54-
}
5552
/* disable fancy animation for certain links */
5653
.regular-link::before {
5754
background: none;

web-frontend/src/Footer.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
{#if version}
1818
<div class=version>{`Version: v${version}`}</div>
1919
{/if}
20-
<div class=copyright>© 2021-2023 DaSCH</div>
20+
<div class=copyright>© 2021-2024 DaSCH</div>
2121
</div>
2222
</footer>
2323

web-frontend/src/interfaces.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export interface Project {
4949
endDate?: string;
5050
contactPoint?: string;
5151
secondaryURL?: URL;
52-
publications?: string[];
52+
publications?: Publications[];
5353
grants?: string[];
5454
alternativeNames?: Text[];
5555
}
@@ -156,3 +156,8 @@ export interface DataManagementPlan {
156156
available?: boolean;
157157
url?: URL;
158158
}
159+
160+
export interface Publications {
161+
text: string;
162+
url?: URL[];
163+
}

web-frontend/src/project-page/ProjectPage.svelte

Lines changed: 87 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,32 @@
1111
import Loading from "../Loading.svelte";
1212
1313
const mobileResolution = window.innerWidth < 992;
14+
const isTestEnvironment: boolean = window.location.hostname === 'localhost' || window.location.hostname.startsWith('meta.test');
15+
const descriptionLanguages = new Map<string, string>([
16+
// contains languages that are presented in provided descriptions, update if necessary
17+
["ar", "Arabic"],
18+
["de", "German"],
19+
["en", "English"],
20+
["fr", "French"]
21+
]);
1422
1523
let isDescriptionExpanded: boolean;
1624
let descriptionLinesNumber: number;
1725
let arePublicationsExpanded: boolean;
18-
let isTestEnvironment: boolean = window.location.hostname === 'localhost' || window.location.hostname.startsWith('meta.dev')
26+
let displayedDescriptionsLanguage: string = "";
27+
let availableDescriptionsIso: string[] = [];
28+
29+
const getIso = (language: string): string => {
30+
const lang = (availableDescriptionsIso.length === 1) ? availableDescriptionsIso[0] : language
31+
return [...descriptionLanguages].find(([key, val]) => val === lang)[0]
32+
}
1933
2034
onMount(async () => {
2135
// wait with component creation for the data to be fetched
2236
await getProjectMetadata();
37+
availableDescriptionsIso = Object.keys($projectMetadata?.project.description);
38+
// initialize iso language to load => assumption is if more than 1 language is available English exists and set as default
39+
displayedDescriptionsLanguage = availableDescriptionsIso.length === 1 ? availableDescriptionsIso[0] : "en"
2340
});
2441
2542
onDestroy(() => {
@@ -34,7 +51,7 @@
3451
const baseUrl = `${protocol}//${window.location.hostname}${port}/`;
3552
const projectID = window.location.pathname.split("/")[2];
3653
37-
const res = await fetch(`${baseUrl}api/projects/${projectID}`);
54+
const res = await fetch(`${baseUrl}api/v1/projects/${projectID}`);
3855
const metadata: Metadata = await res.json();
3956
4057
projectMetadata.set(metadata);
@@ -56,18 +73,20 @@
5673
};
5774
5875
const getDivHeight = () => {
59-
let lineHeight: number;
60-
let divHeight: number;
61-
try {
62-
const el = document.getElementById("description");
63-
divHeight = el.scrollHeight;
64-
lineHeight = parseInt(window.getComputedStyle(el).getPropertyValue('line-height'));
65-
} catch (error) {
66-
lineHeight = 20;
67-
divHeight = 19;
68-
}
69-
descriptionLinesNumber = divHeight / lineHeight;
70-
isDescriptionExpanded = descriptionLinesNumber > 6 ? false : true;
76+
setTimeout(() => {
77+
let lineHeight: number;
78+
let divHeight: number;
79+
try {
80+
const el = document.getElementById("description");
81+
divHeight = el.scrollHeight;
82+
lineHeight = parseInt(window.getComputedStyle(el).getPropertyValue('line-height'));
83+
} catch (error) {
84+
lineHeight = 20;
85+
divHeight = 19;
86+
}
87+
descriptionLinesNumber = divHeight / lineHeight;
88+
isDescriptionExpanded = descriptionLinesNumber > 6 ? false : true;
89+
}, 100);
7190
};
7291
</script>
7392

@@ -113,9 +132,17 @@
113132
<!-- Description -->
114133
<div class="property-row">
115134
{#if $projectMetadata?.project.description && getText($projectMetadata?.project.description)}
116-
<span class="label new-subtitle">Description</span>
135+
<span class="label new-subtitle" style="display: block;">Description
136+
<span style={availableDescriptionsIso.length <= 1 ? "display: none" : "display: contents"}> in
137+
{#each Object.keys($projectMetadata?.project.description).map(k=> descriptionLanguages.get(k)) as l}
138+
<button class="language {availableDescriptionsIso.length > 1 && displayedDescriptionsLanguage === getIso(l) ? "active" : ""}" on:click={() => displayedDescriptionsLanguage = getIso(l)}>
139+
{l}
140+
</button>
141+
{/each}
142+
</span>
143+
</span>
117144
<div id="description" class="data new-text {isDescriptionExpanded ? '' : 'description-short'}">
118-
{getText($projectMetadata?.project.description)}
145+
{$projectMetadata?.project.description[displayedDescriptionsLanguage]}
119146
</div>
120147
{#if descriptionLinesNumber > 6}
121148
<div on:click={toggleDescriptionExpand} class="expand-button">
@@ -133,9 +160,27 @@
133160
<span class="label new-subtitle">Publications</span>
134161
{#each $projectMetadata?.project.publications as p, i}
135162
{#if i > 1}
136-
<span class={arePublicationsExpanded ? "data new-text" : "hidden"}>{p}</span>
163+
<span class={arePublicationsExpanded ? "data new-text" : "hidden"}>{p.text}
164+
{#if p.url}
165+
{#each p.url as url, n}
166+
<a href={url.url} class="publication-link {arePublicationsExpanded ? "data" : "hidden"}" target=_>
167+
{url.text}
168+
{p.url.length > 0 && n < p.url.length - 1 ? "," : ""}
169+
</a>
170+
{/each}
171+
{/if}
172+
</span>
137173
{:else}
138-
<span class="data new-text">{p}</span>
174+
<span class="data new-text">{p.text}
175+
{#if p.url}
176+
{#each p.url as url, n}
177+
<a href={url.url} class="publication-link {arePublicationsExpanded ? "data" : "hidden"}" target=_>
178+
{url.text}
179+
{p.url.length > 0 && n < p.url.length - 1 ? "," : ""}
180+
</a>
181+
{/each}
182+
{/if}
183+
</span>
139184
{/if}
140185
{/each}
141186
</div>
@@ -259,6 +304,30 @@
259304
-webkit-box-orient: vertical;
260305
overflow: hidden;
261306
}
307+
.publication-link {
308+
display: contents;
309+
color: var(--lead-colour);
310+
overflow: hidden;
311+
text-overflow: ellipsis;
312+
white-space: nowrap;
313+
}
314+
button.language {
315+
width: 80px;
316+
margin: 0 5px;
317+
border: 1px solid var(--lead-colour);
318+
background-color: #fff;
319+
display: inline-block;
320+
vertical-align: middle;
321+
border-radius: 0.25rem;
322+
padding: 5px 10px;
323+
color: var(--lead-colour);
324+
box-shadow: var(--shadow-1);
325+
}
326+
button.language.active {
327+
color: white;
328+
background-color: var(--dasch-secondary);
329+
border-color: #dee2e6 #dee2e6 #fff;
330+
}
262331
263332
@supports (-moz-appearance: none) {
264333
button.gototop-button {margin-bottom: 40px;}

web-frontend/src/project-page/ProjectWidget.svelte

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
let isTestEnvironment: boolean = window.location.hostname === 'localhost' || window.location.hostname.startsWith('meta.test')
66
77
const truncateString = (s: string) => {
8-
// TODO: can this be improved? 1. dynamic length depending on space; 2. show full text on hover
8+
// TODO: can this be improved? 1. dynamic langth depending on space; 2. show full text on hover
99
if (s.length > 35) {
1010
return `${s.slice(0, 35)}...`;
1111
} else return s;
@@ -150,7 +150,6 @@
150150
<div class=label>Funder</div>
151151
{#each $projectMetadata?.project.funders.map((o) => {return findObjectByID(o)}) as f}
152152
{#if f.__type === "Person"}
153-
{console.log('person',f)}
154153
<!-- TODO: handle funding person - need to find example -->
155154
<!-- <div class=data>{findObjectById(f)?.givenName.split(";").join(" ")} {findObjectById(f)?.familyName}</div> -->
156155
{:else if f.__type === "Organization"}

0 commit comments

Comments
 (0)