Skip to content

Commit

Permalink
Fix behaviour when deleting agendaitems and navigating between agenda…
Browse files Browse the repository at this point in the history
… tabs
  • Loading branch information
sergiofenoll committed Apr 15, 2022
1 parent 2dd083a commit 04d1484
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 22 deletions.
1 change: 1 addition & 0 deletions app/components/agenda/agenda-header.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
</div>
<Agenda::AgendaHeader::AgendaTabs
@currentAgenda={{@currentAgenda}}
@currentAgendaitems={{@currentAgendaitems}}
@currentMeeting={{@meeting}}
/>
</div>
Expand Down
4 changes: 4 additions & 0 deletions app/components/agenda/agenda-header/agenda-tabs.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
<Auk::Tab @route="agendas" @isHierarchicalBack={{true}} />
<Auk::Tab
@route="agenda.agendaitems.index"
@query={{if
this.currentAgendaItemId
(hash anchor=this.currentAgendaItemId)
}}
>
{{t "overview"}}
</Auk::Tab>
Expand Down
27 changes: 8 additions & 19 deletions app/components/agenda/agenda-header/agenda-tabs.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Component from '@glimmer/component';
import { inject as service } from '@ember/service';
import { task, lastValue } from 'ember-concurrency';

export default class AgendaAgendaHeaderAgendaTabsComponent extends Component {
/**
Expand All @@ -11,23 +10,8 @@ export default class AgendaAgendaHeaderAgendaTabsComponent extends Component {
@service store;
@service currentSession;

@lastValue('loadFirstAgendaitem') firstAgendaitem;

constructor() {
super(...arguments);
this.loadFirstAgendaitem.perform();
}

@task
*loadFirstAgendaitem() {
if (this.args.currentAgenda) {
// sorting on show-as-remark prevents defaulting to an announcement when there are notas
return yield this.store.queryOne('agendaitem', {
'filter[agenda][:id:]': this.args.currentAgenda.id,
sort: 'show-as-remark,number',
});
}
return null;
get firstAgendaitem() {
return this.args.currentAgendaitems?.toArray().sortBy('show-as-remark').sortBy('number').firstObject;
}

get modelsForDetailRoute() {
Expand All @@ -41,11 +25,16 @@ export default class AgendaAgendaHeaderAgendaTabsComponent extends Component {
get currentAgendaItemId() {
const currentRoute = this.router.currentRoute;
let agendaItemsRoute = currentRoute;
if (currentRoute && currentRoute.name.startsWith('agenda.agendaitems.agendaitem')) {
if (currentRoute?.name?.startsWith('agenda.agendaitems.agendaitem')) {
while (agendaItemsRoute.name !== 'agenda.agendaitems.agendaitem') {
agendaItemsRoute = agendaItemsRoute.parent;
}
return agendaItemsRoute.params.agendaitem_id;
} else if (currentRoute?.name?.startsWith('agenda.agendaitems')) {
while (agendaItemsRoute.name !== 'agenda.agendaitems') {
agendaItemsRoute = agendaItemsRoute.parent;
}
return agendaItemsRoute.queryParams.anchor;
}
return null;
}
Expand Down
9 changes: 7 additions & 2 deletions app/pods/agenda/agendaitems/agendaitem/index/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@ export default class IndexAgendaitemAgendaitemsAgendaController extends Controll
'filter[agenda][:id:]': this.agenda.id,
'filter[show-as-remark]': agendaitem.showAsRemark,
'filter[:lte:number]': `"${previousNumber}"`, // Needs quotes because of bug in mu-cl-resources
sort: '-number',
});
if (neighbouringItem) {
this.router.transitionTo('agenda.agendaitems.agendaitem', this.meeting.id, this.agenda.id, neighbouringItem.id);
} else {
this.router.transitionTo('agenda.agendaitems', this.meeting.id, this.agenda.id,{ queryParams: { anchor: neighbouringItem.id }});
this.router.transitionTo('agenda.agendaitems', this.meeting.id, this.agenda.id,{ queryParams: { anchor: null }});
}
}

Expand All @@ -48,8 +49,12 @@ export default class IndexAgendaitemAgendaitemsAgendaController extends Controll
@action
async reassignNumbersAndNavigateToNeighbouringAgendaitem() {
await this.reassignNumbersForAgendaitems();
this.agendaitemsController.send('reloadModel');
await this.navigateToNeighbouringItem(this.model);
this.agendaitemsController.send('reloadModel');
// The call to reloadModel causes a refresh of the agenda.agendaitems route, so its model gets recalculated
// Because we're a subroute of that route, our model will also get recalculated, using the current route
// That means that we're going to query for the current agendaitem, which has been deleted, because
// this method only gets called when the agendaitem gets deleted.
}

@action
Expand Down
5 changes: 5 additions & 0 deletions app/pods/agenda/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,15 @@ export default class AgendaRoute extends Route {
sort: '-serialnumber',
include: 'status',
});
const agendaitems = await this.store.query('agendaitem', {
'filter[agenda][:id:]': agenda.id,
sort: 'show-as-remark,number',
});

return {
meeting,
agenda,
agendaitems,
reverseSortedAgendas,
};
}
Expand Down
1 change: 1 addition & 0 deletions app/pods/agenda/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<Agenda::AgendaHeader
@meeting={{this.model.meeting}}
@currentAgenda={{this.model.agenda}}
@currentAgendaitems={{this.model.agendaitems}}
@reverseSortedAgendas={{this.model.reverseSortedAgendas}}
@onStartLoading={{this.enableIsLoading}}
@onStopLoading={{this.disableIsLoading}}
Expand Down
2 changes: 1 addition & 1 deletion app/pods/agendas/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export default class AgendasController extends Controller {
successfullyAdded() {
this.isCreatingNewSession = false;
this.send('refreshRoute');
this.router.transitionTo('agendas.overview');
this.router.transitionTo('agendas');
}

@action
Expand Down

0 comments on commit 04d1484

Please sign in to comment.