1 // ========================================================================== 2 // Papercube.CollaboratorView 3 // 4 // License: PaperCube is open source software released under 5 // the MIT License (see license.js) 6 // ========================================================================== 7 8 require('core'); 9 require('controllers/collaborator'); 10 require('controllers/canvas'); 11 12 /** @class 13 14 This is the collaborator view. It will show all the collaborators for an author 15 and also link between them. Strong relationships will be shown with thicker and 16 darker lines. This view uses SVG. 17 18 @extends NodeGraph.NodeGraphView 19 @author Peter Bergstrom 20 @version 1.0 21 @copyright 2008-2009 Peter Bergström. 22 */ 23 24 Papercube.CollaboratorView = NodeGraph.NodeGraphView.extend( 25 /** @scope Papercube.CollaboratorView.prototype */ { 26 27 /** 28 The delegate is the collaboratorController 29 */ 30 delegate: Papercube.collaboratorController, 31 32 /** 33 Bind the display properties from the canvasController. 34 35 @property {Array} 36 @binding "Papercube.canvasController.displayProperties" 37 */ 38 displayPropertiesBinding: "Papercube.canvasController.displayProperties", 39 40 /** 41 Bind the depth. Don't show items beyond this depth. 42 43 @property {Integer} 44 @binding "Papercube.collaboratorController.depth" 45 */ 46 depthBinding: "Papercube.collaboratorController.depth", 47 48 /** 49 Bind the collaborator threshold binding. Don't show collaborators with less collaborators. 50 51 @property {Integer} 52 @binding "Papercube.collaboratorController.collabThreshold" 53 */ 54 linkThresholdBinding: "Papercube.collaboratorController.collabThreshold", 55 56 /** 57 Paper link strength threshold binding. Don't show collaborators with less papers. 58 59 @property {Integer} 60 @binding "Papercube.collaboratorController.paperThreshold" 61 */ 62 paperThresholdBinding: "Papercube.collaboratorController.paperThreshold", 63 64 /** 65 Cache. 66 67 @property {Integer} 68 */ 69 _cached_paperThreshold: 0, 70 71 /** 72 Node background color. 73 74 @property {String} 75 @config 76 @default '#BCE510' 77 */ 78 nodeColor: '#BCE510', 79 80 /** 81 Selected node background color. 82 83 @property {String} 84 @config 85 @default '#E7F738' 86 */ 87 nodeColorSel: '#E7F738', 88 89 /** 90 Node border color. 91 92 @property {String} 93 @config 94 @default '#ACD20E' 95 */ 96 nodeBorderColor: '#ACD20E', 97 98 /** 99 Selected node border color. 100 101 @property {String} 102 @config 103 @default '#727C81' 104 */ 105 nodeBorderColorSel: '#CCDA31', 106 107 /** 108 Node text color. 109 110 @property {String} 111 @config 112 @default '#7E6C53' 113 */ 114 nodeTextColor: '#7E6C53', 115 116 /** 117 The name of the view. 118 119 'collaborator' 120 121 @property {String} 122 */ 123 viewName: 'collaborator', 124 125 /** 126 The type of content being displayed. 127 128 'Author' 129 130 @property {String} 131 */ 132 contentTypeViewing: 'Author', 133 134 /** 135 The key for the default title display. 136 137 'name' 138 139 @property {String} 140 */ 141 defaultTitleKey: 'name', 142 143 /** 144 A value of 0.1 would puts the edge label close to start node. 0.5 would put it in the middle of the edge. 145 0.9 would put it close to the end node. 146 147 @property {Float} 148 @default 0.4 149 */ 150 edgeTextPosOffset: 0.4, 151 152 /** 153 Meta data box small height. 154 155 @property {Integer} 156 @default 100px 157 */ 158 metaDataBoxHeightSmall: 100, 159 160 /** 161 Meta data box small width. 162 163 @property {Integer} 164 @default 100px 165 */ 166 metaDataBoxWidthSmall: 100, 167 168 /** 169 Class name for meta data DIV. 170 171 'author' 172 173 @property {String} 174 */ 175 metaDataClassName: 'author', 176 177 /** 178 Get the details of a given item. 179 180 @param guids {Array} The array of guids. 181 @param callBack {Function} The callBack function is called when the request is successful. 182 */ 183 performCustomRequest: function(guids, callBack) 184 { 185 Papercube.adaptor.getAuthorDetails(guids, callBack); 186 }, 187 188 /** 189 Generate custom metadata for item. 190 191 @param guid {string} The guid for content object to be shown in the meta data view. 192 193 @returns {Boolean} Returns NO if there is an error. 194 */ 195 generateCustomMetaData: function(guid) 196 { 197 // Get the author content. 198 var content = Papercube.Author.find(guid); 199 200 if(!content) return; 201 202 // Set the title 203 this.metaDataView.childNodes[0].innerHTML = content.get("name"); 204 this.metaDataView.childNodes[1].innerHTML = "<strong>Papers Published:</strong> " +Papercube.pluralizeString(" paper", content.get('paperCount')); 205 this.metaDataView.childNodes[2].innerHTML = "<strong>Number of Collaborators:</strong> " +Papercube.pluralizeString(" author",content.get('collaborators').length); 206 this.metaDataView.childNodes[3].innerHTML = "<strong>Author references:</strong> " +Papercube.pluralizeString(" other author",content.get('refAuthors').length); 207 this.metaDataView.childNodes[4].innerHTML = "<strong>Author is cited by:</strong> " +Papercube.pluralizeString(" other author",content.get('citeAuthors').length); 208 }, 209 210 /** 211 Generate custom metadata for item. 212 213 @param guid {string} The guid for content object that is found in the SC Store. 214 215 @returns {array|SC.Record} Returns the found content object. 216 */ 217 findCustomObject: function(guid) 218 { 219 return Papercube.Author.find(guid); 220 }, 221 222 /** 223 Find Custom Object Relation Attribute. 224 225 @param object {Record} The content object. 226 227 @returns {Array} Returns the found relation attribute array. 228 */ 229 findCustomObjectAttr: function(object) 230 { 231 if(object) return object._attributes.collaborators; 232 }, 233 234 /** 235 Given relation object, return guid for it. 236 237 @param rel {Object} The relation object or array. 238 239 @returns {String} Returns the guid for the relation object. 240 */ 241 getGuidForRelation: function(rel) 242 { 243 if(rel) return rel[0]; 244 }, 245 246 /** 247 Given relation object, return weight for it. 248 249 @param rel {Object} The relation object or array. 250 251 @returns {Integer} Returns the calculated weight for the relation object. 252 */ 253 calcRelationWeight: function(rel) 254 { 255 return rel[1]; 256 }, 257 258 /** 259 Given an object, return its label. 260 261 @param object {Object} The content object. 262 263 @returns {String} Returns a title string for display. 264 */ 265 findCustomObjectLabel: function(object) 266 { 267 var name = ''; 268 if(object) 269 { 270 var n = object._attributes.name.split(' '); 271 var authLen = n.length; 272 for(var i=0; i<authLen; i++) 273 { 274 if(i<authLen-1) 275 { 276 name += n[i].substr(0,1).toUpperCase() + ' '; 277 } 278 else 279 { 280 name += n[i].substr(0,6); 281 } 282 } 283 } 284 return name; 285 }, 286 287 /** 288 Revert bindings to default. 289 */ 290 setBindingDefaults: function() 291 { 292 Papercube.collaboratorController.setDefaults(); 293 }, 294 295 /** 296 Custom threshold calculation for complex link threshold calculations. 297 298 @param rel {Object} The relation's guid. 299 300 @returns {String} Returns if the item is accepted by the threshold(s). Returns NO otherwise. 301 */ 302 relationMeetsCustomThreshold: function(rel) 303 { 304 if(rel[1] >=this._cached_linkThreshold) 305 { 306 if(this._cached_paperThreshold !=0) 307 { 308 var p = Papercube.Author.find(rel[0]); 309 if(p) return (p._attributes.papers.length >= this._cached_paperThreshold); 310 } 311 return YES; 312 } 313 return NO; 314 }, 315 316 /** 317 Redraw if paperThreshold changes. 318 319 @observes paperThreshold 320 */ 321 paperThresholdDidChange: function() 322 { 323 var content = this.get('content'); 324 // If there is no content or if you're not visible, bail. 325 326 if(!this.get("isVisible") || !content) return; 327 328 var threshold = this.get('paperThreshold'); 329 330 // Render if needed. 331 if(threshold != this._cached_paperThreshold) 332 { 333 this._hideExistingLines(); 334 this._cached_paperThreshold = threshold; 335 this._render(); 336 } 337 }.observes('paperThreshold') 338 }) ; 339