Save / restore project labels for the forge.

This commit is contained in:
Thomas Keller 2011-12-06 20:39:15 +01:00
parent 0d410605f9
commit 63bc47e7b7
6 changed files with 172 additions and 0 deletions

54
src/IDF/Forge.php Normal file
View File

@ -0,0 +1,54 @@
<?php
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
# ***** BEGIN LICENSE BLOCK *****
# This file is part of InDefero, an open source project management application.
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
#
# InDefero is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# InDefero is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
# ***** END LICENSE BLOCK ***** */
/**
* A lightweight model for the singleton forge entity
*/
class IDF_Forge
{
public $_model = __CLASS__;
public $id = 1;
/**
* @var IDF_Gconf
*/
private $conf;
private function __construct() {
$this->conf = new IDF_Gconf();
$this->conf->setModel($this);
}
public static function instance() {
return new IDF_Forge();
}
public function getProjectLabels($default = '') {
return $this->conf->getVal('project_labels', $default);
}
public function setProjectLabels($labels) {
$this->conf->setVal('project_labels', $labels);
}
}

View File

@ -0,0 +1,47 @@
<?php
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
# ***** BEGIN LICENSE BLOCK *****
# This file is part of InDefero, an open source project management application.
# Copyright(C) 2008-2011 Céondo Ltd and contributors.
#
# InDefero is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
#(at your option) any later version.
#
# InDefero is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
# ***** END LICENSE BLOCK ***** */
/**
* Configuration of forge labels.
*/
class IDF_Form_Admin_LabelConf extends Pluf_Form
{
const init_project_labels = 'UI:GUI = Applications with graphical user interfaces
UI:CLI = Applications with no graphical user interfaces
License:BSD = Applications with BSD license
License:GPL = Applications with GPL license
';
public function initFields($extra=array())
{
$this->fields['project_labels'] = new Pluf_Form_Field_Varchar(
array('required' => true,
'label' => __('Predefined project labels'),
'initial' => self::init_project_labels,
'widget_attrs' => array('rows' => 13,
'cols' => 75),
'widget' => 'Pluf_Form_Widget_TextareaInput',
));
}
}

View File

@ -81,6 +81,40 @@ class IDF_Views_Admin
$request); $request);
} }
/**
* Administrate the labels of a project.
*/
public $projectLabels_precond = array('Pluf_Precondition::staffRequired');
public function projectLabels($request, $match)
{
$title = __('Project Labels');
$forge = IDF_Forge::instance();
if ($request->method == 'POST') {
$form = new IDF_Form_Admin_LabelConf($request->POST);
if ($form->isValid()) {
$forge->setProjectLabels($form->cleaned_data['project_labels']);
$request->user->setMessage(__('The label configuration has been saved.'));
$url = Pluf_HTTP_URL_urlForView('IDF_Views_Admin::projectLabels');
return new Pluf_HTTP_Response_Redirect($url);
}
} else {
$params = array();
if (($labels = $forge->getProjectLabels(false)) !== false) {
$params['project_labels'] = $labels;
}
if (count($params) == 0) {
$params = null; //Nothing in the db, so new form.
}
$form = new IDF_Form_Admin_LabelConf($params);
}
return Pluf_Shortcuts_RenderToResponse('idf/gadmin/projects/labels.html',
array(
'page_title' => $title,
'form' => $form,
),
$request);
}
/** /**
* Edition of a project. * Edition of a project.
* *

View File

@ -478,6 +478,11 @@ $ctl[] = array('regex' => '#^/admin/projects/(\d+)/$#',
'model' => 'IDF_Views_Admin', 'model' => 'IDF_Views_Admin',
'method' => 'projectUpdate'); 'method' => 'projectUpdate');
$ctl[] = array('regex' => '#^/admin/projects/labels/$#',
'base' => $base,
'model' => 'IDF_Views_Admin',
'method' => 'projectLabels');
$ctl[] = array('regex' => '#^/admin/projects/create/$#', $ctl[] = array('regex' => '#^/admin/projects/create/$#',
'base' => $base, 'base' => $base,
'model' => 'IDF_Views_Admin', 'model' => 'IDF_Views_Admin',

View File

@ -2,5 +2,6 @@
{block tabprojects} class="active"{/block} {block tabprojects} class="active"{/block}
{block subtabs} {block subtabs}
<a {if $inIndex}class="active" {/if}href="{url 'IDF_Views_Admin::projects'}">{trans 'Project List'}</a> | <a {if $inIndex}class="active" {/if}href="{url 'IDF_Views_Admin::projects'}">{trans 'Project List'}</a> |
<a {if $inLabels}class="active" {/if}href="{url 'IDF_Views_Admin::projectLabels'}">{trans 'Project Labels'}</a> |
<a {if $inCreate}class="active" {/if}href="{url 'IDF_Views_Admin::projectCreate'}">{trans 'Create Project'}</a> {if $project} | <a href="{url 'IDF_Views_Project::admin', array($project.shortname)}">{trans 'Change Project Details'}</a>{/if} <a {if $inCreate}class="active" {/if}href="{url 'IDF_Views_Admin::projectCreate'}">{trans 'Create Project'}</a> {if $project} | <a href="{url 'IDF_Views_Project::admin', array($project.shortname)}">{trans 'Change Project Details'}</a>{/if}
{/block} {/block}

View File

@ -0,0 +1,31 @@
{extends "idf/gadmin/projects/base.html"}
{block docclass}yui-t3{assign $inLabels=true}{/block}
{block body}
<form method="post" action=".">
<table class="form" summary="">
<tr>
<td colspan="2"><strong>{$form.f.project_labels.labelTag}:</strong><br />
{if $form.f.project_labels.errors}{$form.f.project_labels.fieldErrors}{/if}
{$form.f.project_labels|unsafe}
</td>
</tr>
<tr>
<td colspan="2">
<input type="submit" value="{trans 'Save Changes'}" name="submit" />
</td>
</tr>
</table>
</form>
{/block}
{block context}
<div class="issue-submit-info">
{blocktrans}
<p><strong>Instructions:</strong></p>
<p>List one status value per line in desired sort-order.</p>
<p>Optionally, use an equals-sign to document the meaning of each status value.</p>
{/blocktrans}
</div>
{/block}