From f30a0d8a80c58eaa7ae68a2d10561732c8670c06 Mon Sep 17 00:00:00 2001 From: "konstantina.galouni" Date: Fri, 4 Jun 2021 09:36:06 +0000 Subject: [PATCH] [Trunk | Admin Tools]: update_db.js: a. In function addPiwik(), add new communities (galaxy, gortriple, neanias-underwater, pending piwik: embrc). b. New functions for footer divId & div helptexts (connect & communities): addFooterDivIdForConnect(), addFooterDivIdForCommunities(), addFooterHelpTextForConnect(), addFooterHelpTextForCommunities(). --- update_db.js | 137 ++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 131 insertions(+), 6 deletions(-) diff --git a/update_db.js b/update_db.js index 64b9caf..38216ce 100644 --- a/update_db.js +++ b/update_db.js @@ -1717,6 +1717,122 @@ function addPiwik() { db.portal.update({"pid": "covid-19"}, {$set: {piwik:"267"}}); db.portal.update({"pid": "rural-digital-europe"}, {$set: {piwik:"319"}}); db.portal.update({"pid": "enermaps"}, {$set: {piwik:"318"}}); + + db.portal.update({"pid": "galaxy"}, {$set: {piwik:"453"}}); + db.portal.update({"pid": "gotriple"}, {$set: {piwik:"490"}}); + db.portal.update({"pid": "neanias-underwater"}, {$set: {piwik:"474"}}); + // db.portal.update({"pid": "embrc"}, {$set: {piwik:"474"}}); +} + +// 03-06-2021 +function addFooterDivIdForConnect() { + connectHomePageID = db.page.find({"portalType": "connect", "route": "/"}).map( function(page) { return page._id.str; } ).toString(); + db.divId.save({ "name" : "footer", "pages" : [ connectHomePageID ], "portalType" : "connect" }); + print("divId 'footer' added for connect (home page id: "+connectHomePageID + ")"); +} + +function addFooterDivIdForCommunities() { + // db.page.save({ "route" : "/", "name" : "Home", "type" : "other", "entities" : [ ], "portalType" : "community", "top" : false, "bottom" : false, "left" : false, "right" : false }); + // print("page 'Home' added for communities"); + addHomePageInCommunities(); + + communityHomePageID = db.page.find({"portalType": "community", "route": "/"}).map( function(community) { return community._id.str; } ).toString(); + db.divId.save({ "name" : "footer", "pages" : [ communityHomePageID ], "portalType" : "community" }); + print("divId 'footer' added for communities (home page id: "+communityHomePageID + ")"); +} + +function addHomePageInCommunities() { + communityHomePageID = db.page.insertOne({ "route" : "/", "name" : "Home", "type" : "other", "entities" : [ ], "portalType" : "community", "top" : false, "bottom" : false, "left" : false, "right" : false }).insertedId.str; + print("Creating Home page with id " + communityHomePageID); + communities = db.portal.find({"type": "community"}).map( function(community) { return community; } ); + for (var i = 0; i < communities.length; i++) { + community_pages = communities[i].pages; + + community_pages[communityHomePageID] = true; + + community_pid = communities[i].pid; + db.community.update({ "pid" : community_pid },{$set: { "pages": community_pages}}); + print("Add home page with id " + communityHomePageID + " on community " + community_pid); + } +} + +function addFooterHelpTextForConnect() { + connectID = db.portal.find({ "pid" : "connect"}).map( function(portal) { return portal._id.str; } ).toString(); + connectFooterDivIdID = db.divId.find({"portalType": "connect", "name": "footer"}).map( function(divId) { return divId._id.str; } ).toString(); + + db.divHelpContent.save( + { "divId" : connectFooterDivIdID, + "portal" : connectID, + "content" : "

" + + "OpenAIRE has received funding from the European Union's Horizon 2020 research and innovation programme under grant agreements No. 777541, 731011 and 101017452" + + "

", + "isActive" : true + } + ); + + print("div help text for divId 'footer' added for connect (connect id: "+ connectID + " - footer divId id: "+connectFooterDivIdID + ")"); +} + +function addFooterHelpTextForCommunities() { + communityFooterDivIdID = db.divId.find({"portalType": "community", "name": "footer"}).map( function(divId) { return divId._id.str; } ).toString(); + + communities = db.portal.find({"type": "community"}).map( function(community) { return community; } ); + for (var j = 0; j < communities.length; j++) { + community = communities[j]; + + var content = "OpenAIRE has received funding from the European Union's Horizon 2020 research and innovation programme under grant agreements No. 777541, 731011 and 101017452"; + + if(community.pid == "aginfra" || community.pid == "rural-digital-europe") { + content = "This OpenAIRE gateway is part of a project that has received funding from the European Union's Horizon 2020 research and innovation programme under grant agreements No. 777541, 731011 and 101017452"; + + } else if(community.pid == "clarin" || community.pid == "covid-19" || community.pid == "dariah" + || community.pid == "dh-ch" || community.pid == "egi" || community.pid == "mes" || community.pid == "epos" + || community.pid == "elixir-gr" || community.pid == "fam" || community.pid == "ni" + || community.pid == "sdsn-gr" || community.pid == "instruct" || community.pid == "instruct" + || community.pid == "rda" || community.pid == "gotriple") { + + content = "This OpenAIRE gateway is part of a project that has received funding from the European Union's Horizon 2020 research and innovation programme under grant agreements No. 777541, 731011 and 101017452"; + + } else if(community.pid == "enermaps") { + content = "This OpenAIRE gateway is part of a project that has received funding from the European Union's Horizon 2020 research and innovation programme under grant agreements No. 777541, 731011, 101017452 and 884161"; + + } else if(community.pid == "beopen") { + content = "This OpenAIRE gateway is part of a project that has received funding from the European Union's Horizon 2020 research and innovation programme under grant agreements No. 777541, 731011, 101017452 and 824323"; + + } else if(community.pid == "risis" || community.pid == "science-innovation-policy") { + content = "This OpenAIRE gateway is part of a project that has received funding from the European Union's Horizon 2020 research and innovation programme under grant agreements No. 777541, 731011, 101017452 and 824091"; + } + + db.divHelpContent.save( + { "divId" : communityFooterDivIdID, + "portal" : community._id.str, + "content" : "

"+content+"

", + "isActive" : true + } + ); + + print("div help text for divId 'footer' added for community (community id: "+ community._id + " - community pid: " + community.pid + " - footer divId id: "+communityFooterDivIdID + ")"); + } +} + +// 04-06-2021 debug helper function +function cleanPagesFromPortals() { + portals = db.portal.find().map( function(portal) { return portal; } ); + for (var j = 0; j < portals.length; j++) { + portal = portals[j]; + portal_pages = portal.pages; + + for (var key in portal_pages) { + // print(key); + // db.page.findOne({"_id": ObjectId(+'"'+key+'"')}); + if(db.page.find({"_id": ObjectId(key)}).map( function(page) { return page; } ).length == 0) { + delete portal_pages[key]; + print("deleted page: "+key + " from portal: "+portal.pid); + } + } + portal_pid = portal.pid; + db.portal.update({ "pid" : portal_pid },{$set: { "pages": portal_pages}}); + } } use openaireconnect; @@ -1786,11 +1902,20 @@ use openaireconnect; //addSearchResearchOutcomesPages(); // 02-02-2020 - 19-03-2020 -addPortalType(); -createPagesForEachPortalType(); -createDivIdsForEachPortalType(); -renameCollectionAndFields(); -addPortalPidInLayoutRecords(); +// addPortalType(); +// createPagesForEachPortalType(); +// createDivIdsForEachPortalType(); +// renameCollectionAndFields(); +// addPortalPidInLayoutRecords(); // 22-10-2020 -// addPiwik(); \ No newline at end of file +// addPiwik(); + +// 03-06-2021 +addFooterDivIdForConnect(); +addFooterDivIdForCommunities(); +addFooterHelpTextForConnect(); +addFooterHelpTextForCommunities(); + +// 04-06-2021 debug helper function +// cleanPagesFromPortals(); \ No newline at end of file