aboutsummaryrefslogtreecommitdiffstats
path: root/winery/org.eclipse.winery.repository/src/main/webapp/jsp/genericcomponentpage.jsp
blob: 04399045ea9f4029bda47bffd7de63edde76dd5d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
<%--
/*******************************************************************************
 * Copyright (c) 2012-2013 University of Stuttgart.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * and the Apache License 2.0 which both accompany this distribution,
 * and are available at http://www.eclipse.org/legal/epl-v10.html
 * and http://www.apache.org/licenses/LICENSE-2.0
 *
 * Contributors:
 *    Oliver Kopp - initial API and implementation and/or initial documentation
 *******************************************************************************/
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

<%@taglib prefix="c"  uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="v"  uri="http://www.eclipse.org/winery/repository/functions" %>
<%@taglib prefix="t"  tagdir="/WEB-INF/tags" %>
<%@taglib prefix="wc" uri="http://www.eclipse.org/winery/functions" %>

<%-- In English, one can usually form a plural by adding an "s". Therefore, we resue the label to form the window title --%>
<t:genericpage windowtitle="${it.label}s" selected="${it.type}" cssClass="${it.CSSclass}">

<c:choose>
<c:when test="${empty pageContext.request.contextPath}">
<c:set var="URL" value="/" />
</c:when>
<c:otherwise>
<c:set var="URL" value="${pageContext.request.contextPath}/" />
</c:otherwise>
</c:choose>
<t:simpleSingleFileUpload
	title="Upload CSAR"
	text="CSAR file"
	URL="${URL}"
	type="POST"
	id="upCSAR"
	accept="application/zip,.csar"/>

<t:addComponentInstance
	label="${it.label}"
	typeSelectorData="${it.typeSelectorData}"
	/>

<div class="middle" id="ccontainer">
	<br />

	<table cellpadding=0 cellspacing=0 style="margin-top: 0px; margin-left: 30px;">
		<tr>
			<td valign="top" style="padding-top: 25px; width: 680px;">

				<div id="searchBoxContainer">

					<input id="searchBox" />

					<script>

						$('#searchBox').keyup(function() {
							var searchString = $(this).val();
							searchString = searchString.toLowerCase();

							$(".entityContainer").each (function() {
								var name = $(this).find(".informationContainer > .name").text();
								var namespace = $(this).find(".informationContainer > .namespace").text();

								var t = name + namespace;
								t = t.toLowerCase();

								if (t.indexOf(searchString) == -1) {
									$(this).hide();
								} else {
									$(this).show();
								}

							});

						});

					</script>

				</div>

			<c:forEach var="t" items="${it.componentInstanceIds}">
				<%-- even though the id is an invalid XML, it is used for a simple implementation on a click on the graphical rendering to trigger opening the editor --%>
				<div class="entityContainer ${it.CSSclass}" id="${v:URLencode(t.namespace.encoded)}/${v:URLencode(t.xmlId.encoded)}/">
					<div class="left">
						<c:if test="${it.type eq 'NodeType'}">
							<a href="./${v:URLencode(t.namespace.encoded)}/${v:URLencode(t.xmlId.encoded)}/?edit">
								<img src='./${v:URLencode(t.namespace.encoded)}/${v:URLencode(t.xmlId.encoded)}/visualappearance/50x50' style='margin-top: 21px; margin-left: 30px; height: 40px; width: 40px;' />
							</a>
						</c:if>
					</div>
					<div class="center">
						<div class="informationContainer">
							<div class="name">
								${wc:escapeHtml4(t.xmlId.decoded)}
							</div>
							<div class="namespace" alt="${wc:escapeHtml4(t.namespace.decoded)}">
								${wc:escapeHtml4(t.namespace.decoded)}
							</div>
						</div>
						<div class="buttonContainer">
							<a href="${v:URLencode(t.namespace.encoded)}/${v:URLencode(t.xmlId.encoded)}/?csar" class="exportButton"></a>
							<a href="${v:URLencode(t.namespace.encoded)}/${v:URLencode(t.xmlId.encoded)}/?edit" class="editButton"></a>
							<%-- we need double encoding of the URL as the passing to javascript: decodes the given string once --%>
							<a href="javascript:deleteCI('${wc:escapeHtml4(t.xmlId.decoded)}', '${v:URLencode(v:URLencode(t.namespace.encoded))}/${v:URLencode(v:URLencode(t.xmlId.encoded))}/');" class="deleteButton" onclick="element = $(this).parent().parent().parent();"></a>
						</div>
					</div>
					<div class="right"></div>
				</div>
			</c:forEach>
			</td>
			<td id="gcprightcolumn" valign="top">
				<div id="overviewtopshadow"></div>
				<div id="overviewbottomshadow"></div>
			</td>
			<td valign="top">
				<div class="btn-group-vertical" id="buttonList">
					<button type="button" class="btn btn-default" onclick="openNewCIdiag();">Add new</button>
					<button type="button" class="btn btn-default" onclick="importCSAR();">Import CSAR</button>
				</div>
			</td>
		</tr>
	</table>
</div>

<script>

function entityContainerClicked(e) {
	var target = $(e.target);
	if (target.is("a")) {
		// do nothing as a nested a element is clicked
	} else {
		var ec = target.parents("div.entityContainer");
		var url = ec.attr('id');
		if (e.ctrlKey) {
			// emulate browser's default behavior to open a new tab
			window.open(url);
		} else {
			window.location = url;
		}
	}
}

$("div.entityContainer").on("click", entityContainerClicked);

/**
 * deletes given component instance
 * uses global variable "element", which stores the DOM element to delete upon successful deletion
 */
function deleteCI(name, URL) {
	deleteResource(name, URL, function() {
		element.remove();
	});
}

function importCSAR() {
	$('#upCSARDiag').modal('show');
}

// If export button is clicked with "CTRL", the plain XML is shown, not the CSAR
// We use "on" with filters instead as new elements could be added when pressing "Add new" (in the future)
// contained code is the same as the code of the CSAR button at the topology modeler (see index.jsp)
$(document).on("click", ".exportButton", function(evt) {
	var url = $(this).attr("href");
	if (evt.ctrlKey) {
		url = url.replace(/csar$/, "definitions");
	}
	window.open(url);
	return false;
});

<%-- Special feature in the case of the service template --%>
<c:if test="${it.type eq 'ServiceTemplate'}">
//If edit button is clicked with "CTRL", the topology modeler is opened, not the service template editor
//We use "on" with filters instead as new elements could be added when pressing "Add new" (in the future)
$(document).on("click", ".editButton", function(evt) {
	var url = $(this).attr("href");
	if (evt.ctrlKey) {
		url = url.replace(/\?edit$/, "topologytemplate/?edit");
		// open in new tab
		var newWin = window.open(url);
		// focussing the new window does not work in Chrome
		newWin.focus();
	} else {
		// normal behavior
		window.location = url;
	}
	evt.preventDefault();
});
</c:if>

$(".exportButton").tooltip({
	placement: 'bottom',
	html: true,
	title: "Export CSAR.<br/>Hold CTRL key to export XML only."
});
$(".editButton").tooltip({
	placement: 'bottom',
	html: true,
	title: <c:if test="${it.type eq 'ServiceTemplate'}">"Edit.<br/>Hold CTRL key to directly open the topology modeler."</c:if><c:if test="${not (it.type eq 'ServiceTemplate')}">"Edit"</c:if>
});
$(".deleteButton").tooltip({
	placement: 'bottom',
	title: "Delete"
});
</script>

</t:genericpage>