Skip to content

Commit fc62b5d

Browse files
authored
Merge pull request #5 from eapearson/master
Update to support latest Narrative.
2 parents 2e9a538 + 4b7ec04 commit fc62b5d

File tree

8 files changed

+1462
-1470
lines changed

8 files changed

+1462
-1470
lines changed

bower.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
"bootstrap": "^3.3.0",
2222
"nunjucks": "^1.3.0",
2323
"jquery": "^2.1.0",
24-
"kbase-common-js": "^1.1.1",
24+
"kbase-common-js": "^2.0.0",
2525
"kbase-ui-widget": "^1.0.0",
26-
"kbase-service-clients-js": "^1.2.0"
26+
"kbase-service-clients-js": "^3.1.1"
2727
},
2828
"devDependencies": {
2929
},

src/plugin/modules/widgets/DashboardWidget.js

Lines changed: 1157 additions & 1127 deletions
Large diffs are not rendered by default.

src/plugin/modules/widgets/NarrativesWidget.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,6 @@ define([
164164
owners: [this.runtime.getService('session').getUsername()]
165165
})
166166
.then(function (narratives) {
167-
168167
this.setState('narratives', narratives);
169168
this.filterNarratives();
170169
}.bind(this));

src/plugin/modules/widgets/PublicNarrativesWidget.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,9 @@ define([
198198
})
199199
.then(function(narratives) {
200200
narratives = narratives.filter(function(x) {
201+
// Show only narratives which are public, no matter the
202+
// other conditions (e.g. may be owned by this user,
203+
// may be shared with this user as well.)
201204
if (x.workspace.globalread === 'r') {
202205
return true;
203206
}

src/plugin/modules/widgets/SharedNarrativesWidget.js

Lines changed: 47 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@
66
white: true
77
*/
88
define([
9-
'jquery',
10-
'kb_dashboard_widget_base',
11-
'kb/widget/widgets/buttonBar',
12-
'bluebird',
13-
'bootstrap'
14-
],
15-
function ($, DashboardWidget, Buttonbar, Promise) {
9+
'jquery',
10+
'kb_dashboard_widget_base',
11+
'kb/widget/widgets/buttonBar',
12+
'bluebird',
13+
'bootstrap'
14+
],
15+
function($, DashboardWidget, Buttonbar, Promise) {
1616
"use strict";
1717
var widget = Object.create(DashboardWidget, {
1818
init: {
19-
value: function (cfg) {
19+
value: function(cfg) {
2020
cfg.name = 'SharedNarrativesWidget';
2121
cfg.title = 'Narratives Shared with You';
2222
this.DashboardWidget_init(cfg);
@@ -28,17 +28,17 @@ define([
2828
}
2929
},
3030
getAppName: {
31-
value: function (name) {
31+
value: function(name) {
3232
return this.getState(['appsMap', name, 'name'], name);
3333
}
3434
},
3535
getMethodName: {
36-
value: function (name) {
36+
value: function(name) {
3737
return this.getState(['methodsMap', name, 'name'], name);
3838
}
3939
},
4040
setupUI: {
41-
value: function () {
41+
value: function() {
4242
if (this.hasState('narratives') && this.getState('narratives').length > 0) {
4343
this.buttonbar = Object.create(Buttonbar).init({
4444
container: this.container.find('[data-placeholder="buttonbar"]')
@@ -48,15 +48,15 @@ define([
4848
.addInput({
4949
placeholder: 'Search',
5050
place: 'end',
51-
onkeyup: function (e) {
51+
onkeyup: function(e) {
5252
this.setParam('filter', $(e.target).val());
5353
}.bind(this)
5454
});
5555
}
5656
}
5757
},
5858
render: {
59-
value: function () {
59+
value: function() {
6060
// Generate initial view based on the current state of this widget.
6161
// Head off at the pass -- if not logged in, can't show profile.
6262
if (this.error) {
@@ -79,7 +79,7 @@ define([
7979
}
8080
},
8181
filterState: {
82-
value: function () {
82+
value: function() {
8383
var search = this.getParam('filter');
8484
if (!search || search.length === 0) {
8585
this.setState('narrativesFiltered', this.getState('narratives'));
@@ -90,40 +90,39 @@ define([
9090
} catch (ex) {
9191
// User entered invalid search expression. How to give the user feedback?
9292
}
93-
var nar = this.getState('narratives').filter(function (x) {
94-
if (x.workspace.metadata.narrative_nice_name.match(searchRe)
95-
93+
var nar = this.getState('narratives').filter(function(x) {
94+
if (x.workspace.metadata.narrative_nice_name.match(searchRe)
95+
9696
||
97-
97+
9898
x.workspace.owner.match(searchRe)
99-
99+
100100
||
101-
101+
102102
(x.object.metadata.cellInfo &&
103-
(function (apps) {
103+
(function(apps) {
104104
for (var i in apps) {
105105
var app = apps[i];
106106
if (app.match(searchRe) || this.getAppName(app).match(searchRe)) {
107107
return true;
108108
}
109109
}
110-
}.bind(this))(Object.keys(x.object.metadata.cellInfo.app)))
111-
110+
}.bind(this))(Object.keys(x.object.metadata.cellInfo.app)))
111+
112112
||
113-
113+
114114
(x.object.metadata.cellInfo &&
115-
(function (methods) {
115+
(function(methods) {
116116
for (var i in methods) {
117117
var method = methods[i];
118118
if (method.match(searchRe) || this.getMethodName(method).match(searchRe)) {
119119
return true;
120120
}
121121
}
122122
}.bind(this))(Object.keys(x.object.metadata.cellInfo.method)))
123-
124-
125-
)
126-
{
123+
124+
125+
) {
127126
return true;
128127
} else {
129128
return false;
@@ -133,11 +132,11 @@ define([
133132
}
134133
},
135134
onStateChange: {
136-
value: function () {
137-
var count = this.doState('narratives', function (x) {
135+
value: function() {
136+
var count = this.doState('narratives', function(x) {
138137
return x.length;
139138
}, null);
140-
var filtered = this.doState('narrativesFiltered', function (x) {
139+
var filtered = this.doState('narrativesFiltered', function(x) {
141140
return x.length;
142141
}, null);
143142

@@ -148,39 +147,44 @@ define([
148147
}
149148
},
150149
getAppsx: {
151-
value: function () {
150+
value: function() {
152151
var methodStore = new NarrativeMethodStore(this.runtime.getConfig('services.narrative_method_store.url'), {
153152
token: this.runtime.service('session').getAuthToken()
154153
});
155154
return Promise.all([
156-
methodStore.list_apps({})
157-
])
158-
.spread(function (apps) {
155+
methodStore.list_apps({})
156+
])
157+
.spread(function(apps) {
159158
var appMap = {};
160-
apps.forEach(function (app) {
159+
apps.forEach(function(app) {
161160
appMap[app.id] = app;
162161
});
163162
return appMap;
164163
});
165164
}
166165
},
167166
setInitialState: {
168-
value: function (options) {
167+
value: function(options) {
169168

170169
return this.getNarratives({
171-
showDeleted: 0
172-
})
173-
.then(function (narratives) {
170+
showDeleted: 0
171+
})
172+
.then(function(narratives) {
174173
var username = this.runtime.getService('session').getUsername();
175174
narratives = narratives
176-
.filter(function (narrative) {
175+
.filter(function(narrative) {
176+
// Filter out narratives that are owned by the
177+
// current user, and which the current user has no
178+
// special permissions (e.g. for public narratives
179+
// not shared, the user_permission will be 'n'
180+
// even though the user can "read" it.)
177181
if (narrative.workspace.owner === username ||
178182
narrative.workspace.user_permission === 'n') {
179183
return false;
180184
}
181185
return true;
182186
}.bind(this));
183-
187+
184188
this.setState('narratives', narratives);
185189
this.filterState();
186190
}.bind(this));

0 commit comments

Comments
 (0)