Skip to content

Commit

Permalink
work in progress - adds user context filter to dashboard calendar.
Browse files Browse the repository at this point in the history
  • Loading branch information
stopfstedt committed Apr 19, 2024
1 parent 8badc84 commit 08f3f5e
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 4 deletions.
3 changes: 3 additions & 0 deletions packages/ilios-common/addon/components/dashboard/calendar.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@
@clearFilters={{@clearFilters}}
/>
{{/if}}
{{#if this.canFilterByUserContext}}
<Dashboard::UserContextFilter @setUserContext={{set this.userContext}} @userContext={{this.userContext}}/>
{{/if}}
<section class="fullwidth ilios-calendar-container"
{{did-insert (perform this.loadEvents) this.bestSelectedSchool this.fromTimeStamp this.toTimeStamp @mySchedule}}
{{did-update (perform this.loadEvents) this.bestSelectedSchool this.fromTimeStamp this.toTimeStamp @mySchedule}}
Expand Down
33 changes: 29 additions & 4 deletions packages/ilios-common/addon/components/dashboard/calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { map } from 'rsvp';
import { mapBy, sortBy } from 'ilios-common/utils/array-helpers';
import { use } from 'ember-could-get-used-to-this';
import AsyncProcess from 'ilios-common/classes/async-process';

export default class DashboardCalendarComponent extends Component {
@service userEvents;
@service schoolEvents;
Expand All @@ -20,14 +21,28 @@ export default class DashboardCalendarComponent extends Component {

@tracked usersPrimarySchool;
@tracked absoluteIcsUri;
@tracked user;

@tracked ourEvents = [];

@tracked userContext;

@use cohortProxies = new AsyncProcess(() => [
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.
// <code>CurrentUser::isTeachingCourseInSchool()</code> 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))
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -130,6 +144,7 @@ export default class DashboardCalendarComponent extends Component {
'eventsWithSelectedCohorts',
'eventsWithSelectedCourses',
'eventsWithSelectedTerms',
'eventsWithSelectedUserContext',
];
const allFilteredEvents = eventTypes.map((name) => {
return this[name];
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<div class="dashboard-user-context-filter">
<button type="button" {{on "click" this.toggle}}>
{{#if (eq 'instructor' @userContext)}}
Show all
{{else}}
Show instructed only
{{/if}}
</button>
</div>
Original file line number Diff line number Diff line change
@@ -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);
}
}
16 changes: 16 additions & 0 deletions packages/ilios-common/addon/models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from 'ilios-common/components/dashboard/user-context-filter';
Original file line number Diff line number Diff line change
@@ -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]
});
});

0 comments on commit 08f3f5e

Please sign in to comment.