Skip to content

Commit 7abb984

Browse files
committed
Consolidates broken-out utils files in assets/js
1 parent fee216b commit 7abb984

4 files changed

Lines changed: 78 additions & 77 deletions

File tree

assets/js/current-projects-utils.js

Lines changed: 0 additions & 54 deletions
This file was deleted.

assets/js/current-projects.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22

33
---
4+
45
// Do All Dom Manipulation After The DOM content is full loaded
56
document.addEventListener("DOMContentLoaded",function(){
67
(function main(){
@@ -225,6 +226,55 @@ function retrieveProjectDataFromCollection() {
225226
return projectData;
226227
}
227228

229+
/**
230+
* Given an input of a project data array object as returned by the function `retrieveProjectDataFromCollection()`, this
231+
* function sorts the project twice.
232+
* 1. It sort all projects in the array alphabetically on their `status` value
233+
* 2. It sort all project by title for each status type
234+
*/
235+
function projectDataSorter(projectdata){
236+
237+
const statusList = ["Active","Completed","On Hold"]
238+
const sortedProjectContainer = [];
239+
240+
// Sort Project data by status alphabetically
241+
projectdata.sort( (a,b) => (a.project.status > b.project.status) ? 1 : -1)
242+
243+
// Sort Project Data by title for each status type
244+
for(const status of statusList){
245+
let arr = projectdata.filter(function(item){
246+
return item.project.status === status
247+
}).sort( (a,b) => (a.project.title > b.project.title) ? 1 : -1);
248+
sortedProjectContainer.push(...arr);
249+
}
250+
251+
return sortedProjectContainer;
252+
}
253+
254+
/**
255+
* Given an array of project object as returned by ``retrieveProjectDataFromCollection()``
256+
* Returns a filter object -> {filter_type1:[filter_value1,filter_value2], filter_type2:[filter_value1,filter_value2], ... }
257+
*/
258+
function createFilter(sortedProjectData, checkPage = false) {
259+
if (checkPage) {
260+
return {
261+
'technologies': [...new Set(sortedProjectData.map(item => (item.project.technologies?.length > 0) ? [item.project.technologies].flat() : '').flat() ) ].filter(v=>v!='').sort(),
262+
'languages': [...new Set(sortedProjectData.map(item => (item.project.languages?.length > 0) ? [item.project.languages].flat() : '').flat() ) ].filter(v=>v!='').sort(),
263+
'tools': [...new Set(sortedProjectData.map(item => (item.project.tools?.length > 0) ? [item.project.tools].flat() : '').flat() ) ].filter(v=>v!='').sort(),
264+
}
265+
} else {
266+
return {
267+
// 'looking': [ ... new Set( (sortedProjectData.map(item => item.project.looking ? item.project.looking.map(item => item.category) : '')).flat() ) ].filter(v=>v!='').sort(),
268+
// ^ See issue #1997 for more info on why this is commented out
269+
'programs': [...new Set(sortedProjectData.map(item => item.project.programAreas ? item.project.programAreas.map(programArea => programArea) : '').flat() ) ].filter(v=>v!='').sort(),
270+
'technologies': [...new Set(sortedProjectData.map(item => (item.project.technologies?.length > 0) ? [item.project.technologies].flat() : '').flat() ) ].filter(v=>v!='').sort(),
271+
'languages': [...new Set(sortedProjectData.map(item => (item.project.languages?.length > 0) ? [item.project.languages].flat() : '').flat())].filter(v => v != '').sort(),
272+
'tools': [...new Set(sortedProjectData.map(item => (item.project.tools?.length > 0) ? [item.project.tools].flat() : '').flat() ) ].filter(v=>v!='').sort(),
273+
'status': [... new Set(sortedProjectData.map(item => item.project.status))].sort()
274+
}
275+
}
276+
}
277+
228278
/**
229279
* Update the history state and the url parameters on checkbox changes
230280
*/
@@ -879,4 +929,10 @@ function attachEventListenerCloseModal() {
879929
modal.style.display = 'none';
880930
}
881931
});
932+
}
933+
934+
if (typeof module !== 'undefined' && module.exports) {
935+
module.exports = {
936+
createFilter, projectDataSorter,
937+
};
882938
}

assets/js/utility/vrms-events-utils.mjs

Lines changed: 0 additions & 21 deletions
This file was deleted.

assets/js/utility/vrms-events.mjs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
---
22
---
33

4-
import { filterTestEvents, sortEventsByDate } from "./vrms-events-utils.mjs";
5-
64
{% assign vrmsData = site.data.external.vrms_data %}
75
const vrmsData = JSON.parse(decodeURIComponent("{{ vrmsData | jsonify | uri_escape }}"));
86

@@ -20,6 +18,28 @@ export const vrmsDataFetch = (currentPage, appendMeetingTimes) => {
2018
}
2119
}
2220

21+
/**
22+
* Sorts an array of events by their "startTime" variable, from oldest to newest
23+
*/
24+
export function sortEventsByDate(events) {
25+
return events.sort((event1, event2) => {
26+
// startTime includes date information
27+
const date1 = new Date(event1.startTime);
28+
const date2 = new Date(event2.startTime);
29+
return date1 - date2;
30+
});
31+
}
32+
33+
/**
34+
* Filters an array of events to remove instances of events with names containing
35+
* "test" or "testing, case insensitive
36+
*/
37+
export function filterTestEvents(events) {
38+
return events.filter(event => {
39+
return !(/\btest(ing)?\b/i.test(event.name))
40+
});
41+
}
42+
2343
/**
2444
* @param {Date} time - A valid javscript time string. Example: "2020-05-13T02:00:00.000Z"
2545
* @return {String} - A time string formatted in the 12 hour format and converted to your timezone. Example: "10:00 pm"

0 commit comments

Comments
 (0)