Skip to content

Commit

Permalink
Mark tables as non-managed.
Browse files Browse the repository at this point in the history
  • Loading branch information
samwilson committed Jan 4, 2016
1 parent e5e91f2 commit 1f24083
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ php:

# WordPress versions to be tested against.
env:
- WP_VERSION=4.3
- WP_VERSION=4.4
- WP_VERSION=master

# Clones WordPress and configures our testing environment.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Donate link: https://www.bushheritage.org.au/donatenow
* Tags: MySQL, databases, tables, data, CRUD, import, export, CSV, shortcode, OpenStreetMap, KML
* Requires at least: 4.2
* Tested up to: 4.3
* Tested up to: 4.4
* Stable tag: trunk
* License: GPLv2 or later
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
Expand Down
10 changes: 10 additions & 0 deletions assets/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,21 @@ jQuery(document).ready(function ($) {
$("input[data-column-type='time']").mask("99:99:99", { placeholder:"hh:mm:ss" } );
$("input[data-column-type='time']").timepicker( { timeFormat: 'HH:mm:ss', timeOnly: true } );
$("input[data-column-type='year']").mask("9999");

/**
* Schema editing.
*/
$(document.body).on("keyup blur", "input.schema-identifier", function() {
$(this).val($(this).val().replace(/[^a-zA-Z0-9_ ]/g,'')).change();
$(this).val($(this).val().replace(/ /g,'_')).change();
$(this).val($(this).val().toLowerCase());
});
$("#tabulate-schema-table-list a#select-all").click(function(){
$(this).parents("form").find("input[type='checkbox']").prop("checked", true);
});
$("#tabulate-schema-table-list a#select-none").click(function(){
$(this).parents("form").find("input[type='checkbox']").prop("checked", false);
});


/**
Expand Down
10 changes: 5 additions & 5 deletions assets/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ table.tabulate.widefat thead th:hover { background-color:#deedee }
table.tabulate.widefat thead th:hover .sort-icons a { visibility:visible }
table.tabulate.widefat td { line-height:1em }

form.tabulate-schema fieldset { border:2px groove #bbb }
form.tabulate-schema legend { margin:0.1em 0.6em; line-height:1em }
form.tabulate-schema .save { margin:1em 0 }
#tabulate-schema-table-list { float:left; height:500px; overflow-y:scroll; margin-right:1em; background-color:white }
#tabulate-schema-table-list ol { margin:0 0.5em; list-style-type:none }

#tabulate-schema-table-list { float:left; width:30em; margin-right:1em; background-color:white; border:1px solid #bbb }
#tabulate-schema-table-list p { margin:0.5em }
#tabulate-schema-table-list ol { overflow-y:scroll; height:400px; border:2px solid #efefef; border-width:2px 0;
list-style-type:none; padding:0.5em; margin:0 }
#tabulate-schema-table-list li { margin:0 }
#tabulate-schema-table-list a { text-decoration:none }
#tabulate-schema-form { padding-left:1em }
Expand Down
4 changes: 4 additions & 0 deletions src/Controllers/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,12 @@ public function register_routes() {
public function table_names() {
$db = new Database( $this->wpdb );
$tables = $db->get_tables( false );
$managed = get_option( TABULATE_SLUG . '_managed_tables' );
$out = array();
foreach ( $tables as $table ) {
if ( ! in_array( $table->get_name(), $managed ) ) {
continue;
}
$out[] = array(
'value' => $table->get_name(),
'label' => $table->get_title(),
Expand Down
15 changes: 14 additions & 1 deletion src/Controllers/SchemaController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ class SchemaController extends ControllerBase {
public function index( $args ) {
$db = new Database( $this->wpdb );
$tables = $db->get_tables();
$template = new \WordPress\Tabulate\Template( 'schema.html' );
$template = new Template( 'schema.html' );
$template->tables = $tables;
$template->managed_tables = get_option(TABULATE_SLUG . '_managed_tables', array());
if ( isset( $args['schema'] ) ) {
$template->schema = $db->get_table( $args['schema'] );
}
Expand All @@ -26,6 +27,18 @@ public function index( $args ) {
return $template->render();
}

public function tables( $args ) {
// Only save table names that we've got access to (which should be all).
$db = new Database( $this->wpdb );
$tables = array_intersect($db->get_table_names(), $_POST['managed_tables']);
update_option(TABULATE_SLUG . '_managed_tables', $tables);

// Inform the user and redirect.
$template = new Template( 'schema.html' );
$template->add_notice( 'updated', 'Table list saved.' );
wp_redirect( admin_url( 'admin.php?page=tabulate_schema' ) );
}

public function save( $args ) {
if ( ! isset( $args['schema'] ) ) {
$url = admin_url( 'admin.php?page=tabulate_schema' );
Expand Down
4 changes: 2 additions & 2 deletions tabulate.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
* Author URI: http://samwilson.id.au/
* License: GPL-2.0+
* Text Domain: tabulate
* Version: 2.3.1
* Version: 2.4.0
*/
define( 'TABULATE_VERSION', '2.3.1' );
define( 'TABULATE_VERSION', '2.4.0' );
define( 'TABULATE_SLUG', 'tabulate' );

// Make sure Composer has been set up (for installation from Git, mostly).
Expand Down
32 changes: 19 additions & 13 deletions templates/schema.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,40 @@ <h1>
{#<a href="{{admin_url('admin.php?page=tabulate_schema')}}" class="page-title-action">New table</a>#}
</h1>

<form action="{{admin_url('admin.php?page=tabulate_schema&schema='~schema.get_name~'&action=save')}}" method="post" class="tabulate-schema">

<form action="{{admin_url('admin.php?page=tabulate_schema&action=tables')}}" method="post" class="tabulate-schema">
<fieldset id="tabulate-schema-table-list">
<legend>Select a table to edit:</legend>
<p>
In this panel, you can select which tables are available for selection in the quick-jump menu.
</p>
<ol>
{% for table in tables %}
<li>
{#<input type="checkbox" name="managed_tables[{{table.get_name}}]" id="managed_tables_{{table.get_name}}" disabled />#}
<label for="managed_tables_{{table.get_name}}">
<a href="{{admin_url('admin.php?page=tabulate_schema&schema='~table.get_name)}}">
{{table.get_title}}
</a>
</label>
<input {% if table.get_name in managed_tables %}checked{% endif %}
type="checkbox" name="managed_tables[]" value="{{table.get_name}}" />
<a href="{{admin_url('admin.php?page=tabulate_schema&schema='~table.get_name)}}">
{{table.get_title}}
</a>
</li>
{% endfor %}
</ol>
<p>
<a class="button button-secondary" id="select-all">Select all</a>
<a class="button button-secondary" id="select-none">Select none</a>
<input type="submit" value="Save" class="button button-primary" />
</p>
</fieldset>
</form>

{% if schema %}
<form action="{{admin_url('admin.php?page=tabulate_schema&schema='~schema.get_name~'&action=save')}}" method="post" class="tabulate-schema">
<fieldset id="tabulate-schema-form">
<legend>
<h2>
{% if schema %}
Editing <a href="{{schema.get_url()}}" title="Jump to this table">{{schema.get_title}}</a>
{% else %}
New table
{% endif%}
</legend>
</h2>
<p>
<label for="new_name">New name:</label>
<input type="text" id="new_name" name="new_name" value="{{schema.get_name}}" class="schema-identifier" required />
Expand Down Expand Up @@ -105,9 +112,8 @@ <h1>
<input type="submit" value="Save changes" class="btn btn-default" />
</p>
</fieldset>
{% endif%}

</form>
{% endif%}

<div class="clear"></div>

Expand Down

0 comments on commit 1f24083

Please sign in to comment.