Iliad - updating elements

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

Iliad - updating elements

Stefan Schmiedl
Before I dive in and learn to do it manually, is there an idiomatic
way of updating a given element (periodically)?

I am building the supervisor page for the OnlineTester, which
contains something like a "dashboard" showing the completion rate
of each test. This is currently implemented as widget although
it does not need to be, now that I think about it. Anyways, its
contents should be refreshed once every minute.

Thanks,
s.


_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: Iliad - updating elements

Nicolas Petton
Le lundi 13 juillet 2009 à 14:50 +0200, Stefan Schmiedl a écrit :
> Before I dive in and learn to do it manually, is there an idiomatic
> way of updating a given element (periodically)?
>
> I am building the supervisor page for the OnlineTester, which
> contains something like a "dashboard" showing the completion rate
> of each test. This is currently implemented as widget although
> it does not need to be, now that I think about it. Anyways, its
> contents should be refreshed once every minute.

You should probably use one of the periodical updater jQuery plugins.
http://plugins.jquery.com/search/node/updater

There is no integration in Iliad for now, so you will have to write some
Javascript code ;)

HTH,

Nico

_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk

signature.asc (204 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Iliad - updating elements

Stefan Schmiedl
On Mon, 13 Jul 2009 15:05:24 +0200
Nicolas Petton <[hidden email]> wrote:

> Le lundi 13 juillet 2009 à 14:50 +0200, Stefan Schmiedl a écrit :
> > Before I dive in and learn to do it manually, is there an idiomatic
> > way of updating a given element (periodically)?
> >
> > I am building the supervisor page for the OnlineTester, which
> > contains something like a "dashboard" showing the completion rate
> > of each test. This is currently implemented as widget although
> > it does not need to be, now that I think about it. Anyways, its
> > contents should be refreshed once every minute.
>
> You should probably use one of the periodical updater jQuery plugins.
> http://plugins.jquery.com/search/node/updater
Smart solutions for a bigger problem :-)

> There is no integration in Iliad for now, so you will have to write
> some Javascript code ;)

Here's what I have now, but consider cheating (a bit):

  contents [
    <category: 'building'>
    ^ [ :e | |id|
      id := self session nextId printString.
      e build: self statusWidget.
      e anchor id: id; text: 'Refresh'; action: [ self statusWidget markDirty ].
      e script: 'window.setInterval( function() { jQuery( "a#' , id , '" ).click(); }, 60*1000 );'
    ]
  ]

Question #1:
Is there a reason why "session nextId" is a number instead of a string?
It does not matter when assigning it to the id attribute, but it is a bit of a trap
because splicing it (as a number) into a string does not give the desired result.

Question #2:
The solution above nicely logs the expected XHR requests in firebug.
When I tried
            Iliad.evaluteAnchorAction( "a#' , id , '" );
instead, no such requests were logged. Do I actually go and read the Javascript
books on the shelf behind me or is there something else I'm not aware of?

Thanks,
s.

_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk

signature.asc (205 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Iliad - updating elements

Nicolas Petton
Le lundi 13 juillet 2009 à 17:41 +0200, Stefan Schmiedl a écrit :

> On Mon, 13 Jul 2009 15:05:24 +0200
> Nicolas Petton <[hidden email]> wrote:
>
> > Le lundi 13 juillet 2009 à 14:50 +0200, Stefan Schmiedl a écrit :
> > > Before I dive in and learn to do it manually, is there an idiomatic
> > > way of updating a given element (periodically)?
> > >
> > > I am building the supervisor page for the OnlineTester, which
> > > contains something like a "dashboard" showing the completion rate
> > > of each test. This is currently implemented as widget although
> > > it does not need to be, now that I think about it. Anyways, its
> > > contents should be refreshed once every minute.
> >
> > You should probably use one of the periodical updater jQuery plugins.
> > http://plugins.jquery.com/search/node/updater
>
> Smart solutions for a bigger problem :-)
>
> > There is no integration in Iliad for now, so you will have to write
> > some Javascript code ;)
>
> Here's what I have now, but consider cheating (a bit):
>
>   contents [
>     <category: 'building'>
>     ^ [ :e | |id|
>       id := self session nextId printString.
>       e build: self statusWidget.
>       e anchor id: id; text: 'Refresh'; action: [ self statusWidget markDirty ].
>       e script: 'window.setInterval( function() { jQuery( "a#' , id , '" ).click(); }, 60*1000 );'
>     ]
>   ]
>
> Question #1:
> Is there a reason why "session nextId" is a number instead of a string?
Hmm, yes. As far as I remember, numbers are needed to know in which
order actions need to be executed, in a form for instance.

But I don't think you need Session>>nextId, it is mostly used for
actions registration. You could use Iliad.Id instead.

Also, #nextId may not be the appropriate name, since it answers an
integer. If someone has a better name in mind...

> It does not matter when assigning it to the id attribute, but it is a bit of a trap
> because splicing it (as a number) into a string does not give the desired result.
>
> Question #2:
> The solution above nicely logs the expected XHR requests in firebug.
> When I tried
>             Iliad.evaluteAnchorAction( "a#' , id , '" );
> instead, no such requests were logged. Do I actually go and read the Javascript
> books on the shelf behind me or is there something else I'm not aware of?

Iliad.evaluateAnchorAction(anchor) expects a DOM element, not an id.
So Iliad.evaluateAnchorAction(jQuery(#someId)) should work.

HTH,

Nico

_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk

signature.asc (204 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Iliad - updating elements

Stefan Schmiedl
On Mon, 13 Jul 2009 20:07:52 +0200
Nicolas Petton <[hidden email]> wrote:

> Hmm, yes. As far as I remember, numbers are needed to know in which
> order actions need to be executed, in a form for instance.
>
> But I don't think you need Session>>nextId, it is mostly used for
> actions registration. You could use Iliad.Id instead.

Channeling my youngest kid:

butbutbut ... you *told* me I could use *either* of them ... sniff

My reasoning was that after looking at both implementations, I decided
to go with the shorter :-)

>
> Also, #nextId may not be the appropriate name, since it answers an
> integer. If someone has a better name in mind...

if that's the purpose, why not call it #nextActionIndex?

> > Question #2:
> > The solution above nicely logs the expected XHR requests in firebug.
> > When I tried
> >             Iliad.evaluteAnchorAction( "a#' , id , '" );
> > instead, no such requests were logged. Do I actually go and read
> > the Javascript books on the shelf behind me or is there something
> > else I'm not aware of?
>
> Iliad.evaluateAnchorAction(anchor) expects a DOM element, not an id.
> So Iliad.evaluateAnchorAction(jQuery(#someId)) should work.
... and it does, great!

This means I'll skip the general javascript and give the jQuery docs
a thorough reading instead. Looking at the implementation of
evaluateAnchorAction led me to my erroneous belief.

    evaluateAnchorAction: function(anchor) {
        var actionUrl = jQuery(anchor).attr('href');
        this.evaluateAction(actionUrl);
    },

hmmm.... final question: How would I do this without putting an anchor
into my page? I guess I'd have to do some work to gather the expected
session tokens and whatever else is required?

Thanks,
s.

_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk

signature.asc (205 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Iliad - updating elements

Nicolas Petton
Le lundi 13 juillet 2009 à 21:13 +0200, Stefan Schmiedl a écrit :

> On Mon, 13 Jul 2009 20:07:52 +0200
> Nicolas Petton <[hidden email]> wrote:
>
> > Hmm, yes. As far as I remember, numbers are needed to know in which
> > order actions need to be executed, in a form for instance.
> >
> > But I don't think you need Session>>nextId, it is mostly used for
> > actions registration. You could use Iliad.Id instead.
>
> Channeling my youngest kid:
>
> butbutbut ... you *told* me I could use *either* of them ... sniff
Yes, you can. It's just that they are made for different purposes.
>
> My reasoning was that after looking at both implementations, I decided
> to go with the shorter :-)
>
> >
> > Also, #nextId may not be the appropriate name, since it answers an
> > integer. If someone has a better name in mind...
>
> if that's the purpose, why not call it #nextActionIndex?

Hmmm...not bad...let me think about it :)

>
> > > Question #2:
> > > The solution above nicely logs the expected XHR requests in firebug.
> > > When I tried
> > >             Iliad.evaluteAnchorAction( "a#' , id , '" );
> > > instead, no such requests were logged. Do I actually go and read
> > > the Javascript books on the shelf behind me or is there something
> > > else I'm not aware of?
> >
> > Iliad.evaluateAnchorAction(anchor) expects a DOM element, not an id.
> > So Iliad.evaluateAnchorAction(jQuery(#someId)) should work.
>
> ... and it does, great!
>
> This means I'll skip the general javascript and give the jQuery docs
> a thorough reading instead. Looking at the implementation of
> evaluateAnchorAction led me to my erroneous belief.
>
>     evaluateAnchorAction: function(anchor) {
>         var actionUrl = jQuery(anchor).attr('href');
>         this.evaluateAction(actionUrl);
>     },
>
> hmmm.... final question: How would I do this without putting an anchor
> into my page? I guess I'd have to do some work to gather the expected
> session tokens and whatever else is required?
I would register an action in the session on the server side, and add
some js code to trigger the action every x seconds, using iliad.js
functions (evaluateAction).

Nico

_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk

signature.asc (204 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Iliad - updating elements

Stefan Schmiedl
On Mon, 13 Jul 2009 22:40:05 +0200
Nicolas Petton <[hidden email]> wrote:

> Yes, you can. It's just that they are made for different purposes.

So I went along and replaced "self session nextId printString" with
"Iliad.Id new: 8". Imagine my surprise when I found the following:

<script>
$(document).ready( function() { $("#Iliad.Id (97 104 50 57 114 113 112 97 )").focus(); } );
</script>

Ok, I'll do the right thing and subclass it .-)

> I would register an action in the session on the server side, and add
> some js code to trigger the action every x seconds, using iliad.js
> functions (evaluateAction).

Now I'll just have to figure out how to "register an action in the session".
A nice puzzle for tomorrow, please don't spoil it :-)

Thanks,
s.

_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk

signature.asc (205 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Iliad - updating elements

Nicolas Petton
Le lundi 13 juillet 2009 à 23:11 +0200, Stefan Schmiedl a écrit :

> On Mon, 13 Jul 2009 22:40:05 +0200
> Nicolas Petton <[hidden email]> wrote:
>
> > Yes, you can. It's just that they are made for different purposes.
>
> So I went along and replaced "self session nextId printString" with
> "Iliad.Id new: 8". Imagine my surprise when I found the following:
>
> <script>
> $(document).ready( function() { $("#Iliad.Id (97 104 50 57 114 113 112 97 )").focus(); } );
> </script>
Hehe :)

It's fixed, Id should print correctly. Thanks!

Nico

_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk

signature.asc (204 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Iliad - updating elements

Paolo Bonzini-3
In reply to this post by Stefan Schmiedl
>> Yes, you can. It's just that they are made for different purposes.
>
> So I went along and replaced "self session nextId printString" with
> "Iliad.Id new: 8". Imagine my surprise when I found the following:
>
> <script>
> $(document).ready( function() { $("#Iliad.Id (97 104 50 57 114 113 112 97 )").focus(); } );
> </script>
>
> Ok, I'll do the right thing and subclass it .-)

No, what you should do is override Iliad.Id>>#displayOn: (or #printOn:).

Paolo


_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: Iliad - updating elements

Nicolas Petton
Le mardi 14 juillet 2009 à 01:44 +0200, Paolo Bonzini a écrit :

> >> Yes, you can. It's just that they are made for different purposes.
> >
> > So I went along and replaced "self session nextId printString" with
> > "Iliad.Id new: 8". Imagine my surprise when I found the following:
> >
> > <script>
> > $(document).ready( function() { $("#Iliad.Id (97 104 50 57 114 113 112 97 )").focus(); } );
> > </script>
> >
> > Ok, I'll do the right thing and subclass it .-)
>
> No, what you should do is override Iliad.Id>>#displayOn: (or #printOn:).
I already added Iliad.Id>>printOn:, just update :)

Cheers!

Nico

_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk

signature.asc (204 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Iliad - updating elements

Stefan Schmiedl
In reply to this post by Paolo Bonzini-3
On Tue, 14 Jul 2009 01:44:53 +0200
Paolo Bonzini <[hidden email]> wrote:

> >> Yes, you can. It's just that they are made for different purposes.
> >
> > So I went along and replaced "self session nextId printString" with
> > "Iliad.Id new: 8". Imagine my surprise when I found the following:
> >
> > <script>
> > $(document).ready( function() { $("#Iliad.Id (97 104 50 57 114 113
> > 112 97 )").focus(); } ); </script>
> >
> > Ok, I'll do the right thing and subclass it .-)
>
> No, what you should do is override Iliad.Id>>#displayOn: (or
> #printOn:).

Nah ... that would be fiddling in foreign code ... I don't do that ;->

The subclass stays, because 8 random characters for in-page ids
"should be enough for everyone".

s.


_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: Iliad - updating elements

Nicolas Petton
Le mardi 14 juillet 2009 à 08:04 +0200, Stefan Schmiedl a écrit :

> On Tue, 14 Jul 2009 01:44:53 +0200
> Paolo Bonzini <[hidden email]> wrote:
>
> > >> Yes, you can. It's just that they are made for different purposes.
> > >
> > > So I went along and replaced "self session nextId printString" with
> > > "Iliad.Id new: 8". Imagine my surprise when I found the following:
> > >
> > > <script>
> > > $(document).ready( function() { $("#Iliad.Id (97 104 50 57 114 113
> > > 112 97 )").focus(); } ); </script>
> > >
> > > Ok, I'll do the right thing and subclass it .-)
> >
> > No, what you should do is override Iliad.Id>>#displayOn: (or
> > #printOn:).
>
> Nah ... that would be fiddling in foreign code ... I don't do that ;->
>
> The subclass stays, because 8 random characters for in-page ids
> "should be enough for everyone".
Again, please update, the problem should have been fixed.

Nico

_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk

signature.asc (204 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Iliad - updating elements

Stefan Schmiedl
In reply to this post by Nicolas Petton
On Tue, 14 Jul 2009 01:47:51 +0200
Nicolas Petton <[hidden email]> wrote:

> I already added Iliad.Id>>printOn:, just update :)

Well, I did ... and while looking at the diffs I noticed
Iliad.Id table for the first time.

It is implemented on the instance side and builds the array
with the character pool, from which the random ids (themselves a
subclass of ByteArray) are built. And it is called quite often
when constructing an id.

stefan@g128 iliad $ gst
GNU Smalltalk ready

st> PackageLoader fileInPackage: 'Iliad'
...
st> Time millisecondsToRun: [ 10000 timesRepeat: [Iliad.Id new ] ]
3086
st> Time millisecondsToRun: [ 10000 timesRepeat: [Iliad.Id new ] ]
3087
st>

code code clickty click ...

stefan@g128 iliad $ gst
GNU Smalltalk ready

st> PackageLoader fileInPackage: 'Iliad'
st> Time millisecondsToRun: [ 10000 timesRepeat: [Iliad.Id new ] ]
384
st> Time millisecondsToRun: [ 10000 timesRepeat: [Iliad.Id new ] ]
383

off to work,
s.

_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk

id.patch (1K) Download Attachment
signature.asc (205 bytes) Download Attachment