Sum a atributte on collection tag

39 views
Skip to first unread message

Enrique Moreira

unread,
Aug 15, 2011, 8:45:25 PM8/15/11
to hobo...@googlegroups.com
Hello

How to sum a <collection> ? attribute??

<table-plus> not work on Parent Child relation tables?

Any Ideas

Regards
Enrique

Enrique Moreira

unread,
Aug 16, 2011, 5:37:55 PM8/16/11
to hobo...@googlegroups.com

Not ideas??

kevinpfromnm

unread,
Aug 16, 2011, 5:48:04 PM8/16/11
to hobo...@googlegroups.com
Honestly not sure what you're asking.  You want to display a sum from a child relation?  <view field="association_name.sum(:column_name_to_sum)" />

Enrique Moreira

unread,
Aug 16, 2011, 6:10:39 PM8/16/11
to hobo...@googlegroups.com
Hello Kevin
--------------------------
Proyecto.rb
has_many: plan_operativos
-----------------
Plan_Operativo.rb
cant:decimal
belongs_to: proyecto
--------------------

this code in application.dryml>

<def tag="show-page" for="Proyecto">
  <page merge title="#{ht 'proyecto.show.title', :default=>['Proyecto'] }">

    <body: class="show-page proyecto" param/>

    <content: param>
          <header param="content-header">
            <a:epserv param="parent-link">&laquo; <ht key="proyecto.actions.back_to_parent" parent="EPS" name="&this">Back to <name/></ht></a:epserv>
            <h2 param="heading">
              <ht key="proyecto.show.heading" name="&this.respond_to?(:name) ? this.name : ''">
                <name/>
              </ht>
            </h2>

            <record-flags fields="" param/>

            <a action="edit" if="&can_edit?" param="edit-link">
              <ht key="proyecto.actions.edit" name="&this.respond_to?(:name) ? this.name : ''">
                Edit Proyecto
              </ht>
            </a>
          </header>

          <section param="content-body">
            <field-list fields="codigoadm, proyecto, proyectado_hombres, proyectado_mujeres, real_hombres, real_mujeres, anio, fecha_inicio, fecha_final, status, monto_total_aprobado, monto_delap_aprobado, monto_gbeneficiario_aprobado, monto_total_ejecutado, monto_delap_ejecutado, monto_gbeneficiario_ejecutado, ubic_fis, comentario, municipio, rubro, tecnico" param/>
          <!--- Plan Operativo Indicadores -->         
          <section param="collection-section">
              <h3 param="collection-heading">
                <ht key="plan_operativo.collection.heading" count="&this.plan_operativos.count" >
                  <human-collection-name collection="plan_operativos" your/>
                </ht>
              </h3>
              <!-- <collection:plan_operativos param>  --> <!-------this line is original code works fine instead of -->
              
              <!--------  NEXT CODE TO FIX ---------change to table-plus need-------------------->
              <collection plan_operativos param>
                <div>
                  <view field="sum(:cant)"/>  
                </div>
              </collection>
                     
              <div>
              total:         <!--- Sum Total of Collecction --->
              </div>
         <!------------ END- CODE FIX -------------------------------------->
       
              <a:plan_operativos action="new" if="&can_create?(@proyecto.plan_operativos)" param="new-link">
                <ht key="plan_operativo.actions.new" count="1">
                  New Plan_operativo
                </ht>
              </a:plan_operativos>
            </section>
        <!-- Fin PlanOperativo Indicadores --> 
          
          <section param="collection-section">
              <h3 param="collection-heading">
                <ht key="documento.collection.heading" count="&this.documentos.count" >
                  <human-collection-name collection="documentos" your/>
                </ht>
              </h3>

              <collection:documentos param/>

              <a:documentos action="new" if="&can_create?(@proyecto.documentos)" param="new-link">
                <ht key="documento.actions.new" count="1">
                  New Documento
                </ht>
              </a:documentos>
            </section>
          </section>
    </content:>

  </page>
</def>





Date: Tue, 16 Aug 2011 14:48:04 -0700
From: kevinp...@gmail.com
To: hobo...@googlegroups.com
Subject: [Hobo Users] Re: FW: Sum a atributte on collection tag Not ideas?


Honestly not sure what you're asking.  You want to display a sum from a child relation?  <view field="association_name.sum(:column_name_to_sum)" />

--
You received this message because you are subscribed to the Google Groups "Hobo Users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/hobousers/-/ZBZtCOFs4CcJ.
To post to this group, send email to hobo...@googlegroups.com.
To unsubscribe from this group, send email to hobousers+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/hobousers?hl=en.

kevinpfromnm

unread,
Aug 16, 2011, 6:32:56 PM8/16/11
to hobo...@googlegroups.com
Given your data, looks like you don't need to customize the collection.  Just add the view tag below it.

On a side note, you might want to take look through the dryml guide at some point as copying the whole show-page def isn't the dryest way to proceed. http://cookbook.hobocentral.net/manual/dryml-guide  You can extend the tag instead and just replace/add the bits you need to change.  By the way, this is not a requirement, just a suggestion that will make dryml pleasanter to work with in the long run.

As an example, if adding the sum is the only change to make you could do:

<extend tag="show-page" for="Proyecto">
  <old-show-page merge>
    <after-collection:>
      Total: <view field="
plan_operativos.sum(:cant)" />
    </after-collection:>
  </old-show-page>
</extend>

Or even add app/views/proyectos/show.dryml if this is your only show-page for proyecto:

<show-page>
  <after-collection:>
    Total:
<view field="plan_operativos.sum(:cant)" />
  </after-collection:>
</show-page>

Enrique Moreira

unread,
Aug 16, 2011, 7:02:33 PM8/16/11
to hobo...@googlegroups.com
Hello

class PlanOperativo < ActiveRecord::Base

  hobo_model # Don't put anything above this

  fields do
    cant :decimal
    timestamps
  end
  
  belongs_to :indicador
  belongs_to :proyecto

------
in app/views/proyectos/show.dryml 
<show-page>
  <after-collection:>
    Total: 
<view field="plan_operativos.sum(:cant)" />
  </after-collection:>
</show-page>


showme the next error

TypeError in Proyectos#show

Showing /home/quike/pr/simo/app/views/proyectos/show.dryml where line #3 raised:

can't convert String into Integer

can use a <table-plus>  with total sum ? on one o many columns_?

Regards
Enrique


Date: Tue, 16 Aug 2011 15:32:56 -0700
From: kevinp...@gmail.com
To: hobo...@googlegroups.com
Subject: Re: RE: [Hobo Users] Re: FW: Sum a atributte on collection tag Not ideas?
--
You received this message because you are subscribed to the Google Groups "Hobo Users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/hobousers/-/zIBJoGQOi10J.

Ignacio Huerta

unread,
Aug 23, 2011, 12:03:22 PM8/23/11
to hobo...@googlegroups.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi Enrique,

This is a bit offtopic, but I find your emails almost impossible to
read, like the newlines are not working. I also tried visiting the
Google Groups interface to check if my Thunderbird has gone crazy, but
the problem remains.

Could you please check your newline settings? It would really help for
the readibility of your emails :)

Regards,
Ignacio

El 17/08/11 01:02, Enrique Moreira escribi�:


>
> Hello
> class PlanOperativo < ActiveRecord::Base
> hobo_model # Don't put anything above this
> fields do cant :decimal timestamps end belongs_to :indicador belongs_to :proyecto

> ------in app/views/proyectos/show.dryml <show-page> <after-collection:> Total: <view field="plan_operativos.sum(:cant)" /> </after-collection:></show-page>
>
> showme the next errorTypeError in Proyectos#showShowing /home/quike/pr/simo/app/views/proyectos/show.dryml where line #3 raised:can't convert String into Integer


> can use a <table-plus> with total sum ? on one o many columns_?
> RegardsEnrique

> Date: Tue, 16 Aug 2011 15:32:56 -0700
> From: kevinp...@gmail.com
> To: hobo...@googlegroups.com
> Subject: Re: RE: [Hobo Users] Re: FW: Sum a atributte on collection tag Not ideas?
>
> Given your data, looks like you don't need to customize the collection. Just add the view tag below it.
>
> On a side note, you might want to take look through the dryml guide at some point as copying the whole show-page def isn't the dryest way to proceed. http://cookbook.hobocentral.net/manual/dryml-guide You can extend the tag instead and just replace/add the bits you need to change. By the way, this is not a requirement, just a suggestion that will make dryml pleasanter to work with in the long run.
>
> As an example, if adding the sum is the only change to make you could do:
>
> <extend tag="show-page" for="Proyecto">
> <old-show-page merge>
> <after-collection:>
> Total: <view field="plan_operativos.sum(:cant)" />
> </after-collection:>
> </old-show-page>
> </extend>
>
> Or even add app/views/proyectos/show.dryml if this is your only show-page for proyecto:
>
> <show-page>
> <after-collection:>
> Total: <view field="plan_operativos.sum(:cant)" />
> </after-collection:>
> </show-page>
>
>
>
>

- --
Ignacio Huerta Arteche
http://www.ihuerta.net
Tel�fono: 0034 645 70 77 35
Email realizado con software libre
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk5Tz0oACgkQBPlUJ6RHaORRtQCgt9cTmbBPfeONeXBBRVOBpVYt
c2QAoLkc1KdKcXWbK+4P79Qubr2HtOQM
=xauk
-----END PGP SIGNATURE-----

Enrique Moreira

unread,
Aug 23, 2011, 12:12:54 PM8/23/11
to hobo...@googlegroups.com
Hello Ignacio

I dont know how happens this thrash my letter  i m fix it 

I m working on Ubuntu 10.10

to Hobousers can erase my bads emails thanks

Regards 
Enrique

Pd. i was Copy+Paste from Source Code! on gedit pimp with gedit gmate for rails




> Date: Tue, 23 Aug 2011 18:03:22 +0200
> From: ign...@ihuerta.net
> To: hobo...@googlegroups.com
> Subject: Re: [Hobo Users] Re: FW: Sum a atributte on collection tag Not ideas?
>



Ignacio Huerta

unread,
Aug 23, 2011, 12:20:06 PM8/23/11
to hobo...@googlegroups.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Mmm, I also work with Ubuntu and Gedit and haven't seen that problem
copying and pasting...

Anyway, this last email was much more readable, thanks!

Regards,
Ignacio

El 23/08/11 18:12, Enrique Moreira escribi�:

- --

Ignacio Huerta Arteche
http://www.ihuerta.net
Tel�fono: 0034 645 70 77 35
Email realizado con software libre
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk5T0zYACgkQBPlUJ6RHaOQ1HACfQYOZ6sAW5wiNGLuBUWItKn5h
aVMAn3zecUgS4fyI4ab/c1h1r+iTPyiN
=dhin
-----END PGP SIGNATURE-----

Enrique Moreira

unread,
Aug 23, 2011, 12:49:52 PM8/23/11
to hobo...@googlegroups.com
Hello Ignacio

this is mi trouble:
i have a tree tables

Proyectos.rb
   proyecto:string
--
has_many: plan_operativos
-----------------------
Plan_operativo.rb
 fecha:date
  cant:decimal
--
belongs_to: proyecto
has_many: progreso_indicador
--------------------------------------

Progreso_indicador.rb
   fecha:date
   cant:decimal
---
  belongs_to: plan_operativo

i put the next lines on application.dryml:
----------------------------
<def tag="card" for="PlanOperativo">
<card class="plan-operativo" param="default" merge>
<header: param>
    <h4 param="heading"><a><name/></a> : <view:cant/> : [<view:indicador.unidadcl.unidad/>]</h4>
   </header:>
<body: param>
<ht key="progreso_indicador.collection.count" count="&this.progreso_indicadors.size">
<count:progreso_indicadors param/>
</ht>
<div>
<table-plus:progreso_indicadors fields="this,cant" without-search-form>
<progreso_indicador-heading:>Fecha</progreso_indicador-heading:>
<cant-heading:>Cantidad</cant-heading:>
</table-plus>
 <div>total:
   <!--<table-plus fields="progreso_indicadors.sum(:cant)"/> -->  <---HOW TO SUM_? shoeme error cant convert string to integer!!
  </div>
  </div>
  </body:>  
  </card>
</def>
-------------------------

The render works fine!

a) i need a sum of  Progreso_indicadors.cant
b)  -- between dates?    put two select dates ?

c) One New Form with Nested Select Boxes..ajax style? alternatively?
   
   -Select Proyects
       1- Select Plan_Operativos One or Selected Plans [x] checkboxes?
       or / and
       2-Select dates Ranges or ALL
      3. Display a table-plus with SUM results on bottom


Any idea?

Best Regards 
Enrique

Ignacio Huerta

unread,
Aug 25, 2011, 1:13:44 PM8/25/11
to hobo...@googlegroups.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi Enrique,

Why don't you try to make a virtual field in the PlanOperativo model and
sum it there?

def total
progreso_indicadors.sum(:cant)
end


And later you can call the table-plus:

<table-plus fields="total"/>

or maybe you just want something more simple:

<this.total/>

About using custom Ajax forms to make a query and return a result I
recommend you this manual: http://cookbook.hobocentral.net/manual/ajax.
Ajax is a bit crazy when you start but with a lot of Firebug and
patience you can certainly make it :)


Regards,
Ignacio

El 23/08/11 18:49, Enrique Moreira escribi�:


>
> Hello Ignacio
> this is mi trouble:i have a tree tables

> Proyectos.rb proyecto:string--has_many: plan_operativos-----------------------Plan_operativo.rb fecha:date cant:decimal--belongs_to: proyectohas_many: progreso_indicador
> --------------------------------------
> Progreso_indicador.rb fecha:date cant:decimal--- belongs_to: plan_operativo


> i put the next lines on application.dryml:----------------------------<def tag="card" for="PlanOperativo"><card class="plan-operativo" param="default" merge><header: param> <h4 param="heading"><a><name/></a> : <view:cant/> : [<view:indicador.unidadcl.unidad/>]</h4> </header:><body: param><ht key="progreso_indicador.collection.count" count="&this.progreso_indicadors.size"><count:progreso_indicadors param/></ht><div><table-plus:progreso_indicadors fields="this,cant" without-search-form><progreso_indicador-heading:>Fecha</progreso_indicador-heading:><cant-heading:>Cantidad</cant-heading:></table-plus> <div>total: <!--<table-plus fields="progreso_indicadors.sum(:cant)"/> --> <---HOW TO SUM_? shoeme error cant convert string to integer!! </div> </div> </body:> </card></def>-------------------------
> The render works fine!

> a) i need a sum of Progreso_indicadors.cantb) -- between dates? put two select dates ?


> c) One New Form with Nested Select Boxes..ajax style? alternatively? -Select Proyects 1- Select Plan_Operativos One or Selected Plans [x] checkboxes? or / and 2-Select dates Ranges or ALL 3. Display a table-plus with SUM results on bottom
>
> Any idea?
> Best Regards Enrique
>
>
>

- --

Ignacio Huerta Arteche
http://www.ihuerta.net
Tel�fono: 0034 645 70 77 35
Email realizado con software libre
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk5WgsYACgkQBPlUJ6RHaOS6pgCfQhkk15mndgJvO64KSpMUzZOk
nPcAn0Xk1TLo/cXvH/kPUrSF6RbIIFOo
=GGxL
-----END PGP SIGNATURE-----

Enrique Moreira

unread,
Aug 25, 2011, 3:16:24 PM8/25/11
to hobo...@googlegroups.com
Hello Ignacio 

Yes. Its works Fine!! Thanks! sum very well
now one question more please:

The model:

ProgresoIndicators.rb
fecha:date
cant:decimal
---
How to select a range of dates ? on the View?? to sum cant partial
use two select dates put on the  View of Plan_operativo?

Regards

Enrique



> Date: Thu, 25 Aug 2011 19:13:44 +0200

> From: ign...@ihuerta.net
> To: hobo...@googlegroups.com
> Subject: Re: [Hobo Users] Re: FW: Sum a atributte on collection tag Not ideas?
>
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Hi Enrique,
>
> Why don't you try to make a virtual field in the PlanOperativo model and
> sum it there?
>
> def total
> progreso_indicadors.sum(:cant)
> end
>
>
> And later you can call the table-plus:
>
> <table-plus fields="total"/>
>
> or maybe you just want something more simple:
>
> <this.total/>
>
>
>
> About using custom Ajax forms to make a query and return a result I
> recommend you this manual: http://cookbook.hobocentral.net/manual/ajax.
> Ajax is a bit crazy when you start but with a lot of Firebug and
> patience you can certainly make it :)
>
>
> Regards,
> Ignacio
>
> El 23/08/11 18:49, Enrique Moreira escribió:

> >
> > Hello Ignacio
> > this is mi trouble:i have a tree tables
> > Proyectos.rb proyecto:string--has_many: plan_operativos-----------------------Plan_operativo.rb fecha:date cant:decimal--belongs_to: proyectohas_many: progreso_indicador
> > --------------------------------------
> > Progreso_indicador.rb fecha:date cant:decimal--- belongs_to: plan_operativo
> > i put the next lines on application.dryml:----------------------------<def tag="card" for="PlanOperativo"><card class="plan-operativo" param="default" merge><header: param> <h4 param="heading"><a><name/></a> : <view:cant/> : [<view:indicador.unidadcl.unidad/>]</h4> </header:><body: param><ht key="progreso_indicador.collection.count" count="&this.progreso_indicadors.size"><count:progreso_indicadors param/></ht><div><table-plus:progreso_indicadors fields="this,cant" without-search-form><progreso_indicador-heading:>Fecha</progreso_indicador-heading:><cant-heading:>Cantidad</cant-heading:></table-plus> <div>total: <!--<table-plus fields="progreso_indicadors.sum(:cant)"/> --> <---HOW TO SUM_? shoeme error cant convert string to integer!! </div> </div> </body:> </card></def>-------------------------
> > The render works fine!
> > a) i need a sum of Progreso_indicadors.cantb) -- between dates? put two select dates ?
> > c) One New Form with Nested Select Boxes..ajax style? alternatively? -Select Proyects 1- Select Plan_Operativos One or Selected Plans [x] checkboxes? or / and 2-Select dates Ranges or ALL 3. Display a table-plus with SUM results on bottom
> >
> > Any idea?
> > Best Regards Enrique
> >
> >
> >
>
> - --
> Ignacio Huerta Arteche
> http://www.ihuerta.net
> Teléfono: 0034 645 70 77 35

> Email realizado con software libre
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.10 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
>
> iEYEARECAAYFAk5WgsYACgkQBPlUJ6RHaOS6pgCfQhkk15mndgJvO64KSpMUzZOk
> nPcAn0Xk1TLo/cXvH/kPUrSF6RbIIFOo
> =GGxL
> -----END PGP SIGNATURE-----
>
> --
> You received this message because you are subscribed to the Google Groups "Hobo Users" group.

Ignacio Huerta

unread,
Aug 26, 2011, 2:20:31 AM8/26/11
to hobo...@googlegroups.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

This is not stricly about Hobo. I recommend you read some of the theory
behind the Model-View-Controller in Rails, I think it can help you.

For example, you can make customise the Hobo show action in the
controller, something like this:

def show
@records = Model.find(:all, :conditions => "date > '2011-01-01'")
@amount = @records.sum(:cant)
hobo_show
end

And then you have access to @amount in the view :).

Regards,
Ignacio

El 25/08/11 21:16, Enrique Moreira escribi�:
>
> Hello Ignacio
> Yes. Its works Fine!! Thanks! sum very wellnow one question more please:
> The model:
> ProgresoIndicators.rbfecha:datecant:decimal---How to select a range of dates ? on the View?? to sum cant partialuse two select dates put on the View of Plan_operativo?


> Regards
> Enrique
>
>
>> Date: Thu, 25 Aug 2011 19:13:44 +0200
>> From: ign...@ihuerta.net
>> To: hobo...@googlegroups.com
>> Subject: Re: [Hobo Users] Re: FW: Sum a atributte on collection tag Not ideas?
>>

> Hi Enrique,
>
> Why don't you try to make a virtual field in the PlanOperativo model and
> sum it there?
>
> def total
> progreso_indicadors.sum(:cant)
> end
>
>
> And later you can call the table-plus:
>
> <table-plus fields="total"/>
>
> or maybe you just want something more simple:
>
> <this.total/>
>
>
>
> About using custom Ajax forms to make a query and return a result I
> recommend you this manual: http://cookbook.hobocentral.net/manual/ajax.
> Ajax is a bit crazy when you start but with a lot of Firebug and
> patience you can certainly make it :)
>
>
> Regards,
> Ignacio
>

> El 23/08/11 18:49, Enrique Moreira escribi�:


>>>>
>>>> Hello Ignacio
>>>> this is mi trouble:i have a tree tables
>>>> Proyectos.rb proyecto:string--has_many: plan_operativos-----------------------Plan_operativo.rb fecha:date cant:decimal--belongs_to: proyectohas_many: progreso_indicador
>>>> --------------------------------------
>>>> Progreso_indicador.rb fecha:date cant:decimal--- belongs_to: plan_operativo
>>>> i put the next lines on application.dryml:----------------------------<def tag="card" for="PlanOperativo"><card class="plan-operativo" param="default" merge><header: param> <h4 param="heading"><a><name/></a> : <view:cant/> : [<view:indicador.unidadcl.unidad/>]</h4> </header:><body: param><ht key="progreso_indicador.collection.count" count="&this.progreso_indicadors.size"><count:progreso_indicadors param/></ht><div><table-plus:progreso_indicadors fields="this,cant" without-search-form><progreso_indicador-heading:>Fecha</progreso_indicador-heading:><cant-heading:>Cantidad</cant-heading:></table-plus> <div>total: <!--<table-plus fields="progreso_indicadors.sum(:cant)"/> --> <---HOW TO SUM_? shoeme error cant convert string to integer!! </div> </div> </body:> </card></def>-------------------------
>>>> The render works fine!
>>>> a) i need a sum of Progreso_indicadors.cantb) -- between dates? put two select dates ?
>>>> c) One New Form with Nested Select Boxes..ajax style? alternatively? -Select Proyects 1- Select Plan_Operativos One or Selected Plans [x] checkboxes? or / and 2-Select dates Ranges or ALL 3. Display a table-plus with SUM results on bottom
>>>>
>>>> Any idea?
>>>> Best Regards Enrique
>>>>
>>>>
>>>>
>
>>
- --

You received this message because you are subscribed to the Google
Groups "Hobo Users" group.
To post to this group, send email to hobo...@googlegroups.com.
To unsubscribe from this group, send email to
hobousers+...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/hobousers?hl=en.
>>

- --

Ignacio Huerta Arteche
http://www.ihuerta.net

Tel�fono: 0034 645 70 77 35


Email realizado con software libre
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk5XOy8ACgkQBPlUJ6RHaOSuaQCeMSX8K3sPS4P8shdLccr6qe5D
zgcAoIfJzgD2GePDkiakDVJcuShg48Sg
=Qm0H
-----END PGP SIGNATURE-----

Reply all
Reply to author
Forward
0 new messages