Created
November 17, 2016 21:39
-
-
Save edutrul/316d6a94a69e4075949695043ed0643b to your computer and use it in GitHub Desktop.
/Users/edutrul/Projects/magic-gen/src/AppBundle/Controller/TestController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { PropTypes } from 'react'; | |
import $ from 'jquery'; | |
import { Tree } from 'antd'; | |
const TreeNode = Tree.TreeNode; | |
const x = 3; | |
const y = 2; | |
const z = 1; | |
const gData = []; | |
const generateData = (_level, _preKey, _tns) => { | |
const preKey = _preKey || '0'; | |
const tns = _tns || gData; | |
const children = []; | |
for (let i = 0; i < x; i++) { | |
const key = `${preKey}-${i}`; | |
tns.push({ title: key, key }); | |
if (i < y) { | |
children.push(key); | |
} | |
} | |
if (_level < 0) { | |
return tns; | |
} | |
const level = _level - 1; | |
children.forEach((key, index) => { | |
tns[index].children = []; | |
return generateData(level, key, tns[index].children); | |
}); | |
}; | |
generateData(z); | |
console.log(generateData); | |
console.log(gData); | |
console.log(JSON.stringify(gData)); | |
const Folders = React.createClass({ | |
getInitialState() { | |
return { | |
expandedKeys: ['0-0-0', '0-0-1'], | |
autoExpandParent: true, | |
checkedKeys: ['0-0-0'], | |
selectedKeys: [], | |
}; | |
}, | |
onExpand(expandedKeys) { | |
console.log('onExpand', arguments); | |
// if not set autoExpandParent to false, if children expanded, parent can not collapse. | |
// or, you can remove all expanded children keys. | |
this.setState({ | |
expandedKeys, | |
autoExpandParent: false, | |
}); | |
}, | |
onCheck(checkedKeys) { | |
this.setState({ | |
checkedKeys, | |
selectedKeys: ['0-3', '0-4'], | |
}); | |
}, | |
onSelect(selectedKeys, info) { | |
console.log('onSelect', info); | |
var result = confirm("Want to delete?"); | |
if (result) { | |
//Logic to delete the item | |
} | |
this.setState({ selectedKeys }); | |
}, | |
render() { | |
console.log(this.props['folders']); | |
console.log(this.props.folders); | |
const loop = data => data.map((item) => { | |
if (item.children) { | |
return ( | |
<TreeNode key={item.key} title={item.key} disableCheckbox={item.key === '0-0-0'}> | |
{loop(item.children)} | |
</TreeNode> | |
); | |
} | |
return <TreeNode key={item.key} title={item.key} />; | |
}); | |
return ( | |
<Tree | |
onExpand={this.onExpand} expandedKeys={this.state.expandedKeys} | |
autoExpandParent={this.state.autoExpandParent} | |
onSelect={this.onSelect} selectedKeys={this.state.selectedKeys} | |
> | |
{loop(this.props.folders)} | |
</Tree> | |
); | |
}, | |
}); | |
export default Folders; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace AppBundle\Controller; | |
use Symfony\Bundle\FrameworkBundle\Controller\Controller; | |
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; | |
use Symfony\Component\Finder\Finder; | |
class TestController extends Controller | |
{ | |
/** | |
* @Route("/hello") | |
*/ | |
public function helloAction() | |
{ | |
$finder = new Finder(); | |
//$finder->files()->in($this->get('kernel')->getRootDir()); | |
//$finder->files()->in('/Users/edutrul/Projects/magic-gen/src/AppBundle/Tests'); | |
$finder->directories()->in('/Users/edutrul/Projects/magic-gen/src/AppBundle/Tests'); | |
$files = []; | |
$directories = []; | |
foreach ($finder as $file) { | |
// Dump the absolute path | |
//var_dump($file->getRealPath()); | |
//$files[] = $file->getRealPath(); | |
//$files[] = $file->getRelativePath(); | |
$files[] = $file->getRelativePathname(); | |
//$files[] = $file-> | |
} | |
$serializer = $this->get('serializer'); | |
$files = [ | |
'hello' => | |
[ | |
'title' => '0-0', | |
'key' => '0-0', | |
'children' => | |
[ | |
0 => | |
[ | |
'title' => '0-0-0', | |
'key' => '0-0-0', | |
'children' => | |
[ | |
0 => | |
[ | |
'title' => '0-0-0-0', | |
'key' => '0-0-0-0', | |
], | |
1 => | |
[ | |
'title' => '0-0-0-1', | |
'key' => '0-0-0-1', | |
], | |
2 => | |
[ | |
'title' => '0-0-0-2', | |
'key' => '0-0-0-2', | |
], | |
], | |
], | |
1 => | |
[ | |
'title' => '0-0-1', | |
'key' => '0-0-1', | |
'children' => | |
[ | |
0 => | |
[ | |
'title' => '0-0-1-0', | |
'key' => '0-0-1-0', | |
], | |
1 => | |
[ | |
'title' => '0-0-1-1', | |
'key' => '0-0-1-1', | |
], | |
2 => | |
[ | |
'title' => '0-0-1-2', | |
'key' => '0-0-1-2', | |
], | |
], | |
], | |
2 => | |
[ | |
'title' => '0-0-2', | |
'key' => '0-0-2', | |
], | |
], | |
], | |
1 => | |
[ | |
'title' => '0-1', | |
'key' => '0-1', | |
'children' => | |
[ | |
0 => | |
[ | |
'title' => '0-1-0', | |
'key' => '0-1-0', | |
'children' => | |
[ | |
0 => | |
[ | |
'title' => '0-1-0-0', | |
'key' => '0-1-0-0', | |
], | |
1 => | |
[ | |
'title' => '0-1-0-1', | |
'key' => '0-1-0-1', | |
], | |
2 => | |
[ | |
'title' => '0-1-0-2', | |
'key' => '0-1-0-2', | |
], | |
], | |
], | |
1 => | |
[ | |
'title' => '0-1-1', | |
'key' => '0-1-1', | |
'children' => | |
[ | |
0 => | |
[ | |
'title' => '0-1-1-0', | |
'key' => '0-1-1-0', | |
], | |
1 => | |
[ | |
'title' => '0-1-1-1', | |
'key' => '0-1-1-1', | |
], | |
2 => | |
[ | |
'title' => '0-1-1-2', | |
'key' => '0-1-1-2', | |
], | |
], | |
], | |
2 => | |
[ | |
'title' => '0-1-2', | |
'key' => '0-1-2 - ' . __DIR__, | |
], | |
], | |
], | |
2 => | |
[ | |
'title' => '0-2EDUTRULtitle', | |
'key' => '0-2EDUTRULkey' . implode("\n", $files), | |
], | |
]; | |
$files = [ | |
0 => | |
[ | |
'title' => 'mymodule', | |
'key' => 'mymodule', | |
'children' => | |
[ | |
0 => | |
[ | |
'title' => 'src', | |
'key' => 'src', | |
'children' => | |
[ | |
0 => | |
[ | |
'title' => 'cli', | |
'key' => 'cli', | |
'children' => [ | |
0 => | |
[ | |
'title' => 'phpinfo.php', | |
'key' => 'phpinfo.php', | |
], | |
], | |
], | |
1 => | |
[ | |
'title' => 'hello.php', | |
'key' => 'hello.php', | |
], | |
], | |
], | |
1 => | |
[ | |
'title' => 'mymodule.info.yml', | |
'key' => 'mymodule.info.yml', | |
], | |
], | |
], | |
]; | |
//print json_encode($files); | |
return $this->render('generate/test.html.twig', [ | |
'props' => $serializer->normalize( | |
[ | |
'folders' => $files | |
]) | |
]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment