Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/des-2490-nco' into dev-20221212
Browse files Browse the repository at this point in the history
  • Loading branch information
Jake Rosenberg authored and Jake Rosenberg committed Dec 12, 2023
2 parents 9d4ef94 + b532b86 commit f1ab8ff
Show file tree
Hide file tree
Showing 10 changed files with 116 additions and 29 deletions.
3 changes: 2 additions & 1 deletion designsafe/apps/nco/api_urls.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.urls import re_path as url
from designsafe.apps.nco.views import ProjectsListView, FiltersListView, TtcGrantsView, TtcFacilitiesView
from designsafe.apps.nco.views import ProjectsListView, FiltersListView, TtcGrantsView, TtcFacilitiesView, TtcCategoriesView

"""
REST API URLS.
Expand All @@ -10,4 +10,5 @@
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'),
]
13 changes: 10 additions & 3 deletions designsafe/apps/nco/managers/ttc_grants.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ def __init__(self, user):

self._mttc = MongoTTCHelper(self._ac)

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

#turn facility selection into query
#turn facility and category selection into query
if facility:
query = { 'NheriFacility' : facility }
query['NheriFacility'] = facility
if category:
query['Category'] = category

#get the grants list
grants = [grant for grant in self._mttc.get_ttc_grants(query=query,sort=sort)]
Expand All @@ -48,3 +50,8 @@ 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
4 changes: 2 additions & 2 deletions designsafe/apps/nco/views/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from designsafe.apps.nco.views.base import NcoIndexView, NcoTtcGrantsView
from designsafe.apps.nco.views.api import ProjectsListView, FiltersListView, TtcGrantsView, TtcFacilitiesView
from designsafe.apps.nco.views.api import ProjectsListView, FiltersListView, TtcGrantsView, TtcFacilitiesView, TtcCategoriesView

__all__ = ["NcoIndexView", "ProjectsListView", "FiltersListView", "NcoTtcGrantsView", "TtcGrantsView", "TtcFacilitiesView"]
__all__ = ["NcoIndexView", "ProjectsListView", "FiltersListView", "NcoTtcGrantsView", "TtcGrantsView", "TtcFacilitiesView", "TtcCategoriesView"]
16 changes: 14 additions & 2 deletions designsafe/apps/nco/views/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,9 @@ 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,sort)
grants = ttc_mgr.ttc_grants(facility,category,sort)
return MongoJsonResponse({
"status": "OK",
"response": grants,
Expand All @@ -91,4 +92,15 @@ def get(self,request):
return MongoJsonResponse({
"status": "OK",
"response": facilities,
})
})

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

def get(self,request):
ttc_mgr = NcoTtcGrantsManager(request.user)
categories = ttc_mgr.ttc_categories()
return MongoJsonResponse({
"status": "OK",
"response": categories,
})
8 changes: 8 additions & 0 deletions designsafe/libs/mongo/load_ttc_grants.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,11 @@ def get_ttc_facilities(self):
results = list(cursor)
for facility in results:
yield facility

def get_ttc_categories(self):
"""Get ttc categories in the ttc grants filters table"""
mongo_db = self._mc[getattr(settings, 'MONGO_DB', 'scheduler')]
cursor = mongo_db.ttc_grant_categories.find()
results = list(cursor)
for category in results:
yield category['name']
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class TtcAbstractModalCtrl {
}

$onInit() {
this.abstract = this.resolve.abstract;
this.grant = this.resolve.grant;
}

close() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,32 @@
<div class="modal-header">
<h4 class="modal-title">Abstract</h4>
<h4 class="modal-title">Grant Details</h4>
</div>
<div class="modal-body">
<p>
{{ $ctrl.abstract }}
</p>
<div class="ttc-data">Title: {{$ctrl.grant.Title}}</div>
<div class="ttc-data">
Award Number:
<a href="https://www.nsf.gov/awardsearch/showAward?AWD_ID={{grant.AwardNumber}}">
{{$ctrl.grant.AwardNumber}}
</a>
</div>
<div class="ttc-data">Start Date: {{$ctrl.grant.StartDate.$date | date}}</div>
<div class="ttc-data">End Date: {{$ctrl.grant.EndDate.$date | date}}</div>
<div class="ttc-data">
PI: {{$ctrl.grant.PiName}}
<span ng-if="$ctrl.grant.CoPiNames">
<br/>
Co-PI(s): {{$ctrl.grant.CoPiNames}}
</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: No Facility Listed</div>
<hr />
<div>
Abstract:
<br />
{{ $ctrl.grant.Abstract }}
</div>
</div>
<div class="modal-footer">
<button class="btn btn-info btn-sm pull-right" ng-click="$ctrl.close()">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,18 @@ class NcoTtcGrantsCtrl {
}

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

this.loadGrants()
this.loadGrants(this.initialParams)
.then((resp) => {
return resp;
}, (err) => {
Expand All @@ -33,6 +39,15 @@ class NcoTtcGrantsCtrl {
this._ui.facilitiesLoading = false;
});

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

this.sortOptions = [
"Start Date Descending",
"Start Date Ascending",
Expand Down Expand Up @@ -71,11 +86,28 @@ class NcoTtcGrantsCtrl {
});
}

showAbstract(abstract) {
loadCategories(){
this._ui.categoriesLoading = true;
return this.$http.get('/nco/api/ttc_categories')
.then((resp) => {
this.categoriesList = _.map(
resp.data.response,
);
console.log(this.categoriesList);
return this.categoriesList;
}, (err) => {
this._ui.categoriesError = err.message;
}).finally ( () => {
this._ui.categoriesLoading = false;
});
}

//view details
showAbstract(grant) {
this.$uibModal.open({
component: 'ncoTtcAbstract',
resolve: {
abstract: () => abstract
grant: () => grant
},
size: 'lg',
});
Expand All @@ -84,6 +116,7 @@ class NcoTtcGrantsCtrl {
filterSearch(){
var params = {
facility: this.selectedFacility,
category: this.selectedCategory,
sort: this.selectedSort,
};
this.loadGrants(params);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,25 @@
<div>Please make your selections and click the Search button to change the listing.</div>
<div class="ttc-search">
<form class="filter-group ttc-facility-filter">
<label for="ttc-facility-options">Filter by Facility:</label>
<label for="ttc-facility-options">Filter by Facility/Group:</label>
<select name="ttc-facility-options" ng-model="$ctrl.selectedFacility">
<option value="">--Filter by Facility--</option>
<option value="">All</option>
<option ng-repeat="facility in $ctrl.facilitiesList" value="{{facility}}">{{facility}}</option>
</select>
</form>
<form class="filter-group ttc-sort-filter">
<label for="ttc-sort-options">Sort by:</label>
<select name="ttc-sort-options" ng-model="$ctrl.selectedSort">
<option value="">--Sort Options--</option>
<option ng-repeat="sort in $ctrl.sortOptions" value="{{sort}}">{{sort}}</option>
</select>
</form>
<form class="filter-group ttc-category-filter">
<label for="ttc-category-options">Select a Category:</label>
<select name="ttc-category-options" ng-model="$ctrl.selectedCategory">
<option value="">All</option>
<option ng-repeat="category in $ctrl.categoriesList" value="{{category}}">{{category}}</option>
</select>
</form>
<div class="btn btn-default ttc-search-button" ng-click="$ctrl.filterSearch()">Search</div>
</div>
<!-- end search -->
Expand All @@ -35,30 +41,28 @@
<th class="ttc-data">End Date</th>
<th class="ttc-data">PI / Co-PI</th>
<th class="ttc-data">Grant Org</th>
<th class="ttc-data">Org State</th>
<th class="ttc-data">NHERI Facility</th>
<th class="ttc-data">Abstract</th>
<th class="ttc-data">Category/Labels</th>
<th class="ttc-data">Details</th>
</tr>
<!-- end header labels-->

<!-- list of grants -->
<tr class="ttc-row ttc-grant-item" ng-repeat="grant in $ctrl.grantList">
<td class="ttc-data">{{grant.AwardNumber}}</td>
<td class="ttc-data">
<a href="https://www.nsf.gov/awardsearch/showAward?AWD_ID={{grant.AwardNumber}}">
{{grant.AwardNumber}}
</a>
</td>
<td class="ttc-title ttc-data">{{grant.Title}}</td>
<td class="ttc-data">{{grant.StartDate.$date | date}}</td>
<td class="ttc-data">{{grant.EndDate.$date | date}}</td>
<td class="ttc-data">
{{grant.PiName}} <span ng-if="grant.CoPiNames"> / {{grant.CoPiNames}}</span>
</td>
<td class="ttc-data">{{grant.Org}}</td>
<td class="ttc-data ttc-org-state">{{grant.OrgState}}</td>
<td class="ttc-data" ng-if="grant.NheriFacility">{{grant.NheriFacility}}</td>
<td class="ttc-data" ng-if="!grant.NheriFacility">No Facility Listed</td>
<td class="ttc-abstract ttc-data btn btn-default" ng-click="$ctrl.showAbstract(grant.Abstract)">View</td>

<!-- this last one doesn't exist in the db yet so putting filler info for now -->
<td class="ttc-data">None</td>
<td class="ttc-abstract ttc-data btn btn-default" ng-click="$ctrl.showAbstract(grant)">View Details</td>
</tr>
</table>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
padding: 10px;
}

.ttc-facility-filter, .ttc-sort-filter {
.ttc-facility-filter, .ttc-sort-filter, .ttc-category-filter {
display: inline;
padding: 10px;
}
Expand Down

0 comments on commit f1ab8ff

Please sign in to comment.