# HG changeset patch # User rougeronj # Date 1434640680 -7200 # Node ID 460de050f800243e05a14120b26bae2b022b5c75 # Parent a6a3b0e3da576a81ec929314e0ba8706566cd525 Create Viewrepr which handle the representation of the View. - Put in all the function about Hidden Nodes - In scene, initializes this.view with the first view of the project (later it will be handled by a view manager) diff -r a6a3b0e3da57 -r 460de050f800 client/js/main-renderer.js --- a/client/js/main-renderer.js Thu Jun 18 17:17:11 2015 +0200 +++ b/client/js/main-renderer.js Thu Jun 18 17:18:00 2015 +0200 @@ -39,8 +39,9 @@ 'renderer/edgeremovebutton', 'renderer/edgerevertbutton', 'renderer/miniframe', - 'renderer/scene' - ], function(BaseRepresentation, BaseButton, NodeRepr, Edge, TempEdge, BaseEditor, NodeEditor, EdgeEditor, NodeButton, NodeEditButton, NodeRemoveButton, NodeHideButton, NodeShowButton, NodeRevertButton, NodeLinkButton, NodeEnlargeButton, NodeShrinkButton, EdgeEditButton, EdgeRemoveButton, EdgeRevertButton, MiniFrame, Scene){ + 'renderer/scene', + 'renderer/viewrepr' + ], function(BaseRepresentation, BaseButton, NodeRepr, Edge, TempEdge, BaseEditor, NodeEditor, EdgeEditor, NodeButton, NodeEditButton, NodeRemoveButton, NodeHideButton, NodeShowButton, NodeRevertButton, NodeLinkButton, NodeEnlargeButton, NodeShrinkButton, EdgeEditButton, EdgeRemoveButton, EdgeRevertButton, MiniFrame, Scene, ViewRepr){ 'use strict'; @@ -55,6 +56,7 @@ Renderer._BaseButton = BaseButton; Renderer.Node = NodeRepr; Renderer.Edge = Edge; + Renderer.View = ViewRepr; Renderer.TempEdge = TempEdge; Renderer._BaseEditor = BaseEditor; Renderer.NodeEditor = NodeEditor; diff -r a6a3b0e3da57 -r 460de050f800 client/js/renderer/scene.js --- a/client/js/renderer/scene.js Thu Jun 18 17:17:11 2015 +0200 +++ b/client/js/renderer/scene.js Thu Jun 18 17:18:00 2015 +0200 @@ -25,7 +25,6 @@ this.initialScale = 1; this.offset = paper.view.center; this.totalScroll = 0; - this.hiddenNodes = []; this.mouse_down = false; this.click_target = null; this.selected_target = null; @@ -239,29 +238,14 @@ bindClick(".Rk-ZoomFit", "autoScale"); this.$.find(".Rk-ZoomSave").click( function() { // Save scale and offset point - _this.renkan.project.addView( { zoom_level:_this.scale, offset:_this.offset, hidden_nodes: _this.hiddenNodes } ); + _this.renkan.project.addView( { zoom_level:_this.scale, offset:_this.offset, hidden_nodes: _this.view.hiddenNodes } ); }); this.$.find(".Rk-ZoomSetSaved").click( function() { var view = _this.renkan.project.get("views").last(); if(view){ - _this.showNodes(false); _this.setScale(view.get("zoom_level"), new paper.Point(view.get("offset"))); - if (_this.renkan.options.hide_nodes){ - _this.hiddenNodes = (view.get("hidden_nodes") || []).concat(); - _this.hideNodes(); - } } }); - this.$.find(".Rk-ShowHiddenNodes").mouseenter( function() { - _this.showNodes(true); - _this.$.find(".Rk-ShowHiddenNodes").mouseleave( function() { - _this.hideNodes(); - }); - }); - this.$.find(".Rk-ShowHiddenNodes").click( function() { - _this.showNodes(false); - _this.$.find(".Rk-ShowHiddenNodes").off( "mouseleave" ); - }); if(this.renkan.project.get("views").length > 0 && this.renkan.options.save_view){ this.$.find(".Rk-ZoomSetSaved").show(); } @@ -323,7 +307,7 @@ var _thRedraw = _.throttle(function() { _this.redraw(); },50); - + this.addRepresentations("Node", this.renkan.project.get("nodes")); this.addRepresentations("Edge", this.renkan.project.get("edges")); this.renkan.project.on("change:title", function() { @@ -396,6 +380,14 @@ _thRedraw(); } }); + this.renkan.project.on("add:views", function(_view) { + if (!_this.view){ + _this.view = _this.addRepresentation("View", _view); + } + if (!_this.renkan.project.get("loadingStatus")){ + _thRedraw(); + } + }); this.renkan.project.on("change:title", function(_model, _title) { var el = _this.$.find(".Rk-PadTitle"); if (el.is("input")) { @@ -876,40 +868,6 @@ _tmpEdge.redraw(); this.click_target = _tmpEdge; }, - addHiddenNode: function(_model){ - this.hideNode(_model); - this.hiddenNodes.push(_model.id); - }, - hideNode: function(_model){ - var _this = this; - if (typeof _this.getRepresentationByModel(_model) !== 'undefined'){ - _this.getRepresentationByModel(_model).hide(); - } - }, - hideNodes: function(){ - var _this = this; - this.hiddenNodes.forEach(function(_id, index){ - var node = _this.renkan.project.get("nodes").get(_id); - if (typeof node !== 'undefined'){ - return _this.hideNode(_this.renkan.project.get("nodes").get(_id)); - }else{ - _this.hiddenNodes.splice(index, 1); - } - }); - paper.view.draw(); - }, - showNodes: function(ghost){ - var _this = this; - var i = 0; - this.hiddenNodes.forEach(function(_id){ - i++; - _this.getRepresentationByModel(_this.renkan.project.get("nodes").get(_id)).show(ghost); - }); - if (!ghost){ - this.hiddenNodes = []; - } - paper.view.draw(); - }, findTarget: function(_hitResult) { if (_hitResult && typeof _hitResult.item.__representation !== "undefined") { var _newTarget = _hitResult.item.__representation; diff -r a6a3b0e3da57 -r 460de050f800 client/js/renderer/viewrepr.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/client/js/renderer/viewrepr.js Thu Jun 18 17:18:00 2015 +0200 @@ -0,0 +1,82 @@ +define(['jquery', 'underscore', 'requtils', 'renderer/baserepresentation'], function ($, _, requtils, BaseRepresentation) { + 'use strict'; + + var Utils = requtils.getUtils(); + + /* Rkns.Renderer.View Class */ + + /* The representation for the view. */ + + var ViewRepr = Utils.inherit(BaseRepresentation); + + _(ViewRepr.prototype).extend({ + _init: function() { + var _this = this; + this.$ = $(".Rk-Render"); + this.type = "View"; + this.hiddenNodes = []; + +// this.$.find(".Rk-ZoomSetSaved").click( function() { +// var view = _this.renkan.project.get("views").last(); +// if(view){ +// //_this.setScale(view.get("zoom_level"), new paper.Point(view.get("offset"))); + _this.showNodes(false); + if (this.options.hide_nodes){ + this.hiddenNodes = (this.model.get("hidden_nodes") || []).concat(); + this.hideNodes(); + } +// } +// }); + + this.$.find(".Rk-ShowHiddenNodes").mouseenter( function() { + _this.showNodes(true); + _this.$.find(".Rk-ShowHiddenNodes").mouseleave( function() { + _this.hideNodes(); + }); + }); + this.$.find(".Rk-ShowHiddenNodes").click( function() { + _this.showNodes(false); + _this.$.find(".Rk-ShowHiddenNodes").off( "mouseleave" ); + }); + if(this.renkan.project.get("views").length > 0 && this.renkan.options.save_view){ + this.$.find(".Rk-ZoomSetSaved").show(); + } + }, + redraw: function(options) { + }, + addHiddenNode: function(_model){ + this.hideNode(_model); + this.hiddenNodes.push(_model.id); + }, + hideNode: function(_model){ + if (typeof this.renderer.getRepresentationByModel(_model) !== 'undefined'){ + this.renderer.getRepresentationByModel(_model).hide(); + } + }, + hideNodes: function(){ + var _this = this; + this.hiddenNodes.forEach(function(_id, index){ + var node = _this.renkan.project.get("nodes").get(_id); + if (typeof node !== 'undefined'){ + return _this.hideNode(_this.renkan.project.get("nodes").get(_id)); + }else{ + _this.hiddenNodes.splice(index, 1); + } + }); + paper.view.draw(); + }, + showNodes: function(ghost){ + var _this = this; + this.hiddenNodes.forEach(function(_id){ + _this.renderer.getRepresentationByModel(_this.renkan.project.get("nodes").get(_id)).show(ghost); + }); + if (!ghost){ + this.hiddenNodes = []; + } + paper.view.draw(); + }, + }).value(); + + return ViewRepr; + +});