Skip to content

[Widget View] Implemented recent widgets feature. #301

Open
wants to merge 1 commit into from

2 participants

@xuqingkuang

No description provided.

@xuqingkuang

The code is updated, please review.

Thx a lot! @zhizhangchen

@zhizhangchen zhizhangchen commented on the diff Sep 24, 2012
src/js/views/base.js
@@ -110,7 +112,7 @@
// First unbind our ADMDesign modelUpdated handler, if any...
if (d && o.modelUpdated) {
- d.designRoot.unbind("modelUpdated", o.modelUpdated, this);
+ d.unbind("modelUpdated", o.modelUpdated, this);
@zhizhangchen
zhizhangchen added a note Sep 24, 2012

Why are you removing the "designRoot" when unbinding modelUpdated?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@zhizhangchen zhizhangchen commented on an outdated diff Sep 24, 2012
src/js/views/widget.js
widget._setOption("model", groups);
- widget.findDomNode(groups[0]['Functional Groups'])
- .find('> a').trigger('click');
- });
+ widget._getRootNode().find('> a').trigger('click');
@zhizhangchen
zhizhangchen added a note Sep 24, 2012

_getDefaultSelectedNode might be a better name

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@zhizhangchen zhizhangchen commented on an outdated diff Sep 24, 2012
src/js/views/widget.js
@@ -36,19 +44,65 @@
});
};
resolveRefs(groups, groups);
+ widget.treeJSON = groups;
@zhizhangchen
zhizhangchen added a note Sep 24, 2012

widget._groups might be a better name

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@zhizhangchen zhizhangchen commented on an outdated diff Sep 24, 2012
src/js/views/widget.js
+ }
+
+ // Get the json file and initial the tree.
+ $.rib.fsUtils.read(
+ "groups.json",
+ // After read the file succeed, process the JSON file direclty.
+ function(jsonText) {
+ processJSON(JSON.parse(jsonText));
+ },
+ // Read the default groups.json file after failure.
+ function() {
+ $.getJSON("src/assets/groups.json", processJSON);
+ }
+ );
+ this.treeJSON = [{}];
+ this.selectedNode = undefined;
@zhizhangchen
zhizhangchen added a note Sep 24, 2012

"_selectedNode" might be better than "selectedNode"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@zhizhangchen zhizhangchen commented on an outdated diff Sep 24, 2012
src/js/views/widget.js
@@ -56,6 +110,34 @@
// allocate 30% of the remaining space for the filter tree
used = 2 * headerHeight + resizeBarHeight;
e.height(Math.round((e.parent().height() - used) * 0.3));
+ },
+
+ // Diable refresh action in treeView, so override the designReset
+ // handler here.
+ _designResetHandler: function(event, widget) {
@zhizhangchen
zhizhangchen added a note Sep 24, 2012

Please check if "o.mode === ADM" to decide if we need to refresh in baseView instead of copying codes here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@xuqingkuang

@zhizhangchen The code is updated by your comments, please review.

@zhizhangchen zhizhangchen and 1 other commented on an outdated diff Sep 27, 2012
src/js/views/base.js
@@ -109,7 +111,7 @@
d = this.designRoot;
// First unbind our ADMDesign modelUpdated handler, if any...
- if (d && o.modelUpdated) {
+ if (d && d.designRoot && o.modelUpdated) {
@zhizhangchen
zhizhangchen added a note Sep 27, 2012

d.designRoot should be this.designRoot

@xuqingkuang
xuqingkuang added a note Sep 27, 2012

Please see line 114 - d = this.designRoot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@zhizhangchen zhizhangchen and 1 other commented on an outdated diff Sep 27, 2012
src/js/views/base.js
@@ -109,7 +111,7 @@
d = this.designRoot;
// First unbind our ADMDesign modelUpdated handler, if any...
- if (d && o.modelUpdated) {
+ if (d && d.designRoot && o.modelUpdated) {
d.designRoot.unbind("modelUpdated", o.modelUpdated, this);
@zhizhangchen
zhizhangchen added a note Sep 27, 2012

Same comments as above

@xuqingkuang
xuqingkuang added a note Sep 27, 2012

It's the original code, I didn't modify it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@zhizhangchen zhizhangchen commented on an outdated diff Sep 27, 2012
src/js/views/widget.js
+ _modelUpdatedHandler: function(event, widget) {
+ var type, index,
+ recentWidgets = widget._groups[0]['Recent Widgets'];
+ // Check the event type and update recent objects array.
+ if (typeof(event) === 'object' && event.type == 'nodeAdded') {
+ type = event.node.getType();
+ index = $.inArray(type, recentWidgets);
+ // Remove the widget from recentWidget if the widget is exist
+ // in recentWidget and not the first
+ if (index > 0)
+ recentWidgets.splice(index, 1);
+ // Add the widget to the first of recentWidget array when the
+ // widget is not exist in recentWidget or after removed.
+ if (index < 0 || index > 0)
+ recentWidgets.unshift(type);
+ // Refresh the widgetView and update groups file if the
@zhizhangchen
zhizhangchen added a note Sep 27, 2012

"widgetView" should be paletteView

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@xuqingkuang

@zhizhangchen The code updated by your comments, please review.

@xuqingkuang

The code updated by your comments, please review. @zhizhangchen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.