deprecated-oc-search/views/search.tpl

152 lines
5.0 KiB
Smarty
Raw Normal View History

2023-08-26 22:04:56 +02:00
<!DOCTYPE html>
<html>
<head>
<title>o-search</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!--Import Google Icon Font-->
<link type="text/css" rel="stylesheet" href="/static/css/material-icons.css">
<!--Import materialize.css-->
<link type="text/css" rel="stylesheet" href="/static/css/materialize.min.css" media="screen,projection" />
<!--Let browser know website is optimized for mobile-->
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<style>
.small {
font-size: x-small;
}
</style>
<script type="text/javascript" src="/static/js/jquery-3.5.1.min.js"></script>
<script type="text/javascript">
$( document ).ready(function() {
$('.tooltipped').tooltip();
$('.fixed-action-btn').floatingActionButton({direction: 'bottom'});
;(function() {
jQuery.expr[':'].containsNC = function(elem, index, match) {
return (elem.textContent || elem.innerText || jQuery(elem).text() || '').toLowerCase().indexOf((match[3] || '').toLowerCase()) >= 0;
}
}(jQuery));
$('#filter').on('input',function(e)
{
if ($('#filter').val())
{
$('a')
.find('span').not(':containsNC('+$('#filter').val()+')')
.parent()
//.css('outline', '3px solid red');
.hide();
$('a')
.find('span:containsNC('+$('#filter').val()+')')
.parent()
//.css('outline', '3px solid red');
.show();
}
});
});
</script>
</head>
<body>
{{ template "floating_menu.tpl" . }}
<div class="row">
<div class="col s4">
<a href="/"><img src="/static/img/O-cloud.svg" width="40%" height="auto"/></a>
</div>
<div class="input-field col s8 offset-s0">
<i class="material-icons prefix">search</i>
<input id="search" type="text">
<label for="search">Search</label>
</div>
</div>
<div id="parentResults" class="collection">
{{range $key, $value := .list | searchResourceToList}}
<div class="row collection-item">
<a href="/details/{{$value | getRtype}}/{{$value | getID}}">
<div class="col s1">
<img src="data:image/png;base64,{{$value | getLogo}}" style="width: 50%; height: 50%"/>
</div>
<div class="col s10">
<span rtype="{{$value | getRtype}}" rid="{{$value | getID}}" class="title">{{$value | getName}}</span><br>
<span class="small">{{$value | getShortDescription}} </span>
<span class="small">[{{$value | getType}}]</span>
</div>
</a>
<div class="col s1">
<a id="addButton" onclick="submitWorkspace()" class="btn tooltipped gray waves-effect waves-light" data-position="bottom" data-tooltip="Add to Workspace" ><i class="material-icons">shopping_cart</i></a>
</div>
</div>
{{end}}
</div>
<script type="text/javascript" src="/static/js/materialize.min.js"></script>
</body>
{{ template "swagger.tpl" . }}
<script>
window.onload = setInitialStatus;
function setInitialStatus() {
oc_catalog_api.then(client => {
client.apis
.workspace
.WorkspaceController_Get_workspace()
.then(response => {
console.log(response);
Array.from(document.getElementById("parentResults").children).forEach((item) => {
elem = item.querySelector("*[rid]")
rid = elem.getAttribute("rid")
rtype = elem.getAttribute("rtype")
if ( response.body[rtype].includes(rid)) {
item.querySelector("*[id=addButton]").setAttribute("disabled", true);
} else {
item.querySelector("*[id=addButton]").removeAttribute("disabled");
}
});
})
.catch((error) => {
console.log("ERROR: " + error)
});
});
}
function submitWorkspace() {
var shopButton = event.target
var elem = shopButton.closest(".collection-item").querySelector("*[rid]")
var rid = elem.getAttribute("rid")
var rtype = elem.getAttribute("rtype")
//console.log(elem)
oc_catalog_api.then(client => {
client.apis
.workspace
.WorkspaceController_Add_model_to_workspace({id: rid, rtype: rtype})
.then(response => {
shopButton.parentNode.setAttribute("disabled", true);
shopButton.setAttribute("disabled", true);
})
.catch((error) => {
console.log("ERROR: " + error)
M.toast({html: 'already use!'});
});
});
}
</script>
</html>