[algospot-judge] r220 committed - Category Management working

0 views
Skip to first unread message

codesite...@google.com

unread,
Jul 11, 2010, 3:56:08 AM7/11/10
to algospo...@googlegroups.com
Revision: 220
Author: jongman
Date: Sat Jul 10 22:18:45 2010
Log: Category Management working
http://code.google.com/p/algospot-judge/source/detail?r=220

Added:
/trunk/vanillaapp/controllers/class.admincontroller.php
/trunk/vanillaapp/models/class.tagmodel.php
/trunk/vanillaapp/views/admin
/trunk/vanillaapp/views/admin/categories.php
Modified:
/trunk/vanillaapp/controllers/class.aojcontroller.php
/trunk/vanillaapp/design/aoj.css
/trunk/vanillaapp/design/problemlist.css
/trunk/vanillaapp/design/problems.css
/trunk/vanillaapp/settings/structure.php
/trunk/vanillaapp/views/problems/my.php

=======================================
--- /dev/null
+++ /trunk/vanillaapp/controllers/class.admincontroller.php Sat Jul 10
22:18:45 2010
@@ -0,0 +1,50 @@
+<?php if (!defined('APPLICATION')) exit();
+
+function CmpTag($a, $b) {
+ if($a->Name == $b->Name) return 0;
+ return $a->Name > $b->Name ? 1 : -1;
+}
+
+class AdminController extends AOJController {
+ public $Uses =
array("ProblemModel", "AttachmentModel", "SubmissionModel", "TagModel"
+ , "UserModel", "Form");
+
+ public function Initialize() {
+ parent::Initialize();
+ }
+
+ public function Categories() {
+ $this->ForceAdmin();
+ $this->AddCssFile("tables.css");
+ $this->AddCssFile("problems.css");
+ $this->AddJsFile("jquery.dataTables.min.js");
+ $this->AddJsFile("jquery.dataTables.plugins.js");
+ $CategoryCount = array();
+ $CategoryInfo = array();
+ foreach($this->TagModel->GetList() as $Tag) {
+ if($Tag->Name == "") continue;
+ $CategoryInfo[$Tag->Name] = $Tag;
+ $Parts = explode("/", $Tag->Name);
+ for($i = 1; $i <= count($Parts); ++$i) {
+ $Prefix = implode("/", array_slice($Parts, 0, $i));
+ if(!isset($CategoryCount[$Prefix]))
+ $CategoryCount[$Prefix] = 0;
+ $CategoryCount[$Prefix] += $Tag->Count;
+ }
+ }
+ ksort($CategoryCount);
+ $this->SetData("CategoryCount", $CategoryCount, TRUE);
+ $this->SetData("Categories", $CategoryInfo, TRUE);
+ $this->Render();
+ }
+
+ public function DeleteCategory($No) {
+ $this->TagModel->DeleteCategory($No);
+ }
+
+ public function AddCategory() {
+ if(isset($_POST["TagName"])) {
+ $this->TagModel->Save(array("Name" => $_POST["TagName"]));
+ }
+ }
+}
=======================================
--- /dev/null
+++ /trunk/vanillaapp/models/class.tagmodel.php Sat Jul 10 22:18:45 2010
@@ -0,0 +1,34 @@
+<?php if (!defined('APPLICATION')) exit();
+
+class TagModel extends Gdn_Model {
+ public function __construct() {
+ parent::__construct('Tag');
+ }
+
+ public function GetProblems($No) {
+ return
$this->SQL->Select("Problem")->From("ProblemTagRelation")->Where("Tag",
$No)->Result();
+ }
+
+ public function GetList() {
+ return $this->SQL
+ ->Select("t.No", "", "No")
+ ->Select("t.Name", "", "Name")
+ ->Select("COUNT(r.No)", "", "Count")
+ ->From("Tag t")
+ ->Join("ProblemTagRelation r", "r.Tag = t.No", "left")
+ ->GroupBy("t.No")
+ ->Get()->Result();
+ }
+
+ public function DeleteCategory($No) {
+ $Cat = $this->SQL->Select("Name")->From("Tag")->Where("No",
$No)->Get()->FirstRow()->Name;
+ $All = $this->SQL->Select("No")->From("Tag")->Like("Name",
$Cat, "right")->Get()->Result();
+ foreach($All as $Category) {
+ $this->Delete(array("No" => $Category->No));
+ $this->SQL->Delete("ProblemTagRelation", array("Tag" =>
$Category->No));
+ print_r($Category);
+ }
+ }
+}
+
+
=======================================
--- /dev/null
+++ /trunk/vanillaapp/views/admin/categories.php Sat Jul 10 22:18:45 2010
@@ -0,0 +1,111 @@
+<h1>Manage Problem Categories</h1>
+<div class="ProblemCategoryList Section">
+ <table cellpadding="0" cellspacing="0" border="0" class="display"
id="CategoryListTable" width="100%">
+ <thead>
+ <tr>
+ <th><?=T("Category")?></th>
+ <th><?=T("# Problems")?></th>
+ <th><?=T("Action")?></th>
+ </tr>
+ </thead>
+ <tbody>
+<?
+foreach($this->CategoryCount as $Category => $Count) {
+?>
+ <tr>
+ <td>
+<?
+ $Parts = explode("/", $Category);
+ for($i = 0; $i < count($Parts); ++$i) {
+ if($i > 0)
+ echo(" / ");
+ if($i + 1 < count($Parts)) {
+ echo('<span class="CategoryParent">');
+ }
+ else {
+ echo('<a href="#">');
+ }
+ echo($Parts[$i]);
+ if($i + 1 < count($Parts)) {
+ echo('</span>');
+ }
+ else {
+ echo("</a>");
+ }
+ }
+?>
+</td>
+ <td><?=$Count?></td>
+ <td>
+<?
+ if(isset($this->Categories[$Category])) {
+ $CategoryInfo = $this->Categories[$Category];
+?>
+<a href="#"
onclick="confirmDeletion('<?=Url("/admin/deletecategory")?>/<?=$CategoryInfo->No?>',
this)">Delete</a> |
+<?
+ }
+?>
+<a href="#" onclick="addChildTag('<?=$Category?>')">Add Child</a>
+ </td>
+ </tr>
+<?
+}
+?>
+
+ </tbody>
+ </table>
+</div>
+<h4><?=T("Add new top-level category")?></h4>
+<div class="Section">
+ <input type="input" class="InputBox" id="NewTopLevelCategory"
size="40"/>
+ <input type="button" class="Button" id="AddNewTopLevelCategory"
value="<?=T("Submit")?>"/>
+</div>
+
+<script language="javascript">
+ var table = null;
+ $(document).ready(function() {
+ table = $('#CategoryListTable').dataTable( {
+ "bProcessing": false,
+ "bLengthChange": false,
+ "bFilter": false,
+ "bInfo": false,
+ "bSort": false,
+ "bPaginate": false,
+ "bSearch": false });
+ $("#AddNewTopLevelCategory").click(function() {
addTag($("#NewTopLevelCategory").val()) });
+ $("#NewTopLevelCategory").keyup(function(e) {
+ if(e.keyCode == 13) {
+ addTag($("#NewTopLevelCategory").val());
+ }
+ });
+ } );
+ function confirmDeletion(link, elem) {
+ var e = $(elem);
+ if(e.hasClass("ConfirmDelete")) {
+ $.ajax({url: link,
+ success: function() {
+ location.reload();
+ }
+ });
+ }
+ else {
+ $(elem).text("Really?").addClass("ConfirmDelete");
+ }
+ }
+
+ function addChildTag(parentTag) {
+ var newtag = prompt("<?=T("New tag name?")?>", "");
+ if(newtag) {
+ addTag(parentTag + "/" + newtag);
+ }
+ }
+
+ function addTag(tagName) {
+ $.post('<?=Url("/admin/addcategory/")?>',
+ {'TagName': tagName },
+ function() {
+ location.reload();
+ });
+ }
+</script>
+
=======================================
--- /trunk/vanillaapp/controllers/class.aojcontroller.php Sun Jun 27
08:46:02 2010
+++ /trunk/vanillaapp/controllers/class.aojcontroller.php Sat Jul 10
22:18:45 2010
@@ -39,6 +39,11 @@
Redirect("/entry");
}
}
+ protected function ForceAdmin() {
+ if(!$this->IsAdmin()) {
+ Redirect("/filenotfound");
+ }
+ }
protected function GetProblem($IdOrNo=1) {
if($this->Problem === FALSE) {
$Problem = $this->ProblemModel->Get($IdOrNo);
=======================================
--- /trunk/vanillaapp/design/aoj.css Mon May 31 21:48:02 2010
+++ /trunk/vanillaapp/design/aoj.css Sat Jul 10 22:18:45 2010
@@ -52,3 +52,8 @@
width: 640px;
height: 300px;
}
+
+.Section {
+ margin-bottom: 24px;
+}
+
=======================================
--- /trunk/vanillaapp/design/problemlist.css Mon May 31 21:48:02 2010
+++ /trunk/vanillaapp/design/problemlist.css Sat Jul 10 22:18:45 2010
@@ -5,3 +5,4 @@
width: 12px;
}
span.solved_inner { display: none; }
+
=======================================
--- /trunk/vanillaapp/design/problems.css Sat Jul 10 22:17:14 2010
+++ /trunk/vanillaapp/design/problems.css Sat Jul 10 22:18:45 2010
@@ -94,10 +94,6 @@
font-weight: bold;
color: red;
}
-
-.Submission, .Section {
- margin-bottom: 24px;
-}

pre.ErrorMessage {
padding: 8px;
@@ -108,3 +104,8 @@
border: 1px solid gray;
background-color: 1px solid rgb(230, 230, 230);
}
+
+
+.CategoryParent {
+ color: gray;
+}
=======================================
--- /trunk/vanillaapp/settings/structure.php Mon Jun 14 20:18:11 2010
+++ /trunk/vanillaapp/settings/structure.php Sat Jul 10 22:18:45 2010
@@ -72,6 +72,17 @@
->Column("MD5", "varchar(32)")
->Set($Explicit, $Drop);

+$Construct->Table("Tag")
+ ->PrimaryKey("No")
+ ->Column("Name", "varchar(128)")
+ ->Set($Explicit, $Drop);
+
+$Construct->Table("ProblemTagRelation")
+ ->PrimaryKey("No")
+ ->Column("Problem", "int", -1, "index")
+ ->Column("Tag", "int", -1, "index")
+ ->Set($Explicit, $Drop);
+
if($Drop)
{
$PermissionModel = Gdn::PermissionModel();
=======================================
--- /trunk/vanillaapp/views/problems/my.php Sat Jul 10 22:18:29 2010
+++ /trunk/vanillaapp/views/problems/my.php Sat Jul 10 22:18:45 2010
@@ -72,7 +72,7 @@
var id = obj.aData[2];
var ret = "";
if(obj.aData[0] == "DRAFT" ||
<?=($this->IsAdmin() ? 1 : 0)?>) {
- ret += '<a href="<?=Url("/problems/edit/")?>'
+ id + '">Edit</a>';
+ ret += '<a href="<?=Url("/problems/edit")?>/'
+ id + '">Edit</a>';
ret += ' | ';
ret += "<a href=\"#\"
onclick=\"confirmDeletion('<?=Url("/problems/delete/")?>/" + id + "',
this);\">Delete</a>";
}

Reply all
Reply to author
Forward
0 new messages