|  | 
| 11 | 11 |   import Loading from "../Loading.svelte"; | 
| 12 | 12 | 
 | 
| 13 | 13 |   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 | +  ]); | 
| 14 | 22 | 
 | 
| 15 | 23 |   let isDescriptionExpanded: boolean; | 
| 16 | 24 |   let descriptionLinesNumber: number; | 
| 17 | 25 |   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 | +  } | 
| 19 | 33 | 
 | 
| 20 | 34 |   onMount(async () => { | 
| 21 | 35 |     // wait with component creation for the data to be fetched | 
| 22 | 36 |     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" | 
| 23 | 40 |   }); | 
| 24 | 41 | 
 | 
| 25 | 42 |   onDestroy(() => { | 
|  | 
| 34 | 51 |     const baseUrl = `${protocol}//${window.location.hostname}${port}/`; | 
| 35 | 52 |     const projectID = window.location.pathname.split("/")[2]; | 
| 36 | 53 | 
 | 
| 37 |  | -    const res = await fetch(`${baseUrl}api/projects/${projectID}`); | 
|  | 54 | +    const res = await fetch(`${baseUrl}api/v1/projects/${projectID}`); | 
| 38 | 55 |     const metadata: Metadata = await res.json(); | 
| 39 | 56 | 
 | 
| 40 | 57 |     projectMetadata.set(metadata); | 
|  | 
| 56 | 73 |   }; | 
| 57 | 74 | 
 | 
| 58 | 75 |   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); | 
| 71 | 90 |   }; | 
| 72 | 91 | </script> | 
| 73 | 92 | 
 | 
|  | 
| 113 | 132 |         <!-- Description --> | 
| 114 | 133 |         <div class="property-row"> | 
| 115 | 134 |           {#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> | 
| 117 | 144 |             <div id="description" class="data new-text {isDescriptionExpanded ? '' : 'description-short'}"> | 
| 118 |  | -              {getText($projectMetadata?.project.description)} | 
|  | 145 | +              {$projectMetadata?.project.description[displayedDescriptionsLanguage]} | 
| 119 | 146 |             </div> | 
| 120 | 147 |             {#if descriptionLinesNumber > 6} | 
| 121 | 148 |               <div on:click={toggleDescriptionExpand} class="expand-button"> | 
|  | 
| 133 | 160 |             <span class="label new-subtitle">Publications</span> | 
| 134 | 161 |             {#each $projectMetadata?.project.publications as p, i} | 
| 135 | 162 |               {#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> | 
| 137 | 173 |               {: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> | 
| 139 | 184 |               {/if} | 
| 140 | 185 |             {/each} | 
| 141 | 186 |           </div> | 
|  | 
| 259 | 304 |     -webkit-box-orient: vertical; | 
| 260 | 305 |     overflow: hidden; | 
| 261 | 306 |   } | 
|  | 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 | +  } | 
| 262 | 331 | 
 | 
| 263 | 332 |   @supports (-moz-appearance: none) { | 
| 264 | 333 |     button.gototop-button {margin-bottom: 40px;} | 
|  | 
0 commit comments