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: 2 additions & 10 deletions app/components/decision-card.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,9 @@
<c.footer>
{{@item.session.dateFormatted}}
-
{{#if @item.session.governingBody.name}}
{{@item.session.governingBody.name}}
{{else}}
Geen Bestuurorgaan
{{/if}}
{{@item.session.name}}
-
{{#if @item.session.governingBody.administrativeUnit.name}}
{{@item.session.governingBody.administrativeUnit.name}}
{{else}}
Geen Bestuurseenheid
{{/if}}
{{@item.session.municipality}}
</c.footer>
</AuCard>
</LinkTo>
4 changes: 4 additions & 0 deletions app/controllers/detail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@ export default class DetailController extends Controller {
get hasVotes() {
return this.model.agendaItem?.handledBy?.get('hasVotes')?.length > 0;
}

get municipalityQuery() {
return { gemeentes: this.model.agendaItem.session.municipality };
}
}
3 changes: 1 addition & 2 deletions app/controllers/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ export default class MapComponent extends Controller {
this.agendaData.forEach((agendaItem: AgendaItemModel) => {
const agendaItemLocation = agendaItem
.get('session')
?.get('governingBody')
?.get('administrativeUnit')?.name;
?.get('municipality');
Windvis marked this conversation as resolved.
Show resolved Hide resolved
if (name === agendaItemLocation) {
const datenow = new Date(Date.now()).setHours(0, 0, 0, 0);
const f = agendaItem.session?.plannedStart;
Expand Down
14 changes: 10 additions & 4 deletions app/models/administrative-unit.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import Model, { attr, belongsTo, hasMany } from '@ember-data/model';
import Model, {
attr,
belongsTo,
hasMany,
AsyncHasMany,
AsyncBelongsTo,
} from '@ember-data/model';
import GoverningBodyModel from './governing-body';
import AdministrativeUnitClasssificationCodeModel from './location';
import LocationModel from './location';
Expand All @@ -8,14 +14,14 @@ export default class AdministrativeUnitModel extends Model {
declare name: string;

@hasMany('governing-body', { async: true, inverse: 'administrativeUnit' })
declare governingBodies: GoverningBodyModel;
declare governingBodies: AsyncHasMany<GoverningBodyModel>;

@belongsTo('administrative-unit-classification-code', {
async: true,
inverse: null,
})
declare classification: AdministrativeUnitClasssificationCodeModel;
declare classification: AsyncBelongsTo<AdministrativeUnitClasssificationCodeModel>;

@belongsTo('location', { async: true, inverse: null })
@belongsTo('location', { async: false, inverse: null })
declare location: LocationModel;
}
6 changes: 3 additions & 3 deletions app/models/agenda-item-handling.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import Model, { attr, hasMany } from '@ember-data/model';
import Model, { AsyncHasMany, attr, hasMany } from '@ember-data/model';
import ResolutionModel from './resolution';
import VoteModel from './vote';

export default class AgendaItemHandlingModel extends Model {
@attr('boolean') declare public?: boolean;

@hasMany('vote', { async: true, inverse: null })
declare hasVotes?: VoteModel;
declare hasVotes?: AsyncHasMany<VoteModel>;

@hasMany('resolution', { async: true, inverse: null })
declare resolutions?: ResolutionModel;
declare resolutions?: AsyncHasMany<ResolutionModel>;
}
20 changes: 16 additions & 4 deletions app/models/agenda-item.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import Model, { attr, belongsTo } from '@ember-data/model';
import Model, {
attr,
belongsTo,
hasMany,
AsyncHasMany,
AsyncBelongsTo,
} from '@ember-data/model';
import AgendaItemHandlingModel from './agenda-item-handling';
import SessionModel from './session';

Expand All @@ -8,9 +14,15 @@ export default class AgendaItemModel extends Model {
@attr('string') declare alternateLink: string;
@attr('boolean') declare plannedPublic: boolean;

@belongsTo('session', { async: true, inverse: 'agendaItems' })
declare session?: SessionModel;
@hasMany('session', { async: true, inverse: 'agendaItems' })
declare sessions?: AsyncHasMany<SessionModel>;

@belongsTo('agenda-item-handling', { async: true, inverse: null })
declare handledBy?: AgendaItemHandlingModel;
declare handledBy?: AsyncBelongsTo<AgendaItemHandlingModel>;

get session() {
Denperidge marked this conversation as resolved.
Show resolved Hide resolved
return this.sessions?.slice().find((session) => {
Windvis marked this conversation as resolved.
Show resolved Hide resolved
return session.hasMunicipality;
});
}
}
23 changes: 20 additions & 3 deletions app/models/governing-body.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import Model, { attr, belongsTo, type AsyncBelongsTo } from '@ember-data/model';
import Model, {
attr,
belongsTo,
hasMany,
AsyncHasMany,
} from '@ember-data/model';
import SessionModel from './session';
import AdministrativeUnitModel from './administrative-unit';

Expand All @@ -11,6 +16,18 @@ export default class GoverningBodyModel extends Model {
})
declare administrativeUnit: AdministrativeUnitModel;

@belongsTo('session', { async: true, inverse: 'governingBody' })
declare session: AsyncBelongsTo<SessionModel>;
@hasMany('session', { async: true, inverse: 'governingBody' })
declare sessions: AsyncHasMany<SessionModel>;

@belongsTo('governing-body', {
async: false,
inverse: 'hasTimeSpecializations',
})
declare isTimeSpecializationOf: GoverningBodyModel;
Denperidge marked this conversation as resolved.
Show resolved Hide resolved

@hasMany('governing-body', {
async: true,
inverse: 'isTimeSpecializationOf',
})
declare hasTimeSpecializations: AsyncHasMany<GoverningBodyModel>;
}
6 changes: 3 additions & 3 deletions app/models/mandatary.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Model, { attr, belongsTo } from '@ember-data/model';
import Model, { AsyncBelongsTo, attr, belongsTo } from '@ember-data/model';
import MembershipModel from './membership';
import PersonModel from './person';

Expand All @@ -7,8 +7,8 @@ export default class MandataryModel extends Model {
@attr('date') declare endDate: Date;

@belongsTo('person', { async: true, inverse: null })
declare alias: PersonModel;
declare alias: AsyncBelongsTo<PersonModel>;

@belongsTo('membership', { async: true, inverse: null })
declare hasMembership: MembershipModel;
declare hasMembership: AsyncBelongsTo<MembershipModel>;
}
4 changes: 2 additions & 2 deletions app/models/membership.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Model, { belongsTo } from '@ember-data/model';
import Model, { AsyncBelongsTo, belongsTo } from '@ember-data/model';
import parliamentaryGroupModel from './parliamentary-group';

export default class MembershipModel extends Model {
@belongsTo('parliamentary-group', { async: true, inverse: null })
declare innerGroup: parliamentaryGroupModel;
declare innerGroup: AsyncBelongsTo<parliamentaryGroupModel>;
}
24 changes: 13 additions & 11 deletions app/models/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,36 @@ export default class SessionModel extends Model {
@attr('date') declare startedAt?: Date;
@attr('date') declare endedAt?: Date;

@hasMany('agenda-item', { async: true, inverse: 'session' })
@hasMany('agenda-item', { async: true, inverse: 'sessions' })
declare agendaItems: AsyncHasMany<AgendaItemModel>;

@belongsTo('governing-body', { async: false, inverse: 'session' })
@belongsTo('governing-body', { async: false, inverse: 'sessions' })
declare governingBody: GoverningBodyModel;

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

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

get location() {
get hasMunicipality() {
return (
this.governingBody?.administrativeUnit?.location?.label ??
'Ontbrekende locatie'
!!this.governingBody?.isTimeSpecializationOf?.administrativeUnit ||
!!this.governingBody?.administrativeUnit
);
}

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

get dateFormatted() {
if (this.startedAt || this.endedAt) {
return getFormattedDateRange(this.startedAt, this.endedAt);
Expand Down
8 changes: 4 additions & 4 deletions app/models/vote.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Model, { attr, hasMany } from '@ember-data/model';
import Model, { AsyncHasMany, attr, hasMany } from '@ember-data/model';
import MandataryModel from './mandatary';

export default class VoteModel extends Model {
Expand All @@ -8,11 +8,11 @@ export default class VoteModel extends Model {
@attr('boolean') declare secret: boolean;

@hasMany('mandatary', { async: true, inverse: null })
declare hasAbstainers: MandataryModel;
declare hasAbstainers: AsyncHasMany<MandataryModel>;

@hasMany('mandatary', { async: true, inverse: null })
declare hasOpponents: MandataryModel;
declare hasOpponents: AsyncHasMany<MandataryModel>;

@hasMany('mandatary', { async: true, inverse: null })
declare hasProponents: MandataryModel;
declare hasProponents: AsyncHasMany<MandataryModel>;
}
35 changes: 14 additions & 21 deletions app/routes/agenda-items.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,21 @@ const getQuery = ({
plannedStartMin?: string;
plannedStartMax?: string;
}): AgendaItemsRequestInterface => ({
// exclude sessions without governing body and administrative unit
//todo investigate why filtering is not working
include: [
'session',
'session.governing-body',
'session.governing-body.administrative-unit',
'session.governing-body.administrative-unit.location',
'sessions.governing-body.is-time-specialization-of.administrative-unit.location',
'sessions.governing-body.administrative-unit.location',
].join(','),
sort: '-session.planned-start',
sort: '-sessions.planned-start',
filter: {
session: {
sessions: {
':gt:planned-start': plannedStartMin ? plannedStartMin : undefined,
':lt:planned-start': plannedStartMax ? plannedStartMax : undefined,
':has:governing-body': true,
'governing-body': {
':has:administrative-unit': true,
'administrative-unit': {
':has:name': true,
location: {
':id:': locationIds ? locationIds : undefined,
'is-time-specialization-of': {
'administrative-unit': {
location: {
':id:': locationIds ? locationIds : undefined,
},
},
},
},
Expand All @@ -75,16 +70,14 @@ interface AgendaItemsRequestInterface {
sort?: string;
filter?: {
':or:'?: object;
session?: {
sessions?: {
':gt:planned-start'?: string;
':lt:planned-start'?: string;
':has:governing-body'?: boolean;
'governing-body'?: {
':has:administrative-unit'?: boolean;
'administrative-unit': {
':has:name'?: boolean;
name?: string;
location?: object;
'is-time-specialization-of'?: {
'administrative-unit': {
location?: object;
};
};
};
};
Expand Down
26 changes: 11 additions & 15 deletions app/routes/detail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,16 @@ interface FormattedTableVote {
}

const agendaItemIncludes = [
'session',
// "session.governing-body",
'session.governing-body.administrative-unit',
// 'handled-by',
'handled-by.has-votes',
'handled-by.resolutions',
// 'session.governing-body',
'session.governing-body.administrative-unit',
// 'handled-by.has-votes.has-presents',
// 'handled-by.has-votes.has-abstainers',
'handled-by.has-votes.has-abstainers.alias',
'handled-by.has-votes.has-abstainers.has-membership.inner-group',
// 'handled-by.has-votes.has-voters',
// 'handled-by.has-votes.has-opponents',
'handled-by.has-votes.has-opponents.alias',
'handled-by.has-votes.has-opponents.has-membership.inner-group',
// 'handled-by.has-votes.has-proponents',
'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 All @@ -50,7 +41,7 @@ export default class DetailRoute extends Route {
? await this.store.query('agenda-item', {
include: agendaItemIncludes,
filter: {
session: {
sessions: {
[':id:']: sessionId,
},
},
Expand Down Expand Up @@ -110,11 +101,16 @@ export default class DetailRoute extends Route {
size: 4,
},
municipality: agendaItem.session?.get('municipality') || undefined,
include: agendaItemIncludes,
filter: {
session: {
sessions: {
'governing-body': {
'administrative-unit': {
name: agendaItem.session?.get('municipality') || undefined,
'is-time-specialization-of': {
'administrative-unit': {
location: {
label: agendaItem.session?.get('municipality') || undefined,
Windvis marked this conversation as resolved.
Show resolved Hide resolved
},
},
},
},
},
Expand Down
Loading