From 680bc1a2f63994122d64d3b3b9b24c3123ef3336 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Thu, 15 Dec 2016 07:10:01 +0000 Subject: [PATCH] added a project-user relation graph --- codepot/src/codepot/controllers/graph.php | 15 ++ codepot/src/codepot/controllers/project.php | 14 +- codepot/src/codepot/models/projectmodel.php | 45 +++- .../src/codepot/models/subversionmodel.php | 4 +- codepot/src/codepot/views/Makefile.am | 1 + codepot/src/codepot/views/project_catalog.php | 3 +- codepot/src/codepot/views/project_map.php | 245 ++++++++++++++++++ 7 files changed, 322 insertions(+), 5 deletions(-) create mode 100644 codepot/src/codepot/views/project_map.php diff --git a/codepot/src/codepot/controllers/graph.php b/codepot/src/codepot/controllers/graph.php index 96cdcd73..d6ac4242 100644 --- a/codepot/src/codepot/controllers/graph.php +++ b/codepot/src/codepot/controllers/graph.php @@ -197,4 +197,19 @@ class Graph extends Controller $rg = $this->subversion->revisionGraph ($projectid, $path, $rev); print codepot_json_encode ($rg); } + + function enjson_project_user_relation_graph () + { + $this->load->model ('ProjectModel', 'projects'); + + $login = $this->login->getUser (); + if (CODEPOT_SIGNIN_COMPULSORY && $login['id'] == '') + { + header($_SERVER['SERVER_PROTOCOL'].' 404 Not Found'); + return; + } + + $rel = $this->projects->getAllProjectUserRelationGraph(); + print codepot_json_encode($rel); + } } diff --git a/codepot/src/codepot/controllers/project.php b/codepot/src/codepot/controllers/project.php index b1be6cb4..639a3963 100644 --- a/codepot/src/codepot/controllers/project.php +++ b/codepot/src/codepot/controllers/project.php @@ -8,6 +8,7 @@ class Project extends Controller var $VIEW_DELETE = 'project_delete'; var $VIEW_CATALOG = 'project_catalog'; var $VIEW_LOG = 'log'; + var $VIEW_MAP = 'project_map'; function Project () { @@ -117,6 +118,18 @@ class Project extends Controller } } + function map () + { + $this->load->model ('ProjectModel', 'projects'); + + $login = $this->login->getUser (); + if (CODEPOT_SIGNIN_COMPULSORY && $login['id'] == '') + redirect (CODEPOT_SIGNIN_REDIR_PATH . $this->converter->AsciiTohex(current_url())); + $data['login'] = $login; + + $this->load->view ($this->VIEW_MAP, $data); + } + function home ($projectid = "") { $this->load->model ('ProjectModel', 'projects'); @@ -126,7 +139,6 @@ class Project extends Controller $login = $this->login->getUser (); if (CODEPOT_SIGNIN_COMPULSORY && $login['id'] == '') redirect (CODEPOT_SIGNIN_REDIR_PATH . $this->converter->AsciiTohex(current_url())); - $data['login'] = $login; $project = $this->projects->get ($projectid); diff --git a/codepot/src/codepot/models/projectmodel.php b/codepot/src/codepot/models/projectmodel.php index 1fe296c4..8689bfb3 100644 --- a/codepot/src/codepot/models/projectmodel.php +++ b/codepot/src/codepot/models/projectmodel.php @@ -438,7 +438,7 @@ class ProjectModel extends Model $this->db->trans_start (); $this->db->limit ($limit); - $this->db->order_by ('createdon', 'desc'); + $this->db->order_by ('createdon', 'desc'); $query = $this->db->get ('project'); $this->db->trans_complete (); @@ -446,6 +446,8 @@ class ProjectModel extends Model return $query->result (); } + + function _scandir ($dir) { $files = array (); @@ -589,6 +591,47 @@ class ProjectModel extends Model mail ($recipients, $subject, base64_encode($message), $additional_headers); return TRUE; } + + private function _add_rg_node (&$nodeids, &$nodes, $name, $type) + { + if (array_key_exists($name, $nodeids)) return $nodeids[$name]; + $nid = count($nodeids); + array_push ($nodes, array ('id' => $nid, 'label' => $name, '_type' => $type)); + $nodeids[$name] = $nid; + return $nid; + } + + private function _add_rg_edge (&$edges, $from, $to, $label) + { + array_push ($edges, array ('from' => $from, 'to' => $to, 'label' => $label)); + } + + function getAllProjectUserRelationGraph () + { + $this->db->trans_start (); + + $this->db->select ('project.id,project_membership.userid'); + $this->db->join ('project_membership', 'project_membership.projectid = project.id'); + $query = $this->db->get ('project'); + + $this->db->trans_complete (); + + if ($this->db->trans_status() === FALSE) return FALSE; + $result = $query->result (); + + $nodes = array(); + $nodeids = array(); + $edges = array(); + + foreach ($result as $r) + { + $id1 = $this->_add_rg_node ($nodeids, $nodes, $r->id, 'project'); + $id2 = $this->_add_rg_node ($nodeids, $nodes, $r->userid, 'user'); + $this->_add_rg_edge ($edges, $id1, $id2, ""); + } + + return array ('nodes' => $nodes, 'edges' => $edges); + } } ?> diff --git a/codepot/src/codepot/models/subversionmodel.php b/codepot/src/codepot/models/subversionmodel.php index 78f9b8f4..8d271ca5 100644 --- a/codepot/src/codepot/models/subversionmodel.php +++ b/codepot/src/codepot/models/subversionmodel.php @@ -1634,7 +1634,7 @@ class SubversionModel extends Model return $cloc; } - function _add_rg_node (&$nodeids, &$nodes, $name) + private function _add_rg_node (&$nodeids, &$nodes, $name) { if (array_key_exists($name, $nodeids)) return $nodeids[$name]; $nid = count($nodeids); @@ -1643,7 +1643,7 @@ class SubversionModel extends Model return $nid; } - function _add_rg_edge (&$edges, $from, $to, $label) + private function _add_rg_edge (&$edges, $from, $to, $label) { array_push ($edges, array ('from' => $from, 'to' => $to, 'label' => $label)); } diff --git a/codepot/src/codepot/views/Makefile.am b/codepot/src/codepot/views/Makefile.am index ee5bcdff..f1af8f21 100644 --- a/codepot/src/codepot/views/Makefile.am +++ b/codepot/src/codepot/views/Makefile.am @@ -21,6 +21,7 @@ www_DATA = \ project_catalog.php \ project_delete.php \ project_edit.php \ + project_map.php \ project_home.php \ projectbar.php \ site_catalog.php \ diff --git a/codepot/src/codepot/views/project_catalog.php b/codepot/src/codepot/views/project_catalog.php index 4f6b735e..20ee9ad9 100644 --- a/codepot/src/codepot/views/project_catalog.php +++ b/codepot/src/codepot/views/project_catalog.php @@ -189,7 +189,8 @@ $this->load->view ( ), 'ctxmenuitems' => array ( - array ("project/create", ' ' . $this->lang->line('New'), 'project_catalog_new') + array ("project/create", ' ' . $this->lang->line('New'), 'project_catalog_new'), + array ("project/map", $this->lang->line('Graph'), 'project_catalog_map') ) ) ); diff --git a/codepot/src/codepot/views/project_map.php b/codepot/src/codepot/views/project_map.php new file mode 100644 index 00000000..429a8a57 --- /dev/null +++ b/codepot/src/codepot/views/project_map.php @@ -0,0 +1,245 @@ + + + + + + + + + + + + + + + + + + + + +<?php print $this->lang->line('Projects')?> + + + + +
+ + + +load->view ('taskbar'); ?> + + + +load->view ( + 'projectbar', + array ( + 'banner' => $this->lang->line('Projects'), + + 'page' => array ( + 'type' => '', + 'id' => '' + ), + + 'ctxmenuitems' => array ( + array ("project/create", ' ' . $this->lang->line('New'), 'project_map_new'), + array ("project/catalog", $this->lang->line('Directory'), 'project_map_catalog') + ) + ) +); +?> + + + +
+ +
+ +
+
+ +
+ +
+ +
+ + + +
+ + + +load->view ('footer'); ?> + + + + + + +