Skip to content

Commit

Permalink
Merge pull request #8 from kaplanPRO/development
Browse files Browse the repository at this point in the history
version 0.4.2
  • Loading branch information
csengor authored Mar 15, 2021
2 parents 4cabac2 + a2d6d59 commit 989e110
Show file tree
Hide file tree
Showing 9 changed files with 158 additions and 78 deletions.
2 changes: 1 addition & 1 deletion 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.4.0",
"version": "0.4.2",
"description": "An open-source CAT tool.",
"homepage": "https://kaplan.pro",
"main": "src/main.js",
Expand Down
1 change: 1 addition & 0 deletions app/src/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ function lookupSegment(sourceSegment) {

tr.onclick = function() {
activeSegment.getElementsByTagName("td")[1].innerHTML = this.getElementsByTagName("td")[1].innerHTML;
activeSegment.className = "draft";
}
tMHitsTable.append(tr);
})
Expand Down
19 changes: 8 additions & 11 deletions app/src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ footer {
grid-row: 3;
padding: 0.25em;
}
div.kdb-slice {
text-align: center;
}
div.note span {
float: right;
cursor: pointer;
Expand Down Expand Up @@ -154,7 +157,7 @@ main#overlay {
vertical-align: middle;
width: 100vw;
}
main#tb-view div, main#tm-view div {
main#tb-view div:not(.kdb-slice), main#tm-view div:not(.kdb-slice) {
overflow-y: scroll;
max-width: 100%;
}
Expand Down Expand Up @@ -200,31 +203,25 @@ table#tb-hits, table#tm-hits {
grid-column: 1/3;
grid-row: 2;
}
table#tb-hits, table#tb-table, table#tm-hits, table#tm-table, table.segments-table {
table#tb-hits, table#tb-table, table#tm-hits, table#tm-table, table#tb-table, table#tm-table, table.segments-table {
overflow-wrap: break-word;
table-layout: fixed;
}
table#tb-hits th, table#tm-hits th, table.segments-table th {
table#tb-hits th, table#tm-hits th, table#tb-table th, table#tm-table th, table.segments-table th {
border-bottom: 1px solid #c5c5c5;
border-top: 1px solid #c5c5c5;
user-select: none;
width: 4%;
}
table#tb-hits td, table#tm-hits td, table.segments-table td.source, table.segments-table td.target {
table#tb-hits td, table#tm-hits td, table#tb-table td, table#tm-table td, table.segments-table td.source, table.segments-table td.target {
border-bottom: 1px solid #c5c5c5;
border-left: 1px solid #c5c5c5;
border-top: 1px solid #c5c5c5;
user-select: text;
}
table#tb-hits td, table#tm-hits td {
table#tb-hits td, table#tm-hits td, table#tb-table td, table#tm-table td {
width: 48%;
}
table#tb-table td, table#tm-table td {
border-bottom: 1px solid #c5c5c5;
border-top: 1px solid #c5c5c5;
padding: 0.5rem;
width: 50%;
}
table.segments-table td.source, table.segments-table td.target {
width: 35%;
}
Expand Down
8 changes: 8 additions & 0 deletions app/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@
</tr>
</table>
</div>
<div class="kdb-slice">
<hr>
<input id="tm-first-row" type="number"/> - <input id="tm-last-row" type="number"/> / <span id="tm-entry-count">-</span>
</div>
</main>
<header id="tb-header">
<button id="btn-create-tb">Create TB</button>
Expand All @@ -119,6 +123,10 @@
</tr>
</table>
</div>
<div class="kdb-slice">
<hr>
<input id="tb-first-row" type="number"/> - <input id="tb-last-row" type="number"/> / <span id="tb-entry-count">-</span>
</div>
</main>
<header id="mysql-header">
<button id="btn-create-cloud-tm">Create Cloud TM</button>
Expand Down
101 changes: 86 additions & 15 deletions app/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function fireOnReady() {
}, 1000);

// Fetches the entries in a kdb file
function fetchEntries(kdb_role, kdb_id) {
function fetchEntries(kdb_role, kdb_id, firstRow=0, lastRow=100) {
let entries;
let entry;
let entryKeys;
Expand All @@ -54,23 +54,24 @@ function fireOnReady() {

kDBEntries.innerHTML = null;

tr = document.createElement("tr");

th = document.createElement("th");
th.textContent = "Source";
tr.appendChild(th);

th = document.createElement("th");
th.textContent = "Target";
tr.appendChild(th);
if (firstRow !== 0) {
firstRow = firstRow - 1;
}

kDBEntries.appendChild(tr);
if (lastRow === 0 || lastRow > entryKeys.length) {
lastRow = entryKeys.length;
}

for (i = 0; i < entryKeys.length; i++) {
for (i = firstRow; i < lastRow; i++) {
entry = entries[entryKeys[i]];

tr = document.createElement("tr");

th = document.createElement("th");
th.id = entry.id;
th.textContent = entry.id;
tr.appendChild(th);

td = document.createElement("td");
td.textContent = entry.source;
tr.appendChild(td);
Expand All @@ -82,6 +83,14 @@ function fireOnReady() {

kDBEntries.appendChild(tr);
}
let entry_count_message;
if (entryKeys.length === 1) { entry_count_message = "1 entry"}
else { entry_count_message = entryKeys.length + " entries"}
if (kdb_role === "tm") {
document.getElementById("tm-entry-count").textContent = entry_count_message;
} else {
document.getElementById("tb-entry-count").textContent = entry_count_message;
}
}
}

Expand Down Expand Up @@ -178,7 +187,7 @@ function fireOnReady() {
console.log("Projects fetched.")
}
else if (this.readyState == 4 && this.status != 200) {
console.log("Projects not fetched. Trying again in 2 seconds.")
console.error("Projects not fetched. Trying again in 2 seconds.")
setTimeout(() => {
fetchProjects();
}, 2000)
Expand Down Expand Up @@ -503,9 +512,9 @@ function fireOnReady() {
console.log(role.toUpperCase() + "s fetched.");
}
else if (this.readyState == 4 && this.status != 200) {
console.log(role.toUpperCase() + "s not fetched. Trying again in 2 seconds.")
console.error(role.toUpperCase() + "s not fetched. Trying again in 2 seconds.")
setTimeout(() => {
fetchKDBs(role, tableHeader);
fetchKDBs(role, tableHeader, kDBtable);
}, 2000)
}
}
Expand Down Expand Up @@ -753,6 +762,68 @@ function fireOnReady() {
}

window.fetchSegments = fetchSegments;

document.getElementById("tm-first-row").onkeyup = function() {
if (activeTM == null) {
return
} else if (this.value === "") {
firstRow = 0;
} else {
firstRow = parseInt(this.value);
}
if (document.getElementById("tm-last-row").value === "") {
lastRow = 0
} else {
lastRow = parseInt(document.getElementById("tm-last-row").value);
}
fetchEntries("tm", activeTM.id, firstRow, lastRow);
}
document.getElementById("tm-last-row").onkeyup = function() {
if (activeTM == null) {
return
} else if (this.value === "") {
lastRow = 0;
} else {
lastRow = parseInt(this.value);
}
if (document.getElementById("tm-first-row").value === "") {
firstRow = 0;
} else {
firstRow = parseInt(document.getElementById("tm-first-row").value);
}
fetchEntries("tm", activeTM.id, firstRow, lastRow);
}

document.getElementById("tb-first-row").onkeyup = function() {
if (activeTB == null) {
return
} else if (this.value === "") {
firstRow = 0;
} else {
firstRow = parseInt(this.value);
}
if (document.getElementById("tb-last-row").value === "") {
lastRow = 0
} else {
lastRow = parseInt(document.getElementById("tb-last-row").value);
}
fetchEntries("tb", activeTB.id, firstRow, lastRow);
}
document.getElementById("tb-last-row").onkeyup = function() {
if (activeTB == null) {
return
} else if (this.value === "") {
lastRow = 0;
} else {
lastRow = parseInt(this.value);
}
if (document.getElementById("tb-first-row").value === "") {
firstRow = 0;
} else {
firstRow = parseInt(document.getElementById("tb-first-row").value);
}
fetchEntries("tb", activeTB.id, firstRow, lastRow);
}
};

if (document.readyState === "complete") {
Expand Down
11 changes: 5 additions & 6 deletions app/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ const fs = require('fs');
const path = require('path');
const { exec, spawn, spawnSync } = require('child_process');

let backendServer;

// Handle creating/removing shortcuts on Windows when installing/uninstalling.
if (require('electron-squirrel-startup')) { // eslint-disable-line global-require
app.quit();
Expand Down Expand Up @@ -39,9 +41,8 @@ else if (fs.existsSync(path.join(app.getAppPath(), 'backend')))

process.env.KAPLAN_SETTINGS = JSON.stringify(settingsJSON);

const child = spawn(pathToBackend,
['runserver'],
{detached: true});
backendServer = spawn(pathToBackend,
['runserver', '--noreload']);
}

let pathToIcon;
Expand Down Expand Up @@ -75,9 +76,7 @@ const createWindow = () => {
app.on('ready', createWindow);

// This method will be called by app.quit().
app.on('before-quit', () => {
if (fs.existsSync(path.join(app.getAppPath(), 'backend'))) {process.kill(-child.pid)}
});
app.on('before-quit', () => { backendServer.kill() });

// Quit when all windows are closed.
app.on('window-all-closed', () => {
Expand Down
Loading

0 comments on commit 989e110

Please sign in to comment.