From: Michael Wiebusch Date: Wed, 3 Jul 2013 09:03:51 +0000 (+0200) Subject: added file creation routine X-Git-Url: https://jspc29.x-matter.uni-frankfurt.de/git/?a=commitdiff_plain;h=6ca5f652cec4f3f0eff8d0449f39936ad1b7a181;p=mvdsensorcontrol.git added file creation routine --- diff --git a/config/settings.xml b/config/settings.xml index 82d9e4c..2267ce0 100644 --- a/config/settings.xml +++ b/config/settings.xml @@ -1,3 +1,3 @@ - + diff --git a/xml_spielwiese/cgitest.pl b/xml_spielwiese/cgitest.pl index 037dbc3..7318326 100755 --- a/xml_spielwiese/cgitest.pl +++ b/xml_spielwiese/cgitest.pl @@ -79,8 +79,9 @@ if ( $cgiHash{'print'} eq 'fileSelection' ) { if ( $cgiHash{'print'} eq 'spectree' ) { print "
Available Settings
\n"; parseSetAndSpec( $cgiHash{'configFile'} ); - print "
specifications loaded from $specfileName
"; + + print_registers($specfile); } @@ -88,18 +89,21 @@ if ( $cgiHash{'print'} eq 'settree' ) { print "
Selected Settings
\n"; parseSetAndSpec( $cgiHash{'configFile'} ); buildAncestry($setfileName); -# assignFieldColors();#obsolete - $settree = $ancestryTree; # not so elegant - print "
"; - print "inherit settings from:
"; - print ""; - for my $ancestor (@ancestryList) { - print ""; - } - print "
$ancestor
"; + # assignFieldColors();#obsolete + + $settree = $ancestryTree; # not so elegant + print ""; + print ""; + print ""; + print ""; + print "
"; + print_ancestorInfo(); + print "
"; + + print "
you are editing
$setfileName
"; + print "
"; - print "
"; print_registers($setfile); } @@ -123,10 +127,58 @@ if ( defined $cgiHash{'action'} ) { del( $cgiHash{'register'}, "" ); # delete existing register from setfile copyDefaultRegister( $cgiHash{'register'} ); } + if ( $cgiHash{'action'} eq 'createFile' ) { + createFile($cgiHash{'configFile'},$cgiHash{'specFile'}); + } } #################### SUBLAND ###################### + +sub createFile { + my $configFileName=$_[0]; + + my $specFileName=$_[1]; #config file is based on this specification! + my $configFile= $confDir."/".$configFileName; + my $specFile=$specDir."/".$specFileName; + + my $configTree = XML::LibXML->createDocument; + my $specTree = $parser->parse_file($specFile); + + my $configMaps = $configTree->createElementNS( "", "MAPS" ); + $configTree->setDocumentElement( $configMaps ); + + my $specMaps = $specTree->findnodes("/MAPS")->shift(); + + my $mapsType = $specMaps->findvalue("./\@type"); + + $configMaps->setAttribute("type",$mapsType); + $configMaps->setAttribute("specDbFile",$specFileName); + + + open( SCHREIBEN, "> $configFile" ) + or print "could not open file $configFile for writing: $!\n"; + + print SCHREIBEN $configTree->toString(); + close SCHREIBEN; + +} + +sub print_ancestorInfo { + print "
"; + if (@ancestryList) { + print "inherit settings from:
"; + print ""; + for my $ancestor (@ancestryList) { + print ""; + } + print "
$ancestor
"; + } + print "
"; +} + sub prepare_text { my $t = $_[0]; chomp $t; @@ -189,11 +241,11 @@ sub buildAncestry { # recursive $ancestryTree = $xmltree; } - - my $counter=1; - for my $file (reverse(@ancestryList)){ - $fileLevelHash{$file}=$counter; - if ($counter < 6) { + + my $counter = 1; + for my $file ( reverse(@ancestryList) ) { + $fileLevelHash{$file} = $counter; + if ( $counter < 6 ) { $counter++; } } @@ -285,23 +337,43 @@ sub del { close SCHREIBEN; } -sub print_fileSelection { +sub print_fileSelector{ + + my $configFile = $_[0]; + opendir( DIR, $confDir ) or die $!; - my $configFile = $_[0]; + print ''; + print ''; +} + +sub print_specSelector{ + + my $configFile = $_[0]; + opendir( DIR, $specDir ) or die $!; + + print ''; +} +sub print_fileSelection { + + my $configFile = $_[0]; + + print ""; + print ""; + + print ""; + + print ""; + print "
"; + print ""; + print ""; + print ""; + + print ""; + + print ""; print "
select config file:"; + print "
"; + print_fileSelector($configFile); print ""; @@ -333,11 +421,28 @@ sub print_fileSelection { print "
"; + print "

"; print ""; - print ""; + + print ""; + print "
"; - print "selected config file: $configFile"; + print "
"; + print "create new config file:"; print "
"; + print ""; + print ""; + print_specSelector(); + print ""; + print +""; + print "
"; + print "
"; } sub changeAncestor { @@ -450,11 +555,11 @@ sub printHash { # "#CCFFCC", "#CCFFFF", "#CCCCFF", "#FFCCFF", # "#FFCCCC", "#FFFFCC", "#FFFFFF" # ); -# +# # my @ancestryWithChild; # push(@ancestryWithChild,@ancestryList); # push(@ancestryWithChild,$setfileName); -# +# # my $index=0; # for my $fileName (reverse(@ancestryWithChild)){ # $fieldColorHash{$fileName}= $fieldColors[$index]; @@ -462,7 +567,7 @@ sub printHash { # $index++; # } # } -# +# #} sub print_registers { @@ -562,7 +667,7 @@ sub print_fields { $readOnlyFlag = 1; } - print ""; + print ""; print "$fieldName"; print "  = "; @@ -650,12 +755,35 @@ else { } } +function selectedSpecFile(){ +if(document.getElementById("specSelector")){ +var e = document.getElementById("specSelector"); +return e.options[e.selectedIndex].text;} +else { + return ""; +} +} + +function newFileName(){ +if(document.getElementById("newFileName")){ + var fileName = document.getElementById("newFileName").value; + var patt = /\.xml/i; + if(patt.test(fileName)){ + return fileName; + } else { + return fileName+".xml"; + } +} else { + return ""; +} +} var visHash= new Object(); function reloadSpecTree(){ -getdata('$me?print=spectree&configFile='+selectedConfigFile(),'roterBereich',false); +var file_ = encodeURIComponent(selectedConfigFile()); +getdata('$me?print=spectree&configFile='+file_,'roterBereich',false); for (var key in visHash) { if(visHash[key]==true){ showElement(key); @@ -664,7 +792,8 @@ showElement(key); } function reloadSetTree(){ -getdata('$me?print=settree&configFile='+selectedConfigFile(),'blauerBereich',false); +var file_ = encodeURIComponent(selectedConfigFile()); +getdata('$me?print=settree&configFile='+file_,'blauerBereich',false); for (var key in visHash) { if(visHash[key]==true){ showElement(key); @@ -675,12 +804,23 @@ showElement(key); function loadFile(){ debugOutput("load data from "+selectedConfigFile()); +visHash = new Object(); reloadSpecTree(); reloadSetTree(); reloadFileSelection(); } +function createFile(){ + debugOutput("NewFileName: "+newFileName()); + var configFile_ = encodeURIComponent(newFileName()); + var specFile_ = encodeURIComponent(selectedSpecFile()); + getdata("$me?action=createFile&configFile="+configFile_+"&specFile="+specFile_,"debug",false); + getdata('$me?print=fileSelection&configFile='+configFile_,'fileSelection',false); + loadFile(); + +} + function reloadFileSelection(){ var file_ = encodeURIComponent(selectedConfigFile()); getdata('$me?print=fileSelection&configFile='+file_,'fileSelection',false);