Commit a2244eb2 authored by Oleg Dzhimiev's avatar Oleg Dzhimiev

+Loading design files from github

parent 43a1273b
...@@ -7,6 +7,11 @@ LICENSE: AGPL, see http://www.gnu.org/licenses/agpl.txt ...@@ -7,6 +7,11 @@ LICENSE: AGPL, see http://www.gnu.org/licenses/agpl.txt
Copyright (C) 2014 Elphel, Inc. Copyright (C) 2014 Elphel, Inc.
*/ */
var path_local = "local";
var path_remote = "https://raw.githubusercontent.com/Elphel/elens/master";
var pattern_local = "local: ";
var pattern_remote = "github: ";
function save_design(){ function save_design(){
console.log("save_design(): "+$("#file_to_save").val()); console.log("save_design(): "+$("#file_to_save").val());
var xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Document>\n"; var xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Document>\n";
...@@ -43,7 +48,7 @@ function save_design(){ ...@@ -43,7 +48,7 @@ function save_design(){
function postSettings(file, cmd, xml) { function postSettings(file, cmd, xml) {
$.ajax({ $.ajax({
url: "files.php?file="+file+"&cmd="+cmd, url: "files.php?file="+file+"&cmd="+cmd+"&path="+path_local,
type: "POST", type: "POST",
dataType: "xml", dataType: "xml",
data: xml, data: xml,
...@@ -56,13 +61,14 @@ function postSettings(file, cmd, xml) { ...@@ -56,13 +61,14 @@ function postSettings(file, cmd, xml) {
function parse_save_response(text) { function parse_save_response(text) {
//$("#test").html(text); //$("#test").html(text);
//reload list //reload list
designs = Array();
get_designs_list("load_designs_list"); get_designs_list("load_designs_list");
jquery_list("load_designs_list","Load",load_design); jquery_list("load_designs_list","Load",load_design);
} }
function getDesign(file) { function getDesign(file,path) {
$.ajax({ $.ajax({
url: "files.php?file="+file+"&cmd=read", url: "files.php?file="+file+"&cmd=read&path="+path,
type: "GET", type: "GET",
async: false, async: false,
complete: function(response){ complete: function(response){
......
...@@ -14,7 +14,8 @@ else die("-1"); ...@@ -14,7 +14,8 @@ else die("-1");
if (isset($_GET['cmd'])) $cmd = $_GET['cmd']; if (isset($_GET['cmd'])) $cmd = $_GET['cmd'];
else die("-2"); else die("-2");
$default_path = "local"; if (isset($_GET['path'])) $default_path = $_GET['path'];
else die("-3");
if ($cmd=="save") { if ($cmd=="save") {
file_put_contents("$default_path/$file",file_get_contents("php://input")); file_put_contents("$default_path/$file",file_get_contents("php://input"));
......
<?php <?php
/* /*
FILE NAME : get_designs_list.php FILE NAME : get_remote_designs_list.php
DESCRIPTION: optical design DESCRIPTION: optical design
REVISION: 1.00 REVISION: 1.00
AUTHOR: Oleg Dzhimiev <oleg@elphel.com> AUTHOR: Oleg Dzhimiev <oleg@elphel.com>
...@@ -10,17 +10,21 @@ Copyright (C) 2014 Elphel, Inc. ...@@ -10,17 +10,21 @@ Copyright (C) 2014 Elphel, Inc.
//$res_xml = file_get_contents("sensors/sensors.xml"); //$res_xml = file_get_contents("sensors/sensors.xml");
$path = "local"; $path = "https://github.com/Elphel/elens";
$contents = file_get_contents($path);
$regexp = '#<a[^>]*href="([^"]*)"[^>]*title=".*.xml"#';
$files = Array();
if(preg_match_all($regexp, $contents, $matches, PREG_SET_ORDER)) {
foreach ($matches as $match) {
$files[] = basename($match[1]);
}
}
$res_xml = "<?xml version='1.0'?>\n"; $res_xml = "<?xml version='1.0'?>\n";
$res_xml .= "<Document>\n"; $res_xml .= "<Document>\n";
$files = scandir($path);
foreach($files as $file){ foreach($files as $file){
if (is_file("$path/$file")) {
$res_xml .= "\t<file>$file</file>\n"; $res_xml .= "\t<file>$file</file>\n";
}
} }
$res_xml .= "</Document>"; $res_xml .= "</Document>";
......
...@@ -12,27 +12,37 @@ $(function(){ ...@@ -12,27 +12,37 @@ $(function(){
function load_design(src,i){ function load_design(src,i){
console.log("Loading lens design: "+designs[i]); console.log("Loading lens design: "+designs[i]);
getDesign(designs[i]); var path = "";
var file = "";
if (designs[i].indexOf(pattern_remote)!=-1){
path = path_remote;
file = designs[i].replace(pattern_remote,"");
}else{
path = path_local;
file = designs[i].replace(pattern_local,"");
}
getDesign(file,path);
} }
function get_designs_list_sync(some_folder,type) { function get_designs_list_sync(url,prefix) {
$.ajax({ $.ajax({
url: "./get_designs_list.php", //url: "./get_designs_list.php",
url: url,
async: false, async: false,
dataType: "xml", dataType: "xml",
success: function(data){fill_designs_list(data.getElementsByTagName("file"));} success: function(data){fill_designs_list(data.getElementsByTagName("file"),prefix);}
}); });
} }
var designs = Array(); var designs = Array();
function fill_designs_list(designs_list){ function fill_designs_list(designs_list,prefix){
designs = Array();
for (var i=0;i<designs_list.length;i++){ for (var i=0;i<designs_list.length;i++){
var tmp = designs_list[i]; var tmp = designs_list[i];
if (tmp.length != 0) { if (tmp.length != 0) {
if (typeof(tmp.childNodes[0])!='undefined') designs[i] = tmp.childNodes[0].nodeValue; if (typeof(tmp.childNodes[0])!='undefined') designs.push(prefix+tmp.childNodes[0].nodeValue);
else designs[i] = ""; else designs.push = "";
} }
} }
} }
...@@ -41,13 +51,21 @@ function get_designs_list(element_id) { ...@@ -41,13 +51,21 @@ function get_designs_list(element_id) {
var some_folder = ""; var some_folder = "";
var folder_list = ""; var folder_list = "";
if (some_folder!="Load") { if (some_folder!="Load") {
get_designs_list_sync(); //get local list
get_designs_list_sync("./get_designs_list.php","local: ");
//get remote list from elphel's github
var list = "<div class='list_view'><ul>"; var list = "<div class='list_view'><ul>";
for(var i=0; i<designs.length; i++) { for(var i=0; i<designs.length; i++) {
list = list + "<li>"+designs[i]+"</li>"; list = list + "<li>"+designs[i]+"</li>";
} }
get_designs_list_sync("./get_remote_designs_list.php","github: ");
for(var j=i; j<designs.length; j++) {
list = list + "<li>"+designs[j]+"</li>";
}
list = list + "</ul></div>"; list = list + "</ul></div>";
}else{ }else{
list = "<div class='list_view'><ul></ul></div>"; list = "<div class='list_view'><ul></ul></div>";
......
Markdown is supported
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