diff --git a/content/_index.md b/content/_index.md index b0b3b2ca090916111a6e3464a57946b19df240cc..c5d05212ded199a2b1019d322316fddd8eb3d411 100644 --- a/content/_index.md +++ b/content/_index.md @@ -23,7 +23,15 @@ header_wrapper_class: "featured-jumbotron-home" count="5" templatePath="/js/templates/featured-story-custom.mustache" >}} -{{< home/projects highlight="ecd.openvsx:ecd.theia:ecd.jkube">}} +{{< home/projects + projectIds="ecd.openvsx,ecd.theia,ecd.jkube" + templateId="homepage-featured-projects" + url="https://projects.eclipse.org/api/projects?working_group=cloud-development-tools" + classes="margin-top-30" + >}} + +{{< mustache_js template-id="homepage-featured-projects" path="/js/templates/homepage-featured-projects.mustache" >}} + {{< home/whats-new >}} {{< mustache_js template-id="homepage-news-list-item" path="/js/templates/homepage-news-list-item.mustache" >}} {{< home/stats >}} diff --git a/content/projects/_index.md b/content/projects/_index.md index e1359c2dfbc324fe2607638f2beec975ae647d34..1ec7ea1b7a09c5a8f20a55a87f03afce671c35a9 100644 --- a/content/projects/_index.md +++ b/content/projects/_index.md @@ -9,4 +9,11 @@ container: "container-fluid" main_content_class: "col-sm-18 col-sm-offset-3" --- -{{< page/projects >}} \ No newline at end of file +{{< home/projects + templateId="tpl-projects-item" + url="https://projects.eclipse.org/api/projects?working_group=cloud-development-tools" + classes="margin-top-30" + >}} + +{{< page/projects >}} + diff --git a/js/main.js b/js/main.js index 98fa1ff5815b4e481b35e40e28d6808c303403ec..8a920e4c5a87b525dce0ccdc067a3c5a0bb48144 100644 --- a/js/main.js +++ b/js/main.js @@ -14,6 +14,7 @@ import 'eclipsefdn-solstice-assets' import './src/userprofile' import './src/projects' +import './src/featured-projects' import './src/eclipseApi' import './src/parallax' import './adopters-alternate.js' diff --git a/js/src/featured-projects.js b/js/src/featured-projects.js new file mode 100644 index 0000000000000000000000000000000000000000..cb277008bdc1a969e0ca47e99e15015718fdaa50 --- /dev/null +++ b/js/src/featured-projects.js @@ -0,0 +1,138 @@ +/*! + * Copyright (c) 2021 Eclipse Foundation, Inc. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * Contributors: + * Eric Poirier + * + * SPDX-License-Identifier: EPL-2.0 + */ + +import $ from 'jquery'; +import Mustache from 'mustache'; +import template from '../templates/tpl-projects-item.mustache'; +import "numeral"; +import List from 'list.js'; + +export const processJSON = (json, options) => { + + function getCategory(project_id) { + var categories = { + "ecd.che": "Cloud IDE", + "ecd.che.che4z": "Extension Marketplace", + "ecd.codewind": "IDE-Agnostic Library", + "ecd.dirigible": "Service (IDEAAS)", + "ecd.emfcloud": "Cloud IDE", + "ecd.glsp": "Diagram Editors", + "ecd.jkube": "Cloud IDE", + "ecd.openvsx": "Extension Marketplace", + "ecd.sprotty": "Framework", + "ecd.theia": "Cloud IDE", + "ecd.cft": "Cloud IDE", + "ecd.orion": "Extension Marketplace" + }; + return categories[project_id]; + } + + function fileExists(url) { + if(url){ + var req = new XMLHttpRequest(); + req.open('GET', url, false); + req.send(); + return req.status == 200; + } else { + return false; + } + } + + // Initiate the projects array + let projects = json; + + // Filter by project ID + if (options.projectIds !== undefined && options.projectIds !== "") { + const acceptedProjectIds = options.projectIds.split(","); + projects = []; + $(json).each(function(key, element){ + if (acceptedProjectIds.includes(element.project_id)) { + projects.push(element); + } + }); + } + + $(projects).each(function(key, project){ + + projects[key].category = getCategory(projects[key].project_id); + + projects[key].version = 'none'; + if (project.releases[0]) { + projects[key].version = project.releases[0].name; + } + + if (options.templateId !== "tpl-projects-item") { + $(project.project_leads).each(function(project_lead_key, project_lead){ + projects[key].project_lead_image = '/images/ecdtools/home/silhouette.jpg'; + projects[key].project_lead_full_name = project_lead.full_name; + if (fileExists('/images/ecdtools/projects/'+ project_lead.username +'.png')) { + projects[key].project_lead_image = '/images/ecdtools/projects/'+ project_lead.username +'.png'; + } + return false; + }); + } + + }); + + return projects; +}; + +(function ($, document) { + $('.featured-projects').each(function (index, element) { + const options = { + id: '', + templateId: '', + projectIds: '', + url: '', + ...$(element).data(), + }; + + // fetching the users + function fetchProjects() { + return fetch(options.url) + .then(response => response.json()) + } + + let results = []; + Promise.allSettled([fetchProjects()]) + .then(function (responses) { + responses.forEach((el) => { + // skip rejected promises + if (el.status === 'fulfilled') { + const projects = processJSON(el.value, options); + if (projects.length > 0) { + results = projects; + } + } + }); + + const data = { + items: results, + }; + + // Render component + let html = ''; + //console.log(options); + if (options.templateId !== '' && document.getElementById(options.templateId)) { + const theme = document.getElementById(options.templateId).innerHTML; + html = Mustache.render(theme, data); + } else { + html = template(data); + } + element.innerHTML += html; + }) + .catch(err => console.log(err)); + }); +})(jQuery, document); + + diff --git a/js/src/projects.js b/js/src/projects.js index 110c5cf9c67f2e3e80608dc279c7aea9323ce55c..242a280e5a0276c8fce45a79d7a4c7c10bb94072 100644 --- a/js/src/projects.js +++ b/js/src/projects.js @@ -14,7 +14,7 @@ const EclipseProjectList = (function ($) { $.ajax({ type: 'GET', - url: '/js/projects.json', + url: 'https://projects.eclipse.org/api/projects?working_group=cloud-development-tools', dataType: 'json', cache: true, success: function (data) { diff --git a/js/templates/homepage-featured-projects.mustache b/js/templates/homepage-featured-projects.mustache new file mode 100644 index 0000000000000000000000000000000000000000..2a4c0a170657ab0384d9a4f40d91a29a56017640 --- /dev/null +++ b/js/templates/homepage-featured-projects.mustache @@ -0,0 +1,27 @@ +{{#items}} +
  • +
    +

    + + {{#logo}} + + {{/logo}} + {{^logo}} + + {{/logo}} + +

    +

    The Project: {{{ summary }}} +
    Learn more 

    +
    +
    + {{ project_lead_full_name }} +
    +
    +

    Project Lead:
    + {{ project_lead_full_name }}

    +
    +
    +
    +
  • +{{/items}} \ No newline at end of file diff --git a/js/templates/tpl-projects-item.mustache b/js/templates/tpl-projects-item.mustache new file mode 100644 index 0000000000000000000000000000000000000000..384fdd896d269db4514135bbc0c02c679c6f0028 --- /dev/null +++ b/js/templates/tpl-projects-item.mustache @@ -0,0 +1,22 @@ +{{#items}} +
  • + +
  • +{{/items}} \ No newline at end of file diff --git a/layouts/shortcodes/home/projects.html b/layouts/shortcodes/home/projects.html index 1d2c47c1bc9b94b3257272c420b63d34f84628ef..f97eb1ce519e3328bc84e6662dde0d52eaf8b60a 100644 --- a/layouts/shortcodes/home/projects.html +++ b/layouts/shortcodes/home/projects.html @@ -11,73 +11,21 @@ SPDX-License-Identifier: EPL-2.0 --> -{{ $highlights:= split (.Get "highlight") ":" }} -{{/* Pre process projects to find projects with the given working groups (if one is set) */}} -{{ range sort $.Site.Data.eclipsefdn_projects "name" "asc" }} - {{ $project_contains_working_group := false }} - {{ if $.Site.Params.projects_working_group }} - {{ $working_group_id := $.Site.Params.projects_working_group }} - {{ range .working_groups }} - {{ if and (ne $project_contains_working_group true) (eq .id $working_group_id) }} - {{ $project_contains_working_group = true }} - {{ end }} - {{ end }} - {{ end }} - - {{ if or (not ($.Site.Params.projects_working_group)) (eq $project_contains_working_group true) }} - {{ $.Scratch.SetInMap "wg_projects" .name . }} - {{ end }} -{{ end }} - -{{ $scratch := .Scratch }} - - +{{ $id := .Get "id" | default "featured-story-container" }} +{{ $templateId := .Get "templateId" }} +{{ $projectIds := .Get "projectIds" }} +{{ $url := .Get "url" }} +{{ $classes := .Get "classes" }}