Skip to content

Commit 708a2b9

Browse files
committed
more updates
1 parent 3bd0a35 commit 708a2b9

File tree

7 files changed

+253
-68
lines changed

7 files changed

+253
-68
lines changed

js/models/method.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ define([
55
], function(_, Backbone, Session) {
66
var MethodModel = Backbone.Model.extend({
77
urlRoot: function () {
8-
if (typeof this.get('api') !== 'undefined') {
9-
return '/user/' +this.get('username')+ '/api/' +this.get('api')+ '/' + this.get('version') + '/resource/' + this.get('resourceId');
8+
if (typeof this.get('method') !== 'undefined') {
9+
return '/user/' +this.get('username')+ '/api/' +this.get('api')+ '/' + this.get('version') + '/resource/' + this.get('resourceId') + '/' + this.get('method');
1010
} else {
11-
return '/user/' +this.get('username')+ '/api';
11+
return '/user/' +this.get('username')+ '/api/' +this.get('api')+ '/' + this.get('version') + '/resource/' + this.get('resourceId');
1212
}
1313
}
1414
});

js/router.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ define([
1717
'login': 'login',
1818
'register': 'register',
1919
'': 'home',
20+
':username/:apiname/version/:version/resource/:resource/:method': 'apiPage',
2021
':username/:apiname/version/:version/resource/:resource': 'apiPage',
2122
':username/:apiname/version/:version': 'apiPage',
2223
':username': 'defaultAction' // All urls will trigger this route
@@ -27,9 +28,9 @@ define([
2728

2829
var appView = options.appView;
2930
var router = new AppRouter(options);
30-
router.on('route:apiPage', function (username, apiname, version, resourceId) {
31+
router.on('route:apiPage', function (username, apiname, version, resourceId, method) {
3132
require(['views/apis/details'], function (ApiDetailsView) {
32-
var apiDetailsView = Vm.create(appView, 'ApiDetailsView', ApiDetailsView, {username: username, apiname: apiname, version: version, resourceId: resourceId});
33+
var apiDetailsView = Vm.create(appView, 'ApiDetailsView', ApiDetailsView, {username: username, apiname: apiname, version: version, resourceId: resourceId, method: method});
3334
apiDetailsView.render();
3435
});
3536
});

js/views/apis/details.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ define([
1515
'models/api',
1616
'models/resource',
1717
'models/method',
18-
'libs/highlight/highlight'
19-
], function($, _, Backbone, Bootstrap, Router, Vm, Session, apiDetailsTemplate, ApiModel, MethodsCollection, MethodsListView, ResourceListView, MethodDetailView, ApiModel, ResourceModel, MethodModel, hljs){
18+
'libs/highlight/highlight',
19+
'views/methods/details'
20+
], function($, _, Backbone, Bootstrap, Router, Vm, Session, apiDetailsTemplate, ApiModel, MethodsCollection, MethodsListView, ResourceListView, MethodDetailView, ApiModel, ResourceModel, MethodModel, hljs, MethodView){
2021
var NewApiPage = Backbone.View.extend({
2122
el: '.page',
2223
initialize: function () {
@@ -92,6 +93,10 @@ define([
9293
var methodListView = new MethodsListView({username: that.options.username, api: that.options.apiname, version: that.options.version, resourceId: that.options.resourceId});
9394
methodListView.render();
9495
}
96+
if(typeof that.options.method !== 'undefined') {
97+
var methodView = new MethodView({username: that.options.username, api: that.options.apiname, version: that.options.version, resourceId: that.options.resourceId, method: that.options.method});
98+
methodView.render();
99+
}
95100
/*
96101
var owner = false;
97102
if(Session.get('user_id') === api.get('UserId')){

js/views/methods/details.js

Lines changed: 14 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -5,70 +5,31 @@ define([
55
'router',
66
'models/session',
77
'text!templates/methods/details.html',
8-
'models/method',
9-
'models/request',
10-
'views/request/details',
11-
'collections/requests'
12-
], function($, _, Backbone, Router, Session, methodTemplate, MethodModel, RequestModel, RequestDetailsView, RequestCollection){
8+
'models/method'
9+
], function($, _, Backbone, Router, Session, methodTemplate, MethodModel){
1310
var MethodDetailsView = Backbone.View.extend({
1411
el: '.method-container',
1512
initialize: function () {
1613
var that = this;
1714

1815
},
19-
events: {
20-
'click .js-new-request': 'newRequest'
21-
},
22-
newRequest: function (ev) {
23-
24-
$(ev.currentTarget).text('Adding request').attr('disabled', 'disabled');
25-
var that = this;
26-
var requestModel = new RequestModel();
27-
requestModel.save({
28-
name: 'No name',
29-
description: 'No Description',
30-
requestBody: '{"hello": "world"}',
31-
responseBody: '{"hello": "world"}',
32-
MethodId: this.options.methodId
33-
}, {
34-
success: function (request) {
35-
$(ev.currentTarget).text('New request').removeAttr('disabled');
36-
that.$el.append('<div data-request-id="'+request.id+'"></div>');
37-
var requestView = new RequestDetailsView({request: request, el: '[data-request-id="'+request.id+'"]', owner: true});
38-
requestView.render();
39-
}
40-
});
41-
},
16+
4217
render: function () {
43-
$('[data-method-id]').removeClass('active');
44-
$('[data-method-id="'+this.options.methodId+'"]').addClass('active');
4518
var that = this;
46-
this.$el.html('loading');
47-
var methodModel = new MethodModel({id: this.options.methodId});
19+
var methodModel = new MethodModel();
20+
methodModel.set({
21+
method: this.options.method,
22+
version: this.options.version,
23+
api: this.options.api,
24+
username: this.options.username,
25+
resourceId: this.options.resourceId
26+
});
4827
methodModel.fetch({
49-
success: function (method) {
50-
that.$el.html(_.template(methodTemplate, {method: method, owner: that.options.owner}));
51-
var requestCollection = new RequestCollection();
52-
requestCollection.methodId = method.id;
53-
54-
requestCollection.fetch({
55-
success: function (requests) {
28+
success: function(model) {
29+
that.$el.html(_.template(methodTemplate, {method: model}));
5630

57-
$('.requests-container', that.$el).html('');
58-
_.each(requests.models, function(request) {
59-
that.$el.append('<div data-request-id="'+request.id+'"></div>');
60-
var requestView = new RequestDetailsView({request: request, el: '[data-request-id="'+request.id+'"]', owner: that.options.owner});
61-
requestView.render();
62-
});
63-
if(requests.models.length === 0) {
64-
65-
$('.requests-container', that.$el).html('No request');
66-
}
67-
68-
}
69-
});
7031
}
71-
});
32+
})
7233
}
7334
});
7435
return MethodDetailsView;

templates/apis/details.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ <h4 class="alert-heading">Warning!</h4>
127127
</div>
128128
</div>
129129
<div class="span8">
130+
<div class="method-container">
131+
</div>
130132
Page
131133
</div>
132134

templates/methods/details.html

Lines changed: 222 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,222 @@
1-
<h1><%= method.get('type') %> - <%= method.get('resource') %></h1>
2-
<hr />
3-
<% if(owner) {%>
4-
<a class="btn js-new-request">New Request</a><hr />
5-
<% }; %>
6-
<div class="requests-container">Loading request</div>
1+
<div class="span12">
2+
<h2>Users - Update a user</h2>
3+
<code class="xml" style="display: block; width: 100%; margin-top: 10px; margin-bottom: 20px;">
4+
<%= method.get('method') %> - /user/{user}
5+
</code>
6+
7+
<p>Google Compute Engine offers scalable and flexible virtual machine computing capabilities in the cloud. With Google Compute Engine, you can solve large scale processing and analytic problems on Google’s computing, storage, and networking infrastructure.<p>
8+
<hr>
9+
<style>
10+
.matchpre td {
11+
border: 1px solid #000;
12+
}
13+
.table td {
14+
border-bottom: none;
15+
}
16+
</style>
17+
<h3>Request</h3>
18+
<h4>Headers</h4>
19+
20+
<table class="table request-table">
21+
<thead>
22+
<tr>
23+
<th>Property Name</th>
24+
<th>Value</th>
25+
<th>Description</th>
26+
<th>Actions</th>
27+
</tr>
28+
</thead>
29+
<tbody>
30+
31+
<tr id="items">
32+
<td><code>Accept</code></td>
33+
<td><code class="apitype">application/json, text/javascript</code></td>
34+
<td>Some description about this request header</td>
35+
<td></td>
36+
</tr>
37+
<tr id="nextPageToken">
38+
<td><code>X-Requested-With</code></td>
39+
<td><code class="apitype">XMLHttpRequest</code></td>
40+
<td>For security reasons this request header must be set</td>
41+
<td class="action-column"><div class="btn-group">
42+
<button class="btn btn-primary">Action</button>
43+
<button class="btn btn-primary dropdown-toggle" data-toggle="dropdown"><span class="caret"></span></button>
44+
<ul class="dropdown-menu">
45+
<li><a href="#" data-bitly-type="bitly_hover_card">Edit</a></li>
46+
<li><a href="#" data-bitly-type="bitly_hover_card">Add a field</a></li>
47+
<li class="divider"></li>
48+
<li><a href="#" data-bitly-type="bitly_hover_card">Delete</a></li>
49+
</ul>
50+
</div></td>
51+
</tr>
52+
</tbody>
53+
</table>
54+
55+
<h4>Body</h4>
56+
57+
58+
<table class="table request-table">
59+
<thead>
60+
<tr>
61+
<th>Property Name</th>
62+
<th>Value</th>
63+
<th>Description</th>
64+
<th class="action-column">Actions</th>
65+
</tr>
66+
</thead>
67+
<tbody>
68+
<tr id="kind">
69+
<td><code>somearrays[]</code></td>
70+
<td><code class="apitype">array</code></td>
71+
<td>Type of resource. Always <code>compute#diskList</code>.</td>
72+
<td>
73+
<div class="btn-group">
74+
<button class="btn btn-primary">Action</button>
75+
<button class="btn btn-primary dropdown-toggle" data-toggle="dropdown"><span class="caret"></span></button>
76+
<ul class="dropdown-menu">
77+
<li><a href="#" data-bitly-type="bitly_hover_card">Edit</a></li>
78+
<li><a href="#" data-bitly-type="bitly_hover_card">Add a field</a></li>
79+
<li class="divider"></li>
80+
<li><a href="#" data-bitly-type="bitly_hover_card">Delete</a></li>
81+
</ul>
82+
</div>
83+
</td>
84+
</tr>
85+
<tr id="id">
86+
<td><code style="margin-left: 20px;">id</code></td>
87+
<td><code class="apitype">string</code></td>
88+
<td>Unique identifier for the resource; defined by the server (output only).</td>
89+
<td></td>
90+
</tr>
91+
<tr id="id">
92+
<td><code style="margin-left: 20px;">someobject{}</code></td>
93+
<td><code class="apitype">object</code></td>
94+
<td>Unique identifier for the resource; defined by the server (output only).</td>
95+
<td></td>
96+
</tr>
97+
<tr id="selfLink">
98+
<td><code style="margin-left: 40px;">selfLink</code></td>
99+
<td><code class="apitype">string</code></td>
100+
<td>Server-defined URL for this resource (output only).</td>
101+
<td></td>
102+
</tr>
103+
<tr id="id">
104+
<td><code style="margin-left: 20px;">somestring</code></td>
105+
<td><code class="apitype">object</code></td>
106+
<td>Unique identifier for the resource; defined by the server (output only).</td>
107+
<td></td>
108+
</tr>
109+
<tr id="items">
110+
<td><code>items[]</code></td>
111+
<td><code class="apitype">list</code></td>
112+
<td>The persistent disk resources.</td>
113+
<td></td>
114+
</tr>
115+
<tr id="nextPageToken">
116+
<td><code>nextPageToken</code></td>
117+
<td><code class="apitype">string</code></td>
118+
<td>A token used to continue a truncated list request.</td>
119+
<td></td>
120+
</tr>
121+
</tbody>
122+
</table>
123+
124+
125+
<h3>Mock Server Url</h3>
126+
<code class="xml" style="display: block; width: 100%; margin-top: 10px; margin-bottom: 20px;">
127+
http://mockserver.apiengine.com/someserver/user/{user}
128+
</code>
129+
130+
<h3>Code Demos</h3>
131+
<ul class="nav nav-tabs" id="myTab">
132+
<li class="active"><a href="#home">Curl</a></li>
133+
<li><a href="#profile">Node.js</a></li>
134+
<li><a href="#messages">Rails</a></li>
135+
<li><a href="#settings">jQuery</a></li>
136+
</ul>
137+
138+
<div class="tab-content">
139+
<div class="tab-pane active" id="home">
140+
<pre>
141+
<code class="xml">
142+
curl url -i -H "Accept: application/json" http://192.168.0.165/persons/person/1
143+
</code>
144+
</pre>
145+
</div>
146+
147+
148+
149+
</div>
150+
151+
152+
<form class="form-horizontal" style="margin-top: 30px;">
153+
<fieldset>
154+
<div class="control-group">
155+
<input type="text" class="comment-input input-xlarge" id="input01">
156+
<button class="btn btn-primary" style="margin-top: 20px; margin-bottom: 20px;">Add comment</button>
157+
</div>
158+
</fieldset>
159+
</form>
160+
161+
<hr />
162+
<div class="comments-container">
163+
<ul class="comments-list">
164+
<li>
165+
<div class="comment-container">
166+
<div class="comment-user-container">
167+
<div class="user-profile-image"></div>
168+
169+
<div class="comment">
170+
<div class="comment-username">John Howard</div>
171+
I'm a fucking dick sucking. It actually bothered me. Like, the audience in the last panel made it obvious that he wasn't reacting to what was said, and that it was during another part of the interview. Would have been funnier without the audience.</div>
172+
<div style="clear: both;"></div>
173+
</div>
174+
</div>
175+
</li>
176+
<li>
177+
<div class="comment-container">
178+
<div class="comment-user-container">
179+
<div class="user-profile-image">
180+
<img src="http://www.designdownloader.com/item/pngl/maintenance_k01/maintenance_k01-20111010143211-00017.png" style="width: 60px; height: 60px;" />
181+
</div>
182+
183+
<div class="comment">
184+
<div class="comment-username">Mark Hibberd</div>
185+
Like, the audience in the last panel made it obvious that he wasn't reacting to what was said, and that it was during another part of the interview. Would have been funnier without the audience.
186+
187+
<div class="activity-log-changes">
188+
<ul class="activity-log">
189+
<li class=""><i class="icon-minus-sign"></i>
190+
Deleted the property name
191+
</li>
192+
<li><i class="icon-plus-sign"></i>
193+
Added a property name
194+
</li>
195+
</ul>
196+
</div>
197+
</div>
198+
<div style="clear: both;"></div>
199+
200+
201+
<div style="clear: both;"></div>
202+
</div>
203+
</div>
204+
</li>
205+
<li>
206+
<hr>
207+
<div class="comment-container">
208+
<div class="comment-user-container">
209+
<div class="user-profile-image"></div>
210+
<div class="comment">
211+
<div class="comment-username">Peter Andre</div>
212+
<p>I have solved it! I know why people hate Gingers! It is a form of subliminal racisim. Just rearange two letters and you will see. Now think of that the next time you decide to pick on a redhead.</p></div>
213+
<div style="clear: both;"></div>
214+
215+
</div>
216+
</div>
217+
</li>
218+
</div>
219+
</div>
220+
221+
222+

templates/methods/list.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
<li>
1212

1313

14-
<a href="#/<%= resource.get('username')%>/<%= resource.get('api')%>/version/<%= resource.get('version') %>/resource/<%= resource.id%>">
15-
<%= method %>
14+
<a href="#/<%= resource.get('username')%>/<%= resource.get('api')%>/version/<%= resource.get('version') %>/resource/<%= resource.id%>/<%= method %>">
15+
<%= method.label %>
1616
</a>
1717
</li>
1818
<% }); %>

0 commit comments

Comments
 (0)