Newer
Older
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
<template>
<div>
<a ref="download"></a>
<table :id=id class="table table-striped table-bordered table-hover" width="100%"></table>
</div>
</template>
<script>
const _ = require('lodash');
const $ = window.jQuery = require('jquery');
require('./js/datatable');
let table;
export default {
name: 'data-table',
props: ['id', 'data', 'keyword', 'category'],
// watch: {
// selectedItem: function update(newValue) {
// const vm = this;
//
// switch (newValue) {
// case 'Genes':
// default:
// vm.createTable(vm.id, vm.data);
// }
// },
// },
methods: {
moveDetailPage(id) {
const vm = this;
const url = vm.category === "protein" ? `/protein/${id}` : `/condensate/${id}`
// eslint-disable-next-line
// console.log(url)
window.open(url)
},
createTable(id, data) {
const vm = this;
_.forEach(data, (d) => {
d.DT_RowID = vm.category === "protein" ? `${d.proteinId}` : `${d.unique_name}`;
});
const proteinColumns = [
{
title: 'Gene Name',
data: 'gene_name',
fnCreatedCell: (nTd, sData, oData) => {
let n = `${oData.gene_name}`;
if(vm.keyword) {
n = n.replace(new RegExp(vm.keyword, 'gi'), `<mark>$&</mark>`);
}
$(nTd).html(`<a href="" class="detail-link"> ${n}</a>`);
},
},
{
title: 'Name',
data: 'name',
fnCreatedCell: (nTd, sData, oData) => {
let n = `${oData.name}`;
if(vm.keyword) {
n = n.replace(new RegExp(vm.keyword, 'gi'), `<mark>$&</mark>`);
}
$(nTd).html(`${n}`);
},
},
{
title: 'Species',
data: 'species_name',
render: function ( data, type, row, meta ) {
return data + ' (' + row.species_tax_id + ')';
}
},
{
title: 'Uniprot',
data: 'uniprot_id',
// visible: false,
// fnCreatedCell: (nTd, sData, oData) => {
// $(nTd).html(`<a href="" class="detail-link gene"><i class="glyphicon glyphicon-list-alt"></i> </a>`);
// },
// render: function ( data, type, row, meta ) {
// return data + ' (' + row.uniprot_readable_id + ')';
// }
fnCreatedCell: (nTd, sData, oData) => {
let n = `${oData.uniprot_id} (${oData.uniprot_readable_id})`;
if(vm.keyword) {
n.replace(new RegExp(vm.keyword, 'gi'), `<mark>$&</mark>`);
}
$(nTd).html(`${n}`);
},
}
];
const condensateColumns = [
{
title: 'Name',
data: 'name',
fnCreatedCell: (nTd, sData, oData) => {
if(vm.keyword) {
let n = `${oData.name}`.replace(new RegExp(vm.keyword, 'gi'), `<mark>$&</mark>`);
$(nTd).html(`<a href="" class="detail-link"> ${n}</a>`);
} else {
$(nTd).html(`<a href="" class="detail-link"> ${oData.name}</a>`);
}
render: function ( data, type, row, meta ) {
return row.proteins.length;
}
// {
// title: 'Localization',
// render: function ( data, type, row, meta ) {
// return '(placeholder)';
// }
// },
// {
// title: 'Species',
// data: 'species_name',
// render: function ( data, type, row, meta ) {
// return data + ' (' + row.species_tax_id + ')';
// }
// },
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
];
const columns = vm.category === "protein" ? proteinColumns : condensateColumns;
// console.log(columns)
const nTableOptions = {
columns,
// aaSorting: [[ 0, 'asc' ]],
paging: true,
searching: true,
info: true,
data,
order: [], // order: [[0, 'asc']],
bDestroy: true, // Add this property to new setting,
oLanguage: {
sSearch: "Filter",
},
dom: '<"row"<"col-sm-2"f><"col-sm-10"p>><"row"t><"row"<"col-sm-4"i><"col-sm-8"p>>'
};
const tableId = `#${id}`;
if (table) {
table.destroy();
$(tableId).empty();
}
table = $(tableId).DataTable(nTableOptions);
// $("#download").html('<div style="text-align: right;"><div class="dropdown">\n' +
// ' <button class="btn btn-primary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">\n' +
// ' Download\n' +
// ' </button>\n' +
// ' <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">\n' +
// ' <a class="dropdown-item" href="#" ref="csv">CSV</a>\n' +
// ' <a class="dropdown-item" href="#" ref="tsv">TSV</a>\n' +
// ' <a class="dropdown-item" href="#" ref="json">JSON</a>\n' +
// ' </div>\n' +
// '</div></div>');
const tableBody = `${tableId} tbody`;
$(tableBody).on('click', 'tr td a.detail-link', (e) => {
e.preventDefault()
const tr = $(e.target).parent().parent();
const row = table.row(tr);
// console.log(row.data().proteinName)
if (vm.category === "protein") {
vm.moveDetailPage(row.data().uniprot_id);
} else {
vm.moveDetailPage(row.data().unique_name);
}
});
// $('#download').on('click', 'a.dropdown-item', (e) => {
// e.preventDefault()
// switch ($(e.target).text()) {
// case 'CSV':
// vm.downloadCsv(); break;
// case 'TSV':
// vm.downloadTsv(); break;
// case 'JSON':
// vm.downloadJson(); break;
// }
// });
},
// downloadCsv() {
// const vm = this;
// let exports = [];
//
// let header = ['Gene', 'GO Terms', 'Description', 'Phenotypic Top Matches'];
// exports.push(header.join(', '));
//
// _.forEach(vm.data, item => {
// let goTerms = [];
// _.each(item.gos, (i) => {
// goTerms.push(`${i[1]}(${i[0]})`)
// })
//
// let tophits = [];
// _.each(item.em_tophits, (i) => {
// tophits.push(`${i}`)
// })
// _.each(item.ee_tophits, (i) => {
// tophits.push(`${i}`)
// })
// _.each(item.gm_tophits, (i) => {
// tophits.push(`${i}`)
// })
//
// exports.push([item.locusName, `"${goTerms.join('\t')}"`, `"${item.description}"`, tophits.join('\t')].join(','));
// })
//
// let blob = new Blob([exports.join('\n')], {type: 'text/csv'})
//
// let contentDisposition = 'Content-Disposition: attachment; filename="download-data.csv"'
// let filename = contentDisposition.split('filename=')[1]
// filename = filename.replace(/"/g, '')
//
// let link = vm.$refs.download
// link.href = window.URL.createObjectURL(blob)
// link.download = filename
// link.click()
// },
// downloadTsv() {
// const vm = this;
// let exports = [];
//
// let header = ['Gene', 'GO Terms', 'Description', 'Phenotypic Top Matches'];
// exports.push(header.join('\t'));
//
// _.forEach(vm.data, item => {
// let goTerms = [];
// _.each(item.gos, (i) => {
// goTerms.push(`${i[1]}(${i[0]})`)
// })
//
// let tophits = [];
// _.each(item.em_tophits, (i) => {
// tophits.push(`${i}`)
// })
// _.each(item.ee_tophits, (i) => {
// tophits.push(`${i}`)
// })
// _.each(item.gm_tophits, (i) => {
// tophits.push(`${i}`)
// })
//
// exports.push([item.locusName, goTerms.join(', '), item.description, tophits.join(', ')].join('\t'));
// })
//
// let blob = new Blob([exports.join('\n')], {type: 'text/tsv'})
//
// let contentDisposition = 'Content-Disposition: attachment; filename="download-data.tsv"'
// let filename = contentDisposition.split('filename=')[1]
// filename = filename.replace(/"/g, '')
//
// let link = vm.$refs.download
// link.href = window.URL.createObjectURL(blob)
// link.download = filename
// link.click()
// },
// downloadJson() {
// const vm = this;
// let blob = new Blob([JSON.stringify(vm.data, null, 2)], {type: 'application/json'})
//
// let contentDisposition = 'Content-Disposition: attachment; filename="download-data.json"'
// let filename = contentDisposition.split('filename=')[1]
// filename = filename.replace(/"/g, '')
//
// let link = vm.$refs.download
// link.href = window.URL.createObjectURL(blob)
// link.download = filename
// link.click()
// },
},
mounted() {
const vm = this;
vm.createTable(vm.id, vm.data);
},
};
</script>
<style>
.no-padding {
padding: 0;
}
.gene {
font-size: large;
}
table.pheno {
width: 330px;
}
td.pheno-title {
text-align: center;
}
td.pheno {
width: 33%;
border-top: none;
border-bottom: none;
text-align: center;
vertical-align: middle;
font-size: small;
word-wrap: break-spaces;
}
td.pheno-item {
width: 33%;
text-align: center;
border-width: 0 1px;
word-wrap: break-word;
}
.table thead td.pheno {
border-width: 0 1px;
}
table.dataTable.row-border > tbody > tr:first-child > th,
table.dataTable.row-border > tbody > tr:first-child > td,
table.dataTable.display > tbody > tr:first-child > th,
table.dataTable.display > tbody > tr:first-child > td {
border-top: none;
}
table.dataTable.row-border > tbody > tr > th,
table.dataTable.row-border > tbody > tr > td,
table.dataTable.display > tbody > tr > th,
table.dataTable.display > tbody > tr > td {
border-top: 1px solid #ddd;
}
table.dataTable > tbody > tr {
background-color: #ffffff;
}
table.dataTable.row-border > tbody > tr:hover,
table.dataTable.display > tbody > tr:hover {
background-color: #f6f6f6;
}
.detail-link {
color: #0065b9;
font-weight: bold;
}
.dropdown-item {
font-size: 1.2rem;
}
select.form-control {
font-size: 12px;
padding: 3px 12px;
}
.pagination {
font-size: 1.2rem;
}
a mark {
color: #0065b9;
padding: 0;
text-decoration: underline;
font-style: oblique;
}
</style>