-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.js
105 lines (87 loc) · 3.44 KB
/
main.js
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
const {app, BrowserWindow, shell} = require("electron");
const HTMLparser = require("node-html-parser");
var fs = require('fs');
var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
console.log("loaded")
let win = null;
var Questions = null;
require("dotenv").config();
let req = new XMLHttpRequest();
req.onreadystatechange = () => {
console.log(`state changed ${req.readyState}`);
if (req.readyState == 4) {
console.log("recieved");
Questions = JSON.parse(req.responseText).record
var htmlContent = fs.readFileSync(__dirname + "/BasePage.html");
fs.writeFileSync(__dirname + '/temp-html.html', htmlContent,{encoding:'utf8',flag:'w'});
let num = 1
Questions.TextAnswerQuestionList.forEach(question => {
StringQuestion(question, num)
num++
});
var document = HTMLparser.parse(fs.readFileSync(__dirname + "/temp-html.html"));
document.getElementById("Question-info").getElementById("Teacher-name").innerHTML = Questions.TeacherName;
document.getElementById("Question-info").getElementById("Quiz-name").innerHTML = Questions.FeedbackQuestionsTitle
console.log(JSON.stringify(Questions))
fs.writeFileSync(__dirname + "/Questions.json", JSON.stringify(Questions),{encoding:'utf8',flag:'w'})
document.getElementById("main-section").setAttribute("data-", __dirname);
fs.writeFileSync(__dirname + "/temp-html.html", document.toString(),{encoding:'utf8',flag:'w'})
app.whenReady().then(createWindow);
}
};
req.open("GET", process.env.quizBin, true);
req.setRequestHeader(process.env.masterKey, process.env.apiAccessKey);
req.send();
const createWindow = () => {
win = new BrowserWindow({
show: false,
width: 1900,
height:1000,
title: "Feedback",
resizable: true,
fullscreenable: true,
autoHideMenuBar: true,
webPreferences: {
nodeIntegration: true
}
})
win.maximize();
//win.removeMenu();
const electronLocalshortcut = require('electron-localshortcut');
electronLocalshortcut.register(win, 'home', () => {
win.loadFile(__dirname + "/temp-html.html")
win.title = "Feedback"
console.log("back");
// Open DevTools
});
electronLocalshortcut.register(win, 'F11', () => {
win.setFullScreen(true)
console.log("fullscreen");
// Open DevTools
});
electronLocalshortcut.register(win, 'Escape', () => {
win.setFullScreen(false)
console.log("exit-fullscreen");
// Open DevTools
});
win.loadFile(__dirname + "/temp-html.html")
win.show();
};
function StringQuestion(question, num){
var text = question.questionText;
var QuestionExample = HTMLparser.parse(fs.readFileSync(__dirname + "/TextQuestion.html"))
QuestionExample.getElementsByTagName("h1").forEach(element =>{
if (question.manditory) text += " *";
element.innerHTML = text
})
QuestionExample.getElementsByTagName("span").forEach(element =>{
element.setAttribute("id", `Question${num}`)
})
var FinalPage = HTMLparser.parse(fs.readFileSync(__dirname + "/temp-html.html"));
FinalPage.getElementById("questions").innerHTML += QuestionExample.toString();
FinalPage.getElementById("questions").setAttribute("data-", Questions.TextAnswerQuestionList.length)
fs.writeFileSync(__dirname + "/temp-html.html", FinalPage.toString(),{encoding:'utf8',flag:'w'})
}
function GetNumQuestions(){
return Questions.TextAnswerQuestionList.length
}