From 4f23ea4dd5d69012498b86c3dd0fdfeacf44e51e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20d=27Anterroches?= Date: Wed, 11 Aug 2010 13:58:41 +0200 Subject: [PATCH 1/4] Added the ability to create a new project with another one as template. --- src/IDF/Form/Admin/ProjectCreate.php | 73 ++++++++++++++++++- src/IDF/Views/Admin.php | 3 + .../templates/idf/gadmin/projects/create.html | 38 ++++++---- 3 files changed, 97 insertions(+), 17 deletions(-) diff --git a/src/IDF/Form/Admin/ProjectCreate.php b/src/IDF/Form/Admin/ProjectCreate.php index 182c737..1ba8561 100644 --- a/src/IDF/Form/Admin/ProjectCreate.php +++ b/src/IDF/Form/Admin/ProjectCreate.php @@ -109,6 +109,20 @@ class IDF_Form_Admin_ProjectCreate extends Pluf_Form 'cols' => 40), 'widget' => 'Pluf_Form_Widget_TextareaInput', )); + + $projects = array('--' => '--'); + foreach (Pluf::factory('IDF_Project')->getList(array('order' => 'name ASC')) as $proj) { + $projects[$proj->name] = $proj->shortname; + } + $this->fields['template'] = new Pluf_Form_Field_Varchar( + array('required' => false, + 'label' => __('Project template'), + 'initial' => '--', + 'help_text' => __('Use the given project to initialize the new project. Access rights and general configuration will be taken from the template project.'), + 'widget' => 'Pluf_Form_Widget_SelectInput', + 'widget_attrs' => array('choices' => $projects), + )); + /** * [signal] * @@ -229,12 +243,67 @@ class IDF_Form_Admin_ProjectCreate extends Pluf_Form $this->cleaned_data[$key] : ''; $conf->setVal($key, $this->cleaned_data[$key]); } + if ($this->cleaned_data['template'] != '--') { + // Find the template project + $sql = new Pluf_SQL('shortname=%s', + array($this->cleaned_data['template'])); + $tmpl = Pluf::factory('IDF_Project')->getOne(array('filter' => $sql->gen())); + $tmplconf = new IDF_Conf(); + $tmplconf->setProject($tmpl); + // We need to get all the configuration variables we want from + // the old project and put them into the new project. + $props = array( + 'labels_download_predefined', + 'labels_download_one_max', + 'labels_wiki_predefined', + 'labels_wiki_one_max', + 'labels_issue_open', + 'labels_issue_closed', + 'labels_issue_predefined', + 'labels_issue_one_max', + 'webhook_url', + 'downloads_access_rights', + 'review_access_rights', + 'wiki_access_rights', + 'source_access_rights', + 'issues_access_rights', + 'downloads_notification_email', + 'review_notification_email', + 'wiki_notification_email', + 'source_notification_email', + 'issues_notification_email', + ); + foreach ($props as $prop) { + $conf->setVal($prop, $tmplconf->getVal($prop)); + } + } $project->created(); - IDF_Form_MembersConf::updateMemberships($project, - $this->cleaned_data); + if ($this->cleaned_data['template'] == '--') { + IDF_Form_MembersConf::updateMemberships($project, + $this->cleaned_data); + } else { + // Get the membership of the template $tmpl + IDF_Form_MembersConf::updateMemberships($project, + $tmpl->getMembershipData('string')); + } $project->membershipsUpdated(); return $project; } + + /** + * Check that the template project exists. + */ + public function clean_template() + { + if ($this->cleaned_data['template'] == '--') { + return $this->cleaned_data['template']; + } + $sql = new Pluf_SQL('shortname=%s', array($this->cleaned_data['template'])); + if (Pluf::factory('IDF_Project')->getOne(array('filter' => $sql->gen())) == null) { + throw new Pluf_Form_Invalid(__('This project is not available.')); + } + return $this->cleaned_data['template']; + } } diff --git a/src/IDF/Views/Admin.php b/src/IDF/Views/Admin.php index f7525a8..23085a3 100644 --- a/src/IDF/Views/Admin.php +++ b/src/IDF/Views/Admin.php @@ -118,6 +118,9 @@ class IDF_Views_Admin /** * Creation of a project. * + * A project can use another project as template. In that case, + * everything but the data in the input at creation time is + * reused, including the wiki pages. */ public $projectCreate_precond = array('Pluf_Precondition::staffRequired'); public function projectCreate($request, $match) diff --git a/src/IDF/templates/idf/gadmin/projects/create.html b/src/IDF/templates/idf/gadmin/projects/create.html index 1affd7d..f2765fb 100644 --- a/src/IDF/templates/idf/gadmin/projects/create.html +++ b/src/IDF/templates/idf/gadmin/projects/create.html @@ -53,21 +53,28 @@ +{$form.f.template.labelTag} +{if $form.f.template.errors}{$form.f.template.fieldErrors}{/if} +{$form.f.template|unsafe}
+{$form.f.template.help_text} + + + {$form.f.owners.labelTag}: {if $form.f.owners.errors}{$form.f.owners.fieldErrors}{/if} {$form.f.owners|unsafe}
-{trans 'Provide at least one owner for the project.'} +{trans 'Provide at least one owner for the project or use a template.'} - + {$form.f.members.labelTag}: {if $form.f.members.errors}{$form.f.members.fieldErrors}{/if} {$form.f.members|unsafe} - + {if $form.f.private_project.errors}{$form.f.private_project.fieldErrors}{/if} {$form.f.private_project|unsafe} @@ -119,18 +126,19 @@ $(document).ready(function() { $(".svn-form").hide(); } }); + // Hide if not svn + if ($("#id_template option:selected").val() == "--") { + $(".no-template").show(); + } else { + $(".no-template").hide(); + } + $("#id_template").change(function () { + if ($("#id_template option:selected").val() == "--") { + $(".no-template").show(); + } else { + $(".no-template").hide(); + } + }); }); {/literal}{/block} -{* - - $("select").change(function () { - var str = ""; - $("select option:selected").each(function () { - str += $(this).text() + " "; - }); - $("div").text(str); - }) - .trigger('change'); - -*} From 9e6c7dad88b4e9715f7ff03474b004466e1e9ef9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20d=27Anterroches?= Date: Wed, 11 Aug 2010 14:12:03 +0200 Subject: [PATCH 2/4] Fixed to use the private status and the description from the template when creating a project. --- src/IDF/Form/Admin/ProjectCreate.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/IDF/Form/Admin/ProjectCreate.php b/src/IDF/Form/Admin/ProjectCreate.php index 1ba8561..3e5b0cb 100644 --- a/src/IDF/Form/Admin/ProjectCreate.php +++ b/src/IDF/Form/Admin/ProjectCreate.php @@ -248,6 +248,8 @@ class IDF_Form_Admin_ProjectCreate extends Pluf_Form $sql = new Pluf_SQL('shortname=%s', array($this->cleaned_data['template'])); $tmpl = Pluf::factory('IDF_Project')->getOne(array('filter' => $sql->gen())); + $project->private = $tmpl->private; + $project->description = $tmpl->description; $tmplconf = new IDF_Conf(); $tmplconf->setProject($tmpl); // We need to get all the configuration variables we want from From 7a2065c6877dcb85455fcd636e36c1f8d78b59a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20d=27Anterroches?= Date: Wed, 11 Aug 2010 14:42:06 +0200 Subject: [PATCH 3/4] Fixed to correctly use the default values if the template project was not fully updated. --- src/IDF/Form/Admin/ProjectCreate.php | 42 ++++++++++++++-------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/IDF/Form/Admin/ProjectCreate.php b/src/IDF/Form/Admin/ProjectCreate.php index 3e5b0cb..93470f2 100644 --- a/src/IDF/Form/Admin/ProjectCreate.php +++ b/src/IDF/Form/Admin/ProjectCreate.php @@ -255,28 +255,28 @@ class IDF_Form_Admin_ProjectCreate extends Pluf_Form // We need to get all the configuration variables we want from // the old project and put them into the new project. $props = array( - 'labels_download_predefined', - 'labels_download_one_max', - 'labels_wiki_predefined', - 'labels_wiki_one_max', - 'labels_issue_open', - 'labels_issue_closed', - 'labels_issue_predefined', - 'labels_issue_one_max', - 'webhook_url', - 'downloads_access_rights', - 'review_access_rights', - 'wiki_access_rights', - 'source_access_rights', - 'issues_access_rights', - 'downloads_notification_email', - 'review_notification_email', - 'wiki_notification_email', - 'source_notification_email', - 'issues_notification_email', + 'labels_download_predefined' => IDF_Form_UploadConf::init_predefined, + 'labels_download_one_max' => IDF_Form_UploadConf::init_one_max, + 'labels_wiki_predefined' => IDF_Form_WikiConf::init_predefined, + 'labels_wiki_one_max' => IDF_Form_WikiConf::init_one_max, + 'labels_issue_open' => IDF_Form_IssueTrackingConf::init_open, + 'labels_issue_closed' => IDF_Form_IssueTrackingConf::init_closed, + 'labels_issue_predefined' => IDF_Form_IssueTrackingConf::init_predefined, + 'labels_issue_one_max' => IDF_Form_IssueTrackingConf::init_one_max, + 'webhook_url' => '', + 'downloads_access_rights' => 'all', + 'review_access_rights' => 'all', + 'wiki_access_rights' => 'all', + 'source_access_rights' => 'all', + 'issues_access_rights' => 'all', + 'downloads_notification_email' => '', + 'review_notification_email' => '', + 'wiki_notification_email' => '', + 'source_notification_email' => '', + 'issues_notification_email' => '', ); - foreach ($props as $prop) { - $conf->setVal($prop, $tmplconf->getVal($prop)); + foreach ($props as $prop => $def) { + $conf->setVal($prop, $tmplconf->getVal($prop, $def)); } } $project->created(); From 3d1ac97dc34ed13e646dc3fc5b2780095f2135f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20d=27Anterroches?= Date: Wed, 11 Aug 2010 14:50:32 +0200 Subject: [PATCH 4/4] Correctly uses the private/description from the template project. --- src/IDF/Form/Admin/ProjectCreate.php | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/IDF/Form/Admin/ProjectCreate.php b/src/IDF/Form/Admin/ProjectCreate.php index 93470f2..a8017b8 100644 --- a/src/IDF/Form/Admin/ProjectCreate.php +++ b/src/IDF/Form/Admin/ProjectCreate.php @@ -231,8 +231,18 @@ class IDF_Form_Admin_ProjectCreate extends Pluf_Form $project = new IDF_Project(); $project->name = $this->cleaned_data['name']; $project->shortname = $this->cleaned_data['shortname']; - $project->private = $this->cleaned_data['private_project']; - $project->description = __('Click on the Project Management tab to set the description of your project.'); + + if ($this->cleaned_data['template'] != '--') { + // Find the template project + $sql = new Pluf_SQL('shortname=%s', + array($this->cleaned_data['template'])); + $tmpl = Pluf::factory('IDF_Project')->getOne(array('filter' => $sql->gen())); + $project->private = $tmpl->private; + $project->description = $tmpl->description; + } else { + $project->private = $this->cleaned_data['private_project']; + $project->description = __('Click on the Project Management tab to set the description of your project.'); + } $project->create(); $conf = new IDF_Conf(); $conf->setProject($project); @@ -244,12 +254,6 @@ class IDF_Form_Admin_ProjectCreate extends Pluf_Form $conf->setVal($key, $this->cleaned_data[$key]); } if ($this->cleaned_data['template'] != '--') { - // Find the template project - $sql = new Pluf_SQL('shortname=%s', - array($this->cleaned_data['template'])); - $tmpl = Pluf::factory('IDF_Project')->getOne(array('filter' => $sql->gen())); - $project->private = $tmpl->private; - $project->description = $tmpl->description; $tmplconf = new IDF_Conf(); $tmplconf->setProject($tmpl); // We need to get all the configuration variables we want from