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

Add validation report page #466

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/config/custom-inflector-rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,6 @@ inflector.irregular('global-system-message', 'global-system-messages');
inflector.irregular('werkingsgebied', 'werkingsgebieden');

inflector.irregular('bestuurseenheid-contact', 'bestuurseenheid-contacten');

inflector.irregular('report', 'reports');
inflector.irregular('validationresult', 'validationresults');
57 changes: 57 additions & 0 deletions app/controllers/report.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import Controller from '@ember/controller';

import { action } from '@ember/object';
import { service } from '@ember/service';

export default class ReportController extends Controller {
@service store;

get targetClasses() {
return Array.from(this.model.resultsByTargetClass.keys());
}

@action
filterResultsByTargetClass(targetClass) {
return this.model.resultsByTargetClass.get(targetClass);
}

@action
lengthOfResultsByTargetClass(targetClass) {
return this.filterResultsByTargetClass(targetClass).length;
}

@action
async getFocusNodeContext(focusNode, targetClass) {
const mapTargetClassToRoute = {
'http://data.vlaanderen.be/ns/mandaat#Mandataris': {
route: 'mandatarissen.mandataris',
model: 'mandataris',
},
'http://www.w3.org/ns/person#Person': {
route: 'mandatarissen.persoon.mandaten',
model: 'persoon',
},
'http://data.vlaanderen.be/ns/besluit#Bestuursorgaan': {
route: 'organen.orgaan',
model: 'bestuursorgaan',
},
};
return {
route: mapTargetClassToRoute[targetClass].route,
modelId: await this.searchModelIdForFocusNode(
mapTargetClassToRoute[targetClass].model,
focusNode
),
};
}

async searchModelIdForFocusNode(modelName, focusNode) {
return (
await this.store.query(modelName, {
filter: {
':uri:': focusNode,
},
})
)?.at(0)?.id;
}
}
12 changes: 12 additions & 0 deletions app/models/report.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Model, { attr, hasMany } from '@ember-data/model';

export default class ReportModel extends Model {
@attr('datetime') created;
@attr('boolean') conforms;

@hasMany('validationresult', {
async: true,
inverse: null,
})
validationresults;
}
11 changes: 11 additions & 0 deletions app/models/validationresult.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import Model, { attr } from '@ember-data/model';

export default class ValidationresultModel extends Model {
@attr('string') focusNode;
@attr('string') resultSeverity;
@attr('string') sourceConstraintComponent;
@attr('string') sourceShape;
@attr('string') resultMessage;
@attr('string') value;
@attr('string') targetClassOfFocusNode;
}
1 change: 1 addition & 0 deletions app/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,5 @@ Router.map(function () {
path: '/*wildcard',
});
this.route('session-expired');
this.route('report');
});
43 changes: 43 additions & 0 deletions app/routes/report.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import Route from '@ember/routing/route';

import { service } from '@ember/service';

export default class ReportRoute extends Route {
@service store;
@service router;
@service features;
@service session;
beforeModel(transition) {
this.session.requireAuthentication(transition, 'login');

if (!this.features.isEnabled('shacl-report')) {
this.router.replaceWith('index');
}
}

async model() {
const latestReport = (
await this.store.query('report', {
sort: '-created',
page: { size: 1 },
include: 'validationresults',
})
)?.firstObject;

return {
report: latestReport,
resultsByTargetClass: await this.getMappedResults(latestReport),
};
}

async getMappedResults(report) {
const results = (await report?.validationresults) ?? [];
const map = new Map();

for (const result of results) {
const currentResult = map.get(result.targetClassOfFocusNode) ?? [];
map.set(result.targetClassOfFocusNode, currentResult.concat(result));
}
return map;
}
}
49 changes: 49 additions & 0 deletions app/templates/report.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{{page-title "Report"}}

<AuHeading @skin="2">
SHACL validatierapport ({{this.model.report.id}}
-
{{moment-format this.model.report.created "DD-MM-YYYY HH:mm:ss"}})
</AuHeading>

{{#each this.targetClasses as |targetClass|}}
<AuToolbar class="au-o-box" as |Group|>
<Group>
<AuHeading @skin="2">
{{targetClass}}
</AuHeading>
</Group>
</AuToolbar>

<AuDataTable
@content={{this.filterResultsByTargetClass targetClass}}
@noDataMessage="Geen validatieresultaten gevonden"
@page={{@page}}
@size={{this.lengthOfResultsByTargetClass targetClass}}
as |t|
>
<t.content as |c|>
<c.header>
<th class="au-u-padding-small">Entiteit</th>
<th class="au-u-padding-small">Boodschap</th>
</c.header>

<c.body as |result|>
<td>
{{#let (await (this.getFocusNodeContext result.focusNode result.targetClassOfFocusNode)) as |context|}}
<LinkTo
@route={{context.route}}
@model={{context.modelId}}
class="au-c-link au-u-medium"
>
{{result.focusNode}}
</LinkTo>
{{/let}}
</td>
<td>
{{result.resultMessage}}
</td>
</c.body>
</t.content>
</AuDataTable>
{{/each}}
5 changes: 5 additions & 0 deletions config/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ module.exports = function (environment) {
// ENV.APP.LOG_TRANSITIONS = true;
// ENV.APP.LOG_TRANSITIONS_INTERNAL = true;
// ENV.APP.LOG_VIEW_LOOKUPS = true;

ENV.features['shacl-report'] = true;
}

if (environment === 'test') {
Expand All @@ -76,10 +78,13 @@ module.exports = function (environment) {

ENV.APP.rootElement = '#ember-testing';
ENV.APP.autoboot = false;

ENV.features['shacl-report'] = false;
}

if (environment === 'production') {
// here you can enable a production-specific feature
ENV.features['shacl-report'] = false;
}

ENV.features['show-iv-module'] = true;
Expand Down
12 changes: 12 additions & 0 deletions tests/unit/controllers/report-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { module, test } from 'qunit';
import { setupTest } from 'frontend-lmb/tests/helpers';

module('Unit | Controller | report', function (hooks) {
setupTest(hooks);

// TODO: Replace this with your real tests.
test('it exists', function (assert) {
let controller = this.owner.lookup('controller:report');
assert.ok(controller);
});
});
14 changes: 14 additions & 0 deletions tests/unit/models/report-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { module, test } from 'qunit';

import { setupTest } from 'frontend-lmb/tests/helpers';

module('Unit | Model | report', function (hooks) {
setupTest(hooks);

// Replace this with your real tests.
test('it exists', function (assert) {
let store = this.owner.lookup('service:store');
let model = store.createRecord('report', {});
assert.ok(model);
});
});
14 changes: 14 additions & 0 deletions tests/unit/models/validationresult-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { module, test } from 'qunit';

import { setupTest } from 'frontend-lmb/tests/helpers';

module('Unit | Model | validationresult', function (hooks) {
setupTest(hooks);

// Replace this with your real tests.
test('it exists', function (assert) {
let store = this.owner.lookup('service:store');
let model = store.createRecord('validationresult', {});
assert.ok(model);
});
});
11 changes: 11 additions & 0 deletions tests/unit/routes/report-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { module, test } from 'qunit';
import { setupTest } from 'frontend-lmb/tests/helpers';

module('Unit | Route | report', function (hooks) {
setupTest(hooks);

test('it exists', function (assert) {
let route = this.owner.lookup('route:report');
assert.ok(route);
});
});