View | Details | Raw Unified | Return to bug 11876
Collapse All | Expand All

(-)a/koha-tmpl/intranet-tmpl/lib/jsdiff/jsdiff.js (+160 lines)
Line 0 Link Here
1
/*
2
 * Javascript Diff Algorithm
3
 *  By John Resig (http://ejohn.org/)
4
 *  Modified by Chu Alan "sprite"
5
 *
6
 * Released under the MIT license.
7
 *
8
 * More Info:
9
 *  http://ejohn.org/projects/javascript-diff-algorithm/
10
 */
11
12
function escape(s) {
13
    var n = s;
14
    n = n.replace(/&/g, "&");
15
    n = n.replace(/</g, "&lt;");
16
    n = n.replace(/>/g, "&gt;");
17
    n = n.replace(/"/g, "&quot;");
18
19
    return n;
20
}
21
22
function diffString( o, n ) {
23
  o = o.replace(/\s+$/, '');
24
  n = n.replace(/\s+$/, '');
25
26
  var out = diff(o == "" ? [] : o.split(/\s+/), n == "" ? [] : n.split(/\s+/) );
27
  var str = "";
28
29
  var oSpace = o.match(/\s+/g);
30
  if (oSpace == null) {
31
    oSpace = ["\n"];
32
  } else {
33
    oSpace.push("\n");
34
  }
35
  var nSpace = n.match(/\s+/g);
36
  if (nSpace == null) {
37
    nSpace = ["\n"];
38
  } else {
39
    nSpace.push("\n");
40
  }
41
42
  if (out.n.length == 0) {
43
      for (var i = 0; i < out.o.length; i++) {
44
        str += '<del>' + escape(out.o[i]) + oSpace[i] + "</del>";
45
      }
46
  } else {
47
    if (out.n[0].text == null) {
48
      for (n = 0; n < out.o.length && out.o[n].text == null; n++) {
49
        str += '<del>' + escape(out.o[n]) + oSpace[n] + "</del>";
50
      }
51
    }
52
53
    for ( var i = 0; i < out.n.length; i++ ) {
54
      if (out.n[i].text == null) {
55
        str += '<ins>' + escape(out.n[i]) + nSpace[i] + "</ins>";
56
      } else {
57
        var pre = "";
58
59
        for (n = out.n[i].row + 1; n < out.o.length && out.o[n].text == null; n++ ) {
60
          pre += '<del>' + escape(out.o[n]) + oSpace[n] + "</del>";
61
        }
62
        str += " " + out.n[i].text + nSpace[i] + pre;
63
      }
64
    }
65
  }
66
67
  return str;
68
}
69
70
function randomColor() {
71
    return "rgb(" + (Math.random() * 100) + "%, " +
72
                    (Math.random() * 100) + "%, " +
73
                    (Math.random() * 100) + "%)";
74
}
75
function diffString2( o, n ) {
76
  o = o.replace(/\s+$/, '');
77
  n = n.replace(/\s+$/, '');
78
79
  var out = diff(o == "" ? [] : o.split(/\s+/), n == "" ? [] : n.split(/\s+/) );
80
81
  var oSpace = o.match(/\s+/g);
82
  if (oSpace == null) {
83
    oSpace = ["\n"];
84
  } else {
85
    oSpace.push("\n");
86
  }
87
  var nSpace = n.match(/\s+/g);
88
  if (nSpace == null) {
89
    nSpace = ["\n"];
90
  } else {
91
    nSpace.push("\n");
92
  }
93
94
  var os = "";
95
  var colors = new Array();
96
  for (var i = 0; i < out.o.length; i++) {
97
      colors[i] = randomColor();
98
99
      if (out.o[i].text != null) {
100
          os += '<span style="background-color: ' +colors[i]+ '">' +
101
                escape(out.o[i].text) + oSpace[i] + "</span>";
102
      } else {
103
          os += "<del>" + escape(out.o[i]) + oSpace[i] + "</del>";
104
      }
105
  }
106
107
  var ns = "";
108
  for (var i = 0; i < out.n.length; i++) {
109
      if (out.n[i].text != null) {
110
          ns += '<span style="background-color: ' +colors[out.n[i].row]+ '">' +
111
                escape(out.n[i].text) + nSpace[i] + "</span>";
112
      } else {
113
          ns += "<ins>" + escape(out.n[i]) + nSpace[i] + "</ins>";
114
      }
115
  }
116
117
  return { o : os , n : ns };
118
}
119
120
function diff( o, n ) {
121
  var ns = new Object();
122
  var os = new Object();
123
124
  for ( var i = 0; i < n.length; i++ ) {
125
    if ( ns[ n[i] ] == null )
126
      ns[ n[i] ] = { rows: new Array(), o: null };
127
    ns[ n[i] ].rows.push( i );
128
  }
129
130
  for ( var i = 0; i < o.length; i++ ) {
131
    if ( os[ o[i] ] == null )
132
      os[ o[i] ] = { rows: new Array(), n: null };
133
    os[ o[i] ].rows.push( i );
134
  }
135
136
  for ( var i in ns ) {
137
    if ( ns[i].rows.length == 1 && typeof(os[i]) != "undefined" && os[i].rows.length == 1 ) {
138
      n[ ns[i].rows[0] ] = { text: n[ ns[i].rows[0] ], row: os[i].rows[0] };
139
      o[ os[i].rows[0] ] = { text: o[ os[i].rows[0] ], row: ns[i].rows[0] };
140
    }
141
  }
142
143
  for ( var i = 0; i < n.length - 1; i++ ) {
144
    if ( n[i].text != null && n[i+1].text == null && n[i].row + 1 < o.length && o[ n[i].row + 1 ].text == null &&
145
         n[i+1] == o[ n[i].row + 1 ] ) {
146
      n[i+1] = { text: n[i+1], row: n[i].row + 1 };
147
      o[n[i].row+1] = { text: o[n[i].row+1], row: i + 1 };
148
    }
149
  }
150
151
  for ( var i = n.length - 1; i > 0; i-- ) {
152
    if ( n[i].text != null && n[i-1].text == null && n[i].row > 0 && o[ n[i].row - 1 ].text == null &&
153
         n[i-1] == o[ n[i].row - 1 ] ) {
154
      n[i-1] = { text: n[i-1], row: n[i].row - 1 };
155
      o[n[i].row-1] = { text: o[n[i].row-1], row: i - 1 };
156
    }
157
  }
158
159
  return { o: o, n: n };
160
}
(-)a/koha-tmpl/intranet-tmpl/lib/jsdiff/jsdiff.min.js (+10 lines)
Line 0 Link Here
1
/*
2
 * Javascript Diff Algorithm
3
 *  By John Resig (http://ejohn.org/)
4
 *  Modified by Chu Alan "sprite"
5
 *
6
 * Released under the MIT license.
7
 *
8
 * More Info:
9
 *  http://ejohn.org/projects/javascript-diff-algorithm/
10
 */function escape(a){var b=a;return b=b.replace(/&/g,"&amp;"),b=b.replace(/</g,"&lt;"),b=b.replace(/>/g,"&gt;"),b=b.replace(/"/g,"&quot;"),b}function diffString(a,b){a=a.replace(/\s+$/,""),b=b.replace(/\s+$/,"");var c=diff(a==""?[]:a.split(/\s+/),b==""?[]:b.split(/\s+/)),d="",e=a.match(/\s+/g);e==null?e=["\n"]:e.push("\n");var f=b.match(/\s+/g);f==null?f=["\n"]:f.push("\n");if(c.n.length==0)for(var g=0;g<c.o.length;g++)d+="<del>"+escape(c.o[g])+e[g]+"</del>";else{if(c.n[0].text==null)for(b=0;b<c.o.length&&c.o[b].text==null;b++)d+="<del>"+escape(c.o[b])+e[b]+"</del>";for(var g=0;g<c.n.length;g++)if(c.n[g].text==null)d+="<ins>"+escape(c.n[g])+f[g]+"</ins>";else{var h="";for(b=c.n[g].row+1;b<c.o.length&&c.o[b].text==null;b++)h+="<del>"+escape(c.o[b])+e[b]+"</del>";d+=" "+c.n[g].text+f[g]+h}}return d}function randomColor(){return"rgb("+Math.random()*100+"%, "+Math.random()*100+"%, "+Math.random()*100+"%)"}function diffString2(a,b){a=a.replace(/\s+$/,""),b=b.replace(/\s+$/,"");var c=diff(a==""?[]:a.split(/\s+/),b==""?[]:b.split(/\s+/)),d=a.match(/\s+/g);d==null?d=["\n"]:d.push("\n");var e=b.match(/\s+/g);e==null?e=["\n"]:e.push("\n");var f="",g=new Array;for(var h=0;h<c.o.length;h++)g[h]=randomColor(),c.o[h].text!=null?f+='<span style="background-color: '+g[h]+'">'+escape(c.o[h].text)+d[h]+"</span>":f+="<del>"+escape(c.o[h])+d[h]+"</del>";var i="";for(var h=0;h<c.n.length;h++)c.n[h].text!=null?i+='<span style="background-color: '+g[c.n[h].row]+'">'+escape(c.n[h].text)+e[h]+"</span>":i+="<ins>"+escape(c.n[h])+e[h]+"</ins>";return{o:f,n:i}}function diff(a,b){var c=new Object,d=new Object;for(var e=0;e<b.length;e++)c[b[e]]==null&&(c[b[e]]={rows:new Array,o:null}),c[b[e]].rows.push(e);for(var e=0;e<a.length;e++)d[a[e]]==null&&(d[a[e]]={rows:new Array,n:null}),d[a[e]].rows.push(e);for(var e in c)c[e].rows.length==1&&typeof d[e]!="undefined"&&d[e].rows.length==1&&(b[c[e].rows[0]]={text:b[c[e].rows[0]],row:d[e].rows[0]},a[d[e].rows[0]]={text:a[d[e].rows[0]],row:c[e].rows[0]});for(var e=0;e<b.length-1;e++)b[e].text!=null&&b[e+1].text==null&&b[e].row+1<a.length&&a[b[e].row+1].text==null&&b[e+1]==a[b[e].row+1]&&(b[e+1]={text:b[e+1],row:b[e].row+1},a[b[e].row+1]={text:a[b[e].row+1],row:e+1});for(var e=b.length-1;e>0;e--)b[e].text!=null&&b[e-1].text==null&&b[e].row>0&&a[b[e].row-1].text==null&&b[e-1]==a[b[e].row-1]&&(b[e-1]={text:b[e-1],row:b[e].row-1},a[b[e].row-1]={text:a[b[e].row-1],row:e-1});return{o:a,n:b}};
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/about.tt (+3 lines)
Lines 607-612 Link Here
607
            <h2>jQuery Colvis plugin</h2>
607
            <h2>jQuery Colvis plugin</h2>
608
            <p>The <a href="http://datatables.net/extensions/colvis/">controls for column visiblity in DataTables</a>
608
            <p>The <a href="http://datatables.net/extensions/colvis/">controls for column visiblity in DataTables</a>
609
                by Allan Jardine is licensed under the BSD 3 and GPL v2 license.</p>
609
                by Allan Jardine is licensed under the BSD 3 and GPL v2 license.</p>
610
611
            <h2>Javascript Diff Algorithm</h2>
612
            <p>The <a href="http://ejohn.org/projects/javascript-diff-algorithm/">Javascript Diff Algorithm</a> plugin by John Resig is licensed under the <a href="http://opensource.org/licenses/mit-license.php">MIT License</a>.</p>
610
        </div>
613
        </div>
611
614
612
        <div id="translations">
615
        <div id="translations">
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/showdiffmarc.tt (-42 / +47 lines)
Lines 1-50 Link Here
1
[% INCLUDE 'doc-head-open.inc' %]
1
[% INCLUDE 'doc-head-open.inc' %]
2
<title>Koha -- Cataloging: MARC Import</title>
2
<title>Koha &rsaquo; Tools &rsaquo; Manage staged MARC records &rsaquo; Compare matched records</title>
3
3
[% INCLUDE 'doc-head-close.inc' %]
4
<style>
4
<script type="text/javascript" src="[% interface %]/lib/jsdiff/jsdiff.min.js"></script>
5
div#main {
5
<script type="text/javascript">
6
    width: 100%;
6
    $(document).ready(function(){
7
    margin: 10px auto;
7
      var diff1 = $("#col1 pre").text();
8
}
8
      var diff2 = $("#col2 pre").text();
9
9
      var diffs = diffString(diff1,diff2);
10
div.col1,
10
      $("#col1 pre,#col2 pre").html(diffs);
11
div.col2 {
11
    });
12
    float: left;
12
</script>
13
    width: 46%;
13
<style type="text/css">
14
    margin-left: 3%;
14
    ins { background-color: #e6ffe6; }
15
15
    del { background-color: #ffe6e6; }
16
}
16
    #col1 ins, #col2 del { display: none; }
17
17
    pre { padding: 10px; overflow: scroll; }
18
pre {
19
    padding: 10px;
20
    overflow: scroll;
21
}
22
</style>
18
</style>
19
</head>
20
<body id="tools_compare-marc-import" class="tools">
23
21
24
[% INCLUDE 'doc-head-close.inc' %]
22
[% INCLUDE 'header.inc' %]
25
23
26
</head>
24
<div id="breadcrumbs">
27
<body>
25
    <a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a> &rsaquo; <a href="/cgi-bin/koha/tools/manage-marc-import.pl">Manage staged MARC records</a> &rsaquo; <a href="/cgi-bin/koha/tools/manage-marc-import.pl?import_batch_id=[% batchid %]">Batch [% batchid %]</a> &rsaquo; Compare matched records
26
</div>
28
27
29
<div id="main">
28
<div id="doc3">
30
    <div class="col1">
29
    <div class="yui-g">
31
        <h2>Original</h2>
30
        <div id="col1" class="yui-u first">
32
        [% IF ( ERROR_FORMATTED1 ) %]
31
            <h1>Original</h1>
33
            <p>The biblionumber <em>[% BIBLIONUMBER %]</em> doesn't match to any record.</p>
32
            [% IF ( ERROR_FORMATTED1 ) %]
34
        [% ELSE %]
33
                <div class="dialog alert">
35
            <h1>[% BIBLIOTITLE %]</h1>
34
                    <p>The biblionumber <em>[% BIBLIONUMBER %]</em> doesn't match any existing record.</p>
36
            <pre>[% MARC_FORMATTED1 %]</pre>
35
                </div>
37
        [% END %]
36
            [% ELSE %]
37
                <h2>[% BIBLIOTITLE %]</h2>
38
                <pre>[% MARC_FORMATTED1 %]</pre>
39
            [% END %]
40
        </div>
41
        <div id="col2" class="yui-u">
42
            <h1>Imported</h1>
43
            [% IF ( ERROR_FORMATTED2 ) %]
44
                <div class="dialog alert">
45
                    <p>The import id number <em>[% IMPORTID %]</em> doesn't match any existing record.</p>
46
                </div>
47
            [% ELSE %]
48
                <h2>[% IMPORTTITLE %]</h2>
49
                <pre>[% MARC_FORMATTED2 %] </pre>
50
            [% END %]
51
        </div>
38
    </div>
52
    </div>
39
    <div class="col2">
40
        <h2>Imported</h2>
41
        [% IF ( ERROR_FORMATTED2 ) %]
42
            <p>The importid <em>[% IMPORTID %]</em> doesn't match to any record.</p>
43
        [% ELSE %]
44
            <h1>[% IMPORTTITLE %]</h1>
45
            <pre>[% MARC_FORMATTED2 %] </pre>
46
        [% END %]
47
    </div>
48
</div>
49
53
54
<p><a href="/cgi-bin/koha/tools/manage-marc-import.pl?import_batch_id=[% batchid %]">Return to staged MARC batch [% batchid %]</a></p>
50
[% INCLUDE 'intranet-bottom.inc' %]
55
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/tools/batch_records_ajax.pl (-1 / +1 lines)
Lines 107-113 foreach my $record (@$records) { Link Here
107
          || q{},
107
          || q{},
108
        score => $#$match > -1 ? $match->[0]->{'score'} : 0,
108
        score => $#$match > -1 ? $match->[0]->{'score'} : 0,
109
        match_id => $match_id,
109
        match_id => $match_id,
110
        diff_url => $match_id ? "/cgi-bin/koha/tools/showdiffmarc.pl?importid=$record->{import_record_id}&id=$match_id" : undef
110
        diff_url => $match_id ? "/cgi-bin/koha/tools/showdiffmarc.pl?batchid=$import_batch_id&importid=$record->{import_record_id}&id=$match_id" : undef
111
      };
111
      };
112
}
112
}
113
113
(-)a/tools/showdiffmarc.pl (-5 / +6 lines)
Lines 8-14 Link Here
8
#
8
#
9
# Koha is free software; you can redistribute it and/or modify it under the
9
# Koha is free software; you can redistribute it and/or modify it under the
10
# terms of the GNU General Public License as published by the Free Software
10
# terms of the GNU General Public License as published by the Free Software
11
# Foundation; either version 2 of the License, or (at your option) any later
11
# Foundation; either version 3 of the License, or (at your option) any later
12
# version.
12
# version.
13
#
13
#
14
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
14
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
Lines 40-45 use XML::LibXML; Link Here
40
my $input        = new CGI;
40
my $input        = new CGI;
41
my $biblionumber = $input->param('id');
41
my $biblionumber = $input->param('id');
42
my $importid     = $input->param('importid');
42
my $importid     = $input->param('importid');
43
my $batchid      = $input->param('batchid');
43
44
44
45
45
if ( $biblionumber and $importid ) {
46
if ( $biblionumber and $importid ) {
Lines 56-62 if ( $biblionumber and $importid ) { Link Here
56
            query           => $input,
57
            query           => $input,
57
            type            => "intranet",
58
            type            => "intranet",
58
            authnotrequired => 0,
59
            authnotrequired => 0,
59
            flagsrequired   => { catalogue => 1  },
60
            flagsrequired   => { tools => 'manage_staged_marc' },
60
            debug           => 1,
61
            debug           => 1,
61
        }
62
        }
62
    );
63
    );
Lines 82-88 if ( $biblionumber and $importid ) { Link Here
82
    }
83
    }
83
84
84
85
85
    $template->param(     SCRIPT_NAME => $ENV{'SCRIPT_NAME'},
86
    $template->param(   SCRIPT_NAME => $ENV{'SCRIPT_NAME'},
86
                        BIBLIONUMBER => $biblionumber,
87
                        BIBLIONUMBER => $biblionumber,
87
                        IMPORTID => $importid,
88
                        IMPORTID => $importid,
88
                        BIBLIOTITLE => $biblioTitle,
89
                        BIBLIOTITLE => $biblioTitle,
Lines 90-96 if ( $biblionumber and $importid ) { Link Here
90
                        MARC_FORMATTED1 => $formatted1,
91
                        MARC_FORMATTED1 => $formatted1,
91
                        MARC_FORMATTED2 => $formatted2,
92
                        MARC_FORMATTED2 => $formatted2,
92
                        ERROR_FORMATTED1 => $errorFormatted1,
93
                        ERROR_FORMATTED1 => $errorFormatted1,
93
                        ERROR_FORMATTED2 => $errorFormatted2
94
                        ERROR_FORMATTED2 => $errorFormatted2,
95
                        batchid => $batchid
94
                    );
96
                    );
95
97
96
    output_html_with_http_headers $input, $cookie, $template->output;
98
    output_html_with_http_headers $input, $cookie, $template->output;
97
- 

Return to bug 11876