Skip to content

Commit

Permalink
DES-2626: NCO TTC Updates (#1368)
Browse files Browse the repository at this point in the history
* next batch of nco ttc grants page updates

* removing category filter, adding subjects as keywords to details modal

* updating button styles

* fixing bug in abstract details modal

* adding pi name to the text field search
  • Loading branch information
SilversunKSauri authored Jul 30, 2024
1 parent d6bf8a9 commit 41839ff
Show file tree
Hide file tree
Showing 10 changed files with 193 additions and 63 deletions.
12 changes: 10 additions & 2 deletions designsafe/apps/nco/api_urls.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
from django.urls import re_path as url
from designsafe.apps.nco.views import ProjectsListView, FiltersListView, TtcGrantsView, TtcFacilitiesView, TtcCategoriesView
from designsafe.apps.nco.views import (
ProjectsListView,
FiltersListView,
TtcGrantsView,
TtcFacilitiesView,
TtcGrantTypesView,
TtcHazardTypesView,
)

"""
REST API URLS.
Expand All @@ -10,5 +17,6 @@
url(r'filters', FiltersListView.as_view(), name='filters_list'),
url(r'ttc_grants', TtcGrantsView.as_view(), name='ttc_grants_list'),
url(r'ttc_facilities', TtcFacilitiesView.as_view(), name='ttc_facilities_list'),
url(r'ttc_categories', TtcCategoriesView.as_view(), name='ttc_categories_list'),
url(r'ttc_grant_types', TtcGrantTypesView.as_view(), name='ttc_grant_types_list'),
url(r'ttc_hazard_types', TtcHazardTypesView.as_view(), name='ttc_hazard_types_list'),
]
33 changes: 23 additions & 10 deletions designsafe/apps/nco/managers/ttc_grants.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,39 @@ def __init__(self, user):

self._mttc = MongoTTCHelper(self._ac)

def ttc_grants(self, facility=None, category=None, sort=None):
def ttc_grants(self, params=None):
"""Return ttc grants list."""
query = {}

#turn facility and category selection into query
if facility:
query['NheriFacility'] = facility
if category:
query['Category'] = category
if params['facility']:
query['NheriFacility'] = params['facility']
if params['hazard_type']:
query['Hazard'] = params['hazard_type']
if params['grant_type']:
query['Type'] = params['grant_type']
if params['text_search']:
query['$or'] = [
{'Title': {'$regex': params['text_search']}},
{'Abstract': {'$regex': params['text_search']}},
{'PiName': {'$regex': params['text_search']}},
]

#get the grants list
grants = [grant for grant in self._mttc.get_ttc_grants(query=query,sort=sort)]
grants = [grant for grant in self._mttc.get_ttc_grants(query=query,sort=params['sort'])]
return grants

def ttc_facilities(self):
"""Return list of distinct facilities in ttc_grant collection"""
facilities = [facility for facility in self._mttc.get_ttc_facilities()]
return facilities

def ttc_categories(self):
"""Return list of categories in ttc_grant_filters collection"""
categories = [category for category in self._mttc.get_ttc_categories()]
return categories
def ttc_hazard_types(self):
"""Return list of hazard types in ttc_grant collection"""
hazard_types = [hazard_type for hazard_type in self._mttc.get_ttc_hazard_types()]
return hazard_types

def ttc_grant_types(self):
"""return list of grant types in ttc_grant collection"""
grant_types = [grant_type for grant_type in self._mttc.get_ttc_grant_types()]
return grant_types
15 changes: 13 additions & 2 deletions designsafe/apps/nco/templates/designsafe/apps/nco/ttc_grants.j2
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,19 @@ NHERI Facilities Scheduling Dashbaord
<!-- PAGE INTRO ROW -->
<div class="top-row ttc-intro">
<!-- TTC INTRO -->
<h1>NHERI Grants</h1>
These are grants the NCO identified as being related to NHERI projects.
<h1>NHERI Grant Research</h1>
Search for NSF-funded research awards that employ one or more NHERI resources.
<br />
The NCO Technology Transfer Committee maintains this database as a way for potential users
of NHERI research and other researchers to discover cognate investigations conducted within the NHERI network.
<br /><br />
Questions? Contact the NCO Technology Transfer Committee [[email protected]].
<ul>
<li><a href="https://www.designsafe-ci.org/community/ttc/" target=”_blank”>TTC Webpage</a></li>
<li>Contact TTC: [email protected]</li>
<li><a href="https://www.designsafe-ci.org/nco/scheduler/" target=”_blank”>NHERI Scheduler Database</a></li>
<li><a href="https://www.designsafe-ci.org/news/" target=”_blank”>NHERI News</a></li>
</ul>
</div>
<hr class="top-line"/>

Expand Down
20 changes: 18 additions & 2 deletions designsafe/apps/nco/views/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
from designsafe.apps.nco.views.base import NcoIndexView, NcoTtcGrantsView
from designsafe.apps.nco.views.api import ProjectsListView, FiltersListView, TtcGrantsView, TtcFacilitiesView, TtcCategoriesView
from designsafe.apps.nco.views.api import (
ProjectsListView,
FiltersListView,
TtcGrantsView,
TtcFacilitiesView,
TtcGrantTypesView,
TtcHazardTypesView,
)

__all__ = ["NcoIndexView", "ProjectsListView", "FiltersListView", "NcoTtcGrantsView", "TtcGrantsView", "TtcFacilitiesView", "TtcCategoriesView"]
__all__ = [
"NcoIndexView",
"ProjectsListView",
"FiltersListView",
"NcoTtcGrantsView",
"TtcGrantsView",
"TtcFacilitiesView",
"TtcGrantTypesView",
"TtcHazardTypesView",
]
34 changes: 28 additions & 6 deletions designsafe/apps/nco/views/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,20 @@ def get(self,request):
"""Return a list of all TTC Grants."""
ttc_mgr = NcoTtcGrantsManager(request.user)
facility = request.GET.get('facility')
category = request.GET.get('category')
sort = request.GET.get('sort')
grants = ttc_mgr.ttc_grants(facility,category,sort)
hazard_type = request.GET.get('hazard_type')
grant_type = request.GET.get('grant_type')
text_search = request.GET.get('text_search')

params = {
'facility': facility,
'sort': sort,
'hazard_type': hazard_type,
'grant_type': grant_type,
'text_search': text_search,
}

grants = ttc_mgr.ttc_grants(params)
return MongoJsonResponse({
"status": "OK",
"response": grants,
Expand All @@ -94,13 +105,24 @@ def get(self,request):
"response": facilities,
})

class TtcCategoriesView(BaseApiView):
"""NCO TTC Grants Facilities View."""
class TtcGrantTypesView(BaseApiView):
"""NCO TTC Grant Types View."""

def get(self,request):
ttc_mgr = NcoTtcGrantsManager(request.user)
categories = ttc_mgr.ttc_categories()
grant_types = ttc_mgr.ttc_grant_types()
return MongoJsonResponse({
"status": "OK",
"response": categories,
"response": grant_types,
})

class TtcHazardTypesView(BaseApiView):
"""NCO TTC Hazard Types View."""

def get(self,request):
ttc_mgr = NcoTtcGrantsManager(request.user)
hazard_types = ttc_mgr.ttc_hazard_types()
return MongoJsonResponse({
"status": "OK",
"response": hazard_types,
})
24 changes: 18 additions & 6 deletions designsafe/libs/mongo/load_ttc_grants.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,12 @@ def get_ttc_grants(self, query=None, sort=None):

#set sorting option
final_sort = []
if sort == "Start Date Descending":
final_sort = [('StartDate', DESCENDING)]
elif sort == "Start Date Ascending":
final_sort = [('StartDate', ASCENDING)]
elif sort == "End Date Descending":
if sort == "End Date Descending":
final_sort = [('EndDate', DESCENDING)]
elif sort == "End Date Ascending":
final_sort = [('EndDate', ASCENDING)]
else:
final_sort = [('StartDate', DESCENDING)]
final_sort = [('EndDate', DESCENDING)]

mongo_db = self._mc[getattr(settings, 'MONGO_DB', 'scheduler')]
cursor = mongo_db.ttc_grant.find(query).sort(final_sort)
Expand All @@ -84,3 +80,19 @@ def get_ttc_categories(self):
results = list(cursor)
for category in results:
yield category['name']

def get_ttc_hazard_types(self):
"""Get unique hazard type from the ttc grants db"""
mongo_db = self._mc[getattr(settings, 'MONGO_DB', 'scheduler')]
cursor = mongo_db.ttc_grant.distinct('Hazard')
results = list(cursor)
for hazard_type in results:
yield hazard_type

def get_ttc_grant_types(self):
"""Get unique grant type from the ttc grants db"""
mongo_db = self._mc[getattr(settings, 'MONGO_DB', 'scheduler')]
cursor = mongo_db.ttc_grant.distinct('Type')
results = list(cursor)
for grant_type in results:
yield grant_type
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,15 @@ <h4 class="modal-title">Grant Details</h4>
</span>
</div>
<div class="ttc-data">Grant Org: {{$ctrl.grant.Org}}</div>
<div class="ttc-data" ng-if="$ctrl.grant.NheriFacility">NHERI Facility: {{grant.NheriFacility}}</div>
<div class="ttc-data" ng-if="$ctrl.grant.NheriFacility">NHERI Facility: {{$ctrl.grant.NheriFacility}}</div>
<div class="ttc-data" ng-if="!$ctrl.grant.NheriFacility">NHERI Facility: No Facility Listed</div>
<div class="ttc-data">Hazard Type: {{$ctrl.grant.Hazard}}</div>
<div class="ttc-data">Grant Type: {{$ctrl.grant.Type}}</div>
<div class="ttc-data">Keywords:
<ul>
<li ng-repeat="keyword in $ctrl.grant.Subjects">{{keyword}}</li>
</ul>
</div>
<hr />
<div>
Abstract:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ class NcoTtcGrantsCtrl {

$onInit() {
this.initialParams = {
sort: 'Start Date Descending',
sort: 'End Date Descending',
};
// default intitial sorting
this.selectedSort = 'Start Date Descending';
this.selectedSort = 'End Date Descending';
this._ui = {
grantsLoading: true,
facilitiesLoading: false,
categoriesLoading: false,
grantTypesLoading: false,
hazardTypesLoading: false,
};

this.loadGrants(this.initialParams)
Expand All @@ -39,18 +40,25 @@ class NcoTtcGrantsCtrl {
this._ui.facilitiesLoading = false;
});

this.loadCategories({})
.then((resp) => {
return resp;
}, (err) => {
this._ui.categoriesError = err.message;
}).finally( () => {
this._ui.categoriesLoading = false;
});
this.loadGrantTypes({})
.then((resp) => {
return resp;
}, (err) => {
this._ui.grantTypesError = err.message;
}).finally( () => {
this._ui.grantTypesLoading = false;
});

this.loadHazardTypes({})
.then((resp) => {
return resp;
}, (err) => {
this._ui.hazardTypesError = err.message;
}).finally( () => {
this._ui.hazardTypesLoading = false;
});

this.sortOptions = [
"Start Date Descending",
"Start Date Ascending",
"End Date Descending",
"End Date Ascending",
];
Expand Down Expand Up @@ -86,19 +94,33 @@ class NcoTtcGrantsCtrl {
});
}

loadCategories(){
this._ui.categoriesLoading = true;
return this.$http.get('/nco/api/ttc_categories')
loadGrantTypes(){
this._ui.grantTypesLoading = true;
return this.$http.get('/nco/api/ttc_grant_types')
.then((resp) => {
this.grantTypes = _.map(
resp.data.response,
);
return this.grantTypes;
}, (err) => {
this._ui.grantTypesError = err.message;
}).finally ( () => {
this._ui.grantTypesLoading = false;
});
}

loadHazardTypes(){
this._ui.hazardTypesLoading = true;
return this.$http.get('/nco/api/ttc_hazard_types')
.then((resp) => {
this.categoriesList = _.map(
this.hazardTypes = _.map(
resp.data.response,
);
console.log(this.categoriesList);
return this.categoriesList;
return this.hazardTypes;
}, (err) => {
this._ui.categoriesError = err.message;
this._ui.hazardTypesError = err.message;
}).finally ( () => {
this._ui.categoriesLoading = false;
this._ui.hazardTypesLoading = false;
});
}

Expand All @@ -116,8 +138,10 @@ class NcoTtcGrantsCtrl {
filterSearch(){
var params = {
facility: this.selectedFacility,
category: this.selectedCategory,
sort: this.selectedSort,
hazard_type: this.selectedHazardType,
grant_type: this.selectedGrantType,
text_search: this.textSearch,
};
this.loadGrants(params);
}
Expand Down
Loading

0 comments on commit 41839ff

Please sign in to comment.