Skip to content

Commit

Permalink
Remove PK from schema-editing.
Browse files Browse the repository at this point in the history
  • Loading branch information
samwilson committed Feb 16, 2016
1 parent 8b094d9 commit e217c8e
Show file tree
Hide file tree
Showing 10 changed files with 297 additions and 196 deletions.
17 changes: 3 additions & 14 deletions assets/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,53 +36,42 @@ jQuery(document).ready(function ($) {
});
$(document).on('change', "form.tabulate-schema select[name*='xtype']", function() {
var xtype = $(this).val();
$pk = $(this).parents("tr").find("input[name='primary_key']");
$size = $(this).parents("tr").find("input[name*='size']");
$targetTable = $(this).parents("tr").find("select[name*='target_table']");
$autoInc = $(this).parents("tr").find("input[name='auto_increment']");
var $size = $(this).parents("tr").find("input[name*='size']");
var $targetTable = $(this).parents("tr").find("select[name*='target_table']");
var $autoInc = $(this).parents("tr").find("input[name='auto_increment']");
if (xtype === 'fk') {
$pk.prop("disabled", true);
$size.prop("disabled", true);
$targetTable.prop("disabled", false).prop("required", true);
$autoInc.prop("disabled", true);
} else if (xtype === 'integer') {
$pk.prop("disabled", false);
$size.prop("disabled", false).prop("required", true);
$targetTable.prop("disabled", true);
$autoInc.prop("disabled", false);
} else if (xtype === 'decimal') {
$pk.prop("disabled", true);
$size.prop("disabled", false).prop("required", true);
$targetTable.prop("disabled", true);
$autoInc.prop("disabled", true);
} else if (xtype === 'boolean') {
console.log(xtype);
$pk.prop("disabled", true);
$size.prop("disabled", true);
$targetTable.prop("disabled", true);
$autoInc.prop("disabled", true);
} else if (xtype === 'text_short') {
$pk.prop("disabled", true);
$size.prop("disabled", false).prop("required", true);
$targetTable.prop("disabled", true);
$autoInc.prop("disabled", true);
} else if (xtype === 'text_long') {
$pk.prop("disabled", true);
$size.prop("disabled", true);
$targetTable.prop("disabled", true);
$autoInc.prop("disabled", true);
} else if (xtype === 'date') {
$pk.prop("disabled", false);
$size.prop("disabled", true);
$targetTable.prop("disabled", true);
$autoInc.prop("disabled", true);
} else if (xtype === 'point') {
$pk.prop("disabled", true);
$size.prop("disabled", true);
$targetTable.prop("disabled", true);
$autoInc.prop("disabled", true);
} else {
$pk.prop("disabled", true);
$size.prop("disabled", false);
$targetTable.prop("disabled", true);
$autoInc.prop("disabled", true);
Expand Down
3 changes: 0 additions & 3 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,4 @@
<directory>tests</directory>
</testsuite>
</testsuites>
<logging>
<log type="testdox-html" target="testdox.html"/>
</logging>
</phpunit>
28 changes: 27 additions & 1 deletion src/Controllers/SchemaController.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
<?php
/**
* This file contains only one class.
*
* @package Tabulate
* @file
*/

namespace WordPress\Tabulate\Controllers;

Expand All @@ -7,8 +13,17 @@
use \WordPress\Tabulate\DB\Column;
use \WordPress\Tabulate\Template;

/**
* This controller handles creating, modifying, and deleting tables in the database.
*/
class SchemaController extends ControllerBase {

/**
* View and edit the structure of the given table.
*
* @param string[] $args The request arguments.
* @return string
*/
public function index( $args ) {
$template = new Template( 'table/schema.html' );
if ( ! current_user_can( 'promote_users' ) ) {
Expand All @@ -26,6 +41,11 @@ public function index( $args ) {
return $template->render();
}

/**
* Add a new table and redirect to its schema-editing page.
*
* @param string[] $args The request arguments.
*/
public function newtable( $args ) {
// Create table.
$db = new Database( $this->wpdb );
Expand All @@ -39,6 +59,11 @@ public function newtable( $args ) {
exit;
}

/**
* Save modifications to a table's schema.
*
* @param string[] $args The request arguments.
*/
public function save( $args ) {
if ( ! isset( $args['table'] ) || ! current_user_can( 'promote_users' ) ) {
$url = admin_url( 'admin.php?page=tabulate' );
Expand Down Expand Up @@ -104,7 +129,8 @@ public function save( $args ) {

/**
* Delete (drop) a table.
* @param string[] $args
*
* @param string[] $args The request arguments.
*/
public function delete( $args ) {
$template = new Template( 'table/delete.html' );
Expand Down

0 comments on commit e217c8e

Please sign in to comment.