Skip to content

Commit

Permalink
closes issue #23
Browse files Browse the repository at this point in the history
  • Loading branch information
lukesUbuntu committed Jun 14, 2020
1 parent 4227ed8 commit 4656ce4
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 19 deletions.
35 changes: 26 additions & 9 deletions views/default/client_tab_scripts.pdt
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
<!--
@todo finish install options
@todo missing scripts already installed options
!-->
<style>
#install_error{
color:red;
}
.not_installed.removeScript{
display:none;
}
.installed.removeScript{
display:block;
}
.not_installed.install {
display:block;
}
.installed.install {
display:none;
}
</style>
<h4>Available Scripts</h4>

<?php

if ($this->Html->ifSet($script_list) && (count($script_list)) > 0) {
Expand Down Expand Up @@ -34,23 +46,26 @@ if ($this->Html->ifSet($script_list) && (count($script_list)) > 0) {

<div class="pull-right">
<?php
$class = "not_installed ";
if (isset($installed_scripts[strtolower($script['name'])])) {
$class = "installed ";
}
?>
<button data-script_name="<?php echo $script['name']; ?>" class="btn btn-warning removeScript" type="button"
<button data-script_name="<?php echo $script['name']; ?>" class="<?php echo $class?> btn btn-warning removeScript" type="button"
aria-expanded="true">
Remove
</button>

<?php
} else {

?>
<button data-script_name="<?php echo $script['name']; ?>" data-toggle="modal" data-target="#installScriptOptions" role="presentation" class="btn btn-success install " type="button"
<button data-script_name="<?php echo $script['name']; ?>" data-toggle="modal" data-target="#installScriptOptions" role="presentation" class="<?php echo $class?> btn btn-success install " type="button"
aria-expanded="true">
Install
</button>

<?php
}

?>

</div>
Expand Down Expand Up @@ -98,7 +113,9 @@ if ($this->Html->ifSet($script_list) && (count($script_list)) > 0) {
<div style="margin-top:5px;">http://<?php echo $service_fields->virtualmin_domain; ?>/<span class="install_path"></span></div>
</div>
</div>
<div class="modal-body"> <span id="install_error"></span></div>
<div class="modal-footer">

<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<a id="installScript" href="#" class="save_email_forward btn btn-success success">Install</a>
</div>
Expand Down
19 changes: 11 additions & 8 deletions views/default/js/client_tab_scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ $(".install").click(function(e){

$(".script_name").text(script_name);
$(".script_description").text(script['description']);
console.log("TCL: script", script)
console.log("TCL: available_versions", available_versions)
for (var version_index in available_versions) {
var version = available_versions[version_index];
var option = new Option(version, version);
Expand All @@ -31,7 +29,6 @@ $(".install").click(function(e){
$(".install_path").text(cleanScriptName(script_name))

// $(".script_name").text(script_name)
// console.log("TCL: script_name", script_name)
})


Expand All @@ -41,19 +38,20 @@ $("#install_path").keyup(function(){

$(".removeScript").click(function(){
script_name = $(this).data('script_name');

var formData = {

action : 'remove_script',
script_name : script_name
}
console.log("TCL: formData", formData)
sendRequest(formData, function(response) {
console.log("TCL: response", response)


$(this).removeClass('installed').addClass('not_installed')

});
})
$("#installScript").click(function(){
var $this = $(this);
var formData = {
action : 'script_install',
script_name : script_name
Expand All @@ -62,12 +60,17 @@ $("#installScript").click(function(){
$(".form-control").each(function(a,b){
formData[$(b).attr('id')] = $(b).val();
})
console.log("TCL: formData", formData)



sendRequest(formData, function(response) {
console.log("TCL: response", response)
//mysql database (.*) already exists
console.log("TCL: response", response.success)
if (response.success == false){
$("#install_error").text(response.data);
}else{
$this.removeClass('not_installed').addClass('installed')
}


});
Expand Down
18 changes: 16 additions & 2 deletions virtualmin_blesta.php
Original file line number Diff line number Diff line change
Expand Up @@ -2110,6 +2110,12 @@ public function script_install($postRequest, $dataRequest = array()){

$service_fields = $this->serviceFieldsToObject($service->fields);

$install_path = $postRequest['install_path'];
if (strlen($install_path) > 0){
if (substr($postRequest['install_path'],0,1) != '/'){
$install_path = "/$install_path";
}
}
// todo recreate curl request could be a bug with virtualmin that needs to be reported, currently after a script install virtualmin returns a 500 status will check with other virtualmin install
$type = strtolower($postRequest['script_name']);
$prams = [
Expand All @@ -2121,8 +2127,16 @@ public function script_install($postRequest, $dataRequest = array()){
"newdb" => ''
];
try {
$test = $this->api()->install_script($prams); //receiving 500 error but installs script
print_r($test);exit;
$install_response = $this->api()->install_script($prams); //receiving 500 error but installs script
//print_r($install_response);exit;
if (isset($install_response->status) && isset($install_response->error)){
$this->getVirtualMinHelper()->sendAjax($install_response->error, false);
return;
}

$this->getVirtualMinHelper()->sendAjax($install_response->output);


}
catch (Exception $e) {
print_r($e);
Expand Down

0 comments on commit 4656ce4

Please sign in to comment.