-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #493 from bounswe/feature/frontend_integrate_map_b…
…ackend Implement category trees and integrate with backend for map page. Add victim page with quick add need
- Loading branch information
Showing
13 changed files
with
539 additions
and
614 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
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
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,56 @@ | ||
export class Node { | ||
id | ||
data | ||
children | ||
parent | ||
|
||
constructor(id, data, children, parent) { | ||
this.id = id | ||
this.data = data | ||
this.children = children | ||
this.parent = parent | ||
} | ||
|
||
getAllParentCategories() { | ||
if (this.parent.data === "") | ||
return [this] | ||
return [this, ...this.parent.getAllParentCategories()] | ||
} | ||
|
||
findCategoryWithId(id) { | ||
if (this.id === id) { | ||
return this | ||
} else { | ||
for(const child of this.children){ | ||
let cat = child.findCategoryWithId(id) | ||
if (cat) | ||
return cat | ||
} | ||
return null | ||
} | ||
} | ||
|
||
isChildCategory(id) { | ||
if (this.id === id) { | ||
return true | ||
} else { | ||
return !this.children.every(child => !child.isChildCategory(id)) | ||
} | ||
} | ||
|
||
static createFromArray(json, parent) { | ||
return json.map(item => { | ||
const children = [] | ||
const node = new Node(item.id, item.data, children, parent) | ||
children.push(...Node.createFromArray(item.children, node)) | ||
return node | ||
}) | ||
} | ||
} | ||
|
||
export class RootNode extends Node { | ||
constructor(json) { | ||
super("-1", "", [], null); | ||
this.children.push(...Node.createFromArray(json, this)) | ||
} | ||
} |
Oops, something went wrong.