forked from interactivereport/cellxgene_VIP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
saveVIP.js
184 lines (174 loc) · 3.96 KB
/
saveVIP.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
/*
The following provide the functionality for saving and loading the session
*/
// functions for selected cells
function cellSave(){
var v = {};
for(const i of ['1','2']){
var cN = window.store.getState().differential['celllist'+i];
if(cN===null) cN = [];
v['celllist'+i] = Array.from(cN);
}
return v;
}
function cellLoad(v){
for(const i of [1,2]){
window.store.dispatch({type: "store current cell selection as differential set "+i, data:Int32Array.from(v['celllist'+i])});
}
}
// functions for genes and gene sets
function geneSave(){
return {'genes':window.biogen,
'geneSets':window.bioGeneGrp}
}
function geneLoad(v){
window.biogen = v['genes'];
window.bioGeneGrp = v['geneSets'];
}
// functions save all select/dropdown box
function selectSave(){
var v = {};
$('select').each(function(){
if(!this.id.includes('geneset') && this.id.length>0){
v[this.id] = $(this).val();
}
});
return v;
}
function selectLoad(v){
for(const one of Object.keys(v)){
if(!!v[one]){
$("#"+one).val(v[one]);
}
}
}
// function save all checkbox
function checkSave(){
var cIDs = [];
$('input:checkbox').each(function(){
if(!!this.className && this.className.length>0){
cIDs.push(this.className);
}
});
var v={};
for(const cID of [...new Set(cIDs)]){
var notCK = [];
for(const one of $("."+cID+":checkbox:not(:checked)")){
notCK.push(one.value);
}
v[cID] = notCK;
}
return v;
}
function checkLoad(v){
for(const cID of Object.keys(v)){
$("."+cID).prop("checked",false);
for(const one of $("."+cID)){
if(!v[cID].includes(one.value)){
if($(one).prop('disabled')){
break;
}else{
$(one).trigger('click');
}
}
}
}
}
// function save all radio buttons
function radioSave(){
var cNames = [];
$('input:radio').each(function(){
if(!!this.name && this.name.length>0){
cNames.push(this.name);
}
});
var v={};
for(const cName of [...new Set(cNames)]){
v[cName] = $("input[name='"+cName+"']:checked").val();
}
return v;
}
function radioLoad(v){
for(const cName of Object.keys(v)){
$("input[name='"+cName+"'][value='"+v[cName]+"']").prop('checked', true);
}
}
// function save all input numbers
function numberSave(){
var v={};
$('input[type="number"').each(function(){
v[this.id] = $(this).val();
});
return v;
}
function numberLoad(v){
for(const cID of Object.keys(v)){
$("#"+cID).val(v[cID]);
}
}
// function save sortableUI
function sortableSave(){
var v= {};
$(".sortable-list").each(function(){
var one = {}
for(const eID of $(this).sortable('toArray')){
one[eID]=$('[id="'+eID+'"]').find("label").text();
}
v[this.id] = one;
});
return v;
}
function sortableLoad(v){
for(const cID in v){
var htmlCheck = "";
for(const one in v[cID]){
htmlCheck += "<li id='"+one+"'><label>"+v[cID][one]+"</label></li>";
}
$("#"+cID).html(htmlCheck);
}
}
// function save images
function imageCreate(){
var v={};
$('img').each(function(){
if(this.id.length>0){
v[this.id] = $(this).attr('src');
}
})
return v;
}
function imageSave(){
var v=imageCreate();
var hiddenE = document.createElement('a');
hiddenE.href="data:attachment/text,"+encodeURIComponent(JSON.stringify(v));
hiddenE.target='_blank';
hiddenE.download='cellxgene.'+window.store.getState().config.displayNames.dataset+'.img.txt';
hiddenE.click();
}
// function save specific eID
function eIDsave(eIDs){
var v={};
for(const one of eIDs){
switch(one){
case 'GSEAenable':
case "IMGcumuCK":
case "GSEAcollapse":
v[one]=$("#"+one).prop('checked');
break;
}
}
return v;
}
function eIDload(v){
for(const one in v){
switch(one){
case 'GSEAenable':
case "IMGcumuCK":
case "GSEAcollapse":
if(v[one]!=$("#"+one).prop('checked')){
$("#"+one).trigger('click')
}
break;
}
}
}