/
RuleCollectionBuilder.vue
1897 lines (1858 loc) · 79.9 KB
/
RuleCollectionBuilder.vue
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
<template>
<state-div v-if="state == 'build'">
<!-- Different instructions if building up from individual datasets vs.
initial data import. -->
<rule-modal-header v-if="ruleView == 'source'">
Below is a raw JSON description of the rules to apply to the tabular data. This is an advanced setting.
</rule-modal-header>
<rule-modal-header v-else-if="elementsType == 'datasets' || elementsType == 'library_datasets'">
Use this form to describe rules for building collection(s) from the specified datasets. <b>Be sure to specify at least one column as a list identifier</b> - specify more to created nested list structures. Specify a column to serve as "collection name" to group datasets into multiple collections.
</rule-modal-header>
<!-- This modality allows importing individual datasets, multiple collections,
and requires a data source - note that. -->
<rule-modal-header v-else-if="importType == 'datasets'">
Use this form to describe rules for import datasets. At least one column should be defined to a source to fetch data from (URLs, FTP files, etc...).
</rule-modal-header>
<rule-modal-header v-else>
Use this form to describe rules for import datasets. At least one column should be defined to a source to fetch data from (URLs, FTP files, etc...). <b>Be sure to specify at least one column as a list identifier</b> - specify more to created nested list structures. Specify a column to serve as "collection name" to group datasets into multiple collections.
</rule-modal-header>
<rule-modal-middle v-if="ruleView == 'source'">
<p class="errormessagelarge" v-if="ruleSourceError">{{ ruleSourceError }}</p>
<textarea class="rule-source" v-model="ruleSource"></textarea>
</rule-modal-middle>
<rule-modal-middle v-else>
<!-- column-headers -->
<div class="rule-builder-body vertically-spaced"
v-bind:class="{ 'flex-column-container': vertical }" v-if="ruleView == 'normal'">
<!-- width: 30%; -->
<div class="rule-column" v-bind:class="orientation">
<div class="rules-container" v-bind:class="{'rules-container-vertical': initialElements && vertical, 'rules-container-horizontal': initialElements && horizontal, 'rules-container-full': initialElements == null}">
<rule-component rule-type="sort"
:display-rule-type="displayRuleType"
:builder="this">
<column-selector :target.sync="addSortingTarget" :col-headers="activeRuleColHeaders" />
<label v-b-tooltip.hover :title="titleNumericSort">
<input type="checkbox" v-model="addSortingNumeric" />
{{ l("Numeric sorting.") }}
</label>
</rule-component>
<rule-component rule-type="add_column_basename"
:display-rule-type="displayRuleType"
:builder="this">
<column-selector :target.sync="addColumnBasenameTarget" :col-headers="activeRuleColHeaders" />
</rule-component>
<rule-component rule-type="add_column_rownum"
:display-rule-type="displayRuleType"
:builder="this">
<label>
{{ l("Starting from") }}
<input type="number" v-model="addColumnRownumStart" min="0" />
</label>
</rule-component>
<rule-component rule-type="add_column_metadata"
:display-rule-type="displayRuleType"
:builder="this">
<label>
{{ l("For") }}
<select v-model="addColumnMetadataValue">
<option v-for="(col, index) in metadataOptions" :value="index">{{ col }}</option>
</select>
</label>
</rule-component>
<rule-component rule-type="add_column_regex"
:display-rule-type="displayRuleType"
:builder="this">
<column-selector :target.sync="addColumnRegexTarget" :col-headers="activeRuleColHeaders" />
<input type="radio" v-model="addColumnRegexType" value="global">Create column matching expression.<br />
<input type="radio" v-model="addColumnRegexType" value="groups">Create columns matching expression groups.<br />
<input type="radio" v-model="addColumnRegexType" value="replacement">Create column from expression replacement.<br />
<regular-expression-input :target.sync="addColumnRegexExpression" />
<label v-if="addColumnRegexType=='groups'">
{{ l("Number of Groups") }}
<input type="number" v-model="addColumnRegexGroupCount" min="1" />
</label>
<label v-if="addColumnRegexType=='replacement'">
{{ l("Replacement Expression") }}
<input type="text" v-model="addColumnRegexReplacement" class="rule-replacement" />
</label>
</rule-component>
<rule-component rule-type="add_column_concatenate"
:display-rule-type="displayRuleType"
:builder="this">
<column-selector :target.sync="addColumnConcatenateTarget0" :col-headers="activeRuleColHeaders" />
<column-selector :target.sync="addColumnConcatenateTarget1" :col-headers="activeRuleColHeaders" />
</rule-component>
<rule-component rule-type="add_column_substr"
:display-rule-type="displayRuleType"
:builder="this">
<column-selector :target.sync="addColumnSubstrTarget" :col-headers="activeRuleColHeaders" />
<label>
<select v-model="addColumnSubstrType">
<option value="keep_prefix">Keep only prefix specified.</option>
<option value="drop_prefix">Strip off prefix specified.</option>
<option value="keep_suffix">Keep only suffix specified.</option>
<option value="drop_suffix">Strip off suffix specified.</option>
</select>
</label>
<label>
{{ l("Prefix or suffix length") }}
<input type="number" v-model="addColumnSubstrLength" min="0" />
</label>
</rule-component>
<rule-component rule-type="add_column_value"
:display-rule-type="displayRuleType"
:builder="this">
<label>
{{ l("Value") }}
<input type="text" v-model="addColumnValue" />
</label>
</rule-component>
<rule-component rule-type="remove_columns"
:display-rule-type="displayRuleType"
:builder="this">
<column-selector :target.sync="removeColumnTargets" :col-headers="activeRuleColHeaders" :multiple="true" />
</rule-component>
<rule-component rule-type="split_columns"
:display-rule-type="displayRuleType"
:builder="this">
<column-selector :target.sync="splitColumnsTargets0" label="Odd Row Column(s)" :col-headers="activeRuleColHeaders" :multiple="true" />
<column-selector :target.sync="splitColumnsTargets1" label="Even Row Column(s)" :col-headers="activeRuleColHeaders" :multiple="true" />
</rule-component>
<rule-component rule-type="swap_columns"
:display-rule-type="displayRuleType"
:builder="this">
<column-selector :target.sync="swapColumnsTarget0" label="Swap Column" :col-headers="activeRuleColHeaders" />
<column-selector :target.sync="swapColumnsTarget1" label="With Column" :col-headers="activeRuleColHeaders" />
</rule-component>
<rule-component rule-type="add_filter_regex"
:display-rule-type="displayRuleType"
:builder="this">
<column-selector :target.sync="addFilterRegexTarget" :col-headers="activeRuleColHeaders" />
<regular-expression-input :target.sync="addFilterRegexExpression" />
<label v-b-tooltip.hover :title="titleInvertFilterRegex">
<input type="checkbox" v-model="addFilterRegexInvert" />
{{ l("Invert filter.") }}
</label>
</rule-component>
<rule-component rule-type="add_filter_matches"
:display-rule-type="displayRuleType"
:builder="this">
<column-selector :target.sync="addFilterMatchesTarget" :col-headers="activeRuleColHeaders" />
<input type="text" v-model="addFilterMatchesValue" />
<label v-b-tooltip.hover :title="titleInvertFilterMatches">
<input type="checkbox" v-model="addFilterMatchesInvert" />
{{ l("Invert filter.") }}
</label>
</rule-component>
<rule-component rule-type="add_filter_compare"
:display-rule-type="displayRuleType"
:builder="this">
<column-selector :target.sync="addFilterCompareTarget" :col-headers="activeRuleColHeaders" />
<label>
Filter out rows
<select v-model="addFilterCompareType">
<option value="less_than">{{ l("less than") }} </option>
<option value="less_than_equal">{{ l("less than or equal to") }}</option>
<option value="greater_than">{{ l("greater than") }}</option>
<option value="greater_than_equal">{{ l("greater than or equal to") }}</option>
</select>
</label>
<input type="text" v-model="addFilterCompareValue" />
</rule-component>
<rule-component rule-type="add_filter_count"
:display-rule-type="displayRuleType"
:builder="this">
<label>
Filter which rows?
<select v-model="addFilterCountWhich">
<option value="first">first</option>
<option value="last">last</option>
</select>
</label>
<label>
Filter how many rows?
<input type="number" v-model="addFilterCountN" />
</label>
<label v-b-tooltip.hover :title="titleInvertFilterMatches">
<input type="checkbox" v-model="addFilterCountInvert" />
{{ l("Invert filter.") }}
</label>
</rule-component>
<rule-component rule-type="add_filter_empty"
:display-rule-type="displayRuleType"
:builder="this">
<column-selector :target.sync="addFilterEmptyTarget" :col-headers="activeRuleColHeaders" />
<label v-b-tooltip.hover :title="titleInvertFilterEmpty">
<input type="checkbox" v-model="addFilterEmptyInvert" />
{{ l("Invert filter.") }}
</label>
</rule-component>
<div v-if="displayRuleType == 'mapping'">
<div class="map"
v-for="map in mapping"
v-bind:index="map.index"
v-bind:key="map.type">
<column-selector
:class="'rule-map-' + map.type.replace(/_/g, '-')"
:label="mappingTargets()[map.type].label"
:help="mappingTargets()[map.type].help"
:target.sync="map.columns"
:ordered-edit.sync="map.editing"
:col-headers="colHeaders"
:multiple="mappingTargets()[map.type].multiple"
:ordered="true"
:value-as-list="true">
<span v-b-tooltip.hover :title="titleRemoveMapping" class="fa fa-times" @click="removeMapping(map.index)"></span>
</column-selector>
</div>
<div class="buttons rule-edit-buttons d-flex justify-content-end">
<button v-b-tooltip.hover :title="titleAddColumnDefinition" type="button" class="dropdown-toggle btn btn-primary mr-1" data-toggle="dropdown" v-if="unmappedTargets.length > 0">
<span class="fa fa-plus rule-add-mapping"></span> {{ "Add Definition" }}<span class="caret"></span>
</button>
<div class="dropdown-menu" role="menu">
<a v-for="target in unmappedTargets"
v-bind:index="target"
v-bind:key="target"
class="dropdown-item"
href="javascript:void(0)"
:class="'rule-add-mapping-' + target.replace(/_/g, '-')"
@click="addIdentifier(target)">
{{ mappingTargets()[target].label }}
</a>
</div>
<b-button v-b-tooltip.hover.bottom :title="titleApplyColumnDefinitions" class="rule-mapping-ok" v-if="!hasActiveMappingEdit" @click="displayRuleType = null">{{ l("Apply") }}</b-button>
</div>
</div>
<div class="rule-summary" v-if="displayRuleType == null">
<span class="title">
{{ l("Rules") }}
<span v-b-tooltip.hover class="fa fa-wrench rule-builder-view-source" :title="titleViewSource" @click="viewSource"></span>
</span>
<div v-if="jaggedData" class="rule-warning">
Rows contain differing numbers of columns, there was likely a problem parsing your data.
</div>
<ol class="rules">
<!-- Example at the end of https://vuejs.org/v2/guide/list.html -->
<rule-display
v-for="(rule, index) in rules"
v-bind:rule="rule"
v-bind:index="index"
v-bind:key="index"
@edit="editRule(rule, index)"
@remove="removeRule(index)"
:col-headers="colHeadersPerRule[index]" />
<identifier-display v-for="(map, index) in mapping"
v-bind="map"
v-bind:index="index"
v-bind:key="map.type"
@remove="removeMapping(index)"
@edit="displayRuleType = 'mapping'"
v-on:mouseover.native="map.columns.forEach((col) => highlightColumn(col))"
v-on:mouseout.native="map.columns.forEach((col) => unhighlightColumn(col))"
:col-headers="colHeaders" />
<div v-if="mapping.length == 0">
One or more column definitions must be specified. These are required to specify how to build collections and datasets from rows and columns of the table. <a href="javascript:void(0)" @click="displayRuleType = 'mapping'">Click here</a> to manage column definitions.
</div>
</ol>
<div class="rules-buttons">
<div class="btn-group dropup">
<button type="button" v-b-tooltip.hover.bottom :title="titleRulesMenu" class="rule-menu-rules-button primary-button dropdown-toggle" data-toggle="dropdown">
<span class="fa fa-plus"></span> {{ l("Rules") }}<span class="caret"></span>
</button>
<div class="dropdown-menu" role="menu">
<rule-target-component :builder="this" rule-type="sort" />
<rule-target-component :builder="this" rule-type="remove_columns" />
<rule-target-component :builder="this" rule-type="split_columns" />
<rule-target-component :builder="this" rule-type="swap_columns" />
<a href="javascript:void(0)" class="dropdown-item rule-link rule-link-mapping" @click="displayRuleType = 'mapping'">Add / Modify Column Definitions</a>
</div>
</div>
<div class="btn-group dropup">
<button type="button" v-b-tooltip.hover.bottom :title="titleFilterMenu" class="rule-menu-filter-button primary-button dropdown-toggle" data-toggle="dropdown">
<span class="fa fa-plus"></span> {{ l("Filter") }}<span class="caret"></span>
</button>
<div class="dropdown-menu" role="menu">
<rule-target-component :builder="this" rule-type="add_filter_regex" />
<rule-target-component :builder="this" rule-type="add_filter_matches" />
<rule-target-component :builder="this" rule-type="add_filter_compare" />
<rule-target-component :builder="this" rule-type="add_filter_empty" />
<rule-target-component :builder="this" rule-type="add_filter_count" />
</div>
</div>
<div class="btn-group dropup">
<button type="button" v-b-tooltip.hover.bottom :title="titleColumMenu" class="rule-menu-column-button primary-button dropdown-toggle" data-toggle="dropdown">
<span class="fa fa-plus"></span> {{ l("Column") }}<span class="caret"></span>
</button>
<div class="dropdown-menu" role="menu">
<rule-target-component :builder="this" rule-type="add_column_basename" />
<rule-target-component :builder="this" rule-type="add_column_metadata" v-if="elementsType == 'collection_contents'"/>
<rule-target-component :builder="this" rule-type="add_column_regex" />
<rule-target-component :builder="this" rule-type="add_column_concatenate" />
<rule-target-component :builder="this" rule-type="add_column_rownum" />
<rule-target-component :builder="this" rule-type="add_column_value" />
<rule-target-component :builder="this" rule-type="add_column_substr" />
</div>
</div>
</div>
</div>
</div>
</div>
<!-- flex-column column -->
<!-- style="width: 70%;" -->
<div class="table-column" v-bind:class="orientation" style="width: 100%;" v-if="initialElements !== null">
<hot-table id="hot-table"
ref="hotTable"
:data="hotData['data']"
:colHeaders="colHeadersDisplay"
:readOnly="true"
stretchH="all">
</hot-table>
</div>
</div>
</rule-modal-middle>
<rule-modal-footer v-if="ruleView == 'source'">
<b-button v-b-tooltip.hover :title="titleSourceCancel" @click="cancelSourceEdit" class="rule-btn-cancel">
{{ l("Cancel") }}
</b-button>
<b-button v-b-tooltip.hover :title="titleSourceReset" class="creator-reset-btn rule-btn-reset">
{{ l("Reset") }}
</b-button>
<b-button v-b-tooltip.hover :title="titleSourceApply" @click="attemptRulePreview" class="rule-btn-okay">
{{ l("Apply")}}
</b-button>
</rule-modal-footer>
<rule-modal-footer v-else-if="ruleView == 'normal'">
<div class="rule-footer-inputs" slot="inputs">
<label v-if="elementsType == 'datasets'">
{{ l("Hide original elements") }}:
</label>
<input type="checkbox" v-model="hideSourceItems" v-if="elementsType == 'datasets'"/>
<div class="rule-footer-extension-group" v-if="extension && showFileTypeSelector">
<label>
{{ l("Type") }}:
</label>
<select2 name="extension" class="extension-select" v-model="extension" >
<option v-for="(col, index) in extensions" :value="col['id']"">{{ col["text"] }}</option>
</select2>
</div>
<div class="rule-footer-genome-group" v-if="genome && showGenomeSelector">
<label>
{{ l("Genome") }}:
</label>
<select2 class="genome-select" v-model="genome">
<option v-for="(col, index) in genomes" :value="col['id']"">{{ col["text"] }}</option>
</select2>
</div>
<div class="rule-footer-name-group" v-if="showCollectionNameInput">
<b-input class="collection-name"
:placeholder="namePlaceholder" :title="namePlaceholder" v-b-tooltip.hover v-model="collectionName" />
<label>
{{ l("Name") }}:
</label>
</div>
</div>
<b-button v-b-tooltip.hover :help="titleCancel" @click="cancel" class="creator-cancel-btn rule-btn-cancel" tabindex="-1">
{{ l("Cancel") }}
</b-button>
<b-button v-b-tooltip.hover @click="resetRulesAndState" :title="titleReset" class="creator-reset-btn rule-btn-reset">
{{ l("Reset") }}
</b-button>
<b-button v-b-tooltip.hover @click="createCollection" :title="titleFinish" class="create-collection rule-btn-okay" variant="primary" :disabled="!validInput">
{{ finishButtonTitle }}
</b-button>
</rule-modal-footer>
</state-div>
<state-div v-else-if="state == 'wait'">
<rule-modal-header>
{{ l("Galaxy is waiting for collection creation, this dialog will close when this is complete.") }}
</rule-modal-header>
<rule-modal-footer>
<b-button @click="cancel" class="creator-cancel-btn" tabindex="-1">
{{ l("Close") }}
</b-button>
</rule-modal-footer>
</state-div>
<state-div v-else-if="state == 'error'">
<!-- TODO: steal styling from paired collection builder warning... -->
<rule-modal-header>
A problem was encountered.
</rule-modal-header>
<rule-modal-middle>
<p class="errormessagelarge">{{ errorMessage }}</p>
</rule-modal-middle>
<rule-modal-footer>
<b-button v-b-tooltip.hover :title="titleCancel" @click="cancel" class="creator-cancel-btn" tabindex="-1">
{{ l("Close") }}
</b-button>
<b-button v-b-tooltip.hover :title="titleErrorOkay" @click="state = 'build'" tabindex="-1">
{{ l("Okay") }}
</b-button>
</rule-modal-footer>
</state-div>
</template>
<script>
import AjaxQueue from "utils/ajax-queue";
import axios from "axios";
import _l from "utils/localization";
import HotTable from "@handsontable/vue";
import Popover from "mvc/ui/ui-popover";
import UploadUtils from "mvc/upload/upload-utils";
import JobStatesModel from "mvc/history/job-states-model";
import RuleDefs from "mvc/rules/rule-definitions";
import Vue from "vue";
import BootstrapVue from "bootstrap-vue";
Vue.use(BootstrapVue);
const RULES = RuleDefs.RULES;
const MAPPING_TARGETS = RuleDefs.MAPPING_TARGETS;
// Local components...
// Based on https://vuejs.org/v2/examples/select2.html but adapted to handle list values
// with "multiple: true" set.
const Select2 = {
props: ["options", "value", "placeholder"],
template: `<select>
<slot></slot>
</select>`,
mounted: function() {
var vm = this;
$(this.$el)
// init select2
.select2({ data: this.options, placeholder: this.placeholder, allowClear: this.placeholder })
.val(this.value)
.trigger("change")
// emit event on change.
.on("change", function(event) {
vm.$emit("input", event.val);
});
},
watch: {
value: function(value) {
// update value
$(this.$el).val(value);
},
options: function(options) {
// update options
$(this.$el)
.empty()
.select2({ data: options });
}
},
destroyed: function() {
$(this.$el)
.off()
.select2("destroy");
}
};
const ColumnSelector = {
template: `
<div class="rule-column-selector" v-if="!multiple || !ordered">
<label class="d-flex justify-content-end align-items-center">
<span class="mr-auto" v-b-tooltip.hover :title="help">{{ label }}</span>
<div class="mr-1" v-b-tooltip.hover :title="title"><select2 :value="target" @input="handleInput" :multiple="multiple">
<option v-for="(col, index) in colHeaders" :value="index">{{ col }}</option>
</select2></div>
<slot></slot>
</label>
</div>
<div class="rule-column-selector" v-else>
<span>{{ label }}</span>
<slot></slot>
<ol>
<li v-for="(targetEl, index) in target"
v-bind:index="index"
v-bind:key="targetEl"
class="rule-column-selector-target">
{{ colHeaders[targetEl] }}
<span class="fa fa-times rule-column-selector-target-remove" @click="handleRemove(index)"></span>
<span class="fa fa-arrow-up rule-column-selector-up" v-if="index !== 0" @click="moveUp(index)"></span>
<span class="fa fa-arrow-down rule-column-selector-down" v-if="index < target.length - 1" @click="moveUp(index + 1)"></span>
</li>
<li v-if="this.target.length < this.colHeaders.length">
<span class="rule-column-selector-target-add" v-if="!orderedEdit">
<i @click="$emit('update:orderedEdit', true)">... {{ l("Assign Another Column") }}</i>
</span>
<span class="rule-column-selector-target-select" v-else>
<select2 @input="handleAdd" placeholder="Select a column">
<option /><!-- empty option selection for placeholder -->
<option v-for="(col, index) in remainingHeaders" :value="index">{{ col }}</option>
</select2>
</span>
</li>
</ol>
</div>
`,
data: function() {
return {
l: _l
};
},
props: {
target: {
required: true
},
label: {
required: false,
type: String,
default: _l("From Column")
},
help: {
required: false
},
colHeaders: {
type: Array,
required: true
},
multiple: {
type: Boolean,
required: false,
default: false
},
ordered: {
type: Boolean,
required: false,
default: false
},
valueAsList: {
type: Boolean,
required: false,
default: false
},
orderedEdit: {
type: Boolean,
required: false,
default: false
}
},
computed: {
remainingHeaders() {
const colHeaders = this.colHeaders;
if (!this.multiple) {
return colHeaders;
}
const remaining = {};
for (let key in colHeaders) {
if (this.target.indexOf(parseInt(key)) === -1) {
remaining[key] = colHeaders[key];
}
}
return remaining;
},
title() {
return _l("Select a column");
}
},
methods: {
handleInput(value) {
if (this.multiple) {
// https://stackoverflow.com/questions/262427/why-does-parseint-yield-nan-with-arraymap
let val = value.map(idx => parseInt(idx));
this.$emit("update:target", val);
} else {
let val = parseInt(value);
if (this.valueAsList) {
val = [val];
}
this.$emit("update:target", val);
}
},
handleAdd(value) {
this.target.push(parseInt(value));
this.$emit("update:orderedEdit", false);
},
handleRemove(index) {
this.target.splice(index, 1);
},
moveUp(value) {
const swapVal = this.target[value - 1];
Vue.set(this.target, value - 1, this.target[value]);
Vue.set(this.target, value, swapVal);
}
},
components: {
Select2
}
};
const RegularExpressionInput = {
template: `
<div>
<label for="regular_expression" v-b-tooltip.hover :title="title">{{ label }}</label>
<span v-b-popover.html="popoverContent" :title="popoverTitle" class="fa fa-question"></span>
<input v-b-tooltip.hover.left :title="title" name="regular_expression" class="rule-regular-expression" type="text" :value="target" @input="$emit('update:target', $event.target.value)" />
</div>
`,
props: {
target: {
required: true
}
},
computed: {
label() {
return _l("Regular Expression");
},
title() {
return _l("Enter a regular expression.");
},
popoverTitle() {
return _l("Regular Expressions");
},
popoverContent() {
return _l(
`Regular expressions are patterns used to match character combinations in strings. This input accepts Python-style regular expressions, find more information about these in <a href="https://pythonforbiologists.com/regular-expressions/">this Python for Biologists tutorial</a>.`
);
}
}
};
const RuleDisplay = {
template: `
<li class="rule">
<span class="rule-display">
<span class="mr-1">{{ title }}</span>
<span v-b-tooltip.hover :title="editTitle" class="fa fa-edit mr-1" @click="edit"></span>
<span v-b-tooltip.hover :title="removeTitle" class="fa fa-times map" @click="remove"></span>
</span>
<span class="rule-warning" v-if="rule.warn">
{{ rule.warn }}
</span>
<span class="rule-error" v-if="rule.error">
<span class="alert-message">{{ rule.error }}</span>
</span>
</li>
`,
props: {
rule: {
required: true,
type: Object
},
colHeaders: {
type: Array,
required: true
}
},
computed: {
title() {
const ruleType = this.rule.type;
return RULES[ruleType].display(this.rule, this.colHeaders);
},
editTitle() {
return _l("Edit this rule.");
},
removeTitle() {
return _l("Remove this rule.");
}
},
methods: {
edit() {
this.$emit("edit");
},
remove() {
this.$emit("remove");
}
}
};
const IdentifierDisplay = {
template: `
<li class="rule">
<span v-b-tooltip.hover :title="help">Set {{ columnsLabel }} as {{ typeDisplay }}</span>
<span v-b-tooltip.hover :title="titleEdit" class="fa fa-edit" @click="edit"></span>
<span v-b-tooltip.hover :title="titleRemove" class="fa fa-times" @click="remove"></span>
</li>
`,
props: {
type: {
type: String,
required: true
},
columns: {
required: true
},
colHeaders: {
type: Array,
required: true
}
},
methods: {
remove() {
this.$emit("remove");
},
edit() {
this.$emit("edit");
}
},
computed: {
typeDisplay() {
return MAPPING_TARGETS[this.type].label;
},
help() {
return MAPPING_TARGETS[this.type].help || "";
},
titleEdit() {
return _l("Edit column definition");
},
titleRemove() {
return _l("Remove this column definition");
},
columnsLabel() {
return RuleDefs.columnDisplay(this.columns, this.colHeaders);
}
}
};
const RuleTargetComponent = {
template: `<a class="rule-link dropdown-item" href="javascript:void(0)" :class="linkClassName" @click="builder.addNewRule(ruleType)">{{title}}</a>`,
props: {
ruleType: {
type: String,
required: true
},
builder: {
required: true
}
},
computed: {
linkClassName() {
return "rule-link-" + this.ruleType.replace(/_/g, "-");
},
title() {
return RULES[this.ruleType].title;
}
}
};
const RuleComponent = {
template: `
<div v-if="ruleType == displayRuleType" class="rule-editor" :class="typeToClass">
<slot></slot>
<div class="buttons rule-edit-buttons d-flex justify-content-end">
<button type="button" class="btn rule-editor-cancel mr-1" @click="cancel">{{ cancelLabel }}</button>
<button type="button" class="btn btn-primary rule-editor-ok" @click="okay">{{ applyLabel }}</button>
</div>
</div>`,
data: function() {
return {
applyLabel: _l("Apply"),
cancelLabel: _l("Cancel")
};
},
props: {
ruleType: {
type: String,
required: true
},
displayRuleType: {
required: true
},
builder: {
required: true
}
},
methods: {
cancel() {
this.builder.displayRuleType = null;
},
okay() {
this.builder.handleRuleSave(this.ruleType);
this.cancel();
}
},
computed: {
typeToClass() {
return "rule-edit-" + this.ruleType.replace(/_/g, "-");
}
}
};
const StateDiv = {
template: `
<div class="rule-collection-creator collection-creator flex-row-container">
<slot></slot>
</div>`
};
const RuleModalHeader = {
template: `<div class="header flex-row no-flex"><slot></slot></div>`
};
const RuleModalMiddle = {
template: `<div class="middle flex-row flex-row-container"><slot></slot></div>`
};
const RuleModalFooter = {
template: `
<div class="rule-footer footer flex-row no-flex">
<slot name="inputs"></slot>
<div class="actions clear vertically-spaced">
<div class="main-options float-right">
<slot></slot>
</div>
</div>
</div>`
};
export default {
data: function() {
let orientation = "vertical";
let mapping, rules;
if (this.initialRules) {
mapping = this.initialRules.mapping.slice();
rules = this.initialRules.rules.slice();
} else {
if (this.elementsType == "ftp") {
mapping = [{ type: "ftp_path", columns: [0] }];
} else if (this.elementsType == "datasets") {
mapping = [{ type: "list_identifiers", columns: [1] }];
} else {
mapping = [];
}
rules = [];
if (this.elementsType == "collection_contents") {
if (this.initialElements !== null) {
const collectionType = this.initialElements.collection_type;
const collectionTypeRanks = collectionType.split(":");
for (let index in collectionTypeRanks) {
rules.push({
type: "add_column_metadata",
value: "identifier" + index
});
}
} else {
orientation = "horizontal";
// just assume a list is given by default.
rules.push({
type: "add_column_metadata",
value: "identifier0"
});
}
}
}
return {
rules: rules,
colHeadersPerRule: [],
mapping: mapping,
state: "build", // 'build', 'error', 'wait',
ruleView: "normal", // 'normal' or 'source'
ruleSource: "",
ruleSourceJson: null,
ruleSourceError: null,
errorMessage: "",
jaggedData: false,
waitingJobState: "new",
titleReset: _l("Undo all reordering and discards"),
titleNumericSort: _l(
"By default columns will be sorted lexiographically, check this option if the columns are numeric values and should be sorted as numbers"
),
titleInvertFilterRegex: _l("Remove rows not matching the specified regular expression at specified column"),
titleInvertFilterEmpty: _l("Remove rows that have non-empty values at specified column"),
titleInvertFilterMatches: _l("Remove rows not matching supplied value"),
titleViewSource: _l(
"Advanced Option: View and or edit the JSON representation of the rules to apply to this tabular data"
),
titleSourceCancel: _l("Stop editing rules and dismiss changes"),
titleSourceReset: _l("Reset text area to current set of rules"),
titleSourceApply: _l("Apply changes to rule source and return to rule preview"),
titleRulesMenu: _l("General rules to apply"),
titleFilterMenu: _l("Rules that filter rows from the data"),
titleColumMenu: _l("Rules that generate new columns"),
titleRemoveMapping: _l("Remove column definition assignment"),
titleApplyColumnDefinitions: _l("Apply these column definitions and return to rules preview"),
titleAddColumnDefinition: _l("Assign a new piece of metadata as being derived from a column of the table"),
titleErrorOkay: _l("Dismiss this error and return to the rule builder to try again with new rules"),
namePlaceholder: _l("Enter a name for your new collection"),
activeRuleIndex: null,
addColumnRegexTarget: 0,
addColumnBasenameTarget: 0,
addColumnRegexExpression: "",
addColumnRegexReplacement: null,
addColumnRegexGroupCount: null,
addColumnRegexType: "global",
addColumnMetadataValue: 0,
addColumnConcatenateTarget0: 0,
addColumnConcatenateTarget1: 0,
addColumnRownumStart: 1,
addColumnSubstrTarget: 0,
addColumnSubstrType: "keep_prefix",
addColumnSubstrLength: 1,
addColumnValue: "",
removeColumnTargets: [],
addFilterRegexTarget: 0,
addFilterRegexExpression: "",
addFilterRegexInvert: false,
addFilterMatchesTarget: 0,
addFilterMatchesValue: "",
addFilterMatchesInvert: false,
addFilterEmptyTarget: 0,
addFilterEmptyInvert: false,
addFilterCompareTarget: 0,
addFilterCompareValue: 0,
addFilterCompareType: "less_than",
addFilterCountN: 1,
addFilterCountInvert: false,
addFilterCountWhich: "first",
addSortingTarget: 0,
addSortingNumeric: false,
splitColumnsTargets0: [],
splitColumnsTargets1: [],
swapColumnsTarget0: 0,
swapColumnsTarget1: 0,
collectionName: "",
displayRuleType: null,
extensions: [],
extension: null,
genomes: [],
genome: null,
hideSourceItems: this.defaultHideSourceItems,
orientation: orientation
};
},
props: {
initialElements: {
required: true
},
importType: {
type: String,
required: false,
default: "collections"
},
elementsType: {
type: String,
required: false,
default: "datasets"
},
// required if elementsType is "datasets" - hook into Backbone code for creating
// collections from HDAs, etc...
creationFn: {
required: false,
type: Function
},
// required if elementsType is "collection_contents" - hook into tool form to update
// rule parameter
saveRulesFn: {
required: false,
type: Function
},
initialRules: {
required: false,
type: Object
},
defaultHideSourceItems: {
type: Boolean,
required: false,
default: true
},
// Callbacks sent in by modal code.
oncancel: {
required: true,
type: Function
},
oncreate: {
required: true,
type: Function
},
ftpUploadSite: {
type: String,
required: false,
default: null
}
},
computed: {
exisistingDatasets() {
const elementsType = this.elementsType;
return (
elementsType === "datasets" ||
elementsType === "collection_contents" ||
elementsType === "library_datasets"
);
},
showFileTypeSelector() {
return !this.exisistingDatasets && !this.mappingAsDict.file_type;
},
showGenomeSelector() {
return !this.exisistingDatasets && !this.mappingAsDict.dbkey;
},
showCollectionNameInput() {
return (
this.importType == "collections" &&
this.elementsType != "collection_contents" &&
!this.mappingAsDict.collection_name
);
},
titleFinish() {
if (this.elementsType == "datasets" || this.elementsType == "library_datasets") {
return _l("Create new collection from specified rules and datasets");
} else if (this.elementsType == "collection_contents") {
return _l("Save rules and return to tool form");
} else {
return _l("Upload collection using specified rules");
}
},
titleCancel() {
if (this.importType == "datasets") {
return _l("Close this modal and do not upload any datasets");
} else {
return _l("Close this modal and do not create any collections");
}