Mercurial > public > src > phphgadmin
changeset 9:97bc7635ce3f
HGRC read properties, and prepped for write
author | joshjcarrier |
---|---|
date | Thu, 13 May 2010 19:40:22 -0700 |
parents | 6215bb22f3d3 |
children | 0e7e4cead7c9 |
files | admin/application/config/config.php admin/application/controllers/hgdir.php admin/application/controllers/hgrepo.php admin/application/libraries/hgconf2ini.php admin/application/libraries/hgphp.php admin/application/views/repo_directory.php admin/application/views/repository.php |
diffstat | 7 files changed, 132 insertions(+), 76 deletions(-) [+] |
line wrap: on
line diff
--- a/admin/application/config/config.php Thu May 13 17:43:10 2010 -0700 +++ b/admin/application/config/config.php Thu May 13 19:40:22 2010 -0700 @@ -11,8 +11,8 @@ | http://example.com/ | */ -$config['base_url'] = "http://hg-php.joshjcarrier.com/admin/"; - +//$config['base_url'] = "http://hg-php.joshjcarrier.com/admin/"; +$config['base_url'] = "http://localhost/admin/"; /* |-------------------------------------------------------------------------- | Index File
--- a/admin/application/controllers/hgdir.php Thu May 13 17:43:10 2010 -0700 +++ b/admin/application/controllers/hgdir.php Thu May 13 19:40:22 2010 -0700 @@ -97,48 +97,6 @@ $this->template->inject_partial('user_err', 'Repository "'. $del_repo_name .'" could not be deleted; an unknown error has occured.'); break; } - /* - $lsdir = $this->hgphp->lsdir(); - $existingdir = array_keys($lsdir); - $tempexistingdir = array(); - foreach($existingdir as $repo_name) - { - $tempexistingdir[$repo_name] = $repo_name; - } - $existingdir = $tempexistingdir; - - if(isset($lsdir[$del_repo_name])) - { - $del_status = true; - - // existing filesystem is not missing, thus needs to be deleted - if($lsdir[$del_repo_name]['status'] != 2) - { - $del_status = $this->hgphp->delete_repository($del_repo_name); - } - - // remove from hgweb.config - if($del_status) - { - // edit the directory - unset($existingdir[$del_repo_name]); - $this->hgphp->saveconf($existingdir); - - // success message - $this->template->inject_partial('user_msg', 'Repository "'. $del_repo_name .'" deleted successfully.'); - } - else - { - $this->template->inject_partial('user_err', 'Repository "'. $del_repo_name .'" could not be deleted; insufficient user or server privileges.'); - } - } - else - { - $this->template->inject_partial('user_err', 'Repository "'. $del_repo_name .'" could not be deleted; it does not exist or is already deleted.'); - } - */ } - - //$this->index(); } }
--- a/admin/application/controllers/hgrepo.php Thu May 13 17:43:10 2010 -0700 +++ b/admin/application/controllers/hgrepo.php Thu May 13 19:40:22 2010 -0700 @@ -5,23 +5,33 @@ function HgRepo() { parent::Private_Controller(); - $this->load->library('hg_confparser'); + $this->load->library('hgphp'); } function manage() { $repositoryName = $this->uri->segment(3, 0); + if($repositoryName == FALSE) + { + $this->load->helper('url'); + redirect('/hgdir'); + return; + } + + $form_action = $this->input->post('form_action'); + if($form_action != FALSE) + { + print_r($this->input->post('hgrc')); + print_r($this->input->post('hgrc[web]')); + } + $this->template->title($repositoryName, 'Repository Editor'); //$lsdir = $this->hg_confparser->lsdir(); //$this->template->build('repo_directory', array('lsdir'=>$lsdir)); - $this->template->build('repository'); - } - - function save() - { - + $hgrc = $this->hgphp->stat_repository($repositoryName); + $this->template->build('repository', array('hgrc' => $hgrc)); } function index()
--- a/admin/application/libraries/hgconf2ini.php Thu May 13 17:43:10 2010 -0700 +++ b/admin/application/libraries/hgconf2ini.php Thu May 13 19:40:22 2010 -0700 @@ -71,24 +71,52 @@ { $hgwebconf_all = $this->getHgWebDirConfig($fs_hgwebdir); -// $hgwebconf_collections = array(); -// foreach($hg_collections as $hg_collection) -// { -// $hgwebconf_collections[$hg_collection] = $hg_collection; -// } $hgwebconf_all['collections'] = $hg_collections; return $this->setHgWebDirConfig($hgwebconf_all, $fs_hgwebdir); } - function getHGRC($fs_collection_path, $r_name) + function getHGRC($r_name) { + $hgrc = $this->_repositories_rel_dir . $r_name . '/.hg/hgrc'; + return parse_ini_file($hgrc, true); } - function setHGRC() + function setHGRC($r_name, $hgrc_data) { + $hgrc = $this->_repositories_rel_dir . $r_name . '/.hg/hgrc'; + $hgrc_new_ini = ';Generated by Hg-PHP Mercurial Repository Manager'; + // generate ini string + foreach($hgrc_data as $ini_section_name => $ini_section_items) + { + // section header + $hgrc_new_ini .= "\n[".$ini_section_name.']'; + + if($ini_section_name == 'collections') + { + foreach($ini_section_items as $ini_item_name => $ini_item_value) + { + $hgrc_new_ini .= "\n" . $this->_repositories_abs_dir . $ini_item_value . ' = ' . $ini_item_value; + } + } + + else + { + foreach($ini_section_items as $ini_item_name => $ini_item_value) + { + $hgrc_new_ini .= "\n" . $ini_item_name . ' = ' . $ini_item_value; + } + } + } + $hgrc_new_ini .= "\n;End generated HGRC\n"; + + // TODO concurrency check + // persist to disk + file_put_contents($hgrc, $hgrc_new_ini); + + return true; } function touchHGRC($project_name) @@ -98,6 +126,17 @@ // create file touch($cd . 'hgrc'); + // FIXME as config + $blank_hgrc = array( + 'paths' => array('default' => 'http://localhost/' . $project_name), + 'web' => array( + 'contact' => 'admin', + 'description' => '', + 'push_ssl' => 'false', + ) + ); + $this->setHGRC($project_name, $blank_hgrc); + return true; }
--- a/admin/application/libraries/hgphp.php Thu May 13 17:43:10 2010 -0700 +++ b/admin/application/libraries/hgphp.php Thu May 13 19:40:22 2010 -0700 @@ -136,6 +136,7 @@ } + // TODO function update_repository() {} @@ -196,7 +197,12 @@ } } - + function stat_repository($project_name) + { + // FIXME permission check + + return $this->_ci->hgconf2ini->getHGRC($project_name); + } /** * Public accessors - permissions @@ -224,7 +230,7 @@ } $cd = $this->_repositories_rel_dir; - mkdir($cd . $repository_name . '/.hg/store/data/', 755, TRUE); + mkdir($cd . $repository_name . '/.hg/store/data/', 0755, TRUE); // create hgrc return $this->_ci->hgconf2ini->touchHGRC($repository_name);
--- a/admin/application/views/repo_directory.php Thu May 13 17:43:10 2010 -0700 +++ b/admin/application/views/repo_directory.php Thu May 13 19:40:22 2010 -0700 @@ -46,20 +46,20 @@ }); // Dialog Link - $('#dialog_link_create').click(function(){ + $('#dialog_link_create, #dialog_link2_create').click(function(){ $('#dialog_create').dialog('open'); document.forms['form_create'].form_create_name.focus(); return false; }); // Dialog Link - $('#dialog_link_disable').click(function(){ + $('#dialog_link_disable, #dialog_link2_disable').click(function(){ $('#dialog_disable').dialog('open'); return false; }); // Dialog Link - $('#dialog_link_delete').click(function(){ + $('#dialog_link_delete, #dialog_link2_delete').click(function(){ document.forms['form_delete'].form_delete_name.focus(); $('#dialog_delete').dialog('open'); return false; @@ -119,7 +119,7 @@ <!-- ui-dialog --> <div id="dialog_create" class="dialog" title="<?php echo lang('hg_configparser_action_create'); ?>"> - <form action="/admin/hgdir" method="post" id="form_create" name="form_create"> + <form action="<?php echo site_url('hgdir'); ?>" method="post" id="form_create" name="form_create"> <table style="width: 100%"> <tr> <td> @@ -134,7 +134,7 @@ <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p> </div> <div id="dialog_delete" class="dialog" title="<?php echo lang('hg_configparser_action_delete'); ?>"> - <form action="/admin/hgdir" method="post" id="form_delete" name="form_delete"> + <form action="<?php echo site_url('hgdir'); ?>" method="post" id="form_delete" name="form_delete"> <table style="width: 100%"> <tr> <td>
--- a/admin/application/views/repository.php Thu May 13 17:43:10 2010 -0700 +++ b/admin/application/views/repository.php Thu May 13 19:40:22 2010 -0700 @@ -1,21 +1,64 @@ +<script type="text/javascript"> + $(function(){ + // Dialog + $('#dialog_save').dialog({ + autoOpen: false, + width: 600, + modal: true, + buttons: { + "Ok": function() { + document.forms['form_hgrc'].form_action.value = "hgrc_save"; + document.forms['form_hgrc'].submit(); + }, + "Cancel": function() { + document.forms['form_hgrc'].reset(); + $(this).dialog("close"); + } + } + }); + + // Dialog Link + $('#dialog_link_save, #dialog_link2_save').click(function(){ + $('#dialog_save').dialog('open'); + return false; + }); + + //hover states on the static widgets + $('.dialog_link, ul#icons li').hover( + function() { $(this).addClass('ui-state-hover'); }, + function() { $(this).removeClass('ui-state-hover'); } + ); + }); +</script> <table class="bigtable"> +<form action="<?php echo current_url(); ?>" method="post" id="form_hgrc" name="form_hgrc"> + <input type="hidden" name="form_action" id="form_action" value="" /> + <?php if(isset($hgrc)): foreach($hgrc as $section_name => $section): ?> <tr> - <th><?php echo lang('hg_configparser_title_configkey'); ?></th> + <th><?php echo $section_name ?></th> <th></th> - <th><?php echo lang('hg_configparser_title_configval'); ?></th> + <th><a href='http://www.selenic.com/mercurial/hgrc.5.html#<?php echo $section_name ?>' target="_blank">Tips</a></th> </tr> - <tr> - <td>CONFIG ITEM</td> - <td>TOOLTIP</td> - <td><input type="text" /></td> + + <?php $parity=0; foreach($section as $key => $value):?> + <tr class="parity<?php echo $parity; $parity=($parity+1)%2;?>"> + <td><?php echo $key; ?></td> + <td><input type="text" name="hgrc[<?php echo $section_name ?>][<?php echo $key; ?>]" value="<?php echo $value; ?>" /></td> + <td><?php echo $value; ?></td> </tr> + <?php endforeach; ?> + + <?php endforeach; endif; ?> <tr> <td colspan="3"> - <input type="button" value="<?php echo lang('hg_configparser_action_save'); ?>" /> - <input type="button" value="<?php echo lang('hg_configparser_action_reset'); ?>" /> - <input type="button" value="<?php echo lang('hg_configparser_action_cancel'); ?>" /> - <input type="button" value="<?php echo lang('hg_configparser_action_delete'); ?>" /> + <p><a href="#" id="dialog_link_save" class="ui-state-default ui-corner-all dialog_link"><span class="ui-icon"></span><?php print lang('hg_configparser_action_save'); ?></a> + <a href="#" id="dialog_link_reset" class="ui-state-default ui-corner-all dialog_link"><span class="ui-icon"></span><?php print lang('hg_configparser_action_reset'); ?></a> + <a href="#" id="dialog_link_cancel" class="ui-state-default ui-corner-all dialog_link"><span class="ui-icon"></span><?php print lang('hg_configparser_action_cancel'); ?></a> + <a href="#" id="dialog_link_delete" class="ui-state-default ui-corner-all dialog_link"><span class="ui-icon"></span><?php print lang('hg_configparser_action_delete'); ?></a></p> </td> </tr> -</table> \ No newline at end of file +</table> + <div id="dialog_save" class="dialog" title="Save HGRC?"> + Saving will immediately put the changes into effect. + </div> \ No newline at end of file