Skip to content

Commit

Permalink
Much better look for configuration list
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdma committed Feb 11, 2016
1 parent fdff8a6 commit c348c12
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 43 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Entity-Centric API integration for Wordpress 4
# Entity-Centric API integration for WordPress 4

A set of utilities for handling and consuming data sources for ECApi from within a Wordpress installation
A set of utilities for handling and consuming data sources for ECApi from within a WordPress installation

## Requirements

To __build__ the project you will need to have [Bower](http://bower.io) and [Composer](http://getcomposer.org) installed. At the risk of stating the obvious, this is because this package does _not_ come with the PHP and JavaScript dependencies of the project bundled with it.

To __run__ the project after building it, you will need a Wordpress installation (so far only [version 4.2](https://codex.wordpress.org/Version_4.0.x) has been tested), and by extension a *AMP stack.
To __run__ the project after building it, you will need a WordPress 4 installation (so far only [version 4.3](http://codex.wordpress.org/Version_4.3) has been tested), and by extension a *AMP stack.

## Building
From within the root dir of the project:
Expand All @@ -19,4 +19,4 @@ Then, assuming Composer is installed either there or globally on your system:

The above command will also run Bower automatically as a post-install hook.

Finally, stage the whole `ecapi` directory into the `wp-content/plugins` of your Wordpress.
Finally, stage the whole `ecapi` directory into the `wp-content/plugins` of your WordPress.
8 changes: 8 additions & 0 deletions plugins/ecapi/css/config.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
table.datasets { border-collapse: collapse; margin-top:20px; width:95% }
table.datasets tbody tr { border-top: 1px solid #aaa }
table.datasets tbody tr td { padding: 5px 3px 10px }
table.datasets th { text-align: left }
table.datasets .ds_endpoint { font-size: 0.9em }
table.datasets .ds_entry a { font-weight: bold }
table.datasets .ds_entry .ds_meta { font-size: 0.8em; margin-left: 10px }
table.datasets .ds_status { font-size: 1.8em; text-align: center }
6 changes: 5 additions & 1 deletion plugins/ecapi/ecapi.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Plugin Name: MKS Entity-Centric API Management
Description: Utilities for accessing, testing and configuring an Entity-Centric API from a WordPress installation
Plugin URI: http://github.com/mk-smart/ecapi-wordpress
Version: 0.1.0
Version: 0.1.1
Author: Alessandro Adamou
Author URI: http://kmi.open.ac.uk/people/member/alessandro-adamou
*/
Expand Down Expand Up @@ -157,6 +157,7 @@ function ecapi_admin_intercept() {

function ecapi_config_page() {
require_once dirname(__FILE__) . '/inc/ecapiconfigform/couchdb.class.php';
require_once dirname(__FILE__) . '/lib/catalogue.php';
include dirname(__FILE__) . '/config.php';
}

Expand Down Expand Up @@ -222,14 +223,17 @@ function ecapi_setting_url() {
function add_scripts(){
$plugdir = dirname(__FILE__) . '/ecapi'; // Stupid Wordpress function plugins_url going bananas
$scripts_head = array(
array( 'ecapi-conf', 'js/config.js', array() ),
array( 'prism', 'vendor/bower/prism/prism.js', array() )
);
foreach( $scripts_head as $k => $v )
wp_register_script( $v[0], plugins_url($v[1], $plugdir), $v[2] );
foreach( $scripts_head as $k => $v )
wp_enqueue_script($v[0]);

wp_register_style('ecapi_conf', plugins_url('css/config.css', $plugdir), array(), FALSE, 'all');
wp_register_style('prism', plugins_url('vendor/bower/prism/themes/prism.css', $plugdir), array(), '20120208', 'all');
wp_enqueue_style('ecapi_conf');
wp_enqueue_style('prism');
}

Expand Down
32 changes: 0 additions & 32 deletions plugins/ecapi/inc/config_edit.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,6 @@

<?php

function listDatasetsDiocane(){
$dacc = MKSDC_DataAccess::instance();
$type = 'mksdc-datasets';
$args=array(
'post_type' => $type,
'post_status' => 'publish',
'posts_per_page' => -1,
'ignore_sticky_posts'=> 1
);
$my_query = new WP_Query($args);
$datasets = array();
while ($my_query->have_posts()) {
$my_query->the_post();
$tags = get_the_tags();
array_push($datasets, array(
'uuid' => $dacc->getDatasetUUIDByPostId(get_the_id()),
'permalink' => get_the_permalink(),
'post_title' => get_the_title()
));
}
wp_reset_query();

function cmpa($a, $b)
{
return strcmp($a['post_title'], $b['post_title']);
}

usort($datasets, "cmpa");

return $datasets;
}

$_id = $_GET['id'];
$opts = get_option('ecapi_options');
$dbms = new couchdb(
Expand Down
51 changes: 45 additions & 6 deletions plugins/ecapi/inc/config_list.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,60 @@ $dbms = new couchdb(
$opts['ecapi_config_db_username'], $opts['ecapi_config_db_password']
);
$json = $dbms->getDoc('datasets', '/_design/catalogue/_view/');
$uuids = array();
foreach( listDatasetsDiocane() as $ds ) $uuids []= $ds['uuid'];

$type_support = array();
$typemaps = $dbms->getDoc('typemaps', '/_design/compile/_view/');
foreach( $typemaps['data']->rows as $row ) {
if( isset($row->value->dataset) ) $type_support[$row->value->dataset] []= $row->key;
}
?>
<table>
<div style="position:relative">
<button class="button" onclick="window.location.href='?page=ecapi-config&action=edit'" style="position:absolute;right:30px;top:-40px">Add Configuration</button>

<table class="datasets" id="configurations">
<thead><tr>
<td>ID</id>
<td>Endpoint</id>
<th>Configuration ID</th>
<th>Service endpoint</th>
<th>Linked</th>
</tr></thead>
<tbody>
<?php foreach( $json['data']->rows as $row ) : ?>
<tr>
<td><a href="?page=ecapi-config&action=view&id=<?php print urlencode($row->id) ?>"><?php print $row->id ?></a></td>
<td><?php print $row->value->service_url ?></td>
<td class="ds_entry">
<a href="?page=ecapi-config&action=view&id=<?php print urlencode($row->id) ?>" title="<?php print $row->id ?>"><?php print $row->id ?></a>
<div class="ds_meta">
<?php if( isset($type_support[$row->id]) ) {
$ar = $type_support[$row->id];
sort($ar);
print "supports: ";
for( $i = 0; $i < count($ar); $i++ ) {
if( $i > 0 ) print ', ';
$expl = explode( '/', $ar[$i] );
$s = end($expl);
print "<strong>$s</strong>";
}
} ?>
</div>
</td>
<td class="ds_endpoint"><?php print $row->value->service_url ?></td>
<td class="ds_status">
<?php if( isset($row->value->catalogue_uuid) )
print in_array( $row->value->catalogue_uuid, $uuids ) ? "&#10004;" : "&#x26a0;";
?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>

<hr/>
<button class="button" onclick="window.location.href='?page=ecapi-config&action=edit'" style="float:right">Add New</button>

<script>
jQuery('table#configurations td a').each(function(i,item){
var text = jQuery(this).text();
jQuery(this).text(shortUrl(text,80));
});
</script>
28 changes: 28 additions & 0 deletions plugins/ecapi/js/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
function shortString(s, l, reverse){
var stop_chars = [' ','/', '&'];
var acceptable_shortness = l * 0.80; // When to start looking for stop characters
var reverse = typeof(reverse) != "undefined" ? reverse : false;
var s = reverse ? s.split("").reverse().join("") : s;
var short_s = "";

for(var i=0; i < l-1; i++){
short_s += s[i];
if(i >= acceptable_shortness && stop_chars.indexOf(s[i]) >= 0){
break
}
};
if(reverse){ return short_s.split("").reverse().join("") };
return short_s
};

function shortUrl(url, l){
var l = typeof(l) != "undefined" ? l : 50;
var chunk_l = (l/2);
var url = url.replace("http://","").replace("https://","");

if(url.length <= l){ return url };

var start_chunk = shortString(url, chunk_l, false);
var end_chunk = shortString(url, chunk_l, true);
return start_chunk + "..." + end_chunk
};
1 change: 1 addition & 0 deletions plugins/ecapi/lib/catalogue.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?phpfunction listDatasetsDiocane(){ $dacc = MKSDC_DataAccess::instance(); $type = 'mksdc-datasets'; $args=array( 'post_type' => $type, 'post_status' => 'publish', 'posts_per_page' => -1, 'ignore_sticky_posts'=> 1 ); $my_query = new WP_Query($args); $datasets = array(); while ($my_query->have_posts()) { $my_query->the_post(); $tags = get_the_tags(); array_push($datasets, array( 'uuid' => $dacc->getDatasetUUIDByPostId(get_the_id()), 'permalink' => get_the_permalink(), 'post_title' => get_the_title() )); } wp_reset_query(); function cmpa($a, $b) { return strcmp($a['post_title'], $b['post_title']); } usort($datasets, "cmpa"); return $datasets;}
Expand Down

0 comments on commit c348c12

Please sign in to comment.