Skip to content

Commit

Permalink
get start the manage project page and a little code re-organize.
Browse files Browse the repository at this point in the history
created the classes folder for all kind of classes.
  • Loading branch information
seanchen committed Feb 7, 2013
1 parent 2226cb0 commit ae17011
Show file tree
Hide file tree
Showing 4 changed files with 202 additions and 187 deletions.
4 changes: 2 additions & 2 deletions wp-trac-client/admin-manager.php
Expand Up @@ -10,8 +10,8 @@
wptc_handle_pm_submit($pm_context);

switch($pm_context['action']) {
case 'editproject':
wptc_widget_eidt_project();
case 'manageproject':
wptc_widget_manage_project();
break;
case 'list':
default:
Expand Down
199 changes: 14 additions & 185 deletions wp-trac-client/admin-widgets.php
@@ -1,189 +1,5 @@
<?php

// load the WP_List_Table class.
if(!class_exists('WP_List_Table')){
require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
}

/**
* the customize list table class for projcts list.
*/
class WPTC_Project_List_Table extends WP_List_Table {

function __construct() {
global $status, $page;

parent::__construct(array(
'singular' => 'project',
'plural' => 'projects',
'ajax' => false
));
}

/**
* define the columns here,
*/
function get_columns() {
// the values for each key will show as the
// title columns
// the key will be used in method name to
// customize the column value for each item/row.
$columns = array(
'cb' => '<input type="checkbox" />',
'name' => 'Name',
'description' => 'Description'
// current milestones / versions
// components
);
return $columns;
}

/**
* cb is the checkbox column, it will be treated specially!
* this method customize the value of cb column for each
* item (each row).
*/
function column_cb($item) {
return sprintf(
'<input type="checkbox" name="%1$s[]"
value="%2$s" />',
// for %1$s, using lable for singular,
// defined in the consturct method.
$this->_args['singular'],
// project id is the value.
$item['id']
);
}

/**
* customize the value for name column.
*/
function column_name($item) {

// Build row actions: Edit and Delete
$aTemp = '<a href="?page=%s&action=%s&project=%s">%s</a>';
$actions = array(
'edit' => sprintf($aTemp, $_REQUEST['page'],
'editproject',$item['name'],
'Edit'),
'delete' => sprintf($aTemp, $_REQUEST['page'],
'deleteproject',$item['name'],
'Delete'),
);

// Return the title contents
// <span style="color:silver">(id:%2$s)</span>
// /*$2%s*/ $item['ID'],
return sprintf('%1$s %2$s',
/*$1%s*/ $item['name'],
/*$2%s*/ $this->row_actions($actions)
);
}

/**
* here is for easy columns.
* column_name should be one the keys defined in
* method get_columns.
*/
function column_default($item, $column_name) {

switch($column_name) {
case 'description':
return $item[$column_name];
default:
// should not happen.
// in case it happens, print out details...
return print_r($item, true);
}
}

/**
* set the sortable columns here.
*/
function get_sortable_columns() {

$sortable_columns = array(
// true means it's already sorted
'name' => array('title',false),
'description' => array('director',false)
);

return $sortable_columns;
}

/**
* set bulk actions for checkboxes.
*/
function get_bulk_actions() {

$actions = array(
'delete' => 'Delete'
);

return $actions;
}

/**
* handle bulk action here.
*/
function process_bulk_action() {

if ('delete' === $this->current_action()) {
wp_die('action place holder for now');
}
}

/**
* get ready the data here.
*/
function prepare_items() {

//global $wpdb;

// how many items per page.
$per_page = 5;
$columns = $this->get_columns();
// no hidden for now.
$hidden = array();
$sortable = $this->get_sortable_columns();

$this->_column_headers = array($columns, $hidden,
$sortable);
$this->process_bulk_action();

$data = wptc_get_projects();

// this is array sorting,
// we could query database directly
function usort_reorder($a,$b){
$orderby = (!empty($_REQUEST['orderby'])) ? $_REQUEST['orderby'] : 'name'; //If no sort, default to name
$order = (!empty($_REQUEST['order'])) ? $_REQUEST['order'] : 'asc'; //If no order, default to asc
// Determine sort order
$result = strcmp($a[$orderby], $b[$orderby]);
// Send final sort direction to usort
return ($order==='asc') ? $result : -$result;
}
usort($data, 'usort_reorder');

// for pagination.
$current_page = $this->get_pagenum();
$total_items = count($data);
$data = array_slice($data,
(($current_page - 1) * $per_page),
$per_page);

// here is the data
$this->items = $data;

// tracking pages.
$this->set_pagination_args(array(
'total_items' => $total_items,
'per_page' => $per_page,
'total_pages' => ceil($total_items / $per_page)
));
}
}

/**
* load and analyzt the request context.
* the context will be array with
Expand Down Expand Up @@ -211,7 +27,7 @@ function wptc_widget_projects_list() {

echo <<<EOT
<div id="icon-edit-pages" class="icon32"><br/></div>
<h2>Trac Projects</h2>
<h2>Trac Project Management</h2>
EOT;
// new projcet form.
wptc_widget_new_project();
Expand Down Expand Up @@ -341,3 +157,16 @@ function wptc_handle_delete_project() {
</strong></p></div>
EOT;
}

/**
* page to manage a project.
*/
function wptc_widget_manage_project() {

$name = $_REQUEST['project'];

echo <<<EOT
<div id="icon-edit-pages" class="icon32"><br/></div>
<h2>Manage Project <b>$name</b></h2>
EOT;
}

0 comments on commit ae17011

Please sign in to comment.