annotate src/common.js @ 1:7e3085fc60c1 draft default tip

master branch Updating
author lain
date Wed, 30 Aug 2023 14:21:18 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
1
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
2 this.ctx = () => context;
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
3 var all_contexts = [] ;
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
4 var inchidata = {} ;
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
5 var all_mix_data = {} ;
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
6 var already_sent_data = {} ;
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
7
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
8 function no_success(tab_index, inchi, data) {
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
9 console.log(`inchikey ${inchi} not found...`) ;
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
10 console.log(`disabling ${data} ...`)
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
11 disable_tab(
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
12 tab_index,
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
13 "red",
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
14 "This compound has not been found on peakforest"
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
15 ) ;
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
16 }
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
17
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
18 function disable_tab(tab_index, color, title) {
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
19 var element = $(`#open_tab_${tab_index}`) ;
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
20 element.attr("disabled", "disabled").off("click");
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
21 element.attr("onclick", null) ;
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
22 element.attr("title", title) ;
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
23 element.attr("data-toggle", null) ;
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
24 element.attr("href", null) ;
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
25 element.css("color", color) ;
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
26 element.css("cursor", "not-allowed") ;
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
27 }
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
28
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
29 function successfull_send_to_pf(bundle, json, index) {
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
30 for (var i = 0 ; i < all_contexts.length ; i += 1) {
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
31 if (all_contexts[i] === null || all_contexts[i] === undefined) {
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
32 continue ;
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
33 }
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
34 if (all_contexts[i].inchikey == bundle["sample"]["inchikey"]) {
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
35 disable_tab(
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
36 all_contexts[i].tab_index,
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
37 "green",
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
38 "This compound has already been sent to peakforest"
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
39 )
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
40 }
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
41 }
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
42 if (already_sent_data[index] == null) {
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
43 already_sent_data[index] = [] ;
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
44 }
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
45 json.forEach((id) => {
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
46 already_sent_data[index].push(id)
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
47 $("#send_buttons_div").prepend(`
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
48 <div class="row">
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
49 <div class="col-lg-3">
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
50 <div class="alert alert-success alert-dismissible" role="alert">
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
51 <button type="button" class="close" data-dismiss="alert">
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
52 <span aria-hidden="true">×</span>
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
53 <span class="sr-only">
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
54 <spring:message code="alert.close" text="Close"></spring:message>
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
55 </span>
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
56 </button>
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
57 <strong>
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
58 <spring:message code="alert.strong.info" text="Success!"></spring:message>
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
59 </strong> Spectrum has been sent:
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
60 <a
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
61 href="${ctx().peakforest_url}/webapp/home?PFs=${id.slice(3)}"
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
62 target="_blank"
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
63 >${id}</a>
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
64 </div>
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
65 </div>
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
66 </div>`)
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
67 })
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
68 }
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
69
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
70 function failed_send_to_pf(err, bundle) {
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
71 console.log(err) ;
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
72 $("#send_buttons_div").prepend(`
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
73 <div class="row">
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
74 <div class="col-lg-3">
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
75 <div class="alert alert-error alert-dismissible" role="alert">
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
76 <button type="button" class="close" data-dismiss="alert">
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
77 <span aria-hidden="true">×</span>
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
78 <span class="sr-only">
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
79 <spring:message code="alert.close" text="Close"></spring:message>
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
80 </span>
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
81 </button>
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
82 <strong>
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
83 <spring:message code="alert.strong.info" text="Error!"></spring:message>
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
84 </strong> Spectrum has not been sent!
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
85 </div>
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
86 </div>
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
87 </div>`)
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
88 }
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
89
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
90 function already_sent(bundle, index) {
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
91 return already_sent_data[index] != null ;
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
92 }
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
93
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
94 function failed_already_sent(bundle, index) {
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
95 already_sent_data[index].forEach((id) => {
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
96 $("#send_buttons_div").prepend(`
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
97 <div class="row">
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
98 <div class="col-lg-3">
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
99 <div class="alert alert-warning alert-dismissible" role="alert">
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
100 <button type="button" class="close" data-dismiss="alert">
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
101 <span aria-hidden="true">×</span>
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
102 <span class="sr-only">
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
103 <spring:message code="alert.close" text="Close"></spring:message>
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
104 </span>
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
105 </button>
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
106 <strong>
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
107 <spring:message code="alert.strong.info" text="warning!"></spring:message>
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
108 </strong> Spectrum has already been sent:
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
109 <a
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
110 href="${ctx().peakforest_url}/webapp/home?PFs=${id.slice(3)}"
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
111 target="_blank"
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
112 >${id}</a>
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
113 </div>
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
114 </div>
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
115 </div>`)
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
116 }) ;
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
117 }
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
118
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
119 function send_everything_to_peakforest(url, token) {
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
120 var bundles ;
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
121 if (context.is_mix()) {
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
122 bundles = [all_mix_data] ;
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
123 } else {
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
124 bundles = create_dataset_bundles() ;
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
125 }
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
126 bundles.forEach((bundle, index) => {
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
127 if (already_sent(bundle, index)) {
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
128 return failed_already_sent(bundle, index) ;
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
129 }
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
130 console.log(bundle)
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
131 $.ajax({
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
132 type: "post",
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
133 url: `${url}/rest/v2/spectrum?token=${token}`,
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
134 data: JSON.stringify(bundle),
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
135 contentType: "application/json",
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
136 success: function(json) {
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
137 successfull_send_to_pf(bundle, json, index)
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
138 }, error: function(err) {
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
139 failed_send_to_pf(err, bundle)
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
140 }
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
141 })
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
142 $.ajax({
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
143 type: "post",
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
144 url: "/",
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
145 data: `{"index": ${index}, "object": ${JSON.stringify(bundle)}}`,
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
146 contentType: "application/json",
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
147 error: function(err) {
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
148 console.log(`Error: JSON will not be produced by the application.`)
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
149 }
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
150 })
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
151 })
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
152 // console.log(bundles)
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
153 }
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
154
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
155 function create_dataset_bundles() {
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
156 var bundles = [] ;
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
157 var data ;
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
158 all_contexts.forEach((context, index) => {
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
159 if ((data = context.sent_json) === null) {
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
160 return ;
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
161 }
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
162 if (bundles.length === 0) {
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
163 // console.log("First metadata!")
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
164 return bundles.push(data) ;
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
165 }
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
166 if (merge_in_bundle(bundles, data)) {
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
167 // console.log("Merged!")
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
168 } else {
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
169 // console.log("New metadata!")
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
170 }
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
171 }) ;
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
172 return bundles ;
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
173 }
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
174
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
175 function merge_in_bundle(bundles, data) {
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
176 for(var i = 0 ; i < bundles.length ; i += 1) {
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
177 if (
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
178 identical(bundles[i]["sample"], data["sample"])
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
179 && identical(bundles[i]["chromatography"], data["chromatography"])
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
180 && identical(bundles[i]["analyzer"], data["analyzer"])
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
181 && identical(bundles[i]["ionization_mode_positive"], data["ionization_mode_positive"])
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
182 && identical(bundles[i]["ionization_mode_negative"], data["ionization_mode_negative"])
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
183 && identical(bundles[i]["other_metadata"], data["other_metadata"])
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
184 ) {
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
185 bundles[i]["peaklists"].push(data["peaklists"][0]) ;
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
186 return true ;
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
187 } else {
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
188 continue ;
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
189 console.log(
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
190 "sample: "
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
191 + identical(bundles[i]["sample"], data["sample"])
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
192 )
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
193 console.log(
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
194 "chromatography: "
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
195 + identical(bundles[i]["chromatography"], data["chromatography"])
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
196 )
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
197 console.log(
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
198 "analyzer: "
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
199 + identical(bundles[i]["analyzer"], data["analyzer"])
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
200 )
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
201 console.log(
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
202 "ionization_mode_positive: "
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
203 + identical(bundles[i]["ionization_mode_positive"], data["ionization_mode_positive"])
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
204 )
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
205 console.log(
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
206 "ionization_mode_negative: "
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
207 + identical(bundles[i]["ionization_mode_negative"], data["ionization_mode_negative"])
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
208 )
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
209 console.log(
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
210 "other_metadata: "
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
211 + identical(bundles[i]["other_metadata"], data["other_metadata"])
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
212 )
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
213 }
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
214 }
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
215 bundles.push(data) ;
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
216 return false ;
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
217 }
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
218
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
219 function identical(left, right) {
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
220 if (typeof left !== typeof right) {
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
221 return false ;
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
222 }
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
223 if (left === null) {
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
224 return right === null ;
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
225 }
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
226 if (right === null) {
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
227 return left === null ;
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
228 }
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
229 switch (typeof left) {
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
230 case "array":
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
231 return identical_array(left, right) ;
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
232 break ;
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
233 case "object":
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
234 return identical_object(left, right) ;
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
235 break ;
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
236 default:
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
237 break ;
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
238 }
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
239 return (left === right)
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
240 }
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
241
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
242 function identical_array(left, right) {
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
243 if (right.length !== left.length) {
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
244 return false ;
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
245 }
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
246 for(var i = 0 ; i < left.length ; i += 1) {
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
247 if (!identical(left[i], right[i])) {
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
248 return false ;
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
249 }
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
250 }
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
251 return true ;
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
252 }
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
253
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
254 function identical_object(left, right) {
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
255 var left_keys ;
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
256
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
257 if (!(
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
258 share_keys(left, right)
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
259 && share_keys(right, left)
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
260 )) {
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
261 return true ;
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
262 }
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
263 left_keys = Object.keys(left) ;
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
264 for (var i = 0 ; i < left_keys.length ; i += 1){
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
265 if (!identical(left[left_keys[i]], right[left_keys[i]])) {
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
266 return false ;
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
267 }
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
268 }
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
269 return true ;
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
270 }
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
271
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
272 function share_keys(left, right) {
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
273 var left_keys ;
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
274 var right_keys ;
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
275
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
276 left_keys = Object.keys(left) ;
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
277 right_keys = Object.keys(right) ;
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
278 for(var i = 0 ; i < left_keys.length ; i += 1) {
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
279 if (!right_keys.includes(left_keys[i])) {
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
280 return false ;
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
281 }
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
282 }
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
283 return true ;
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
284 }
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
285
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
286 var set_inchi_data = function(data, tab_index) {
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
287 inchidata[data.inchikey] = data ;
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
288 $(`#add1spectrum-sample-inchi-${tab_index}`).val(data.inchi);
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
289 $(`#add1spectrum-sample-inchi-${tab_index}`).change();
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
290 $(`#add1spectrum-sample-commonName-${tab_index}`).val(data.name);
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
291 $(`#add1spectrum-sample-commonName-${tab_index}`).change();
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
292 $(`#sample-bonus-display-${tab_index}`).html(
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
293 `<img
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
294 class=""
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
295 src="{{ PF_URL_PLACEHOLDER }}/webapp/image/${data.type}/${data.inchikey}"
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
296 alt="${data.name}"
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
297 >`
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
298 );
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
299 }
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
300
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
301 var lightgrayRenderer = function(instance, td, row, col, prop, value, cellProperties) {
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
302 Handsontable.renderers.TextRenderer.apply(this, arguments);
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
303 td.style.backgroundColor = "#EEE";
7e3085fc60c1 master branch Updating
lain
parents:
diff changeset
304 }