Skip to content

Commit

Permalink
Merge pull request #8274 from michaelchadwick/remove-common-course-re…
Browse files Browse the repository at this point in the history
…nder-modifiers

Remove common Course render modifiers
  • Loading branch information
stopfstedt authored Dec 19, 2024
2 parents a4b122f + e91315e commit bf55f08
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 114 deletions.
4 changes: 0 additions & 4 deletions packages/ilios-common/.lint-todo
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ add|ember-template-lint|no-at-ember-render-modifiers|3|2|3|2|7491f1d2f4e83f2c87f
add|ember-template-lint|no-at-ember-render-modifiers|13|6|13|6|1a2522cd1202904fb09a6e811dec6b46d8189ab3|1731542400000|1762646400000|1793750400000|addon/components/user-name-info.hbs
add|ember-template-lint|no-at-ember-render-modifiers|8|57|8|57|49de9e74a62c8d39ef6a37eaecf07bd389aa57c7|1731542400000|1762646400000|1793750400000|addon/components/wait-saving.hbs
add|ember-template-lint|no-at-ember-render-modifiers|7|2|7|2|1a2522cd1202904fb09a6e811dec6b46d8189ab3|1731542400000|1762646400000|1793750400000|addon/components/weekly-calendar-event.hbs
add|ember-template-lint|no-at-ember-render-modifiers|4|2|4|2|23cd787c79c34a628dadb6e96dd4004d42eebb79|1731542400000|1762646400000|1793750400000|addon/components/course/header.hbs
add|ember-template-lint|no-at-ember-render-modifiers|5|2|5|2|32658810aa13672f5981281c562729112a89788f|1731542400000|1762646400000|1793750400000|addon/components/course/header.hbs
add|ember-template-lint|no-at-ember-render-modifiers|4|2|4|2|23cd787c79c34a628dadb6e96dd4004d42eebb79|1731542400000|1762646400000|1793750400000|addon/components/course/objective-list.hbs
add|ember-template-lint|no-at-ember-render-modifiers|5|2|5|2|84076f8cf85c554eaf0d9fdec26154bae5bceeb2|1731542400000|1762646400000|1793750400000|addon/components/course/objective-list.hbs
add|ember-template-lint|no-at-ember-render-modifiers|4|2|4|2|2bbf15957242a9a3c1e26e14e5d022c858199fde|1731542400000|1762646400000|1793750400000|addon/components/course/rollover-date-picker.hbs
add|ember-template-lint|no-at-ember-render-modifiers|5|2|5|2|167e8d9ede488c7f199cb748e81bc09b97617e71|1731542400000|1762646400000|1793750400000|addon/components/course/rollover-date-picker.hbs
add|ember-template-lint|no-at-ember-render-modifiers|3|2|3|2|1009d3843f6aed52099f0e7fbd4eebb52bc176e5|1731542400000|1762646400000|1793750400000|addon/components/course/rollover.hbs
Expand Down
104 changes: 50 additions & 54 deletions packages/ilios-common/addon/components/course/header.hbs
Original file line number Diff line number Diff line change
@@ -1,54 +1,50 @@
<div
class="course-header"
data-test-course-header
{{did-insert (perform this.load)}}
{{did-update this.revertTitleChanges}}
>
{{#unless this.load.isRunning}}
<span class="title" data-test-title>
{{#if @editable}}
<EditableField
@value={{this.courseTitle}}
@save={{perform this.changeTitle}}
@close={{this.revertTitleChanges}}
@saveOnEnter={{true}}
@onEditingStatusChange={{set this "isEditingTitle"}}
@closeOnEscape={{true}} as |isSaving|
>
<input
aria-label={{t "general.courseTitle"}}
disabled={{isSaving}}
type="text"
value={{this.courseTitle}}
{{on "input" (pick "target.value" (set this "courseTitle"))}}
{{on "keypress" (fn this.addErrorDisplayFor "courseTitle")}}
>
<ValidationError @validatable={{this}} @property="courseTitle" />
</EditableField>
{{else}}
<h2>
{{#if @course.locked}}
<FaIcon @icon="lock" />
{{/if}}
{{@course.title}}
</h2>
{{/if}}
{{#unless this.isEditingTitle}}
<h3 class="academic-year" data-test-academic-year>
{{#if this.academicYearCrossesCalendarYearBoundaries}}
{{@course.year}} - {{add @course.year 1}}
{{else}}
{{@course.year}}
{{/if}}
</h3>
{{/unless}}
</span>
<div class="course-publication">
{{#if @editable}}
<Course::PublicationMenu @course={{@course}} />
{{else}}
<PublicationStatus @item={{@course}} @showIcon={{true}} @showText={{true}} />
{{/if}}
</div>
{{/unless}}
</div>
<div class="course-header" data-test-course-header>
<span class="title" data-test-title>
{{#if @editable}}
<EditableField
@value={{this.courseTitle}}
@save={{perform this.changeTitle}}
@close={{this.revertTitleChanges}}
@saveOnEnter={{true}}
@onEditingStatusChange={{set this "isEditingTitle"}}
@closeOnEscape={{true}}
as |isSaving|
>
<input
aria-label={{t "general.courseTitle"}}
disabled={{isSaving}}
type="text"
value={{this.courseTitle}}
{{on "input" (pick "target.value" (set this "courseTitle"))}}
{{on "keypress" (fn this.addErrorDisplayFor "courseTitle")}}
/>
<ValidationError @validatable={{this}} @property="courseTitle" />
</EditableField>
{{else}}
<h2>
{{#if @course.locked}}
<FaIcon @icon="lock" />
{{/if}}
{{@course.title}}
</h2>
{{/if}}
{{#unless this.isEditingTitle}}
<h3 class="academic-year" data-test-academic-year>
{{#if this.academicYearCrossesCalendarYearBoundaries}}
{{@course.year}}
-
{{add @course.year 1}}
{{else}}
{{@course.year}}
{{/if}}
</h3>
{{/unless}}
</span>
<div class="course-publication">
{{#if @editable}}
<Course::PublicationMenu @course={{@course}} />
{{else}}
<PublicationStatus @item={{@course}} @showIcon={{true}} @showText={{true}} />
{{/if}}
</div>
</div>
25 changes: 18 additions & 7 deletions packages/ilios-common/addon/components/course/header.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,35 @@
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { cached, tracked } from '@glimmer/tracking';
import { action } from '@ember/object';
import { restartableTask } from 'ember-concurrency';
import { validatable, Length, NotBlank } from 'ilios-common/decorators/validation';
import { service } from '@ember/service';
import { TrackedAsyncData } from 'ember-async-data';

@validatable
export default class CourseHeaderComponent extends Component {
@service iliosConfig;

@Length(3, 200) @NotBlank() @tracked courseTitle;
@tracked isEditingTitle = false;
@tracked academicYearCrossesCalendarYearBoundaries = false;

load = restartableTask(async () => {
this.academicYearCrossesCalendarYearBoundaries = await this.iliosConfig.itemFromConfig(
'academicYearCrossesCalendarYearBoundaries',
constructor() {
super(...arguments);
this.courseTitle = this.args.course.title;
}

@cached
get academicYearCrossesCalendarYearBoundariesData() {
return new TrackedAsyncData(
this.iliosConfig.itemFromConfig('academicYearCrossesCalendarYearBoundaries'),
);
this.revertTitleChanges();
});
}

get academicYearCrossesCalendarYearBoundaries() {
return this.academicYearCrossesCalendarYearBoundariesData.isResolved
? this.academicYearCrossesCalendarYearBoundariesData.value
: false;
}

changeTitle = restartableTask(async () => {
this.courseTitle = this.courseTitle.trim();
Expand Down
78 changes: 36 additions & 42 deletions packages/ilios-common/addon/components/course/objective-list.hbs
Original file line number Diff line number Diff line change
@@ -1,45 +1,39 @@
<div
class="course-objective-list"
data-test-course-objective-list
{{did-insert (perform this.load)}}
{{did-update (perform this.load) @course}}
>
{{#if this.isSorting}}
<ObjectiveSortManager
@subject={{@course}}
@close={{set this "isSorting" false}}
/>
{{/if}}

{{#if (and this.courseObjectiveCount (not this.isSorting))}}
{{#if (and @editable (gt this.courseObjectiveCount 1))}}
<button
class="sort-button"
type="button"
{{on "click" (set this "isSorting" true)}}
data-test-sort
>
{{t "general.sortObjectives"}}
</button>
<div class="course-objective-list" data-test-course-objective-list>
{{#if this.courseSessionsLoaded}}
{{#if this.isSorting}}
<ObjectiveSortManager @subject={{@course}} @close={{set this "isSorting" false}} />
{{/if}}
<div class="grid-row headers" data-test-headers>
<span class="grid-item" data-test-header>{{t "general.description"}}</span>
<span class="grid-item" data-test-header>{{t "general.parentObjectives"}}</span>
<span class="grid-item" data-test-header>{{t "general.vocabularyTerms"}}</span>
<span class="grid-item" data-test-header>{{t "general.meshTerms"}}</span>
<span class="actions grid-item" data-test-header>{{t "general.actions"}}</span>
</div>
{{#if (and (is-array this.courseObjectives) this.cohortObjectivesLoaded)}}
{{#each this.courseObjectives as |courseObjective|}}
<Course::ObjectiveListItem
@courseObjective={{courseObjective}}
@editable={{@editable}}
@cohortObjectives={{this.cohortObjectives}}
@course={{@course}}
/>
{{/each}}
{{else}}
<Course::ObjectiveListLoading @count={{this.courseObjectiveCount}} />

{{#if (and this.courseObjectiveCount (not this.isSorting))}}
{{#if (and @editable (gt this.courseObjectiveCount 1))}}
<button
class="sort-button"
type="button"
{{on "click" (set this "isSorting" true)}}
data-test-sort
>
{{t "general.sortObjectives"}}
</button>
{{/if}}
<div class="grid-row headers" data-test-headers>
<span class="grid-item" data-test-header>{{t "general.description"}}</span>
<span class="grid-item" data-test-header>{{t "general.parentObjectives"}}</span>
<span class="grid-item" data-test-header>{{t "general.vocabularyTerms"}}</span>
<span class="grid-item" data-test-header>{{t "general.meshTerms"}}</span>
<span class="actions grid-item" data-test-header>{{t "general.actions"}}</span>
</div>
{{#if (and (is-array this.courseObjectives) this.cohortObjectivesLoaded)}}
{{#each this.courseObjectives as |courseObjective|}}
<Course::ObjectiveListItem
@courseObjective={{courseObjective}}
@editable={{@editable}}
@cohortObjectives={{this.cohortObjectives}}
@course={{@course}}
/>
{{/each}}
{{else}}
<Course::ObjectiveListLoading @count={{this.courseObjectiveCount}} />
{{/if}}
{{/if}}
{{/if}}
</div>
</div>
25 changes: 18 additions & 7 deletions packages/ilios-common/addon/components/course/objective-list.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Component from '@glimmer/component';
import { cached, tracked } from '@glimmer/tracking';
import { restartableTask } from 'ember-concurrency';
import { map } from 'rsvp';
import { service } from '@ember/service';
import { TrackedAsyncData } from 'ember-async-data';
Expand All @@ -12,6 +11,19 @@ export default class CourseObjectiveListComponent extends Component {
@service dataLoader;
@tracked isSorting = false;

@cached
get courseSessionsData() {
return new TrackedAsyncData(this.getCourseSessions(this.args.course));
}

get courseSessions() {
return this.courseSessionsData.isResolved ? this.courseSessionsData.value : null;
}

get courseSessionsLoaded() {
return this.courseSessionsData.isResolved;
}

@cached
get courseObjectivesAsyncData() {
return new TrackedAsyncData(this.args.course.courseObjectives);
Expand All @@ -27,7 +39,7 @@ export default class CourseObjectiveListComponent extends Component {
}

get courseObjectives() {
if (this.load.lastSuccessful && this.courseObjectivesAsync) {
if (this.courseSessionsLoaded && this.courseObjectivesAsync) {
return this.courseObjectivesAsync.slice().sort(sortableByPosition);
}

Expand All @@ -39,7 +51,7 @@ export default class CourseObjectiveListComponent extends Component {
}

get courseCohorts() {
if (this.load.lastSuccessful && this.courseCohortsAsync) {
if (this.courseSessionsLoaded && this.courseCohortsAsync) {
return this.courseCohortsAsync;
}

Expand Down Expand Up @@ -67,10 +79,9 @@ export default class CourseObjectiveListComponent extends Component {
return this.args.course.hasMany('courseObjectives').ids().length;
}

load = restartableTask(async () => {
//pre-load all session data as well to get access to child objectives
await this.dataLoader.loadCourseSessions(this.args.course.id);
});
async getCourseSessions(course) {
await this.dataLoader.loadCourseSessions(course.id);
}

async getCohortObjectives(cohorts, intl) {
return await map(cohorts, async (cohort) => {
Expand Down

0 comments on commit bf55f08

Please sign in to comment.