Skip to content
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

Responsive diff page html #328

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions html/core/page.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func (c *Page) WriteHTMLTo(w io.Writer) (int64, error) {
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/octicons/4.4.0/font/octicons.css"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div class="container">`)
Expand Down
2 changes: 1 addition & 1 deletion html/core/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func NewTable(tableClass string, content ...Component) *Table {
}

func (c *Table) WriteHTMLTo(w io.Writer) (int64, error) {
n := appendSprintf(w, `<table class="table %s">`, c.tableClass)
n := appendSprintf(w, `<table class="table table-responsive %s">`, c.tableClass)
n += appendComponent(w, NewComponents(c.content...))
n += appendString(w, "</table>")

Expand Down
71 changes: 49 additions & 22 deletions html/diff_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/elliotchance/gedcom/html/core"
"github.com/elliotchance/gedcom/util"
"io"
"os"
"sort"
)

Expand Down Expand Up @@ -177,45 +178,53 @@ func (c *DiffPage) WriteHTMLTo(w io.Writer) (int64, error) {
precalculatedComparisons = append(precalculatedComparisons, comparison)
}

args := os.Args
Sternbach-Software marked this conversation as resolved.
Show resolved Hide resolved
var rightGedcom string
var leftGedcom string
for index, arg := range args {
if arg == "-right-gedcom" {
rightGedcom = args[index+1]
continue
}
if arg == "-left-gedcom" {
leftGedcom = args[index+1]
continue
}
}
class := "text-center"
attr := map[string]string{}
headerTag := "h5"
// The index at the top of the page.
rows := []core.Component{}
rows := []core.Component{
core.NewTableRow(
core.NewTableCell(
core.NewTag(headerTag, attr, core.NewText(leftGedcom))).Class(class),
core.NewTableCell(
core.NewTag(headerTag, attr, core.NewText("Similarity score"))).Class(class),
core.NewTableCell(
core.NewTag(headerTag, attr, core.NewText(rightGedcom))).Class(class)),
}
for _, comparison := range precalculatedComparisons {
weightedSimilarity := c.weightedSimilarity(comparison.comparison)

leftClass := ""
rightClass := ""

switch {
case comparison.comparison.Left != nil && comparison.comparison.Right == nil:
case comparison.comparison.Left != nil && comparison.comparison.Right == nil: //right is missing
leftClass = "bg-warning"

case comparison.comparison.Left == nil && comparison.comparison.Right != nil:
case comparison.comparison.Left == nil && comparison.comparison.Right != nil: //left is missing
rightClass = "bg-primary"

case weightedSimilarity < 1:
case weightedSimilarity < 1: //neither are missing, but they aren't identical
leftClass = "bg-info"
rightClass = "bg-info"

case c.filterFlags.HideEqual:
case c.filterFlags.HideEqual: //neither are missing, and they are identical (therefore equal); if user said to hide equal, hide this row
continue
}

leftNameAndDates := NewIndividualNameAndDatesLink(comparison.comparison.Left, c.visibility, "")
rightNameAndDates := NewIndividualNameAndDatesLink(comparison.comparison.Right, c.visibility, "")

left := core.NewTableCell(leftNameAndDates).Class(leftClass)
right := core.NewTableCell(rightNameAndDates).Class(rightClass)

middle := core.NewTableCell(core.NewText(""))
if weightedSimilarity != 0 {
similarityString := fmt.Sprintf("%.2f%%", weightedSimilarity*100)
middle = core.NewTableCell(core.NewText(similarityString)).
Class("text-center " + leftClass)
}

tableRow := core.NewTableRow(left, middle, right)

rows = append(rows, tableRow)
rows = append(rows, c.getRow(comparison, leftClass, rightClass, weightedSimilarity))
}

// Individual pages
Expand All @@ -236,6 +245,24 @@ func (c *DiffPage) WriteHTMLTo(w io.Writer) (int64, error) {
).WriteHTMLTo(w)
}

func (c *DiffPage) getRow(comparison *IndividualCompare, leftClass string, rightClass string, weightedSimilarity float64) *core.TableRow {

leftNameAndDates := NewIndividualNameAndDatesLink(comparison.comparison.Left, c.visibility, "")
rightNameAndDates := NewIndividualNameAndDatesLink(comparison.comparison.Right, c.visibility, "")

left := core.NewTableCell(leftNameAndDates).Class(leftClass)
right := core.NewTableCell(rightNameAndDates).Class(rightClass)

middle := core.NewTableCell(core.NewText(""))
if weightedSimilarity != 0 {
similarityString := fmt.Sprintf("%.2f%%", weightedSimilarity*100)
middle = core.NewTableCell(core.NewText(similarityString)).
Class("text-center " + leftClass)
}

return core.NewTableRow(left, middle, right)
}

func (c *DiffPage) shouldSkip(comparison *IndividualCompare) bool {
switch c.show {
case DiffPageShowAll:
Expand Down
138 changes: 68 additions & 70 deletions node_diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,29 @@
//
// CompareNodes recursively compares two nodes. For example:
//
// 0 INDI @P3@ | 0 INDI @P4@
// 1 NAME John /Smith/ | 1 NAME J. /Smith/
// 1 BIRT | 1 BIRT
// 2 DATE 3 SEP 1943 | 2 DATE Abt. Sep 1943
// 1 DEAT | 1 BIRT
// 2 PLAC England | 2 DATE 3 SEP 1943
// 1 BIRT | 1 DEAT
// 2 DATE Abt. Oct 1943 | 2 DATE Aft. 2001
// | 2 PLAC Surry, England
// 0 INDI @P3@ | 0 INDI @P4@
// 1 NAME John /Smith/ | 1 NAME J. /Smith/
// 1 BIRT | 1 BIRT
// 2 DATE 3 SEP 1943 | 2 DATE Abt. Sep 1943
// 1 DEAT | 1 BIRT
// 2 PLAC England | 2 DATE 3 SEP 1943
// 1 BIRT | 1 DEAT
// 2 DATE Abt. Oct 1943 | 2 DATE Aft. 2001
// | 2 PLAC Surry, England
//
// Produces a *NodeDiff than can be rendered with the String method:
//
// LR 0 INDI @P3@
// L 1 NAME John /Smith/
// LR 1 BIRT
// L 2 DATE Abt. Oct 1943
// LR 2 DATE 3 SEP 1943
// R 2 DATE Abt. Sep 1943
// LR 1 DEAT
// L 2 PLAC England
// R 2 DATE Aft. 2001
// R 2 PLAC Surry, England
// R 1 NAME J. /Smith/
// LR 0 INDI @P3@
// L 1 NAME John /Smith/
// LR 1 BIRT
// L 2 DATE Abt. Oct 1943
// LR 2 DATE 3 SEP 1943
// R 2 DATE Abt. Sep 1943
// LR 1 DEAT
// L 2 PLAC England
// R 2 DATE Aft. 2001
// R 2 PLAC Surry, England
// R 1 NAME J. /Smith/
package gedcom

import (
Expand Down Expand Up @@ -54,10 +54,10 @@ import (
// considered to be equal because the BirthNode.Equals regards all BirthNodes as
// equal (see specific documentation for a complete explanation):
//
// BIRT | BIRT | BIRT
// DATE 3 SEP 1943 | DATE 3 SEP 1943 | PLAC England
// BIRT | PLAC England | DATE 3 SEP 1943
// PLAC England | | BIRT
// BIRT | BIRT | BIRT
// DATE 3 SEP 1943 | DATE 3 SEP 1943 | PLAC England
// BIRT | PLAC England | DATE 3 SEP 1943
// PLAC England | | BIRT
//
// However, the semantics of Equals is quite different for other types of nodes.
// For example ResidenceNodes are considered equal only if they have the same
Expand Down Expand Up @@ -92,7 +92,7 @@ type NodeDiff struct {
// If you need to be sure the root node are the equal after the comparison, you
// can use (this is also nil safe):
//
// d.Left.Equals(d.Right)
// d.Left.Equals(d.Right)
//
// The algorithm to perform the diff is actually very simple:
//
Expand All @@ -110,34 +110,33 @@ type NodeDiff struct {
//
// Here are two individuals that have slightly different data:
//
// 0 INDI @P3@ | 0 INDI @P4@
// 1 NAME John /Smith/ | 1 NAME J. /Smith/
// 1 BIRT | 1 BIRT
// 2 DATE 3 SEP 1943 | 2 DATE Abt. Sep 1943
// 1 DEAT | 1 BIRT
// 2 PLAC England | 2 DATE 3 SEP 1943
// 1 BIRT | 1 DEAT
// 2 DATE Abt. Oct 1943 | 2 DATE Aft. 2001
// | 2 PLAC Surry, England
// 0 INDI @P3@ | 0 INDI @P4@
// 1 NAME John /Smith/ | 1 NAME J. /Smith/
// 1 BIRT | 1 BIRT
// 2 DATE 3 SEP 1943 | 2 DATE Abt. Sep 1943
// 1 DEAT | 1 BIRT
// 2 PLAC England | 2 DATE 3 SEP 1943
// 1 BIRT | 1 DEAT
// 2 DATE Abt. Oct 1943 | 2 DATE Aft. 2001
// | 2 PLAC Surry, England
//
// In this case both of the root nodes are different (because of the different
// pointer values). The returned left and right will have the respective root
// nodes.
//
// Here is the output, rendered with NodeDiff.String():
//
// LR 0 INDI @P3@
// L 1 NAME John /Smith/
// LR 1 BIRT
// L 2 DATE Abt. Oct 1943
// LR 2 DATE 3 SEP 1943
// R 2 DATE Abt. Sep 1943
// LR 1 DEAT
// L 2 PLAC England
// R 2 DATE Aft. 2001
// R 2 PLAC Surry, England
// R 1 NAME J. /Smith/
//
// LR 0 INDI @P3@
// L 1 NAME John /Smith/
// LR 1 BIRT
// L 2 DATE Abt. Oct 1943
// LR 2 DATE 3 SEP 1943
// R 2 DATE Abt. Sep 1943
// LR 1 DEAT
// L 2 PLAC England
// R 2 DATE Aft. 2001
// R 2 PLAC Surry, England
// R 1 NAME J. /Smith/
func CompareNodes(left, right Node) *NodeDiff {
result := &NodeDiff{}

Expand Down Expand Up @@ -218,17 +217,17 @@ func (nd *NodeDiff) string(indent int) string {

// String returns a readable comparison of nodes, like:
//
// LR 0 INDI @P3@
// L 1 NAME John /Smith/
// LR 1 BIRT
// L 2 DATE Abt. Oct 1943
// LR 2 DATE 3 SEP 1943
// R 2 DATE Abt. Sep 1943
// LR 1 DEAT
// L 2 PLAC England
// R 2 DATE Aft. 2001
// R 2 PLAC Surry, England
// R 1 NAME J. /Smith/
// LR 0 INDI @P3@
// L 1 NAME John /Smith/
// LR 1 BIRT
// L 2 DATE Abt. Oct 1943
// LR 2 DATE 3 SEP 1943
// R 2 DATE Abt. Sep 1943
// LR 1 DEAT
// L 2 PLAC England
// R 2 DATE Aft. 2001
// R 2 PLAC Surry, England
// R 1 NAME J. /Smith/
//
// The L/R/LR represent which side has the node, followed by the GEDCOM indent
// and node line.
Expand All @@ -237,8 +236,8 @@ func (nd *NodeDiff) string(indent int) string {
// displayed as two separate lines even though they both belong to the same
// NodeDiff:
//
// LR 0 INDI @P3@
// LR 0 INDI @P4@
// LR 0 INDI @P3@
// LR 0 INDI @P4@
//
// You should not rely on this format to be machine readable as it may change in
// the future.
Expand All @@ -254,16 +253,15 @@ func (nd *NodeDiff) String() string {
// The following diff (rendered with String) shows each NodeDiff and if it would
// be considered DeepEqual:
//
// LR 0 INDI @P3@ | false
// LR 1 NAME John /Smith/ | true
// LR 1 BIRT | false
// L 2 DATE Abt. Oct 1943 | false
// LR 2 DATE 3 SEP 1943 | true
// R 2 DATE Abt. Sep 1943 | false
// LR 1 DEAT | true
// LR 2 PLAC England | true
// R 1 NAME J. /Smith/ | false
//
// LR 0 INDI @P3@ | false
// LR 1 NAME John /Smith/ | true
// LR 1 BIRT | false
// L 2 DATE Abt. Oct 1943 | false
// LR 2 DATE 3 SEP 1943 | true
// R 2 DATE Abt. Sep 1943 | false
// LR 1 DEAT | true
// LR 2 PLAC England | true
// R 1 NAME J. /Smith/ | false
func (nd *NodeDiff) IsDeepEqual() bool {
leftIsNil := IsNil(nd.Left)
rightIsNil := IsNil(nd.Right)
Expand Down Expand Up @@ -345,7 +343,7 @@ func (nd *NodeDiff) LeftNode() Node {

// RightNode returns the flattening Node value that favors the right side.
//
// To favor means to return the Left value when both the Left and Right are set.
// To favor means to return the Right value when both the Left and Right are set.
func (nd *NodeDiff) RightNode() Node {
n := nd.Right

Expand Down
20 changes: 19 additions & 1 deletion simple_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (node *SimpleNode) Identifier() string {
if node == nil {
return ""
}

return fmt.Sprintf("@%s@", node.pointer)
}

Expand All @@ -84,6 +84,24 @@ func (node *SimpleNode) Equals(node2 Node) bool {
}

tag := node2.Tag()
//if both Ancestry sources, only check if their _APID is the same
if node.Tag().String() == "Source" && tag.String() == "Source" {
Sternbach-Software marked this conversation as resolved.
Show resolved Hide resolved
found := false
ancestry:
for _, leftNode := range node.Nodes() {
for _, rightNode := range node2.Nodes() {
leftValue := leftNode.Value()
rightValue := rightNode.Value()
if leftNode.Tag().String() == "_APID" && rightNode.Tag().String() == "_APID" && rightValue == leftValue {
found = true
break ancestry
}
}
}
if found { //can't just return found, because they may be non-ancestry sources
return true
}
}
if node.tag != tag {
return false
}
Expand Down