Skip to content

Commit

Permalink
refactor(admin): make component handle new features more easily
Browse files Browse the repository at this point in the history
  • Loading branch information
frinyvonnick authored and Alexandre-Monney committed Feb 5, 2025
1 parent ec767f3 commit de2f75d
Show file tree
Hide file tree
Showing 12 changed files with 277 additions and 590 deletions.
80 changes: 37 additions & 43 deletions admin/app/components/organizations/information-section-edit.gjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@ import PixButton from '@1024pix/pix-ui/components/pix-button';
import PixCheckbox from '@1024pix/pix-ui/components/pix-checkbox';
import PixInput from '@1024pix/pix-ui/components/pix-input';
import PixSelect from '@1024pix/pix-ui/components/pix-select';
import { fn } from '@ember/helper';
import { concat, fn, get } from '@ember/helper';
import { on } from '@ember/modifier';
import { action } from '@ember/object';
import { service } from '@ember/service';
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { t } from 'ember-intl';
import { and, eq, not } from 'ember-truth-helpers';
import lodashGet from 'lodash/get';
import set from 'lodash/set';
import Organization from 'pix-admin/models/organization';

export default class OrganizationInformationSectionEditionMode extends Component {
@service accessControl;
Expand Down Expand Up @@ -55,7 +59,7 @@ export default class OrganizationInformationSectionEditionMode extends Component

@action
updateFormCheckBoxValue(key) {
this.form[key] = !this.form[key];
set(this.form, key, !lodashGet(this.form, key));
}

@action
Expand Down Expand Up @@ -84,12 +88,10 @@ export default class OrganizationInformationSectionEditionMode extends Component
this.args.organization.set('dataProtectionOfficerEmail', this.form.dataProtectionOfficerEmail);
this.args.organization.set('email', this.form.email);
this.args.organization.set('credit', this.form.credit);
this.args.organization.set('isManagingStudents', this.form.isManagingStudents);
this.args.organization.set('documentationUrl', this.form.documentationUrl);
this.args.organization.set('showSkills', this.form.showSkills);
this.args.organization.set('identityProviderForCampaigns', this.form.identityProviderForCampaigns);
this.args.organization.set('isMultipleSendingAssessmentEnabled', this.form.isMultipleSendingAssessmentEnabled);
this.args.organization.set('isPlacesManagementEnabled', this.form.isPlacesManagementEnabled);

this.args.organization.set('features', this.form.features);

this.closeAndResetForm();
return this.args.onSubmit();
Expand All @@ -104,13 +106,11 @@ export default class OrganizationInformationSectionEditionMode extends Component
this.form.dataProtectionOfficerEmail = this.args.organization.dataProtectionOfficerEmail;
this.form.email = this.args.organization.email;
this.form.credit = this.args.organization.credit;
this.form.isManagingStudents = this.args.organization.isManagingStudents;
this.form.documentationUrl = this.args.organization.documentationUrl;
this.form.showSkills = this.args.organization.showSkills;
this.form.isMultipleSendingAssessmentEnabled = this.args.organization.isMultipleSendingAssessmentEnabled;
this.form.isPlacesManagementEnabled = this.args.organization.isPlacesManagementEnabled;
this.form.identityProviderForCampaigns =
this.args.organization.identityProviderForCampaigns ?? this.noIdentityProviderOption.value;

this.form.features = JSON.parse(JSON.stringify(this.args.organization.features));
}

<template>
Expand Down Expand Up @@ -198,13 +198,6 @@ export default class OrganizationInformationSectionEditionMode extends Component
><:label>Lien vers la documentation</:label></PixInput>
</div>

<div class="form-field">
<PixCheckbox
@checked={{this.form.showSkills}}
{{on "change" (fn this.updateFormCheckBoxValue "showSkills")}}
><:label>Affichage des acquis dans l'export de résultats</:label></PixCheckbox>
</div>

<div class="form-field">
<PixSelect
@options={{this.identityProviderOptions}}
Expand All @@ -225,33 +218,12 @@ export default class OrganizationInformationSectionEditionMode extends Component
><:label>Adresse e-mail d'activation SCO</:label></PixInput>
</div>

{{#if this.isManagingStudentAvailable}}
<div class="form-field">
<PixCheckbox
@checked={{this.form.isManagingStudents}}
{{on "change" (fn this.updateFormCheckBoxValue "isManagingStudents")}}
><:label>Gestion d’élèves/étudiants</:label></PixCheckbox>
</div>
{{/if}}
<FeaturesForm
@features={{this.form.features}}
@updateFormCheckBoxValue={{this.updateFormCheckBoxValue}}
@isManagingStudentAvailable={{this.isManagingStudentAvailable}}
/>

<div class="form-field">
<PixCheckbox
@id="isMultipleSendingAssessmentEnabled"
@checked={{this.form.isMultipleSendingAssessmentEnabled}}
{{on "change" (fn this.updateFormCheckBoxValue "isMultipleSendingAssessmentEnabled")}}
>
<:label>Activer l'envoi multiple pour les campagnes de type évaluation</:label>
</PixCheckbox>
</div>
<div class="form-field">
<PixCheckbox
@id="isPlacesManagementEnabled"
@checked={{this.form.isPlacesManagementEnabled}}
{{on "change" (fn this.updateFormCheckBoxValue "isPlacesManagementEnabled")}}
>
<:label>Activer la page Places sur PixOrga</:label>
</PixCheckbox>
</div>
<div class="form-actions">
<PixButton @size="small" @variant="secondary" @triggerAction={{this.closeAndResetForm}}>
{{t "common.actions.cancel"}}
Expand All @@ -264,3 +236,25 @@ export default class OrganizationInformationSectionEditionMode extends Component
</div>
</template>
}

function keys(obj) {
return Object.keys(obj);
}

const FeaturesForm = <template>
{{#each (keys Organization.editableFeatureList) as |feature|}}
{{#let
(get @features feature) (concat "components.organizations.information-section-view.features." feature)
as |organizationFeature featureLabel|
}}
{{#if (not (and (eq feature "IS_MANAGING_STUDENTS") (not @isManagingStudentAvailable)))}}
<div class="form-field">
<PixCheckbox
@checked={{organizationFeature.active}}
{{on "change" (fn @updateFormCheckBoxValue (concat "features." feature ".active"))}}
><:label>{{t featureLabel}}</:label></PixCheckbox>
</div>
{{/if}}
{{/let}}
{{/each}}
</template>;
114 changes: 64 additions & 50 deletions admin/app/components/organizations/information-section-view.gjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ import PixButton from '@1024pix/pix-ui/components/pix-button';
import PixButtonLink from '@1024pix/pix-ui/components/pix-button-link';
import PixNotificationAlert from '@1024pix/pix-ui/components/pix-notification-alert';
import PixTag from '@1024pix/pix-ui/components/pix-tag';
import { concat, get } from '@ember/helper';
import { LinkTo } from '@ember/routing';
import { service } from '@ember/service';
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { t } from 'ember-intl';
import { eq } from 'ember-truth-helpers';
import ENV from 'pix-admin/config/environment';
import Organization from 'pix-admin/models/organization';

export default class OrganizationInformationSection extends Component {
@service oidcIdentityProviders;
Expand Down Expand Up @@ -53,12 +56,6 @@ export default class OrganizationInformationSection extends Component {
return urlDashboardPrefix && urlDashboardPrefix + this.args.organization.id;
}

displayBooleanState = (bool) => {
const yes = this.intl.t('common.words.yes');
const no = this.intl.t('common.words.no');
return bool ? yes : no;
};

<template>
<div class="organization__data">
<h2 class="organization__name">{{@organization.name}}</h2>
Expand Down Expand Up @@ -143,55 +140,12 @@ export default class OrganizationInformationSection extends Component {
<br />

<li>Adresse e-mail d'activation SCO : {{@organization.email}}</li>

<br />

<li>Lien vers le formulaire du Net Promoter Score :
{{#if @organization.formNPSUrl}}
<a
href="{{@organization.formNPSUrl}}"
target="_blank"
rel="noopener noreferrer"
>{{@organization.formNPSUrl}}</a>
{{else}}
Non spécifié
{{/if}}
</li>
<li>Affichage du Net Promoter Score :
{{this.displayBooleanState @organization.showNPS}}
</li>
</ul>
<h3 class="page-section__title page-section__title--sub">Fonctionnalités disponibles : </h3>
<ul class="organization-information-section__details__list">
<li>Affichage des acquis dans l'export de résultats :
{{this.displayBooleanState @organization.showSkills}}
</li>
{{#if this.isManagingStudentAvailable}}
<li>Gestion d’élèves/étudiants :
{{this.displayBooleanState @organization.isManagingStudents}}
</li>
{{/if}}
<li>Activer l'envoi multiple sur les campagnes d'évaluation :
{{this.displayBooleanState @organization.isMultipleSendingAssessmentEnabled}}
</li>
<li>Activer la page Places sur PixOrga :
{{this.displayBooleanState @organization.isPlacesManagementEnabled}}
</li>
{{#if @organization.code}}
<br />
<li>Code : {{@organization.code}}</li>
{{/if}}
{{#if @organization.isLearnerImportEnabled}}
<li>Import activé ({{@organization.learnerImportFormatName}})</li>
{{/if}}
{{#if @organization.isComputeCertificabilityEnabled}}
<li>Certificabilité automatique activée</li>
{{/if}}
{{#if @organization.isAttestationsEnabled}}
<li>{{t "components.organizations.information-section-view.features.attestations"}}</li>
{{/if}}

</ul>
<FeaturesSection @features={{@organization.features}} />
{{#if this.accessControl.hasAccessToOrganizationActionsScope}}
<div class="form-actions">
<PixButton @variant="secondary" @size="small" @triggerAction={{@toggleEditMode}}>
Expand Down Expand Up @@ -219,3 +173,63 @@ export default class OrganizationInformationSection extends Component {
</div>
</template>
}

function keys(obj) {
return Object.keys(obj);
}

const FeaturesSection = <template>
<h3 class="page-section__title page-section__title--sub">{{t
"components.organizations.information-section-view.features.title"
}}
:
</h3>
<ul class="organization-information-section__details__list">
{{#each (keys Organization.featureList) as |feature|}}
{{#let
(get @features feature) (concat "components.organizations.information-section-view.features." feature)
as |organizationFeature featureLabel|
}}
<li>
{{#if (eq feature "SHOW_NPS")}}
<Feature @label={{t featureLabel}} @value={{organizationFeature.active}}>
<a
rel="noopener noreferrer"
href={{organizationFeature.params.formNPSUrl}}
target="_blank"
>{{organizationFeature.params.formNPSUrl}}</a>
</Feature>
{{else if (eq feature "LEARNER_IMPORT")}}
<Feature @label={{t featureLabel}} @value={{organizationFeature.active}}>
{{organizationFeature.params.name}}
</Feature>
{{else if (eq feature "ATTESTATIONS_MANAGEMENT")}}
<Feature @label={{t featureLabel}} @value={{organizationFeature.active}}>
6ème
</Feature>
{{else}}
<Feature @label={{t featureLabel}} @value={{organizationFeature.active}} />
{{/if}}
</li>
{{/let}}
{{/each}}
</ul>
</template>;

function displayBooleanState(bool) {
return bool ? 'common.words.yes' : 'common.words.no';
}

const Feature = <template>
{{@label}}
:
{{#if (has-block)}}
{{#if @value}}
{{yield}}
{{else}}
{{t "common.words.no"}}
{{/if}}
{{else}}
{{t (displayBooleanState @value)}}
{{/if}}
</template>;
16 changes: 0 additions & 16 deletions admin/app/models/organization-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,6 @@ const Validations = buildValidations({
}),
],
},
isManagingStudents: {
validators: [
validator('inclusion', {
in: [true, false],
}),
],
},
documentationUrl: {
validators: [
validator('absolute-url', {
Expand All @@ -101,13 +94,6 @@ const Validations = buildValidations({
}),
],
},
showSkills: {
validators: [
validator('inclusion', {
in: [true, false],
}),
],
},
});

export default class OrganizationForm extends Model.extend(Validations) {
Expand All @@ -119,9 +105,7 @@ export default class OrganizationForm extends Model.extend(Validations) {
@attr('string') dataProtectionOfficerEmail;
@attr('string') email;
@attr('number') credit;
@attr('string') isManagingStudents;
@attr('string') documentationUrl;
@attr('boolean') showSkills;
@attr() identityProviderForCampaigns;

#getErrorAttribute(name) {
Expand Down
Loading

0 comments on commit de2f75d

Please sign in to comment.