expandChildren(children) ::= <<
^children:{c |
	^if(c.ArchimateElement)^
		<tr>
		    <td> <a href="../elements/^c.ArchimateConcept.Id^.html" target="element"> ^c.Name;format="xml-encode"^ </a> </td>
		    <td> <a href="../elements/^c.ArchimateConcept.Id^.html" target="element" class="i18n-elementtype-^c.ArchimateConcept.Class.SimpleName^">
		    ^if(c.ArchimateConcept.PrimaryProfile)^
		    	(^c.ArchimateConcept.PrimaryProfile.Name^)
		    ^endif^
		    </a> </td>
		</tr>
	^elseif(c.ReferencedModel)^
		<tr>
		    <td> <a href="../views/^c.ReferencedModel.Id^.html" target="view"> ^c.Name^ </a> </td>
		    <td> <a href="../views/^c.ReferencedModel.Id^.html" target="view" class="i18n-viewpoint-^c.ReferencedModel.Viewpoint^"> </a> </td>
		</tr>
    <!-- Other graphical objects -->
	^elseif(c.Bounds)^
        <tr>
           <td> <a href="../objects/^c.Id^.html" target="element"> ^c.Name;format="xml-encode"^ </a> </td>
           <td> <a href="../objects/^c.Id^.html" target="element" class="i18n-elementtype-^c.Class.SimpleName^"> </a> </td>
        </tr>
	^endif^
	
	^if(c.Children)^
		^expandChildren(c.Children)^		
	^endif^
}^
>>

expandChildrenRel(children) ::= <<
^children:{c |
	^if(c.ArchimateElement)^
		^if(c.SourceConnections)^
			^c.SourceConnections:{r |
				^if(r.ArchimateConcept)^
					<tr>
						<td> <a href="../elements/^r.ArchimateConcept.Id^.html" target="element"> ^r.Name;format="xml-encode"^ </a> </td>
						<td> <a href="../elements/^r.ArchimateConcept.Id^.html" target="element" class="i18n-elementtype-^r.ArchimateConcept.Class.SimpleName^">
					    ^if(r.ArchimateConcept.PrimaryProfile)^
					    	(^r.ArchimateConcept.PrimaryProfile.Name^)
					    ^endif^
						</a> </td>
						<td> <a href="../elements/^r.ArchimateConcept.Source.Id^.html" target="element"> ^r.ArchimateConcept.Source.Name;format="xml-encode"^ </a> </td>
						<td> <a href="../elements/^r.ArchimateConcept.Target.Id^.html" target="element"> ^r.ArchimateConcept.Target.Name;format="xml-encode"^ </a> </td>
					</tr>
				^endif^
			}^
		^endif^
	^else^
		<!-- DEBUG: Skipping element from class ^c.Class.Name^ -->
	^endif^
	^if(c.Children)^
		^expandChildrenRel(c.Children)^		
	^endif^
}^
>>

expandFolderForQuery(folder) ::= <<
dataFolders.push({id:"^folder.Id^", type:"^folder.Class.SimpleName^", name:decodeURL("^folder.Name;format="url-encode"^"), documentation:decodeURL("^folder.Documentation;format="url-encode"^")\});
^folder.Folders:{f |
	dataFoldersContent.push({folderid:"^folder.Id^", contentid:"^f.Id^", contenttype:"^f.Class.SimpleName^"\});
	^expandFolderForQuery(f)^
}^
^folder.Elements:{c |
	dataFoldersContent.push({folderid:"^folder.Id^", contentid:"^c.Id^", contenttype:"^c.Class.SimpleName^"\});
	^if(c.Source)^
		dataRelationships.push({id:"^c.Id^", type:"^c.Class.SimpleName^", specialization:decodeURL("^c.PrimaryProfile.Name;format="url-encode"^"), name:decodeURL("^c.Name;format="url-encode"^"), documentation:decodeURL("^c.Documentation;format="url-encode"^"), sourceid:"^c.Source.Id^", targetid:"^c.Target.Id^"\});
		^c.Properties:{p |
			dataProperties.push({conceptid:"^c.Id^", propkey:decodeURL("^p.Key;format="url-encode"^"), propvalue:decodeURL("^p.Value;format="url-encode"^")\});
		}^
	^elseif(c.ConnectionRouterType)^
		dataViews.push({id:"^c.Id^", type:"^c.Class.SimpleName^", name:decodeURL("^c.Name;format="url-encode"^"), documentation:decodeURL("^c.Documentation;format="url-encode"^")\});
		^c.Properties:{p |
			dataProperties.push({conceptid:"^c.Id^", propkey:decodeURL("^p.Key;format="url-encode"^"), propvalue:decodeURL("^p.Value;format="url-encode"^")\});
		}^
		^expandViewElementsForQuery(c, c.Children)^
		^expandViewRelsForQuery(c, c.Children)^
	^else^
		dataElements.push({id:"^c.Id^", type:"^c.Class.SimpleName^", specialization:decodeURL("^c.PrimaryProfile.Name;format="url-encode"^"), name:decodeURL("^c.Name;format="url-encode"^"), documentation:decodeURL("^c.Documentation;format="url-encode"^")\});
		^c.Properties:{p |
			dataProperties.push({conceptid:"^c.Id^", propkey:decodeURL("^p.Key;format="url-encode"^"), propvalue:decodeURL("^p.Value;format="url-encode"^")\});
		}^
	^endif^
}^
>>

expandViewElementsForQuery(view, children) ::= <<
^children:{c |
	^if(c.ArchimateElement)^
		dataViewsContent.push({viewid:"^view.Id^", contentid:"^c.ArchimateElement.Id^", contenttype:"^c.ArchimateElement.Class.SimpleName^"\});
	^elseif(c.ReferencedModel)^
		dataViewsContent.push({viewid:"^view.Id^", contentid:"^c.ReferencedModel.Id^", contenttype:"^c.ReferencedModel.Class.SimpleName^"\});
	^endif^
	^if(c.Children)^
		^expandViewElementsForQuery(view, c.Children)^		
	^endif^
}^
>>

expandViewRelsForQuery(view, children) ::= <<
^children:{c |
	^if(c.ArchimateElement)^
		^if(c.SourceConnections)^
			^c.SourceConnections:{r |
				^if(r.ArchimateConcept)^
					dataViewsContent.push({viewid:"^view.Id^", contentid:"^r.ArchimateConcept.Id^", contenttype:"^r.ArchimateConcept.Class.SimpleName^"\});
				^endif^
			}^
		^endif^
	^endif^
	^if(c.Children)^
		^expandViewRelsForQuery(view, c.Children)^		
	^endif^
}^
>>

expandAreasForChildren(children) ::= <<
^reverse(children):{c |
	^if(c.Children)^
		^expandAreasForChildren(c.Children)^
	^endif^
	^if(c.ArchimateElement)^
		<area shape="rect" coords="^bounds(c, "X1")^,^bounds(c, "Y1")^,^bounds(c, "X2")^,^bounds(c, "Y2")^" href="../elements/^c.ArchimateElement.Id^.html"  target="element">
	^elseif(c.ReferencedModel)^
		<area shape="rect" coords="^bounds(c, "X1")^,^bounds(c, "Y1")^,^bounds(c, "X2")^,^bounds(c, "Y2")^" href="../views/^c.ReferencedModel.Id^.html"  target="view">
    <!-- Other diagram objects -->
    ^elseif(c.Bounds)^
        <area shape="rect" coords="^bounds(c, "X1")^,^bounds(c, "Y1")^,^bounds(c, "X2")^,^bounds(c, "Y2")^" href="../objects/^c.Id^.html" target="element" >
	^endif^
}^
>>

bounds(c, pos) ::= "^map.(c.Id).(pos)^"

expandModelRelations(relations) ::= <<
	^relations: {r | <tr>
		<td><a href="../elements/^r.Id^.html" target="element" title="^r.Name;format="xml-encode"^">^r.Name;format="xml-encode"^</a></td>
		<td><span class="i18n-elementtype-^r.Class.SimpleName^" /></td>
		<td><a href="../elements/^r.Source.Id^.html" target="element"> ^r.Source.Name;format="xml-encode"^</a></td>
		<td><a href="../elements/^r.Target.Id^.html" target="element"> ^r.Target.Name;format="xml-encode"^</a></td>
	</tr>}^
>>

frame(element, map) ::= <<
<!DOCTYPE html>
<html class="frame" lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
	<title>^element.Name^</title>

	<!-- JQUERY -->
	<script type="text/javascript" src="../../lib/jquery/jquery.min.js"></script>
	<!-- BOOTSTRAP -->
	<link type="text/css" rel="stylesheet" href="../../lib/bootstrap/css/bootstrap.min.yeti.css">
	<script type="text/javascript" src="../../lib/bootstrap/js/bootstrap-3.4.1.min.js"></script>
	<!-- REPORT SPECIFIC -->
	<link type="text/css" rel="stylesheet" href="../../css/model.css">
	<link type="text/css" rel="stylesheet" href="../../css/i18n.css">
	<script type="text/javascript" src="../../js/frame.js"></script>
	<script type="text/javascript" src="../../js/imageMapResizer.min.js"></script>
</head>

<body>
	<div class="panel panel-default root-panel">
		
		<div class="panel-heading root-panel-heading">
            <!-- Name -->
		    ^if(element.Name && element.Name.Empty)^
               <b class="i18n-elementtype-^element.Class.SimpleName^"></b>
			^else^
               <b>^element.Name;format="xml-encode"^</b>
            ^endif^

            <!-- If a View with Viewpoint -->
			^if(element.Viewpoint)^
			   (<span class="i18n-viewpoint-^element.Viewpoint^"></span>)
			   <a class="glyphicon glyphicon-info-sign" id="hint-viewpoint_^element.Viewpoint^" target="hint"></a>
            <!-- Or if a model (i.e has Purpose method) -->
			^elseif(!element.Purpose)^
			   (<span class="i18n-elementtype-^element.Class.SimpleName^"></span>)
			   <a class="glyphicon glyphicon-info-sign" id="hint-^element.Class.SimpleName^" target="hint"></a>
			^endif^
		</div>
		
		<div class="panel-body root-panel-body">
		    <!-- If this is a digram model (has children and no bounds) show the image -->
			^if(element.Children && !element.Bounds)^
			   <img class="diagram" src="../images/^element.Id^.png" alt="^element.Name^" usemap="#^element.Id^map"/>
			   <map name="^element.Id^map">
				  ^expandAreasForChildren(element.Children)^
			   </map>
			^endif^
			
			<div role="tabpanel">
				<!-- Nav tabs -->
				<ul class="nav nav-tabs" role="tablist">
                    <!-- Purpose / Documentation / Content -->
                    ^if(element.Purpose)^
                       <li role="presentation" class="active"><a href="#documentation" aria-controls="documentation" role="tab" data-toggle="tab" class="i18n-purpose"></a></li>
                    ^elseif(element.Documentation)^
					   <li role="presentation" class="active"><a href="#documentation" aria-controls="documentation" role="tab" data-toggle="tab" class="i18n-documentation"></a></li>
					^elseif(element.Content)^
                       <li role="presentation" class="active"><a href="#documentation" aria-controls="documentation" role="tab" data-toggle="tab" class="i18n-content"></a></li>
					^endif^
					
                    <!-- Properties -->
                    <li role="presentation"><a href="#properties" aria-controls="properties" role="tab" data-toggle="tab" class="i18n-properties"></a></li>
                    
                    <!-- Analysis -->
                    ^if(element.SourceRelationships || element.TargetRelationships || element.ReferencingDiagramComponents)^
                    	<li role="presentation"><a href="#analysis" aria-controls="analysis" role="tab" data-toggle="tab" class="i18n-analysis"></a></li>
					^endif^
					
					^if(element.Children)^
						<li role="presentation"><a href="#elements" aria-controls="elements" role="tab" data-toggle="tab" class="i18n-elements"></a></li>
						<li role="presentation"><a href="#relationships" aria-controls="relationships" role="tab" data-toggle="tab" class="i18n-relationships"></a></li>
                    <!-- Model, Query Tab -->
					^elseif(element.Purpose)^
						<li role="presentation"><a href="#query" aria-controls="query" role="tab" data-toggle="tab" class="i18n-query"></a></li>
					^endif^
				</ul>
		
				<!-- Tab panes -->
				<div class="tab-content">
					<div role="tabpanel" class="tab-pane active" id="documentation">
						^if(element.PrimaryProfile)^
							<br>
							<b class="i18n-specialization"></b>
								^element.PrimaryProfile.Name^
					    ^endif^
						^if(element.Source)^
							<br>
							<b class="i18n-relation-source"></b>
								<a href="../elements/^element.Source.Id^.html" target="element">
									^element.Source.Name;format="xml-encode"^
								</a>
							<br>
							<b class="i18n-relation-target"></b>
								<a href="../elements/^element.Target.Id^.html" target="element">
									^element.Target.Name;format="xml-encode"^
								</a>
							<br>
							<br>
						^endif^
						<div class="convertlinks documentation" style="white-space:pre-wrap">^element.Documentation;format="xml-encode"^^element.Purpose;format="xml-encode"^^element.Content;format="xml-encode"^</div>
					</div>
					<div role="tabpanel" class="tab-pane" id="properties">
						<table class="table table-striped table-hover table-condensed">
							<thead>
								<tr>
									<th class="i18n-key"></th>
									<th class="i18n-value"></th>
								</tr>
							</thead>
							<tbody>
								^element.Properties:{p | <tr><td>^p.Key;format="xml-encode"^</td><td class="convertlinks no-margin" style="white-space:pre-wrap">^p.Value;format="xml-encode"^</td></tr>}^
							</tbody>
						</table>
					</div>
					<div role="tabpanel" class="tab-pane" id="analysis">
						<table class="table table-striped table-hover table-condensed" id="used-in-views">
							<thead>
								<tr><th colspan="2" class="i18n-used-in-views" /></tr>
								<tr>
									<th class="i18n-name"></th>
									<th class="i18n-viewpoint"></th>
								</tr>
							</thead>
							<tbody>
								^element.ReferencingDiagramComponents: {v | <tr id="used-in-views-^v.DiagramModel.Id^">
									<td><a href="../views/^v.DiagramModel.Id^.html" target="view" title="^v.DiagramModel.Name;format="xml-encode"^"> ^v.DiagramModel.Name;format="xml-encode"^ </a></td>
									<td><span class="i18n-viewpoint-^v.DiagramModel.Viewpoint^" /></td>
								</tr>}^
							</tbody>
						</table>
						<table class="table table-striped table-hover table-condensed" id="model-relations">
							<thead>
								<tr><th colspan="4" class="i18n-model-relations" /></tr>
								<tr>
									<th class="i18n-name"></th>
									<th class="i18n-type"></th>
									<th class="i18n-source"></th>
									<th class="i18n-target"></th>
								</tr>
							</thead>
							<tbody>
								^expandModelRelations(element.SourceRelationships)^
								^expandModelRelations(element.TargetRelationships)^
							</tbody>
						</table>
					</div>
					^if(element.Children)^
						<div role="tabpanel" class="tab-pane" id="elements">
							<table class="table table-striped table-hover table-condensed">
								<thead>
									<tr>
										<th class="i18n-name"></th>
										<th class="i18n-type"></th>
									</tr>
								</thead>
								<tbody>
									^expandChildren(element.Children)^
								</tbody>
							</table>
						</div>
						<div role="tabpanel" class="tab-pane" id="relationships">
							<table class="table table-striped table-hover table-condensed">
								<thead>
									<tr>
										<th class="i18n-name"></th>
										<th class="i18n-type"></th>
										<th class="i18n-source"></th>
										<th class="i18n-target"></th>
									</tr>
								</thead>
								<tbody>
									^expandChildrenRel(element.Children)^
								</tbody>
							</table>
						</div>
					^elseif(element.Purpose)^
						<div role="tabpanel" class="tab-pane" id="query">
						<br>
						<style>
						#myprompt {
						    width: 80%;
						    font-family: Consolas,Monaco, monospace;
						}
						</style>
						
						<div id='myconsole'></div>
						
						<p>
							<tt><span id="useid">alasql</span> &gt;</tt> <input id='myprompt' autofocus/> 
						</p>
						
						<script src='../../lib/alasql/alasql.min.js'></script>
						
						<script>
							function decodeURL(s) {
								return decodeURIComponent(s.replace(/\+/g, "%20"));
							}
							
							var first = decodeURI(location.search.substr(1));
						 	alasql.options.logtarget = 'myconsole';
							alasql.prompt('myprompt','useid');
							alasql.prompt('myprompt','useid', first);
							  
							var dataElements = [ ];	  
						  	var dataProperties = [ ];
						 	var dataRelationships = [ ];
						 	var dataViews = [ ];
						 	var dataViewsContent = [ ];
						 	var dataFolders = [ ];
						 	var dataFoldersContent = [ ];
							
							^expandFolderForQuery(element)^
							
						    alasql('CREATE TABLE Elements');
						    alasql('CREATE TABLE Properties');
						    alasql('CREATE TABLE Relationships');
						    alasql('CREATE TABLE Views');
						    alasql('CREATE TABLE ViewsContent');
						    alasql('CREATE TABLE Folders');
						    alasql('CREATE TABLE FoldersContent');
						
						    alasql.tables.Elements.data = dataElements;
						    alasql.tables.Properties.data = dataProperties;
						    alasql.tables.Relationships.data = dataRelationships;
						    alasql.tables.Views.data = dataViews;
						    alasql.tables.ViewsContent.data = dataViewsContent;
						    alasql.tables.Folders.data = dataFolders;
						    alasql.tables.FoldersContent.data = dataFoldersContent;
						</script> 
						</div>
					^endif^
			  </div>
			</div>
		</div>
	</div>
	<script type="text/javascript">imageMapResize();</script>
</body>
</html>
>>
