-
Notifications
You must be signed in to change notification settings - Fork 12
/
NoctuaEditor.js
2996 lines (2634 loc) · 93.3 KB
/
NoctuaEditor.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* NoctuaEditor runner.
* Application initializer.
* Application logic.
* Initialze with (optional) incoming data and setup the GUI.
*
* @module NoctuaEditor
*/
// Let jshint pass over over our external globals (browserify takes
// care of it all).
/* global jQuery */
/* global global_golr_server */
/* global global_golr_neo_server */
/* global global_barista_location */
/* global global_minerva_definition_name */
/* global jsPlumb */
/* global global_barista_token */
/* global global_collapsible_relations */
/* global global_collapsible_reverse_relations */
/* global global_id */
/* global global_model */
/* global global_known_relations */
/* global global_workbenches_individual */
/* global global_noctua_minimal_p */
/* global global_noctua_context */
/* global global_github_api */
/* global global_github_org */
/* global global_github_repo */
/* global global_use_github_p */
// Code here will be ignored by JSHint, as we are technically
// "redefining" jQuery (although we are not).
/* jshint ignore:start */
var jQuery = require('jquery');
var jsPlumb = require('jsplumb');
/* jshint ignore:end */
//require('jquery-ui');
//require('bootstrap');
//require('tablesorter');
//require('./js/connectors-sugiyama.js');
var bbop_legacy = require('bbop').bbop;
var bbopx = require('bbopx');
var amigo_inst_gen = require('amigo2-instance-data');
var amigo_inst = new amigo_inst_gen();
// Replacement for context data.
var ontext = require('ontology-ui-overlay-data');
// The new backbone libs.
var us = require('underscore');
var bbop = require('bbop-core');
var model = require('bbop-graph-noctua');
var barista_response = require('bbop-response-barista');
var minerva_requests = require('minerva-requests');
var rest_response = require('bbop-rest-response').json;
var class_expression = require('class-expression');
//
var jquery_engine = require('bbop-rest-manager').jquery;
var minerva_manager = require('bbop-manager-minerva');
// Barista (telekinesis, etc.) communication.
var barista_client = require('bbop-client-barista');
// Get a localized layout system to test.
// A local separated lib to handle the (semi-)seperable UI widgets.
var widgetry = require('noctua-widgetry');
var notify_barista = require('toastr'); // regular notifications
var broadcast_barista = require('toastr'); // broadcast notifications
var notify_github = require('toastr'); // notifications
// And the layouts!
var layout_engine = require('bbop-layout');
// Some render support.
var pretty = require('js-object-pretty-print').pretty;
// Aliases.
var each = us.each;
var noctua_graph = model.graph;
var noctua_node = model.node;
var noctua_annotation = model.annotation;
var edge = model.edge;
//
var edit_ann_modal = widgetry.edit_annotations_modal;
var edit_node_modal = widgetry.edit_node_modal;
// Want a "global" shield to help deal with bridging the initial
// minerva contact load.
var compute_shield_modal = null;
/**
* Bootstraps a working environment for the MME client.
*
* @param {Object} model_json TODO
* @param {Object} in_relations TODO
* @param {Object} in_token TODO
*/
var MMEnvInit = function(model_json, in_relations, in_token){
//ll('model_json', model_json);
var logger = new bbop.logger('noctua editor');
logger.DEBUG = true;
function ll(str){ logger.kvetch(str); }
// Help with strings and colors--configured separately.
// // BUG/TODO: Some fixes for Paul as going upstream today is still
// // fiddly--would like to spin this out as a separate package.
// amigo.data.context['RO:0002411']['priority'] = 1;
// amigo.data.context['RO:0002413']['priority'] = 1;
// console.log(amigo.data.context);
// // Instantiate.
//var aid = new bbop_legacy.context(amigo_inst.data.context);
var aid = new bbop_legacy.context(ontext);
// Create the core model.
var ecore = new noctua_graph();
// The type of view we'll use to edit; tells which load function
// to use.
//var view_type = 'basic'; // or 'ev_fold' or 'go_fold' or ...
var view_type = 'go_fold'; // or 'ev_fold' or 'go_fold' or ...
// Optionally use the messaging server as an experiment.
var barclient = null;
// Where we move the nodes during this session.
// BUG/TODO: Should be the domain of Barista.
var local_position_store = new bbopx.noctua.location_store();
// Events registry.
// Add manager and default callbacks to minerva/barista.
var engine = new jquery_engine(barista_response);
engine.method('POST');
var manager = new minerva_manager(global_barista_location,
global_minerva_definition_name,
in_token, engine, 'async');
// GOlr location and conf setup.
var gserv = global_golr_server;
var gserv_neo = global_golr_neo_server;
var gconf = new bbop_legacy.golr.conf(amigo_inst.data.golr);
// Define what annotations are allowed to be edited where.
// Looking eerily like GOlr config now.
var model_annotation_config = [
{
'id': 'title',
'label': 'Title',
'widget_type': 'text',
'policy': 'mutable',
'cardinality': 'one',
'placeholder': 'Add title'
},
{
'id': 'contributor',
'label': 'Contributor',
'policy': 'read-only'
//'cardinality': 'many'
//'placeholder': 'n/a!',
//'widget_type': 'text'
},
{
'id': 'date',
'label': 'Date',
'policy': 'read-only'
//'cardinality': 'many'
//'placeholder': 'n/a!',
//'widget_type': 'text'
},
{
'id': 'state',
'label': 'Annotation state',
'widget_type': 'dropdown',
'policy': 'mutable',
//'policy': 'read-only',
'cardinality': 'one',
'placeholder': 'development', // acts as default select here
'options': [
{
'label': 'production',
'identifier': 'production',
'comment': 'Considered Good, always exported.'
},
{
'label': 'review',
'identifier': 'review',
'comment': 'Between production and development, may still be exported in data, but has possibly been flagged (in a manual or automated process) or is just setting out from development for the first time.'
},
{
'label': 'development',
'identifier': 'development',
'comment': 'The model is a work in progress, would only be exported in development environments; the standard initial state (public).'
},
{
'label': 'internal test',
'identifier': 'internal_test',
'comment': 'The model is intended at an exemplar or serve some internal or pedagogical purpose. These models are not intended to for production use and may contain other metadata.'
},
{
'label': 'closed',
'identifier': 'closed',
'comment': 'Editable, but never exported.'
},
{
'label': 'delete',
'identifier': 'delete',
'comment': 'Never exported, request for irrevocable deletion.'
}
]
},
// {
// 'id': 'evidence',
// 'label': 'Evidence',
// 'widget_type': 'text',
// 'policy': 'mutable',
// 'cardinality': 'many',
// 'placeholder': 'Enter evidence type'
// },
// {
// 'id': 'source',
// 'label': 'Source',
// 'widget_type': 'text',
// 'policy': 'mutable',
// 'cardinality': 'many',
// 'placeholder': 'Enter reference type'
// },
{
'id': 'deprecated',
'label': 'Deprecated',
'widget_type': 'dropdown',
'policy': 'mutable',
'cardinality': 'one',
'placeholder': 'false',
'options': [
{
'label': 'True (model is deprecated)',
'identifier': 'true',
'comment': 'Considered Good, always exported.'
},
{
'label': 'False (default; model is good)',
'identifier': 'false',
'comment': 'Considered Bad never exported.'
}
]
},
{
'id': 'template',
'label': 'Use as template',
'widget_type': 'dropdown',
'policy': 'mutable',
'cardinality': 'one',
'placeholder': 'false',
'options': [
{
'label': 'True (model is a template)',
'identifier': 'true',
'comment': 'Can be copied form workbench, but no longer edited.'
},
{
'label': 'False (default; model is not a template)',
'identifier': 'false',
'comment': 'Edited as normal.'
}
]
},
{
'id': 'comment',
'label': 'Comment',
'widget_type': 'textarea',
'policy': 'mutable',
'cardinality': 'many',
'placeholder': 'Add comment...'
}
];
var individual_annotation_config = [
// {
// 'id': 'title',
// 'label': 'Title',
// 'widget_type': 'text',
// 'policy': 'mutable',
// 'cardinality': 'one',
// 'placeholder': 'Add title'
// },
{
'id': 'contributor',
'label': 'Contributor',
'policy': 'read-only'
//'cardinality': 'many'
//'placeholder': 'n/a!',
//'widget_type': 'text'
},
{
'id': 'date',
'label': 'Date',
'policy': 'read-only'
//'cardinality': 'many'
//'placeholder': 'n/a!',
//'widget_type': 'text'
},
// {
// 'id': 'source',
// 'label': 'Source'
// // 'widget_type': 'text',
// // 'policy': 'mutable',
// // 'cardinality': 'many',
// // 'placeholder': 'Enter reference type'
// },
// {
// 'id': 'with',
// 'label': 'With',
// 'policy': 'read-only-optional'
// //'cardinality': 'many'
// //'placeholder': 'n/a!',
// //'widget_type': 'text'
// },
{
'id': 'comment',
'label': 'Comment',
'widget_type': 'textarea',
'policy': 'mutable',
'cardinality': 'many',
'placeholder': 'Add comment...'
}
];
var fact_annotation_config = [
// {
// 'id': 'title',
// 'label': 'Title',
// 'widget_type': 'text',
// 'policy': 'mutable',
// 'cardinality': 'one',
// 'placeholder': 'Add title'
// },
{
'id': 'contributor',
'label': 'Contributor',
'policy': 'read-only'
//'cardinality': 'many'
//'placeholder': 'n/a!',
//'widget_type': 'text'
},
{
'id': 'date',
'label': 'Date',
'policy': 'read-only'
//'cardinality': 'many'
//'placeholder': 'n/a!',
//'widget_type': 'text'
},
{
'id': 'evidence',
'label': 'Evidence',
//'widget_type': 'text',
'widget_type': 'source_ref',
'policy': 'mutable',
'cardinality': 'many',
'placeholder': 'Enter evidence code (ECO label, ECO ID, or 3-letter code)',
'placeholder_secondary': 'Enter reference (must be in form of PREFIX:ID)',
'placeholder_tertiary': 'If appropriate, enter with/from value (must be in form of PREFIX:ID)'
},
// {
// 'id': 'source',
// 'label': 'Source'
// // 'widget_type': 'text',
// // 'policy': 'mutable',
// // 'cardinality': 'many',
// // 'placeholder': 'Enter reference type'
// },
{
'id': 'comment',
'label': 'Comment',
'widget_type': 'textarea',
'policy': 'mutable',
'cardinality': 'many',
'placeholder': 'Add comment...'
}
];
// Div contact points.
var graph_container_id = 'main_exp_graph_container';
var graph_container_div = '#' + graph_container_id;
var graph_id = 'main_exp_graph';
var graph_div = '#' + graph_id;
var table_info_id = 'main_info_table';
var table_info_div = '#' + table_info_id;
var table_exp_id = 'main_exp_table';
var table_exp_div = '#' + table_exp_id;
var table_edge_id = 'main_edge_table';
var table_edge_div = '#' + table_edge_id;
var control_id = 'main_exp_gui';
var control_div = '#' + control_id;
// Ubernoodle contact points.
var simple_ubernoodle_auto_id = 'simple_ubernoodle_auto';
var simple_ubernoodle_auto_elt = '#' + simple_ubernoodle_auto_id;
var simple_ubernoodle_not_checkbox_id = 'simple_ubernoodle_not_checkbox';
var simple_ubernoodle_not_checkbox_elt =
'#' + simple_ubernoodle_not_checkbox_id;
var simple_ubernoodle_add_btn_id ='simple_ubernoodle_adder_button';
var simple_ubernoodle_add_btn_elt = '#' + simple_ubernoodle_add_btn_id;
// MF (free form) button contact points.
var simple_mf_free_enb_auto_id = 'simple_mf_free_enb_auto';
var simple_mf_free_enb_auto_elt = '#' + simple_mf_free_enb_auto_id;
var simple_mf_free_act_auto_id = 'simple_mf_free_act_auto';
var simple_mf_free_act_auto_elt = '#' + simple_mf_free_act_auto_id;
var simple_mf_free_occ_auto_id = 'simple_mf_free_occ_auto';
var simple_mf_free_occ_auto_elt = '#' + simple_mf_free_occ_auto_id;
var simple_mf_free_add_btn_id = 'simple_mf_free_adder_button';
var simple_mf_free_add_btn_elt = '#' + simple_mf_free_add_btn_id;
// BP (free form) button contact points.
// var simple_bp_free_enb_auto_id = 'simple_bp_free_enb_auto';
// var simple_bp_free_enb_auto_elt = '#' + simple_bp_free_enb_auto_id;
var simple_bp_free_act_auto_id = 'simple_bp_free_act_auto';
var simple_bp_free_act_auto_elt = '#' + simple_bp_free_act_auto_id;
var simple_bp_free_occ_auto_id = 'simple_bp_free_occ_auto';
var simple_bp_free_occ_auto_elt = '#' + simple_bp_free_occ_auto_id;
var simple_bp_free_add_btn_id = 'simple_bp_free_adder_button';
var simple_bp_free_add_btn_elt = '#' + simple_bp_free_add_btn_id;
// Other contact points.
var model_ann_id = 'menu-model-annotations';
var model_ann_elt = '#' + model_ann_id;
//
var toggle_part_of_id = 'toggle_part_of';
var toggle_part_of_elt = '#' + toggle_part_of_id;
var toggle_screen_id = 'toggle_screen_of';
var toggle_screen_elt = '#' + toggle_screen_id;
var toggle_reasoner_id = 'action_use_reasoner';
var toggle_reasoner_elt = '#' + toggle_reasoner_id;
//
var view_basic_id = 'view_basic';
var view_basic_elt = '#' + view_basic_id;
var view_ev_fold_id = 'view_ev_fold';
var view_ev_fold_elt = '#' + view_ev_fold_id;
var view_go_fold_id = 'view_go_fold';
var view_go_fold_elt = '#' + view_go_fold_id;
//
var zin_btn_id = 'zoomin';
var zin_btn_elt = '#' + zin_btn_id;
var zret_btn_id = 'zoomret';
var zret_btn_elt = '#' + zret_btn_id;
var zout_btn_id = 'zoomout';
var zout_btn_elt = '#' + zout_btn_id;
//
var undo_btn_id = 'action_undo';
var undo_btn_elt = '#' + undo_btn_id;
var redo_btn_id = 'action_redo';
var redo_btn_elt = '#' + redo_btn_id;
//
var refresh_btn_id = 'action_refresh';
var refresh_btn_elt = '#' + refresh_btn_id;
var reset_btn_id = 'action_reset';
var reset_btn_elt = '#' + reset_btn_id;
// var export_btn_id = 'action_export';
// var export_btn_elt = '#' + export_btn_id;
var save_btn_id = 'action_save';
var save_btn_elt = '#' + save_btn_id;
// var ping_btn_id = 'action_ping';
// var ping_btn_elt = '#' + ping_btn_id;
var compact_btn_id = 'action_compact';
var compact_btn_elt = '#' + compact_btn_id;
// var test_btn_id = 'action_test';
// var test_btn_elt = '#' + test_btn_id;
// var exp_btn_id = 'action_shin';
// var exp_btn_elt = '#' + exp_btn_id;
var help_btn_id = 'action_help';
var help_btn_elt = '#' + help_btn_id;
// A hidden for to communicate with the outside world.
var action_form_id = 'invisible_action';
var action_form_elt = '#' + action_form_id;
var action_form_data_id = 'invisible_action_data';
var action_form_data_elt = '#' + action_form_data_id;
// Some experimental stuff for optional messaging server.
var message_area_id = 'message_area';
//var message_area_elt = '#' + message_area_id;
var message_area_tab_id = 'message_area_tab';
var message_area_tab_elt = '#' + message_area_tab_id;
var reporter = new widgetry.reporter(message_area_id);
///
/// Render helpers.
///
// Add the necessary elements to the display.
var h_spacer = 75;
var v_spacer = 75;
var box_width = 150;
var box_height = 100;
var vbox_width = 5;
var vbox_height = 5;
function _box_top(raw_y){
return ((box_height + v_spacer) * raw_y) + v_spacer;
}
function _box_left(raw_x){
return ((box_width + h_spacer) * raw_x) + h_spacer;
}
function _vbox_top(raw_y){
return _box_top(raw_y) + (box_height / 2.0);
}
function _vbox_left(raw_x){
return _box_left(raw_x) + (box_width / 2.0);
}
// Somewhat vary the intitial placement.
function _vari(){
var min = -25;
var max = 25;
var rand = Math.random();
var seed = Math.floor(rand * (max-min+1) +min);
return seed + 100;
}
function _extract_node_position(node, x_or_y){
var ret = null;
var hint_str = null;
if( x_or_y === 'x' || x_or_y === 'y' ){
hint_str = 'hint-layout-' + x_or_y;
}
var hint_anns = node.get_annotations_by_key(hint_str);
if( hint_anns.length === 1 ){
ret = parseInt(hint_anns[0].value());
//ll('extracted coord ' + x_or_y + ': ' + ret);
}else if( hint_anns.length === 0 ){
//ll('no coord');
}else{
//ll('too many coord');
}
return ret;
}
///
/// jsPlumb preamble.
///
var instance = jsPlumb.getInstance(
{
// All connections have these properties.
DragOptions: {ccursor: 'pointer', zIndex:2000 },
Endpoints : ["Rectangle", ["Dot", { radius:8 } ]],
//Endpoints : [["Dot", { radius:8 } ], "Rectangle"],
EndpointStyles : [
{
width: 15,
height: 15,
//strokeStyle: '#000000',
fillStyle: "#666666" // subject endpoint color
},
{
fillStyle: "#0d78bc" // object endpoint
//fillStyle: "#006"
}
],
//PaintStyle: { strokeStyle:'#0d78bc' },
PaintStyle : {
strokeStyle:"#666666", // color when creating new edge
lineWidth: 5
},
Container: graph_id
});
///
/// jsPlumb helpers.
///
function _set_zoom(zlvl) {
var btype = [ "-webkit-", "-moz-", "-ms-", "-o-", "" ];
var scale_str = "scale(" + zlvl + ")";
each(btype, function(b){
jQuery(graph_div).css(b + "transform", scale_str);
});
instance.setZoom(zlvl);
}
///
/// jsPlumb/edit core helpers.
///
function _attach_node_draggable(sel){
var foo = jsPlumb.getSelector(sel);
// Make it draggable, and update where it is when it is
// dropped.
function _on_drag_stop(evt, ui){
// Try an jimmy out the enode ssociated with this event.
var enid = ui.helper.attr('id');
var en = ecore.get_node_by_elt_id(enid);
// If we got something, locate it and save the position.
if( en ){
// Grab position.
var t = ui.position.top;
var l = ui.position.left;
//ll('stop (' + en.id() + ') at:' + t + ', ' + l);
// Keep track of where we leave it when we move it.
local_position_store.add(en.id(), l, t);
}
}
// While we are dragging, make note.
function _on_dragging(evt, ui){
// Try an jimmy out the enode ssociated with this event.
var enid = ui.helper.attr('id');
var en = ecore.get_node_by_elt_id(enid);
// If we got something, locate it and save the position.
if( en ){
// Grab position.
var top = ui.position.top;
var left = ui.position.left;
//ll('dragging (' + en.id() + ') at:' + top + ', ' + left);
if( barclient ){
barclient.telekinesis(en.id(), top, left);
}
}
}
// Try top-level container containment to prevent inaccessible
// nodes.
//instance.draggable(foo, {stop: _on_drag_stop});
instance.draggable(foo, {stop: _on_drag_stop,
drag: _on_dragging,
containment: graph_div,
scroll: false
});
}
function _make_selector_target(sel){
instance.makeTarget(jsPlumb.getSelector(sel), {
anchor:"Continuous",
isTarget: true,
//maxConnections: -1,
connector:[ "Sugiyama", { curviness: 25 } ]
});
}
function _make_selector_source(sel, subsel){
instance.makeSource(jsPlumb.getSelector(sel), {
filter: subsel,
anchor:"Continuous",
isSource: true,
//maxConnections: -1,
connector:[ "Sugiyama", { curviness: 25 } ]
});
}
function _attach_node_click_edit(sel){
// Add this event to whatever we got called in.
jQuery(sel).unbind('click');
jQuery(sel).click(
function(evnt){
evnt.stopPropagation();
// Resolve the event into the edit core node.
var target_elt = jQuery(evnt.target);
var parent_elt = target_elt.parent();
var parent_id = parent_elt.attr('id');
var enode = ecore.get_node_by_elt_id(parent_id);
if( ! enode ){
alert('Could not find related element.');
}else{
var nedit = edit_node_modal(ecore, manager, enode,
in_relations, aid,
gserv_neo, gconf,
global_workbenches_individual,
in_token);
nedit.show();
}
});
}
function _attach_node_click_annotation_edit(sel){
// Add this event to whatever we got called in.
jQuery(sel).unbind('click');
jQuery(sel).click(
function(evnt){
evnt.stopPropagation();
// Resolve the event into the edit core node.
var target_elt = jQuery(evnt.target);
var parent_elt = target_elt.parent();
var parent_id = parent_elt.attr('id');
var enode = ecore.get_node_by_elt_id(parent_id);
if( ! enode ){
alert('Could not find related test element.');
}else{
var eam = edit_ann_modal(individual_annotation_config, ecore,
manager, enode.id(),
gserv, gserv_neo, gconf,
global_noctua_context);
eam.show();
}
});
}
function _attach_node_click_violation_view(sel){
// Add this event to whatever we got called in.
jQuery(sel).unbind('click');
jQuery(sel).click(
function(evnt){
evnt.stopPropagation();
// Resolve the event into the edit core node.
var target_elt = jQuery(evnt.target);
var parent_elt = target_elt.parent();
var parent_id = parent_elt.attr('id');
var enode = ecore.get_node_by_elt_id(parent_id);
if( ! enode ){
alert('Could not find related violation element.');
}else{
var violation_renderings = [];
var violations = ecore.get_violations_by_id(enode.id());
each(violations, function(v){
if( v.explanations().length === 0 ){
violation_renderings.push(
'[No explanation available.]');
}else{
violation_renderings.push(
pretty(v.explanations(), '3', 'HTML'));
}
});
var vvm = new widgetry.contained_modal(
null, 'Violations',
'<div class="alert alert-dismissable alert-warning">' +
'<button type="button" class="close" data-dismiss="alert">×</button>' +
'This feature is <strong>currently under development</strong>, with more user friendly error reports coming. If you have questions about the error messages you\'re seeing, please create a <a href="https://github.com/geneontology/noctua"><u>ticket</u></a>.' +
'</div>' +
violation_renderings.join(' <hr /> '));
vvm.show();
}
});
}
// Delete all UI connections associated with node. This also
// triggers the "connectionDetached" event, so the edges are being
// removed from the model at the same time.
function _delete_iae_from_ui(indv_id){
// Node ID to element ID.
var nelt = ecore.get_node_elt_id(indv_id);
// Get rid of it's connections.
instance.detachAllConnections(nelt);
// Delete node from UI/model.
jQuery('#' + nelt).remove();
}
// // Helper for getting rid of nodes. In all these cases, edges will
// // come off naturally.
// function _delete_iae_from_ecore(indv_id){
// // Should recursively remove direct evidence, etc.
// ecore.remove_node(indv_id, true);
// }
function _connect_with_edge(eedge){
var sn = eedge.source();
var tn = eedge.target();
var rn = eedge.relation() || 'n/a';
// Readable label, try context aid first.
var readable_rn = aid.readable(rn) || rn;
// If context aid doesn't work, see if it comes with a label.
if( readable_rn === rn && typeof(eedge.label) === 'function' ){
var label_rn = eedge.label();
if( label_rn !== rn ){
readable_rn = label_rn; // use label
}
}
//ll('looking at edge: [' + [sn,tn,rn].join(', ') + ']');
// Try changing the color with context.
var clr = aid.color(rn);
// Append if there are comments, etc.
var eanns = eedge.annotations();
if( eanns.length !== 0 ){
// Meta counts.
var n_ev = 0;
var n_other = 0;
each(eanns, function(ann){
if( ann.key() === 'evidence' ){
n_ev++;
}else{
n_other++;
}
});
readable_rn +=
' <small style="color: grey;">'+n_ev+'/'+n_other+'</small>';
}
// Try and detect the proper edge type.
var rglyph = aid.glyph(rn);
var glyph = null;
var glyph_args = {};
if( rglyph === 'arrow' ){ // Arrow is explicit filled "PlainArrow".
glyph = 'Arrow';
glyph_args['length'] = 20;
glyph_args['width'] = 20;
glyph_args['location'] = -4;
glyph_args['foldback'] = 1.0;
// }else if( rglyph === 'diamond' ){
// glyph = 'Diamond';
// glyph_args['location'] = -5;
}else if( rglyph === 'bar' ){ // Bar simulated by flattened arrow.
glyph = 'Arrow';
glyph_args['length'] = 2;
glyph_args['width'] = 25;
glyph_args['foldback'] = 2.0;
glyph_args['location'] = -5;
// }else if( rglyph === 'wedge' ){
// glyph = 'PlainArrow';
// glyph_args['location'] = -4;
}else if( ! rglyph || rglyph === 'none' ){ // Default is small "V".
// Let it go as nothing.
glyph = 'Arrow';
glyph_args['length'] = 12.5;
glyph_args['width'] = 15;
glyph_args['location'] = -4;
glyph_args['foldback'] = 0.25;
}else{
// Unpossible.
// throw new Error('unpossible glyph...is apparently possible');
// For things like diamonds, and other currently unspecified
// relations.
glyph = 'Arrow';
glyph_args['length'] = 12.5;
glyph_args['width'] = 15;
glyph_args['location'] = -4;
glyph_args['foldback'] = 0.25;
}
var openann_edge_str = '<button class="open-annotation-dialog-edge btn btn-default" title="Open annotation dialog"></button>';
var new_conn_args = {
// remember that edge ids and elts ids are the same
'source': ecore.get_node_elt_id(sn),
'target': ecore.get_node_elt_id(tn),
//'label': 'foo' // works
'anchor': "Continuous",
'connector': ["Sugiyama", { curviness: 75 } ],
// Endpoints : [["Dot", { radius:8 } ], "Rectangle"],
'paintStyle': {
strokeStyle: clr,
lineWidth: 5
},
'overlays': [ // does not!?
["Label", {'label': openann_edge_str + ' ' + readable_rn,
'location': 0.5,
'cssClass': "aLabel",
'id': 'label' } ]
]
//}, {'PaintStyle': { strokeStyle: clr, lineWidth: 5}});
};
if( glyph ){
new_conn_args['overlays'].push([glyph, glyph_args]);
}
var new_conn = instance.connect(new_conn_args);
// Associate the connection ID with the edge ID.
ecore.create_edge_mapping(eedge, new_conn);
// Add activity listener to the new edge.
new_conn.bind('click', function(connection, event){
//alert('edge click: ' + eedge.id());
var eam = edit_ann_modal(fact_annotation_config, ecore, manager,
eedge.id(), gserv, gserv_neo, gconf,
global_noctua_context);
eam.show();
});
// NOTE: This is necessary since these connectors are created
// under the covers of jsPlumb--I don't have access during
// creation like I do with the nodes.
ecore.create_edge_mapping(eedge, new_conn);
}
///
/// Callback helpers and manager registration.
///
// Block interface from taking user input while
// operating.
function _shields_up(){
if( compute_shield_modal ){
// Already have one.
}else{
ll('shield up');
compute_shield_modal = widgetry.compute_shield();
compute_shield_modal.show();
}
}
// Release interface when transaction done.
function _shields_down(){
if( compute_shield_modal ){
ll('shield down');
compute_shield_modal.destroy();
compute_shield_modal = null;
}else{
// None to begin with.
}
}
// Update/repaint the table.
function _refresh_tables(){
ll('refreshing tables/info');
widgetry.repaint_info(ecore, aid, table_info_div);
widgetry.repaint_exp_table(ecore, aid, table_exp_div);
widgetry.repaint_edge_table(ecore, aid, table_edge_div);
// And update browser title.
var mtitle = 'Untitled';
var title_anns = ecore.get_annotations_by_key('title');
if( title_anns && title_anns.length === 1 ){
mtitle = title_anns[0].value();
//alert(mtitle);
}
// Tag on modification mark.
ll('modified-p: ' + ecore.modified_p());
if( ecore.modified_p() === true ){
mtitle = '*' + mtitle + '*';
}
// Tag on violation mark.
ll('valid-p: ' + ecore.valid_p());
if( ecore.valid_p() === false ){
mtitle = '! ' + mtitle;
}
document.title = mtitle + ' (Noctua Editor)';
}
// See what the undo/redo listing looks like.
function _trigger_undo_redo_lookup(){
if( ! manager.user_token() ){ // only try if logged-in; priv op
ll('skip undo/redo lookup due to lack of standing');
}else{
manager.get_model_undo_redo(ecore.get_id());
}
}
// Build on new graph.
function _fold_graph_appropriately(d_graph, d_view_type){
// Undo whatever we've done before.
d_graph.unfold();
each([view_basic_elt, view_ev_fold_elt, view_go_fold_elt], function(elt){
jQuery(elt).css("font-weight","");
});
// Now do it again.
if( d_view_type === 'basic' ){
// Nothing.
jQuery(view_basic_elt).css("font-weight","bold");
}else if( d_view_type === 'ev_fold' ){
jQuery(view_ev_fold_elt).css("font-weight","bold");
d_graph.fold_evidence();
}else if( d_view_type === 'go_fold' ){
jQuery(view_go_fold_elt).css("font-weight","bold");
d_graph.fold_go_noctua(global_collapsible_relations,
global_collapsible_reverse_relations);
}else{
throw new Error('unknown graph editor view: ' + d_view_type);
}
}
// The core initial layout function.
function _rebuild_model_and_display(model_data){
// Wipe UI.
each(ecore.get_nodes(), function(en, enid){
_delete_iae_from_ui(enid);
});
widgetry.wipe(graph_div); // rather severe
// Wipe ecore and structures if not attempting to preserve
// current data. Reasons to preserve could include switching