Changeset 12825


Ignore:
Timestamp:
Mar 28, 2013, 1:30:39 AM (12 years ago)
Author:
Ryan J Ollos
Message:

Refs #4668: Added admin panel for configuration.

Initial patch by mixedpuppy, with iterations by 5past10 and szaffarano.

Note: this has been lightly tested by the committer. Please open new ticket to report any problems you find.

Location:
condfieldsplugin/0.11
Files:
1 deleted
3 edited

Legend:

Unmodified
Added
Removed
  • condfieldsplugin/0.11/condfields/templates/condfields.js

    r5287 r12825  
    1 var condfields = {};
    2 #for type, fields in condfields.types.iteritems()
    3 condfields['$type'] = {};
    4 #for field, val in fields.iteritems()
    5 condfields['$type']['$field'] = ${val and 'true' or 'false'};
    6 #end
    7 #end
    8 
    9 var ok_view_fields = [];
    10 #for field, val in enumerate(condfields.ok_view_fields)
    11 ok_view_fields[$field] = '$val';
    12 #end
    13 
    14 var ok_new_fields = [];
    15 #for field, val in enumerate(condfields.ok_new_fields)
    16 ok_new_fields[$field] = '$val';
    17 #end
     1var condfields = $condfields.types;
     2var field_types = $condfields.field_types;
     3var required_fields = $condfields.required_fields;
    184
    195$(function() {
    206    var mode = '$condfields.mode';
    21 
    22     if(mode == 'view'){
    23         ok_fields = ok_view_fields;
    24     } else {
    25         ok_fields = ok_new_fields;
    26     }
    27    
     7    var all_fields = [];
     8    $('#properties tbody').find('label[for]').each(function(i,e) {
     9        var field = e.getAttribute('for') ? e.getAttribute('for').substr(6): e.getAttribute('htmlFor').substr(6);
     10        all_fields.push(field)
     11    });
    2812    var field_data = {};
    29     for(var i=0;i<ok_fields.length;i++) {
    30         var field = ok_fields[i];
    31         if(mode == 'view' && field == 'owner') continue;
     13    for(var i=0;i<all_fields.length;i++) {
     14        var field = all_fields[i];
    3215        field_data[field] = {
    33             label: $('label[@for=field-'+field+']').parents('th').html(),
    34             input: $('#field-'+field).parents('td').html()
     16            label: $('label[@for=field-'+field+']').parents('th'),
     17            input: $('#field-'+field).parents('td')
    3518        }
    3619    }
     
    4023    function set_type(t) {
    4124
     25        var condfields_fragement = $("<div/>");
     26        $('#properties tbody tr').each(function(i,e) {
     27            var lf = $(this).find("label[for]").attr('for');
     28            if (lf && lf.length > 6 && required_fields.join(' ').indexOf(lf.substr(6))==-1) {
     29                $(this).appendTo(condfields_fragement);
     30            }
     31        })
     32
    4233        var col = 1;
    43         var table = '';
    44         var values = [];
    45         for(var i=0;i<ok_fields.length;i++) {
    46             var field = ok_fields[i];
     34        var rows = [];
     35        for(var i=0;i<all_fields.length;i++) {
     36            var field = all_fields[i];
     37            if (!field_data[field] || field_data[field].label == null) continue;
    4738            if(mode == 'view' && field == 'owner') continue;
    48             if(condfields[t][field] == 0) continue;
     39            if(required_fields.join(' ').indexOf(field) != -1 || condfields[t][field] == 0) continue;
    4940           
    50             if(col == 1) {
    51         table += '<tr><th class="col1">';
    52         table += field_data[field].label + '</th>'
    53         table += '<td class="col1">' + field_data[field].input + '</td>'
     41            full_row = field_types[field] == 'textarea'
     42
     43            if(col == 1 || full_row) {
     44                var tr = $("<tr/>");
     45                field_data[field].label.removeClass("col2");
     46                field_data[field].label.addClass("col1");
     47                tr.append(field_data[field].label);
     48                field_data[field].input.removeClass("col2");
     49                field_data[field].input.addClass("col1");
     50                tr.append(field_data[field].input);
     51                rows.push(tr);
     52                col = 2;
    5453            } else {
    55                 table += '<th class="col2">'
    56         table += field_data[field].label + '</th>'
    57         table += '<td class="col2">' + field_data[field].input + '</td>'
    58             }
    59    
    60    
    61    
    62         if(col == 1){
    63         col =2;
    64             } else {
    65                 table += '</tr>'
    66                 col = 1;
     54                tr = rows[rows.length-1];
     55                field_data[field].label.removeClass("col1");
     56                field_data[field].label.addClass("col2");
     57                tr.append(field_data[field].label);
     58                field_data[field].input.removeClass("col1");
     59                field_data[field].input.addClass("col2");
     60                tr.append(field_data[field].input);
     61                col = 1;
    6762            }
    6863
    69             // Copy out the value
    70             values.push({field:field,value:$('#field-'+field).val()});
     64        if (full_row) {
     65            col = 1
     66        }
     67        }
    7168
    72         }
    73        
    74         if(mode == 'new') {
    75             //$('#properties tbody').html(table);
    76             var n=0;
    77             $('#properties tbody tr').each(function() {
    78                 if(n > 3) {
    79                     $(this).remove()
    80                 }
    81                 n += 1;
    82             })
    83             $('#properties tbody').append(table);
    84         } else {
    85             var n=0;
    86             $('#properties tbody tr').each(function() {
    87                 if(n > 3) {
    88                     $(this).remove()
    89                 }
    90                 n += 1;
    91             })
    92             $('#properties tbody').append(table);
    93         }
    94        
    95         // Restore the previous values
    96         for(var i=0;i<values.length;i++) {
    97             $('#field-'+values[i].field).val(values[i].value);
    98         }
     69        if (col == 2) {
     70            tr = rows[rows.length-1];
     71            tr.append('<th class="col2"/><td class="col2"/>');
     72        }
     73        for (var i=0; i < rows.length; i++) {
     74            $('#properties tbody').append(rows[i]);
     75        }
    9976    }
    10077   
    10178    function set_header_type(t) {
    102         // Make a dict so I can check containment
    103         ok_fields_dict = {}
    104         for(var i=0;i<ok_fields.length;i++) {
    105             ok_fields_dict[ok_fields[i]] = 1;
    106         }
    107        
    10879        var elms = [[]];
    10980        $('table.properties tr').each(function() {
  • condfieldsplugin/0.11/condfields/web_ui.py

    r5287 r12825  
    1 # Created by Noah Kantrowitz on 2007-05-05.
    2 # Copyright (c) 2007 Noah Kantrowitz. All rights reserved.
     1#!/usr/bin/env python
     2# -*- coding: utf-8 -*-
     3#
     4# Copyright (C) 2007-2009 Noah Kantrowitz <noah@coderanger.net>
     5# All rights reserved.
     6#
     7# This software is licensed as described in the file COPYING, which
     8# you should have received as part of this distribution.
     9#
     10
     11try:
     12    import json
     13except ImportError:
     14    import simplejson as json
     15import urllib
    316
    417from trac.core import *
     
    922from trac.ticket.api import TicketSystem
    1023from trac.util.compat import sorted, set
    11 import urllib
    1224
    13 from pkg_resources import resource_filename
    1425
    1526class CondFieldsModule(Component):
     
    2031    include_std = BoolOption('condfields', 'include_standard', default='true',
    2132                             doc='Include the standard fields for all types.')
     33    show_default = BoolOption('condfields', 'show_default', default='false',
     34                             doc='Default is to show or hide selected fields.')
    2235   
    23     forced_fields = set(['type', 'summary', 'reporter', 'description', 'status', 'resolution', 'priority'])
     36    forced_fields = ListOption('condfields', 'forced_fields', doc='Fields that cannot be disabled',
     37                               default="type, summary, reporter, description, status, resolution, priority")
    2438
    2539    def __init__(self):
     
    2842        self.types = [t.name for t in Type.select(self.env)]
    2943        for t in self.types:
    30             setattr(self.__class__, '%s_fields'%t, ListOption('condfields', t, doc='Fields to include for type "%s"'%t))
     44            setattr(self.__class__, '%s_fields'%t, ListOption('condfields', t, doc='Fields to hide for type "%s"'%t))
    3145
    3246    # IRequestHandler methods
     
    3751        #self.log.debug("@ process_request")
    3852        data = {}
    39         data['types'] = {}
     53        ticket_types = {}
     54    field_types = {}
    4055        mode = req.path_info[12:-3]
    4156        if mode != 'new' and mode != 'view':
     
    4560        for f in TicketSystem(self.env).get_ticket_fields():
    4661            all_fields.append(f['name'])
     62
     63        field_types[f['name']] = f['type']
     64       
    4765            if not f.get('custom'):
    4866                standard_fields.add(f['name'])
     
    5977       
    6078        for t in self.types:
    61             fields = set(getattr(self, t+'_fields'))
    62             if self.include_std:
    63                 fields.update(standard_fields)
    64             fields.update(self.forced_fields)
    65             data['types'][t] = dict([
     79            if not self.show_default:
     80                hiddenfields = set(getattr(self, t+'_fields'))
     81                fields = set(all_fields)
     82                fields.difference_update(hiddenfields)
     83            else:
     84                fields = set(getattr(self, t+'_fields'))
     85                if self.include_std:
     86                    fields.update(standard_fields)
     87            fields.update(set(self.forced_fields))
     88            ticket_types[t] = dict([
    6689                (f, f in fields) for f in all_fields
    6790            ])
     
    7194       
    7295        data['mode'] = mode
    73         data['all_fields'] = list(all_fields)
    74         data['ok_view_fields'] = sorted(set(all_fields) - self.forced_fields, key=lambda x: all_fields.index(x))
    75         data['ok_new_fields'] = sorted(set(all_fields) - set(['summary', 'reporter', 'description', 'owner', 'type', 'status', 'resolution']), key=lambda x: all_fields.index(x))
    76         return 'condfields.js', {'condfields': data}, 'text/javascript'
     96        data['types'] = json.dumps(ticket_types)
     97        data['field_types'] = json.dumps(field_types)
     98        data['required_fields'] = json.dumps(list(self.forced_fields))
     99        #data['ok_view_fields'] = sorted(set(all_fields) - set(self.forced_fields), key=lambda x: all_fields.index(x))
     100        #data['ok_new_fields'] = sorted(set(all_fields) - set(['summary', 'reporter', 'description', 'owner', 'type', 'status', 'resolution']), key=lambda x: all_fields.index(x))
     101        return 'condfields.js', {'condfields': data}, 'text/plain'
    77102
    78103    # IRequestFilter methods
     
    96121        return template, data, content_type
    97122
    98     # ITemplateProvider methods
     123    ### ITemplateProvider methods
     124
    99125    def get_htdocs_dirs(self):
    100         #from pkg_resources import resource_filename
    101         #return [('condfields', resource_filename(__name__, 'htdocs'))]
    102         return ()
     126        return []
    103127           
    104128    def get_templates_dirs(self):
    105         #yield resource_filename(__name__, 'templates')
    106129        return ()
     130        from pkg_resources import resource_filename
     131        return [resource_filename(__name__, 'templates')]
    107132
    108    
  • condfieldsplugin/0.11/setup.py

    r5287 r12825  
    11#!/usr/bin/env python
    2 # -*- coding: iso-8859-1 -*-
     2# -*- coding: utf-8 -*-
     3#
     4# Copyright (C) 2007-2009 Noah Kantrowitz <noah@coderanger.net>
     5# All rights reserved.
     6#
     7# This software is licensed as described in the file COPYING, which
     8# you should have received as part of this distribution.
     9#
    310
    411from setuptools import setup
    512
    613setup(
    7     name = 'TracCondFields',
    8     version = '2.0',
    9     packages = ['condfields'],
    10     package_data = { 'condfields': ['templates/*', 'htdocs/*.js', 'htdocs/*.css' ] },
     14    name='TracCondFields',
     15    version='2.0',
     16    packages=['condfields'],
     17    package_data={'condfields': ['templates/*']},
    1118
    12     author = 'Noah Kantrowitz',
    13     author_email = 'noah@coderanger.net',
    14     description = 'Support for conditional fields in different ticket types.',
    15     license = 'BSD',
    16     keywords = 'trac plugin ticket conditional fields',
    17     url = 'http://trac-hacks.org/wiki/CondFieldsPlugin',
    18     classifiers = [
     19    author='Noah Kantrowitz',
     20    author_email='noah@coderanger.net',
     21    description='Support for conditional fields in different ticket types.',
     22    license='BSD 3-Clause',
     23    keywords='trac plugin ticket conditional fields',
     24    url='http://trac-hacks.org/wiki/CondFieldsPlugin',
     25    classifiers=[
    1926        'Framework :: Trac',
    2027    ],
    21    
    22     install_requires = ['Trac>=0.11'],
    2328
    24     entry_points = {
     29    install_requires=['Trac>=0.11'],
     30    extras_require={'customfieldadmin': 'TracCustomFieldAdmin'},
     31
     32    entry_points={
    2533        'trac.plugins': [
    2634            'condfields.web_ui = condfields.web_ui',
     35            'condfields.admin = condfields.admin[customfieldadmin]',
    2736        ]
    2837    },
Note: See TracChangeset for help on using the changeset viewer.