Skip to content

Commit

Permalink
Merge branch 'main' into MET-task#1781
Browse files Browse the repository at this point in the history
  • Loading branch information
jadmsaadaot committed Jul 7, 2023
2 parents f76d643 + 0aba80e commit ebd2bbf
Show file tree
Hide file tree
Showing 12 changed files with 949 additions and 500 deletions.
65 changes: 50 additions & 15 deletions met-api/src/met_api/models/survey.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,47 @@ def get_surveys_paginated(cls, pagination_options: PaginationOptions,
query = db.session.query(Survey).join(Engagement, isouter=True).join(EngagementStatus, isouter=True)
query = cls._add_tenant_filter(query)

query = cls.filter_by_search_options(survey_search_options, query)

sort = asc(text(pagination_options.sort_key)) if pagination_options.sort_order == 'asc'\
else desc(text(pagination_options.sort_key))

query = query.order_by(sort)

no_pagination_options = not pagination_options.page or not pagination_options.size
if no_pagination_options:
items = query.all()
return items, len(items)

page = query.paginate(page=pagination_options.page, per_page=pagination_options.size)

return page.items, page.total

@classmethod
def filter_by_search_options(cls, survey_search_options: SurveySearchOptions, query):
"""Filter by search options."""
if survey_search_options.exclude_hidden:
query = query.filter(Survey.is_hidden.is_(False))

if survey_search_options.exclude_template:
query = query.filter(Survey.is_template.is_(False))

if survey_search_options.unlinked:
if survey_search_options.is_unlinked:
query = query.filter(Survey.engagement_id.is_(None))

if survey_search_options.is_linked:
query = query.filter(Survey.engagement_id.isnot(None))

if survey_search_options.is_hidden:
query = query.filter(Survey.is_hidden.is_(True))

if survey_search_options.is_template:
query = query.filter(Survey.is_template.is_(True))

query = cls._filter_by_created_date(query, survey_search_options)

query = cls._filter_by_published_date(query, survey_search_options)

# if role has access to view all engagements then include all surveys which are in ready status or
# surveys linked to draft and assigned engagements
if survey_search_options.can_view_all_engagements:
Expand All @@ -79,20 +111,7 @@ def get_surveys_paginated(cls, pagination_options: PaginationOptions,

if survey_search_options.search_text:
query = query.filter(Survey.name.ilike('%' + survey_search_options.search_text + '%'))

sort = asc(text(pagination_options.sort_key)) if pagination_options.sort_order == 'asc'\
else desc(text(pagination_options.sort_key))

query = query.order_by(sort)

no_pagination_options = not pagination_options.page or not pagination_options.size
if no_pagination_options:
items = query.all()
return items, len(items)

page = query.paginate(page=pagination_options.page, per_page=pagination_options.size)

return page.items, page.total
return query

@classmethod
def create_survey(cls, survey: SurveySchema) -> Survey:
Expand Down Expand Up @@ -166,3 +185,19 @@ def _filter_accessible_surveys(query, assigned_engagements: list[int]):
Survey.engagement_id.is_(None)]
query = query.filter(or_(*filter_conditions))
return query

@staticmethod
def _filter_by_created_date(query, search_options: SurveySearchOptions):
if search_options.created_date_from:
query = query.filter(Survey.created_date >= search_options.created_date_from)
if search_options.created_date_to:
query = query.filter(Survey.created_date <= search_options.created_date_to)
return query

@classmethod
def _filter_by_published_date(cls, query, search_options: SurveySearchOptions):
if search_options.published_date_from:
query = query.filter(Engagement.published_date >= search_options.published_date_from)
if search_options.published_date_to:
query = query.filter(Engagement.published_date <= search_options.published_date_to)
return query
14 changes: 11 additions & 3 deletions met-api/src/met_api/models/survey_search_options.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""This module holds data classes."""

from typing import List
from typing import List, Optional

from attr import dataclass


Expand All @@ -10,7 +11,14 @@ class SurveySearchOptions: # pylint: disable=too-many-instance-attributes

exclude_hidden: bool
exclude_template: bool
assigned_engagements: List[int] = None
assigned_engagements: Optional[List[int]] = None
search_text: str = ''
unlinked: bool = False
can_view_all_engagements: bool = True
is_unlinked: bool = False
is_linked: bool = False
is_hidden: bool = False
is_template: bool = False
created_date_from: Optional[str] = None
created_date_to: Optional[str] = None
published_date_from: Optional[str] = None
published_date_to: Optional[str] = None
9 changes: 8 additions & 1 deletion met-api/src/met_api/resources/survey.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,14 @@ def get():
exclude_hidden=args.get('exclude_hidden', False, bool),
exclude_template=args.get('exclude_template', False, bool),
search_text=args.get('search_text', '', str),
unlinked=args.get('unlinked', False, bool),
is_unlinked=args.get('is_unlinked', default=False, type=lambda v: v.lower() == 'true'),
is_linked=args.get('is_linked', default=False, type=lambda v: v.lower() == 'true'),
is_hidden=args.get('is_hidden', default=False, type=lambda v: v.lower() == 'true'),
is_template=args.get('is_template', default=False, type=lambda v: v.lower() == 'true'),
created_date_from=args.get('created_date_from', None, type=str),
created_date_to=args.get('created_date_to', None, type=str),
published_date_from=args.get('published_date_from', None, type=str),
published_date_to=args.get('published_date_to', None, type=str),
)

survey_records = SurveyService()\
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const TeamMemberListing = () => {
label: 'Team Members',
allowSort: false,
renderCell: (row: EngagementTeamMember) => (
<MuiLink component={Link} to={``}>
<MuiLink component={Link} to={`/usermanagement/${row.user_id}/details`}>
{row.user?.last_name + ', ' + row.user?.first_name}
</MuiLink>
),
Expand Down
44 changes: 22 additions & 22 deletions met-web/src/components/layout/SideNav/UserGuideNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,31 @@ import { MetHeader4 } from 'components/common';
import { levenshteinDistance } from 'helper';

const THRESHOLD_SIMILARITY_SCORE = 10;
const DEFAULT_HELP_PATH = 'https://www.example.com/help/dashboard';
const HELP_URL = 'https://bcgov.github.io/met-guide';

const UserGuideNav = () => {
const { pathname } = useLocation();

const helpPaths: { [key: string]: string } = {
'/': 'https://www.example.com/help/dashboard',
'/engagements': 'https://www.example.com/help/engagements',
'/surveys': 'https://www.example.com/help/surveys',
'/surveys/create': 'https://www.example.com/help/create-survey',
'/surveys/1/build': 'https://www.example.com/help/survey-builder',
'/surveys/1/submit': 'https://www.example.com/help/survey-submission',
'/surveys/1/comments': 'https://www.example.com/help/survey-comments',
'/surveys/1/comments/all': 'https://www.example.com/help/all-comments',
'/surveys/1/submissions/1/review': 'https://www.example.com/help/review-submission',
'/engagements/create/form': 'https://www.example.com/help/create-engagement',
'/engagements/1/form': 'https://www.example.com/help/edit-engagement',
'/engagements/1/view': 'https://www.example.com/help/view-engagement',
'/engagements/1/comments': 'https://www.example.com/help/engagement-comments',
'/engagements/1/dashboard': 'https://www.example.com/help/engagement-dashboard',
'/feedback': 'https://www.example.com/help/feedback',
'/calendar': 'https://www.example.com/help/calendar',
'/reporting': 'https://www.example.com/help/reporting',
'/usermanagement': 'https://www.example.com/help/user-management',
'/usermanagement/1/details': 'https://www.example.com/help/user-details',
'/': HELP_URL,
'/engagements': `${HELP_URL}/posts/engagement-listing/`,
'/surveys': `${HELP_URL}/posts/survey-listing/`,
'/surveys/create': `${HELP_URL}/posts/create-survey/`,
'/surveys/1/build': `${HELP_URL}/posts/survey-builder/`,
'/surveys/1/submit': `${HELP_URL}/posts/survey-builder/`,
'/surveys/1/comments': `${HELP_URL}/posts/comment-review/`,
'/surveys/1/comments/all': `${HELP_URL}/posts/comment-review/`,
'/surveys/1/submissions/1/review': `${HELP_URL}/posts/comment-review/`,
'/engagements/create/form': `${HELP_URL}/posts/create-engagement/`,
'/engagements/1/form': `${HELP_URL}/posts/edit-engagement/`,
'/engagements/1/view': `${HELP_URL}/posts/preview-engagement/`,
'/engagements/1/comments': `${HELP_URL}/posts/preview-engagement/`,
'/engagements/1/dashboard': `${HELP_URL}/posts/manage-engagement/`,
'/feedback': `${HELP_URL}/posts/feedback-tool/`,
'/calendar': HELP_URL,
'/reporting': `${HELP_URL}/posts/report/`,
'/usermanagement': `${HELP_URL}/posts/user-management/`,
'/usermanagement/1/details': `${HELP_URL}/posts/user-details/`,
};

const handleSimilarityScore = () => {
Expand All @@ -55,10 +55,10 @@ const UserGuideNav = () => {
const openHelpPage = () => {
const key = handleSimilarityScore();
if (!key) {
window.open(DEFAULT_HELP_PATH, '_blank', 'noopener');
window.open(HELP_URL, '_blank', 'noopener');
return;
}
const helpPagePath = key ? helpPaths[key] : DEFAULT_HELP_PATH;
const helpPagePath = key ? helpPaths[key] : HELP_URL;
window.open(helpPagePath, '_blank', 'noopener');
};

Expand Down
2 changes: 1 addition & 1 deletion met-web/src/components/survey/create/LinkOptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const LinkOptions = () => {
const handleFetchSurveys = async () => {
try {
const fetchedSurveys = await fetchSurveys({
unlinked: true,
is_unlinked: true,
exclude_hidden: true,
exclude_template: true,
});
Expand Down
Loading

0 comments on commit ebd2bbf

Please sign in to comment.