Skip to content

Commit

Permalink
Add Project Settings view
Browse files Browse the repository at this point in the history
This view is accessible in the Files view and allows users to change the 
TMs and TBs associated with projects
  • Loading branch information
csengor committed Nov 5, 2021
1 parent e2c3d2d commit 3f4c3f8
Show file tree
Hide file tree
Showing 5 changed files with 164 additions and 5 deletions.
7 changes: 5 additions & 2 deletions app/src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,13 @@ header#projects-header, header#settings {
input {
padding: 0.25em;
}
main#editor-view, main#files-view, main#mysql-view, main#projects-view, main#tb-view, main#tm-view, main#overlay {
main#editor-view, main#files-view, main#mysql-view, main#projects-view, main#project-settings-view, main#tb-view, main#tm-view, main#overlay {
background-color: #f5f5f5;
grid-column: 2;
grid-row: 2;
overflow: hidden;
}
main#editor-view, main#files-view, main#mysql-view, main#tb-view, main#tm-view, main#overlay {
main#editor-view, main#files-view, main#mysql-view, main#project-settings-view, main#tb-view, main#tm-view, main#overlay {
display: none;
}
main#editor-view, main#tb-view, main#tm-view {
Expand All @@ -161,6 +161,9 @@ main#overlay {
top: 0px;
width: 100vw;
}
main#project-settings-view table {
width: auto;
}
main#projects-view {
overflow-y: scroll;
}
Expand Down
27 changes: 27 additions & 0 deletions app/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
<button id="btn-create-return-project-package">Create Return Package</button>
<button id="btn-update-from-package">Update From Package</button>
<button id="btn-analyze-files">Analyze</button>
<button id="btn-project-settings">Settings</button>
</header>
<main id="files-view">
<div>
Expand Down Expand Up @@ -67,6 +68,32 @@
</div>
</div>
</main>
<header id="project-settings-header"></header>
<main id="project-settings-view">
<form id="form-project-settings">
<table>
<tr>
<th>
<label for="tm">Translation Memories</label>
</th>
<td>
<select id="select-project-settings-tm" name="tm" multiple></select>
</td>
</tr>
<tr>
<th>
<label for="td">Termbases</label>
</th>
<td>
<select id="select-project-settings-tb" name="tb" multiple></select>
</td>
</tr>
<tr>
<th></th><td><button type="submit" name="button">Update</button></td>
</tr>
</table>
</form>
</main>
<header id="editor-header">
<button id="btn-segment-merge" disabled>Merge</button>
<button id="btn-save-progress" disabled>Save</button>
Expand Down
89 changes: 86 additions & 3 deletions app/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,10 @@ function fireOnReady() {
document.getElementById("btn-mysql-view").onclick = function() {
toggleView("mysql-view", "block", "mysql-header", "btn-mysql-view");
}
document.getElementById("btn-project-settings").onclick = function() {
toggleView("project-settings-view", "block", "project-settings-header", null);
getRelevantKDBs();
}

function setFooter() {
let footerString;
Expand All @@ -614,13 +618,92 @@ function fireOnReady() {
function toggleView(viewId, viewDisplay, headerId, buttonId) {
activeView.style.display = "none";
activeHeader.style.display = "none";
activeButton.classList.remove("active");
if (activeButton)
{
activeButton.classList.remove("active");
}
activeView = document.getElementById(viewId);
activeView.style.display = viewDisplay;
activeHeader = document.getElementById(headerId);
activeHeader.style.display = "block";
activeButton = document.getElementById(buttonId);
activeButton.classList.add("active");
if (buttonId)
{
activeButton.classList.add("active");
}
}

function getRelevantKDBs() {
let xhttp = new XMLHttpRequest();

let queryURL = "http://127.0.0.1:8000/project/"
+ filesView.getAttribute("cur-p-id")
+ "?task=get_relevant_kdbs";

xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
relevantKDBs = JSON.parse(this.responseText);
let projectTMSelect = document.getElementById("select-project-settings-tm");
projectTMSelect.innerHTML = null;
let projectTBSelect = document.getElementById("select-project-settings-tb");
projectTBSelect.innerHTML = null;
[...Object.keys(relevantKDBs["tm"])].forEach((key, i) => {
let option = new Option(relevantKDBs["tm"][key]["name"], key);
projectTMSelect.appendChild(option);
option.selected = relevantKDBs["tm"][key]["selected"];
});
[...Object.keys(relevantKDBs["tb"])].forEach((key, i) => {
let option = new Option(relevantKDBs["tb"][key]["name"], key);
projectTBSelect.appendChild(option);
option.selected=relevantKDBs["tb"][key]["selected"];
});
}
}

xhttp.open("GET", queryURL, true);
xhttp.send();
}

document.getElementById("form-project-settings").onsubmit = function(e) {
e.preventDefault();

let xhttp = new XMLHttpRequest();

let parameters = new FormData();
parameters.append("task", "set_language_resources");

let tMs = "";
[...this['tm'].selectedOptions].forEach((option, i) => {
if (tMs != "")
{
tMs += ";"
}
tMs += option.value
})
if (tMs != "")
{
parameters.append("tm", tMs);
}

let tBs = "";
[...this['tb'].selectedOptions].forEach((option, i) => {
if (tBs != "")
{
tBs += ";"
}
tBs += option.value
})
if (tBs != "")
{
parameters.append("tb", tBs);
}

let queryURL = "http://127.0.0.1:8000/project/"
+ filesView.getAttribute("cur-p-id")
+ "?task=set_language_resources";

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

document.getElementById("toggle-sidebar").onclick = function() {
Expand Down Expand Up @@ -821,7 +904,7 @@ function fireOnReady() {
window.importProject();
}

document.forms[0].onsubmit = function(e) {
document.getElementById("project-package").onsubmit = function(e) {
e.preventDefault();
let filesToPackage = [];

Expand Down
16 changes: 16 additions & 0 deletions backend/api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,19 @@ def get_target_direction(self):
return self.target_direction
else:
return LanguageProfile.get_language_direction(self.target_language)

def get_relevant_kdbs(self):
project_kdbs = self.language_resources.all()
relevant_kdbs_dict = {'tm':{}, 'tb':{}}
for relevant_kdb in KaplanDatabase.objects \
.filter(source_language=self.source_language) \
.filter(target_language=self.target_language):

relevant_kdb_dict = {
'name': relevant_kdb.title,
'selected': relevant_kdb in project_kdbs
}

relevant_kdbs_dict[relevant_kdb.role][relevant_kdb.id] = relevant_kdb_dict

return relevant_kdbs_dict
30 changes: 30 additions & 0 deletions backend/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,9 +530,39 @@ def project_view(request, project_id):
request.POST['files'].split(';'))

return JsonResponse({'message': 'Target files updated.'})
elif request.POST.get('task') == 'set_language_resources':
kdbs = []
tms = request.POST.get('tm')
if tms:
for tm_i in tms.split(';'):
if tm_i == '':
continue
kdb = KaplanDatabase.objects.get(id=int(tm_i))
if (kdb.source_language == project.source_language
and kdb.target_language == project.target_language):
kdbs.append(kdb)

tbs = request.POST.get('tb')
if tbs:
for tb_i in tbs.split(';'):
if tb_i == '':
continue
kdb = KaplanDatabase.objects.get(id=int(tb_i))
if (kdb.source_language == project.source_language
and kdb.target_language == project.target_language):
kdbs.append(kdb)


project.language_resources.clear()
project.language_resources.add(*kdbs)
project.save()

return JsonResponse({'status': 'success'})
else:
if request.GET.get('task') == 'get_manifest':
return JsonResponse(project.get_project_metadata())
elif request.GET.get('task') == 'get_relevant_kdbs':
return JsonResponse(project.get_relevant_kdbs())
else:
files_dict = {}
reports_dict = {}
Expand Down

0 comments on commit 3f4c3f8

Please sign in to comment.