Skip to content

Commit

Permalink
Merge pull request #8039 from jrjohnson/i5374-some-stuff
Browse files Browse the repository at this point in the history
Replace Some Modifier Loaders
  • Loading branch information
jrjohnson authored Aug 6, 2024
2 parents ced510c + a29f8c1 commit 2cfa9ea
Show file tree
Hide file tree
Showing 14 changed files with 198 additions and 144 deletions.
2 changes: 0 additions & 2 deletions packages/frontend/.lint-todo
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
add|ember-template-lint|no-at-ember-render-modifiers|5|2|5|2|23cd787c79c34a628dadb6e96dd4004d42eebb79|1721088000000|1723680000000|1726272000000|app/components/new-directory-user.hbs
add|ember-template-lint|no-at-ember-render-modifiers|4|4|4|4|5d93dc162628c4faaa7bce9ef9bfba305f14ce38|1721088000000|1723680000000|1726272000000|app/components/unassigned-students-summary.hbs
add|ember-template-lint|no-at-ember-render-modifiers|5|4|5|4|5f7f17419fe451673ab74fb58778311bc01912c0|1721088000000|1723680000000|1726272000000|app/components/unassigned-students-summary.hbs
add|ember-template-lint|no-at-ember-render-modifiers|5|4|5|4|ddf86727990ead62165fe28c6dff53552a4d49b7|1721088000000|1723680000000|1726272000000|app/components/user-menu.hbs
add|ember-template-lint|no-at-ember-render-modifiers|28|43|28|43|5c127b0b8124a93b18177d7580bcc47dbb8ebbff|1721088000000|1723680000000|1726272000000|app/components/user-menu.hbs
add|ember-template-lint|no-at-ember-render-modifiers|4|2|4|2|23cd787c79c34a628dadb6e96dd4004d42eebb79|1721088000000|1723680000000|1726272000000|app/components/user-profile-bio.hbs
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
{{#let (unique-id) as |templateId|}}
<div
class="unassigned-students-summary small-component {{if this.hasUnassignedStudents "alert"}}"
{{did-insert (perform this.load) this.schoolId}}
{{did-update (perform this.load) this.schoolId}}
data-test-unassigned-students-summary
>
<h3 data-test-title>
Expand Down Expand Up @@ -32,7 +30,7 @@
{{/if}}
</div>
</div>
{{#if (and this.load.isIdle (is-array this.unassignedStudents))}}
{{#if this.isLoaded}}
<p data-test-summary-text>
{{t
"general.unassignedStudentsSummary"
Expand Down
73 changes: 52 additions & 21 deletions packages/frontend/app/components/unassigned-students-summary.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,66 @@
import Component from '@glimmer/component';
import { service } from '@ember/service';
import { tracked } from '@glimmer/tracking';
import { restartableTask } from 'ember-concurrency';
import { cached, tracked } from '@glimmer/tracking';
import { findById } from 'ilios-common/utils/array-helpers';
import { TrackedAsyncData } from 'ember-async-data';

export default class UnassignedStudentsSummaryComponent extends Component {
@service currentUser;
@service store;

@tracked schoolId;
@tracked selectedSchool;
@tracked unassignedStudents;

get hasUnassignedStudents() {
return this.unassignedStudents?.length > 0;
@cached
get userModelData() {
return new TrackedAsyncData(this.currentUser.getModel());
}

get currentUserModel() {
return this.userModelData.isResolved ? this.userModelData.value : null;
}

@cached
get userSchoolData() {
return new TrackedAsyncData(this.currentUserModel?.school);
}
get userSchool() {
return this.userSchoolData.isResolved ? this.userSchoolData.value : null;
}

load = restartableTask(async (element, [schoolId]) => {
if (schoolId) {
this.selectedSchool = findById(this.args.schools.slice(), schoolId);
} else {
const user = await this.currentUser.getModel();
this.selectedSchool = await user.school;
get selectedSchool() {
if (this.schoolId) {
return findById(this.args.schools, this.schoolId);
}
this.unassignedStudents = await this.store.query('user', {
filters: {
cohorts: null,
enabled: true,
roles: [4],
school: this.selectedSchool.id,
},
});
});
return this.userSchool;
}

@cached
get unassignedStudentsData() {
return new TrackedAsyncData(
this.store.query('user', {
filters: {
cohorts: null,
enabled: true,
roles: [4],
school: this.selectedSchool.id,
},
}),
);
}

get unassignedStudents() {
return this.unassignedStudentsData.isResolved ? this.unassignedStudentsData.value : [];
}

get hasUnassignedStudents() {
return this.isLoaded && this.unassignedStudents?.length > 0;
}

get isLoaded() {
return (
this.userModelData.isResolved &&
this.userSchoolData.isResolved &&
this.unassignedStudentsData.isResolved
);
}
}
10 changes: 0 additions & 10 deletions packages/ilios-common/.lint-todo
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,5 @@ add|ember-template-lint|no-at-ember-render-modifiers|3|2|3|2|9b56ba661238d88b20a
add|ember-template-lint|no-at-ember-render-modifiers|4|2|4|2|23cd787c79c34a628dadb6e96dd4004d42eebb79|1720137600000|1722729600000|1725321600000|addon/components/dashboard/courses-calendar-filter.hbs
add|ember-template-lint|no-at-ember-render-modifiers|5|2|5|2|a90be151f45cd8ab32827e9247a9a9eb7f1baef2|1720137600000|1722729600000|1725321600000|addon/components/dashboard/courses-calendar-filter.hbs
add|ember-template-lint|no-at-ember-render-modifiers|25|10|25|10|4913c92cf4c945ea3970261ab1c1da9fa97d4bbc|1720137600000|1722729600000|1725321600000|addon/components/dashboard/courses-calendar-filter.hbs
add|ember-template-lint|no-at-ember-render-modifiers|4|4|4|4|03a0b2a6468e5c6768194c11af7aae4a82913ad9|1720137600000|1722729600000|1725321600000|addon/components/dashboard/filter-tags.hbs
add|ember-template-lint|no-at-ember-render-modifiers|5|4|5|4|c66686be652666be4c47d41c570b9807967cf118|1720137600000|1722729600000|1725321600000|addon/components/dashboard/filter-tags.hbs
add|ember-template-lint|no-at-ember-render-modifiers|4|2|4|2|23cd787c79c34a628dadb6e96dd4004d42eebb79|1720137600000|1722729600000|1725321600000|addon/components/session/collapsed-objectives.hbs
add|ember-template-lint|no-at-ember-render-modifiers|5|2|5|2|7e0d8502a2d39a13198bac7b12683622f4f70fa2|1720137600000|1722729600000|1725321600000|addon/components/session/collapsed-objectives.hbs
add|ember-template-lint|no-at-ember-render-modifiers|5|2|5|2|da607c2bd27a97b79ff86927cc7e3cdf7f565cb9|1720137600000|1722729600000|1725321600000|addon/components/session/objective-list-item.hbs
add|ember-template-lint|no-at-ember-render-modifiers|6|2|6|2|a53cdd3e0f9a1da348e33891999342148844afe4|1720137600000|1722729600000|1725321600000|addon/components/session/objective-list-item.hbs
add|ember-template-lint|no-at-ember-render-modifiers|3|2|3|2|31149a49c6b7ccbedc584e99d2280cfba9726e71|1720137600000|1722729600000|1725321600000|addon/components/session/objectives.hbs
add|ember-template-lint|no-at-ember-render-modifiers|4|2|4|2|60333f2ba463ca3d2ba17a04d799c8d66d8b99e2|1720137600000|1722729600000|1725321600000|addon/components/session/objectives.hbs
add|ember-template-lint|no-at-ember-render-modifiers|3|2|3|2|1fb6f249958ee245e6abc413681c9fe096120cef|1720137600000|1722729600000|1725321600000|addon/components/session/postrequisite-editor.hbs
add|ember-template-lint|no-at-ember-render-modifiers|4|2|4|2|856162ce473b112534763bb641aae7a4422d8e2e|1720137600000|1722729600000|1725321600000|addon/components/session/postrequisite-editor.hbs
add|ember-template-lint|no-at-ember-render-modifiers|28|6|28|6|242be4337ef58ba487a9168fe2944bd6919a1397|1720137600000|1722729600000|1725321600000|addon/components/session/publication-menu.hbs
add|ember-template-lint|no-at-ember-render-modifiers|29|6|29|6|df94e6558ff62dea69f6f656f668f29b56bcc378|1720137600000|1722729600000|1725321600000|addon/components/session/publication-menu.hbs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
{{#if this.activeFilters.length}}
<section
class="filters-list"
{{did-insert (perform this.load) this.activeFilters}}
{{did-update (perform this.load) this.activeFilters}}
data-test-dashboard-filter-tags
>
{{#if this.filterTags}}
Expand Down
126 changes: 77 additions & 49 deletions packages/ilios-common/addon/components/dashboard/filter-tags.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import Component from '@glimmer/component';
import { restartableTask } from 'ember-concurrency';
import { all, map } from 'rsvp';
import { tracked } from '@glimmer/tracking';
import { cached } from '@glimmer/tracking';
import { service } from '@ember/service';
import { findById } from 'ilios-common/utils/array-helpers';
import { TrackedAsyncData } from 'ember-async-data';

export default class DashboardFilterTagsComponent extends Component {
@service store;
@service intl;
@tracked filterTags = [];

get activeFilters() {
return [].concat(
Expand All @@ -20,23 +18,22 @@ export default class DashboardFilterTagsComponent extends Component {
);
}

load = restartableTask(async () => {
const tags = await all([
this.getCourseLevelTags(),
this.getSessionTypeTags(),
this.getCohortTags(),
this.getTermTags(),
this.getCourseTags(),
]);
this.filterTags = tags.flat();
});
get filterTags() {
return [
...this.courseLevelTags,
...this.sessionTypeTags,
...this.cohortTags,
...this.termTags,
...this.courseTags,
];
}

async fetchModel(modelName, id) {
const model = this.store.peekRecord(modelName, id);
return model ? model : this.store.findRecord(modelName, id);
}

getCourseLevelTags() {
get courseLevelTags() {
return this.args.selectedCourseLevels.map((level) => {
return {
id: level,
Expand All @@ -46,18 +43,29 @@ export default class DashboardFilterTagsComponent extends Component {
};
});
}
async getSessionTypeTags() {
return map(this.args.selectedSessionTypeIds, async (id) => {
const sessionType = await this.fetchModel('session-type', id);
return {
id,
class: 'tag-session-type',
remove: this.args.removeSessionTypeId,
name: sessionType.title,
};
});

@cached
get sessionTypeTagsData() {
return new TrackedAsyncData(
Promise.all(
this.args.selectedSessionTypeIds.map(async (id) => {
const sessionType = await this.fetchModel('session-type', id);
return {
id,
class: 'tag-session-type',
remove: this.args.removeSessionTypeId,
name: sessionType.title,
};
}),
),
);
}
getCohortTags() {

get sessionTypeTags() {
return this.sessionTypeTagsData.isResolved ? this.sessionTypeTagsData.value : [];
}

get cohortTags() {
return this.args.selectedCohortIds.map((id) => {
const proxy = findById(this.args.cohortProxies, id);
return {
Expand All @@ -68,29 +76,49 @@ export default class DashboardFilterTagsComponent extends Component {
};
});
}
async getTermTags() {
return map(this.args.selectedTermIds, async (id) => {
const term = await this.fetchModel('term', id);
const allTitles = await term.getTitleWithParentTitles();
const vocabulary = await term.get('vocabulary');
const title = vocabulary.get('title');
return {
id,
class: 'tag-term',
remove: this.args.removeTermId,
name: `${title} > ${allTitles}`,
};
});

@cached
get termTagsData() {
return new TrackedAsyncData(
Promise.all(
this.args.selectedTermIds.map(async (id) => {
const term = await this.fetchModel('term', id);
const allTitles = await term.getTitleWithParentTitles();
const vocabulary = await term.vocabulary;
const title = vocabulary.get('title');
return {
id,
class: 'tag-term',
remove: this.args.removeTermId,
name: `${title} > ${allTitles}`,
};
}),
),
);
}
async getCourseTags() {
return map(this.args.selectedCourseIds, async (id) => {
const course = await this.fetchModel('course', id);
return {
id,
class: 'tag-course',
remove: this.args.removeCourseId,
name: `${course.year} ${course.title}`,
};
});

get termTags() {
return this.termTagsData.isResolved ? this.termTagsData.value : [];
}

@cached
get courseTagsData() {
return new TrackedAsyncData(
Promise.all(
this.args.selectedCourseIds.map(async (id) => {
const course = await this.fetchModel('course', id);
return {
id,
class: 'tag-course',
remove: this.args.removeCourseId,
name: `${course.year} ${course.title}`,
};
}),
),
);
}

get courseTags() {
return this.courseTagsData.isResolved ? this.courseTagsData.value : [];
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<section
class="session-collapsed-objectives"
data-test-session-collapsed-objectives
{{did-insert (perform this.load)}}
{{did-update (perform this.load) @session.sessionObjectives}}
>
<div>
<button
Expand All @@ -16,7 +14,7 @@
<FaIcon @icon="caret-right" />
</button>
</div>
{{#if this.load.lastSuccessful}}
{{#if this.objectivesData.isResolved}}
<div class="content">
<table>
<thead>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,32 @@
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { restartableTask } from 'ember-concurrency';
import { cached } from '@glimmer/tracking';
import { TrackedAsyncData } from 'ember-async-data';

export default class SessionCollapsedObjectivesComponent extends Component {
@tracked objectivesRelationship;

load = restartableTask(async () => {
this.objectivesRelationship = await this.args.session.sessionObjectives;
});
@cached
get objectivesData() {
return new TrackedAsyncData(this.args.session.sessionObjectives);
}

get objectives() {
return this.objectivesRelationship ? this.objectivesRelationship.slice() : [];
return this.objectivesData.isResolved ? this.objectivesData.value : [];
}

get objectivesWithParents() {
return this.objectives.filter((objective) => {
return objective.courseObjectives.length > 0;
return objective.hasMany('courseObjectives').ids().length > 0;
});
}

get objectivesWithMesh() {
return this.objectives.filter((objective) => {
return objective.meshDescriptors.length > 0;
return objective.hasMany('meshDescriptors').ids().length > 0;
});
}

get objectivesWithTerms() {
return this.objectives.filter((objective) => {
return objective.terms.length > 0;
return objective.hasMany('terms').ids().length > 0;
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
id="objective-{{@sessionObjective.id}}"
class="grid-row objective-row {{if this.showRemoveConfirmation "confirm-removal"}} {{if this.highlightSave.isRunning "highlight-ok"}} {{if this.isManaging "is-managing"}}"
data-test-session-objective-list-item
{{did-insert this.load @sessionObjective}}
{{did-update this.load @sessionObjective}}
>
<div class="description grid-item" data-test-description>
{{#if (and @editable (not this.isManaging) (not this.showRemoveConfirmation))}}
Expand Down
Loading

0 comments on commit 2cfa9ea

Please sign in to comment.