Skip to content

Commit c348c12

Browse files
committed
Much better look for configuration list
1 parent fdff8a6 commit c348c12

File tree

7 files changed

+91
-43
lines changed

7 files changed

+91
-43
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
# Entity-Centric API integration for Wordpress 4
1+
# Entity-Centric API integration for WordPress 4
22

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

55
## Requirements
66

77
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.
88

9-
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.
9+
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.
1010

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

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

22-
Finally, stage the whole `ecapi` directory into the `wp-content/plugins` of your Wordpress.
22+
Finally, stage the whole `ecapi` directory into the `wp-content/plugins` of your WordPress.

plugins/ecapi/css/config.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
table.datasets { border-collapse: collapse; margin-top:20px; width:95% }
2+
table.datasets tbody tr { border-top: 1px solid #aaa }
3+
table.datasets tbody tr td { padding: 5px 3px 10px }
4+
table.datasets th { text-align: left }
5+
table.datasets .ds_endpoint { font-size: 0.9em }
6+
table.datasets .ds_entry a { font-weight: bold }
7+
table.datasets .ds_entry .ds_meta { font-size: 0.8em; margin-left: 10px }
8+
table.datasets .ds_status { font-size: 1.8em; text-align: center }

plugins/ecapi/ecapi.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Plugin Name: MKS Entity-Centric API Management
44
Description: Utilities for accessing, testing and configuring an Entity-Centric API from a WordPress installation
55
Plugin URI: http://github.com/mk-smart/ecapi-wordpress
6-
Version: 0.1.0
6+
Version: 0.1.1
77
Author: Alessandro Adamou
88
Author URI: http://kmi.open.ac.uk/people/member/alessandro-adamou
99
*/
@@ -157,6 +157,7 @@ function ecapi_admin_intercept() {
157157

158158
function ecapi_config_page() {
159159
require_once dirname(__FILE__) . '/inc/ecapiconfigform/couchdb.class.php';
160+
require_once dirname(__FILE__) . '/lib/catalogue.php';
160161
include dirname(__FILE__) . '/config.php';
161162
}
162163

@@ -222,14 +223,17 @@ function ecapi_setting_url() {
222223
function add_scripts(){
223224
$plugdir = dirname(__FILE__) . '/ecapi'; // Stupid Wordpress function plugins_url going bananas
224225
$scripts_head = array(
226+
array( 'ecapi-conf', 'js/config.js', array() ),
225227
array( 'prism', 'vendor/bower/prism/prism.js', array() )
226228
);
227229
foreach( $scripts_head as $k => $v )
228230
wp_register_script( $v[0], plugins_url($v[1], $plugdir), $v[2] );
229231
foreach( $scripts_head as $k => $v )
230232
wp_enqueue_script($v[0]);
231233

234+
wp_register_style('ecapi_conf', plugins_url('css/config.css', $plugdir), array(), FALSE, 'all');
232235
wp_register_style('prism', plugins_url('vendor/bower/prism/themes/prism.css', $plugdir), array(), '20120208', 'all');
236+
wp_enqueue_style('ecapi_conf');
233237
wp_enqueue_style('prism');
234238
}
235239

plugins/ecapi/inc/config_edit.phtml

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,6 @@
22

33
<?php
44

5-
function listDatasetsDiocane(){
6-
$dacc = MKSDC_DataAccess::instance();
7-
$type = 'mksdc-datasets';
8-
$args=array(
9-
'post_type' => $type,
10-
'post_status' => 'publish',
11-
'posts_per_page' => -1,
12-
'ignore_sticky_posts'=> 1
13-
);
14-
$my_query = new WP_Query($args);
15-
$datasets = array();
16-
while ($my_query->have_posts()) {
17-
$my_query->the_post();
18-
$tags = get_the_tags();
19-
array_push($datasets, array(
20-
'uuid' => $dacc->getDatasetUUIDByPostId(get_the_id()),
21-
'permalink' => get_the_permalink(),
22-
'post_title' => get_the_title()
23-
));
24-
}
25-
wp_reset_query();
26-
27-
function cmpa($a, $b)
28-
{
29-
return strcmp($a['post_title'], $b['post_title']);
30-
}
31-
32-
usort($datasets, "cmpa");
33-
34-
return $datasets;
35-
}
36-
375
$_id = $_GET['id'];
386
$opts = get_option('ecapi_options');
397
$dbms = new couchdb(

plugins/ecapi/inc/config_list.phtml

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,60 @@ $dbms = new couchdb(
55
$opts['ecapi_config_db_username'], $opts['ecapi_config_db_password']
66
);
77
$json = $dbms->getDoc('datasets', '/_design/catalogue/_view/');
8+
$uuids = array();
9+
foreach( listDatasetsDiocane() as $ds ) $uuids []= $ds['uuid'];
10+
11+
$type_support = array();
12+
$typemaps = $dbms->getDoc('typemaps', '/_design/compile/_view/');
13+
foreach( $typemaps['data']->rows as $row ) {
14+
if( isset($row->value->dataset) ) $type_support[$row->value->dataset] []= $row->key;
15+
}
816
?>
9-
<table>
17+
<div style="position:relative">
18+
<button class="button" onclick="window.location.href='?page=ecapi-config&action=edit'" style="position:absolute;right:30px;top:-40px">Add Configuration</button>
19+
20+
<table class="datasets" id="configurations">
1021
<thead><tr>
11-
<td>ID</id>
12-
<td>Endpoint</id>
22+
<th>Configuration ID</th>
23+
<th>Service endpoint</th>
24+
<th>Linked</th>
1325
</tr></thead>
1426
<tbody>
1527
<?php foreach( $json['data']->rows as $row ) : ?>
1628
<tr>
17-
<td><a href="?page=ecapi-config&action=view&id=<?php print urlencode($row->id) ?>"><?php print $row->id ?></a></td>
18-
<td><?php print $row->value->service_url ?></td>
29+
<td class="ds_entry">
30+
<a href="?page=ecapi-config&action=view&id=<?php print urlencode($row->id) ?>" title="<?php print $row->id ?>"><?php print $row->id ?></a>
31+
<div class="ds_meta">
32+
<?php if( isset($type_support[$row->id]) ) {
33+
$ar = $type_support[$row->id];
34+
sort($ar);
35+
print "supports: ";
36+
for( $i = 0; $i < count($ar); $i++ ) {
37+
if( $i > 0 ) print ', ';
38+
$expl = explode( '/', $ar[$i] );
39+
$s = end($expl);
40+
print "<strong>$s</strong>";
41+
}
42+
} ?>
43+
</div>
44+
</td>
45+
<td class="ds_endpoint"><?php print $row->value->service_url ?></td>
46+
<td class="ds_status">
47+
<?php if( isset($row->value->catalogue_uuid) )
48+
print in_array( $row->value->catalogue_uuid, $uuids ) ? "&#10004;" : "&#x26a0;";
49+
?>
50+
</td>
1951
</tr>
2052
<?php endforeach; ?>
2153
</tbody>
2254
</table>
55+
</div>
2356

2457
<hr/>
25-
<button class="button" onclick="window.location.href='?page=ecapi-config&action=edit'" style="float:right">Add New</button>
58+
59+
<script>
60+
jQuery('table#configurations td a').each(function(i,item){
61+
var text = jQuery(this).text();
62+
jQuery(this).text(shortUrl(text,80));
63+
});
64+
</script>

plugins/ecapi/js/config.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
function shortString(s, l, reverse){
2+
var stop_chars = [' ','/', '&'];
3+
var acceptable_shortness = l * 0.80; // When to start looking for stop characters
4+
var reverse = typeof(reverse) != "undefined" ? reverse : false;
5+
var s = reverse ? s.split("").reverse().join("") : s;
6+
var short_s = "";
7+
8+
for(var i=0; i < l-1; i++){
9+
short_s += s[i];
10+
if(i >= acceptable_shortness && stop_chars.indexOf(s[i]) >= 0){
11+
break
12+
}
13+
};
14+
if(reverse){ return short_s.split("").reverse().join("") };
15+
return short_s
16+
};
17+
18+
function shortUrl(url, l){
19+
var l = typeof(l) != "undefined" ? l : 50;
20+
var chunk_l = (l/2);
21+
var url = url.replace("http://","").replace("https://","");
22+
23+
if(url.length <= l){ return url };
24+
25+
var start_chunk = shortString(url, chunk_l, false);
26+
var end_chunk = shortString(url, chunk_l, true);
27+
return start_chunk + "..." + end_chunk
28+
};

plugins/ecapi/lib/catalogue.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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;}

0 commit comments

Comments
 (0)