lp-collaborative-workspace/lp-cw-component/lp-cw-component-ui/src/main/resources/LPUI/ModelSheet.xml
<?xml version="1.0" encoding="UTF-8"?>
<!--
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-->
<xwikidoc version="1.2" reference="LPUI.ModelSheet" locale="">
<web>LPUI</web>
<name>ModelSheet</name>
<language/>
<defaultLanguage/>
<translation>0</translation>
<creator>xwiki:XWiki.Admin</creator>
<creationDate>1443012383000</creationDate>
<parent>Main.WebHome</parent>
<author>xwiki:XWiki.Admin</author>
<contentAuthor>xwiki:XWiki.Admin</contentAuthor>
<date>1465211801000</date>
<contentUpdateDate>1465208346000</contentUpdateDate>
<version>1.1</version>
<title>$!{doc.getObject('LPCode.ModelClass').getProperty('name').value}</title>
<comment/>
<minorEdit>false</minorEdit>
<syntaxId>xwiki/2.1</syntaxId>
<hidden>true</hidden>
<content>{{velocity}}
#set ($discard = $xwiki.ssx.use('LPUI.ModelSheet'))
#set ($discard = $xwiki.jsx.use('LPUI.ModelSheet'))
#set ($modelObject = $doc.getObject('LPCode.ModelClass'))
#set ($modelsetid = $modelObject.getProperty('modelsetid').value)
#set ($modelid = $modelObject.getProperty('id').value)
#set ($modelidNumber = $modelid.split("\.").get(1))
#set ($documentation = $modelObject.getProperty('documentation').value)
#set ($modelSetReference = $services.model.createDocumentReference($xcontext.database, 'CoreRepository', ${modelsetid}))
#set ($attachmentName = "${modelsetid}.ADOXX")
#set ($attachmentReference = $services.model.createAttachmentReference($modelSetReference, $attachmentName))
#set ($attachmentPath = "attach:${services.model.serialize($attachmentReference, 'default')}")
#set ($query = "from doc.object(LPCode.BaseElementClass) as be where be.modelsetid = :modelsetid and be.modelid = :modelid and be.type = 'bpmn-event-start'")
#set ($startEventFullnames = $services.query.xwql($query).bindValue("modelsetid", "${modelsetid}").bindValue("modelid", "${modelid}").execute())
#set ($collaborateReference = $services.model.createDocumentReference("CD", ${doc.documentReference.lastSpaceReference}))
#set ($queryString = "modelsetid=$modelsetid&modelid=$modelid")
#set ($collaborateMode = "view")
#set ($collaborateIsNew = $xwiki.getDocument($collaborateReference).isNew())
#if ($collaborateIsNew)
#set ($queryString = "editor=inline&sheet=CKEditor.EditSheet&template=LPCode.CollaborativeDocumentTemplate&${queryString}")
#set ($collaborateMode = "edit")
#end
#set ($collaborateURL = $xwiki.getURL($collaborateReference, "${collaborateMode}", ${queryString}))
#set ($bpmnName = "${modelidNumber}.bpmn")
#set ($bpmnPath = "${attachmentPath}/${bpmnName}")
#set ($imageName = "${modelidNumber}.png")
#set ($mapName = "${modelidNumber}.map")
#set ($imagePath = "${attachmentPath}/${imageName}")
#set ($mapPath = "${attachmentPath}/${mapName}")
################
## Buttons
(% class="row" %)(((
(% class="col-xs-12 col-md-3" %)(((
(% class="dropdown" %)(((
(% data-toggle="dropdown" role="button" %)(((
(% class="btn btn-block btn-browse" %)${services.localization.render('LPUI.ModelSheet.button.browse')}
)))
(% class="dropdown-menu" role="menu" %)
#foreach($startEventFullname in $startEventFullnames)
#set ($startEventReference = $services.model.resolveDocument($startEventFullname))
#set ($startEventDocument = $xwiki.getDocument($startEventReference))
#set ($startEventObject = $startEventDocument.getObject('LPCode.BaseElementClass'))
#set ($startEventName = $startEventObject.getProperty('name').value)
#set ($startEventURL = $xwiki.getURL($startEventReference, 'view'))
* [[${services.icon.render('play')} ${startEventName}>>path:${startEventURL}||class="btn"]]
#end
)))
)))
#if ($niotool.isRegularFile($bpmnPath, null))
#set ($simulationReference = $services.model.createDocumentReference($xcontext.database, 'LPUI', 'SimulationEnvironment'))
#set ($simulationURL = $xwiki.getURL($simulationReference, 'view', "modelsetid=${modelsetid}&modelid=${modelid}"))
(% class="col-xs-12 col-md-3" %)(((
[[${services.localization.render('LPUI.ModelSheet.button.simulate')}>>path:${simulationURL}||class="btn btn-block btn-simulation"]]
)))
#end
(% class="col-xs-12 col-md-3" %)(((
[[${services.localization.render('LPUI.ModelSheet.button.contribute')}>>path:${collaborateURL}||class="btn btn-block btn-contribute"]]
)))
)))
################
## Documentation
(% class="row text-center description" %)(((
{{documentation}}
${documentation}
{{/documentation}}
)))
################
## Image
(% class="row" %)(((
#if ($niotool.isRegularFile($imagePath, null))
(% class="col-xs-12" %)(((
(% id="boxesContainer" data-modelsetid="$modelsetid" data-modelidnumber="$modelidNumber" %) (((
[[image:path:$services.vfs.url($imagePath)||width="100%" usemap="#modelmap" alt="Image of the model"]]
)))
{{html clean="false"}}
<map name="modelmap">
<area shape="rect" coords="100,100,1000,1000"
</map>
{{/html}}
)))
#end
)))
################
## Livetable
#set ($columnsProperties = {
'modelsetid': {'type': 'hidden'},
'modelid': {'type': 'hidden'},
'name': {'type': 'text', 'size': 8, 'link': 'view'},
'type': {'type': 'list', 'size': 2},
'doc.date': {'type': 'text', 'size': 2}
})
#set ($options = {
'className': 'LPCode.BaseElementClass',
'resultPage': 'XWiki.LiveTableResults',
'translationPrefix': 'lpcode.livetable.model.',
'tagCloud': true,
'rowCount': 15,
'maxPages': 20,
'selectedColumn': 'name',
'defaultOrder': 'asc',
'extraParams': "&modelsetid=${modelsetid}&modelid=${modelid}"
})
#set ($columns = ['modelsetid', 'modelid', 'name', 'type', 'doc.date'])
#livetable('lp-modellist' $columns $columnsProperties $options)
{{/velocity}}</content>
<object>
<name>LPUI.ModelSheet</name>
<number>0</number>
<className>XWiki.JavaScriptExtension</className>
<guid>27bec18a-7872-4cb3-9d6b-2868654bda3e</guid>
<class>
<name>XWiki.JavaScriptExtension</name>
<customClass/>
<customMapping/>
<defaultViewSheet/>
<defaultEditSheet/>
<defaultWeb/>
<nameField/>
<validationScript/>
<cache>
<cache>0</cache>
<disabled>0</disabled>
<displayType>select</displayType>
<multiSelect>0</multiSelect>
<name>cache</name>
<number>5</number>
<prettyName>Caching policy</prettyName>
<relationalStorage>0</relationalStorage>
<separator> </separator>
<separators>|, </separators>
<size>1</size>
<unmodifiable>0</unmodifiable>
<values>long|short|default|forbid</values>
<classType>com.xpn.xwiki.objects.classes.StaticListClass</classType>
</cache>
<code>
<disabled>0</disabled>
<name>code</name>
<number>2</number>
<prettyName>Code</prettyName>
<rows>20</rows>
<size>50</size>
<unmodifiable>0</unmodifiable>
<classType>com.xpn.xwiki.objects.classes.TextAreaClass</classType>
</code>
<name>
<disabled>0</disabled>
<name>name</name>
<number>1</number>
<prettyName>Name</prettyName>
<size>30</size>
<unmodifiable>0</unmodifiable>
<classType>com.xpn.xwiki.objects.classes.StringClass</classType>
</name>
<parse>
<disabled>0</disabled>
<displayFormType>select</displayFormType>
<displayType>yesno</displayType>
<name>parse</name>
<number>4</number>
<prettyName>Parse content</prettyName>
<unmodifiable>0</unmodifiable>
<classType>com.xpn.xwiki.objects.classes.BooleanClass</classType>
</parse>
<use>
<cache>0</cache>
<disabled>0</disabled>
<displayType>select</displayType>
<multiSelect>0</multiSelect>
<name>use</name>
<number>3</number>
<prettyName>Use this extension</prettyName>
<relationalStorage>0</relationalStorage>
<separator> </separator>
<separators>|, </separators>
<size>1</size>
<unmodifiable>0</unmodifiable>
<values>currentPage|onDemand|always</values>
<classType>com.xpn.xwiki.objects.classes.StaticListClass</classType>
</use>
</class>
<property>
<cache>long</cache>
</property>
<property>
<code>require(['jquery'], function ($) {
var debug = () => {};
//debug = function (msg) { console.log(msg); }
var parsePosition = function (pos) {
var xywh = {};
pos.split(' ').forEach(function (x) {
x.replace(/^([xywh]):([0-9\.]+)cm$/, function (all, _xywh, num) {
xywh[_xywh] = Number(num);
});
});
if (!xywh.h && !xywh.w) {
xywh.h = 2;
xywh.w = 2;
}
if (!xywh.x || !xywh.y || !xywh.w || !xywh.h) {
throw new Error("failed to parse " + pos);
}
return xywh;
};
var getWidthHeightMultiplier = function (xml, modelNum, imageDiv) {
var area = $(xml).find('MODEL[id="mod.' + modelNum + '"] ATTRIBUTE[name="World area"]').text();
if (!area) { throw new Error("Failed to get 'World area'"); }
var wh = {};
area.split(' ').forEach(function (x) {
x.replace(/^([wh]):([0-9\.]+)cm$/, function (all, _wh, num) { wh[_wh] = Number(num); });
});
if (!wh.w || !wh.h) { throw new Error("failed to parse " + area); }
debug("w:" + imageDiv.children().width());
debug("h:" + imageDiv.children().height());
debug("nw:" + imageDiv.children()[0].naturalWidth);
debug("nh:" + imageDiv.children()[0].naturalHeight);
return {
widthPixPerCm: imageDiv.children().width() / wh.w,
heightPixPerCm: imageDiv.children().height() / wh.h
};
};
var handleXML = function (xml, modelNum, imageDiv) {
var whm = getWidthHeightMultiplier(xml, modelNum, imageDiv);
debug(whm);
$(xml).find('MODEL[id="mod.' + modelNum + '"] INSTANCE').each(function (i, el) {
if (['Pool','Lane'].indexOf($(el).attr('class')) > -1) { return; }
var pos = parsePosition($(el).find('ATTRIBUTE[name="Position"]').text());
var posX = pos.x - (pos.w / 2);
var posY = pos.y - (pos.h / 2);
var redirectElmt = window.docviewurl+$(el).attr('id');
var box = $(
'<a href="' + redirectElmt + '" ' +
'title="' + $(el).attr('name') + '"' +
'class="learnpad-clickable-map" ' +
'style="' +
'left:' + ( posX * whm.widthPixPerCm) + 'px;' +
'top:' + ( posY * whm.heightPixPerCm) + 'px;' +
'width:' + (pos.w * whm.widthPixPerCm) + 'px;' +
'height:' + (pos.h * whm.heightPixPerCm) + 'px;">' +
'</a>'
).appendTo(imageDiv);
});
};
var start = function() {
var imageDiv = $('#boxesContainer');
var obj = $(imageDiv).attr('data-modelidnumber');
var modelsetId = $(imageDiv).attr('data-modelsetid');
var url = 'learnpad-modelset-'+modelsetId;
if (localStorage[url]) {
handleXML(localStorage[url], obj, imageDiv);
} else {
$.ajax("/xwiki/rest/learnpad/cw/corefacade/getmodel/"+modelsetId+"?type=ADOXX", { dataType: "text" }).success(function (xml) {
localStorage[url] = xml;
handleXML(xml, obj, imageDiv);
}).error(function (x, y, z) {
throw new Error(z);
});
}
};
start();
});</code>
</property>
<property>
<name>Boxes</name>
</property>
<property>
<parse>0</parse>
</property>
<property>
<use>onDemand</use>
</property>
</object>
<object>
<name>LPUI.ModelSheet</name>
<number>0</number>
<className>XWiki.StyleSheetExtension</className>
<guid>0b203abe-8686-4464-825d-527ecb698f3d</guid>
<class>
<name>XWiki.StyleSheetExtension</name>
<customClass/>
<customMapping/>
<defaultViewSheet/>
<defaultEditSheet/>
<defaultWeb/>
<nameField/>
<validationScript/>
<cache>
<cache>0</cache>
<disabled>0</disabled>
<displayType>select</displayType>
<multiSelect>0</multiSelect>
<name>cache</name>
<number>6</number>
<prettyName>Caching policy</prettyName>
<relationalStorage>0</relationalStorage>
<separator> </separator>
<separators>|, </separators>
<size>1</size>
<unmodifiable>0</unmodifiable>
<values>long|short|default|forbid</values>
<classType>com.xpn.xwiki.objects.classes.StaticListClass</classType>
</cache>
<code>
<disabled>0</disabled>
<name>code</name>
<number>3</number>
<prettyName>Code</prettyName>
<rows>20</rows>
<size>50</size>
<unmodifiable>0</unmodifiable>
<classType>com.xpn.xwiki.objects.classes.TextAreaClass</classType>
</code>
<contentType>
<cache>0</cache>
<disabled>0</disabled>
<displayType>select</displayType>
<multiSelect>0</multiSelect>
<name>contentType</name>
<number>1</number>
<prettyName>Content Type</prettyName>
<relationalStorage>0</relationalStorage>
<separator> </separator>
<separators>|, </separators>
<size>1</size>
<unmodifiable>0</unmodifiable>
<values>CSS|LESS</values>
<classType>com.xpn.xwiki.objects.classes.StaticListClass</classType>
</contentType>
<name>
<disabled>0</disabled>
<name>name</name>
<number>2</number>
<prettyName>Name</prettyName>
<size>30</size>
<unmodifiable>0</unmodifiable>
<classType>com.xpn.xwiki.objects.classes.StringClass</classType>
</name>
<parse>
<disabled>0</disabled>
<displayFormType>select</displayFormType>
<displayType>yesno</displayType>
<name>parse</name>
<number>5</number>
<prettyName>Parse content</prettyName>
<unmodifiable>0</unmodifiable>
<classType>com.xpn.xwiki.objects.classes.BooleanClass</classType>
</parse>
<use>
<cache>0</cache>
<disabled>0</disabled>
<displayType>select</displayType>
<multiSelect>0</multiSelect>
<name>use</name>
<number>4</number>
<prettyName>Use this extension</prettyName>
<relationalStorage>0</relationalStorage>
<separator> </separator>
<separators>|, </separators>
<size>1</size>
<unmodifiable>0</unmodifiable>
<values>currentPage|onDemand|always</values>
<classType>com.xpn.xwiki.objects.classes.StaticListClass</classType>
</use>
</class>
<property>
<cache>long</cache>
</property>
<property>
<code>.xdocLastModification {
display: none;
}
.learnpad-clickable-map:hover {
background:red;
}
.learnpad-clicked-map {
background:green;
}
.learnpad-clickable-map {
position:absolute;
opacity:0.3;
z-index:9000;
}
#boxesContainer {
position:relative;
border:0px;
margin:0px;
}</code>
</property>
<property>
<contentType>CSS</contentType>
</property>
<property>
<name/>
</property>
<property>
<parse/>
</property>
<property>
<use>currentPage</use>
</property>
</object>
</xwikidoc>