-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ admin: Allow to access attach-target-profile without existing one
- Loading branch information
Showing
13 changed files
with
370 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
admin/app/components/complementary-certifications/attach-badges/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
import { action } from '@ember/object'; | ||
import { service } from '@ember/service'; | ||
import { tracked } from '@glimmer/tracking'; | ||
|
||
const DEFAULT_BADGE_LEVEL = '1'; | ||
|
||
import Component from '@glimmer/component'; | ||
|
||
export default class add extends Component { | ||
@service notifications; | ||
@service router; | ||
@service store; | ||
|
||
@tracked isSubmitDisabled = true; | ||
@tracked isSubmitting = false; | ||
@tracked selectedTargetProfile; | ||
|
||
#notifyOrganizations = true; | ||
#targetProfileBadges = new Map(); | ||
|
||
get hasExternalJury() { | ||
return this.args.complementaryCertification.hasExternalJury; | ||
} | ||
|
||
@action | ||
async onError(errorMessage) { | ||
if (errorMessage) { | ||
this.notifications.error(errorMessage); | ||
} | ||
} | ||
|
||
@action | ||
async onSelection(selectedAttachableTargetProfile) { | ||
if (selectedAttachableTargetProfile) { | ||
this.selectedTargetProfile = selectedAttachableTargetProfile; | ||
this.#targetProfileBadges = new Map(); | ||
this.isSubmitDisabled = false; | ||
} | ||
} | ||
|
||
@action | ||
onReset() { | ||
this.selectedTargetProfile = undefined; | ||
this.#targetProfileBadges = new Map(); | ||
this.#notifyOrganizations = true; | ||
this.isSubmitDisabled = true; | ||
this.isSubmitting = false; | ||
} | ||
|
||
@action | ||
onBadgeUpdated({ update: { badgeId, fieldName, fieldValue } }) { | ||
this.#updateBadge({ badgeId, fieldName, fieldValue }); | ||
} | ||
|
||
@action | ||
onNotificationUpdated({ target }) { | ||
this.#notifyOrganizations = target.checked; | ||
} | ||
|
||
@action | ||
async onCancel() { | ||
this.router.transitionTo('authenticated.complementary-certifications.complementary-certification.details'); | ||
} | ||
|
||
@action | ||
async onSubmit(event) { | ||
event.preventDefault(); | ||
this.isSubmitting = true; | ||
try { | ||
const complementaryCertification = this.args.complementaryCertification; | ||
|
||
const complementaryCertificationBadges = this.store.peekAll('complementary-certification-badge').toArray(); | ||
|
||
complementaryCertificationBadges.forEach((complementaryCertificationBadge) => { | ||
complementaryCertification.complementaryCertificationBadges.removeObject(complementaryCertificationBadge); | ||
}); | ||
|
||
this.#targetProfileBadges.forEach((badge, badgeId) => { | ||
const aBadge = this.store.createRecord('complementary-certification-badge', { | ||
complementaryCertification, | ||
badgeId, | ||
level: badge.level ?? DEFAULT_BADGE_LEVEL, | ||
imageUrl: badge['certificate-image'], | ||
label: badge['certificate-label'], | ||
certificateMessage: badge['certificate-message'], | ||
temporaryCertificateMessage: badge['certificate-temporary-message'], | ||
stickerUrl: badge['certificate-sticker'], | ||
minimumEarnedPix: badge['minimum-earned-pix'], | ||
}); | ||
complementaryCertification.complementaryCertificationBadges.pushObject(aBadge); | ||
}); | ||
|
||
await complementaryCertification.save({ | ||
adapterOptions: { | ||
attachBadges: true, | ||
targetProfileId: this.args.currentTargetProfile?.id, | ||
notifyOrganizations: this.#notifyOrganizations, | ||
}, | ||
}); | ||
|
||
this.router.transitionTo('authenticated.complementary-certifications.complementary-certification.details'); | ||
|
||
this.notifications.success( | ||
`Profil cible rattaché à la certification ${complementaryCertification.label} mis à jour avec succès !`, | ||
); | ||
} catch (error) { | ||
console.error({ error }); | ||
await this.onError("Une erreur est survenue lors de l'enregistrement du profil cible."); | ||
} finally { | ||
this.isSubmitting = false; | ||
} | ||
} | ||
|
||
#updateBadge({ badgeId, fieldName, fieldValue }) { | ||
const currentBadge = this.#targetProfileBadges.get(badgeId); | ||
this.#targetProfileBadges.set(badgeId, { | ||
...currentBadge, | ||
[fieldName]: fieldValue, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
.../complementary-certifications/complementary-certification/attach-target-profile/update.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import controller from './new.js'; | ||
|
||
export default controller; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
...ted/complementary-certifications/complementary-certification/attach-target-profile/new.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import Route from '@ember/routing/route'; | ||
import { service } from '@ember/service'; | ||
|
||
export default class AttachTargetProfileNewRoute extends Route { | ||
@service accessControl; | ||
|
||
beforeModel() { | ||
this.accessControl.restrictAccessTo( | ||
['isSuperAdmin'], | ||
'authenticated.complementary-certifications.complementary-certification', | ||
); | ||
} | ||
|
||
model(params) { | ||
const complementaryCertification = this.modelFor( | ||
'authenticated.complementary-certifications.complementary-certification', | ||
); | ||
|
||
return { | ||
complementaryCertification, | ||
currentTargetProfile: null, | ||
}; | ||
} | ||
|
||
resetController(controller, isExiting) { | ||
if (isExiting) { | ||
controller.onReset(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
...ed/complementary-certifications/complementary-certification/attach-target-profile/new.hbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<ComplementaryCertifications::AttachBadges | ||
@complementaryCertification={{@model.complementaryCertification}} | ||
@currentTargetProfile={{null}} | ||
/> |
4 changes: 4 additions & 0 deletions
4
...complementary-certifications/complementary-certification/attach-target-profile/update.hbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<ComplementaryCertifications::AttachBadges | ||
@complementaryCertification={{@model.complementaryCertification}} | ||
@currentTargetProfile={{@model.currentTargetProfile}} | ||
/> |
Oops, something went wrong.