Commit 1ec4abf5 authored by remy's avatar remy
Browse files

-a

refactoring
parent 0bb92f3d
......@@ -3,123 +3,6 @@ var SELECTED_PACKAGES_COLOR = [];
var PREVIEW = "";
function showPackage(distribName) {
var distrib = distribName;
if(distribName == "Distribution") {
distrib = document.getElementById("selectedOS").value;
}
var str = document.getElementById("find"+distribName+"Packages").value;
var limit = document.getElementById("limit"+distribName).value;
if (str == "") {
document.getElementById("containPackages"+distribName).innerHTML = "";
return;
} else {
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest(); // code for IE7+, Firefox, Chrome, Opera, Safari
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); // code for IE6, IE5
}
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("containPackages"+distribName).innerHTML = this.responseText;
}
};
var patternName = document.getElementById("pattern"+distribName+"Name").checked;
var patternDescription = document.getElementById("pattern"+distribName+"Description").checked;
//xmlhttp.open("GET","get"+distribName+"Packages.php?distrib="+distrib+"&filter="+str+"&patternName="+patternName+"&patternDescription="+patternDescription+"&limit="+limit,true);
xmlhttp.open("GET","getPackages.php?distrib="+distrib+"&filter="+str+"&patternName="+patternName+"&patternDescription="+patternDescription+"&limit="+limit,true);
xmlhttp.send();
}
}
function generatePackageSelected(Pthis) {
var key = Pthis.dataset["psection"];
var data = [Pthis.dataset["pname"], Pthis.dataset["pversion"], key, Pthis.id];
if(key == "Distribution") {
data = [Pthis.dataset["pname"], Pthis.dataset["pversion"], document.getElementById("selectedOS").value, Pthis.id];
}
var newSelected = [];
if(Pthis.checked) {
var add = true;
for(var i = 0; i < SELECTED_PACKAGES[key].length; i++) {
if(SELECTED_PACKAGES[key][i][0] === Pthis.dataset["pname"]) {
add = false;
}
newSelected.push(SELECTED_PACKAGES[key][i]);
}
if(add) {
newSelected.push(data);
}
} else {
for(var i = 0; i < SELECTED_PACKAGES[key].length; i++) {
if (SELECTED_PACKAGES[key][i][0] === Pthis.dataset["pname"]) {
//nothing
} else {
newSelected.push(SELECTED_PACKAGES[key][i]);
}
}
}
SELECTED_PACKAGES[key] = newSelected;
gestionPackageSelected();
}
function gestionPackageSelected() {
var result = "";
for (var key in SELECTED_PACKAGES) {
var tab = SELECTED_PACKAGES[key];
for(var i = 0; i < tab.length; i++) {
result = result + "<tr><td><button type='button' data-pname='"+ tab[i][0] +"' data-pid = '"+ tab[i][3] +"' data-psection = '"+ tab[i][2] +"' onclick='removePackageButton(this)' class='btn btn-danger btn-sm'>x</button></td><td style=\"text-align: center;\"><span class=\"badge\" style=\"background-color: "+ SELECTED_PACKAGES_COLOR[key] + "; color: #fff;\" >"+ tab[i][2] +"</span></td><td>"+ tab[i][0] +"<span class=\"badge\" style=\"background-color: #2f3640; color: #FFFFFF; margin-left: 10px\" >"+ tab[i][1] +"</span></td></tr>";
}
}
document.getElementById("TableSelectedPackages").innerHTML = result;
}
function removePackageButton(Pthis) {
var newSelected = [];
var key = Pthis.dataset["psection"];
if(key == document.getElementById("selectedOS").value) {
key = "Distribution";
}
for(var i = 0; i < SELECTED_PACKAGES[key].length; i++) {
if (SELECTED_PACKAGES[key][i][0] === Pthis.dataset["pname"]) {
//nothing
if(document.getElementById(Pthis.dataset["pid"])) {
document.getElementById(Pthis.dataset["pid"]).checked = false;
}
} else {
newSelected.push(SELECTED_PACKAGES[key][i]);
}
}
SELECTED_PACKAGES[key] = newSelected;
gestionPackageSelected();
}
$( "#generateButton" ).click(function() {
if((SELECTED_PACKAGES["CRAN"].length > 0 || SELECTED_PACKAGES["Bioconductor"].length > 0 ) && document.getElementById("selectedR").value == 0) {
......@@ -134,24 +17,31 @@ $( "#generateButton" ).click(function() {
}
});
function downloadFile2(name, value) {
var filename = name;
function buildRecipe() {
var filename = document.getElementById("imageNameInput").value;
var isSingularity = document.getElementById("singularityRadio").checked;
var text = value;
var element = document.createElement('a');
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
element.setAttribute('download', filename);
if (filename === "") {
if (isSingularity) {
filename = "Singularity";
} else {
filename = "Dockerfile";
}
}
element.style.display = 'none';
document.body.appendChild(element);
if (isSingularity) {
alert("sudo singularity build ./" + filename);
} else {
alert("sudo docker build ./" + filename);
}
element.click();
document.body.removeChild(element);
}
function downloadFile() {
if(PREVIEW !== "") {
......@@ -183,29 +73,26 @@ function downloadFile() {
}
}
function buildRecipe() {
var filename = document.getElementById("imageNameInput").value;
function downloadFile2(name, value) {
var filename = name;
var isSingularity = document.getElementById("singularityRadio").checked;
if (filename === "") {
if (isSingularity) {
filename = "Singularity";
} else {
filename = "Dockerfile";
}
}
var text = value;
var element = document.createElement('a');
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
element.setAttribute('download', filename);
if (isSingularity) {
alert("sudo singularity build ./" + filename);
} else {
alert("sudo docker build ./" + filename);
}
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
}
function generate_container() {
PREVIEW = "";
......@@ -604,3 +491,149 @@ function generate_container() {
document.getElementById('containerPreview').focus();
}
function generatePackageSelected(Pthis) {
var key = Pthis.dataset["psection"];
var data = [Pthis.dataset["pname"], Pthis.dataset["pversion"], key, Pthis.id];
if(key == "Distribution") {
data = [Pthis.dataset["pname"], Pthis.dataset["pversion"], document.getElementById("selectedOS").value, Pthis.id];
}
var newSelected = [];
if(Pthis.checked) {
var add = true;
for(var i = 0; i < SELECTED_PACKAGES[key].length; i++) {
if(SELECTED_PACKAGES[key][i][0] === Pthis.dataset["pname"]) {
add = false;
}
newSelected.push(SELECTED_PACKAGES[key][i]);
}
if(add) {
newSelected.push(data);
}
} else {
for(var i = 0; i < SELECTED_PACKAGES[key].length; i++) {
if (SELECTED_PACKAGES[key][i][0] === Pthis.dataset["pname"]) {
//nothing
} else {
newSelected.push(SELECTED_PACKAGES[key][i]);
}
}
}
SELECTED_PACKAGES[key] = newSelected;
gestionPackageSelected();
}
function gestionPackageSelected() {
var result = "";
for (var key in SELECTED_PACKAGES) {
var tab = SELECTED_PACKAGES[key];
for(var i = 0; i < tab.length; i++) {
result = result + "<tr><td><button type='button' data-pname='"+ tab[i][0] +"' data-pid = '"+ tab[i][3] +"' data-psection = '"+ tab[i][2] +"' onclick='removePackageButton(this)' class='btn btn-danger btn-sm'>x</button></td><td style=\"text-align: center;\"><span class=\"badge\" style=\"background-color: "+ SELECTED_PACKAGES_COLOR[key] + "; color: #fff;\" >"+ tab[i][2] +"</span></td><td>"+ tab[i][0] +"<span class=\"badge\" style=\"background-color: #2f3640; color: #FFFFFF; margin-left: 10px\" >"+ tab[i][1] +"</span></td></tr>";
}
}
document.getElementById("TableSelectedPackages").innerHTML = result;
}
function removePackageButton(Pthis) {
var newSelected = [];
var key = Pthis.dataset["psection"];
if(key == document.getElementById("selectedOS").value) {
key = "Distribution";
}
for(var i = 0; i < SELECTED_PACKAGES[key].length; i++) {
if (SELECTED_PACKAGES[key][i][0] === Pthis.dataset["pname"]) {
//nothing
if(document.getElementById(Pthis.dataset["pid"])) {
document.getElementById(Pthis.dataset["pid"]).checked = false;
}
} else {
newSelected.push(SELECTED_PACKAGES[key][i]);
}
}
SELECTED_PACKAGES[key] = newSelected;
gestionPackageSelected();
}
function showFormContainer() {
if(PREVIEW !== "") {
var isSingularity = document.getElementById("singularityRadio").checked;
if(isSingularity) {
document.getElementById("typeContainer").value = "Singularity";
} else {
document.getElementById("typeContainer").value = "Docker";
}
document.getElementById("valueContainer").value = PREVIEW;
$('#modalSaveRecipe').modal();
} else {
alert("Generate once before publish file");
}
}
function showPackage(distribName) {
var distrib = distribName;
if(distribName == "Distribution") {
distrib = document.getElementById("selectedOS").value;
}
var str = document.getElementById("find"+distribName+"Packages").value;
var limit = document.getElementById("limit"+distribName).value;
if (str == "") {
document.getElementById("containPackages"+distribName).innerHTML = "";
return;
} else {
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest(); // code for IE7+, Firefox, Chrome, Opera, Safari
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); // code for IE6, IE5
}
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("containPackages"+distribName).innerHTML = this.responseText;
}
};
var patternName = document.getElementById("pattern"+distribName+"Name").checked;
var patternDescription = document.getElementById("pattern"+distribName+"Description").checked;
//xmlhttp.open("GET","get"+distribName+"Packages.php?distrib="+distrib+"&filter="+str+"&patternName="+patternName+"&patternDescription="+patternDescription+"&limit="+limit,true);
xmlhttp.open("GET","getPackages.php?distrib="+distrib+"&filter="+str+"&patternName="+patternName+"&patternDescription="+patternDescription+"&limit="+limit,true);
xmlhttp.send();
}
}
\ No newline at end of file
<?php
function printPanel($name) {
echo '
<br/>
<label for="find'.$name.'Packages">Find packages with pattern :</label>
<input type="email" class="form-control" id="find'.$name.'Packages">
<div class="form-check">
<input type="checkbox" class="form-check-input" id="pattern'.$name.'Name" checked>
<label class="form-check-label" for="pattern'.$name.'Name">Pattern on name</label>
</div>
<div class="form-check">
<input type="checkbox" class="form-check-input" id="pattern'.$name.'Description" checked>
<label class="form-check-label" for="pattern'.$name.'Description">Pattern on description</label>
</div>
<br/>
<div class="form-group">
<label for="limit'.$name.'" class="font-check-label">Max found :</label>
<select class="custom-select" id="limit'.$name.'">
<option value="5">5</option>
<option value="10" selected="selected">10</option>
<option value="25">25</option>
<option value="50">50</option>
<option value="100">100</option>
<option value="100">200</option>
<option value="1000000000">all</option>
</select>
</div>
<br/>
<button type="button" class="btn btn-primary" onclick="showPackage(\''.$name.'\')">Search</button>
<br/><br/>
<div id="containPackages'.$name.'">
</div>
';
}
\ No newline at end of file
......@@ -13,6 +13,7 @@
session_start ();
require_once "./dao/DBquery.php";
require_once "./inc/php/printPanel.php";
$db = new DBquery();
......@@ -42,47 +43,6 @@ foreach ($db->getAllActiveSectionParent() as $s){
}
}
function printPanel($name) {
echo '
<br/>
<label for="find'.$name.'Packages">Find packages with pattern :</label>
<input type="email" class="form-control" id="find'.$name.'Packages">
<div class="form-check">
<input type="checkbox" class="form-check-input" id="pattern'.$name.'Name" checked>
<label class="form-check-label" for="pattern'.$name.'Name">Pattern on name</label>
</div>
<div class="form-check">
<input type="checkbox" class="form-check-input" id="pattern'.$name.'Description" checked>
<label class="form-check-label" for="pattern'.$name.'Description">Pattern on description</label>
</div>
<br/>
<div class="form-group">
<label for="limit'.$name.'" class="font-check-label">Max found :</label>
<select class="custom-select" id="limit'.$name.'">
<option value="5">5</option>
<option value="10" selected="selected">10</option>
<option value="25">25</option>
<option value="50">50</option>
<option value="100">100</option>
<option value="100">200</option>
<option value="1000000000">all</option>
</select>
</div>
<br/>
<button type="button" class="btn btn-primary" onclick="showPackage(\''.$name.'\')">Search</button>
<br/><br/>
<div id="containPackages'.$name.'">
</div>
';
}
?>
<!doctype html>
......@@ -499,7 +459,6 @@ function printPanel($name) {
echo '';
}
?>
hide_os_rows();
......@@ -507,28 +466,6 @@ function printPanel($name) {
});
function showFormContainer() {
if(PREVIEW !== "") {
var isSingularity = document.getElementById("singularityRadio").checked;
if(isSingularity) {
document.getElementById("typeContainer").value = "Singularity";
} else {
document.getElementById("typeContainer").value = "Docker";
}
document.getElementById("valueContainer").value = PREVIEW;
$('#modalSaveRecipe').modal();
} else {
alert("Generate once before publish file");
}
}
function hide_os_rows() {
var e = document.getElementById("selectedOS");
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment