Easy way to make many similar descriptions at once?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Easy way to make many similar descriptions at once?

wagwilk


I'm trying to create a magritte form for surveys used at our company, where many
of the field are identical.

Surveys consist of a header, for which I've created magritte descriptions in the
standard way, and questions which are answered by a rating (an integer of -1, 0
or   1 or nil) and an optional comment (a string).

For this particular survey, there are 18 questions; I'd like some advice on how
to best use magritte to describe them. I've heard of 'multiplicites' in the
context of OneToMany relations -- so this is probably not what I want -- but is
there a count attribute in magritte descriptions?

I'd like to avoid copy/pasting 18 field descriptions if possible.

Cheers
Warren Wilkinson


_______________________________________________
SmallWiki, Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki
Reply | Threaded
Open this post in threaded view
|

Re: Easy way to make many similar descriptions at once?

Lukas Renggli-2
> For this particular survey, there are 18 questions; I'd like some  
> advice on how
> to best use magritte to describe them. I've heard of  
> 'multiplicites' in the
> context of OneToMany relations -- so this is probably not what I  
> want -- but is
> there a count attribute in magritte descriptions?

Yes, OneToMany relations is probably not what you want.

> I'd like to avoid copy/pasting 18 field descriptions if possible.

You can also create descriptions (or copy them from somewhere else)  
programmatically. Just override #description on the instance (or  
class) side of your object and return whatever you want.

Question>>description
        ^ super description copy
                addAll: OtherClass1 description copy;
                addAll: OtherClass2 description copy;
                yourself

The problem you probably now run into is that Question do not  
understand the stuff from OtherClass1 and OtherClass2. To solve this  
you might want to override #readUsing: and #write:using: in Question  
to dispatch the reading/writing to other objects/dictionaries/
whatever ...

Hope this helps?

Cheers,
Lukas

--
Lukas Renggli
http://www.lukas-renggli.ch



_______________________________________________
SmallWiki, Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki
Reply | Threaded
Open this post in threaded view
|

Re: Easy way to make many similar descriptions at once?

wagwilk
Thanks, that worked well. I'm just going to include a brief tutorial on it, so
anyone in the future with a similar problem (maybe, me in three weeks) can benefit.


1) Create the non-programmatically generated fields as you normally would. (In
my case, this was things like Name, Region, Office, etc).

2) Put all the survey questions in a class methods called 'questions'
mine looks like this:

questions
        ^#('Event Free Tool Use'
           'Understands Tasks'
           'Peer Checking'
           'Co-worker Coaching'
           '...'
           'Other')

3) Create instance variables to hold the data on your object. I added two,
questionArray and commentArray, so my class description looks like this:

Object subclass: #EmployeeSurvey
        instanceVariableNames: 'region office questionArray commentArray'
        classVariableNames: ''
        poolDictionaries: ''
        category: 'MyEmployeeSurvey'

4) Modify your initialization method to initialize the arrays

initialize
        questionArray := (Array new: ((self class questions) size)).
        commentArray := (Array new: ((self class questions) size)).


5) Modify this method that generates an array Magritte Descriptions (one for the
field, one for the comment, my appologies for how the code formatting):

createQuestionLabel: aLabel priority: aPriority
        ^(Array new: 2)
                at: 1 put: ((MASingleOptionDescription accessor:
                        (MAChainAccessor accessor: (MAAutoSelectorAccessor selector: #questionArray)
                                                           next: (MADictionaryAccessor key: aPriority))
                                                label: aLabel priority: 9+2*aPriority)
                                                options: #( 'Needs Improvement' 'Meets Expectation' 'Outstanding');
                                                reference: MANumberDescription new;
                                                yourself);
                at: 2 put: (MAMemoDescription accessor:
                        (MAChainAccessor accessor: (MAAutoSelectorAccessor selector: #commentArray)
                                                           next: (MADictionaryAccessor key: aPriority))
                                                label: 'Comment'
                                                priority: 9+2*aPriority+1);
                yourself.


6) Override your classes 'description' method to look like this:

description
        | desc cfields |
        desc := (super description copy).
        (self questions) doWithIndex: [ :val :index | cfields := self
createQuestionLabel: val priority: index.
                                                                                                desc add: (cfields at: 1).
                                                                                                desc add: (cfields at: 2). ].
        ^desc

Cheers,
Warren Wilkinson


Quoting Lukas Renggli <[hidden email]>:

> > For this particular survey, there are 18 questions; I'd like some  
> > advice on how
> > to best use magritte to describe them. I've heard of  
> > 'multiplicites' in the
> > context of OneToMany relations -- so this is probably not what I  
> > want -- but is
> > there a count attribute in magritte descriptions?
>
> Yes, OneToMany relations is probably not what you want.
>
> > I'd like to avoid copy/pasting 18 field descriptions if possible.
>
> You can also create descriptions (or copy them from somewhere else)  
> programmatically. Just override #description on the instance (or  
> class) side of your object and return whatever you want.
>
> Question>>description
> ^ super description copy
> addAll: OtherClass1 description copy;
> addAll: OtherClass2 description copy;
> yourself
>
> The problem you probably now run into is that Question do not  
> understand the stuff from OtherClass1 and OtherClass2. To solve this  
> you might want to override #readUsing: and #write:using: in Question  
> to dispatch the reading/writing to other objects/dictionaries/
> whatever ...
>
> Hope this helps?
>
> Cheers,
> Lukas
>
> --
> Lukas Renggli
> http://www.lukas-renggli.ch
>
>
>
> _______________________________________________
> SmallWiki, Magritte, Pier and Related Tools ...
> https://www.iam.unibe.ch/mailman/listinfo/smallwiki
>





_______________________________________________
SmallWiki, Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki