Changing source preview to use new syntax highlighter

fixing issue with QR OTP on user page
This commit is contained in:
Nathan Adams 2014-03-11 21:01:25 -05:00
parent 22de793422
commit 822e107958
5 changed files with 105 additions and 65 deletions

View File

@ -65,12 +65,15 @@ class IDF_FileUtil
} }
$table = array(); $table = array();
$i = 1; $i = 1;
foreach (self::splitIntoLines($content) as $line) { /*foreach (self::splitIntoLines($content) as $line) {
$table[] = '<tr class="c-line"><td class="code-lc" id="L'.$i.'"><a href="#L'.$i.'">'.$i.'</a></td>' $table[] = '<tr class="c-line"><td class="code-lc" id="L'.$i.'"><a href="#L'.$i.'">'.$i.'</a></td>'
.'<td class="code mono'.$pretty.'">'.self::emphasizeControlCharacters(Pluf_esc($line)).'</td></tr>'; .'<td class="code mono'.$pretty.'">'.self::emphasizeControlCharacters(Pluf_esc($line)).'</td></tr>';
$i++; $i++;
} }
return Pluf_Template::markSafe(implode("\n", $table)); return Pluf_Template::markSafe(implode("\n", $table));*/
//var_dump($fileinfo);
$content = '<script type="syntaxhighlighter" class="brush: ' . $fileinfo[2] . '">' . $content . '</script>';
return Pluf_Template::markSafe($content);
} }
/** /**

View File

@ -380,10 +380,11 @@ class IDF_Views_Source
$props = $scm->getProperties($commit, $request_file); $props = $scm->getProperties($commit, $request_file);
$cache = Pluf_Cache::factory(); $cache = Pluf_Cache::factory();
$key = sha1($request_file.$commit); $key = sha1($request_file.$commit);
if (null === ($content=$cache->get($key))) { $content = IDF_FileUtil::highLight($extra['mime'], $scm->getFile($request_file_info));
$content = IDF_FileUtil::highLight($extra['mime'], $scm->getFile($request_file_info)); /*if (null === ($content=$cache->get($key))) {
$cache->set($key, $content); $cache->set($key, $content);
} }*/
return Pluf_Shortcuts_RenderToResponse('idf/source/'.$scmConf.'/file.html', return Pluf_Shortcuts_RenderToResponse('idf/source/'.$scmConf.'/file.html',
array( array(
'page_title' => $page_title, 'page_title' => $page_title,

View File

@ -56,11 +56,11 @@ class IDF_Views_User
$form = new IDF_Form_ProjectRequest(null, $params); $form = new IDF_Form_ProjectRequest(null, $params);
} }
return Pluf_Shortcuts_RenderToResponse('idf/user/projectrequest.html', return Pluf_Shortcuts_RenderToResponse('idf/user/projectrequest.html',
array('page_title' => $title, array('page_title' => $title,
'form' => $form, 'form' => $form,
'success' => $success, 'success' => $success,
'error' => $error), 'error' => $error),
$request); $request);
} }
/** /**
@ -114,24 +114,24 @@ class IDF_Views_User
$pag->sort_order = array('modif_dtime', 'ASC'); // will be reverted $pag->sort_order = array('modif_dtime', 'ASC'); // will be reverted
$pag->sort_reverse_order = array('modif_dtime'); $pag->sort_reverse_order = array('modif_dtime');
$list_display = array( $list_display = array(
'id' => __('Id'), 'id' => __('Id'),
array('project', 'Pluf_Paginator_FkToString', __('Project')), array('project', 'Pluf_Paginator_FkToString', __('Project')),
array('summary', 'IDF_Views_IssueSummaryAndLabels', __('Summary')), array('summary', 'IDF_Views_IssueSummaryAndLabels', __('Summary')),
array('status', 'IDF_Views_Issue_ShowStatus', __('Status')), array('status', 'IDF_Views_Issue_ShowStatus', __('Status')),
array('modif_dtime', 'Pluf_Paginator_DateAgo', __('Last Updated')), array('modif_dtime', 'Pluf_Paginator_DateAgo', __('Last Updated')),
); );
$pag->configure($list_display, array(), array('status', 'modif_dtime')); $pag->configure($list_display, array(), array('status', 'modif_dtime'));
$pag->items_per_page = 10; $pag->items_per_page = 10;
$pag->no_results_text = ($working) ? __('No issues are assigned to you, yeah!') : __('All the issues you submitted are fixed, yeah!'); $pag->no_results_text = ($working) ? __('No issues are assigned to you, yeah!') : __('All the issues you submitted are fixed, yeah!');
$pag->setFromRequest($request); $pag->setFromRequest($request);
return Pluf_Shortcuts_RenderToResponse('idf/user/dashboard.html', return Pluf_Shortcuts_RenderToResponse('idf/user/dashboard.html',
array( array(
'page_title' => $title, 'page_title' => $title,
'nb_submit' => $nb_submit, 'nb_submit' => $nb_submit,
'nb_owner' => $nb_owner, 'nb_owner' => $nb_owner,
'issues' => $pag, 'issues' => $pag,
), ),
$request); $request);
} }
/** /**
@ -147,9 +147,9 @@ class IDF_Views_User
$params = array('user' => $request->user); $params = array('user' => $request->user);
if ($request->method == 'POST') { if ($request->method == 'POST') {
$form = new IDF_Form_UserAccount(array_merge( $form = new IDF_Form_UserAccount(array_merge(
(array)$request->POST, (array)$request->POST,
(array)$request->FILES (array)$request->FILES
), $params); ), $params);
if ($form->isValid()) { if ($form->isValid()) {
$user = $form->save(); $user = $form->save();
$url = Pluf_HTTP_URL_urlForView('IDF_Views_User::myAccount'); $url = Pluf_HTTP_URL_urlForView('IDF_Views_User::myAccount');
@ -166,13 +166,13 @@ class IDF_Views_User
$mailaddrs = Pluf::factory('IDF_EmailAddress')->get_email_addresses_for_user($request->user); $mailaddrs = Pluf::factory('IDF_EmailAddress')->get_email_addresses_for_user($request->user);
return Pluf_Shortcuts_RenderToResponse('idf/user/myaccount.html', return Pluf_Shortcuts_RenderToResponse('idf/user/myaccount.html',
array('page_title' => __('Your Account'), array('page_title' => __('Your Account'),
'api_key' => $api_key, 'api_key' => $api_key,
'ext_pass' => $ext_pass, 'ext_pass' => $ext_pass,
'keys' => $keys, 'keys' => $keys,
'mailaddrs' => $mailaddrs, 'mailaddrs' => $mailaddrs,
'form' => $form), 'form' => $form),
$request); $request);
} }
/** /**
@ -233,9 +233,9 @@ class IDF_Views_User
$form = new IDF_Form_UserChangeEmail(); $form = new IDF_Form_UserChangeEmail();
} }
return Pluf_Shortcuts_RenderToResponse('idf/user/changeemail.html', return Pluf_Shortcuts_RenderToResponse('idf/user/changeemail.html',
array('page_title' => __('Confirm The Email Change'), array('page_title' => __('Confirm The Email Change'),
'form' => $form), 'form' => $form),
$request); $request);
} }
@ -286,22 +286,24 @@ class IDF_Views_User
$user = $users[0]; $user = $users[0];
$user_data = IDF_UserData::factory($user); $user_data = IDF_UserData::factory($user);
$ownedprojects = IDF_Views::getOwnedProjects($request->user); $ownedprojects = IDF_Views::getOwnedProjects($user);
$pubprojects = array(); $pubprojects = array();
$privprojects = 0; $privprojects = 0;
foreach($ownedprojects as $proj) if ($ownedprojects != null && count($ownedprojects) > 0 )
{ {
if ($proj->private == 1) foreach($ownedprojects as $proj)
{ {
$privprojects += 1; if ($proj->private == 1)
continue; {
} else { $privprojects += 1;
$pubprojects[] = $proj; continue;
} else {
$pubprojects[] = $proj;
}
} }
} }
$projectstats = IDF_Views::getProjectsStatistics($pubprojects); $projectstats = IDF_Views::getProjectsStatistics($pubprojects);
//print_r($projectstats); //print_r($projectstats);
//echo $privprojects; //echo $privprojects;
@ -311,10 +313,10 @@ class IDF_Views_User
$pag = new Pluf_Paginator(new IDF_Issue()); $pag = new Pluf_Paginator(new IDF_Issue());
$pag->model_view = "project_find_private"; $pag->model_view = "project_find_private";
$pag->class = 'recent-issues'; $pag->class = 'recent-issues';
$pag->item_extra_props = array('current_user' => $request->user); $pag->item_extra_props = array('current_user' => $user);
$pag->summary = __('This table shows the open issues.'); $pag->summary = __('This table shows the open issues.');
$pag->forced_where = new Pluf_SQL("owner = " . $request->user->id); $pag->forced_where = new Pluf_SQL("owner = " . $user->id);
$pag->action = 'idf_dashboard'; $pag->action = array('idf_user_view', array($user->login));
$pag->sort_order = array('modif_dtime', 'ASC'); // will be reverted $pag->sort_order = array('modif_dtime', 'ASC'); // will be reverted
$pag->sort_reverse_order = array('modif_dtime'); $pag->sort_reverse_order = array('modif_dtime');
$list_display = array( $list_display = array(
@ -326,16 +328,17 @@ class IDF_Views_User
array('modif_dtime', 'Pluf_Paginator_DateAgo', __('Last Updated')), array('modif_dtime', 'Pluf_Paginator_DateAgo', __('Last Updated')),
); );
$pag->configure($list_display, array(), array('status', 'modif_dtime')); $pag->configure($list_display, array(), array('status', 'modif_dtime'));
$pag->items_per_page = 10; $pag->items_per_page = 20;
$pag->no_results_text = __('This user has no issues assigned to them!'); $pag->no_results_text = __('This user has no issues assigned to them!');
$pag->setFromRequest($request); $pag->setFromRequest($request);
$pag2 = new Pluf_Paginator(new IDF_Commit()); $pag2 = new Pluf_Paginator(new IDF_Commit());
$pag->model_view = "project_find_private"; $pag2->nb_items = 20;
$pag2->model_view = "project_find_private";
$pag2->class = 'recent-issues'; $pag2->class = 'recent-issues';
$pag2->summary = __('This table shows the latest commits of this user.'); $pag2->summary = __('This table shows the latest commits of this user.');
$pag2->forced_where = new Pluf_SQL("author = " . $request->user->id); $pag2->forced_where = new Pluf_SQL("author = " . $user->id);
$pag2->action = 'idf_dashboard'; $pag2->action = array('idf_user_view', array($user->login));
$pag2->sort_order = array('creation_dtime', 'ASC'); // will be reverted $pag2->sort_order = array('creation_dtime', 'ASC'); // will be reverted
$pag2->sort_reverse_order = array('creation_dtime'); $pag2->sort_reverse_order = array('creation_dtime');
$list_display = array( $list_display = array(
@ -349,18 +352,18 @@ class IDF_Views_User
$pag2->no_results_text = __('This user has not made any commits yet!'); $pag2->no_results_text = __('This user has not made any commits yet!');
$pag2->setFromRequest($request); $pag2->setFromRequest($request);
$projects = IDF_Views::getOwnedProjects($user); $projects = IDF_Views::getOwnedProjects($user);
return Pluf_Shortcuts_RenderToResponse('idf/user/public.html', return Pluf_Shortcuts_RenderToResponse('idf/user/public.html',
array('page_title' => (string) $user, array('page_title' => (string) $user,
'member' => $user, 'member' => $user,
'user_data' => $user_data, 'user_data' => $user_data,
'projects' => $projects, 'projects' => $projects,
'issues' => $pag, 'issues' => $pag,
'commits' => $pag2, 'commits' => $pag2,
'stats' => new Pluf_Template_ContextVars($projectstats), 'stats' => new Pluf_Template_ContextVars($projectstats),
'privatecount' => $privprojects 'privatecount' => $privprojects
), ),
$request); $request);
} }
} }
@ -384,11 +387,11 @@ function IDF_Views_IssueSummaryAndLabels($field, $issue, $extra='')
{ {
$project = $issue->get_project(); $project = $issue->get_project();
$edit = Pluf_HTTP_URL_urlForView('IDF_Views_Issue::view', $edit = Pluf_HTTP_URL_urlForView('IDF_Views_Issue::view',
array($project->shortname, $issue->id)); array($project->shortname, $issue->id));
$tags = array(); $tags = array();
foreach ($issue->get_tags_list() as $tag) { foreach ($issue->get_tags_list() as $tag) {
$url = Pluf_HTTP_URL_urlForView('IDF_Views_Issue::listLabel', $url = Pluf_HTTP_URL_urlForView('IDF_Views_Issue::listLabel',
array($project->shortname, $tag->id, 'open')); array($project->shortname, $tag->id, 'open'));
$tags[] = sprintf('<a class="label" href="%s">%s</a>', $url, Pluf_esc((string) $tag)); $tags[] = sprintf('<a class="label" href="%s">%s</a>', $url, Pluf_esc((string) $tag));
} }
$out = ''; $out = '';
@ -397,3 +400,4 @@ function IDF_Views_IssueSummaryAndLabels($field, $issue, $extra='')
} }
return sprintf('<a href="%s">%s</a>', $edit, Pluf_esc($issue->summary)).$out; return sprintf('<a href="%s">%s</a>', $edit, Pluf_esc($issue->summary)).$out;
} }

View File

@ -133,6 +133,28 @@ $(document).ready(function(){
return result return result
}; };
function gotoline()
{
if ($('.number' + window.location.hash.substring(1)).first().offset() == null)
{
window.setTimeout(gotoline, 100);
return;
}
$('html, body').animate({
scrollTop: ($('.number' + window.location.hash.substring(1)).first().offset().top)
},500);
changegutter();
}
function changegutter()
{
if ($('.gutter > [class*=number]').first().offset() == null)
{
window.setTimeout(changegutter, 100);
return;
}
$(".gutter > [class*=number]").each(function(){ $(this).html('<a href="https://' + window.location.hostname + window.location.pathname + '#' + $(this).html() +'">' + $(this).html() + '</a>'); });
}
$(function() { $(function() {
@ -164,7 +186,17 @@ $(function() {
)); ));
SyntaxHighlighter.all(); SyntaxHighlighter.all();
if(window.location.hash)
{
window.setTimeout(gotoline, 100);
} else {
window.setTimeout(changegutter, 100);
}
}); });
{/literal} {/literal}
</script> </script>
</body> </body>

View File

@ -194,7 +194,7 @@ $(document).ready(function() {
for(var i = 0; i < 32; i++) for(var i = 0; i < 32; i++)
key += chars[Math.floor(Math.random() * 32)]; key += chars[Math.floor(Math.random() * 32)];
$("#id_otpkey").val(key); $("#id_otpkey").val(key);
var url = "https://chart.googleapis.com/chart?chs=300x300&cht=qr&chl=otpauth%3A%2F%2Ftotp%srchub:" + user + "?secret=" + $("#id_otpkey").val().toUpperCase() + "%26issuer=srchub&choe=UTF-8"; var url = "https://chart.googleapis.com/chart?chs=300x300&cht=qr&chl=otpauth%3A%2F%2Ftotp%2Fsrchub:" + user + "?secret=" + $("#id_otpkey").val().toUpperCase() + "%26issuer=srchub&choe=UTF-8";
$("#QRcode").html('<img src="' + url + '" />') $("#QRcode").html('<img src="' + url + '" />')
return false; return false;
}); });