-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathTable.js
More file actions
150 lines (143 loc) · 3.68 KB
/
Copy pathTable.js
File metadata and controls
150 lines (143 loc) · 3.68 KB
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
/**
* @license
* Copyright 2019-2020 CERN and copyright holders of ALICE O2.
* See http://alice-o2.web.cern.ch/copyright for details of the copyright holders.
* All rights not expressly granted are reserved.
*
* This software is distributed under the terms of the GNU General Public
* License v3 (GPL Version 3), copied verbatim in the file "COPYING".
*
* In applying this license CERN does not waive the privileges and immunities
* granted to it by virtue of its status as an Intergovernmental Organization
* or submit itself to any jurisdiction.
*/
import { Observable } from '/js/src/index.js';
/**
* Model Table, encapsulate all changes of the table based on the user profile
*/
export default class Table extends Observable {
/**
* Instantiate Log class and its internal LogFilter
* @param {Model} model - root model of the application
*/
constructor(model) {
super();
this.model = model;
this.colsHeader = this.resetColumnsHeaderToDefault();
}
/**
* Increase cell size by one position. If at max, reduce to minimum
* @param {string} currentSize - current size of the column
* @param {string} column - column to be resized
*/
setNextSizeOfColumn(currentSize, column) {
switch (currentSize) {
case 'cell-xs':
this.colsHeader[column].size = 'cell-s';
break;
case 'cell-s':
this.colsHeader[column].size = 'cell-m';
break;
case 'cell-m':
this.colsHeader[column].size = 'cell-l';
break;
case 'cell-l':
this.colsHeader[column].size = 'cell-xl';
break;
case 'cell-xl':
this.colsHeader[column].size = 'cell-xs';
break;
default:
this.colsHeader[column].size = 'cell-xs';
}
this.notify();
}
/**
* Toggle the visibility of the column
* @param {string} column - column for which visibility is to be toggled
*/
toggleColumn(column) {
if (this.colsHeader[column]) {
this.colsHeader[column].visible = !this.colsHeader[column].visible;
this.notify();
}
}
/**
* Set column visibility based on `isVisible`.
* Hide the column if no value is passed
* @param {string} fieldName - column of which the visibility will be set
* @param {boolean} isVisible - hide/show the column
*/
setColumnVisibility(fieldName, isVisible = false) {
this.colsHeader[fieldName].visible = isVisible;
this.notify();
}
/**
* Method to reset what columns are displayed and their sizes
* @returns {object} - object with the default columns and their sizes
*/
resetColumnsHeaderToDefault() {
return {
date: {
size: 'cell-m',
visible: false,
},
time: {
size: 'cell-m',
visible: true,
},
hostname: {
size: 'cell-m',
visible: true,
},
rolename: {
size: 'cell-m',
visible: false,
},
pid: {
size: 'cell-s',
visible: false,
},
username: {
size: 'cell-m',
visible: false,
},
system: {
size: 'cell-s',
visible: true,
},
facility: {
size: 'cell-m',
visible: true,
},
detector: {
size: 'cell-s',
visible: true,
},
partition: {
size: 'cell-m',
visible: true,
},
run: {
size: 'cell-s',
visible: true,
},
errcode: {
size: 'cell-s',
visible: false,
},
errline: {
size: 'cell-s',
visible: false,
},
errsource: {
size: 'cell-m',
visible: false,
},
message: {
size: 'cell-xl', // remaining
visible: true,
},
};
}
}