Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/detail enhance municipality button behavior #52

Merged
merged 9 commits into from
Jul 13, 2023
12 changes: 9 additions & 3 deletions app/models/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,26 @@ export default class SessionModel extends Model {

get name() {
Denperidge marked this conversation as resolved.
Show resolved Hide resolved
return (
this.governingBody?.isTimeSpecializationOf?.name ??
this.governingBody?.isTimeSpecializationOf?.name ||
this.governingBody?.name ||
'Ontbrekend bestuursorgaan'
);
}

get municipality() {
return (
this.governingBody?.isTimeSpecializationOf?.administrativeUnit?.location
?.label ?? 'Ontbrekende bestuurseenheid'
?.label ||
this.governingBody?.administrativeUnit?.location?.label ||
'Ontbrekende bestuurseenheid'
);
}

get hasMunicipality() {
return !!this.governingBody?.isTimeSpecializationOf?.administrativeUnit;
return (
!!this.governingBody?.isTimeSpecializationOf?.administrativeUnit ||
!!this.governingBody?.administrativeUnit
);
}

get dateFormatted() {
Expand Down
16 changes: 5 additions & 11 deletions app/routes/agenda-items.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,17 @@ const getQuery = ({
plannedStartMin?: string;
plannedStartMax?: string;
}): AgendaItemsRequestInterface => ({
// exclude sessions without governing body and administrative unit
//todo investigate why filtering is not working
include:
include: [
'sessions.governing-body.is-time-specialization-of.administrative-unit.location',
'sessions.governing-body.administrative-unit.location',
].join(','),
sort: '-sessions.planned-start',
filter: {
sessions: {
':gt:planned-start': plannedStartMin ? plannedStartMin : undefined,
':lt:planned-start': plannedStartMax ? plannedStartMax : undefined,
':has:governing-body': true,
'governing-body': {
':has:is-time-specialization-of': true,
'is-time-specialization-of': {
':has:administrative-unit': true,
'administrative-unit': {
location: {
':id:': locationIds ? locationIds : undefined,
Expand Down Expand Up @@ -72,17 +69,14 @@ interface AgendaItemsRequestInterface {
include: string;
sort?: string;
filter?: {
':or:'?: unknown;
':or:'?: object;
sessions?: {
':gt:planned-start'?: string;
':lt:planned-start'?: string;
':has:governing-body'?: boolean;
'governing-body'?: {
':has:is-time-specialization-of'?: boolean;
'is-time-specialization-of'?: {
':has:administrative-unit'?: boolean;
'administrative-unit': {
location?: unknown;
location?: object;
};
};
};
Expand Down
2 changes: 2 additions & 0 deletions app/routes/detail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const agendaItemIncludes = [
'handled-by.has-votes.has-proponents.alias',
'handled-by.has-votes.has-proponents.has-membership.inner-group',
'sessions.governing-body.is-time-specialization-of.administrative-unit.location',
'sessions.governing-body.administrative-unit.location',
].join(',');

export default class DetailRoute extends Route {
Expand Down Expand Up @@ -100,6 +101,7 @@ export default class DetailRoute extends Route {
size: 4,
},
municipality: agendaItem.session?.get('municipality') || undefined,
include: agendaItemIncludes,
filter: {
sessions: {
'governing-body': {
Expand Down
25 changes: 3 additions & 22 deletions app/routes/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,12 @@ interface AgendaItemsRequestInterface {
include: string;
municipality?: string;
filter?: {
':has:sessions'?: boolean;
sessions?: {
':gt:planned-start'?: string;

':has:governing-body'?: boolean;
'governing-body'?: {
':has:is-time-specialization-of': true;
'is-time-specialization-of': {
':has:administrative-unit'?: boolean;
'administrative-unit': {
':has:location'?: boolean;
location?: {
':has:label'?: boolean;
label?: string;
};
};
Expand All @@ -41,29 +34,17 @@ export default class MapRoute extends Route {
page: {
size: 600,
},
include:
include: [
'sessions.governing-body.is-time-specialization-of.administrative-unit.location',
'sessions.governing-body.administrative-unit.location',
].join(','),
filter: {
':has:sessions': true,
sessions: {
':gt:planned-start': new Date(
new Date().setMonth(new Date().getMonth() - 3)
)
.toISOString()
.split('T')[0],
':has:governing-body': true,
'governing-body': {
':has:is-time-specialization-of': true,
'is-time-specialization-of': {
':has:administrative-unit': true,
'administrative-unit': {
':has:location': true,
location: {
':has:label': true,
},
},
},
},
},
},
};
Expand Down
10 changes: 6 additions & 4 deletions app/routes/municipality.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ interface AgendaItemsRequestInterface {
include: string;
municipality?: string;
filter?: {
':or:'?: unknown;
':or:'?: object;
sessions?: {
'governing-body'?: {
'is-time-specialization-of'?: {
'administrative-unit': {
location?: unknown;
location?: object;
};
};
};
Expand All @@ -35,16 +35,18 @@ export default class MunicipalityRoute extends Route {
page: { refreshModel: true },
};

async model(params: any) {
async model(params: MunicipalityParams) {
const { municipality } = params;

const req: AgendaItemsRequestInterface = {
page: {
size: 10,
},
municipality: municipality,
include:
include: [
'sessions.governing-body.is-time-specialization-of.administrative-unit.location',
'sessions.governing-body.administrative-unit.location',
].join(','),
filter: {},
};

Expand Down
7 changes: 1 addition & 6 deletions app/routes/sessions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,10 @@ const getQuery = (
plannedStartMax?: string,
locationIds?: string
) => ({
// exclude sessions without governing body and administrative unit
//todo investigate why filtering is not working
filter: {
':has:governing-body': true,
'governing-body': {
':has:is-time-specialization-of': true,
'is-time-specialization-of': {
':has:administrative-unit': true,
'administrative-unit': {
':has:location': true,
location: {
':id:': locationIds ? locationIds : undefined,
},
Expand All @@ -40,6 +34,7 @@ const getQuery = (
},
include: [
'governing-body.is-time-specialization-of.administrative-unit.location',
'governing-body.administrative-unit.location',
'agenda-items',
].join(','),
sort: '-planned-start',
Expand Down
21 changes: 7 additions & 14 deletions app/routes/sessions/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,12 @@ export default class SessionRoute extends Route {
@service declare store: Store;

async model({ session_id }: { session_id: string }) {
const sessionFromParent: undefined | SessionModel = this.modelFor(
'sessions.index'
// @ts-ignore
)?.sessions?.find((session: any) => session.id === session_id);
const session: SessionModel =
sessionFromParent ??
(await this.store.findRecord('session', session_id, {
include: [
'governing-body.is-time-specialization-of.administrative-unit.location',
'agenda-items',
].join(','),
}));

return session;
return this.store.findRecord('session', session_id, {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we might have had the same idea for simplifying this request, I think I also did something similar in one of the PR's woopss
But that's neither here nor there, we'll cross that bridge when we get there! Love the streamlining you did

include: [
'governing-body.is-time-specialization-of.administrative-unit.location',
'governing-body.administrative-unit.location',
'agenda-items',
].join(','),
});
}
}