Skip to content

Commit 83b021a

Browse files
[FEATURE] Affiche le nom de l'élève sélectionné dans la page des missions (PIX-9087)
#7282
2 parents 80a351d + 1d4b737 commit 83b021a

31 files changed

+250
-43
lines changed

1d/app/models/organization-learner.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import Model, { attr } from '@ember-data/model';
2+
3+
export default class OrganizationLearner extends Model {
4+
@attr id;
5+
@attr lastName;
6+
@attr firstName;
7+
@attr division;
8+
@attr organizationId;
9+
}

1d/app/pods/assessment/results/template.hbs

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
{{/if}}
3636
</ul>
3737

38-
<PixButtonLink @route="missions" @shape="rounded" class="details-action">
38+
<PixButtonLink @route="identified.missions" @shape="rounded" class="details-action">
3939
<p>{{t "pages.missions.end-page.back-to-missions"}}</p>
4040
<FaIcon @icon="arrow-right" class="details-action__icon" />
4141
</PixButtonLink>

1d/app/pods/components/robot-dialog/robot-dialog.scss

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
}
3131
}
3232

33-
a::after {
33+
a:not(.internal-link)::after {
3434
display: inline-block;
3535
width: 1rem;
3636
height: 1rem;

1d/app/pods/error/template.hbs

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,7 @@
22
<div class="error">
33
<h1>{{t "pages.error.title"}}</h1>
44
<p>{{t "pages.error.message"}}</p>
5-
<LinkTo class="pix1d-button pix1d-button--small not-found__button" @route="home">{{t "pages.error.backHome"}}</LinkTo>
5+
<LinkTo class="pix1d-button pix1d-button--small not-found__button" @route="identified.missions">{{t
6+
"pages.error.backHome"
7+
}}</LinkTo>
68
</div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import Controller from '@ember/controller';
2+
import { service } from '@ember/service';
3+
4+
export default class Students extends Controller {
5+
@service currentLearner;
6+
7+
get learnerFirstName() {
8+
return this.currentLearner.learner.firstName;
9+
}
10+
}

1d/app/pods/missions/list/template.hbs 1d/app/pods/identified/missions/list/template.hbs

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
{{page-title "Home"}}
22
<div>
3-
<RobotDialog @instruction={{t "pages.missions.start-page.list"}} />
3+
<RobotDialog
4+
@instruction={{t "pages.missions.start-page.list" prenom=this.learnerFirstName backUrl=@model.studentsUrl}}
5+
/>
46
<div class="cards">
5-
<LinkTo @route="missions.mission" @model="recExjO7RHeDI48HK">
7+
<LinkTo @route="identified.missions.mission" @model="recExjO7RHeDI48HK">
68
<MissionCard @title="Recherche sur internet" @colorClass="red" @imageName="internet-search" />
79
</LinkTo>
810

9-
<LinkTo @route="missions.mission" @model="recZtwymXXrtdXRrx">
11+
<LinkTo @route="identified.missions.mission" @model="recZtwymXXrtdXRrx">
1012
<MissionCard @title="Données personnelles" @colorClass="blue" @imageName="personal-data" />
1113
</LinkTo>
1214
</div>

1d/app/pods/missions/mission/resume/unit_test.js 1d/app/pods/identified/missions/mission/resume/unit_test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { module, test } from 'qunit';
2-
import { setupTest } from '../../../../helpers/tests';
2+
import { setupTest } from '../../../../../helpers/tests';
33
import sinon from 'sinon';
44

55
module('Unit | Route | MissionResumeRoute', function (hooks) {
66
setupTest(hooks);
77

88
module('#model', function () {
99
test('should call queryRecord method', async function (assert) {
10-
const route = this.owner.lookup('route:missions.mission.resume');
10+
const route = this.owner.lookup('route:identified.missions.mission.resume');
1111
const store = this.owner.lookup('service:store');
1212
const missionId = 23;
1313
const transition = { to: { parent: { params: { mission_id: missionId } } } };
@@ -21,7 +21,7 @@ module('Unit | Route | MissionResumeRoute', function (hooks) {
2121

2222
module('#afterModel', function () {
2323
test('should redirect to assessment resume route', async function (assert) {
24-
const route = this.owner.lookup('route:missions.mission.resume');
24+
const route = this.owner.lookup('route:identified.missions.mission.resume');
2525
const assessment = Symbol('assessment');
2626
sinon.stub(route.router, 'replaceWith');
2727

1d/app/pods/missions/mission/template.hbs 1d/app/pods/identified/missions/mission/template.hbs

+4-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
{{/if}}
99

1010
<div class="mission-page__details">
11-
<LinkTo @route="missions" class="details-go-back">{{t "pages.missions.start-page.back-to-missions"}}</LinkTo>
11+
<LinkTo @route="identified.missions" class="details-go-back">{{t
12+
"pages.missions.start-page.back-to-missions"
13+
}}</LinkTo>
1214
<p class="details-list__title details-list__title--big">{{t "pages.missions.start-page.purpose-title"}}</p>
1315
<ul class="details-list">
1416
<li class="details-list__item">
@@ -21,7 +23,7 @@
2123
</li>
2224
</ul>
2325

24-
<PixButtonLink @route="missions.mission.resume" @shape="rounded" class="details-action">
26+
<PixButtonLink @route="identified.missions.mission.resume" @shape="rounded" class="details-action">
2527
<p>{{t "pages.missions.start-page.start-mission"}}</p>
2628
<FaIcon @icon="arrow-right" class="details-action__icon" />
2729
</PixButtonLink>

1d/app/pods/identified/route.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import Route from '@ember/routing/route';
2+
import { service } from '@ember/service';
3+
4+
export default class IdentifiedRoute extends Route {
5+
@service router;
6+
@service currentLearner;
7+
8+
async beforeModel() {
9+
if (!this.currentLearner.learner) {
10+
this.router.transitionTo('organization-code');
11+
}
12+
}
13+
14+
async model() {
15+
const currentLearner = this.currentLearner.learner;
16+
return {
17+
studentsUrl: `${currentLearner.schoolUrl}/students?division=${currentLearner.division}`,
18+
};
19+
}
20+
}

1d/app/pods/not-found/template.hbs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<div class="error">
33
<h1>{{t "pages.not-found.title"}}</h1>
44
<p>{{t "pages.not-found.message"}}</p>
5-
<LinkTo class="pix1d-button pix1d-button--small not-found__button" @route="home">{{t
5+
<LinkTo class="pix1d-button pix1d-button--small not-found__button" @route="identified.missions">{{t
66
"pages.not-found.backHome"
77
}}</LinkTo>
88
</div>

1d/app/pods/home/controller.js 1d/app/pods/organization-code/controller.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ export default class Home extends Controller {
1717
}
1818

1919
@action
20-
goToSchool() {
20+
goToSchool(event) {
21+
event.preventDefault();
2122
this.router.transitionTo('school', this.upperCaseCode);
2223
}
2324
}
File renamed without changes.
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import Route from '@ember/routing/route';
2+
import { service } from '@ember/service';
3+
4+
export default class OrganizationCodeRoute extends Route {
5+
@service currentLearner;
6+
7+
async beforeModel() {
8+
this.currentLearner.remove();
9+
}
10+
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{{page-title "Home"}}
2+
23
<RobotDialog @instruction={{t "pages.home.code-instruction"}} />
3-
<div class="school-code">
4+
5+
<form onSubmit={{this.goToSchool}} class="school-code">
46
<PixInputCode
57
@ariaLabel={{t "pages.home.field-description"}}
68
@legend={{t "pages.home.code-description"}}
@@ -10,7 +12,7 @@
1012
class="school-code__input"
1113
/>
1214

13-
<PixButton class="pix1d-button" @triggerAction={{this.goToSchool}} @shape="rounded">
15+
<PixButton class="pix1d-button" @type="submit" @shape="rounded">
1416
{{t "pages.home.go-to-school"}}
1517
</PixButton>
16-
</div>
18+
</form>

1d/app/pods/school/route.js

+6
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,17 @@ import { service } from '@ember/service';
33

44
export default class SchoolRoute extends Route {
55
@service store;
6+
@service currentLearner;
7+
8+
async beforeModel() {
9+
this.currentLearner.remove();
10+
}
611

712
async model(params) {
813
const school = await this.store.findRecord('school', params.code);
914
const divisions = [...new Set(school.organizationLearners.map((learner) => learner.division))];
1015
return {
16+
code: school.code,
1117
name: school.name,
1218
organizationLearners: school.organizationLearners,
1319
divisions: divisions.sort(),

1d/app/pods/school/school.scss

+13-2
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,22 @@
1313
flex-direction: column;
1414
align-items: center;
1515
justify-content: center;
16-
width: 150px;
16+
min-width: 150px;
1717
height: 70px;
18+
color: black;
19+
font-size: 1.125rem;
1820
background: #FFFFFF;
19-
border: 4px solid #FFFFFF;
2021
border-radius: 8px;
2122
box-shadow: 0 0 1px 0 #3D68FF, 8px 8px 32px -8px rgb(61 104 255 / 20%);
23+
24+
&:hover {
25+
background-color: #EBEFFF;
26+
}
27+
}
28+
}
29+
30+
.pix-button--background-blue.learners__item {
31+
&:hover {
32+
background-color: #EBEFFF;
2233
}
2334
}
+11
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
11
import Controller from '@ember/controller';
2+
import { action } from '@ember/object';
3+
import { service } from '@ember/service';
24

35
export default class Students extends Controller {
6+
@service currentLearner;
7+
@service router;
8+
49
queryParams = ['division'];
510

611
uppercaseFirstLetter(name) {
712
return name.charAt(0).toUpperCase() + name.slice(1);
813
}
14+
15+
@action
16+
identifyUser(learner) {
17+
this.currentLearner.setLearner({ ...learner, schoolUrl: this.model.schoolUrl });
18+
this.router.transitionTo('identified.missions');
19+
}
920
}

1d/app/pods/school/students/route.js

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
11
import Route from '@ember/routing/route';
22
import { service } from '@ember/service';
3+
34
export default class StudentsRoute extends Route {
45
@service router;
5-
async model(_, transition) {
6+
7+
queryParams = {
8+
division: '',
9+
};
10+
11+
async model(params) {
612
const school = await this.modelFor('school');
7-
if (transition.to.queryParams.division) {
8-
const division = transition.to.queryParams.division;
13+
const division = params.division;
14+
if (division) {
915
const divisionLearners = school.organizationLearners.filter((learner) => learner.division === division);
1016
return {
1117
division,
1218
organizationLearners: divisionLearners,
19+
schoolUrl: `/schools/${school.code}`,
1320
};
1421
} else {
1522
return this.router.replaceWith('school', school);
+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
<RobotDialog @instruction={{t "pages.school.division.find-name" division=@model.division}} />
1+
<RobotDialog @instruction={{t "pages.school.division.find-name" division=@model.division backUrl=@model.schoolUrl}} />
22
<div class="learners">
33
{{#each @model.organizationLearners as |learner|}}
4-
<LinkTo @route="missions" class="learners__item">
4+
<PixButton @triggerAction={{fn this.identifyUser learner}} class="learners__item">
55
<p>{{learner.firstName}}</p>
66
<p>{{this.uppercaseFirstLetter learner.lastName}}</p>
7-
</LinkTo>
7+
</PixButton>
88
{{/each}}
99
</div>

1d/app/router.js

+8-5
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,18 @@ export default class Router extends EmberRouter {
1717
}
1818

1919
Router.map(function () {
20-
this.route('home', { path: '/' });
20+
this.route('organization-code');
2121
this.route('school', { path: '/schools/:code' }, function () {
2222
this.route('divisions', { path: '/' });
2323
this.route('students');
2424
});
25-
this.route('missions', function () {
26-
this.route('list', { path: '/' });
27-
this.route('mission', { path: '/:mission_id' }, function () {
28-
this.route('resume');
25+
26+
this.route('identified', { path: '/' }, function () {
27+
this.route('missions', { path: '/' }, function () {
28+
this.route('list', { path: '/' });
29+
this.route('mission', { path: 'missions/:mission_id' }, function () {
30+
this.route('resume');
31+
});
2932
});
3033
});
3134

1d/app/services/current-learner.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import Service from '@ember/service';
2+
3+
export default class CurrentLearnerService extends Service {
4+
get learner() {
5+
return JSON.parse(localStorage.getItem('learner'));
6+
}
7+
8+
async setLearner(learner) {
9+
localStorage.setItem('learner', JSON.stringify(learner));
10+
}
11+
12+
async remove() {
13+
localStorage.removeItem('learner');
14+
}
15+
}

0 commit comments

Comments
 (0)