Add dynamic project tree
This commit is contained in:
4
.gitignore
vendored
4
.gitignore
vendored
@@ -1,4 +1,6 @@
|
||||
.buildpath
|
||||
.project
|
||||
.settings/
|
||||
*.xcf
|
||||
.htaccess
|
||||
application/config/config.php
|
||||
application/config/database.php
|
||||
|
||||
0
application/.htaccess
Executable file → Normal file
0
application/.htaccess
Executable file → Normal file
58
application/controllers/projects.php
Normal file
58
application/controllers/projects.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
class Projects extends CI_Controller {
|
||||
|
||||
/**
|
||||
* List all projects the user has access to.
|
||||
*/
|
||||
public function getAvailable() {
|
||||
$this->load->model('Project');
|
||||
|
||||
$path = $this->input->get_post('node');
|
||||
|
||||
|
||||
switch($path) {
|
||||
case '/projects/own':
|
||||
$projects = $this->Project->getOwn();
|
||||
break;
|
||||
case '/projects/shared':
|
||||
$projects = $this->Project->getShared();
|
||||
break;
|
||||
case '/projects/public':
|
||||
$projects = $this->Project->getPublic();
|
||||
break;
|
||||
default:
|
||||
$projects = array(
|
||||
array(
|
||||
'id' => '/projects/own',
|
||||
'cls' => 'folder',
|
||||
'text' => 'Eigene Projekte',
|
||||
'icon' => '/ScattPort/assets/images/icons/folder.png',),
|
||||
array(
|
||||
'id' => '/projects/shared',
|
||||
'cls' => 'leaf',
|
||||
'text' => 'Für mich freigegeben',
|
||||
'icon' => '/ScattPort/assets/images/icons/folder-share.png',
|
||||
),
|
||||
array(
|
||||
'id' => '/projects/public',
|
||||
'cls' => 'folder',
|
||||
'text' => 'Öffentliche Projekte',
|
||||
'icon' => '/ScattPort/assets/images/icons/folder-network.png',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
$this->output
|
||||
->set_content_type('application/json')
|
||||
->set_output(json_encode($projects));
|
||||
// ->set_output(json_encode(array('count' => $count, 'projects' => $projects)));
|
||||
}
|
||||
|
||||
public function detail($projects, $area, $id) {
|
||||
$result = $this->db->get_where('projects', array('id' => $id))->row_array();
|
||||
$this->output
|
||||
->set_content_type('application/json')
|
||||
->set_output(json_encode(array('result' => $result)));
|
||||
}
|
||||
}
|
||||
65
application/models/project.php
Normal file
65
application/models/project.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
class Project extends CI_Model {
|
||||
|
||||
public function getOwn() {
|
||||
$query = $this->db->where(array('owner' => '215cd70f310ae6ae'))
|
||||
->order_by('lastaccess', 'desc')
|
||||
->get('projects');
|
||||
$projects = $query->result_array();
|
||||
$ownCount = $query->num_rows();
|
||||
|
||||
$i = 0;
|
||||
foreach($projects as $project) {
|
||||
$ownProjects[$i]['id'] = '/projects/own/'.$project['id'];
|
||||
$ownProjects[$i]['cls'] = 'folder';
|
||||
$ownProjects[$i]['text'] = $project['name'];
|
||||
$ownProjects[$i]['leaf'] = true;
|
||||
$ownProjects[$i]['icon'] = "/ScattPort/assets/images/icons/document.png";
|
||||
$i++;
|
||||
}
|
||||
|
||||
return $ownProjects;
|
||||
}
|
||||
|
||||
public function getShared() {
|
||||
$this->db->select('*')->from('shares')->order_by('lastaccess', 'desc')->where(array('user_id' => '215cd70f310ae6ae'));
|
||||
$this->db->join('projects', 'projects.id = shares.project_id');
|
||||
$query = $this->db->get();
|
||||
|
||||
$projects = $query->result_array();
|
||||
$sharedCount = $query->num_rows();
|
||||
|
||||
$i = 0;
|
||||
foreach($projects as $project) {
|
||||
$sharedProjects[$i]['id'] = '/projects/shared/'.$project['id'];
|
||||
$sharedProjects[$i]['cls'] = 'folder';
|
||||
$sharedProjects[$i]['text'] = $project['name'];
|
||||
$sharedProjects[$i]['leaf'] = true;
|
||||
$sharedProjects[$i]['icon'] = "/ScattPort/assets/images/icons/document.png";
|
||||
$i++;
|
||||
}
|
||||
|
||||
return $sharedProjects;
|
||||
}
|
||||
|
||||
public function getPublic() {
|
||||
$query = $this->db->where(array('public' => '1'))
|
||||
->order_by('name', 'asc')
|
||||
->get('projects');
|
||||
$projects = $query->result_array();
|
||||
$publicCount = $query->num_rows();
|
||||
|
||||
$i = 0;
|
||||
foreach($projects as $project) {
|
||||
$publicProjects[$i]['id'] = '/projects/public/'.$project['id'];
|
||||
$publicProjects[$i]['cls'] = 'folder';
|
||||
$publicProjects[$i]['text'] = $project['name'];
|
||||
$publicProjects[$i]['leaf'] = true;
|
||||
$publicProjects[$i]['icon'] = "/ScattPort/assets/images/icons/document.png";
|
||||
$i++;
|
||||
}
|
||||
|
||||
return $publicProjects;
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@
|
||||
<?=script_tag('assets/js/ext/adapter/jquery/ext-jquery-adapter.js');?>
|
||||
<!-- ExtJS library: all widgets -->
|
||||
<?=script_tag('assets/js/ext/ext-all.js');?>
|
||||
<?=script_tag('assets/js/ProjectInfoWindow.js');?>
|
||||
<script type="text/javascript">
|
||||
var BASE_URL = '<?=base_url();?>' + 'index.php/';
|
||||
var BASE_PATH = '<?=base_url();?>';
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
<?php $this->load->view('header'); ?>
|
||||
|
||||
<script type="text/javascript">
|
||||
var projectPanel = new Ext.tree.TreePanel({
|
||||
id: 'project-tree',
|
||||
var projectTree = new Ext.tree.TreePanel({
|
||||
region: 'west',
|
||||
title: "Projekte",
|
||||
height: 400,
|
||||
height: 250,
|
||||
bodyStyle: 'margin-bottom: 6px;',
|
||||
autoScroll: true,
|
||||
rootVisible: true,
|
||||
lines: false,
|
||||
tbar: [{
|
||||
enableDD: false,
|
||||
rootVisible: false,
|
||||
id: 'treePanel',
|
||||
tbar: [{
|
||||
icon: BASE_PATH + 'assets/images/icons/box--plus.png',
|
||||
text: "Neues Projekt",
|
||||
scope: this
|
||||
@@ -20,20 +20,18 @@ var projectPanel = new Ext.tree.TreePanel({
|
||||
text: "Entfernen",
|
||||
scope: this
|
||||
}],
|
||||
dataUrl: BASE_URL + 'projects/getAvailable',
|
||||
root: {
|
||||
text: "Meine Projekte",
|
||||
nodeType: 'async',
|
||||
text: 'Projekte',
|
||||
expanded: true,
|
||||
children: [{
|
||||
text: 'Projekt 1',
|
||||
leaf: true
|
||||
}, {
|
||||
text: 'Projekt 2',
|
||||
leaf: true
|
||||
}]
|
||||
id: 'projects'
|
||||
}
|
||||
});
|
||||
|
||||
var layoutLeft2 = new Ext.Panel({
|
||||
projectTree.on('click', loadProjectInfo);
|
||||
|
||||
var infoPanel = new Ext.Panel({
|
||||
region: 'west',
|
||||
margin: '10 0 0 0',
|
||||
autoScroll: true,
|
||||
@@ -41,7 +39,8 @@ var layoutLeft2 = new Ext.Panel({
|
||||
html: 'Test'
|
||||
});
|
||||
|
||||
var panelCenter = new Ext.TabPanel({
|
||||
|
||||
var tabPanel = new Ext.TabPanel({
|
||||
xtype: 'tabpanel',
|
||||
resizeTabs: false,
|
||||
minTabWidth: 115,
|
||||
@@ -55,7 +54,8 @@ var panelCenter = new Ext.TabPanel({
|
||||
xtype: 'panel',
|
||||
id: 'tab_welcome',
|
||||
bodyStyle: 'padding: 10px',
|
||||
title: "Willkommen"
|
||||
title: "Willkommen",
|
||||
closable: true,
|
||||
}]
|
||||
});
|
||||
|
||||
@@ -66,7 +66,7 @@ var layoutCenter = new Ext.Panel({
|
||||
margins: '0 5 5 0',
|
||||
activeItem: 0,
|
||||
border: true,
|
||||
items: [panelCenter]
|
||||
items: [tabPanel]
|
||||
});
|
||||
|
||||
var layoutMain = new Ext.Viewport({
|
||||
@@ -88,12 +88,12 @@ var layoutMain = new Ext.Viewport({
|
||||
border: false,
|
||||
split: true,
|
||||
margins: '0 0 0 5',
|
||||
items: [projectPanel, layoutLeft2]
|
||||
items: [projectTree]
|
||||
}, layoutCenter]
|
||||
});
|
||||
|
||||
function logout() {
|
||||
$.ajax({
|
||||
Ext.Ajax.request({
|
||||
url: BASE_URL + 'auth/do_logout',
|
||||
method: 'post',
|
||||
success: function(xhr) {
|
||||
@@ -101,8 +101,50 @@ function logout() {
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
function loadProjectInfo(n) {
|
||||
if(n.isLeaf()){
|
||||
Ext.Ajax.request({
|
||||
url: BASE_URL + 'projects/detail' + n.id,
|
||||
method: 'get',
|
||||
success: function ( result, request ) {
|
||||
|
||||
var theResponse = Ext.util.JSON.decode(result.responseText);
|
||||
|
||||
tabPanel.add({
|
||||
title: 'New Tab ',
|
||||
html: 'Lade Projekt...',
|
||||
closable:true,
|
||||
handler: function(){
|
||||
alert("foo");
|
||||
var data = theResponse.result;
|
||||
var tpl = new Ext.Template(
|
||||
'<p>ID: {id}</p>',
|
||||
'<p>Name: {name}</p>'
|
||||
);
|
||||
|
||||
tpl.overwrite(this.html, data);
|
||||
}
|
||||
}).show();
|
||||
},
|
||||
failure: function ( result, request ) {
|
||||
//Ext.MessageBox.alert("Fehler!", "Das gewünschte Projekt kann nicht geladen werden.");
|
||||
switch(result.status) {
|
||||
case 404:
|
||||
Ext.MessageBox.alert("Fehler", "Das gewünschte Projekt konnte nicht gefunden werden.");
|
||||
break;
|
||||
case 401:
|
||||
Ext.MessageBox.alert("Fehler", "Sie besitzen nicht die nötigen Zugriffsrechte, um dieses Projekt zu lesen."
|
||||
+ "Wenden Sie sich an den Projektbesitzer, um Zugriff zu erhalten.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
</script>
|
||||
<div id="main"></div>
|
||||
|
||||
<?php $this->load->view('footer'); ?>
|
||||
<?php $this->load->view('footer'); ?>
|
||||
|
||||
Reference in New Issue
Block a user