1 // ==========================================================================
  2 // Papercube.AuthorPaperView
  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/canvas');
 10 require('controllers/authorpaper');
 11 
 12 /** @class
 13 
 14   This view shows the author's papers.
 15   
 16   @extends NodeGraph.NodeGraphView
 17   @author Peter Bergstrom
 18   @version 1.0
 19   @copyright 2008-2009 Peter Bergström.
 20 */
 21 Papercube.AuthorPaperView = NodeGraph.NodeGraphView.extend(
 22 /** @scope Papercube.AuthorPaperView.prototype */ {
 23   
 24   /**
 25     The delegate is the authorPaperController
 26   */
 27   delegate: Papercube.authorPaperController,
 28 
 29   /**
 30     Bind the display properties from the canvasController.
 31 
 32     @property {Array}
 33     @binding "Papercube.canvasController.displayProperties"
 34   */
 35   displayPropertiesBinding: "Papercube.canvasController.displayProperties",
 36 
 37   /**
 38     @property
 39     @default {Current year}
 40     @type {Number}
 41   */
 42   _year: new Date().getFullYear(),
 43   
 44   /**
 45     The value for the depth slider. 
 46     
 47     @property {Integer}
 48     @default 1
 49   */
 50   depth: 1,
 51   
 52   /**
 53     Collab ref threshold binding.Don't show papers with less refs. 
 54   
 55     @property {Integer}
 56     @binding "Papercube.authorPaperController.refThreshold"
 57   */
 58   linkThresholdBinding: "Papercube.authorPaperController.refThreshold",
 59 
 60   /**
 61     Collab ref threshold cached value.
 62   
 63     @property {Integer}
 64     @default 1
 65   */
 66   _cached_linkThreshold: 1, 
 67 
 68   /**
 69     Bind the cite threshold binding. Don't show papers with less cites. 
 70   
 71     @property {Integer}
 72     @binding "Papercube.authorPaperController.citeThreshold"
 73   */
 74   citeThresholdBinding: "Papercube.authorPaperController.citeThreshold",
 75 
 76   /**
 77     Collab cite threshold cached value.
 78   
 79     @property {Integer}
 80     @default 1
 81   */
 82   _cached_citeThreshold: 1,
 83 
 84   /**
 85     Bind the start year threshold binding. Don't show papers published before 
 86     this date. 
 87   
 88     @property {Integer}
 89     @binding "Papercube.authorPaperController.startYearThreshold"
 90   */
 91   startYearThresholdBinding: "Papercube.authorPaperController.startYearThreshold",
 92 
 93   /**
 94     The start year threshold cached value.
 95   
 96     @property {Integer}
 97     @default 1
 98   */
 99   _cached_startYearThreshold: 1960,
100 
101   /**
102     Bind the end year threshold binding. Don't show papers published after 
103     this date. 
104   
105     @property {Integer}
106     @binding "Papercube.authorPaperController.endYearThreshold"
107   */
108   endYearThresholdBinding: "Papercube.authorPaperController.endYearThreshold",
109 
110   /**
111     The end year threshold cached value.
112   
113     @property {Integer}
114     @default 1
115   */
116   _cached_endYearThreshold: new Date().getFullYear(),
117 
118   /**
119     Node background color.
120     
121     @property {String}
122     @config
123     @default '#C3D2DB'
124   */
125   nodeColor: '#B0BDC5',
126 
127   /**
128     Selected node background color.
129     
130     @property {String}
131     @config
132     @default '#D2E2EC'
133   */
134   nodeColorSel: '#D2E2EC',
135 
136   /**
137     Node border color.
138     
139     @property {String}
140     @config
141     @default '#727C81'
142   */
143   nodeBorderColor: '#727C81',
144 
145   /**
146     Selected node border color.
147     
148     @property {String}
149     @config
150     @default '#727C81'
151   */
152   nodeBorderColorSel: '#727C81',
153 
154   /**
155     Node text color.
156     
157     @property {String}
158     @config
159     @default '#111'
160   */
161   nodeTextColor: '#111',
162   
163   /**
164     The name of the view.
165     
166     Overridden value is "authorpaper"
167 
168     @property {String}
169     @config 
170     @default "authorpaper"
171   */
172   viewName: 'authorpaper',
173   
174   /**
175     The type of content being displayed. 
176     
177     Overridden value is "Paper"
178 
179     @property {String}
180     @config 
181     @default "Paper"
182   */
183   contentTypeViewing: 'Paper',
184 
185   /** 
186     The key for the default title display.
187 
188     Overridden value is "Name"
189 
190     @property {String}
191     @config 
192     @default "Name"
193   */
194   defaultTitleKey: 'name',
195 
196   /**
197     The nodeTextRatio allows the font size for the node to the calculated. The font size is calculated as radius/nodeTextRatio.
198 
199     @property {Integer}
200     @config 
201     @default 3
202   */
203   nodeTextRatio: 3,
204 
205   /**
206     If set to YES, show the edge label. If NO, hide the label.
207     
208     @property {Boolean}
209     @config 
210     @default NO
211   */
212   showEdgeLabel: NO,
213 
214   /**
215     If set to YES, calculate the edge width by looking at the weight of the item. Otherwise, skip this operation.
216     
217     Overridden value is NO
218 
219     @property {Boolean}
220     @config 
221     @default NO
222   */
223   useEdgeWeightWidth: NO,
224 
225   /**
226     If NO, don't show edges.
227     
228     Overridden value is NO.
229 
230     @property {Boolean}
231     @config 
232     @default NO
233   */
234   showEdges: NO,
235  
236   /**
237     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. 
238     0.9 would put it close to the end node.
239 
240     Overridden value is 0.4.
241     
242     @property {Float}
243     @config 
244     @default 0.4
245   */
246   edgeTextPosOffset: 0.4, 
247 
248   /** 
249     Get the details of a given item.
250     
251     @param guids {Array} The array of guids.
252     @param callBack {Function} The callBack function is called when the request is successful.
253   */
254   performCustomRequest: function(guids, callBack)
255   {
256     Papercube.adaptor.getPaperDetails(guids, callBack);
257   },
258   
259   /** 
260     Generate custom metadata for item.
261     
262     @param guid {string} The guid for content object to be shown in the meta data view.
263 
264     @returns {Boolean} Returns NO if there is an error.
265   */
266   generateCustomMetaData: function(guid)
267   {
268     // Get the uathor content.
269     var content = Papercube.Paper.find(guid);
270 
271     if(!content)
272     {
273       var content = Papercube.Author.find(guid);
274     
275       if(!content)
276         return NO;
277 
278       // Set the title
279       this.metaDataView.childNodes[0].innerHTML = content.get("name");
280       this.metaDataView.childNodes[1].innerHTML = "<strong>Number of Collaborators:</strong> " +Papercube.pluralizeString(" author",content.get('collaborators').length);
281       this.metaDataView.childNodes[2].innerHTML = "<strong>Author references:</strong> " +Papercube.pluralizeString(" other author",content.get('refAuthors').length);
282       this.metaDataView.childNodes[3].innerHTML = "<strong>Author is cited by:</strong> " +Papercube.pluralizeString(" other author",content.get('citeAuthors').length);
283       this.metaDataView.childNodes[4].innerHTML = "<strong>Papers Published:</strong> " +Papercube.pluralizeString(" paper", content.get('paperCount'));
284       this.metaDataView.childNodes[5].innerHTML = '';
285       return NO;
286     } 
287 
288     // Set the title
289     this.metaDataView.childNodes[0].innerHTML = content.get("title");
290 
291     // Set the authors
292     var authors = content.get('authorNames').join(', ');
293     var authLen = authors.length;
294     this.metaDataView.childNodes[1].innerHTML = (authLen > 150) ? (authors.substr(0,150)+"…") : authors;
295     this.metaDataView.childNodes[2].innerHTML = (content.get('publisher')) ? content.get('publisher') : '';
296 
297     // Set the date
298     this.metaDataView.childNodes[3].innerHTML = "<strong>Publication Date: </strong> " + content.get("year");
299 
300     this.metaDataView.childNodes[4].innerHTML = Papercube.pluralizeString(" reference", content.get('refCount'));
301     this.metaDataView.childNodes[5].innerHTML = Papercube.pluralizeString(" citation", content.get('citeCount'));
302   },
303   
304   /** 
305     Generate custom metadata for item.
306     
307     @param guid {string} The guid for content object that is found in the SC Store.
308 
309     @returns {array|SC.Record} Returns the found content object.
310   */
311   findCustomObject: function(guid)
312   {
313     var obj = Papercube.Paper.find(guid);
314     if(!obj)
315     {
316       obj = Papercube.Author.find(guid); 
317     }
318     return obj;
319   },
320 
321   /** 
322     Find Custom Object Relation Attribute.
323     
324     @param object {Record} The content object.
325 
326     @returns {Array} Returns the found relation attribute array.
327   */
328   findCustomObjectAttr: function(object)
329   {
330     if(object) 
331     {
332       if(object._type == "Papercube.Author")
333         return object._attributes.papers;
334       return [];
335     }
336     else
337     {
338       return [];
339     }
340   },
341 
342   /**
343     Given relation object, return guid for it.
344     
345     @param rel {Object} The relation object or array.
346 
347     @returns {String} Returns the guid for the relation object.
348   */
349   getGuidForRelation: function(rel)
350   {
351     if(rel) return rel;
352   },
353   
354   /**
355     Given relation object, return weight for it.
356 
357     @param rel {Object} The relation object or array.
358 
359     @returns {Integer} Returns the calculated weight for the relation object.
360   */
361   calcRelationWeight: function(rel)
362   {
363     return 1;
364   },
365 
366   /**
367     Given an object, return its label.
368 
369     @param object {Object} The content object.
370 
371     @returns {String} Returns a title string for display.
372   */
373   findCustomObjectLabel: function(object)
374   {
375     if(object)
376     {
377       if(object._type == "Papercube.Author")
378       {
379         var name = '';
380         var n = object._attributes.name.split(' ');
381         var authLen = n.length;
382         for(var i=0; i<authLen; i++)
383         {
384           if(i<authLen-1)
385           {
386             name += n[i].substr(0,1).toUpperCase() + ' ';
387           }
388           else
389           {
390             name += n[i].substr(0,6);
391           }
392         }          
393         return name;
394       }
395       return object._attributes.title.substr(0,20);
396       // var title = object.get('title');
397       // if(title.length > 40)
398       // {
399       //   return [title.substr(0,20), title.substr(20, 40)];
400       // }
401       // return title.substr(0,20);
402     }
403     return '?';
404   },
405   
406   /**
407     Revert bindings to default.
408   */
409   setBindingDefaults: function()
410   {
411     Papercube.authorPaperController.setDefaults();
412   },
413   
414   /**
415     Custom threshold calculation for complex link threshold calculations.
416 
417     @param rel {Object} The relation's guid.
418 
419     @returns {String} Returns if the item is accepted by the threshold(s). Returns NO otherwise.
420   */
421   relationMeetsCustomThreshold: function(rel)
422   {
423     if(this._cached_linkThreshold === 0 && 
424        this._cached_citeThreshold === 0 &&
425        this._cached_startYearThreshold === 1960 && 
426        this._cached_endYearThreshold === this._year
427        ) return YES;
428        
429     var paper = Papercube.Paper.find(rel);
430 
431     if(paper)
432     {
433       return (paper.get('refCount') >= this._cached_linkThreshold &&
434               paper.get('citeCount') >= this._cached_citeThreshold && 
435               paper.get('year') >= this._cached_startYearThreshold &&
436               paper.get('year') <= this._cached_endYearThreshold);
437     }
438     return NO;
439   },
440   
441   /**
442     Redraw if citeThreshold change.
443 
444     @observes citeThreshold
445   */
446   citeThresholdDidChange: function()
447   {
448     var content = this.get('content');
449     // If there is no content or if you're not visible, bail.
450 
451     if(!this.get("isVisible") || !content) return;
452     
453     var threshold = this.get('citeThreshold');
454     
455     // Render if needed.
456     if(threshold != this._cached_citeThreshold)
457     {
458       this._hideExistingLines();
459       this._cached_citeThreshold = threshold;
460       this._render();
461     }
462   }.observes('citeThreshold'),
463   
464   /**
465     Redraw if startYearThreshold change.
466 
467     @observes startYearThreshold
468   */
469   startYearThresholdDidChange: function()
470   {
471     var content = this.get('content');
472     // If there is no content or if you're not visible, bail.
473     if(!this.get("isVisible") || !content) return;
474     
475     var threshold = this.get('startYearThreshold');
476     
477     // Render if needed.
478     if(threshold != this._cached_startYearThreshold)
479     {
480       this._hideExistingLines();
481       this._cached_startYearThreshold = threshold;
482       this._render();
483     }
484   }.observes('startYearThreshold'),
485 
486   /**
487     Redraw if endYearThreshold change.
488 
489     @observes endYearThreshold
490   */
491   endYearThresholdDidChange: function()
492   {
493     var content = this.get('content');
494     // If there is no content or if you're not visible, bail.
495     if(!this.get("isVisible") || !content) return;
496     
497     var threshold = this.get('endYearThreshold');
498     
499     // Render if needed.
500     if(threshold != this._cached_endYearThreshold)
501     {
502       this._hideExistingLines();
503       this._cached_endYearThreshold = threshold;
504       this._render();
505     }
506   }.observes('endYearThreshold')
507   
508 }) ;
509