11-- -
22
33-- -
4+
45// Do All Dom Manipulation After The DOM content is full loaded
56document . 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}
0 commit comments