diff --git a/wp-trac-client/admin-manager.php b/wp-trac-client/admin-manager.php index fdf8379..f1c009a 100644 --- a/wp-trac-client/admin-manager.php +++ b/wp-trac-client/admin-manager.php @@ -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: diff --git a/wp-trac-client/admin-widgets.php b/wp-trac-client/admin-widgets.php index e693856..b047a61 100644 --- a/wp-trac-client/admin-widgets.php +++ b/wp-trac-client/admin-widgets.php @@ -1,189 +1,5 @@ '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' => '', - '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( - '', - // 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 = '%s'; - $actions = array( - 'edit' => sprintf($aTemp, $_REQUEST['page'], - 'editproject',$item['name'], - 'Edit'), - 'delete' => sprintf($aTemp, $_REQUEST['page'], - 'deleteproject',$item['name'], - 'Delete'), - ); - - // Return the title contents - // (id:%2$s) - // /*$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 @@ -211,7 +27,7 @@ function wptc_widget_projects_list() { echo <<
-

Trac Projects

+

Trac Project Management

EOT; // new projcet form. wptc_widget_new_project(); @@ -341,3 +157,16 @@ function wptc_handle_delete_project() {

EOT; } + +/** + * page to manage a project. + */ +function wptc_widget_manage_project() { + + $name = $_REQUEST['project']; + + echo <<
+

Manage Project $name

+EOT; +} diff --git a/wp-trac-client/classes/listtables.php b/wp-trac-client/classes/listtables.php new file mode 100644 index 0000000..4b1d830 --- /dev/null +++ b/wp-trac-client/classes/listtables.php @@ -0,0 +1,185 @@ + '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' => '', + '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( + '', + // 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 = '%s'; + $actions = array( + 'edit' => sprintf($aTemp, $_REQUEST['page'], + 'manageproject', + $item['name'], 'Manage'), + 'delete' => sprintf($aTemp, $_REQUEST['page'], + 'deleteproject', + $item['name'], 'Delete'), + ); + + // Return the title contents + // (id:%2$s) + // /*$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) + )); + } +} diff --git a/wp-trac-client/wp-trac-client.php b/wp-trac-client/wp-trac-client.php index 86e34ed..28be1bc 100644 --- a/wp-trac-client/wp-trac-client.php +++ b/wp-trac-client/wp-trac-client.php @@ -43,6 +43,7 @@ define('MY_PLUGIN_FILE', $my_plugin_file); define('MY_PLUGIN_PATH', WP_PLUGIN_DIR.'/'.basename(dirname($my_plugin_file))); +require_once(MY_PLUGIN_PATH . '/classes/listtables.php'); require_once(MY_PLUGIN_PATH . '/admin-tags.php'); require_once(MY_PLUGIN_PATH . '/admin-widgets.php');