Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update frontend to latest dsp-meta-svc state (DEV-3818) #143

Merged
merged 2 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions web-frontend/public/global.css
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ a.email {
color: var(--dasch-primary) !important;
font-size: 0.85rem;
}
a:visited {
color: inherit;
}
/* disable fancy animation for certain links */
.regular-link::before {
background: none;
Expand Down
2 changes: 1 addition & 1 deletion web-frontend/src/Footer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
{#if version}
<div class=version>{`Version: v${version}`}</div>
{/if}
<div class=copyright>© 2021-2023 DaSCH</div>
<div class=copyright>© 2021-2024 DaSCH</div>
</div>
</footer>

Expand Down
7 changes: 6 additions & 1 deletion web-frontend/src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export interface Project {
endDate?: string;
contactPoint?: string;
secondaryURL?: URL;
publications?: string[];
publications?: Publications[];
grants?: string[];
alternativeNames?: Text[];
}
Expand Down Expand Up @@ -156,3 +156,8 @@ export interface DataManagementPlan {
available?: boolean;
url?: URL;
}

export interface Publications {
text: string;
url?: URL[];
}
105 changes: 87 additions & 18 deletions web-frontend/src/project-page/ProjectPage.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,32 @@
import Loading from "../Loading.svelte";

const mobileResolution = window.innerWidth < 992;
const isTestEnvironment: boolean = window.location.hostname === 'localhost' || window.location.hostname.startsWith('meta.test');
const descriptionLanguages = new Map<string, string>([
// contains languages that are presented in provided descriptions, update if necessary
["ar", "Arabic"],
["de", "German"],
["en", "English"],
["fr", "French"]
]);

let isDescriptionExpanded: boolean;
let descriptionLinesNumber: number;
let arePublicationsExpanded: boolean;
let isTestEnvironment: boolean = window.location.hostname === 'localhost' || window.location.hostname.startsWith('meta.dev')
let displayedDescriptionsLanguage: string = "";
let availableDescriptionsIso: string[] = [];

const getIso = (language: string): string => {
const lang = (availableDescriptionsIso.length === 1) ? availableDescriptionsIso[0] : language
return [...descriptionLanguages].find(([key, val]) => val === lang)[0]
}

onMount(async () => {
// wait with component creation for the data to be fetched
await getProjectMetadata();
availableDescriptionsIso = Object.keys($projectMetadata?.project.description);
// initialize iso language to load => assumption is if more than 1 language is available English exists and set as default
displayedDescriptionsLanguage = availableDescriptionsIso.length === 1 ? availableDescriptionsIso[0] : "en"
});

onDestroy(() => {
Expand All @@ -34,7 +51,7 @@
const baseUrl = `${protocol}//${window.location.hostname}${port}/`;
const projectID = window.location.pathname.split("/")[2];

const res = await fetch(`${baseUrl}api/projects/${projectID}`);
const res = await fetch(`${baseUrl}api/v1/projects/${projectID}`);
const metadata: Metadata = await res.json();

projectMetadata.set(metadata);
Expand All @@ -56,18 +73,20 @@
};

const getDivHeight = () => {
let lineHeight: number;
let divHeight: number;
try {
const el = document.getElementById("description");
divHeight = el.scrollHeight;
lineHeight = parseInt(window.getComputedStyle(el).getPropertyValue('line-height'));
} catch (error) {
lineHeight = 20;
divHeight = 19;
}
descriptionLinesNumber = divHeight / lineHeight;
isDescriptionExpanded = descriptionLinesNumber > 6 ? false : true;
setTimeout(() => {
let lineHeight: number;
let divHeight: number;
try {
const el = document.getElementById("description");
divHeight = el.scrollHeight;
lineHeight = parseInt(window.getComputedStyle(el).getPropertyValue('line-height'));
} catch (error) {
lineHeight = 20;
divHeight = 19;
}
descriptionLinesNumber = divHeight / lineHeight;
isDescriptionExpanded = descriptionLinesNumber > 6 ? false : true;
}, 100);
};
</script>

Expand Down Expand Up @@ -113,9 +132,17 @@
<!-- Description -->
<div class="property-row">
{#if $projectMetadata?.project.description && getText($projectMetadata?.project.description)}
<span class="label new-subtitle">Description</span>
<span class="label new-subtitle" style="display: block;">Description
<span style={availableDescriptionsIso.length <= 1 ? "display: none" : "display: contents"}> in
{#each Object.keys($projectMetadata?.project.description).map(k=> descriptionLanguages.get(k)) as l}
<button class="language {availableDescriptionsIso.length > 1 && displayedDescriptionsLanguage === getIso(l) ? "active" : ""}" on:click={() => displayedDescriptionsLanguage = getIso(l)}>
{l}
</button>
{/each}
</span>
</span>
<div id="description" class="data new-text {isDescriptionExpanded ? '' : 'description-short'}">
{getText($projectMetadata?.project.description)}
{$projectMetadata?.project.description[displayedDescriptionsLanguage]}
</div>
{#if descriptionLinesNumber > 6}
<div on:click={toggleDescriptionExpand} class="expand-button">
Expand All @@ -133,9 +160,27 @@
<span class="label new-subtitle">Publications</span>
{#each $projectMetadata?.project.publications as p, i}
{#if i > 1}
<span class={arePublicationsExpanded ? "data new-text" : "hidden"}>{p}</span>
<span class={arePublicationsExpanded ? "data new-text" : "hidden"}>{p.text}
{#if p.url}
{#each p.url as url, n}
<a href={url.url} class="publication-link {arePublicationsExpanded ? "data" : "hidden"}" target=_>
{url.text}
{p.url.length > 0 && n < p.url.length - 1 ? "," : ""}
</a>
{/each}
{/if}
</span>
{:else}
<span class="data new-text">{p}</span>
<span class="data new-text">{p.text}
{#if p.url}
{#each p.url as url, n}
<a href={url.url} class="publication-link {arePublicationsExpanded ? "data" : "hidden"}" target=_>
{url.text}
{p.url.length > 0 && n < p.url.length - 1 ? "," : ""}
</a>
{/each}
{/if}
</span>
{/if}
{/each}
</div>
Expand Down Expand Up @@ -259,6 +304,30 @@
-webkit-box-orient: vertical;
overflow: hidden;
}
.publication-link {
display: contents;
color: var(--lead-colour);
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
button.language {
width: 80px;
margin: 0 5px;
border: 1px solid var(--lead-colour);
background-color: #fff;
display: inline-block;
vertical-align: middle;
border-radius: 0.25rem;
padding: 5px 10px;
color: var(--lead-colour);
box-shadow: var(--shadow-1);
}
button.language.active {
color: white;
background-color: var(--dasch-secondary);
border-color: #dee2e6 #dee2e6 #fff;
}

@supports (-moz-appearance: none) {
button.gototop-button {margin-bottom: 40px;}
Expand Down
1 change: 0 additions & 1 deletion web-frontend/src/project-page/ProjectWidget.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@
<div class=label>Funder</div>
{#each $projectMetadata?.project.funders.map((o) => {return findObjectByID(o)}) as f}
{#if f.__type === "Person"}
{console.log('person',f)}
<!-- TODO: handle funding person - need to find example -->
<!-- <div class=data>{findObjectById(f)?.givenName.split(";").join(" ")} {findObjectById(f)?.familyName}</div> -->
{:else if f.__type === "Organization"}
Expand Down