Skip to content

Commit

Permalink
Merge branch 'GUI' of http://git.vst.lan/cloud/polemarch into developer
Browse files Browse the repository at this point in the history
  • Loading branch information
onegreyonewhite committed Jul 14, 2017
2 parents 8da3f96 + 9c2cd2b commit 859eedc
Show file tree
Hide file tree
Showing 5 changed files with 220 additions and 52 deletions.
124 changes: 75 additions & 49 deletions polemarch/main/templates/gui/gui.html
Original file line number Diff line number Diff line change
Expand Up @@ -2601,7 +2601,7 @@ <h1>

<% if(jsonEditor.options[optionsblock] && jsonEditor.options[optionsblock][name]){ thisOpt = jsonEditor.options[optionsblock][name]; %>
<div class="form-group
<% if(thisOpt.type == 'textarea' ){ %> col-lg-12 <% }else{ %> col-lg-12 <% } %>
<% if(thisOpt.type == 'textarea' || thisOpt.type == 'textfile' ){ %> col-lg-12 <% }else{ %> col-lg-12 <% } %>
<% if(thisOpt.type == 'boolean' ){ %> boolean-select <% } %>"
id="json_<%- name %>_line">
<label
Expand All @@ -2611,38 +2611,22 @@ <h1>
>
<%- name %>
</label>
<div class="input-group col-sm-8 col-lg-9 " >
<% if(thisOpt.type == 'select' ){ %>
<select class="form-control jsonEditor-data"
id="json_<%- name %>_value"
data-json-name="<%- name %>"
data-type="<%- thisOpt.type %>" >
<% for(var i in thisOpt.options){ %>
<option value="<%- thisOpt.options[i] %>" <% if(value == thisOpt.options[i]){ %>selected<% } %>><%- thisOpt.options[i] %></option>
<% } %>
</select>
<% } else if(thisOpt.type == 'password' ){ %>
<input type="password"
placeholder="Enter value"
data-type="<%- thisOpt.type %>"
id="json_<%- name %>_value"
value="<%- value %>"
class="form-control jsonEditor-data"
data-json-name="<%- name %>"
>
<% } else if(thisOpt.type == 'boolean' ){ %>
<div class="form-control jsonEditor-data selected"
onselectstart="return false"
onmousedown="return false"
style="cursor: pointer;"
id="json_<%- name %>_value"
data-json-name="<%- name %>"
data-type="<%- thisOpt.type %>" >
<div class="ico-on fa fa-toggle-on"></div>
<div class="ico-off fa fa-toggle-off"></div>
<div class="boolean-title" >Boolean value</div>
</div>
<% } else if(thisOpt.type == 'textarea' ){ %>
<div class="input-group col-xs-12 col-sm-8 col-lg-9 " >

<% if(thisOpt.type == 'textfile' ){ %>
<% if(!thisOpt.required){ %>
<span class="btn btn-default btn-right" onclick="$('#json_<%- name %>_line').remove()" style="float: right; margin-left: 10px;" >
<span class="glyphicon glyphicon-remove"></span>
</span>
<% } %>
<span class="btn btn-default btn-right textfile"style="float: right; margin-left: 10px;" >
<input type="file" class="input-file" onchange="jsonEditor.loadFile(event, '#json_<%- name %>_value');" >
<span class="glyphicon glyphicon-file"></span>
</span>
<div style="clear: both; padding-top: 10px;" ></div>
<textarea
data-type="<%- thisOpt.type %>"
placeholder="Enter value"
Expand All @@ -2653,21 +2637,63 @@ <h1>
style="resize:vertical;"
><%- value %></textarea>
<% } else { %>
<input type="text"
data-type="text"
placeholder="Enter value"
id="json_<%- name %>_value"
value="<%- value %>"
class="form-control jsonEditor-data"
data-json-name="<%- name %>"
>
<% } %>
<% if(thisOpt.type == 'select' ){ %>
<select class="form-control jsonEditor-data"
id="json_<%- name %>_value"
data-json-name="<%- name %>"
data-type="<%- thisOpt.type %>" >
<% for(var i in thisOpt.options){ %>
<option value="<%- thisOpt.options[i] %>" <% if(value == thisOpt.options[i]){ %>selected<% } %>><%- thisOpt.options[i] %></option>
<% } %>
</select>
<% } else if(thisOpt.type == 'password' ){ %>
<input type="password"
placeholder="Enter value"
data-type="<%- thisOpt.type %>"
id="json_<%- name %>_value"
value="<%- value %>"
class="form-control jsonEditor-data"
data-json-name="<%- name %>"
>
<% } else if(thisOpt.type == 'boolean' ){ %>
<div class="form-control jsonEditor-data selected"
onselectstart="return false"
onmousedown="return false"
style="cursor: pointer;"
id="json_<%- name %>_value"
data-json-name="<%- name %>"
data-type="<%- thisOpt.type %>" >
<div class="ico-on fa fa-toggle-on"></div>
<div class="ico-off fa fa-toggle-off"></div>
<div class="boolean-title" >Boolean value</div>
</div>
<% } else if(thisOpt.type == 'textarea' ){ %>
<textarea
data-type="<%- thisOpt.type %>"
placeholder="Enter value"
id="json_<%- name %>_value"
class="form-control jsonEditor-data"
data-json-name="<%- name %>"
rows="4"
style="resize:vertical;"
><%- value %></textarea>
<% } else { %>
<input type="text"
data-type="text"
placeholder="Enter value"
id="json_<%- name %>_value"
value="<%- value %>"
class="form-control jsonEditor-data"
data-json-name="<%- name %>"
>
<% } %>
<% if(!thisOpt.required){ %>
<span class="input-group-addon btn btn-danger" onclick="$('#json_<%- name %>_line').remove()">
<span class="glyphicon glyphicon-remove"></span>
</span>
<% } %>
<% if(!thisOpt.required){ %>
<span class="input-group-addon btn btn-danger" onclick="$('#json_<%- name %>_line').remove()">
<span class="glyphicon glyphicon-remove"></span>
</span>
<% } %>
<% } %>
</div>
<% if(thisOpt.help){ %>
<span class="col-sm-8 col-lg-9 col-lg-offset-3 col-sm-offset-4 help-block" style="padding-left: 0px;"
Expand Down Expand Up @@ -2743,7 +2769,7 @@ <h1>
<label class=" col-sm-2 col-lg-2 control-label">
Name
</label>
<div class="input-group col-sm-10 col-lg-10" >
<div class="input-group col-sm-10 col-lg-10 col-xs-12" >
<input type="text" placeholder="Enter name" id="new_json_name" value="" class="form-control" >
<div class="help-block"></div>
</div>
Expand All @@ -2756,7 +2782,7 @@ <h1>
<label class="col-sm-2 col-lg-2 control-label">
Value
</label>
<div class="input-group col-sm-10 col-lg-10" >
<div class="input-group col-sm-10 col-lg-10 col-xs-12" >
<textarea placeholder="Enter value" id="new_json_value" class="form-control" style="resize:vertical;"></textarea>
<div class="help-block"></div>
</div>
Expand Down
3 changes: 1 addition & 2 deletions polemarch/main/templates/menu.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
{% load rest_framework %}
{% get_current_language as LANGUAGE_CODE %}{% get_current_language_bidi as LANGUAGE_BIDI %}

{% if user.is_authenticated %}
<li><a href="/help/" ><i class="fa fa-info"></i> <span>Help</span></a></li>
{% if user.is_authenticated %}
<li><a href="/api/"><i class="glyphicon glyphicon-star"></i> <span>{% trans 'API' %}</span></a></li>
{% endif %}

Expand Down
15 changes: 15 additions & 0 deletions polemarch/static/css/gui.css
Original file line number Diff line number Diff line change
Expand Up @@ -426,4 +426,19 @@ table{
.popover{
max-width: 272px;
}
}

.textfile{
position: relative;
}

.textfile .input-file{
position: absolute;
top: 0px;
left: 0px;
width: 100%;
height: 100%;
z-index: 1;
opacity: 0;
cursor: pointer;
}
24 changes: 23 additions & 1 deletion polemarch/static/js/jsonEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jsonEditor.options['item']['ansible_ssh_pass'] = {
}

jsonEditor.options['item']['ansible_ssh_private_key_file'] = {
type:'textarea',
type:'textfile',
help:'Inventory Parameter - ansible_ssh_private_key_file',
helpcontent:'Private key file used by ssh. Useful if using multiple keys and you don’t want to use SSH agent.'
}
Expand Down Expand Up @@ -568,3 +568,25 @@ jsonEditor.jsonEditorAddVar = function(optionsblock)
$("#jsonEditorVarList").append(spajs.just.render('jsonEditorLine', {name:name, value:value, optionsblock:optionsblock}))
}

jsonEditor.loadFile = function(event, element)
{
console.log("jsonEditor.loadFile", event.target.files)
for(var i=0; i<event.target.files.length; i++)
{
if( event.target.files[i].size > 1024*1024*1)
{
$.notify("File too large", "error");
console.log("File too large " + event.target.files[i].size)
continue;
}

var reader = new FileReader();
reader.onload = function(e)
{
$(element).val(e.target.result)
}

reader.readAsText(event.target.files[i]);
return;
}
}
106 changes: 106 additions & 0 deletions polemarch/static/js/pmTasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,109 @@ pmTasks.execute = function(project_id, inventory, playbook)

return def.promise();
}



/**
* Обновляет поле модел this.model.itemslist и ложит туда список пользователей
* Обновляет поле модел this.model.items и ложит туда список инфу о пользователях по их id
*/
pmTasks.loadItems = function(limit, offset)
{
if(!limit)
{
limit = 30;
}

if(!offset)
{
offset = 0;
}

var thisObj = this;
return jQuery.ajax({
url: "/api/v1/"+this.model.name+"/",
type: "GET",
contentType:'application/json',
data: "limit="+encodeURIComponent(limit)+"&offset="+encodeURIComponent(offset),
beforeSend: function(xhr, settings) {
if (!(/^http:.*/.test(settings.url) || /^https:.*/.test(settings.url))) {
// Only send the token to relative URLs i.e. locally.
xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken'));
}
},
success: function(data)
{
//console.log("update Items", data)
thisObj.model.itemslist = data
thisObj.model.itemslist.limit = limit
thisObj.model.itemslist.offset = offset


for(var i in data.results)
{
data.results[i].id = data.results[i].playbook
var val = data.results[i]
thisObj.model.items.justWatch(val.id);
thisObj.model.items[val.id] = mergeDeep(thisObj.model.items[val.id], val)
}
},
error:function(e)
{
console.warn(e)
polemarch.showErrors(e)
}
});
}

pmTasks.sendSearchQuery = function(query, limit, offset)
{
if(!limit)
{
limit = 999;
}

if(!offset)
{
offset = 0;
}

var q = [];
for(var i in query)
{
q.push(encodeURIComponent(i)+"="+encodeURIComponent(query[i]))
}

var thisObj = this;
return jQuery.ajax({
url: "/api/v1/"+this.model.name+"/?"+q.join('&'),
type: "GET",
contentType:'application/json',
data: "limit="+encodeURIComponent(limit)+"&offset="+encodeURIComponent(offset),
beforeSend: function(xhr, settings) {
if (!(/^http:.*/.test(settings.url) || /^https:.*/.test(settings.url))) {
// Only send the token to relative URLs i.e. locally.
xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken'));
}
},
success: function(data)
{
//console.log("update Items", data)
thisObj.model.itemslist = data

for(var i in data.results)
{
data.results[i].id = data.results[i].playbook

var val = data.results[i]
thisObj.model.items[val.id] = val
}
},
error:function(e)
{
console.warn(e)
polemarch.showErrors(e)
}
});
}

0 comments on commit 859eedc

Please sign in to comment.