integrated webodf.js into the code file view

This commit is contained in:
hyung-hwan 2016-02-17 10:08:44 +00:00
parent c33b186641
commit c9d4ff5885
6 changed files with 1108 additions and 56 deletions

View File

@ -93,7 +93,30 @@ class SubversionModel extends Model
$prop = @svn_proplist ($workurl, FALSE, $rev); $prop = @svn_proplist ($workurl, FALSE, $rev);
if ($prop === FALSE) return FALSE; if ($prop === FALSE) return FALSE;
$fileinfo['properties'] = array_key_exists($orgurl, $prop)? $prop[$orgurl]: NULL; //$fileinfo['properties'] = array_key_exists($orgurl, $prop)? $prop[$orgurl]: NULL;
$fileinfo['properties'] = NULL;
foreach ($prop as $k => $v)
{
if ($k == $orgurl || $k == $workurl)
{
$fileinfo['properties'] = $v;
break;
}
else
{
// it looks like the subversion module returns a URL-encoded
// path when it contains a whitespace and the revision is given.
// for example, "UOML SAMPLE.ODT" is returned as "UOML%20SAMPLE.ODT"
// when revision is specified. let's work around it.
$decurl = urldecode($k);
if ($decurl == $orgurl || $decurl == $workurl)
{
$fileinfo['properties'] = $v;
break;
}
}
}
$fileinfo['logmsg'] = (count($log) > 0)? $log[0]['msg']: ''; $fileinfo['logmsg'] = (count($log) > 0)? $log[0]['msg']: '';
} }
@ -133,7 +156,26 @@ class SubversionModel extends Model
$prop = @svn_proplist ($workurl, FALSE, $rev); $prop = @svn_proplist ($workurl, FALSE, $rev);
if ($prop === FALSE) return FALSE; if ($prop === FALSE) return FALSE;
$fileinfo['properties'] = array_key_exists($orgurl, $prop)? $prop[$orgurl]: NULL; //$fileinfo['properties'] = array_key_exists($orgurl, $prop)? $prop[$orgurl]: NULL;
$fileinfo['properties'] = NULL;
foreach ($prop as $k => $v)
{
if ($k == $orgurl || $k == $workurl)
{
$fileinfo['properties'] = $v;
break;
}
else
{
$decurl = urldecode($k);
if ($decurl == $orgurl || $decurl == $workurl)
{
$fileinfo['properties'] = $v;
break;
}
}
}
$fileinfo['logmsg'] = (count($log) > 0)? $log[0]['msg']: ''; $fileinfo['logmsg'] = (count($log) > 0)? $log[0]['msg']: '';
} }
@ -188,7 +230,25 @@ class SubversionModel extends Model
$prop = @svn_proplist ($workurl, FALSE, $rev); $prop = @svn_proplist ($workurl, FALSE, $rev);
if ($prop === FALSE) return FALSE; if ($prop === FALSE) return FALSE;
$fileinfo['properties'] = array_key_exists($orgurl, $prop)? $prop[$orgurl]: NULL; //$fileinfo['properties'] = array_key_exists($orgurl, $prop)? $prop[$orgurl]: NULL;
$fileinfo['properties'] = NULL;
foreach ($prop as $k => $v)
{
if ($k == $orgurl || $k == $workurl)
{
$fileinfo['properties'] = $v;
break;
}
else
{
$decurl = urldecode($k);
if ($decurl == $orgurl || $decurl == $workurl)
{
$fileinfo['properties'] = $v;
break;
}
}
}
$log = @svn_log ($workurl, $log = @svn_log ($workurl,
$fileinfo['created_rev'], $fileinfo['created_rev'],

View File

@ -7,6 +7,7 @@
$is_image_file = FALSE; $is_image_file = FALSE;
$is_pdf_file = FALSE; $is_pdf_file = FALSE;
$is_odf_file = FALSE;
$is_special_stream = FALSE; $is_special_stream = FALSE;
if (array_key_exists('properties', $file) && count($file['properties']) > 0) if (array_key_exists('properties', $file) && count($file['properties']) > 0)
{ {
@ -17,7 +18,7 @@
if ($pv == 'application/octet-stream') if ($pv == 'application/octet-stream')
{ {
$lower_fileext = strtolower($fileext); $lower_fileext = strtolower($fileext);
if (in_array ($lower_fileext, array ('png', 'jpg', 'gif', 'tif', 'bmp', 'ico'))) if (in_array ($lower_fileext, array ('png', 'jpg', 'jpeg', 'gif', 'tif', 'bmp', 'ico')))
{ {
$img = @imagecreatefromstring ($file['content']); $img = @imagecreatefromstring ($file['content']);
if ($img !== FALSE) if ($img !== FALSE)
@ -34,6 +35,12 @@
$is_pdf_file = TRUE; $is_pdf_file = TRUE;
break; break;
} }
else if (in_array ($lower_fileext, array ('odt', 'odp', 'ods')))
{
$is_special_stream = TRUE;
$is_odf_file = TRUE;
break;
}
} }
else if ($pv == 'application/pdf') else if ($pv == 'application/pdf')
{ {
@ -41,6 +48,14 @@
$is_pdf_file = TRUE; $is_pdf_file = TRUE;
break; break;
} }
else if ($pv == 'application/vnd.oasis.opendocument.text' ||
$pv == 'application/vnd.oasis.opendocument.presentation' ||
$pv == 'application/vnd.oasis.opendocument.spreadsheet')
{
$is_special_stream = TRUE;
$is_odf_file = TRUE;
break;
}
} }
} }
} }
@ -75,6 +90,10 @@ if ($is_pdf_file)
{ {
printf ('<script type="text/javascript" src="%s"></script>', base_url_make('/js/pdf.min.js')); printf ('<script type="text/javascript" src="%s"></script>', base_url_make('/js/pdf.min.js'));
} }
else if ($is_odf_file)
{
printf ('<script type="text/javascript" src="%s"></script>', base_url_make('/js/webodf.js'));
}
$enstyle_anchor_text = '<i class="fa fa-magic"></i> ' . $this->lang->line('Enstyle'); $enstyle_anchor_text = '<i class="fa fa-magic"></i> ' . $this->lang->line('Enstyle');
$destyle_anchor_text = '<i class="fa fa-times"></i> ' . $this->lang->line('Destyle'); $destyle_anchor_text = '<i class="fa fa-times"></i> ' . $this->lang->line('Destyle');
@ -99,24 +118,6 @@ else
?> ?>
<script type="text/javascript"> <script type="text/javascript">
var showing_raw_code = false;
function showRawCode()
{
if (showing_raw_code)
{
$("#code_file_style_button").button("option", "label", '<?php print $destyle_anchor_text; ?>');
$("#code_file_result_code").removeClass("prettyprinted");
prettyPrint();
}
else
{
$("#code_file_style_button").button("option", "label", '<?php print $enstyle_anchor_text; ?>');
$("#code_file_result_code").html($("#code_file_result_raw").html());
}
showing_raw_code = !showing_raw_code;
}
<?php if ($is_pdf_file): ?> <?php if ($is_pdf_file): ?>
@ -133,7 +134,7 @@ function render_pdf_page (num)
// Using promise to fetch the page // Using promise to fetch the page
pdf_doc.getPage(num).then(function(page) { pdf_doc.getPage(num).then(function(page) {
var vp1 = page.getViewport (1); var vp1 = page.getViewport (1);
scale = ($('#code_file_result_code').innerWidth() - 20) / vp1.width; scale = ($('#code_file_result').innerWidth() - 20) / vp1.width;
var viewport = page.getViewport(scale); var viewport = page.getViewport(scale);
pdf_canvas.height = viewport.height; pdf_canvas.height = viewport.height;
pdf_canvas.width = viewport.width; pdf_canvas.width = viewport.width;
@ -198,6 +199,31 @@ function on_last_pdf_page ()
pdf_page_num = pdf_doc.numPages; pdf_page_num = pdf_doc.numPages;
queue_pdf_rendering_in_progress (pdf_page_num); queue_pdf_rendering_in_progress (pdf_page_num);
} }
<?php elseif ($is_odf_file): ?>
var odf_canvas = null;
<?php elseif (!$is_special_stream): ?>
var showing_raw_code = false;
function showRawCode()
{
if (showing_raw_code)
{
$("#code_file_style_button").button("option", "label", '<?php print $destyle_anchor_text; ?>');
$("#code_file_result_code").removeClass("prettyprinted");
prettyPrint();
}
else
{
$("#code_file_style_button").button("option", "label", '<?php print $enstyle_anchor_text; ?>');
$("#code_file_result_code").html($("#code_file_result_raw").html());
}
showing_raw_code = !showing_raw_code;
}
<?php endif; ?> <?php endif; ?>
@ -208,30 +234,31 @@ $(function () {
heightStyle: "content" heightStyle: "content"
}); });
$("#code_file_mainarea_loc_info").hide(); <?php if (!$is_special_stream): ?>
$("#code_file_loc_info").hide();
btn = $("#code_file_mainarea_loc_button").button().click (function () { btn = $("#code_file_mainarea_loc_button").button().click (function () {
if ($("#code_file_mainarea_loc_info").is(":visible")) if ($("#code_file_loc_info").is(":visible"))
{ {
$("#code_file_mainarea_loc_info").hide("blind",{},200); $("#code_file_loc_info").hide("blind",{},200);
} }
else else
{ {
$("#code_file_mainarea_loc_info").show("blind",{},200); $("#code_file_loc_info").show("blind",{},200);
} }
return false; // prevent the default behavior return false; // prevent the default behavior
}); });
<?php if (!$is_special_stream): ?>
$("#code_file_mainarea_edit_button").button();
<?php endif; ?>
<?php if ($file['created_rev'] != $file['head_rev']): ?> $("#code_file_mainarea_edit_button").button();
$("#code_file_headrev_button").button().click (function() { <?php endif; ?>
$(location).attr ('href', codepot_merge_path("<?php print site_url(); ?>", '<?php print "/code/file/{$project->id}/${hex_headpath}"; ?>'));
return false; <?php if ($file['created_rev'] != $file['head_rev']): ?>
}); $("#code_file_headrev_button").button().click (function() {
<?php endif; ?> $(location).attr ('href', codepot_merge_path("<?php print site_url(); ?>", '<?php print "/code/file/{$project->id}/${hex_headpath}"; ?>'));
return false;
});
<?php endif; ?>
$("#code_file_blame_button").button().click (function() { $("#code_file_blame_button").button().click (function() {
$(location).attr ('href', codepot_merge_path("<?php print site_url(); ?>", '<?php print "/code/blame/{$project->id}/${hex_headpath}{$revreq}"; ?>')); $(location).attr ('href', codepot_merge_path("<?php print site_url(); ?>", '<?php print "/code/blame/{$project->id}/${hex_headpath}{$revreq}"; ?>'));
@ -262,15 +289,17 @@ $(function () {
PDFJS.workerSrc = "<?php print base_url_make('/js/pdf.worker.min.js'); ?>"; PDFJS.workerSrc = "<?php print base_url_make('/js/pdf.worker.min.js'); ?>";
var pdf_data = new Uint8Array( [ //var pdf_data = new Uint8Array( [
<?php <?php
/*
$fc = &$file['content']; $fc = &$file['content'];
$len = strlen ($fc); $len = strlen ($fc);
printf ("%d", ord($fc[0])); printf ("%d", ord($fc[0]));
/* TODO: use encoding to minimize data size when dumping to pdf_data */
for ($i = 1; $i < $len; $i++) printf (",%d", ord($fc[$i])); for ($i = 1; $i < $len; $i++) printf (",%d", ord($fc[$i]));
*/
?> ?>
]); //]);
var pdf_data = codepot_merge_path("<?php print site_url(); ?>", '<?php print "/code/fetch/{$project->id}/${hex_headpath}{$revreq}"; ?>');
PDFJS.getDocument(pdf_data).then(function (pdf) { PDFJS.getDocument(pdf_data).then(function (pdf) {
pdf_doc = pdf; pdf_doc = pdf;
@ -293,6 +322,11 @@ $(function () {
}); });
<?php elseif ($is_odf_file): ?>
odf_canvas = new odf.OdfCanvas (document.getElementById('code_file_result'));
odf_canvas.load (codepot_merge_path("<?php print site_url(); ?>", '<?php print "/code/fetch/{$project->id}/${hex_headpath}{$revreq}"; ?>'));
<?php elseif (!$is_special_stream): ?> <?php elseif (!$is_special_stream): ?>
$("#code_file_style_button").button({"label": '<?php print $destyle_anchor_text; ?>'}).click (function () { $("#code_file_style_button").button({"label": '<?php print $destyle_anchor_text; ?>'}).click (function () {
@ -373,8 +407,16 @@ $this->load->view (
if ($headpath != $file['fullpath']) if ($headpath != $file['fullpath'])
{ {
print ' - '; // it looks like the subversion module returns a URL-encoded
print htmlspecialchars($file['fullpath']); // path when it contains a whitespace and the revision is given.
// for example, "UOML SAMPLE.ODT" is returned as "UOML%20SAMPLE.ODT"
// when revision is specified. let's work around it.
$decpath = urldecode ($file['fullpath']);
if ($headpath != $decpath)
{
print ' - ';
print htmlspecialchars($file['fullpath']);
}
} }
?> ?>
</div> </div>
@ -405,12 +447,15 @@ $this->load->view (
print ' | '; print ' | ';
printf ('%s: %s', $this->lang->line('Size'), $file['size']); printf ('%s: %s', $this->lang->line('Size'), $file['size']);
if ((isset($login['id']) && $login['id'] != '') && !$is_special_stream) if (!$is_special_stream)
{ {
print ' '; if ((isset($login['id']) && $login['id'] != '') )
print anchor ("code/edit/{$project->id}/{$hex_headpath}{$revreq}", $this->lang->line('Edit'), 'id="code_file_mainarea_edit_button"'); {
print ' ';
print anchor ("code/edit/{$project->id}/{$hex_headpath}{$revreq}", $this->lang->line('Edit'), 'id="code_file_mainarea_edit_button"');
}
print anchor ("#", "LOC", "id=code_file_mainarea_loc_button");
} }
print anchor ("#", "LOC", "id=code_file_mainarea_loc_button");
?> ?>
</div> </div>
@ -488,7 +533,11 @@ $this->load->view (
</pre> </pre>
</div> </div>
<?php if ($is_special_stream): ?>
<div id="code_file_result">
<?php else: ?>
<div id="code_file_result" class="codepot-relative-container-view codepot-styled-code-view" > <div id="code_file_result" class="codepot-relative-container-view codepot-styled-code-view" >
<?php endif; ?>
<?php <?php
if ($fileext == 'adb' || $fileext == 'ads') $fileext = 'ada'; if ($fileext == 'adb' || $fileext == 'ads') $fileext = 'ada';
@ -502,7 +551,6 @@ if ($login['settings'] != NULL &&
$login['settings']->code_hide_line_num == 'Y') $prettyprint_linenums = ''; $login['settings']->code_hide_line_num == 'Y') $prettyprint_linenums = '';
?> ?>
<pre class="prettyprint <?php print $prettyprint_linenums?> <?php print $prettyprint_lang?>" id="code_file_result_code">
<?php <?php
if ($is_image_file) if ($is_image_file)
{ {
@ -520,8 +568,12 @@ if ($login['settings'] != NULL &&
print '</div>'; print '</div>';
print '<canvas id="code_file_pdf_canvas" style="border:1px solid black;"/>'; print '<canvas id="code_file_pdf_canvas" style="border:1px solid black;"/>';
} }
else if ($is_odf_file)
{
}
else else
{ {
printf ('<pre class="prettyprint %s %s" id="code_file_result_code">', $prettyprint_linenums, $prettyprint_lang);
$charset = ''; $charset = '';
if (array_key_exists('properties', $file) && count($file['properties']) > 0) if (array_key_exists('properties', $file) && count($file['properties']) > 0)
{ {
@ -550,18 +602,19 @@ if ($login['settings'] != NULL &&
// ignore iconv error // ignore iconv error
print htmlspecialchars(@iconv ($charset, 'UTF-8//IGNORE', $file['content'])); print htmlspecialchars(@iconv ($charset, 'UTF-8//IGNORE', $file['content']));
} }
}
?>
</pre>
<div id="code_file_mainarea_loc_info" class="codepot-infobox"> print '</pre>';
<div class="title">LOC</div>
<?php print '<div id="code_file_loc_info" class="codepot-infobox">';
print '<div class="title">LOC</div>';
/* TODO: show this if it's enabled in the user settings */ /* TODO: show this if it's enabled in the user settings */
$graph_url = codepot_merge_path (site_url(), "/code/graph/cloc-file/{$project->id}/{$hex_headpath}{$revreq}"); $graph_url = codepot_merge_path (site_url(), "/code/graph/cloc-file/{$project->id}/{$hex_headpath}{$revreq}");
print "<img src='{$graph_url}' id='code_file_mainarea_loc_info_locgraph' />"; print "<img src='{$graph_url}' id='code_file_loc_info_locgraph' />";
?> print '</div>';
</div> <!-- code_file_mainarea_loc_info --> }
?>
</div> <!-- code_file_result --> </div> <!-- code_file_result -->

View File

@ -115,6 +115,7 @@
#code_file_pdf_canvas { #code_file_pdf_canvas {
border: none !important; border: none !important;
} }
/*----------------------------------------------- /*-----------------------------------------------
* project source folder view * project source folder view
*-----------------------------------------------*/ *-----------------------------------------------*/

View File

@ -30,7 +30,8 @@ www_DATA = \
d3.min.js \ d3.min.js \
CodeFlower.js \ CodeFlower.js \
pdf.min.js \ pdf.min.js \
pdf.worker.min.js pdf.worker.min.js \
webodf.js
EXTRA_DIST = $(www_DATA) EXTRA_DIST = $(www_DATA)

View File

@ -183,7 +183,8 @@ www_DATA = \
d3.min.js \ d3.min.js \
CodeFlower.js \ CodeFlower.js \
pdf.min.js \ pdf.min.js \
pdf.worker.min.js pdf.worker.min.js \
webodf.js
EXTRA_DIST = $(www_DATA) EXTRA_DIST = $(www_DATA)

936
codepot/src/js/webodf.js Normal file

File diff suppressed because one or more lines are too long