-
Notifications
You must be signed in to change notification settings - Fork 4
feat(territories): Prévoir le mode 'DragNDrop' sur les territoires du … #468
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -165,6 +165,13 @@ class Territories extends Control { | |||||||||||
| this.getContainer().classList.add("gpf-button-no-gutter"); | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| // draggable des vues | ||||||||||||
| var self = this; | ||||||||||||
| this.createDraggableElement( | ||||||||||||
| self.element.querySelector("#gpf-territories-views-listview-entries-id"), | ||||||||||||
| self | ||||||||||||
| ); | ||||||||||||
|
|
||||||||||||
| /** | ||||||||||||
| * event triggered when a territory is loaded | ||||||||||||
| * | ||||||||||||
|
|
@@ -211,10 +218,7 @@ class Territories extends Control { | |||||||||||
| var view = this._createTerritoryView(territory); | ||||||||||||
| if (entry && view) { | ||||||||||||
| this.panelTerritoriesEntriesContainer.appendChild(entry); | ||||||||||||
| var panelTerritoriesViewsContainer = this.element.querySelector("#gpf-territories-views-listview-entries-id"); | ||||||||||||
| if (panelTerritoriesViewsContainer) { | ||||||||||||
| panelTerritoriesViewsContainer.appendChild(view); | ||||||||||||
| } | ||||||||||||
| this.panelTerritoriesViewsContainer.appendChild(view); | ||||||||||||
| var count = this.element.querySelector("#gpf-territories-views-count-id"); | ||||||||||||
| if (count) { | ||||||||||||
| var nb = this.territories.filter(t => !t.isRemoved).length + 1; | ||||||||||||
|
|
@@ -224,6 +228,7 @@ class Territories extends Control { | |||||||||||
| isRemoved : false, | ||||||||||||
| isAdded : isAdded, | ||||||||||||
| data : territory, | ||||||||||||
| initialIndex : this.territories.length, | ||||||||||||
| domEntry : entry, | ||||||||||||
| domView : view | ||||||||||||
| }); | ||||||||||||
|
|
@@ -249,7 +254,7 @@ class Territories extends Control { | |||||||||||
| * Remove a territory | ||||||||||||
| * | ||||||||||||
| * @param {String} territory - territory id (FRA, MTQ, ...) | ||||||||||||
| * @param {Boolean} [force=false] - force removal even if territory was added manually | ||||||||||||
| * @param {Boolean} [force=false] - force removal | ||||||||||||
| * @returns {Boolean} - true|false | ||||||||||||
| * @public | ||||||||||||
| * @example | ||||||||||||
|
|
@@ -261,14 +266,16 @@ class Territories extends Control { | |||||||||||
| for (let i = 0; i < this.territories.length; i++) { | ||||||||||||
| const o = this.territories[i]; | ||||||||||||
| if (o.data.id === territory.data.id) { | ||||||||||||
| this.territories[i].domEntry.remove(); | ||||||||||||
| this.territories[i].domView.remove(); | ||||||||||||
| if (!force) { | ||||||||||||
| // on ne le supprime pas de la liste des territoires | ||||||||||||
| // mais on le masque uniquement | ||||||||||||
| this.territories[i].isRemoved = true; | ||||||||||||
| this.territories[i].domEntry.classList.add("gpf-hidden"); | ||||||||||||
| this.territories[i].domView.style.display = "none"; | ||||||||||||
| } else { | ||||||||||||
| // on le supprime de la liste des territoires | ||||||||||||
| this.territories[i].domEntry.remove(); | ||||||||||||
| this.territories[i].domView.remove(); | ||||||||||||
| this.territories.splice(i, 1); | ||||||||||||
| } | ||||||||||||
| found = true; | ||||||||||||
|
|
@@ -402,6 +409,7 @@ class Territories extends Control { | |||||||||||
| * isAdded : { Boolean }, | ||||||||||||
| * domView : { HTMLelment }, | ||||||||||||
| * domEntry : { HTMLelment }, | ||||||||||||
| * initialIndex : { Number }, // index d’origine | ||||||||||||
| * data : { | ||||||||||||
| * id: "MTQ", | ||||||||||||
| * title: "Martinique", | ||||||||||||
|
|
@@ -434,6 +442,8 @@ class Territories extends Control { | |||||||||||
| this.containerTerritoriesOptions = null; | ||||||||||||
| /** @private */ | ||||||||||||
| this.panelTerritoriesEntriesContainer = null; | ||||||||||||
| /** @private */ | ||||||||||||
| this.panelTerritoriesViewsContainer = null; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| /** | ||||||||||||
|
|
@@ -460,6 +470,7 @@ class Territories extends Control { | |||||||||||
| // menu views button | ||||||||||||
| var territoriesPanelMenuViewsDiv = this._createTerritoriesPanelMenuViewsDivElement(); | ||||||||||||
| territoriesPanel.appendChild(territoriesPanelMenuViewsDiv); | ||||||||||||
| this.panelTerritoriesViewsContainer = territoriesPanelMenuViewsDiv.querySelector("#gpf-territories-views-listview-entries-id"); | ||||||||||||
|
|
||||||||||||
| // INFO | ||||||||||||
| // Les territoires seront ajoutés dans ce conteneur | ||||||||||||
|
|
@@ -788,23 +799,31 @@ class Territories extends Control { | |||||||||||
| logger.trace(e); | ||||||||||||
| // On supprime tous les territoires ajoutées manuellement via le bouton "Ajouter une vue" | ||||||||||||
| // et on recharge la liste initiale | ||||||||||||
| var territories = [...this.territories]; | ||||||||||||
| for (let index = 0; index < territories.length; index++) { | ||||||||||||
| const territory = territories[index]; | ||||||||||||
| for (let index = 0; index < this.territories.length; index++) { | ||||||||||||
| const territory = this.territories[index]; | ||||||||||||
| if (territory.isAdded) { | ||||||||||||
| // on supprime les territoires ajoutés manuellement | ||||||||||||
| this.removeTerritory(territory, true); | ||||||||||||
| } else { | ||||||||||||
| // on ré-affiche les territoires non supprimés | ||||||||||||
| if (territory.isRemoved) { | ||||||||||||
| this.panelTerritoriesEntriesContainer.appendChild(territory.domEntry); | ||||||||||||
| var panelTerritoriesViewsContainer = this.element.querySelector("#gpf-territories-views-listview-entries-id"); | ||||||||||||
| if (panelTerritoriesViewsContainer) { | ||||||||||||
| panelTerritoriesViewsContainer.appendChild(territory.domView); | ||||||||||||
| } | ||||||||||||
| territory.domEntry.classList.remove("gpf-hidden"); | ||||||||||||
| territory.domView.style.display = ""; | ||||||||||||
| territory.isRemoved = false; | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
| // reordonne la liste des territoires selon l'index initial | ||||||||||||
| this.territories.sort((a, b) => a.initialIndex - b.initialIndex); | ||||||||||||
| // mise à jour le DOM principal | ||||||||||||
|
||||||||||||
| // mise à jour le DOM principal | |
| // mise à jour du DOM principal |
Copilot
AI
Nov 30, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The JSDoc comment for onReorderTerritoriesViews is incomplete. It should describe what the method does (reorders territories based on drag-and-drop interaction) and specify the type of event parameter (e.g., Sortable event object).
| * ... | |
| * @param {Event} e - ... | |
| * Reorders the territories based on the current order of views in the container, | |
| * typically after a drag-and-drop interaction. | |
| * @param {Event} e - The drag-and-drop event object (e.g., from a Sortable or Draggable interaction). |
Copilot
AI
Nov 30, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corrected 'mise à jour' to 'mise à jour de' for proper grammar.
| // mise à jour l’ordre des territoires dans le DOM principal | |
| // mise à jour de l’ordre des territoires dans le DOM principal |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Iterating through
this.territorieswhile callingremoveTerritory(territory, true)modifies the array during iteration (viaspliceat line 279), causing elements to be skipped. Use a reverse loop or iterate over a copy of the array.