Skip to content

Commit 3b61002

Browse files
author
frostwind
committed
Added edit
1 parent 9e7da09 commit 3b61002

File tree

6 files changed

+186
-14
lines changed

6 files changed

+186
-14
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
_ = require 'underscore'
2+
3+
module.exports = class
4+
@$inject: ['$scope', '$http', '$location']
5+
constructor: (@scope, @http, @location) ->
6+
@scope.test =
7+
name: ''
8+
description: ''
9+
baseUrl: ''
10+
requests: 0
11+
concurrency: 0
12+
tasks: []
13+
14+
@addTask()
15+
16+
angular.extend @scope,
17+
save: @save
18+
addTask: @addTask
19+
removeTask: @removeTask
20+
addHeader: @addHeader
21+
removeHeader: @removeHeader
22+
23+
addTask: () =>
24+
@scope.test.tasks.push
25+
method: 'GET'
26+
path: ''
27+
headers: []
28+
rawBody: ''
29+
30+
removeTask: (task) =>
31+
@scope.test.tasks = _(@scope.test.tasks).reject (t) ->
32+
t is task
33+
34+
addHeader: (task) =>
35+
task.headers.push
36+
field: ''
37+
value: ''
38+
39+
removeHeader: (task, header) =>
40+
task.headers = _(task.headers).reject (h) ->
41+
h is header
42+
43+
save: (run = false) =>
44+
console.log @scope.test
45+
@http.post '/api/tests', @scope.test
46+
.success (res) =>
47+
if run is true
48+
@location.path '/tests/'+res._id
49+
else
50+
@location.path '/tests'
51+
console.debug 'Your test has been saved'
52+
.error (err) =>
53+
console.debug 'An error occured'

assets/javascripts/controllers/new_test.coffee

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
_ = require 'underscore'
22

33
module.exports = class
4-
@$inject: ['$scope', '$http', '$location']
5-
constructor: (@scope, @http, @location) ->
4+
@$inject: ['$scope', '$http', '$location', '$routeParams']
5+
constructor: (@scope, @http, @location, @params) ->
66
@scope.test =
77
name: ''
88
description: ''
@@ -11,7 +11,12 @@ module.exports = class
1111
concurrency: 0
1212
tasks: []
1313

14-
@addTask()
14+
if @params.id?
15+
@http.get '/api/tests/'+@params.id
16+
.success (res) =>
17+
@scope.test = res
18+
else
19+
@addTask()
1520

1621
angular.extend @scope,
1722
save: @save

assets/javascripts/index.coffee

+4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ class Config
2121
templateUrl: 'views/start_test.html'
2222
controller: 'StartTestController'
2323

24+
.when '/tests/:id/edit',
25+
templateUrl: 'views/new_test.html'
26+
controller: 'NewTestController'
27+
2428
.otherwise
2529
redirectTo: '/'
2630

assets/javascripts/modules/app.controllers.coffee

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
app = angular.module 'app.controllers', []
22

33
app.controller 'NewTestController', require '../controllers/new_test'
4+
app.controller 'EditTestController', require '../controllers/edit_test'
45
app.controller 'AllTestsController', require '../controllers/all_tests'
56
app.controller 'StartTestController', require '../controllers/start_test'
67

gopherling.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,12 @@ func addTest(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
5555

5656
tests := database.C("tests")
5757

58-
t.Id = bson.NewObjectId()
58+
// i'm in a hurry :p
59+
if len(t.Id) > 0 {
60+
err = database.C("tests").RemoveId(t.Id)
61+
}
5962

63+
t.Id = bson.NewObjectId()
6064
err = tests.Insert(&t)
6165

6266
if err != nil {

static/javascripts/app.js

+115-10
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ Config = (function() {
1717
}).when('/tests/:id', {
1818
templateUrl: 'views/start_test.html',
1919
controller: 'StartTestController'
20+
}).when('/tests/:id/edit', {
21+
templateUrl: 'views/new_test.html',
22+
controller: 'NewTestController'
2023
}).otherwise({
2124
redirectTo: '/'
2225
});
@@ -30,7 +33,7 @@ angular.module('app').config(['$routeProvider', '$locationProvider', Config]);
3033

3134

3235

33-
},{"./modules/app":5}],2:[function(require,module,exports){
36+
},{"./modules/app":6}],2:[function(require,module,exports){
3437
var _,
3538
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
3639

@@ -73,7 +76,7 @@ module.exports = (function() {
7376

7477

7578

76-
},{"underscore":10}],3:[function(require,module,exports){
79+
},{"underscore":11}],3:[function(require,module,exports){
7780
var _,
7881
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
7982

@@ -164,7 +167,107 @@ module.exports = (function() {
164167

165168

166169

167-
},{"underscore":10}],4:[function(require,module,exports){
170+
},{"underscore":11}],4:[function(require,module,exports){
171+
var _,
172+
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
173+
174+
_ = require('underscore');
175+
176+
module.exports = (function() {
177+
_Class.$inject = ['$scope', '$http', '$location', '$routeParams'];
178+
179+
function _Class(scope, http, location, params) {
180+
this.scope = scope;
181+
this.http = http;
182+
this.location = location;
183+
this.params = params;
184+
this.save = __bind(this.save, this);
185+
this.removeHeader = __bind(this.removeHeader, this);
186+
this.addHeader = __bind(this.addHeader, this);
187+
this.removeTask = __bind(this.removeTask, this);
188+
this.addTask = __bind(this.addTask, this);
189+
this.scope.test = {
190+
name: '',
191+
description: '',
192+
baseUrl: '',
193+
requests: 0,
194+
concurrency: 0,
195+
tasks: []
196+
};
197+
if (this.params.id != null) {
198+
this.http.get('/api/tests/' + this.params.id).success((function(_this) {
199+
return function(res) {
200+
return _this.scope.test = res;
201+
};
202+
})(this));
203+
} else {
204+
this.addTask();
205+
}
206+
angular.extend(this.scope, {
207+
save: this.save,
208+
addTask: this.addTask,
209+
removeTask: this.removeTask,
210+
addHeader: this.addHeader,
211+
removeHeader: this.removeHeader
212+
});
213+
}
214+
215+
_Class.prototype.addTask = function() {
216+
return this.scope.test.tasks.push({
217+
method: 'GET',
218+
path: '',
219+
headers: [],
220+
rawBody: ''
221+
});
222+
};
223+
224+
_Class.prototype.removeTask = function(task) {
225+
return this.scope.test.tasks = _(this.scope.test.tasks).reject(function(t) {
226+
return t === task;
227+
});
228+
};
229+
230+
_Class.prototype.addHeader = function(task) {
231+
return task.headers.push({
232+
field: '',
233+
value: ''
234+
});
235+
};
236+
237+
_Class.prototype.removeHeader = function(task, header) {
238+
return task.headers = _(task.headers).reject(function(h) {
239+
return h === header;
240+
});
241+
};
242+
243+
_Class.prototype.save = function(run) {
244+
if (run == null) {
245+
run = false;
246+
}
247+
console.log(this.scope.test);
248+
return this.http.post('/api/tests', this.scope.test).success((function(_this) {
249+
return function(res) {
250+
if (run === true) {
251+
_this.location.path('/tests/' + res._id);
252+
} else {
253+
_this.location.path('/tests');
254+
}
255+
return console.debug('Your test has been saved');
256+
};
257+
})(this)).error((function(_this) {
258+
return function(err) {
259+
return console.debug('An error occured');
260+
};
261+
})(this));
262+
};
263+
264+
return _Class;
265+
266+
})();
267+
268+
269+
270+
},{"underscore":11}],5:[function(require,module,exports){
168271
module.exports = (function() {
169272
_Class.$inject = ['$scope', '$http', '$routeParams', '$location', '$websocket'];
170273

@@ -256,7 +359,7 @@ module.exports = (function() {
256359

257360

258361

259-
},{}],5:[function(require,module,exports){
362+
},{}],6:[function(require,module,exports){
260363
var app;
261364

262365
require('angular');
@@ -273,13 +376,15 @@ module.exports = app;
273376

274377

275378

276-
},{"./app.controllers":6,"angular":9,"angular-route":7,"angular-websocket":8}],6:[function(require,module,exports){
379+
},{"./app.controllers":7,"angular":10,"angular-route":8,"angular-websocket":9}],7:[function(require,module,exports){
277380
var app;
278381

279382
app = angular.module('app.controllers', []);
280383

281384
app.controller('NewTestController', require('../controllers/new_test'));
282385

386+
app.controller('EditTestController', require('../controllers/edit_test'));
387+
283388
app.controller('AllTestsController', require('../controllers/all_tests'));
284389

285390
app.controller('StartTestController', require('../controllers/start_test'));
@@ -288,7 +393,7 @@ module.exports = app;
288393

289394

290395

291-
},{"../controllers/all_tests":2,"../controllers/new_test":3,"../controllers/start_test":4}],7:[function(require,module,exports){
396+
},{"../controllers/all_tests":2,"../controllers/edit_test":3,"../controllers/new_test":4,"../controllers/start_test":5}],8:[function(require,module,exports){
292397
/**
293398
* @license AngularJS v1.3.8
294399
* (c) 2010-2014 Google, Inc. http://angularjs.org
@@ -1285,10 +1390,10 @@ function ngViewFillContentFactory($compile, $controller, $route) {
12851390

12861391
})(window, window.angular);
12871392

1288-
},{}],8:[function(require,module,exports){
1393+
},{}],9:[function(require,module,exports){
12891394
!function(){"use strict";function t(t,e,o,u){function p(e,o,r){r||!c(o)||l(o)||(r=o,o=void 0),this.protocols=o,this.url=e||"Missing URL",this.ssl=/(wss)/i.test(this.url),this.scope=r&&r.scope||t,this.rootScopeFailover=r&&r.rootScopeFailover&&!0,this._reconnectAttempts=r&&r.reconnectAttempts||0,this.initialTimeout=r&&r.initialTimeout||500,this.maxTimeout=r&&r.maxTimeout||3e5,this.sendQueue=[],this.onOpenCallbacks=[],this.onMessageCallbacks=[],this.onErrorCallbacks=[],this.onCloseCallbacks=[],n(this._readyStateConstants),e?this._connect():this._setInternalState(0)}return p.prototype._readyStateConstants={CONNECTING:0,OPEN:1,CLOSING:2,CLOSED:3,RECONNECT_ABORTED:4},p.prototype._reconnectableStatusCodes=[4e3],p.prototype.safeDigest=function(t){t&&!this.scope.$$phase&&this.scope.$digest()},p.prototype.bindToScope=function(e){return e&&(this.scope=e,this.rootScopeFailover&&this.scope.$on("$destroy",function(){this.scope=t})),this},p.prototype._connect=function(t){(t||!this.socket||this.socket.readyState!==this._readyStateConstants.OPEN)&&(this.socket=u.create(this.url,this.protocols),this.socket.onopen=this._onOpenHandler.bind(this),this.socket.onmessage=this._onMessageHandler.bind(this),this.socket.onerror=this._onErrorHandler.bind(this),this.socket.onclose=this._onCloseHandler.bind(this))},p.prototype.fireQueue=function(){for(;this.sendQueue.length&&this.socket.readyState===this._readyStateConstants.OPEN;){var t=this.sendQueue.shift();this.socket.send(s(t.message)?t.message:JSON.stringify(t.message)),t.deferred.resolve()}},p.prototype.notifyOpenCallbacks=function(){for(var t=0;t<this.onOpenCallbacks.length;t++)this.onOpenCallbacks[t].call(this)},p.prototype.notifyCloseCallbacks=function(t){for(var e=0;e<this.onCloseCallbacks.length;e++)this.onCloseCallbacks[e].call(this,t)},p.prototype.notifyErrorCallbacks=function(t){for(var e=0;e<this.onErrorCallbacks.length;e++)this.onErrorCallbacks[e].call(this,t)},p.prototype.onOpen=function(t){return this.onOpenCallbacks.push(t),this},p.prototype.onClose=function(t){return this.onCloseCallbacks.push(t),this},p.prototype.onError=function(t){return this.onErrorCallbacks.push(t),this},p.prototype.onMessage=function(t,e){if(!i(t))throw new Error("Callback must be a function");if(e&&a(e.filter)&&!s(e.filter)&&!(e.filter instanceof RegExp))throw new Error("Pattern must be a string or regular expression");return this.onMessageCallbacks.push({fn:t,pattern:e?e.filter:void 0,autoApply:e?e.autoApply:!0}),this},p.prototype._onOpenHandler=function(){this._reconnectAttempts=0,this.notifyOpenCallbacks(),this.fireQueue()},p.prototype._onCloseHandler=function(t){this.notifyCloseCallbacks(t),this._reconnectableStatusCodes.indexOf(t.code)>-1&&this.reconnect()},p.prototype._onErrorHandler=function(t){this.notifyErrorCallbacks(t)},p.prototype._onMessageHandler=function(t){for(var e,o,n=this,r=0;r<n.onMessageCallbacks.length;r++)o=n.onMessageCallbacks[r],e=o.pattern,e?s(e)&&t.data===e?(o.fn.call(n,t),n.safeDigest(o.autoApply)):e instanceof RegExp&&e.exec(t.data)&&(o.fn.call(n,t),n.safeDigest(o.autoApply)):(o.fn.call(n,t),n.safeDigest(o.autoApply))},p.prototype.close=function(t){return(t||!this.socket.bufferedAmount)&&this.socket.close(),this},p.prototype.send=function(t){function o(t){t.cancel=n;var e=t.then;return t.then=function(){var t=e.apply(this,arguments);return o(t)},t}function n(e){return s.sendQueue.splice(s.sendQueue.indexOf(t),1),r.reject(e),s}var r=e.defer(),s=this,i=o(r.promise);return s.readyState===s._readyStateConstants.RECONNECT_ABORTED?r.reject("Socket connection has been closed"):(s.sendQueue.push({message:t,deferred:r}),s.fireQueue()),i},p.prototype.reconnect=function(){var t=this;return t.close(),o(t._connect,t._getBackoffDelay(++t._reconnectAttempts)),t},p.prototype._getBackoffDelay=function(t){var e=Math.random()+1,o=this.initialTimeout,n=2,r=t,s=this.maxTimeout;return Math.floor(Math.min(e*o*Math.pow(n,r),s))},p.prototype._setInternalState=function(t){if(Math.floor(t)!==t||0>t||t>4)throw new Error("state must be an integer between 0 and 4, got: "+t);r||(this.readyState=t||this.socket.readyState),this._internalConnectionState=t,angular.forEach(this.sendQueue,function(t){t.deferred.reject("Message cancelled due to closed socket connection")})},r&&r(p.prototype,"readyState",{get:function(){return this._internalConnectionState||this.socket.readyState},set:function(){throw new Error("The readyState property is read-only")}}),function(t,e){return new p(t,e)}}function e(t,e){this.create=function(e,o){var n,r,s=/wss?:\/\//.exec(e);if(!s)throw new Error("Invalid url provided");if("object"==typeof exports&&require)try{r=require("ws"),n=r.Client||r.client||r}catch(i){}return n=n||t.WebSocket||t.MozWebSocket,o?new n(e,o):new n(e)},this.createWebSocketBackend=function(t,o){return e.warn("Deprecated: Please use .create(url, protocols)"),this.create(t,o)}}var o=angular.noop,n=Object.freeze?Object.freeze:o,r=Object.defineProperty,s=angular.isString,i=angular.isFunction,a=angular.isDefined,c=angular.isObject,l=angular.isArray,u=Array.prototype.slice;Array.prototype.indexOf||(Array.prototype.indexOf=function(t){var e=this.length>>>0,o=Number(arguments[1])||0;for(o=0>o?Math.ceil(o):Math.floor(o),0>o&&(o+=e);e>o;o++)if(o in this&&this[o]===t)return o;return-1}),Function.prototype.bind||(Function.prototype.bind=function(t){if("function"!=typeof this)throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable");var e=u.call(arguments,1),o=this,n=function(){},r=function(){return o.apply(this instanceof n&&t?this:t,e.concat(u.call(arguments)))};return n.prototype=this.prototype,r.prototype=new n,r}),angular.module("ngWebSocket",[]).factory("$websocket",["$rootScope","$q","$timeout","$websocketBackend",t]).factory("WebSocket",["$rootScope","$q","$timeout","WebsocketBackend",t]).service("$websocketBackend",["$window","$log",e]).service("WebSocketBackend",["$window","$log",e]),angular.module("angular-websocket",["ngWebSocket"])}();
12901395
//# sourceMappingURL=angular-websocket.min.js.map
1291-
},{"ws":11}],9:[function(require,module,exports){
1396+
},{"ws":12}],10:[function(require,module,exports){
12921397
/**
12931398
* @license AngularJS v1.3.8
12941399
* (c) 2010-2014 Google, Inc. http://angularjs.org
@@ -27359,7 +27464,7 @@ var styleDirective = valueFn({
2735927464
})(window, document);
2736027465

2736127466
!window.angular.$$csp() && window.angular.element(document).find('head').prepend('<style type="text/css">@charset "UTF-8";[ng\\:cloak],[ng-cloak],[data-ng-cloak],[x-ng-cloak],.ng-cloak,.x-ng-cloak,.ng-hide:not(.ng-hide-animate){display:none !important;}ng\\:form{display:block;}</style>');
27362-
},{}],10:[function(require,module,exports){
27467+
},{}],11:[function(require,module,exports){
2736327468
// Underscore.js 1.7.0
2736427469
// http://underscorejs.org
2736527470
// (c) 2009-2014 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
@@ -28776,7 +28881,7 @@ var styleDirective = valueFn({
2877628881
}
2877728882
}.call(this));
2877828883

28779-
},{}],11:[function(require,module,exports){
28884+
},{}],12:[function(require,module,exports){
2878028885

2878128886
/**
2878228887
* Module dependencies.

0 commit comments

Comments
 (0)