Skip to content

Commit a9bbcb6

Browse files
committed
hookup resource list code properly, read notifications for API overview & adjust DOM to make this possible
1 parent 7e91e8d commit a9bbcb6

File tree

3 files changed

+38
-35
lines changed

3 files changed

+38
-35
lines changed

js/views/resource/list.js

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ define([
1616
el: '.resource-list-container',
1717
initialize: function () {
1818
var that = this;
19-
19+
2020
},
2121
events: {
2222
'click a[data-resource-id]': 'showMethodList',
@@ -32,27 +32,27 @@ define([
3232
} else {
3333
var el = $('[data-resource-id=' + this.options.resourceId + ']');
3434
}
35-
if(el.length > 0) {
35+
if(el.length > 0) {
3636
this.expandMethods($(el).parents('li[data-resource-id]'));
3737
}
38-
38+
3939
//var methodListView = new MethodsListView({username: that.options.username, api: that.options.api, version: that.options.version, resourceId: that.options.resourceId, method: that.options.method});
40-
//methodListView.render();
40+
//methodListView.render();
4141
var resourcePageView = Vm.create(this, 'resourcepageview', ResourcePageView, that.options);
42-
resourcePageView.render();
42+
resourcePageView.render();
4343
},
4444
expandMethodsHandler: function (ev) {
4545
$(ev.currentTarget).text('-');
4646
$(ev).addClass('expanded');
4747
var ele = $(ev.currentTarget).parents('li[data-resource-id]');
4848
this.expandMethods(ele);
4949
},
50-
expandMethods: function (ele) {
50+
expandMethods: function (ele) {
5151
var resourceId = $(ele).attr('data-resource-id');
5252
var el = $(ele).next('li');
5353
var methodListView = Vm.create(this, 'methodlist'+this.options.resourceId, MethodsListView, {username: this.options.username, apiname: this.options.apiname, version: this.options.version, resourceId: resourceId, method: this.options.method, el: el});
5454
methodListView.setElement(el);
55-
methodListView.render();
55+
methodListView.render();
5656
},
5757
contractMethods: function (ev) {
5858
$(ev.currentTarget).removeClass('expanded');
@@ -67,34 +67,38 @@ define([
6767
that.$el.attr('data-api-id', that.options.apiname);
6868
resources.fetch({
6969
success: function (collection) {
70+
// mark active resource in list if we're viewing one
7071
if(that.options.resourceId) {
71-
72-
collection.get(that.options.resourceId).set({active: 'active'});
72+
collection.get(that.options.resourceId).set({active: 'active'});
7373
}
7474
that.$el.html(Mustache.render(resourceListTemplate, {_:_, selectedResource: that.options.resourceId, is_public: that.options.is_public, resources: collection, username: Session.get('login'), location: that.options.location}));
75-
if(typeof that.options.resourceId !== 'undefined') { //&& $('.method-list-container').attr('data-resource-id') !== that.options.resourceId) {
76-
that.showMethodList();
75+
76+
// render method list for active resource
77+
if(typeof that.options.resourceId !== 'undefined') {
78+
that.showMethodList();
7779
}
78-
//that.showMethodList();
7980

81+
// read in notification counts
8082
var notificationTotals = new NTotals();
8183
notificationTotals.options = {
8284
api: that.options.apiname,
8385
version: that.options.version,
8486
username: that.options.username
8587
};
8688
notificationTotals.fetch({
87-
success: function (model) {
88-
console.log('I dont know what to do', model);
89-
//var notifEl = $('.notification[data-resource-id='+model.options.resourceId+']');
90-
// notifEl.text(model.get('resource')).show();
89+
success: function(model) {
90+
// set notifiactions on the top-level API
91+
if (model.get('api')) {
92+
var anotifEl = $('ul.api-menu-list[data-api-id='+that.options.apiname+'] .api-notification');
93+
anotifEl.text(model.get('api')).show();
94+
}
95+
96+
// set notifications on each resource
9197
_.each(model.get('resources'), function(method){
92-
console.log(method,'wtf is this');
9398
if(method.count > 0) {
94-
var anotifEl = $('.resource-notification[data-resource-id='+method.key+']');
99+
var anotifEl = $('li[data-resource-id='+method.key+'] .resource-notification');
95100
anotifEl.text(method.count).show();
96101
}
97-
98102
});
99103
}
100104
});
@@ -105,7 +109,7 @@ define([
105109
}
106110
});
107111

108-
112+
109113
}
110114
});
111115
return ApisPage;

templates/apis/docs.html

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,13 @@
88
<button class="ebtn ebtn-blue js-new-resource">Add a new resource</button>
99
<button class="ebtn ebtn-blue js-new-method">Add a new method</button>
1010

11-
<ul class="api-menu-list">
12-
<li><a href="#{{user}}/{{api}}/version/{{version}}" class="overview-link">Overview</a></li>
11+
<ul class="api-menu-list" data-api-id="{{api}}">
12+
<li>
13+
<a href="#{{user}}/{{api}}/version/{{version}}" class="overview-link">
14+
Overview
15+
<span class="api-notification notification"></span>
16+
</a>
17+
</li>
1318
</ul>
1419
<div class="resource-list-container">
1520
Loading resources

templates/resource/list.html

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
1-
<style>
2-
</style>
31
<ul class="api-menu-list resource-list">
42
{{#resources.models}}
53
<li class="{{active}}" data-resource-id="{{id}}" data-resource-resource="{{attributes.resource}}">
6-
<div style="">
7-
<a data-resource-id="{{id}}" href="#{{attributes.user}}/{{attributes.api}}/version/{{attributes.version}}/resource/{{id}}">
8-
<span class="resource-label">{{attributes.label}}</span>
9-
10-
<span data-resource-id="{{id}}" class="resource-notification notification"></span>
11-
12-
</a>
13-
<div style="clear: both;">
14-
</div>
15-
</div>
4+
<a data-resource-id="{{id}}" href="#{{attributes.user}}/{{attributes.api}}/version/{{attributes.version}}/resource/{{id}}">
5+
<span class="resource-label">{{attributes.label}}</span>
6+
<span class="resource-notification notification"></span>
7+
</a>
8+
<div style="clear: both;">
9+
</div>
1610
</li>
1711
<li style="display: none; border-top: none;">
1812
<div class="resource-submenu">
@@ -28,4 +22,4 @@
2822
</div>
2923
</li>
3024
{{/resources.models}}
31-
</ul>
25+
</ul>

0 commit comments

Comments
 (0)