|
3 | 3 | require_once("/usr/local/emhttp/plugins/compose.manager/php/defines.php"); |
4 | 4 | require_once("/usr/local/emhttp/plugins/compose.manager/php/util.php"); |
5 | 5 |
|
| 6 | +function createComboButton($text, $id, $onClick, $onClickParams, $items) { |
| 7 | + $o = ""; |
| 8 | + |
| 9 | + $o .= "<div class='combo-btn-group'>"; |
| 10 | + $o .= "<input type='button' value='$text' class='combo-btn-group-left' id='$id-left-btn' onclick='$onClick($onClickParams);'>"; |
| 11 | + $o .= "<section class='combo-btn-subgroup dropdown'>"; |
| 12 | + $o .= "<button type='button' class='dropdown-toggle combo-btn-group-right' data-toggle='dropdown'><i class='fa fa-caret-down'></i></button>"; |
| 13 | + $o .= "<div class='dropdown-content'>"; |
| 14 | + foreach ( $items as $item ) |
| 15 | + { |
| 16 | + $o .= "<a href='#' onclick='$onClick($onClickParams, "$item");'>$item</a>"; |
| 17 | + } |
| 18 | + $o .= "</div>"; |
| 19 | + $o .= "</section>"; |
| 20 | + $o .= "</div>"; |
| 21 | + |
| 22 | + return $o; |
| 23 | +} |
| 24 | + |
6 | 25 | $vars = parse_ini_file("/var/local/emhttp/var.ini"); |
7 | 26 |
|
8 | 27 | $stackstate = shell_exec($plugin_root."/scripts/compose.sh -c list"); |
|
69 | 88 | } |
70 | 89 | } |
71 | 90 |
|
| 91 | + $profiles = array(); |
| 92 | + if ( is_file("$compose_root/$project/profiles") ) { |
| 93 | + $profilestext = @file_get_contents("$compose_root/$project/profiles"); |
| 94 | + $profiles = json_decode($profilestext, false); |
| 95 | + } |
| 96 | + |
72 | 97 | $o .= "<tr><td width='30%' style='text-align:initial'>"; |
73 | 98 | $o .= "<font size='2'><span class='ca_nameEdit' id='name$id' data-nameName='$projectName' data-isup='$isup' data-scriptName=".escapeshellarg($project)." style='font-size:1.9rem;cursor:pointer;color:#ff8c2f;'><i class='fa fa-gear'></i></span> <b><span style='color:#ff8c2f;'>$projectName</span> </b></font>"; |
74 | 99 | if ( $isup ) { |
|
97 | 122 | $o .= "<span class='ca_descEdit' data-scriptName=".escapeshellarg($project)." id='desc$id'>$description</span>"; |
98 | 123 | $o .= "</td>"; |
99 | 124 | $o .= "<td width=25%></td>"; |
100 | | - $o .= "<td width=5%><input type='button' value='Compose Up' class='up$id' id='$id' onclick='ComposeUp("$compose_root/$project");'></td>"; |
101 | | - $o .= "<td width=5%><input type='button' value='Compose Down' class='down$id' id='$id' onclick='ComposeDown("$compose_root/$project");'></td>"; |
102 | | - $o .= "<td width=5%><input type='button' value='Update Stack' class='update$id' id='$id' onclick='UpdateStack("$compose_root/$project");'></td>"; |
103 | | - $o .= "<td width=5%><input type='checkbox' class='auto_start' data-scriptName=".escapeshellarg($project)." id='$id' style='display:none' $autostart></td>"; |
| 125 | + $buttons = [ |
| 126 | + ["Compose Up", "ComposeUp", "up"], |
| 127 | + ["Compose Down", "ComposeDown", "down"], |
| 128 | + ["Update Stack", "UpdateStack", "update"] |
| 129 | + ]; |
| 130 | + |
| 131 | + foreach ($buttons as $button) |
| 132 | + { |
| 133 | + $o .= "<td width=5%>"; |
| 134 | + if ( $profiles ) { |
| 135 | + // $onclick = $button[1]; |
| 136 | + $onClickParams = ""$compose_root/$project""; |
| 137 | + $o .= createComboButton($button[0], "$button[2]-$id", $button[1], $onClickParams, $profiles); |
| 138 | + } else { |
| 139 | + $o .= "<input type='button' value='$button[0]' class='$button[2]-button' id='$button[2]-$id' onclick='$button[1]("$compose_root/$project");'>"; |
| 140 | + } |
| 141 | + $o .= "</td>"; |
| 142 | + } |
| 143 | + |
| 144 | + $o .= "<td width=5%>"; |
| 145 | + $o .= "<input type='checkbox' class='auto_start' data-scriptName=".escapeshellarg($project)." id='autostart-$id' style='display:none' $autostart>"; |
| 146 | + $o .= "</td>"; |
104 | 147 | $o .= "</tr>"; |
105 | 148 | } |
106 | 149 | ?> |
|
116 | 159 | const webui_label = <?php echo json_encode($docker_label_webui); ?>; |
117 | 160 | const shell_label = <?php echo json_encode($docker_label_shell); ?>; |
118 | 161 |
|
| 162 | +$('head').append( $('<link rel="stylesheet" type="text/css" />').attr('href', '<?autov("/plugins/compose.manager/styles/comboButton.css");?>') ); |
| 163 | + |
119 | 164 | if (typeof swal2 === "undefined") { |
120 | 165 | $('head').append( $('<link rel="stylesheet" type="text/css" />').attr('href', '<?autov("/plugins/compose.manager/styles/sweetalert2.css");?>') ); |
121 | 166 | $.getScript( '/plugins/compose.manager/javascript/sweetalert/sweetalert2.min.js'); |
@@ -497,6 +542,47 @@ function generateOverride(myID, myProject=null) { |
497 | 542 | }); |
498 | 543 | } |
499 | 544 |
|
| 545 | +function generateProfiles(myID, myProject=null) { |
| 546 | + var project = myProject; |
| 547 | + if( myID ) { |
| 548 | + $("#"+myID).tooltipster("close"); |
| 549 | + project = $("#"+myID).attr("data-scriptname"); |
| 550 | + } |
| 551 | + |
| 552 | + $.post(caURL,{action:'getYml',script:project},function(rawComposefile) { |
| 553 | + var project_profiles = new Set(); |
| 554 | + if(rawComposefile) { |
| 555 | + var rawComposefile = jQuery.parseJSON(rawComposefile); |
| 556 | + |
| 557 | + if( (rawComposefile.result == 'success') ) { |
| 558 | + var main_doc = jsyaml.load(rawComposefile.content); |
| 559 | + |
| 560 | + for( var service_key in main_doc.services ) { |
| 561 | + var service = main_doc.services[service_key]; |
| 562 | + if( service.hasOwnProperty("profiles") ) { |
| 563 | + // console.log(service.profiles); |
| 564 | + for( const profile of service.profiles ) { |
| 565 | + project_profiles.add(profile); |
| 566 | + } |
| 567 | + } |
| 568 | + } |
| 569 | + |
| 570 | + // console.log(project_profiles); |
| 571 | + var rawProfiles = JSON.stringify(Array.from(project_profiles)); |
| 572 | + // console.log(rawProfiles); |
| 573 | + $.post(caURL,{action:"saveProfiles",script:project,scriptContents:rawProfiles},function(data) { |
| 574 | + if (!data) { |
| 575 | + swal2({ |
| 576 | + title: "Failed to update profiles.", |
| 577 | + icon: "error", |
| 578 | + }) |
| 579 | + } |
| 580 | + }); |
| 581 | + } |
| 582 | + } |
| 583 | + }); |
| 584 | +} |
| 585 | + |
500 | 586 | function editComposeFile(myID) { |
501 | 587 | var origID = myID; |
502 | 588 | $("#"+myID).tooltipster("close"); |
@@ -568,6 +654,7 @@ function saveEdit() { |
568 | 654 | $(".editing").hide(); |
569 | 655 | if (actionStr == 'saveYml') { |
570 | 656 | generateOverride(null,project); |
| 657 | + generateProfiles(null,project); |
571 | 658 | } |
572 | 659 | } |
573 | 660 | }); |
@@ -621,33 +708,33 @@ function editStackSettings(myID) { |
621 | 708 | }); |
622 | 709 | } |
623 | 710 |
|
624 | | -function ComposeUp(path) { |
| 711 | +function ComposeUp(path, profile="") { |
625 | 712 | var height = 800; |
626 | 713 | var width = 1200; |
627 | 714 |
|
628 | | - $.post(compURL,{action:'composeUp',path:path},function(data) { |
| 715 | + $.post(compURL,{action:'composeUp',path:path,profile:profile},function(data) { |
629 | 716 | if (data) { |
630 | 717 | openBox(data,"Stack "+basename(path)+" Up",height,width,true); |
631 | 718 | } |
632 | 719 | }) |
633 | 720 | } |
634 | 721 |
|
635 | | -function ComposeDown(path) { |
| 722 | +function ComposeDown(path, profile="") { |
636 | 723 | var height = 800; |
637 | 724 | var width = 1200; |
638 | 725 |
|
639 | | - $.post(compURL,{action:'composeDown',path:path},function(data) { |
| 726 | + $.post(compURL,{action:'composeDown',path:path,profile:profile},function(data) { |
640 | 727 | if (data) { |
641 | 728 | openBox(data,"Stack "+basename(path)+" Down",height,width,true); |
642 | 729 | } |
643 | 730 | }) |
644 | 731 | } |
645 | 732 |
|
646 | | -function UpdateStack(path) { |
| 733 | +function UpdateStack(path, profile="") { |
647 | 734 | var height = 800; |
648 | 735 | var width = 1200; |
649 | 736 |
|
650 | | - $.post(compURL,{action:'composeUpPullBuild',path:path},function(data) { |
| 737 | + $.post(compURL,{action:'composeUpPullBuild',path:path,profile:profile},function(data) { |
651 | 738 | if (data) { |
652 | 739 | openBox(data,"Update Stack "+basename(path),height,width,true); |
653 | 740 | } |
|
0 commit comments