#
#		ITSV GmbH
#	CCDB - Command and Control Database
#
#	FILE:			dquermfile_textInfo.txt
#	DESCRIPTION:	DQUERY definition for CCDB DQUERY "textInfo"
#
@querytitle									Information über einen Text
@querydescription							Zeigt alle Text-Fragmente mit derselben Text-ID an und erlaubt die Bearbeitung
@group										ADMINTEXTFRAG
@paramnames									textid:textid:{{textidoptions}}
@textidoptions								{"labeltext":"Text-ID","typedesc":"ID des Texts, dessen Eigenschaften angezeigt werden sollen"}
@querytype									dbselect
@sql										select type,ident,version,parent,child_index,frag_index,data,'' as "Bearbeiten",'' as "Löschen",'' as "Information" from CCTEXTFRAG where ident=::textid::
											UNION
											select '','','','','','','','','','neues Fragment'
@title										Eigenschaften des Texts mit der ID "[[textid]]"
@decoration.decorate_colcell.0				$TEXTINPUT:type:typeoptions
@typeoptions.size							10
@decoration.decorate_colcell.1				$TEXTINPUT
@decoration.decorate_colcell.2				$TEXTINPUT:version:versionoptions
@versionoptions.size						3
@decoration.decorate_colcell.3				$TEXTINPUT:parent:parentoptions
@parentoptions.style						resize: both;
@decoration.decorate_colcell.4				$TEXTINPUT:child_index:child_indexoptions
@child_indexoptions.size					3
@decoration.decorate_colcell.5				$TEXTINPUT:frag_index:frag_indexoptions
@frag_indexoptions.size						3
@decoration.decorate_colcell.6				$TEXTAREA:datainput:datainputoptions
@datainputoptions.rows						1
@datainputoptions.style						font-family: monospace;
@decoration.decorate_colcell.7				$BUTTON:Änderungen speichern:updbuttonoptions
@decoration.decorate_colcell.8				$BUTTON:Löschen:delbuttonoptions
@decoration.decorate_colcell.9				$IDCELL
@updbuttonoptions.action					execrest
@updbuttonoptions.dataname					updateTextFragment
@updbuttonoptions.parameters				action,type,ident,version,parent,child_index,frag_index,data
@updbuttonoptions.action_parametername		action
@updbuttonoptions.action_value				update
@updbuttonoptions.resulttocol				9
@updbuttonoptions.type_parametername		type
@updbuttonoptions.type_fromcol				0
@updbuttonoptions.ident_parametername		ident
@updbuttonoptions.ident_fromcol				1
@updbuttonoptions.version_parametername		version
@updbuttonoptions.version_fromcol			2
@updbuttonoptions.parent_parametername		parent
@updbuttonoptions.parent_fromcol			3
@updbuttonoptions.child_index_parametername	child_index
@updbuttonoptions.child_index_fromcol		4
@updbuttonoptions.frag_index_parametername	frag_index
@updbuttonoptions.frag_index_fromcol		5
@updbuttonoptions.data_parametername		data
@updbuttonoptions.data_fromcol				6
@delbuttonoptions.action					execrest
@delbuttonoptions.dataname					updateTextFragment
@delbuttonoptions.parameters				action,type,ident,version,child_index,frag_index
@delbuttonoptions.action_parametername		action
@delbuttonoptions.action_value				delete
@delbuttonoptions.type_parametername		type
@delbuttonoptions.type_fromcol				0
@delbuttonoptions.ident_parametername		ident
@delbuttonoptions.ident_fromcol				1
@delbuttonoptions.version_parametername		version
@delbuttonoptions.version_fromcol			2
@delbuttonoptions.child_index_parametername	child_index
@delbuttonoptions.child_index_fromcol		4
@delbuttonoptions.frag_index_parametername	frag_index
@delbuttonoptions.frag_index_fromcol		5
@delbuttonoptions.resulttocol				9
@post_query	
		if (that.debug) logger.debug("textinfo.dbresult: "+aux.objTxt(that.result));
		let cv;
		for (let ri=0; ri<that.result.getRowCount(); ri++) {
		  for (let ci=0; ci<that.result.getRowLength(ri); ci++) {
		    cv = String(that.result.getCellValue(ri,ci));
		    if (typeof(cv)!='string') {
		      logger.error("textinfo.row="+ri+".column="+ci+".is_not_string: "+aux.objTxt(cv));
		      cv = aux.objTxt(cv);
		    }
		    cv = cv.replace(/\r/g,"&#13;").replace(/\n/g,"&#10;");
		    that.result.setCellValue(ri,ci,cv);
		  }
		}
		if (that.debug) logger.debug("textinfo.dbresult_after_Stringification: "+aux.objTxt(that.result));
		let types = {};
		let have_types = false;
		let ri, ro;
		for (ri=0; ri<that.result.getRowCount(); ri++) {
		  ro = that.result.getRowObject(ri);
		  if (!types[ro.type]) {
		    types[ro.type] = 1;
		    have_types = true;
		  } else {
		    types[ro.types]++;
		  }
		}
		that.result.bottomtext = "<ul>";
		that.result.bottomtext += '  <li><a href="/dquery?dataname=execSqlSeqFromText&textid='+that.query.textid+
		                          '">SQL aus dem Text mit ID='+that.query.textid+' ausführen</a></li>';
		that.result.bottomtext += '  <li><a href="/dquery?dataname=newTextFragment">neues Textfragment hinzuf&uuml;gen</a></li>'; 
		that.result.bottomtext += '  <li><a href="/dquery?dataname=qryTextChildren&parTextId='+that.query.textid+'">gesamte Struktur des Texts mit der ID='+that.query.textid+' anzeigen</a></li>'; 
		that.result.bottomtext += "</ul>"; 
