Skip to content

Commit

Permalink
Merge pull request #805 from alexgurrola/master
Browse files Browse the repository at this point in the history
Angular 0.12.7: Fix Drag & Drop
  • Loading branch information
alexgurrola authored Dec 5, 2024
2 parents 1a6ced4 + a1e4a62 commit 3db3135
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 26 deletions.
2 changes: 1 addition & 1 deletion packages/angular/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@stratusjs/angular",
"version": "0.12.6",
"version": "0.12.7",
"description": "This is the angular package for StratusJS.",
"scripts": {},
"repository": {
Expand Down
87 changes: 62 additions & 25 deletions packages/angular/src/tree/tree.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -685,9 +685,7 @@ export class TreeComponent extends RootComponent implements OnInit, OnDestroy {

// Search for targetNodeIndex via targetNode and branch
const targetNodeIdentifier = targetNode.model ? targetNode.model.get('id') : null
const targetNodeIndex =
(targetNodeIdentifier !== null && this.nodeIsEqual(parentNode, pastParentNode)) ?
branch.findIndex((n: Node) => n.id === targetNodeIdentifier) : event.previousIndex
let targetNodeIndex = (targetNodeIdentifier !== null) ? branch.findIndex((n: Node) => n.id === targetNodeIdentifier) : event.previousIndex
if (cookie('env') && this.isDebug && targetNodeIndex !== event.previousIndex) {
console.log('target index correction:', targetNodeIndex)
}
Expand Down Expand Up @@ -716,44 +714,78 @@ export class TreeComponent extends RootComponent implements OnInit, OnDestroy {
}
}

/* *
if (cookie('env') && this.isDebug) {
forEach(branch, (node: Node) => {
if (!node.model || !node.model.get) {
// Menu Changes
const setPriority = (branch: Node[]) => {
let priority = 0
return forEach(branch, (node: Node) => {
if (!node.model || !node.model.set) {
return
}
console.log(`current priority for ${node.model.get('name')}:`, node.model.get('priority'))
node.model.set('priority', priority++)
})
}
/* */

// Display Priorities for Debug
const displayPriorities = (node: Node, index: number) => {
if (!node.model || !node.model.get) {
return
}
console.log(`[branch] index ${index}:`, node.model.get('id'), node.model.get('name'))
}

// Handle new cell placement
if (isNumber(targetDropIndex)) {
// Move cell in array
/* *
if (!this.nodeIsEqual(parentNode, pastParentNode)) {
// Target Node Index Correction
if (!targetNodeIndex || targetNodeIndex < 0) {
if (cookie('env') && this.isDebug) {
console.log('[branch] parent change injection:', targetNode.model.get('id'), targetNode.model.get('name'))
}
branch.push(targetNode)
}
targetNodeIndex = branch.findIndex((n: Node) => n.id === targetNodeIdentifier)
/* */
if (cookie('env') && this.isDebug) {
console.log('[branch] priorities:')
forEach(branch, displayPriorities)
console.log('[parent] target index correction:', targetNodeIndex, targetNodeIdentifier)
}
/* */
}
if (cookie('env') && this.isDebug) {
console.log('moveItemInArray:', targetNodeIndex, '->', targetDropIndex)
}
/* */
if (this.nodeIsEqual(parentNode, pastParentNode)) {
moveItemInArray(branch, targetNodeIndex, targetDropIndex)
}
moveItemInArray(branch, targetNodeIndex, targetDropIndex)
// Generate new priority
let priority = 0
forEach(branch, (node: Node) => {
if (!node.model || !node.model.set) {
return
setPriority(branch)
// Display debug data
if (cookie('env') && this.isDebug) {
console.log('new priority:', targetNode.model.get('priority'))
}
}

// Generate new priorities for previous branch
if (!this.nodeIsEqual(parentNode, pastParentNode)) {
// Define Past Branch
const pastBranch: Node[] = pastParentNode ? pastParentNode.children : this.dataRef()
const pastIndex = pastBranch.findIndex((n: Node) => n.id === targetNodeIdentifier)
// Past Branch Correction
if (pastIndex !== -1) {
if (cookie('env') && this.isDebug) {
console.log('[pastBranch] current priorities:')
forEach(pastBranch, displayPriorities)
}
node.model.set('priority', priority++)
/* *
this.removeNode(pastBranch, targetNode)
if (cookie('env') && this.isDebug) {
console.log(`new priority for ${node.model.get('name')}: ${node.model.get('priority')}`)
console.log('[pastBranch] removed element:', pastIndex)
}
/* */
})
// Display debug data
}
// Reset Priorities
setPriority(pastBranch)
if (cookie('env') && this.isDebug) {
console.log('new priority:', targetNode.model.get('priority'))
console.log('[pastParent] new priorities:')
forEach(pastBranch, displayPriorities)
}
}

Expand Down Expand Up @@ -781,6 +813,11 @@ export class TreeComponent extends RootComponent implements OnInit, OnDestroy {
// Start XHR
await targetNode.model.save()

// (API Debug) Save Last Child of Past Parent
// if (pastParentLastChild) {
// await pastParentLastChild.model.save()
// }

// Enable Listeners
this.unsettled = false

Expand Down

0 comments on commit 3db3135

Please sign in to comment.