Ignore:
Timestamp:
Nov 17, 2010, 4:20:33 PM (10 years ago)
Author:
robert@…
Message:

Improved the template editor so that template fields can be removed from templates, even if the templates are in use, but only if the template fields are never filled. (see ticket #74)

Also changed the user registration so that the administrator confirmation mails will be sent to the administrators in production environment, but still to gscfproject@… in other environments.

Location:
trunk/grails-app/domain/dbnp
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/domain/dbnp/authentication/SecRole.groovy

    r976 r1159  
    1212                authority blank: false, unique: true
    1313        }
     14
     15        static List<SecUser> findUsers(String authority) {
     16                def userRoles = SecUserSecRole.findAllBySecRole( SecRole.findByAuthority( authority ) );
     17               
     18                def users = [];
     19                userRoles.each { users.add( it.secUser ) }
     20               
     21                return users
     22        }
    1423}
  • trunk/grails-app/domain/dbnp/studycapturing/TemplateField.groovy

    r959 r1159  
    118118
    119119        /**
    120          * The number of templates that use this template
    121          *
    122          * @returns             the number of templates that use this template.
     120         * The number of templates that use this template field
     121         *
     122         * @returns             the number of templates that use this template field.
    123123         */
    124124        def numUses() {
     125                return getUses().size();
     126        }
     127
     128        /**
     129         * Retrieves the templates that use this template field
     130         *
     131         * @returns             a list of templates that use this template field.
     132         */
     133        def getUses() {
    125134                def templates = Template.findAll();
    126135                def elements;
     136
    127137                if( templates && templates.size() > 0 ) {
    128138                        elements = templates.findAll { template -> template.fields.contains( this ) };
    129139                } else {
    130                         return 0;
     140                        return [];
    131141                }
    132142
    133                 return elements.size();
    134         }
     143                return elements;
     144        }
     145
     146        /**
     147         * Checks whether this template field is used in a template and also filled in any instance of that template
     148         *
     149         * @returns             true iff this template field is used in a template, the template is instantiated
     150         *                              and an instance has a value for this field. false otherwise
     151         */
     152        def isFilled() {
     153                // Find all entities that use this template
     154                def templates = getUses();
     155
     156                if( templates.size() == 0 )
     157                        return false;
     158
     159                def c = this.entity.createCriteria()
     160                def entities = c {
     161                        'in'("template",templates)
     162                }
     163
     164                def filledEntities = entities.findAll { entity -> entity.getFieldValue( this.name ) }
     165
     166                return filledEntities.size() > 0;
     167        }
     168
     169        /**
     170         * Checks whether this template field is used in the given template and also filled in an instance of that template
     171         *
     172         * @returns             true iff this template field is used in the given template, the template is instantiated
     173         *                              and an instance has a value for this field. false otherwise
     174         */
     175        def isFilledInTemplate(Template t) {
     176                println( "Checking field " + this.name )
     177                println( "Filled in template: " + t)
     178                if( t == null )
     179                        return false;
     180                       
     181                // If the template is not used, if can never be filled
     182                if( !t.fields.contains( this ) )
     183                        return false;
     184
     185                // Find all entities that use this template
     186                def entities = entity.findAllByTemplate( t );
     187
     188                println( "Num entities: " + entities.size() )
     189
     190                def filledEntities = entities.findAll { entity -> entity.getFieldValue( this.name ) }
     191
     192                println( "Num filled entities: " + filledEntities.size() )
     193                println( "Values: " + filledEntities*.getFieldValue( this.name ).join( ', ' ) )
     194                return filledEntities.size() > 0;
     195        }
     196
     197        /**
     198         * Check whether a templatefield that is used in a template may still be edited or deleted.
     199         * That is possible if the templatefield is never filled and the template is only used in one template
     200         *
     201         * This method should only be used for templatefields used in a template that is currently shown. Otherwise
     202         * the user may edit this template field, while it is also in use in another template than is currently shown.
     203         * That lead to confusion.
     204         *
     205         * @returns true iff this template may still be edited or deleted.
     206         */
     207        def isEditable() {
     208                return !isFilled() && numUses() == 1;
     209        }
     210
     211        /**
     212         * Checks whether the given list item is selected in an entity where this template field is used
     213         *
     214         * @param       item    ListItem to check.
     215         * @returns                     true iff the list item is part of this template field and the given list
     216         *                                      item is selected in an entity where this template field is used. false otherwise
     217         *                                      Returns false if the type of this template field is other than STRINGLIST
     218         */
     219        def entryUsed(TemplateFieldListItem item) {
     220                //return numUses() > 0;
     221        }
     222
     223        /**
     224         * Checks whether a term from the given ontology is selected in an entity where this template field is used
     225         *
     226         * @param       item    ListItem to check.
     227         * @returns                     true iff the ontology is part of this template field and a term from the given
     228         *                                      ontology is selected in an entity where this template field is used. false otherwise
     229         *                                      Returns false if the type of this template field is other than ONTOLOGY
     230         */
     231        def entryUsed(Ontology item) {
     232                //return numUses() > 0;
     233        }
     234
    135235}
Note: See TracChangeset for help on using the changeset viewer.