template.j2 4.68 KB
Newer Older
Saad Jbabdi's avatar
Saad Jbabdi committed
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
<!DOCTYPE html>
<html>
<style>
* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: Arial, Helvetica, sans-serif;
}

.header {
    text-align: center;
    padding: 32px;
}

.row {
    display: -ms-flexbox; /* IE 10 */
    display: flex;
    -ms-flex-wrap: wrap; /* IE 10 */
    flex-wrap: wrap;
    padding: 0 4px;
}

/* Create two equal columns that sits next to each other */
.column {
    -ms-flex: 50%; /* IE 10 */
    flex: 50%;
    padding: 0 4px;
}

.column img {
    margin-top: 8px;
    vertical-align: middle;
}

/* Style the buttons */
.btn {
    border: none;
    outline: none;
    padding: 10px 16px;
    background-color: #f1f1f1;
    cursor: pointer;
    font-size: 18px;
}

.btn:hover {
    background-color: #ddd;
}

.btn.active {
    background-color: #666;
    color: white;
}
</style>
<body>

<!-- Header -->
<div class="header" id="myHeader">
  <h1>Cell density mapping report</h1>
  <p>Click on the buttons to change the grid view. Click on the images to change labels (red=bad, orange=ok, white=good)</p>
  <button class="btn" onclick="one()">1 per row</button>
  <button class="btn active" onclick="two()">2</button>
  <button class="btn" onclick="four()">4</button>
  <button class="btn" onclick="eight()">8</button>
  <button class="btn" onclick="onsave()">Save</button>
</div>

<!-- Photo Grid -->
Saad Jbabdi's avatar
updates    
Saad Jbabdi committed
71
72
73
74
75
<div class="row" style="text-align:center;border:1px solid black"> 
  {% for  img,n in images_ncells %}
<div class="column" style="text-align:center;border:1px solid black">
    <p> <font size="1" color="red"> ~{{ n }} cells</font>
    <img src="{{ img }}" style="width:100%">
Saad Jbabdi's avatar
Saad Jbabdi committed
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
  </div>
    {% endfor %}
</div>



<script>
// Get the elements with class="column"
var elements = document.getElementsByClassName("column");

// Declare a loop variable
var i;

// Full-width images
function one() {
    for (i = 0; i < elements.length; i++) {
        elements[i].style.msFlex = "100%";  // IE10
        elements[i].style.flex = "100%";
    }
}

// Two images side by side
function two() {
    for (i = 0; i < elements.length; i++) {
        elements[i].style.msFlex = "50%";  // IE10
        elements[i].style.flex = "50%";
    }
}

// Four images side by side
function four() {
    for (i = 0; i < elements.length; i++) {
        elements[i].style.msFlex = "25%";  // IE10
        elements[i].style.flex = "25%";
    }
}

// Eight images side by side
function eight() {
    for (i = 0; i < elements.length; i++) {
        elements[i].style.msFlex = "12.5%";  // IE10
        elements[i].style.flex = "12.5%";
    }
}

// Add active class to the current button (highlight it)
var header = document.getElementById("myHeader");
var btns = header.getElementsByClassName("btn");
for (var i = 0; i < btns.length; i++) {
  btns[i].addEventListener("click", function() {
    var current = document.getElementsByClassName("active");
    current[0].className = current[0].className.replace(" active", "");
    this.className += " active";
  });
}

// clicking on images
var classes = [
    "good",
    "bad",
    "ok"
];

var borders = {
    "good" : "5px solid #ffffff", // good (wite)
    "bad"  : "5px solid #ff0000", // bad (red)
    "ok"   : "5px solid #FFA500"  // ok (orange)
};

var imgs = document.getElementsByTagName("img");

for (var i = 0; i < imgs.length; i++) {
    (function(idx) {
      var img = imgs[idx];
      img.style.border = borders[classes[0]];
      img.current_class = classes[0];
      img.addEventListener("click", function() {
      
	var class_idx = classes.indexOf(img.current_class);
	var new_class = classes[(class_idx + 1) % 3]; 
	
	img.style.border  = borders[new_class];
	img.current_class = new_class;
      });
    })(i);
}

function onsave() {

	 var imgs = document.getElementsByTagName("img");
	 
	 let csvContent = "File,Score\r\n";
	 for (var i = 0; i < imgs.length; i++) {   
		var img = imgs[i];
   	    	img_class = img.current_class;

		csvContent += img.src + " , " + img_class + "\r\n";
	}
	// console.log(str);
	
	var download = function(content, fileName, mimeType) {
	var a = document.createElement('a');
  	mimeType = mimeType || 'application/octet-stream';

 	if (navigator.msSaveBlob) { // IE10
  	   navigator.msSaveBlob(new Blob([content], {
      	   type: mimeType
    	   }), fileName);
  	} else if (URL && 'download' in a) { //html5 A[download]
    	a.href = URL.createObjectURL(new Blob([content], {
      	type: mimeType
    	}));
    	a.setAttribute('download', fileName);
    	document.body.appendChild(a);
    	a.click();
    	document.body.removeChild(a);
  	} else {
    	location.href = 'data:application/octet-stream,' + encodeURIComponent(content); // only this mime type is supported
  	}
	}

	download(csvContent, 'report.csv', 'text/csv;encoding:utf-8');
}


</script>

</body>
</html>