6
6
white: true
7
7
*/
8
8
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 ) {
16
16
"use strict" ;
17
17
var widget = Object . create ( DashboardWidget , {
18
18
init : {
19
- value : function ( cfg ) {
19
+ value : function ( cfg ) {
20
20
cfg . name = 'SharedNarrativesWidget' ;
21
21
cfg . title = 'Narratives Shared with You' ;
22
22
this . DashboardWidget_init ( cfg ) ;
@@ -28,17 +28,17 @@ define([
28
28
}
29
29
} ,
30
30
getAppName : {
31
- value : function ( name ) {
31
+ value : function ( name ) {
32
32
return this . getState ( [ 'appsMap' , name , 'name' ] , name ) ;
33
33
}
34
34
} ,
35
35
getMethodName : {
36
- value : function ( name ) {
36
+ value : function ( name ) {
37
37
return this . getState ( [ 'methodsMap' , name , 'name' ] , name ) ;
38
38
}
39
39
} ,
40
40
setupUI : {
41
- value : function ( ) {
41
+ value : function ( ) {
42
42
if ( this . hasState ( 'narratives' ) && this . getState ( 'narratives' ) . length > 0 ) {
43
43
this . buttonbar = Object . create ( Buttonbar ) . init ( {
44
44
container : this . container . find ( '[data-placeholder="buttonbar"]' )
@@ -48,15 +48,15 @@ define([
48
48
. addInput ( {
49
49
placeholder : 'Search' ,
50
50
place : 'end' ,
51
- onkeyup : function ( e ) {
51
+ onkeyup : function ( e ) {
52
52
this . setParam ( 'filter' , $ ( e . target ) . val ( ) ) ;
53
53
} . bind ( this )
54
54
} ) ;
55
55
}
56
56
}
57
57
} ,
58
58
render : {
59
- value : function ( ) {
59
+ value : function ( ) {
60
60
// Generate initial view based on the current state of this widget.
61
61
// Head off at the pass -- if not logged in, can't show profile.
62
62
if ( this . error ) {
@@ -79,7 +79,7 @@ define([
79
79
}
80
80
} ,
81
81
filterState : {
82
- value : function ( ) {
82
+ value : function ( ) {
83
83
var search = this . getParam ( 'filter' ) ;
84
84
if ( ! search || search . length === 0 ) {
85
85
this . setState ( 'narrativesFiltered' , this . getState ( 'narratives' ) ) ;
@@ -90,40 +90,39 @@ define([
90
90
} catch ( ex ) {
91
91
// User entered invalid search expression. How to give the user feedback?
92
92
}
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
+
96
96
||
97
-
97
+
98
98
x . workspace . owner . match ( searchRe )
99
-
99
+
100
100
||
101
-
101
+
102
102
( x . object . metadata . cellInfo &&
103
- ( function ( apps ) {
103
+ ( function ( apps ) {
104
104
for ( var i in apps ) {
105
105
var app = apps [ i ] ;
106
106
if ( app . match ( searchRe ) || this . getAppName ( app ) . match ( searchRe ) ) {
107
107
return true ;
108
108
}
109
109
}
110
- } . bind ( this ) ) ( Object . keys ( x . object . metadata . cellInfo . app ) ) )
111
-
110
+ } . bind ( this ) ) ( Object . keys ( x . object . metadata . cellInfo . app ) ) )
111
+
112
112
||
113
-
113
+
114
114
( x . object . metadata . cellInfo &&
115
- ( function ( methods ) {
115
+ ( function ( methods ) {
116
116
for ( var i in methods ) {
117
117
var method = methods [ i ] ;
118
118
if ( method . match ( searchRe ) || this . getMethodName ( method ) . match ( searchRe ) ) {
119
119
return true ;
120
120
}
121
121
}
122
122
} . bind ( this ) ) ( Object . keys ( x . object . metadata . cellInfo . method ) ) )
123
-
124
-
125
- )
126
- {
123
+
124
+
125
+ ) {
127
126
return true ;
128
127
} else {
129
128
return false ;
@@ -133,11 +132,11 @@ define([
133
132
}
134
133
} ,
135
134
onStateChange : {
136
- value : function ( ) {
137
- var count = this . doState ( 'narratives' , function ( x ) {
135
+ value : function ( ) {
136
+ var count = this . doState ( 'narratives' , function ( x ) {
138
137
return x . length ;
139
138
} , null ) ;
140
- var filtered = this . doState ( 'narrativesFiltered' , function ( x ) {
139
+ var filtered = this . doState ( 'narrativesFiltered' , function ( x ) {
141
140
return x . length ;
142
141
} , null ) ;
143
142
@@ -148,39 +147,44 @@ define([
148
147
}
149
148
} ,
150
149
getAppsx : {
151
- value : function ( ) {
150
+ value : function ( ) {
152
151
var methodStore = new NarrativeMethodStore ( this . runtime . getConfig ( 'services.narrative_method_store.url' ) , {
153
152
token : this . runtime . service ( 'session' ) . getAuthToken ( )
154
153
} ) ;
155
154
return Promise . all ( [
156
- methodStore . list_apps ( { } )
157
- ] )
158
- . spread ( function ( apps ) {
155
+ methodStore . list_apps ( { } )
156
+ ] )
157
+ . spread ( function ( apps ) {
159
158
var appMap = { } ;
160
- apps . forEach ( function ( app ) {
159
+ apps . forEach ( function ( app ) {
161
160
appMap [ app . id ] = app ;
162
161
} ) ;
163
162
return appMap ;
164
163
} ) ;
165
164
}
166
165
} ,
167
166
setInitialState : {
168
- value : function ( options ) {
167
+ value : function ( options ) {
169
168
170
169
return this . getNarratives ( {
171
- showDeleted : 0
172
- } )
173
- . then ( function ( narratives ) {
170
+ showDeleted : 0
171
+ } )
172
+ . then ( function ( narratives ) {
174
173
var username = this . runtime . getService ( 'session' ) . getUsername ( ) ;
175
174
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.)
177
181
if ( narrative . workspace . owner === username ||
178
182
narrative . workspace . user_permission === 'n' ) {
179
183
return false ;
180
184
}
181
185
return true ;
182
186
} . bind ( this ) ) ;
183
-
187
+
184
188
this . setState ( 'narratives' , narratives ) ;
185
189
this . filterState ( ) ;
186
190
} . bind ( this ) ) ;
0 commit comments