Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
yaf authored and AndreiaPena committed Dec 16, 2024
1 parent 4cbf727 commit 0c7f7a3
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 87 deletions.
90 changes: 90 additions & 0 deletions admin/app/components/certifications/header.gjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import PixButton from '@1024pix/pix-ui/components/pix-button';
import PixTooltip from '@1024pix/pix-ui/components/pix-tooltip';
import { service } from '@ember/service';
import { action } from '@ember/object';
import { tracked } from '@glimmer/tracking';
import ConfirmPopup from '../confirm-popup';
import Component from '@glimmer/component';


export default class CertificationsHeader extends Component {
@service accessControl;

@tracked isModalDisplayed = false;
@tracked confirmMessage = null;

get canPublish() {
return (
!this.args.juryCertificationSummaries.some(
(certification) => certification.status === 'error' && !certification.isCancelled,
) && this.args.session.isFinalized
);
}

@action
displayConfirmationModal() {
this.confirmMessage = this.args.session.isPublished
? 'Souhaitez-vous dépublier la session ?'
: 'Souhaitez-vous publier la session ?';
this.isModalDisplayed = true;
}

@action
onModalCancel() {
this.isModalDisplayed = false;
}

@action
async toggleSessionPublication() {
if (this.args.session.isPublished) {
await this.args.unpublishSession();
} else {
await this.args.publishSession();
}
this.isModalDisplayed = false;
}

<template>
<header class="certification-list-page__header">
<h2>Certifications</h2>
{{#if this.accessControl.hasAccessToCertificationActionsScope}}
<div class="btn-group" role="group">

{{#if @session.isPublished}}
<PixButton @triggerAction={{this.displayConfirmationModal}}>Dépublier la session</PixButton>
{{else}}

{{#if this.canPublish}}
<PixButton @triggerAction={{this.displayConfirmationModal}}>Publier la session</PixButton>
{{else}}

<PixTooltip @position="left" @isWide={{true}}>
<:triggerElement>
<PixButton
@triggerAction={{this.displayConfirmationModal}}
@isDisabled={{true}}
>
Publier la session
</PixButton>
</:triggerElement>
<:tooltip>
Vous ne pouvez pas publier la session tant qu'elle n'est pas finalisée ou qu'il reste des
certifications en erreur.
</:tooltip>
</PixTooltip>
{{/if}}

{{/if}}
</div>
{{/if}}
</header>


<ConfirmPopup
@message={{this.confirmMessage}}
@confirm={{this.toggleSessionPublication}}
@cancel={{this.onModalCancel}}
@show={{this.isModalDisplayed}}
/>
</template>
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,53 +7,17 @@ const DEFAULT_PAGE_NUMBER = 1;
export default class ListController extends Controller {
@service pixToast;
@service store;
@service accessControl;

@tracked pageNumber = DEFAULT_PAGE_NUMBER;
@tracked pageSize = 10;

@tracked displayConfirm = false;
@tracked confirmMessage = null;

get canPublish() {
const juryCertificationSummaries = this.model.juryCertificationSummaries;
const { session } = this.model;

return (
!juryCertificationSummaries.some(
(certification) => certification.status === 'error' && !certification.isCancelled,
) && session.isFinalized
);
}

get sortedCertificationJurySummaries() {
return this.model.juryCertificationSummaries
.sortBy('numberOfCertificationIssueReportsWithRequiredAction')
.reverse();
}

@action
displayCertificationStatusUpdateConfirmationModal() {
const sessionIsPublished = this.model.session.isPublished;

if (!this.canPublish && !sessionIsPublished) return;

this.confirmMessage = sessionIsPublished
? 'Souhaitez-vous dépublier la session ?'
: 'Souhaitez-vous publier la session ?';
this.displayConfirm = true;
}

@action
async toggleSessionPublication() {
const isPublished = this.model.session.isPublished;
if (isPublished) {
await this.unpublishSession();
} else {
await this.publishSession();
}
}

async unpublishSession() {
try {
await this.model.session.save({ adapterOptions: { updatePublishedCertifications: true, toPublish: false } });
Expand All @@ -64,9 +28,9 @@ export default class ListController extends Controller {
} finally {
await this.forceRefreshModelFromBackend();
}
this.hideConfirmationModal();
}

@action
async publishSession() {
try {
await this.model.session.save({ adapterOptions: { updatePublishedCertifications: true, toPublish: true } });
Expand All @@ -80,9 +44,9 @@ export default class ListController extends Controller {
if (this.model.session.isPublished) {
this.pixToast.sendSuccessNotification({ message: 'Les certifications ont été correctement publiées.' });
}
this.hideConfirmationModal();
}

@action
notifyError(error) {
if (error.errors && error.errors[0] && error.errors[0].detail) {
this.pixToast.sendErrorNotification({ message: error.errors[0].detail });
Expand All @@ -91,16 +55,8 @@ export default class ListController extends Controller {
}
}

@action
async forceRefreshModelFromBackend() {
await this.store.findRecord('session', this.model.session.id, { reload: true });
}

hideConfirmationModal() {
this.displayConfirm = false;
}

@action
onCancelConfirm() {
this.displayConfirm = false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,12 @@
<section>
<div class="certification-list-page">

<header class="certification-list-page__header">
<h2>Certifications</h2>
{{#if this.accessControl.hasAccessToCertificationActionsScope}}
<div class="btn-group" role="group">

{{#if this.model.session.isPublished}}
<PixButton @triggerAction={{this.displayCertificationStatusUpdateConfirmationModal}}>Dépublier la session</PixButton>
{{else}}

{{#if this.canPublish}}
<PixButton @triggerAction={{this.displayCertificationStatusUpdateConfirmationModal}}>Publier la session</PixButton>
{{else}}

<PixTooltip @position="left" @isWide={{true}}>
<:triggerElement>
<PixButton
@triggerAction={{this.displayCertificationStatusUpdateConfirmationModal}}
@isDisabled={{true}}
>
Publier la session
</PixButton>
</:triggerElement>
<:tooltip>
Vous ne pouvez pas publier la session tant qu'elle n'est pas finalisée ou qu'il reste des
certifications en erreur.
</:tooltip>
</PixTooltip>
{{/if}}

{{/if}}
</div>
{{/if}}
</header>
<Certifications::Header
@session={{this.model.session}}
@juryCertificationSummaries={{this.model.juryCertificationSummaries}}
@unpublishSession={{this.unpublishSession}}
@publishSession={{this.publishSession}}
/>

<div>
<Certifications::List
Expand All @@ -46,10 +19,3 @@
</div>
</div>
</section>

<ConfirmPopup
@message={{this.confirmMessage}}
@confirm={{action this.toggleSessionPublication}}
@cancel={{action this.onCancelConfirm}}
@show={{this.displayConfirm}}
/>

0 comments on commit 0c7f7a3

Please sign in to comment.