Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tree folder structure #2

Open
wants to merge 13 commits into
base: TreeFolderStructure
Choose a base branch
from
8 changes: 5 additions & 3 deletions src/app/directives/keytable.directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
}

function add(key, value, fixed) {
vm.rows.push({key:key, value:value, fixed:fixed===true});
vm.rows.push({key:key, value:JSON.stringify(value), fixed:fixed===true});
}

function remove(i) {
Expand All @@ -85,8 +85,10 @@
if (! r.key) continue;

var value = r.value;
if (!isNaN(value) && value !== '') {
value = parseFloat(value);
try {
value = JSON.parse(value);
} catch (e) {
// keep value as string
}

vm.model[r.key] = value;
Expand Down
80 changes: 71 additions & 9 deletions src/app/pages/editor/modals/editfolder.controller.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(function() {
(function () {
'use strict';

angular
Expand All @@ -15,19 +15,21 @@
];

function EditFolderController($scope,
$window,
$state,
$stateParams,
dialogService,
notificationService) {
$window,
$state,
$stateParams,
dialogService,
notificationService) {
var vm = this;
vm.action = 'New';
vm.folder = null;
vm.blacklist = null;
vm.folderList = null;
vm.original = null;
vm.showExport = false;
vm.save = save;
vm.remove = remove;
vm.removeTrees = removeTrees;

_active();

Expand All @@ -39,14 +41,17 @@
vm.folder = folder.copy();
vm.original = folder;
vm.action = 'Update';
p._selectedFolder = folder;
console.log("EditFolderController:", folder);
vm.showExport = folder.category === "tree";
} else {
vm.folder = new b3e.Folder();
vm.folder.category = 'tree';
}

var blacklist = [];
var folderList = [];
p.folders.each(function(folder) {
p.folders.each(function (folder) {
if (folder.name !== vm.folder.name) {
blacklist.push(folder.name);
if (vm.original != null &&
Expand Down Expand Up @@ -77,12 +82,69 @@
$state.go('editor');
}

function removeTrees() {
dialogService.
confirm(
'Remove folder and sub Trees?',
'Are you sure you want to remove this folder?\n\nNote: all blocks using this folder will be removed.'
).then(function () {
var p = $window.editor.project.get();
console.log("removeTrees.p", p);
console.log("removeTrees.vm.original", vm.original);
p.folders.remove(vm.original);
var reli = []

if (vm.original.category === "tree") {
p.trees.each(function (tree) {
console.log("removeTrees.tree", tree);
console.log("removeTrees.tree.folder", tree._root._parent);

if (vm.original.name === tree._root._parent) {
reli.push(tree);
}
}, this);
for (var index = 0; index < reli.length; index++) {
var tree = reli[index];
p.trees.remove(tree);
console.log("removeTrees.trees.remove:", tree);
}
// reli.forEach(function(tree) {
// p.trees.remove(tree);
// console.log("removeTrees.trees.remove:", tree);
// });
} else {
p.nodes.each(function (node) {
if (node.isDefault) {
return
}
console.log("removeTrees.node", node);
// console.log("removeTrees.node.folder", node._root._parent)

if (vm.original.name === node.parent) {
reli.push(node);
}
}, this);
for (var i = 0; i < reli.length; i++) {
var node = reli[i];
p.nodes.remove(node);
console.log("removeTrees.nodes.remove:", node);
};
}

notificationService.success(
'folder removed',
'The folder has been removed from this project.'
);
$state.go('editor');
});
}

function remove() {
dialogService.
confirm(
'Remove folder?',
'Remove folder?',
'Are you sure you want to remove this folder?\n\nNote: all blocks using this folder will be removed.'
).then(function() {
).then(function () {
var p = $window.editor.project.get();
p.folders.remove(vm.original);
notificationService.success(
Expand Down
2 changes: 2 additions & 0 deletions src/app/pages/editor/modals/editfolder.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ <h1 class="b3modal-title">{{editfolder.action}} folder</h1>

<div class="b3modal-buttons">
<input type="button" class="btn btn-danger btn-lg pull-left" ng-click="editfolder.remove()" value="Remove" ng-show="editfolder.original">
<input type="button" class="btn btn-danger btn-lg pull-left" ng-click="editfolder.removeTrees()" value="RemoveTrees" ng-show="editfolder.original">
<input type="button" class="btn btn-default btn-lg" ui-sref="editor.export({type:'folder', format:'json'})" value="Export" ng-show="editfolder.showExport">

<input type="button" class="btn btn-default btn-lg" ui-sref="editor" value="Cancel">
<button type="submit" class="btn btn-success btn-lg" ng-disabled="nodeForm.name.$invalid">Save</button>
Expand Down
5 changes: 4 additions & 1 deletion src/app/pages/editor/modals/export.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,17 @@
var e = $window.editor.export;

if (vm.type === 'project' && vm.format === 'json') {
_createJson(e.projectToData());
_createJson(e.projectToDataByTree());
}
else if (vm.type === 'tree' && vm.format === 'json') {
_createJson(e.treeToData());
}
else if (vm.type === 'nodes' && vm.format === 'json') {
_createJson(e.nodesToData());
}
else if (vm.type === 'folder' && vm.format === 'json') {
_createJson(e.folderToData());
}
}

function _createJson(data) {
Expand Down
2 changes: 1 addition & 1 deletion src/app/pages/editor/modals/import.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@

try {
if (vm.type === 'project' && vm.format === 'json') {
i.projectAsData(data.data);
i.projectAsData(data);
}
else if (vm.type === 'tree' && vm.format === 'json') {
i.treeAsData(data);
Expand Down
2 changes: 1 addition & 1 deletion src/assets/less/variables.less
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
@z-notification: 50;

// SIZES ======================================================================
@size-sidebar: 250px;
@size-sidebar: 400px;
@size-menubar: 35px;
@size-page-content: 700px+@size-sidebar;

Expand Down
18 changes: 15 additions & 3 deletions src/assets/libs/behavior3js-0.1.0.min.js
Original file line number Diff line number Diff line change
Expand Up @@ -1720,7 +1720,7 @@ var p = Sequence.prototype;
* @readonly
**/
p.name = 'Sequence';

p.description = '顺序执行子节点,当子节点返回SUCCESS,直接访问下一个子节点;所有子节点都返回SUCCESS,Sequence节点才返回SUCCESS;当有子节点返回FAILURE,则后续子节点不再执行,Sequence节点直接返回FAILURE,类似于逻辑与的概念。';
/**
* Tick method.
*
Expand Down Expand Up @@ -1796,7 +1796,7 @@ var p = Priority.prototype
* @readonly
**/
p.name = 'Priority';

p.description = '就是Selector节点,选择执行子节点,当子节点返回FAILURE,访问下一个子节点,当所有子节点都返回FAILURE,Priority节点返回FAILURE;当有子节点返回SUCCESS,则后续子节点不再执行,Priority节点直接返回SUCCESS,类似于逻辑或的概念。';
/**
* Tick method.
*
Expand Down Expand Up @@ -1872,7 +1872,7 @@ var p = MemSequence.prototype
* @readonly
**/
p.name = 'MemSequence';

p.description = 'MemSequence节点的逻辑和Sequence一样,这里涉及到一个b3.RUNNING的返回值。MemSequence却会记住之前在Running的子节点,下次遍历的时候,直接从Running的那个子节点开始,这可以很方便的继续之前中断的逻辑决策。'
/**
* Open method.
*
Expand Down Expand Up @@ -1962,6 +1962,7 @@ var p = MemPriority.prototype;
* @readonly
**/
p.name = 'MemPriority';
p.description = 'MemPriority节点的逻辑和Priority一样,然后Running的却会记住之前在Running的子节点,下次遍历的时候,直接从Running的那个子节点开始,这可以很方便的继续之前中断的逻辑决策。'

/**
* Open method.
Expand Down Expand Up @@ -2051,6 +2052,7 @@ var p = Inverter.prototype;
* @readonly
**/
p.name = 'Inverter';
p.descriptions = ''

/**
* Tick method.
Expand Down Expand Up @@ -2130,6 +2132,7 @@ var p = Limiter.prototype;
* @readonly
**/
p.name = 'Limiter';
p.descriptions = ''

/**
* Node title. Default to `Limit X Activations`. Used in Editor.
Expand Down Expand Up @@ -2267,6 +2270,7 @@ var p = MaxTime.prototype;
* @readonly
**/
p.name = 'MaxTime';
p.descriptions = ''

/**
* Node title. Default to `Max XXms`. Used in Editor.
Expand Down Expand Up @@ -2402,6 +2406,7 @@ var p = Repeater.prototype;
* @readonly
**/
p.name = 'Repeater';
p.descriptions = ''

/**
* Node title. Default to `Repeat XXx`. Used in Editor.
Expand Down Expand Up @@ -2536,6 +2541,7 @@ var p = RepeatUntilFailure.prototype;
* @readonly
**/
p.name = 'RepeatUntilFailure';
p.descriptions = ''

/**
* Node title. Default to `Repeat Until Failure`.
Expand Down Expand Up @@ -2670,6 +2676,7 @@ var p = RepeatUntilSuccess.prototype;
* @readonly
**/
p.name = 'RepeatUntilSuccess';
p.descriptions = ''

/**
* Node title. Default to `Repeat Until Success`.
Expand Down Expand Up @@ -2802,6 +2809,7 @@ var p = Error.prototype;
* @readonly
**/
p.name = 'Error';
p.descriptions = ''

/**
* Tick method.
Expand Down Expand Up @@ -2868,6 +2876,7 @@ var p = Failer.prototype;
* @readonly
**/
p.name = 'Failer';
p.descriptions = ''

/**
* Tick method.
Expand Down Expand Up @@ -2934,6 +2943,7 @@ var p = Runner.prototype;
* @readonly
**/
p.name = 'Runner';
p.descriptions = ''

/**
* Tick method.
Expand Down Expand Up @@ -3000,6 +3010,7 @@ var p = Succeeder.prototype;
* @readonly
**/
p.name = 'Succeeder';
p.descriptions = ''

/**
* Tick method.
Expand Down Expand Up @@ -3066,6 +3077,7 @@ var p = Wait.prototype;
* @readonly
**/
p.name = 'Wait';
p.descriptions = ''

/**
* Node title. Default to `Wait XXms`. Used in Editor.
Expand Down
14 changes: 13 additions & 1 deletion src/editor/draw/symbols.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,12 @@
};

b3e.draw.textSymbol = function(block, settings) {
var title = block.getTitle();
if (title.substr(0,3) == "Mem"){
title = "✷" + title.substr(3);
}
var text = new createjs.Text(
block.getTitle(),
title,
'18px Arial',
settings.get('block_symbol_color')
);
Expand All @@ -128,6 +132,14 @@
var bounds = text.getBounds();
text.regY = bounds.height/2;

/*
如果this.name中有Mem那就把星号加上去
shape.graphics.setStrokeStyle(swidth, 'round');
shape.graphics.beginStroke(scolor);
shape.graphics.beginFill(scolor);
shape.graphics.drawPolyStar(0, -ssize*0.75, ssize/2, 6, ssize/10, 0);
*/

// text.x = -block._width/2;
// text.y = -block._height/2;

Expand Down
Loading