Skip to content

Commit

Permalink
Merge pull request #7 from socrathematics/hints-and-solutions
Browse files Browse the repository at this point in the history
Added support for practice problems
  • Loading branch information
saumyasinghal747 authored Jul 5, 2020
2 parents 51db1fa + a63bdd6 commit 0231dc8
Show file tree
Hide file tree
Showing 2 changed files with 200 additions and 24 deletions.
180 changes: 176 additions & 4 deletions v2/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
const { app, BrowserWindow } = require('electron')
const { app, BrowserWindow, Menu } = require('electron')

const isMac = process.platform === 'darwin';

const windows = new Set();

function createWindow () {
// Create the browser window.
const win = new BrowserWindow({
width: 800,
height: 600,
width: 1100,
height: 700,
webPreferences: {
nodeIntegration: true
}
Expand All @@ -14,7 +18,7 @@ function createWindow () {
win.loadFile('index.html')

// Open the DevTools.
//win.webContents.openDevTools()
//win.webContents.openDevTools()
}

// This method will be called when Electron has finished
Expand All @@ -41,3 +45,171 @@ app.on('activate', () => {

// In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and require them here.
const template = [
// { role: 'appMenu' }
...(isMac ? [{
label: app.name,
submenu: [
{ role: 'about' },
{ type: 'separator' },
{ role: 'services' },
{ type: 'separator' },
{ role: 'hide' },
{ role: 'hideothers' },
{ role: 'unhide' },
{ type: 'separator' },
{ role: 'quit' }
]
}] : []),
// { role: 'fileMenu' }
{
label: 'File',
submenu: [
/*{
label: 'New File',
accelerator:'CommandOrControl+Shift+N',
click(item, focusedWindow) {
//const win = require('electron').remote.getCurrentWindow();
focusedWindow.webContents.executeJavaScript(`makeCourse;`);
}
},*/
{
label: 'Generate Course',
accelerator:'CommandOrControl+Enter',
click(item, focusedWindow) {
focusedWindow.webContents.executeJavaScript(`makeCourse();`);

}
},
{ type: 'separator' },
isMac ? { role: 'close' } : { role: 'quit' }

]
},
// { role: 'editMenu' }
{
label: 'Edit',
submenu: [
{ role: 'undo' },
{ role: 'redo' },
{ type: 'separator' },
{ role: 'cut' },
{ role: 'copy' },
{ role: 'paste' },
...(isMac ? [
//{ role: 'pasteAndMatchStyle' },
//{ role: 'delete' },
{ role: 'selectAll' },
{ type: 'separator' },
{
label: 'Speech',
submenu: [
{ role: 'startspeaking' },
{ role: 'stopspeaking' }
]
}
] : [
{ role: 'delete' },
{ type: 'separator' },
{ role: 'selectAll' }
])
]
},
// { role: 'viewMenu' }
{
label: 'View',
submenu: [
{ role: 'reload' },
{ role: 'forcereload' },
{ role: 'toggledevtools' },
{ type: 'separator' },
{ role: 'resetzoom' },
{ role: 'zoomin' },
{ role: 'zoomout' },
{ type: 'separator' },
{ role: 'togglefullscreen' }
]
},
// { role: 'windowMenu' }
{
label: 'Window',
submenu: [
{ role: 'minimize' },
{ role: 'zoom' },
...(isMac ? [
{ type: 'separator' },
{ role: 'front' },
{ type: 'separator' },
{ role: 'window' }
] : [
{ role: 'close' }
])
]
},
{
label: 'Insert',
submenu: [
{
label: 'Text Box',
accelerator:'CommandOrControl+T',
click(item, focusedWindow) {
//const win = require('electron').remote.getCurrentWindow();
focusedWindow.webContents.executeJavaScript(`addText();`);

}
},
{
label: 'Inline equation',
accelerator:'CommandOrControl+E',
click(item, focusedWindow) {
//const win = require('electron').remote.getCurrentWindow();
focusedWindow.webContents.executeJavaScript(`addEquation();`);

}
},
{
label: 'Display equation',
accelerator:'CommandOrControl+D',
click(item, focusedWindow) {
//const win = require('electron').remote.getCurrentWindow();
focusedWindow.webContents.executeJavaScript(`addDisplayEquation();`);

}
},
{
label: 'Line break',
accelerator:'CommandOrControl+L',
click(item, focusedWindow) {
//const win = require('electron').remote.getCurrentWindow();
focusedWindow.webContents.executeJavaScript(`addBreak();`);

}
},
{
label: 'Practice problem',
accelerator:'CommandOrControl+P',
click(item, focusedWindow) {
//const win = require('electron').remote.getCurrentWindow();
focusedWindow.webContents.executeJavaScript(`addProblem();`);

}
}
]
},
{
role: 'help',
submenu: [
{
label: 'Learn More',
click: async () => {
const { shell } = require('electron')
await shell.openExternal('https://electronjs.org')
}
}
]
}
]

const menu = Menu.buildFromTemplate(template);
Menu.setApplicationMenu(menu);
44 changes: 24 additions & 20 deletions v2/make.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ var root = document.querySelector("#root");
var info = [{type:"none"}];
var uinfo = [];
var lastFocused={id:"e0"};
var pnum=0
var pnum=0;
var soltext;
function addEquation(){
n = document.createElement("SPAN");
if(!!document.getElementById(lastFocused.id)){
Expand Down Expand Up @@ -173,17 +174,19 @@ if(!!document.getElementById(lastFocused.id)){
$(n).insertAfter("#"+lastFocused.id);}
else{$(n).insertAfter("#"+(lastFocused.id-1));}
n.className = "card-body card no-def my-3 pop";
n.innerHTML = `<p><span id='q${info.length}' class='form-control-sm answerb' ></span><div id="h1${info.length}"><div class="btn-group mb-5" role="group"><button type="button" class="btn btn-secondary" onclick="addEquation2('h1${info.length}');">Math</button>
<button type="button" class="btn btn-secondary" onclick="addDisplayEquation2('h1${info.length}');">Display Math</button>
<button type="button" id="txt" class="btn btn-secondary" onclick="addText2('h1${info.length}');">Text</button>
</div></div><div id="h2${info.length}"><div class="btn-group mb-5" role="group">
<button type="button" class="btn btn-secondary" onclick="addEquation2('h2${info.length}');">Math</button>
<button type="button" class="btn btn-secondary" onclick="addDisplayEquation2('h2${info.length}');">Display Math</button>
<button type="button" class="btn btn-secondary" onclick="addText2('h2${info.length}');">Text</button></div></div><div id="s${info.length}"><div class="btn-group mb-5" role="group"><button type="button" class="btn btn-secondary" onclick="addEquation2('s${info.length}');">Math</button>
<button type="button" class="btn btn-secondary" onclick="addDisplayEquation2('s${info.length}');">Display Math</button>
<button type="button" id="txt" class="btn btn-secondary" onclick="addText2('s${info.length}');">Text</button>
<button type="button" id="lb" class="btn btn-secondary" onclick="addBreak2('s${info.length}');">Line break</button></div></div></p>`
n.innerHTML = `<p><span id='q${info.length}' class='form-control-sm answerb' ></span>
<div class="form-group">
<label for="h1${info.length}">Hint 1</label>
<textarea class="form-control" id="h1${info.length}" rows="3"></textarea>
</div>
<div class="form-group">
<label for="h2${info.length}">Hint 2</label>
<textarea class="form-control" id="h2${info.length}" rows="3"></textarea>
</div>
<div class="form-group">
<label for="s${info.length}">Solution</label>
<textarea class="form-control" id="s${info.length}" rows="3"></textarea>
</div></p>`;
n.id = "e"+info.length;
n.onclick='lastFocused=this;'
var answerMathField = MQ.MathField(document.querySelector("#q"+info.length), {
Expand All @@ -194,11 +197,12 @@ if(!!document.getElementById(lastFocused.id)){
elem: document.querySelector("#e"+l),
qfield:answerMathField,
pnum:pnum,
h1field:{info:[]},
h2field:{info:[]},
sfield:{info:[]}
h1field:("h1"+l),
h2field:("h2"+l),
sfield:("s"+l)

});
console.log(info);
//have a form to fill out, can put mathquills in for answers, hint space (2) and solution space.
}

Expand Down Expand Up @@ -252,18 +256,18 @@ final += "</p><p>"
}
if (obj.type =="problem"){
//console.log(obj.qfield);
console.log(obj.h2field);
var soltext = make(obj.sfield.info);
//console.log(obj.h2field);
//soltext = make(obj.sfield.info);
final += `</p><li class="card card-body no-def my-3 pop">
<p>$\\displaystyle{ ${obj.qfield.latex()} }$ <span id="answer${obj.pnum}" class="form-control-sm answerb"></span><svg id="tu${obj.pnum}" class="bi bi-hand-thumbs-up" width="2em" height="2em" style="display:none" viewBox="0 0 16 16" fill="var(--success)" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd"
d="M13.854 3.646a.5.5 0 0 1 0 .708l-7 7a.5.5 0 0 1-.708 0l-3.5-3.5a.5.5 0 1 1 .708-.708L6.5 10.293l6.646-6.647a.5.5 0 0 1 .708 0z"/>
</svg></p>
<!--Hints--><details><summary class="btn btn-outline-success btn-sm mt-2">Hint</summary> ${make(obj.h1field.info)}</details>
<details><summary class="btn btn-outline-success btn-sm mt-2">Hint</summary> ${make(obj.h2field.info)}</details>
<!--Hints--><details><summary class="btn btn-outline-success btn-sm mt-2">Hint</summary> ${document.getElementById(obj.h1field).value}</details>
<details><summary class="btn btn-outline-success btn-sm mt-2">Hint</summary> ${document.getElementById(obj.h2field).value}</details>
<!--Solution--><details><summary class="btn btn-sm btn-outline-success mt-2">Show/Hide Solution</summary>
${soltext}
${document.getElementById(obj.sfield).value}
</details>
</li><p>`
}
Expand Down

0 comments on commit 0231dc8

Please sign in to comment.