From: Maxious Date: Sat, 14 Jan 2012 09:31:24 +0000 Subject: Beginnings of visual conflict resolution X-Git-Url: https://maxious.lambdacomplex.org/git/?p=disclosr.git&a=commitdiff&h=2b921f90255f3b989b7ec071e310ebfe9dff3650 --- Beginnings of visual conflict resolution Former-commit-id: f8dfd63919aab30a6b99f6861e80a36b55f5af04 --- --- a/.gitmodules +++ b/.gitmodules @@ -7,4 +7,7 @@ [submodule "lib/springy"] path = lib/springy url = https://github.com/dhotson/springy.git +[submodule "lib/php-diff"] + path = lib/php-diff + url = https://github.com/chrisboulton/php-diff.git --- a/admin/import.php +++ b/admin/import.php @@ -1,6 +1,6 @@ create_db('disclosr-agencies'); } catch (SetteeRestClientException $e) { --- /dev/null +++ b/admin/resolveConflicts.php @@ -1,1 +1,43 @@ + + + + '; +require_once dirname(__FILE__) . '/../lib/php-diff/lib/Diff.php'; +// Generate a side by side diff +require_once dirname(__FILE__) . '/../lib/php-diff/lib/Diff/Renderer/Html/SideBySide.php'; +$renderer = new Diff_Renderer_Html_SideBySide; + + + +$db = $server->get_db('disclosr-agencies'); +$docs = Array(); +try { + $rows = $db->get_view("app", "getConflicts")->rows; + //print_r($rows); + foreach ($rows as $row) { + echo '

' . $row->id . '

'; + echo "Comparing " . $row->value[0] . " and " . $row->value[1]; + $docA = explode(",", json_encode($db->get($row->id . "?rev=" . $row->value[0]))); + $docB = explode(",", json_encode($db->get($row->id . "?rev=" . $row->value[1]))); + // Options for generating the diff + $options = array( + //'ignoreWhitespace' => true, + //'ignoreCase' => true, + ); + + // Initialize the diff class + $diff = new Diff($docA, $docB, $options); + echo $diff->Render($renderer); + } +} catch (SetteeRestClientException $e) { + setteErrorHandler($e); +} +include_footer(); +?> --- a/admin/verify.php +++ b/admin/verify.php @@ -1,6 +1,6 @@ get_db('disclosr-agencies'); --- /dev/null +++ b/alaveteli/exportAgencies.csv.php @@ -1,1 +1,75 @@ +get_db('disclosr-agencies'); + +$tag = Array(); +try { + $rows = $db->get_view("app", "byDeptStateName", null, true)->rows; + //print_r($rows); + foreach ($rows as $row) { + $tag[$row->value] = phrase_to_tag(dept_to_portfolio($row->key)); + } +} catch (SetteeRestClientException $e) { + setteErrorHandler($e); +} + +$fp = fopen('php://output', 'w'); +if ($fp && $db) { + header('Content-Type: text/csv'); + header('Content-Disposition: attachment; filename="export.' . date("c") . '.csv"'); + header('Pragma: no-cache'); + header('Expires: 0'); + fputcsv($fp, $headers); + try { + $agencies = $db->get_view("app", "byCanonicalName", null, true)->rows; + //print_r($rows); + foreach ($agencies as $agency) { + // print_r($agency); + $row = Array(); + $row["#id"] = $agency->value->_id; + $row["name"] = $agency->value->name; + if (isset($agency->value->foi_email)) { + $row["request_email"] = $agency->value->foi_email; + } else { + $row["request_email"] = "foi@".GetDomain($agency->value->website); + // + } + if (isset($agency->value->short_name)) { + $row["short_name"] = $agency->value->short_name; + } else { + $out = Array(); + preg_match_all('/[A-Z]/', $agency->value->name, $out); + $row["short_name"] = implode("",$out[0]); + } + $row["notes"] = ""; + $row["publication_scheme"] = $agency->value->infoPublicationSchemeURL; + $row["home_page"] = $agency->value->website; + if ($agency->value->orgType == "FMA-DepartmentOfState") { + $row["tag_string"] = $tag[$agency->value->_id]; + } else { + $row["tag_string"] = $tag[$agency->value->parentOrg];; + } + + fputcsv($fp, array_values($row)); + + if (isset($agency->value->foiBodies)) { + foreach ($agency->value->foiBodies as $foiBody) { + $row['name'] = $foiBody; + $row['short_name'] = ""; + fputcsv($fp, array_values($row)); + } + } + } + } catch (SetteeRestClientException $e) { + setteErrorHandler($e); + } + + die; +} +?> + --- /dev/null +++ b/alaveteli/exportCategories.rb.php @@ -1,1 +1,23 @@ +get_db('disclosr-agencies'); +try { + $rows = $db->get_view("app", "byDeptStateName", null, true)->rows; + //print_r($rows); + foreach ($rows as $row) { + echo ' [ "'.phrase_to_tag(dept_to_portfolio($row->key)).'","'. dept_to_portfolio($row->key).'","'.dept_to_portfolio($row->key).'" ],'.PHP_EOL; + } +} catch (SetteeRestClientException $e) { + setteErrorHandler($e); +} +echo '])'; +?> + --- a/getAgency.php +++ b/getAgency.php @@ -4,6 +4,7 @@ include_header(); function displayValue($key, $value, $mode) { + global $db; if ($mode == "view") { if (is_array($value)) { echo "$key
    "; @@ -30,8 +31,16 @@ } else { if (strpos($key, "_") === 0) { echo""; - } if (strpos($key, "has") === 0) { - echo ""; + } else if ($key == "parentOrg") { + echo ""; + } else if (strpos($key, "has") === 0) { + echo ""; } else { echo ""; if ((strpos($key,"URL") > 0 || $key == 'website')&& $value != "") { @@ -52,8 +61,13 @@ foreach ($defaultFields as $defaultField) { if (!isset($row[$defaultField])) { if ($schemas['agency']['properties'][$defaultField]['type'] == "string") { + if (strpos($defaultField, "has") === 0) { + $row[$defaultField] = "false"; + } else { $row[$defaultField] = ""; + } + } if ($schemas['agency']['properties'][$defaultField]['type'] == "array") { --- a/graph.php +++ b/graph.php @@ -10,36 +10,47 @@ var nodes = []; get_db('disclosr-agencies'); - +echo "nodes[\"fedg\"] = graph.newNode({label: \"Federal Government - Commonwealth of Australia\"});" . PHP_EOL; try { $rows = $db->get_view("app", "byCanonicalName", null, true)->rows; //print_r($rows); foreach ($rows as $row) { - echo "nodes[\"{$row->value}\"] = graph.newNode({label: \"{$row->key}\"});".PHP_EOL; + echo "nodes[\"{$row->value->_id}\"] = graph.newNode({label: \"{$row->key}\"});" . PHP_EOL; } } catch (SetteeRestClientException $e) { setteErrorHandler($e); } + +try { + $rows = $db->get_view("app", "byDeptStateName", null, true)->rows; + //print_r($rows); + foreach ($rows as $row) { + echo "graph.newEdge(nodes[\"fedg\"], nodes['{$row->value}'], {color: '#00A0B0'});" . PHP_EOL; + } +} catch (SetteeRestClientException $e) { + setteErrorHandler($e); +} + try { $rows = $db->get_view("app", "parentOrgs", null, true)->rows; - // print_r($rows); + // print_r($rows); foreach ($rows as $row) { - echo "graph.newEdge(nodes[\"{$row->key}\"], nodes['{$row->value}'], {color: '#00A0B0'});".PHP_EOL; + echo "graph.newEdge(nodes[\"{$row->key}\"], nodes['{$row->value}'], {color: '#FFA0B0'});" . PHP_EOL; } } catch (SetteeRestClientException $e) { setteErrorHandler($e); } ?> - window.onload = function() { - $(document).ready(function() { - var springy = $('#springydemo').springy({ - graph: graph + window.onload = function() { + $(document).ready(function() { + var springy = $('#springydemo').springy({ + graph: graph + }); }); - }); - }; + }; - + --- a/include/common.inc.php +++ b/include/common.inc.php @@ -1,4 +1,13 @@ stdClass return (object) $array; } + +function dept_to_portfolio($deptName) { + return trim(str_replace("Department of", "", str_replace("Department of the", "Department of", $deptName))); +} +function phrase_to_tag ($phrase) { + return str_replace(" ","_",str_replace(",","",strtolower($phrase))); +} +function GetDomain($url) +{ +$nowww = ereg_replace('www\.','',$url); +$domain = parse_url($nowww); +if(!empty($domain["host"])) + { + return $domain["host"]; + } else + { + return $domain["path"]; + } +} + ?> --- a/include/couchdb.inc.php +++ b/include/couchdb.inc.php @@ -1,6 +1,8 @@ views->byABN->map = "function(doc) { emit(doc.abn, doc); };"; $obj->views->byCanonicalName->map = "function(doc) { if (doc.parentOrg || doc.orgType == 'FMA-DepartmentOfState') { + emit(doc.name, doc._id); + } +};"; + $obj->views->byDeptStateName->map = "function(doc) { + if (doc.orgType == 'FMA-DepartmentOfState') { emit(doc.name, doc._id); } };"; @@ -60,21 +67,19 @@ return $db->save($obj, true); } -require ('couchdb/settee/src/settee.php'); if( php_uname('n') == "vanille") { $server = new SetteeServer('http://192.168.178.21:5984'); } else - if( php_uname('n') == "kyuubey") { + if( php_uname('n') == "KYUUBEY") { -$server = new SetteeServer('http://192.168.1.8:5984'); +$server = new SetteeServer('http://192.168.1.148:5984'); } else { $server = new SetteeServer('http://127.0.0.1:5984'); } function setteErrorHandler($e) { echo $e->getMessage() . "
    " . PHP_EOL; } - ?> --- a/include/template.inc.php +++ b/include/template.inc.php @@ -1,6 +1,7 @@ @@ -18,11 +19,11 @@ Disclosr - - + + @@ -62,8 +63,8 @@ - - + + --- /dev/null +++ b/lib/php-diff --- a/schemas/agency.json.php +++ b/schemas/agency.json.php @@ -5,7 +5,10 @@ "type" => "object", "properties" => Array( "name" => Array("type" => "string", "required" => true, "x-title"=> "Agency Name", "description" => "Agency Name, most recent and broadest"), + "short_name" => Array("type" => "string", "required" => false, "x-title"=> "Agency Short Name", "description" => "Agency Name shortened, usually to an acronym"), "otherNames" => Array("type" => "array", "required" => true, "x-title" => "Agency Past/Other Names", "description" => "Agency Names", + "items" => Array("type" => "string")), + "foiBodies" => Array("type" => "array", "required" => true, "x-title" => "FOI Bodies", "description" => "Organisational units within this agency that are subject to FOI Act but are not autonomous", "items" => Array("type" => "string")), "orgType"=> Array("type" => "string", "required" => true, "x-title"=> "Agency Name", "description" => "Agency Name, most recent and broadest"), "parentOrg"=> Array("type" => "string", "required" => true, "x-title"=> "Agency Name", "description" => "Agency Name, most recent and broadest"), @@ -20,6 +23,12 @@ "FOIDocumentsURL"=> Array("type" => "string", "required" => true, "x-title"=> "Agency Name", "description" => "Agency Name, most recent and broadest"), "infoPublicationSchemeURL"=> Array("type" => "string", "required" => true, "x-title"=> "Agency Name", "description" => "Agency Name, most recent and broadest"), "appointmentsURL"=> Array("type" => "string", "required" => true, "x-title"=> "Agency Name", "description" => "Agency Name, most recent and broadest"), + "hasRSS"=> Array("type" => "string", "required" => true, "x-title"=> "Agency Name", "description" => "Agency Name, most recent and broadest"), + "hasMailingList"=> Array("type" => "string", "required" => true, "x-title"=> "Agency Name", "description" => "Agency Name, most recent and broadest"), + "hasTwitter"=> Array("type" => "string", "required" => true, "x-title"=> "Agency Name", "description" => "Agency Name, most recent and broadest"), + "hasFacebook"=> Array("type" => "string", "required" => true, "x-title"=> "Agency Name", "description" => "Agency Name, most recent and broadest"), + "hasYouTube"=> Array("type" => "string", "required" => true, "x-title"=> "Agency Name", "description" => "Agency Name, most recent and broadest"), + ), /*"org":{"type":"object", "properties":{