Skip to content

Commit

Permalink
merging in pull request 8 from osmbsrn
Browse files Browse the repository at this point in the history
  • Loading branch information
donhenton committed May 1, 2020
2 parents e4b5531 + 36d2798 commit 22ad5e1
Show file tree
Hide file tree
Showing 11 changed files with 9,605 additions and 66 deletions.
9,410 changes: 9,410 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions public_html/mountebank-UI/assets/css/mountebank-UI.min.css

Large diffs are not rendered by default.

56 changes: 28 additions & 28 deletions public_html/mountebank-UI/assets/js/mountebank-UI.min.js

Large diffs are not rendered by default.

30 changes: 30 additions & 0 deletions public_html/mountebank-UI/sections/help/help_wait.tpl.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<div class="helpContainer">
<h3>Help for Wait</h3>


<div class="row">
<p>If a number is passed in, mountebank will wait that number of milliseconds before returning. If a string is
passed in, it is expected to be a parameterless JavaScript function that returns the number of milliseconds
to wait.</p>
</div>
<div class="row">
<div><em>Wait function sample</em></div>
<pre><code>
function() {
return Math.floor(Math.random() * 901) + 100;
}
</code></pre>
</div>

<div class="row">

<button ng-click="cancel()" style="margin:auto" class="btn btn-primary">Close</button>
</div>
<br>
<div class="row">

<em>Note that the Mountebank server must run with the --allowInjection flag</em>.
<a href="http://www.mbtest.org/docs/api/behaviors">Mountebank decoration documentation</a>
</div>

</div>
21 changes: 17 additions & 4 deletions public_html/mountebank-UI/sections/home/home.tpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ <h3>Imposters</h3>

<div class="row">

<div id="itemSelectorColumn" class="col-sm-2">
<div id="itemSelectorColumn" class="col-sm-4">


<div class="limitY">
Expand All @@ -41,7 +41,7 @@ <h3>Imposters</h3>



<button uib-tooltip={{item.documentation}} tooltip-placement="auto top" class="btn btn-sm btn-primary pull-right"
<button uib-tooltip={{item.documentation}} tooltip-placement="auto top" class="btn btn-sm btn-primary w-100 text-left"
style="margin: 5px"
ng-click="home.changeImposter($index)" id="imposter_{{$index}}">
<i ng-hide="$index != home.currentImposterIdx" class="glyphicon glyphicon-arrow-right"></i> {{home.composeImposterAlias($index)}}</button>
Expand All @@ -50,7 +50,7 @@ <h3>Imposters</h3>

</div>
<br>
<div class="row pull-left">
<div class="row pull-left mL0">

<button ng-click="home.addImposter()" class="btn btn-med btn-primary">Add New</button>

Expand All @@ -61,7 +61,7 @@ <h3>Imposters</h3>

</div>

<div id="formColumn" class="col-sm-10">
<div id="formColumn" class="col-sm-8">
<div class="row">
<form class="form-horizontal" novalidate>
<div class="form-group clearfix">
Expand Down Expand Up @@ -160,6 +160,19 @@ <h3>Imposters</h3>
</div>
</uib-accordion-group>

<uib-accordion-group heading="Wait">
<div class="injectionContainer">
<div>
<button class="btn btn-small" ng-click="home.formatWait(home.buffer.data.imposters[home.currentImposterIdx].responses[home.currentResponseIdx])" href="">Format</button>
<a ng-click="$event.preventDefault(); home.doHelpDisplay('Wait')" class="pull-right" href="">Decoration Help</a>
</div>
<br>
<div>
<textarea ng-blur="home.inputChange(this, $event)" class="form-control" ng-model="home.buffer.data.imposters[home.currentImposterIdx].responses[home.currentResponseIdx].wait" style="width:100%;height:350px"></textarea>
</div>
</div>
</uib-accordion-group>



</uib-accordion>
Expand Down
45 changes: 21 additions & 24 deletions src/mountebank-UI/app/app.constants.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
angular.module('app.constants',[])
.constant('TPL_PATH', getTemplatePath()) //used to prepend a set of folders for templates in app.routes
.constant('HEADER_LOCATION',getHeaderPath());

//localhost:8383/mountebank-UI/mountebank-UI/partials/plainHeader.tpl.html
function getTemplatePath()
{
var path = window.location.pathname;
var pathCol = path.split("/");
// console.log(pathCol);
var pathItem = 'http://' + window.location.host;

for (var i=0;i<pathCol.length-1;i++)
{
pathItem = pathItem + pathCol[i]+"/";
}

//pathItem is full url and app context
pathItem += 'mountebank-UI/';
//now in the folder that contains all the js
return pathItem;
angular.module('app.constants', [])
.constant('TPL_PATH', getTemplatePath()) //used to prepend a set of folders for templates in app.routes
.constant('HEADER_LOCATION', getHeaderPath());

//localhost:8383/mountebank-UI/mountebank-UI/partials/plainHeader.tpl.html
function getTemplatePath() {
var path = window.location.pathname;
var pathCol = path.split("/");
// console.log(pathCol);
var pathItem = window.location.protocol + '//' + window.location.host;

for (var i = 0; i < pathCol.length - 1; i++) {
pathItem = pathItem + pathCol[i] + "/";
}

//pathItem is full url and app context
pathItem += 'mountebank-UI/';
//now in the folder that contains all the js
return pathItem;
}

function getHeaderPath()
{
return getTemplatePath()+"partials/plainHeader.tpl.html";
function getHeaderPath() {
return getTemplatePath() + "partials/plainHeader.tpl.html";
}

12 changes: 12 additions & 0 deletions src/mountebank-UI/assets/css/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,15 @@ div.injectionContainer
{
border: #1b6d85 ridge; width:90%; padding:10px
}

.w-100 {
width: 100%;
}

.btn.text-left {
text-align: left;
}

.mL0 {
margin-left: 0px !important;
}
30 changes: 30 additions & 0 deletions src/mountebank-UI/sections/help/help_wait.tpl.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<div class="helpContainer">
<h3>Help for Wait</h3>


<div class="row">
<p>If a number is passed in, mountebank will wait that number of milliseconds before returning. If a string is
passed in, it is expected to be a parameterless JavaScript function that returns the number of milliseconds
to wait.</p>
</div>
<div class="row">
<div><em>Wait function sample</em></div>
<pre><code>
function() {
return Math.floor(Math.random() * 901) + 100;
}
</code></pre>
</div>

<div class="row">

<button ng-click="cancel()" style="margin:auto" class="btn btn-primary">Close</button>
</div>
<br>
<div class="row">

<em>Note that the Mountebank server must run with the --allowInjection flag</em>.
<a href="http://www.mbtest.org/docs/api/behaviors">Mountebank decoration documentation</a>
</div>

</div>
21 changes: 17 additions & 4 deletions src/mountebank-UI/sections/home/home.tpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ <h3>Imposters</h3>

<div class="row">

<div id="itemSelectorColumn" class="col-sm-2">
<div id="itemSelectorColumn" class="col-sm-4">


<div class="limitY">
Expand All @@ -41,7 +41,7 @@ <h3>Imposters</h3>



<button uib-tooltip={{item.documentation}} tooltip-placement="auto top" class="btn btn-sm btn-primary pull-right"
<button uib-tooltip={{item.documentation}} tooltip-placement="auto top" class="btn btn-sm btn-primary w-100 text-left"
style="margin: 5px"
ng-click="home.changeImposter($index)" id="imposter_{{$index}}">
<i ng-hide="$index != home.currentImposterIdx" class="glyphicon glyphicon-arrow-right"></i> {{home.composeImposterAlias($index)}}</button>
Expand All @@ -50,7 +50,7 @@ <h3>Imposters</h3>

</div>
<br>
<div class="row pull-left">
<div class="row pull-left mL0">

<button ng-click="home.addImposter()" class="btn btn-med btn-primary">Add New</button>

Expand All @@ -61,7 +61,7 @@ <h3>Imposters</h3>

</div>

<div id="formColumn" class="col-sm-10">
<div id="formColumn" class="col-sm-8">
<div class="row">
<form class="form-horizontal" novalidate>
<div class="form-group clearfix">
Expand Down Expand Up @@ -160,6 +160,19 @@ <h3>Imposters</h3>
</div>
</uib-accordion-group>

<uib-accordion-group heading="Wait">
<div class="injectionContainer">
<div>
<button class="btn btn-small" ng-click="home.formatWait(home.buffer.data.imposters[home.currentImposterIdx].responses[home.currentResponseIdx])" href="">Format</button>
<a ng-click="$event.preventDefault(); home.doHelpDisplay('Wait')" class="pull-right" href="">Decoration Help</a>
</div>
<br>
<div>
<textarea ng-blur="home.inputChange(this, $event)" class="form-control" ng-model="home.buffer.data.imposters[home.currentImposterIdx].responses[home.currentResponseIdx].wait" style="width:100%;height:350px"></textarea>
</div>
</div>
</uib-accordion-group>



</uib-accordion>
Expand Down
21 changes: 20 additions & 1 deletion src/mountebank-UI/sections/home/homePage.ctl.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,20 @@ angular.module('myApp')
}
currentResponse.decorate = js_beautify(currentResponse.decorate);
}

/**
* used to format the wait function if any
* @param {type} currentResponse
* @returns {undefined}
*/
vm.formatWait = function(currentResponse)
{
if (!currentResponse.wait)
{
currentResponse.wait = "";
}
currentResponse.wait = js_beautify(currentResponse.wait);
}

/**
* compose the display for the buttons that switch imposters or sort
Expand All @@ -340,11 +354,16 @@ angular.module('myApp')
*/
vm.composeImposterAlias = function(idx)
{
var verb = vm.buffer.data.imposters[idx].match.verb;
var imposter = vm.buffer.data.imposters[idx]
var verb = imposter.match.verb;
if (vm.buffer.data.imposters[idx].match.injection.use)
{
verb = "INJ";
}

if(imposter.documentation && imposter.documentation.length > 0) {
return "(" +verb+") " + imposter.documentation
}

return "Item "+(idx+1) +" (" +verb+")";
};
Expand Down
21 changes: 18 additions & 3 deletions src/mountebank-UI/services/mountebank.fct.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ function mountebankService($log, $http) {
isResponse["body"] = response.body;
}
var newResponse = {
"is": isResponse
"is": isResponse,
"_behaviors": {}
};
newStub.responses.push(newResponse);

Expand All @@ -142,12 +143,26 @@ function mountebankService($log, $http) {
response.decorate = "";
}
if (response.decorate.trim().length > 1) {
newResponse["_behaviors"] = {"decorate": response.decorate};
newResponse["_behaviors"] = Object.assign(newResponse["_behaviors"], {"decorate": response.decorate});
}

////decorate ///////////////////////////////

////wait ///////////////////////////////
if (!response.wait) {
response.wait = "";
}
if (response.wait.trim().length > 1) {
newResponse["_behaviors"] = Object.assign(newResponse["_behaviors"], {"wait": response.wait});
}

////decorate ///////////////////////////////
////wait ///////////////////////////////

var isBehaviorsExists = Object.keys(newResponse["_behaviors"]).length > 0;

if(!isBehaviorsExists) {
delete newResponse._behaviors
}

}// end if not using injection for response
})
Expand Down

0 comments on commit 22ad5e1

Please sign in to comment.