From 08f3f5e63c20a22cfd6e59541ed7287e362df28f Mon Sep 17 00:00:00 2001 From: Stefan Topfstedt Date: Thu, 18 Apr 2024 17:22:35 -0700 Subject: [PATCH] work in progress - adds user context filter to dashboard calendar. --- .../addon/components/dashboard/calendar.hbs | 3 ++ .../addon/components/dashboard/calendar.js | 33 ++++++++++++++++--- .../dashboard/user-context-filter.hbs | 9 +++++ .../dashboard/user-context-filter.js | 10 ++++++ packages/ilios-common/addon/models/user.js | 16 +++++++++ .../dashboard/user-context-filter.js | 1 + .../dashboard/user-context-filter-test.js | 16 +++++++++ 7 files changed, 84 insertions(+), 4 deletions(-) create mode 100644 packages/ilios-common/addon/components/dashboard/user-context-filter.hbs create mode 100644 packages/ilios-common/addon/components/dashboard/user-context-filter.js create mode 100644 packages/ilios-common/app/components/dashboard/user-context-filter.js create mode 100644 packages/test-app/tests/integration/components/dashboard/user-context-filter-test.js diff --git a/packages/ilios-common/addon/components/dashboard/calendar.hbs b/packages/ilios-common/addon/components/dashboard/calendar.hbs index bb0df9aeaa..37caf7816c 100644 --- a/packages/ilios-common/addon/components/dashboard/calendar.hbs +++ b/packages/ilios-common/addon/components/dashboard/calendar.hbs @@ -101,6 +101,9 @@ @clearFilters={{@clearFilters}} /> {{/if}} + {{#if this.canFilterByUserContext}} + + {{/if}}
[ this.getCohortProxies.bind(this), this.bestSelectedSchool, ]); + get canFilterByUserContext() { + // KLUDGE! + // checking if the current user is an instructor at all cast the net too wide. + // what we really want is to check if this user instructs in the currently selected school. + // CurrentUser::isTeachingCourseInSchool() is supposed to provide that functionality, but it's bugged. + // until this gets fixed we'll have to use this getter on the User model instead. + // @see https://github.com/ilios/ilios/issues/5410 + // [ST 2024/04/18] + return this.user?.isInstructor; + } + get fromTimeStamp() { if ('week' === this.args.selectedView) { return DateTime.fromJSDate(this.localeDays.firstDayOfDateWeek(this.args.selectedDate)) @@ -64,10 +79,9 @@ export default class DashboardCalendarComponent extends Component { } setup = dropTask(async () => { - const user = await this.currentUser.getModel(); - this.usersPrimarySchool = await user.school; - - const icsFeedKey = user.icsFeedKey; + this.user = await this.currentUser.getModel(); + this.usersPrimarySchool = await this.user.school; + const icsFeedKey = this.user.icsFeedKey; const apiHost = this.iliosConfig.apiHost; const loc = window.location.protocol + '//' + window.location.hostname; const server = apiHost ? apiHost : loc; @@ -130,6 +144,7 @@ export default class DashboardCalendarComponent extends Component { 'eventsWithSelectedCohorts', 'eventsWithSelectedCourses', 'eventsWithSelectedTerms', + 'eventsWithSelectedUserContext', ]; const allFilteredEvents = eventTypes.map((name) => { return this[name]; @@ -207,6 +222,16 @@ export default class DashboardCalendarComponent extends Component { }); } + get eventsWithSelectedUserContext() { + if (!this.userContext) { + return this.ourEvents; + } + + return this.ourEvents.filter((event) => { + return event.userContexts.includes(this.userContext); + }); + } + @action changeSchool(event) { this.args.changeSchool(event.target.value); diff --git a/packages/ilios-common/addon/components/dashboard/user-context-filter.hbs b/packages/ilios-common/addon/components/dashboard/user-context-filter.hbs new file mode 100644 index 0000000000..24d6d37ef9 --- /dev/null +++ b/packages/ilios-common/addon/components/dashboard/user-context-filter.hbs @@ -0,0 +1,9 @@ +
+ +
\ No newline at end of file diff --git a/packages/ilios-common/addon/components/dashboard/user-context-filter.js b/packages/ilios-common/addon/components/dashboard/user-context-filter.js new file mode 100644 index 0000000000..a1dcd5f090 --- /dev/null +++ b/packages/ilios-common/addon/components/dashboard/user-context-filter.js @@ -0,0 +1,10 @@ +import Component from '@glimmer/component'; +import { action } from '@ember/object'; + +export default class DashboardUserContextFilterComponent extends Component { + @action + toggle() { + const newUserContext = 'instructor' === this.args.userContext ? null : 'instructor'; + this.args.setUserContext(newUserContext); + } +} diff --git a/packages/ilios-common/addon/models/user.js b/packages/ilios-common/addon/models/user.js index a57d5afef8..9b7155e913 100644 --- a/packages/ilios-common/addon/models/user.js +++ b/packages/ilios-common/addon/models/user.js @@ -300,6 +300,22 @@ export default class User extends Model { return false; } + /** + * Checks if this user is instructing any offerings or ILMs. + */ + get isInstructor() { + if (this._instructedOfferingsData.isResolved && this._instructedOfferingsData.value.length) { + return true; + } + if ( + this._instructorIlmSessionsData.isResolved && + this._instructorIlmSessionsData.value.length + ) { + return true; + } + return false; + } + /** * Checks if a user is linked to any non-student things */ diff --git a/packages/ilios-common/app/components/dashboard/user-context-filter.js b/packages/ilios-common/app/components/dashboard/user-context-filter.js new file mode 100644 index 0000000000..a81012879f --- /dev/null +++ b/packages/ilios-common/app/components/dashboard/user-context-filter.js @@ -0,0 +1 @@ +export { default } from 'ilios-common/components/dashboard/user-context-filter'; \ No newline at end of file diff --git a/packages/test-app/tests/integration/components/dashboard/user-context-filter-test.js b/packages/test-app/tests/integration/components/dashboard/user-context-filter-test.js new file mode 100644 index 0000000000..49b2abad2b --- /dev/null +++ b/packages/test-app/tests/integration/components/dashboard/user-context-filter-test.js @@ -0,0 +1,16 @@ +import { module, test } from 'qunit'; +import { setupRenderingTest } from 'test-app/tests/helpers'; +import { setupIntl } from 'ember-intl/test-support'; +// import { render } from '@ember/test-helpers'; +// import { hbs } from 'ember-cli-htmlbars'; +import { setupMirage } from 'ember-cli-mirage/test-support'; + +module('Integration | Component | dashboard/user-context-filter', function (hooks) { + setupRenderingTest(hooks); + setupIntl(hooks, 'en-us'); + setupMirage(hooks); + + test('it renders', async function (/* assert */) { + // @todo implement [ST 2024/04/18] + }); +});