Skip to content

Commit

Permalink
Merge pull request #7 from kaplanPRO/development
Browse files Browse the repository at this point in the history
version 0.4.0
  • Loading branch information
csengor authored Feb 23, 2021
2 parents b0d13eb + 7c9a61e commit 4cabac2
Show file tree
Hide file tree
Showing 12 changed files with 605 additions and 131 deletions.
4 changes: 2 additions & 2 deletions app/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "kaplan-desktop",
"productName": "Kaplan Desktop",
"version": "0.3.3",
"version": "0.4.0",
"description": "An open-source CAT tool.",
"homepage": "https://kaplan.pro",
"main": "src/main.js",
Expand Down Expand Up @@ -63,6 +63,6 @@
"@electron-forge/maker-rpm": "6.0.0-beta.54",
"@electron-forge/maker-squirrel": "6.0.0-beta.54",
"@electron-forge/maker-zip": "6.0.0-beta.54",
"electron": "^11.2.3"
"electron": "^11.3.0"
}
}
106 changes: 104 additions & 2 deletions app/src/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,112 @@ function selectSegmentForMerge(segmentHeader) {
mergeButton.disabled = true;
}
}
function openCommentForm(buttonElement) {
buttonElement.classList.add("hidden");

noteDiv = document.createElement("div");
noteDiv.classList.add("note");

noteForm = document.createElement("form");

noteLabel = document.createElement("label");
noteLabel.setAttribute("for", "comment");
noteLabel.textContent = "Comment:";
noteForm.appendChild(noteLabel);

noteTextarea = document.createElement("textarea");
noteTextarea.setAttribute("name", "comment");
noteForm.appendChild(noteTextarea);

submitButton = document.createElement("button");
submitButton.setAttribute("type", "submit");
submitButton.textContent = "Submit";
noteForm.appendChild(submitButton);

cancelButton = document.createElement("button");
cancelButton.className = "cancel";
cancelButton.setAttribute("type", "button");
cancelButton.textContent = "Cancel";
cancelButton.onclick = function() {
this.parentNode.parentNode.parentNode.getElementsByTagName("button")[0].classList.remove("hidden");
this.parentNode.parentNode.remove();
}
noteForm.appendChild(cancelButton);

noteDiv.appendChild(noteForm);
buttonElement.parentNode.appendChild(noteDiv);

noteForm.onsubmit = function(e) {
e.preventDefault();
noteFormData = new FormData(noteForm);
noteFormData.append("segment", this.parentNode.parentNode.parentNode.id);
noteFormData.append("author", username);
noteFormData.append("task", "add_comment");

if (noteFormData.get("comment") === "") {
this.parentNode.parentNode.getElementsByTagName("button")[0].classList.remove("hidden");
this.parentNode.remove();

return false;
}

let xhttp = new XMLHttpRequest();
let queryURL = "http://127.0.0.1:8000/project/"
+ filesView.getAttribute("cur-p-id")
+ "/file/"
+ editorView.getAttribute("cur-f-id");

xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
console.log("Comment submitted succesfully!");

noteDiv = document.createElement("div");
noteDiv.classList.add("note");

noteP = document.createElement("p");
noteP.textContent = noteFormData.get("comment");
noteDiv.appendChild(noteP);

noteForm.parentNode.parentNode.appendChild(noteDiv);

noteForm.parentNode.remove();
}
}

xhttp.open("POST", queryURL, true);
xhttp.send(noteFormData);

}
}
function resolveComment(closeSpan) {
noteDiv = closeSpan.parentNode;

let noteFormData = new FormData();
noteFormData.append("segment", noteDiv.getAttribute("segment"));
noteFormData.append("comment", noteDiv.id);
noteFormData.append("author", username);
noteFormData.append("task", "resolve_comment");

let xhttp = new XMLHttpRequest();
let queryURL = "http://127.0.0.1:8000/project/"
+ filesView.getAttribute("cur-p-id")
+ "/file/"
+ editorView.getAttribute("cur-f-id");

xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
noteDiv.remove();
}
}

xhttp.open("POST", queryURL, true);
xhttp.send(noteFormData);

}
function submitSegment(target_cell, segment_state) {
paragraph_no = target_cell.parentNode.getAttribute("p-id");
segment_no = target_cell.parentNode.getAttribute("id");
source_segment = "<source>" + target_cell.parentNode.getElementsByClassName("source")[0].innerHTML.replace(/<ph contenteditable="false">\\n<\/ph>/g, "\n") + "</source>";
source_segment = "<source>" + target_cell.parentNode.getElementsByClassName("source")[0].innerHTML.replace(/&nbsp;/g, " ").replace(/<ph contenteditable="false">\\n<\/ph>/g, "\n") + "</source>";
target_segment = target_cell.innerHTML.replace(/&nbsp;/g, " ").replace(/<ph contenteditable="false">\\n<\/ph>/g, "\n");

if (target_segment == "") {
Expand All @@ -90,6 +191,7 @@ function submitSegment(target_cell, segment_state) {
+ "/file/"
+ editorView.getAttribute("cur-f-id");
let segmentForm = new FormData();
segmentForm.append("editor_mode", editorMode);
segmentForm.append("segment_state", segment_state);
segmentForm.append("source_segment", source_segment);
segmentForm.append("target_segment", target_segment);
Expand Down Expand Up @@ -119,7 +221,7 @@ function lookupSegment(sourceSegment) {
+ editorView.getAttribute("cur-f-id")
+ "?task=lookup"
+ "&source_segment="
+ encodeURIComponent("<source>" + sourceSegment.innerHTML.replace(/<ph contenteditable="false">\\n<\/ph>/g, "\n") + "</source>");
+ encodeURIComponent("<source>" + sourceSegment.innerHTML.replace(/&nbsp;/g, " ").replace(/<ph contenteditable="false">\\n<\/ph>/g, "\n") + "</source>");

const parser = new DOMParser();

Expand Down
209 changes: 171 additions & 38 deletions app/src/index-preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,15 @@ window.openFileContextMenu = (e, fileId, filePath, canGenerateTargetFile) => {
e.preventDefault();

const fileMenu = new Menu();
fileMenu.append(new MenuItem({ label: 'Open in translation mode', click() { fetchSegments(filesView.getAttribute('cur-p-id'), fileId, canGenerateTargetFile, "translation") } }));
fileMenu.append(new MenuItem({ label: 'Open in review mode', click() { fetchSegments(filesView.getAttribute('cur-p-id'), fileId, canGenerateTargetFile, "review") } }));
fileMenu.append(new MenuItem({ type: 'separator' }));
if (canGenerateTargetFile === 'true') {
fileMenu.append(new MenuItem({ label: 'Generate target translation', click() { getTargetTranslation(fileId) } }));
} else {
fileMenu.append(new MenuItem({ label: 'Generate target translation', enabled: false }));
}
fileMenu.append(new MenuItem({ type: 'separator' }));
fileMenu.append(new MenuItem({ label: 'Show in file explorer', click() { shell.showItemInFolder(filePath) } }));

fileMenu.popup({ window: indexWindow });
Expand Down Expand Up @@ -166,53 +172,180 @@ window.openKDBContextMenu = (e, kDBPath, kDBId) => {
kDBMenu.popup({ window: indexWindow });
}

window.getDatetimeString = function(datetimeISOFormat) {
function addZero(i) {
if (i < 10) {
i = "0" + i;
}
return i;
}

datetime = new Date(datetimeISOFormat);
datetimeString = datetime.getFullYear()
+ "-"
+ addZero((datetime.getMonth()+1))
+ "-"
+ addZero(datetime.getDate())
+ " "
+ addZero(datetime.getHours())
+ ":"
+ addZero(datetime.getMinutes());

return datetimeString
}

window.viewProjectReport = function(tableRow) {
reportTable = document.getElementById("project-report");
reportTable.innerHTML = "<tr><th class=\"name\"></th><th>Repetitions</th><th>100%</th><th>95%-99%</th><th>85%-94%</th><th>75%-84%</th><th>50%-74%</th><th>New</th><th>Total</th></tr>";

reportJSON = JSON.parse(tableRow.getAttribute("json"));
if (activeReport) {
activeReport.classList.remove("active");
}
tableRow.classList.add("active");
activeReport = tableRow;
Object.keys(reportJSON).forEach(function(fileName) {
tr = document.createElement("tr");

td = document.createElement("td");
td.className = "name"
td.textContent = fileName;
tr.appendChild(td);

td = document.createElement("td");
td.textContent = reportJSON[fileName]["Repetitions"];
tr.appendChild(td);

td = document.createElement("td");
td.textContent = reportJSON[fileName]["100%"];
tr.appendChild(td);

td = document.createElement("td");
td.textContent = reportJSON[fileName]["95%-99%"];
tr.appendChild(td);

td = document.createElement("td");
td.textContent = reportJSON[fileName]["85%-94%"];
tr.appendChild(td);

td = document.createElement("td");
td.textContent = reportJSON[fileName]["75%-84%"];
tr.appendChild(td);

td = document.createElement("td");
td.textContent = reportJSON[fileName]["50%-74%"];
tr.appendChild(td);

td = document.createElement("td");
td.textContent = reportJSON[fileName]["New"];
tr.appendChild(td);

td = document.createElement("td");
td.textContent = reportJSON[fileName]["Total"];
tr.appendChild(td);

reportTable.appendChild(tr);
})
}

function fireOnReady() {
const mYSQLTable = document.getElementById('mysql-table')

let connection = mysql.createConnection(settingsJSON.mysql);
if (settingsJSON.mysql) {
let connection = mysql.createConnection(settingsJSON.mysql);

connection.connect(function(error) {
connection.connect(function(error) {
if (error) {
console.error(error);
alert(error);
console.error(error);
alert(error);
} else {
document.getElementById('btn-mysql-view').disabled = false;
mYSQLTable.innerHTML = null;
tr = document.createElement('tr');
tr.innerHTML = '<th class="name">Cloud TM</th><th>Source Language</th><th>Target Language</th>'
mYSQLTable.appendChild(tr);

connection.query('SELECT * FROM kaplan_tables', function (error, result, fields) {
if (error) {
console.error(error)
alert(error)
} else if (result.length === 0) {
document.getElementById('btn-mysql-view').disabled = false;
mYSQLTable.innerHTML = null;
tr = document.createElement('tr');
tr.innerHTML = '<th class="name">Cloud TM</th><th>Source Language</th><th>Target Language</th>'
mYSQLTable.appendChild(tr);

connection.query('SELECT * FROM kaplan_tables', function (error, result, fields) {
if (error) {
console.error(error)
alert(error)
} else if (result.length === 0) {
tr = document.createElement('tr');
tr.innerHTML = '<td colspan="3">No tables found</td>'
mYSQLTable.appendChild(tr);
} else {
result.map(function(row) {
tr = document.createElement('tr');
tr.setAttribute('cloud-tm-id', row.id);

td = document.createElement('td');
td.textContent = row.name;
tr.appendChild(td);

td = document.createElement('td');
td.textContent = row.source;
tr.appendChild(td);

td = document.createElement('td');
td.textContent = row.target;
tr.appendChild(td);

mYSQLTable.appendChild(tr);
})
}
})
}
});
}

document.getElementById('btn-analyze-files').onclick = function() {
this.disabled = 'true';
projectId = filesView.getAttribute('cur-p-id');
let formData = new FormData();
formData.append('task', 'analyze_files');

let xhttp = new XMLHttpRequest();

xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
if (projectId === filesView.getAttribute('cur-p-id')) {
document.getElementById('btn-analyze-files').disabled = null;
responseJSON = JSON.parse(this.responseText);

projectReportsTable = document.getElementById('reports-table').tBodies[0];
rows = projectReportsTable.getElementsByTagName('tr');
lastRow = rows.item(rows.length-1);
if (lastRow.innerHTML === '<td>-</td>') {
lastRow.remove();
}
reportId = Object.keys(responseJSON)[0];
report = responseJSON[reportId];

tr = document.createElement('tr');
tr.innerHTML = '<td colspan="3">No tables found</td>'
mYSQLTable.appendChild(tr);
} else {
result.map(function(row) {
tr = document.createElement('tr');
tr.setAttribute('cloud-tm-id', row.id);

td = document.createElement('td');
td.textContent = row.name;
tr.appendChild(td);

td = document.createElement('td');
td.textContent = row.source;
tr.appendChild(td);

td = document.createElement('td');
td.textContent = row.target;
tr.appendChild(td);

mYSQLTable.appendChild(tr);
})
tr.id = reportId;
tr.setAttribute('json', report.json);
tr.ondblclick = function() {
viewProjectReport(this);
}

td = document.createElement('td');
td.textContent = getDatetimeString(report.timestamp);
tr.appendChild(td);

if (projectReportsTable.getElementsByTagName('tr').length > 1) {
projectReportsTable.insertBefore(tr,
projectReportsTable.getElementsByTagName('tr')[1]);
} else {
projectReportsTable.appendChild(tr);
}

}
})
}
}
});

xhttp.open('POST', 'http://127.0.0.1:8000/project/' + filesView.getAttribute("cur-p-id"))
xhttp.send(formData);
}

document.getElementById('btn-create-cloud-tm').onclick = () => {
const newCloudTMWindow = new BrowserWindow({
Expand Down
Loading

0 comments on commit 4cabac2

Please sign in to comment.