[algospot-judge] r205 committed - submission view works

0 views
Skip to first unread message

codesite...@google.com

unread,
Jul 11, 2010, 2:59:22 AM7/11/10
to algospo...@googlegroups.com
Revision: 205
Author: jongman
Date: Sat Jul 10 22:16:40 2010
Log: submission view works
http://code.google.com/p/algospot-judge/source/detail?r=205

Added:
/trunk/vanillaapp/js/jquery.beautyOfCode.js
/trunk/vanillaapp/views/problems/submission.php
Modified:
/trunk/vanillaapp/controllers/class.problemscontroller.php
/trunk/vanillaapp/design/problems.css
/trunk/vanillaapp/design/tables.css
/trunk/vanillaapp/models/class.submissionmodel.php

=======================================
--- /dev/null
+++ /trunk/vanillaapp/js/jquery.beautyOfCode.js Sat Jul 10 22:16:40 2010
@@ -0,0 +1,236 @@
+jQuery.beautyOfCode = {
+
+ settings: {
+ // should the syntax highlighter and brushes
+ // be loaded dynamically
+ autoLoad: true,
+ // the base url to alex' hosted sources
+ // http://alexgorbatchev.com/wiki/SyntaxHighlighter:Hosting
+ baseUrl: 'http://alexgorbatchev.com/pub/sh/2.1.364/',
+ // the baseurl for the hosted scripts
+ scripts: 'scripts/',
+ // the baseurl for the hosted styles
+ styles: 'styles/',
+ // themes from
http://alexgorbatchev.com/wiki/SyntaxHighlighter:Themes
+ theme: 'Default',
+ // the brushes that should be loaded - case sensitive!
+ // http://alexgorbatchev.com/wiki/SyntaxHighlighter:Brushes
+ brushes: ['Xml', 'JScript', 'CSharp', 'Plain'],
+ // overrides for configurations and defaults
+ // http://alexgorbatchev.com/wiki/SyntaxHighlighter:Configuration
+ config: {},
+ defaults: {},
+ // function to be called, when all scripts are loaded
+ ready: function() {
+ jQuery.beautyOfCode.beautifyAll();
+ }
+ },
+
+ init: function(settings) {
+ settings = jQuery.extend({},
+ jQuery.beautyOfCode.settings, settings);
+
+ if (!settings.config.clipboardSwf)
+ settings.config.clipboardSwf = settings.baseUrl + settings.scripts
+ 'clipboard.swf';
+
+ $(document).ready(function() {
+ if (!settings.autoLoad) {
+ settings.ready();
+ }
+ else {
+ jQuery.beautyOfCode.utils.loadCss(settings.baseUrl +
settings.styles + 'shCore.css');
+ jQuery.beautyOfCode.utils.loadCss(settings.baseUrl +
settings.styles + 'shTheme' + settings.theme + '.css', 'shTheme');
+
+ var scripts = new Array();
+ scripts.push(settings.baseUrl + settings.scripts
+ 'shCore.js');
+ jQuery.each(settings.brushes,
+ function(i, item) {
+ scripts.push(settings.baseUrl + settings.scripts
+ 'shBrush' + item + ".js")
+ });
+
+ jQuery.beautyOfCode.utils.loadAllScripts(
+ scripts,
+ function() {
+ if (settings && settings.config)
+ jQuery.extend(SyntaxHighlighter.config,
settings.config);
+
+ if (settings && settings.defaults)
+ jQuery.extend(SyntaxHighlighter.defaults,
settings.defaults);
+
+ settings.ready();
+ });
+ }
+ });
+ },
+
+ beautifyAll: function() {
+ jQuery("pre.code:has(code[class])").beautifyCode();
+ },
+ utils: {
+ loadScript: function(url, complete) {
+ jQuery.ajax({
+ url: url,
+ complete: function() {
+ complete();
+ },
+ type: 'GET',
+ dataType: 'script',
+ cache: true
+ });
+ },
+ loadAllScripts: function(urls, complete) {
+ if (!urls || urls.length == 0)
+ {
+ complete();
+ return;
+ }
+ var first = urls[0];
+ jQuery.beautyOfCode.utils.loadScript(
+ first,
+ function() {
+ jQuery.beautyOfCode.utils.loadAllScripts(
+ urls.slice(1, urls.length),
+ complete
+ );
+ }
+ );
+ },
+ loadCss: function(url, id) {
+ var headNode = jQuery("head")[0];
+ if (url && headNode)
+ {
+ var styleNode = document.createElement('link');
+ styleNode.setAttribute('rel', 'stylesheet');
+ styleNode.setAttribute('href', url);
+ if (id) styleNode.id = id;
+ headNode.appendChild(styleNode);
+ }
+ },
+ addCss: function(css, id) {
+ var headNode = jQuery("head")[0];
+ if (css && headNode)
+ {
+ var styleNode = document.createElement('style');
+
+ styleNode.setAttribute('type', 'text/css');
+
+ if (id) styleNode.id = id;
+
+ if (styleNode.styleSheet) {
+ // for IE
+ styleNode.styleSheet.cssText = css;
+ }
+ else {
+ $(styleNode).text(css);
+ }
+
+ headNode.appendChild(styleNode);
+ }
+ },
+ addCssForBrush: function(brush, highlighter) {
+ if (brush.isCssInitialized)
+ return;
+
+ jQuery.beautyOfCode.utils.addCss(highlighter.Style);
+
+ brush.isCssInitialized = true;
+ },
+ parseParams: function(params) {
+ var trimmed = jQuery.map(params, jQuery.trim);
+
+ var paramObject = {};
+
+ var getOptionValue = function(name, list) {
+ var regex = new RegExp('^' + name
+ '\\[([^\\]]+)\\]$', 'gi');
+ var matches = null;
+
+ for (var i = 0; i < list.length; i++)
+ if ((matches = regex.exec(list[i])) != null)
+ return matches[1];
+
+ return null;
+ }
+
+ var handleValue = function(flag) {
+ var flagValue = getOptionValue('boc-' + flag, trimmed);
+ if (flagValue) paramObject[flag] = flagValue;
+ };
+
+ handleValue('class-name');
+ handleValue('first-line');
+ handleValue('tab-size');
+
+ var highlight = getOptionValue('boc-highlight', trimmed);
+ if (highlight) paramObject['highlight'] =
jQuery.map(highlight.split(','), jQuery.trim);
+
+ var handleFlag = function(flag) {
+ if (jQuery.inArray('boc-' + flag, trimmed) != -1)
+ paramObject[flag] = true;
+ else if (jQuery.inArray('boc-no-' + flag, trimmed) != -1)
+ paramObject[flag] = false;
+ };
+
+ handleFlag('smart-tabs');
+ handleFlag('ruler');
+ handleFlag('gutter');
+ handleFlag('toolbar');
+ handleFlag('collapse');
+ handleFlag('auto-links');
+ handleFlag('light');
+ handleFlag('wrap-lines');
+ handleFlag('html-script');
+
+ return paramObject;
+ }
+ }
+};
+
+jQuery.fn.beautifyCode = function(brush, params) {
+ var saveBrush = brush;
+ var saveParams = params;
+
+ // iterate all elements
+ this.each(function(i, item) {
+ var $item = jQuery(item);
+
+ // for now, only supports <pre><code>...</code></pre>
+ // support for only pre, or only code could be added
+ var $code = $item.children("code");
+ var code = $code[0];
+ var classItems = code.className.split(" ");
+
+ var brush = saveBrush ? saveBrush: classItems[0];
+ var elementParams =
jQuery.beautyOfCode.utils.parseParams(classItems);
+
+ var params = jQuery.extend({},
+ SyntaxHighlighter.defaults, saveParams, elementParams);
+
+ // Instantiate a brush
+ if (params['html-script'] == 'true')
+ {
+ highlighter = new SyntaxHighlighter.HtmlScript(brush);
+ }
+ else
+ {
+ var brush = SyntaxHighlighter.utils.findBrush(brush);
+
+ if (brush)
+ highlighter = new brush();
+ else
+ return;
+ }
+
+ // i'm not sure if this is still neccessary
+ jQuery.beautyOfCode.utils.addCssForBrush(brush, highlighter);
+
+ // IE Bug?: code in pre has to be skipped
+ // in order to preserve line breaks.
+ if ($item.is("pre") && ($code = $item.children("code")))
+ $item.text($code.text());
+
+ highlighter.highlight($item.html(), params);
+ highlighter.source = item;
+
+ $item.replaceWith(highlighter.div);
+ });
+}
=======================================
--- /dev/null
+++ /trunk/vanillaapp/views/problems/submission.php Sat Jul 10 22:16:40 2010
@@ -0,0 +1,60 @@
+<div class="Submission">
+ <h2>Submission #<?=$this->Submission->No?></h2>
+ <table cellpadding="0" cellspacing="0" border="0" class="display"
id="SubmissionInfo" width="100%">
+ <thead>
+ <tr>
+ <th><?=T("Problem")?></th>
+ <th><?=T("Author")?></th>
+ <th><?=T("Submitted")?></th>
+ <th><?=T("Verdict")?></th>
+ <th><?=T("Memory")?></th>
+ <th><?=T("Time")?></th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td><?=$this->Problem->Name?></td>
+ <td><?=$this->Submission->AuthorInfo->Name?></td>
+
<td><?=Gdn_Format::Date($this->Submission->Submitted, "%Y-%m-%d %H:%M:%S")?></td>
+ <td><span
class="Submission<?=$this->Submission->StateText?>"><?=str_replace("_", " ",
$this->Submission->StateText)?></span></td>
+ <td><?=$this->Submission->Memory?> kb</td>
+ <td><?=$this->Submission->Time?> ms</td>
+ </tr>
+ </tbody>
+ </table>
+</div>
+<?
+ if($this->Submission->State == SubmissionState::RUNTIME_ERROR ||
+ $this->Submission->State == SubmissionState::COMPILE_ERROR ||
+ $this->Submission->State == SubmissionState::CANT_BE_JUDGED) {
+?>
+<div class="Submission">
+ <h2>Message</h2>
+
+ <pre
class="ErrorMessage"><?=htmlentities($this->Submission->Message)?></pre>
+</div>
+<?
+ }
+?>
+<div class="Submission">
+ <h2>Source Code</h2>
+
+ <pre class="code"><code
class="<?=$this->Submission->Language?>"><?=htmlentities($this->Submission->Source)?></code></pre>
+
+</div>
+<script language="javascript">
+ var table = null;
+ $(document).ready(function() {
+ table = $('#SubmissionInfo').dataTable( {
+ "bProcessing": false,
+ "bLengthChange": false,
+ "bFilter": false,
+ "bInfo": false,
+ "bSort": false,
+ "bPaginate": false,
+ "bSearch": false });
+ $.beautyOfCode.init({
+ brushes: ['Cpp', 'Python', 'Java']
+ });
+ });
+</script>
=======================================
--- /trunk/vanillaapp/controllers/class.problemscontroller.php Sat Jul 10
22:15:21 2010
+++ /trunk/vanillaapp/controllers/class.problemscontroller.php Sat Jul 10
22:16:40 2010
@@ -321,6 +321,16 @@
public function Submission($No) {
$this->GetSubmission($No);
$this->ForceReadSubmissionPermissions();
+ $this->GetProblem($this->Submission->Problem);
+
+ $this->AddCssFile("tables.css");
+ $this->AddCssFile("submissions.css");
+ $this->AddJsFile("jquery.beautyOfCode.js");
+ $this->AddJsFile("jquery.dataTables.min.js");
+ $this->AddJsFile("jquery.dataTables.plugins.js");
+ $this->AddModule("ProblemInfoModule");
+ $this->AddModule("SubmitModule");
+
$this->Render();
}
}
=======================================
--- /trunk/vanillaapp/design/problems.css Sat Jul 10 22:16:17 2010
+++ /trunk/vanillaapp/design/problems.css Sat Jul 10 22:16:40 2010
@@ -94,3 +94,17 @@
font-weight: bold;
color: red;
}
+
+.Submission {
+ margin-bottom: 24px;
+}
+
+pre.ErrorMessage {
+ padding: 8px;
+ margin-left: 10px;
+ width: 640px;
+ height: auto;
+ overflow: auto;
+ border: 1px solid gray;
+ background-color: 1px solid rgb(230, 230, 230);
+}
=======================================
--- /trunk/vanillaapp/design/tables.css Mon May 31 21:48:02 2010
+++ /trunk/vanillaapp/design/tables.css Sat Jul 10 22:16:40 2010
@@ -32,7 +32,7 @@

.dataTables_wrapper {
position: relative;
- min-height: 302px;
+ /*min-height: 302px;*/
clear: both;
_height: 302px;
zoom: 1; /* Feeling sorry for IE */
=======================================
--- /trunk/vanillaapp/models/class.submissionmodel.php Sat Jul 10 22:16:04
2010
+++ /trunk/vanillaapp/models/class.submissionmodel.php Sat Jul 10 22:16:40
2010
@@ -37,10 +37,18 @@
class SubmissionModel extends Gdn_Model {
public function __construct() {
parent::__construct('Submission');
+ $this->UserModel = new UserModel();
+ }
+
+ private function Augment($Submission) {
+ $Submission->StateText =
SubmissionState::ToString($Submission->State);
+ $Submission->AuthorInfo =
$this->UserModel->Get($Submission->Author);
}

public function Get($No) {
- return $this->SQL->Select("*")->From("Submission")->Where("No",
$No)->Get()->FirstRow();
+ $ret = $this->SQL->Select("*")->From("Submission")->Where("No",
$No)->Get()->FirstRow();
+ $this->Augment($ret);
+ return $ret;
}

public function Update($No, $NewValues) {
@@ -67,10 +75,8 @@
$this->Where($Author, $ShowHidden, $UserID, $ExcludeState);
$this->SQL->Limit($Limit, $Offset);
$ret = $this->SQL->Get()->Result();
- $UserModel = new UserModel();
for($i = 0; $i < Count($ret); ++$i) {
- $ret[$i]->StateText =
SubmissionState::ToString($ret[$i]->State);
- $ret[$i]->AuthorInfo = $UserModel->Get($ret[$i]->Author);
+ $this->Augment($ret[$i]);
}
return $ret;
}

Reply all
Reply to author
Forward
0 new messages