Skip to content

Commit 665b5c0

Browse files
author
Francisco Moreno
committed
refactor and export json fixes
1 parent ca9f152 commit 665b5c0

4 files changed

Lines changed: 48 additions & 119 deletions

File tree

js/popup.js

Lines changed: 45 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,62 @@
11
window.onload = function () {
2+
initElements();
3+
4+
$(function () {
5+
$('[data-toggle="tooltip"]').tooltip()
6+
})
7+
}
8+
9+
function initElements(){
10+
annotationListeners();
11+
exportListeners();
212
updateCounters();
313
$(function () {
414
$('[data-toggle="tooltip"]').tooltip()
515
})
616
}
17+
function annotationListeners(){
18+
$(document).on('click', '#BugBtn' ,showBugReport);
19+
$(document).on('click', '#IdeaBtn' ,showIdeaReport);
20+
$(document).on('click', '#NoteBtn' ,showNoteReport);
21+
$(document).on('click', '#QuestionBtn' ,showQuestionReport);
22+
23+
$(document).on('click', '#addNewBugBtn', () => {addNewBug("")});
24+
$(document).on('click', '#addNewIdeaBtn', () => {addNewIdea("")});
25+
$(document).on('click', '#addNewNoteBtn', () => {addNewNote("")});
26+
$(document).on('click', '#addNewQuestionBtn', () => {addNewQuestion("")});
27+
28+
$(document).on('click', '#addNewBugSCBtn', () => {addNewAnnotationWithScreenShot("bug")});
29+
$(document).on('click', '#addNewIdeaSCBtn', () => {addNewAnnotationWithScreenShot("idea")});
30+
$(document).on('click', '#addNewNoteSCBtn', () =>{addNewAnnotationWithScreenShot("note")});
31+
$(document).on('click', '#addNewQuestionSCBtn', ()=> { addNewAnnotationWithScreenShot("question")});
32+
}
733

834
function showBugReport() {
935
hideAllReports();
1036
$("#addNewBug").fadeIn();
11-
document.getElementById("newBugDescription").focus();
37+
$('#newBugDescription').focus();
1238
};
1339

1440
function showIdeaReport() {
1541
hideAllReports();
1642
$("#addNewIdea").fadeIn();
17-
document.getElementById("newIdeaDescription").focus();
43+
$('#newIdeaDescription').focus();
1844
};
1945

2046
function showNoteReport() {
2147
hideAllReports();
2248
$("#addNewNote").fadeIn();
23-
document.getElementById("newNoteDescription").focus();
49+
$('#newNoteDescription').focus();
2450
};
2551

2652
function showQuestionReport() {
2753
hideAllReports();
2854
$("#addNewQuestion").fadeIn();
29-
document.getElementById("newQuestionDescription").focus();
55+
$('#newQuestionDescription').focus();
3056
};
3157

32-
document.addEventListener('DOMContentLoaded', function () {
33-
var bugBtn = document.getElementById("BugBtn");
34-
bugBtn.addEventListener('click', showBugReport);
35-
}, false);
36-
37-
document.addEventListener('DOMContentLoaded', function () {
38-
var addNewBugBtn = document.getElementById("addNewBugBtn");
39-
addNewBugBtn.addEventListener('click', function () {
40-
addNewBug("");
41-
}, false);
42-
}, false);
43-
44-
document.addEventListener('DOMContentLoaded', function () {
45-
var addNewBugBtn = document.getElementById("addNewBugSCBtn");
46-
addNewBugBtn.addEventListener('click', function () {
47-
addNewAnnotationWithScreenShot("bug");
48-
}, false);
49-
}, false);
50-
5158

5259
function addNewBug(imageURL) {
53-
//var bugName = document.getElementById("newBugDescription").value;
5460
var bugName = $('#newBugDescription').val().trim();
5561
if (bugName == "") return;
5662

@@ -67,7 +73,6 @@ function addNewBug(imageURL) {
6773
};
6874

6975
function addNewNote(imageURL) {
70-
//var noteName = document.getElementById("newNoteDescription").value;
7176
var noteName = $('#newNoteDescription').val().trim();
7277
if (noteName == "") return;
7378

@@ -84,7 +89,7 @@ function addNewNote(imageURL) {
8489
};
8590

8691
function addNewIdea(imageURL) {
87-
//var ideaName = document.getElementById("newIdeaDescription").value;
92+
8893
var ideaName = $('#newIdeaDescription').val().trim();
8994
if (ideaName == "") return;
9095
chrome.extension.sendMessage({
@@ -100,7 +105,6 @@ function addNewIdea(imageURL) {
100105
};
101106

102107
function addNewQuestion(imageURL) {
103-
//var questionName = document.getElementById("newQuestionDescription").value;
104108
var questionName = $('#newQuestionDescription').val().trim();
105109
if (questionName == "") return;
106110
chrome.extension.sendMessage({
@@ -115,63 +119,6 @@ function addNewQuestion(imageURL) {
115119
hideAllReports();
116120
};
117121

118-
document.addEventListener('DOMContentLoaded', function () {
119-
var noteBtn = document.getElementById("NoteBtn");
120-
noteBtn.addEventListener('click', showNoteReport);
121-
}, false);
122-
123-
document.addEventListener('DOMContentLoaded', function () {
124-
var addNewNoteBtn = document.getElementById("addNewNoteBtn");
125-
addNewNoteBtn.addEventListener('click', function () {
126-
addNewNote("");
127-
}, false);
128-
}, false);
129-
130-
document.addEventListener('DOMContentLoaded', function () {
131-
var addNewNoteBtn = document.getElementById("addNewNoteSCBtn");
132-
addNewNoteBtn.addEventListener('click', function () {
133-
addNewAnnotationWithScreenShot("note");
134-
});
135-
});
136-
137-
document.addEventListener('DOMContentLoaded', function () {
138-
var questionBtn = document.getElementById("QuestionBtn");
139-
questionBtn.addEventListener('click', showQuestionReport)
140-
}, false);
141-
142-
document.addEventListener('DOMContentLoaded', function () {
143-
var questionBtn = document.getElementById("addNewQuestionBtn");
144-
questionBtn.addEventListener('click', function () {
145-
addNewQuestion("");
146-
}, false);
147-
}, false);
148-
149-
document.addEventListener('DOMContentLoaded', function () {
150-
var questionBtn = document.getElementById("addNewQuestionSCBtn");
151-
questionBtn.addEventListener('click', function () {
152-
addNewAnnotationWithScreenShot("question");
153-
}, false);
154-
}, false);
155-
156-
157-
document.addEventListener('DOMContentLoaded', function () {
158-
var ideaBtn = document.getElementById("IdeaBtn");
159-
ideaBtn.addEventListener('click', showIdeaReport)
160-
}, false);
161-
162-
document.addEventListener('DOMContentLoaded', function () {
163-
var ideaBtn = document.getElementById("addNewIdeaBtn");
164-
ideaBtn.addEventListener('click', function () {
165-
addNewIdea("");
166-
}, false);
167-
}, false);
168-
169-
document.addEventListener('DOMContentLoaded', function () {
170-
var ideaBtn = document.getElementById("addNewIdeaSCBtn");
171-
ideaBtn.addEventListener('click', function () {
172-
addNewAnnotationWithScreenShot("idea");
173-
}, false);
174-
}, false);
175122

176123

177124
function addNewAnnotationWithScreenShot(type) {
@@ -206,10 +153,13 @@ function exportSessionCSV() {
206153
});
207154
};
208155

209-
document.addEventListener('DOMContentLoaded', function () {
210-
var exportCSVBtn = document.getElementById("exportCSVBtn");
211-
exportCSVBtn.addEventListener('click', exportSessionCSV)
212-
}, false);
156+
function exportListeners(){
157+
$(document).on('click','#exportCSVBtn', exportSessionCSV);
158+
$(document).on('click','#exportJsonBtn', exportSessionJSon);
159+
$(document).on('click','#importJsonBtn', ()=>{ $('#importJsonInput').click()});
160+
$(document).on('change','#importJsonInput', importSessionJSon);
161+
}
162+
213163

214164

215165
/* Export to JSon */
@@ -219,10 +169,6 @@ function exportSessionJSon() {
219169
});
220170
};
221171

222-
document.addEventListener('DOMContentLoaded', function () {
223-
var exportJSonBtn = document.getElementById("exportJsonBtn");
224-
exportJSonBtn.addEventListener('click', exportSessionJSon)
225-
}, false);
226172

227173
/* Import from JSon */
228174
function importSessionJSon(evt) {
@@ -235,28 +181,19 @@ function importSessionJSon(evt) {
235181
};
236182

237183
function onReaderLoad(event) {
238-
184+
clearAllReports();
239185
var importSession = event.target.result;
240186
chrome.extension.sendMessage({
241187
type: "importSessionJSon",
242188
jSonSession: importSession
243189
}, function (response) {
244-
clearAllReports();
245190
updateCounters();
191+
//Reset input value
192+
$('#importJsonInput').val("");
246193
});
247194

248195
}
249-
document.addEventListener('DOMContentLoaded', function () {
250-
var importJSonBtn = document.getElementById("importJsonBtn");
251-
importJSonBtn.addEventListener('click', function () {
252-
$('#importJsonInput').click();
253-
})
254-
}, false);
255196

256-
document.addEventListener('DOMContentLoaded', function () {
257-
var importJSonBtn = document.getElementById("importJsonInput");
258-
importJSonBtn.addEventListener('change', importSessionJSon)
259-
}, false);
260197

261198
document.addEventListener('DOMContentLoaded', function () {
262199
var cancelAnnotationBtn = document.getElementsByName("Cancel");
@@ -324,21 +261,12 @@ function updateCounters() {
324261
var ideas = session.getIdeas().length;
325262
var questions = session.getQuestions().length;
326263

327-
if (bugs > 0) {
328-
$("#bugCounter").html(" " + bugs + " ");
329-
}
330-
331-
if (notes > 0) {
332-
$("#noteCounter").html(" " + notes + " ");
333-
}
264+
bugs > 0? $("#bugCounter").html(" " + bugs + " "): $("#bugCounter").html("");
265+
notes > 0? $("#noteCounter").html(" " + notes + " "): $("#noteCounter").html("");
266+
ideas > 0? $("#ideaCounter").html(" " + ideas + " "): $("#ideaCounter").html("");
267+
questions > 0? $("#questionCounter").html(" " + questions + " "): $("#questionCounter").html("");
334268

335-
if (ideas > 0) {
336-
$("#ideaCounter").html(" " + ideas + " ");
337-
}
338269

339-
if (questions > 0) {
340-
$("#questionCounter").html(" " + questions + " ");
341-
}
342270
};
343271

344272
document.addEventListener('DOMContentLoaded', function () {

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"short_name": "Chrome Exploratory Testing",
55
"description": "Exploratory testing session using Chrome",
66
"author": "@morvader",
7-
"version": "2.0.0",
7+
"version": "2.0.1",
88
"icons": {
99
"16": "/icons/iconbig.png",
1010
"48": "/icons/iconbig.png",

popup.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,9 @@
9494
<button id="exportCSVBtn" class="btn btn-secondary" title="Export session to CSV" data-toggle="tooltip" data-placement="top"></button>
9595
<button id="exportJsonBtn" class="btn btn-secondary" title="Export session to JSON" data-toggle="tooltip" data-placement="top"></button>
9696
<button id="importJsonBtn" class="btn btn-secondary" title="Import session from JSON" data-toggle="tooltip" data-placement="top">
97-
<input type="file" name = "jsonFile" class="file-input" id="importJsonInput" ></input>
9897
</button>
98+
<input type="file" name = "jsonFile" class="file-input" id="importJsonInput" hidden="true"></input>
99+
99100
<button id="previewBtn" class="btn btn-secondary" title="View Session report" data-toggle="tooltip" data-placement="top"></button>
100101

101102
</div>

screenshots/report.png

55 KB
Loading

0 commit comments

Comments
 (0)