From 3e034f6558d4c1e930ad131a1a1a6a66d8ed0995 Mon Sep 17 00:00:00 2001 From: senator Date: Mon, 11 Apr 2011 17:25:25 -0400 Subject: [PATCH] a little progress on the match set editor: now we can retrieve a tree from the server and use it as the basis of our dijit.Tree widget. Still work to be done. Can't save anything yet. Note to self: borrow dojo dnd's "copy" operation (as opposed to move) to mean replacing a node in the tree, rather than adding to the tree. Re the permissions I changed, actual users of Evergreen hate having as much granularity as there was before, and it just confuses people trying to figure out what perms to give to whom. Note to self 2: add ADMIN_IMPORT_MATCH_SET to ppl --- Open-ILS/examples/fm_IDL.xml | 25 +++--- .../perlmods/lib/OpenILS/Application/Vandelay.pm | 27 ++++-- Open-ILS/src/sql/Pg/012.schema.vandelay.sql | 1 + .../default/vandelay/{treetest.js => match_set.js} | 98 +++++++++++++++++++--- .../vandelay/{treetest.tt2 => match_set.tt2} | 8 +- 5 files changed, 122 insertions(+), 37 deletions(-) rename Open-ILS/web/js/ui/default/vandelay/{treetest.js => match_set.js} (76%) rename Open-ILS/web/templates/default/vandelay/{treetest.tt2 => match_set.tt2} (91%) diff --git a/Open-ILS/examples/fm_IDL.xml b/Open-ILS/examples/fm_IDL.xml index ae41a471e6..b4891d3c81 100644 --- a/Open-ILS/examples/fm_IDL.xml +++ b/Open-ILS/examples/fm_IDL.xml @@ -540,10 +540,10 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA - - - - + + + + @@ -557,6 +557,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + @@ -568,16 +569,16 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA - + - + - + - + @@ -599,10 +600,10 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA - - - - + + + + diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Vandelay.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Vandelay.pm index ca6963cfc5..024be0819f 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Vandelay.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Vandelay.pm @@ -1108,23 +1108,32 @@ sub respond_with_status { } __PACKAGE__->register_method( - api_name => "open-ils.vandelay.match_set_point.get_tree", - method => "match_set_point_get_tree", + api_name => "open-ils.vandelay.match_set.get_tree", + method => "match_set_get_tree", api_level => 1, argc => 1 ); -sub match_set_point_get_tree { - my ($self, $conn, $parent_id) = @_; +sub match_set_get_tree { + my ($self, $conn, $authtoken, $match_set_id) = @_; - $parent_id = int($parent_id) or return; + $match_set_id = int($match_set_id) or return; - my $tree = new_editor->search_vandelay_match_set_point([ - {"parent" => $parent_id}, - {"flesh" => -1, "flesh_fields" => ["children"]} + my $e = new_editor("authtoken" => $authtoken); + $e->checkauth or return $e->die_event; + + my $set = $e->retrieve_vandelay_match_set($match_set_id) or + return $e->die_event; + + $e->allowed("ADMIN_IMPORT_MATCH_SET", $set->owner) or + return $e->die_event; + + my $tree = $e->search_vandelay_match_set_point([ + {"match_set" => $match_set_id, "parent" => undef}, + {"flesh" => -1, "flesh_fields" => {"vmsp" => ["children"]}} ]) or return $e->die_event; - return $tree; + return pop @$tree; } diff --git a/Open-ILS/src/sql/Pg/012.schema.vandelay.sql b/Open-ILS/src/sql/Pg/012.schema.vandelay.sql index 804d8ad4a6..9bfd413e5e 100644 --- a/Open-ILS/src/sql/Pg/012.schema.vandelay.sql +++ b/Open-ILS/src/sql/Pg/012.schema.vandelay.sql @@ -23,6 +23,7 @@ CREATE TABLE vandelay.match_set_point ( svf TEXT REFERENCES config.record_attr_definition (name), tag TEXT, subfield TEXT, + negate BOOL DEFAULT FALSE, quality INT NOT NULL DEFAULT 1, -- higher is better CONSTRAINT vmsp_need_a_subfield_with_a_tag CHECK ((tag IS NOT NULL AND subfield IS NOT NULL) OR tag IS NULL), CONSTRAINT vmsp_need_a_tag_or_a_ff_or_a_bo CHECK ( diff --git a/Open-ILS/web/js/ui/default/vandelay/treetest.js b/Open-ILS/web/js/ui/default/vandelay/match_set.js similarity index 76% rename from Open-ILS/web/js/ui/default/vandelay/treetest.js rename to Open-ILS/web/js/ui/default/vandelay/match_set.js index 4d4b7b2d34..1e51b1a67d 100644 --- a/Open-ILS/web/js/ui/default/vandelay/treetest.js +++ b/Open-ILS/web/js/ui/default/vandelay/match_set.js @@ -5,6 +5,7 @@ dojo.require("dojo.dnd.Source"); dojo.require("dijit._tree.dndSource"); //dojo.require("openils.vandelay.TreeDndSource"); dojo.require("openils.vandelay.TreeStoreModel"); +dojo.require("openils.CGI"); dojo.require("openils.User"); dojo.require("openils.Util"); dojo.require("openils.PermaCrud"); @@ -12,6 +13,7 @@ dojo.require("openils.widget.ProgressDialog"); var node_editor; var _crads; +var CGI; function _find_crad_by_name(name) { for (var i = 0; i < _crads.length; i++) { @@ -126,14 +128,14 @@ function NodeEditor() { this.update_draggable = function(draggable) { var s = ""; -// draggable.data = {"match_point": new vmsp()}; + draggable.data = {"match_point": new vmsp()}; var had_op = false; dojo.query("[fmfield]", this.node_editor_container).forEach( function(control) { var used_svf = null; var field = dojo.attr(control, "fmfield"); var value = _simple_value_getter(control); -// draggable.data.match_point[field](value); + draggable.data.match_point[field](value); if (field == "subfield") s += " \u2021"; @@ -217,27 +219,99 @@ function NodeEditor() { this._init.apply(this, arguments); } +/* XXX replace later with code that will suit this function's purpose + * as well as that of update_draggable. */ +function display_name_from_point(point) { + /* quick and dirty */ + if (point.bool_op()) { + return (point.negate() == "t" ? "N" : "") + point.bool_op(); + } else if (point.svf()) { + return (point.negate() == "t" ? "NOT " : "") + point.svf(); + } else { + return (point.negate() == "t" ? "NOT " : "") + point.tag() + + "\u2021" + point.subfield(); + } +} + +/* dojoize_match_set_tree() takes an argument, "point", that is actually a + * vmsp fieldmapper object with descendants fleshed hierarchically. It turns + * that into a syntactically flat array but preserving the hierarchy + * semantically in the language used by dojo data stores, i.e., + * + * [ + * {'id': 'root', children:[{'_reference': '0'}, {'_reference': '1'}]}, + * {'id': '0', children:[]}, + * {'id': '1', children:[]} + * ], + * + */ +function dojoize_match_set_tree(point, refgen) { + /* XXX TODO test with deeper trees! */ + var root = false; + if (!refgen) { + refgen = 0; + root = true; + } + + var bathwater = point.children(); + point.children([]); + var item = { + "id": (root ? "root" : refgen), + "name": display_name_from_point(point), + "match_point": point.clone(), + "children": [] + }; + point.children(bathwater); + + var results = [item]; + + if (point.children()) { + for (var i = 0; i < point.children().length; i++) { + var child = point.children()[i]; + item.children.push({"_reference": ++refgen}); + results = results.concat( + dojoize_match_set_tree(child, refgen) + ); + } + } + + return results; +} + function init_test() { progress_dialog.show(true); + CGI = new openils.CGI(); + /* XXX No-one should have hundreds of these or anything, but theoretically * this could be problematic with a big enough list of crad objects. */ _crads = new openils.PermaCrud().retrieveAll( "crad", {"order_by": {"crad": "label"}} ); + var match_set_tree = fieldmapper.standardRequest( + ["open-ils.vandelay", "open-ils.vandelay.match_set.get_tree"], + [openils.User.authtoken, CGI.param("match_set")] + ); + +// { +// "identifier": "id", "label": "name", "items": [ +// { +// "id": "root", "name": "AND", +// "children": [ +// {"_reference": "leaf0"}, {"_reference": "leaf1"} +// ] +// }, +// {"id": "leaf0", "name": "nonsense test"}, +// {"id": "leaf1", "name": "more nonsense"} +// ] +// } + var store = new dojo.data.ItemFileWriteStore({ "data": { - "identifier": "id", "label": "name", "items": [ - { - "id": "root", "name": "AND", - "children": [ - {"_reference": "leaf0"}, {"_reference": "leaf1"} - ] - }, - {"id": "leaf0", "name": "nonsense test"}, - {"id": "leaf1", "name": "more nonsense"} - ] + "identifier": "id", + "label": "name", + "items": dojoize_match_set_tree(match_set_tree) } }); diff --git a/Open-ILS/web/templates/default/vandelay/treetest.tt2 b/Open-ILS/web/templates/default/vandelay/match_set.tt2 similarity index 91% rename from Open-ILS/web/templates/default/vandelay/treetest.tt2 rename to Open-ILS/web/templates/default/vandelay/match_set.tt2 index 32e72c9893..7883cf445d 100644 --- a/Open-ILS/web/templates/default/vandelay/treetest.tt2 +++ b/Open-ILS/web/templates/default/vandelay/match_set.tt2 @@ -1,11 +1,11 @@ [% WRAPPER 'default/base.tt2' %] -[% ctx.page_title = 'Vandelay Match Set Points' %] +[% ctx.page_title = 'Vandelay Match Set' %]

[% ctx.page_title %]

@@ -13,7 +13,7 @@ @@ -55,5 +55,5 @@
+ src="[% ctx.media_prefix %]/js/ui/default/vandelay/match_set.js"> [% END %] -- 2.11.0