Re: chart row reordering?

2008-09-17 Thread Tomas Hlavaty
Hi Alex,

thank you for great explanation!

Tomas
-- 
UNSUBSCRIBE: mailto:[EMAIL PROTECTED]


Re: chart row reordering?

2008-09-17 Thread Alexander Burger
Hi Tomas,

> (setq *List (; *ID it))
> 
> (when (nth *List *Bubble)
>(xchg @ (cdr @)) )
>
> (put!> *ID 'it *List)
> (commit)

This is correct in principle, but will not work here.

The problem here is that 'put!>' always tries to detect whether the new
data are different from the current state of the object. If not, nothing
is written. Otherwise, the object is modified and set to a "dirty" state
so that on subsequent 'commit's it is written to the file. (The 'commit'
is implied in the '!' versions of these functions)

If we use 'xchg', the 'it' list is modified destructively, so that
'put!>' later will believe it did not change at all.

In such a case we can use 'touch' explicitly (which is not necessary
normally). We might do (we can also omit the global '*List' here):

   (when (nth (; *ID it) *Bubble)
  (xchg @ (cdr @))
  (touch *ID)
  (commit) )


Usually, when the DB is used by multiple users or processes, we must
call (dbSync) before the change, and (commit 'upd) after. These two
things are done by 'put!>' internally. So the correct solution would be:

   (when (nth (; *ID it) *Bubble)
  (dbSync)
  (xchg @ (cdr @))
  (touch *ID)
  (commit 'upd) )

Note that 'put>' is not needed, as the list is already modified and set
to dirty.


If we insist to use 'put!>', we must use a non-destructive way to modify
the list:

   (let L (; *ID it)
  (put!> *ID 'it
 (append
(cut (dec *Bubble) 'L)
(cons (cadr L) (car L) (cddr L)) ) ) )

This last version is more "standard", but I would go with the 'xchg'
version (it is more clear, I believe).



> but what about locking and maybe other stuff?

The database is locked and synchronized between different (child-)
processes if (dbSync) and (commit 'upd), or 'put!>' is used.

This does not prevent some user, however, to modify the database while
the old state is still visible in the browser of another user. It will
not put the database into an inconsistent state, but the first user's
changes will be lost. That's why the 'form' GUI uses the Save/Edit
button mechanisms.



> Also, I have seen put!> being used to set "simple" relations but is it
> intended for lists?  How would that impact +Joint relation etc.?

It works as well for lists (as you can see in the example above). You
can either

   (put> Obj 'it '(list of it-objects))

or

   (put> Obj 'it 'single-it-object)

In the latter case the relation daemons will take care of inserting the
single object into the list.


> Also, if the db is big and the list is really long, isn't there a
> mechanism avoiding fetching the whole list from db and just swapping
> the two objects? Or, maybe I am worrying about it too much and it will
> turn out really simple? ;-)

I think you will usually not put a very long list of +It objects into a
single +Cat object. This would indeed be very inefficient, and also
difficult to handle. And no, there is no way to fetch only part of an
object from the DB.

Practically, I don't think this situation will arise. If you know that a
+Cat has very many +It objects, you would not use a mutual +Joint, but
an indexed +Link:

(class +Cat +Entity)
(rel nr (+Need +Key +Number))
(rel nm (+Ref +String))

(class +It +Entity)
(rel nr (+Need +Key +Number))
(rel nm (+Sn +Idx +String))
(rel cat (+List +Ref +Link) NIL (+Cat))


Generally, a +Joint on both sides is equivalent to a (+Ref +Link) on one
side. With that, you can also navigate in both directions, from +It to
+Cut in the same way, i.e.

   (get '{It} 'cat)

and from +Cat to +It using the index, e.g.

   (collect 'cat '+It '{It})

In this case there is virtually no limit of the number of +It objects assigned
to a +Cat object.

Cheers,
- Alex
-- 
UNSUBSCRIBE: mailto:[EMAIL PROTECTED]


Re: chart row reordering?

2008-09-17 Thread Tomas Hlavaty
Hi Alex,

> Does the following script something close?

yes, that's exactly what I am trying to achieve except how would this
work with persistent objects?

Assuming I have the following schema and want to change order of items
"it" in a category "*ID" of type "+Cat"?

(class +Cat +Entity)

(rel nr (+Need +Key +Number))
(rel nm (+Ref +String))
(rel it (+List +Joint) cat (+It))

(class +It +Entity)

(rel nr (+Need +Key +Number))
(rel nm (+Sn +Idx +String))
(rel cat (+List +Joint) it (+Cat))

What I am after is what would the db update code be like?

I imagine roughly something like:

(setq *List (; *ID it))

(when (nth *List *Bubble)
   (xchg @ (cdr @)) )

(put!> *ID 'it *List)
(commit)

but what about locking and maybe other stuff?

Also, I have seen put!> being used to set "simple" relations but is it
intended for lists?  How would that impact +Joint relation etc.?
Also, if the db is big and the list is really long, isn't there a
mechanism avoiding fetching the whole list from db and just swapping
the two objects? Or, maybe I am worrying about it too much and it will
turn out really simple? ;-)

Thanks for help,

Tomas
-- 
UNSUBSCRIBE: mailto:[EMAIL PROTECTED]


Re: chart row reordering?

2008-09-16 Thread Alexander Burger
Hi Tomas,

> I would like to add a link ^ which would do the same thing as
> +BubbleField button:

Probably I would use the '' function.

Does the following script something close?


#!bin/picolisp lib.l

(load "ext.l" "lib/http.l" "lib/xhtml.l")

(de start ()
   (when (app)
  (setq
 *List '("A" "B" "C" "D" "E")
 *Bubble 0 ) )
   (when (nth *List *Bubble)
  (xchg @ (cdr @)) )
   (html 0 "Bubble" "lib.css" NIL
  ( NIL
 ( NIL
(ht:Prin (car *List)) )
 (for (I . Sym) (cdr *List)
( NIL
   Sym
   ()
   ( '*Bubble I "\^") ) ) ) ) )

(server 8080 "@start")


For simplicity, I'm using "A", "B", "C" etc. instead of objects.

'' reloads the current page, passing a value (here 'I') to a given
variable (here '*Bubble').

Cheers,
- Alex
-- 
UNSUBSCRIBE: mailto:[EMAIL PROTECTED]


Re: chart row reordering?

2008-09-16 Thread Tomas Hlavaty
Hi Alex,

> Nothing I can think of at the moment (except, as you know, the
> normal administrative things like changing 3 -> 4 in the +Chart
> line).

oops, that was it, thanks!

One more question regarding ordering.  Suppose I do not use a chart
but draw the objects myself in a tree-like format inside 
element:

cat1
  it11
  it12
  it13
cat2
  it21
  it22
  cat21
it211
..

I would like to add a link ^ which would do the same thing as
+BubbleField button:

cat1
  it11 ^
  it12 ^
  it13 ^
cat2
  it21 ^
  it22 ^
  cat21
it211 ^
..

What do I need to do to swap two items of a relation manually/via the
^ link?

Thank you,

Tomas
-- 
UNSUBSCRIBE: mailto:[EMAIL PROTECTED]


Re: chart row reordering?

2008-09-16 Thread Alexander Burger
Hi Tomas,

> (class +Ord +Entity)
> (rel nr  (+Need +Key +Number))
> (rel pos (+List +Joint) ord (+Pos))
> 
> (class +Pos +Entity)
> (rel ord (+Dep +Joint) (art) pos (+Ord))

Oops, sorry for the confusion! A month or so ago I noticed that
"app/er.l" was not correct :-(

The current "testing" release contains the fixes. The above line must be

> (rel ord (+Dep +Joint) (itm) pos (+Ord))# Order


'+Dep' takes a list of "dependent" relations, (itm) in this case. This
means, whenever the 'ord' relation of '+Pos' is cleared, so will
automatically be the 'itm' relation.

Clearing the 'itm' is necessary here, in order to remove this position
from the '+Ref' index. Otherwise, for example, a report listing all
sales for this item would show incorrect results.



> (class +Cat +Entity)
> 
> (rel nr (+Need +Key +Number))
> (rel nm (+Ref +String))
> (rel it (+List +Joint) cat (+It))
> 
> (class +It +Entity)
> 
> (rel nr (+Need +Key +Number))
> (rel nm (+Sn +Idx +String))
> (rel cat (+List +Joint) it (+Cat))
> 
>  (gui '(+E/R +Chart) '(it : home obj) 3 '((This) (list NIL This NIL)) 
> cadr)
>  ( NIL NIL '((btn) NIL (btn))
> (do 6
>( NIL
>   (gui 1 '(+ChoButton) '(choIt (field 1)))
>   (gui 2 '(+Obj +TextField) '(nm +It) 40)
>   (gui 3 '(+DelRowButton
>( NIL NIL (scroll 6)))

Looks good, though I haven't tested it.

> I would like to be able to reorder items +It in a category +Cat.
> What else do I need to do except adding (gui 4 '(+BubbleButton)) ?

Nothing I can think of at the moment (except, as you know, the normal
administrative things like changing 3 -> 4 in the +Chart line).


> Is +Dep and (art) related to row reordering?

No, as changing the line does not cause any removal of relations.

Cheers,
- Alex
-- 
UNSUBSCRIBE: mailto:[EMAIL PROTECTED]