Skip to content

Commit

Permalink
poc
Browse files Browse the repository at this point in the history
  • Loading branch information
masimons committed Sep 14, 2024
1 parent 07fd699 commit f9aea32
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 7 deletions.
28 changes: 25 additions & 3 deletions packages/client/src/components/GrantsTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ import GrantDetailsLegacy from '@/components/Modals/GrantDetailsLegacy.vue';
import SearchPanel from '@/components/Modals/SearchPanel.vue';
import SavedSearchPanel from '@/components/Modals/SavedSearchPanel.vue';
import SearchFilter from '@/components/SearchFilter.vue';
// import moment from 'moment';
const DEFAULT_CURRENT_PAGE = 1;
const DEFAULT_ORDER_BY = 'rank';
Expand Down Expand Up @@ -279,6 +280,27 @@ export default {
txt.innerHTML = t;
return txt.value;
};
const generateCloseDate = (date, status, close_date_explanation) => {

Check failure on line 283 in packages/client/src/components/GrantsTable.vue

View workflow job for this annotation

GitHub Actions / qa / Lint JavaScript

Identifier 'close_date_explanation' is not in camel case
const formattedDate = new Date(date).toLocaleDateString('en-US', { timeZone: 'UTC' });
if (['posted'].includes(status) && !date) {
return 'Not yet issued';
} if (status === 'forecasted') {
if (date) {
return `est. ${formattedDate}`;
} if (close_date_explanation) {

Check failure on line 290 in packages/client/src/components/GrantsTable.vue

View workflow job for this annotation

GitHub Actions / qa / Lint JavaScript

Identifier 'close_date_explanation' is not in camel case
return 'See details';
}
return 'Not yet issued';
}
return formattedDate;
};
const generateOpenDate = (date, status) => {
const formattedDate = new Date(date).toLocaleDateString('en-US', { timeZone: 'UTC' });
if (status === 'forecasted') {
return `est. ${formattedDate}`;
}
return formattedDate;
};
return this.grants.map((grant) => ({
...grant,
title: generateTitle(grant.title),
Expand All @@ -288,10 +310,10 @@ export default {
viewed_by: grant.viewed_by_agencies
.map((v) => v.agency_abbreviation)
.join(', '),
status: grant.opportunity_status,
status: titleize(grant.opportunity_status),
award_ceiling: grant.award_ceiling,
open_date: new Date(grant.open_date).toLocaleDateString('en-US', { timeZone: 'UTC' }),
close_date: new Date(grant.close_date).toLocaleDateString('en-US', { timeZone: 'UTC' }),
open_date: generateOpenDate(grant.open_date, grant.opportunity_status?.toLowerCase()),
close_date: generateCloseDate(grant.close_date, grant.opportunity_status?.toLowerCase(), grant.close_date_explanation),
_cellVariants: (() => {
const daysUntilClose = daysUntil(grant.close_date);
if (daysUntilClose <= dangerThreshold) {
Expand Down
3 changes: 2 additions & 1 deletion packages/client/src/components/Modals/SearchPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ const defaultCriteria = {
includeKeywords: null,
excludeKeywords: null,
opportunityNumber: null,
opportunityStatuses: ['posted'],
opportunityStatuses: ['forecasted', 'posted'],
fundingTypes: null,
agency: null,
bill: null,
Expand Down Expand Up @@ -310,6 +310,7 @@ export default {
{ code: 'O', name: 'Other' },
],
opportunityStatusOptions: [
{ text: 'Forecasted', value: 'forecasted' },
{ text: 'Posted', value: 'posted' },
// b-form-checkbox-group doesn't handle multiple values well 'archived' is added
// whenever 'closed' is checked, but as post processing step. See apply()
Expand Down
5 changes: 3 additions & 2 deletions packages/client/src/store/modules/grants.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ function buildGrantsNextQuery({ filters, ordering, pagination }) {
criteria.fundingActivityCategories = criteria.fundingActivityCategories?.map((c) => c.code);

if (!criteria.opportunityStatuses || criteria.opportunityStatuses.length === 0) {
// by default, only show posted opportunities
criteria.opportunityStatuses = ['posted'];
// by default, only show forecasted and posted opportunities
criteria.opportunityStatuses = ['forecasted', 'posted'];
}
const paginationQuery = Object.entries(pagination)
// filter out undefined and nulls since api expects parameters not present as undefined
Expand Down Expand Up @@ -145,6 +145,7 @@ export default {
const filters = { ...this.state.grants.searchFormFilters };
const { criteriaQuery, paginationQuery, orderingQuery } = buildGrantsNextQuery({ filters, ordering, pagination });

// this is the call to (initially) populate the table
return fetchApi.get(`/api/organizations/${rootGetters['users/selectedAgencyId']}/grants/next?${paginationQuery}&${orderingQuery}&${criteriaQuery}`)
.then((data) => commit('SET_GRANTS', data));
},
Expand Down
16 changes: 15 additions & 1 deletion packages/client/src/views/GrantDetailsView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ export default {
value: this.currentGrant.grant_number,
}, {
name: 'Open Date',
value: this.formatDate(this.currentGrant.open_date),
value: this.openDateDisplay,
}, {
name: 'Close Date',
value: this.closeDateDisplay,
Expand Down Expand Up @@ -374,10 +374,24 @@ export default {
},
];
},
openDateDisplay() {
// make 'forecasted' a constant
if (this.currentGrant.opportunity_status === 'forecasted') {
// change this.currentGrant.open_date to relevant field
// check for date validity here and in closeDateDisplay
return `est. ${this.formatDate(this.currentGrant.open_date)}`;
}
return this.formatDate(this.currentGrant.open_date);
},
closeDateDisplay() {
// If we have an explainer text instead of a real close date, display that instead
if (this.currentGrant.close_date === FAR_FUTURE_CLOSE_DATE) {
return this.currentGrant.close_date_explanation ?? NOT_AVAILABLE_TEXT;
} if (this.currentGrant.opportunity_status === 'forecasted') { // what if we check for posted status as well?
if (!this.currentGrant.close_date) {
return this.currentGrant.close_date_explanation ? this.currentGrant.close_date_explanation : 'Not yet issued';
}
return `est. ${this.formatDate(this.currentGrant.close_date)}`;
}
return this.formatDate(this.currentGrant.close_date);
},
Expand Down
3 changes: 3 additions & 0 deletions packages/server/src/db/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,7 @@ function addCsvData(qb) {
agencyId: number
*/
async function getGrantsNew(filters, paginationParams, orderingParams, tenantId, agencyId, toCsv) {
// get grants for grants table
console.log(JSON.stringify([filters, paginationParams, orderingParams, tenantId, agencyId, toCsv]));

const errors = validateSearchFilters(filters);
Expand All @@ -732,6 +733,7 @@ async function getGrantsNew(filters, paginationParams, orderingParams, tenantId,
'grants.cfda_list',
'grants.open_date',
'grants.close_date',
'grants.close_date_explanation',
'grants.archive_date',
'grants.reviewer_name',
'grants.opportunity_category',
Expand All @@ -753,6 +755,7 @@ async function getGrantsNew(filters, paginationParams, orderingParams, tenantId,
CASE
WHEN grants.archive_date <= now() THEN 'archived'
WHEN grants.close_date <= now() THEN 'closed'
WHEN grants.open_date > now() THEN 'forecasted'
ELSE 'posted'
END as opportunity_status
`))
Expand Down
7 changes: 7 additions & 0 deletions packages/server/src/lib/grants-ingest.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ function mapSourceDataToGrant(source) {
grant.opportunity_status = 'archived';
} else if (today.isSameOrAfter(moment(grant.close_date), 'date')) {
grant.opportunity_status = 'closed';
} else if (today.isBefore(moment(grant.open_date), 'date')) {
// depending on how we model the estimated open date, we may need to do the
// date comparison with the new field for estimated date
grant.opportunity_status = 'forecasted'
// Note: in the knex query, we are deriving the status based on
// archive_date and close_date. Probably we just want to pass
// the opportunity_status to the frontend, and not re-derive it here?
} else {
grant.opportunity_status = 'posted';
}
Expand Down
2 changes: 2 additions & 0 deletions packages/server/src/routes/grants.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ router.get('/', requireUser, async (req, res) => {
});

function criteriaToFiltersObj(criteria, agencyId) {
// this function makes request to populate grants table
const filters = criteria || {};
const postedWithinOptions = {
'All Time': 0, 'One Week': 7, '30 Days': 30, '60 Days': 60,
Expand All @@ -66,6 +67,7 @@ function criteriaToFiltersObj(criteria, agencyId) {
}

router.get('/next', requireUser, async (req, res) => {
// api call to populate table
const { user } = req.session;

let orderingParams;
Expand Down

0 comments on commit f9aea32

Please sign in to comment.