Re: [basex-talk] Rest Access from javascript using AngularJs

2014-05-15 Thread Yoann Maingon
In fact the Json I was building was not valid.
Now I understood how to fix it. Seems to work well :

module namespace _ = 'getObjectTypes';

(:~
 : test dev YMA
 :)
declare
  %rest:path("/getObjectTypes")
(:   %rest:query-param("name", "{$name}", "anonymous friend") :)
   %output:method("json")
   %output:json("format=attributes")
   %output:json("lax=yes")
function _:getObjectTypes() {
   let $db := db:open("simplePLM_test1")//objectType
   return
  {
for $n in $db
return
<_ type="object">
  
   {data($n/@name)}
 
 
   {data($n/@label)}
 

} 
};


Question now will be how you ouput nested structure with unknown depth. Any
idea or Experience ?


*Cordialement / Best Regards, *

*Yoann Maingon*
Minerva France

*+33 6 64 32 49 66*

Download Aras Innovator - Téléchargez Aras
Innovator




2014-05-15 9:57 GMT+02:00 Yoann Maingon :

> Thx, I thought using option format=attribute would work but apparently
> not.
> So no I fixed my issue using building the json:
>
> module namespace _ = 'getObjectTypes';
>
> (:~
>  : test dev YMA
>  :)
> declare
>   %rest:path("/getObjectTypes")
> (:   %rest:query-param("name", "{$name}", "anonymous friend") :)
>%output:method("json")
> function _:getObjectTypes() {
>let $db := db:open("simplePLM_test1")//objectType
> return 
> {
> for $n in $db
> return
> 
> {data($n/@name)}
> {data($n/@label)}
> 
>  } 
> };
>
> Thank you for your help !
>
>
> *Cordialement / Best Regards,*
>
> *Yoann Maingon*
> Minerva France
>
> *+33 6 64 32 49 66 <%2B33%206%C2%A064%2032%2049%2066>*
>
> Download Aras Innovator - Téléchargez Aras 
> Innovator
>
>
>
>
> 2014-05-15 9:07 GMT+02:00 Arve Gengelbach :
>
>> Bonjour Yoann,
>>
>> The mapping XML –> JSON is not  1-1, i.e. not any XML can be immediately
>> serialised to JSON. Your XML has to be in a certain format (direct,
>> attributes, jsonml or map) as described in [JSON Module].
>>
>> I suggest you to template the JSON output you expect and apply
>> json:parse() with desired options. This is the same as specifying output
>> options in RestXQ. By then you know which format your XML has to have. I.e.
>> start like this...
>>
>> json:parse(
>> '{"resultat":[
>>   {"objectType":[
>> {"label":"nodes",
>> "name":"nodes"}
>>   ]},
>>   {"objectType":[
>> {"label":"links",
>> "name":"links"}
>>   ]}
>> ]}', {"format":"direct"})
>>
>>
>> hope this helps
>> Arve
>>
>> [JSON Module] http://docs.basex.org/wiki/JSON_Module
>>
>> On 15 May 2014, at 01:17, Yoann Maingon 
>> wrote:
>>
>> > Working on this development including Basex and AngularJs, I'm stuck
>> with the Json output.
>> > here is the error :
>> >  [BXJS0002] JSON serializer:  has invalid attribute "label".
>> > Here is the xqm :
>> > module namespace _ = 'getObjectTypes';
>> >
>> > (:~
>> >  : test dev YMA
>> >  :)
>> > declare
>> >   %rest:path("/getObjectTypes")
>> > (:   %rest:query-param("name", "{$name}", "anonymous friend") :)
>> >%output:method("json")
>> >%output:json("lax=yes")
>> > function _:getObjectTypes() {
>> >let $db := db:open("simplePLM_test1")//objectType
>> >return {$db}
>> > };
>> >
>> > If instead I export in XML I get this :
>> > 
>> >
>> >
>> >
>> > http://schemas.xmlsoap.org/soap/envelope/";
>> label="nodes" name="nodes"/>
>> > http://schemas.xmlsoap.org/soap/envelope/";
>> label="links" name="links"/>
>> > 
>> >
>> > using this xqm:
>> >
>> > module namespace _ = 'getObjectTypes';
>> >
>> > (:~
>> >  : test dev YMA
>> >  :)
>> > declare
>> >   %rest:path("/getObjectTypes")
>> > (:   %rest:query-param("name", "{$name}", "anonymous friend") :)
>> >%output:method("xml")
>> > function _:getObjectTypes() {
>> >let $db := db:open("simplePLM_test1")//objectType
>> >return {$db}
>> > };
>> >
>> > any idea?
>> >
>> >
>> >
>> > Cordialement / Best Regards,
>> >
>> > Yoann Maingon
>> > Minerva France
>> >
>> > +33 6 64 32 49 66
>> >
>> > Download Aras Innovator - Téléchargez Aras Innovator
>> >
>> >
>> >
>> >
>> >
>> > 2014-05-14 20:59 GMT+02:00 Yoann Maingon > >:
>> > Thx for the blog post !
>> >
>> > I was close to make it work but now I've got an issue with Basex itself.
>> > It says can't communicate with server when I'm trying to launch the
>> basexhttp
>> > I know it happened to me once on another computer never knew how I
>> either fixed it or if I had my computer stolen since then.
>> >
>> > Is there any log I should check, any cleaning advice?
>> >
>> >
>> > Cordialement / Best Regards,
>> >
>> > Yoann Maingon
>> > Minerva France
>> >
>> > +33 6 64 32 49 66
>> >
>> > Download Aras Innovator - Téléchargez Aras Innovator
>> >
>> >
>> >
>> >
>> >
>> > 2014-05-14 16:25 GMT+02:00 Andy Bunce :
>> >
>> > Hi Yoann,
>> >
>> > I do it like this:
>> http://quodatum.wordpress.com/2014/05/14/using-angular-with-basex
>> >
>> > /Andy

Re: [basex-talk] Rest Access from javascript using AngularJs

2014-05-15 Thread Yoann Maingon
Thx, I thought using option format=attribute would work but apparently not.
So no I fixed my issue using building the json:

module namespace _ = 'getObjectTypes';

(:~
 : test dev YMA
 :)
declare
  %rest:path("/getObjectTypes")
(:   %rest:query-param("name", "{$name}", "anonymous friend") :)
   %output:method("json")
function _:getObjectTypes() {
   let $db := db:open("simplePLM_test1")//objectType
return 
{
for $n in $db
return

{data($n/@name)}
{data($n/@label)}

 } 
};

Thank you for your help !


*Cordialement / Best Regards,*

*Yoann Maingon*
Minerva France

*+33 6 64 32 49 66*

Download Aras Innovator - Téléchargez Aras
Innovator




2014-05-15 9:07 GMT+02:00 Arve Gengelbach :

> Bonjour Yoann,
>
> The mapping XML –> JSON is not  1-1, i.e. not any XML can be immediately
> serialised to JSON. Your XML has to be in a certain format (direct,
> attributes, jsonml or map) as described in [JSON Module].
>
> I suggest you to template the JSON output you expect and apply
> json:parse() with desired options. This is the same as specifying output
> options in RestXQ. By then you know which format your XML has to have. I.e.
> start like this...
>
> json:parse(
> '{"resultat":[
>   {"objectType":[
> {"label":"nodes",
> "name":"nodes"}
>   ]},
>   {"objectType":[
> {"label":"links",
> "name":"links"}
>   ]}
> ]}', {"format":"direct"})
>
>
> hope this helps
> Arve
>
> [JSON Module] http://docs.basex.org/wiki/JSON_Module
>
> On 15 May 2014, at 01:17, Yoann Maingon 
> wrote:
>
> > Working on this development including Basex and AngularJs, I'm stuck
> with the Json output.
> > here is the error :
> >  [BXJS0002] JSON serializer:  has invalid attribute "label".
> > Here is the xqm :
> > module namespace _ = 'getObjectTypes';
> >
> > (:~
> >  : test dev YMA
> >  :)
> > declare
> >   %rest:path("/getObjectTypes")
> > (:   %rest:query-param("name", "{$name}", "anonymous friend") :)
> >%output:method("json")
> >%output:json("lax=yes")
> > function _:getObjectTypes() {
> >let $db := db:open("simplePLM_test1")//objectType
> >return {$db}
> > };
> >
> > If instead I export in XML I get this :
> > 
> >
> >
> >
> > http://schemas.xmlsoap.org/soap/envelope/";
> label="nodes" name="nodes"/>
> > http://schemas.xmlsoap.org/soap/envelope/";
> label="links" name="links"/>
> > 
> >
> > using this xqm:
> >
> > module namespace _ = 'getObjectTypes';
> >
> > (:~
> >  : test dev YMA
> >  :)
> > declare
> >   %rest:path("/getObjectTypes")
> > (:   %rest:query-param("name", "{$name}", "anonymous friend") :)
> >%output:method("xml")
> > function _:getObjectTypes() {
> >let $db := db:open("simplePLM_test1")//objectType
> >return {$db}
> > };
> >
> > any idea?
> >
> >
> >
> > Cordialement / Best Regards,
> >
> > Yoann Maingon
> > Minerva France
> >
> > +33 6 64 32 49 66
> >
> > Download Aras Innovator - Téléchargez Aras Innovator
> >
> >
> >
> >
> >
> > 2014-05-14 20:59 GMT+02:00 Yoann Maingon :
> > Thx for the blog post !
> >
> > I was close to make it work but now I've got an issue with Basex itself.
> > It says can't communicate with server when I'm trying to launch the
> basexhttp
> > I know it happened to me once on another computer never knew how I
> either fixed it or if I had my computer stolen since then.
> >
> > Is there any log I should check, any cleaning advice?
> >
> >
> > Cordialement / Best Regards,
> >
> > Yoann Maingon
> > Minerva France
> >
> > +33 6 64 32 49 66
> >
> > Download Aras Innovator - Téléchargez Aras Innovator
> >
> >
> >
> >
> >
> > 2014-05-14 16:25 GMT+02:00 Andy Bunce :
> >
> > Hi Yoann,
> >
> > I do it like this:
> http://quodatum.wordpress.com/2014/05/14/using-angular-with-basex
> >
> > /Andy
> >
> >
> >
> > On 14 May 2014 10:53, Yoann Maingon 
> wrote:
> > Hi,
> >
> > I've got two questions about using Basex with Angular, because I still
> have an issue accessing the XQuery module file.
> >
> > Quick feasibility question for development: If I just install basex and
> store my angularjs app in the webapp folder will this is be ok to interact
> with the database?
> > The github repo shows a typical folder structure :
> https://github.com/BaseXdb/basex-contrib/tree/master/basex-web-ng
> > What would it be if directly integrated in the basex folder?
> > Might be a noob question, but I'm a bit struggling here. I'm looking for
> an easy to way to setup a dev environnement. I'm not too much about
> perf/dbsize for now.
> >
> > Thx for your help.
> >
> >
> >
> >
> >
> > Cordialement / Best Regards,
> >
> > Yoann Maingon
> > Minerva France
> >
> > +33 6 64 32 49 66
> >
> > Download Aras Innovator - Téléchargez Aras Innovator
> >
> >
> >
> >
> >
> > 2014-05-07 15:21 GMT+02:00 Alexander Holupirek :
> >
> > On 07.05.2014, at 09:34, Maximilian Gärber  wrote:
> > > @basex: maybe it is time for a basex contrib page?
> >
> > Nice idea!
> >
> > We have just created
> >
> > https://github.com/BaseXdb/basex-cont

Re: [basex-talk] Rest Access from javascript using AngularJs

2014-05-15 Thread Arve Gengelbach
Bonjour Yoann,

The mapping XML –> JSON is not  1-1, i.e. not any XML can be immediately 
serialised to JSON. Your XML has to be in a certain format (direct, attributes, 
jsonml or map) as described in [JSON Module].

I suggest you to template the JSON output you expect and apply json:parse() 
with desired options. This is the same as specifying output options in RestXQ. 
By then you know which format your XML has to have. I.e. start like this...

json:parse(
'{"resultat":[
  {"objectType":[
{"label":"nodes",
"name":"nodes"}
  ]},
  {"objectType":[
{"label":"links",
"name":"links"}
  ]}
]}', {"format":"direct"})


hope this helps
Arve

[JSON Module] http://docs.basex.org/wiki/JSON_Module

On 15 May 2014, at 01:17, Yoann Maingon  wrote:

> Working on this development including Basex and AngularJs, I'm stuck with the 
> Json output.
> here is the error : 
>  [BXJS0002] JSON serializer:  has invalid attribute "label".
> Here is the xqm :
> module namespace _ = 'getObjectTypes';
> 
> (:~
>  : test dev YMA
>  :)
> declare
>   %rest:path("/getObjectTypes")
> (:   %rest:query-param("name", "{$name}", "anonymous friend") :)
>%output:method("json")
>%output:json("lax=yes")
> function _:getObjectTypes() {
>let $db := db:open("simplePLM_test1")//objectType
>return {$db}
> };
> 
> If instead I export in XML I get this :
> 
> 
> 
> 
> http://schemas.xmlsoap.org/soap/envelope/"; 
> label="nodes" name="nodes"/>
> http://schemas.xmlsoap.org/soap/envelope/"; 
> label="links" name="links"/>
> 
> 
> using this xqm:
> 
> module namespace _ = 'getObjectTypes';
> 
> (:~
>  : test dev YMA
>  :)
> declare
>   %rest:path("/getObjectTypes")
> (:   %rest:query-param("name", "{$name}", "anonymous friend") :)
>%output:method("xml")
> function _:getObjectTypes() {
>let $db := db:open("simplePLM_test1")//objectType
>return {$db}
> };
> 
> any idea?
> 
> 
> 
> Cordialement / Best Regards,
> 
> Yoann Maingon
> Minerva France
> 
> +33 6 64 32 49 66
> 
> Download Aras Innovator - Téléchargez Aras Innovator
> 
> 
> 
> 
> 
> 2014-05-14 20:59 GMT+02:00 Yoann Maingon :
> Thx for the blog post ! 
> 
> I was close to make it work but now I've got an issue with Basex itself.
> It says can't communicate with server when I'm trying to launch the basexhttp
> I know it happened to me once on another computer never knew how I either 
> fixed it or if I had my computer stolen since then.
> 
> Is there any log I should check, any cleaning advice? 
> 
> 
> Cordialement / Best Regards,
> 
> Yoann Maingon
> Minerva France
> 
> +33 6 64 32 49 66
> 
> Download Aras Innovator - Téléchargez Aras Innovator
> 
> 
> 
> 
> 
> 2014-05-14 16:25 GMT+02:00 Andy Bunce :
> 
> Hi Yoann,
> 
> I do it like this: 
> http://quodatum.wordpress.com/2014/05/14/using-angular-with-basex
> 
> /Andy
> 
> 
> 
> On 14 May 2014 10:53, Yoann Maingon  wrote:
> Hi,
> 
> I've got two questions about using Basex with Angular, because I still have 
> an issue accessing the XQuery module file.
> 
> Quick feasibility question for development: If I just install basex and store 
> my angularjs app in the webapp folder will this is be ok to interact with the 
> database?
> The github repo shows a typical folder structure : 
> https://github.com/BaseXdb/basex-contrib/tree/master/basex-web-ng
> What would it be if directly integrated in the basex folder?
> Might be a noob question, but I'm a bit struggling here. I'm looking for an 
> easy to way to setup a dev environnement. I'm not too much about perf/dbsize 
> for now.
> 
> Thx for your help.
> 
> 
> 
> 
> 
> Cordialement / Best Regards,
> 
> Yoann Maingon
> Minerva France
> 
> +33 6 64 32 49 66
> 
> Download Aras Innovator - Téléchargez Aras Innovator
> 
> 
> 
> 
> 
> 2014-05-07 15:21 GMT+02:00 Alexander Holupirek :
> 
> On 07.05.2014, at 09:34, Maximilian Gärber  wrote:
> > @basex: maybe it is time for a basex contrib page?
> 
> Nice idea!
> 
> We have just created
> 
> https://github.com/BaseXdb/basex-contrib
> 
> A github repository for
> 
> BaseX User Community Contributions
> 
> 
> On 07.05.2014, at 01:38, Yoann Maingon  wrote:
> > Does anyone as some example using either angularjs or jquery ?
> 
> We just added a first project
> 
> BaseX-Web-NG
> A BaseX-RestXQ-AngularJS-Bootstrap-WebApp example
> 
> motivated by your initial question (screenshot [1]):
> 
> 
> Looking forward to your examples and contributions!
> Micheee and Holu
> 
> [1] 
> https://raw.githubusercontent.com/BaseXdb/basex-contrib/master/basex-web-ng/public/static/gfx/Hello_Stranger.png
> 
> 
> 
> 
> 



Re: [basex-talk] Rest Access from javascript using AngularJs

2014-05-14 Thread Yoann Maingon
Working on this development including Basex and AngularJs, I'm stuck with
the Json output.
here is the error :

 [BXJS0002] JSON serializer:  has invalid attribute "label".

Here is the xqm :

module namespace _ = 'getObjectTypes';

(:~
 : test dev YMA
 :)
declare
  %rest:path("/getObjectTypes")
(:   %rest:query-param("name", "{$name}", "anonymous friend") :)
   %output:method("json")
   %output:json("lax=yes")
function _:getObjectTypes() {
   let $db := db:open("simplePLM_test1")//objectType
   return {$db}
};

If instead I export in XML I get this :


http://schemas.xmlsoap.org/soap/envelope/";
label="nodes" name="nodes"/>
http://schemas.xmlsoap.org/soap/envelope/";
label="links" name="links"/>


using this xqm:

module namespace _ = 'getObjectTypes';


(:~
 : test dev YMA
 :)
declare
  %rest:path("/getObjectTypes")
(:   %rest:query-param("name", "{$name}", "anonymous friend") :)
   %output:method("xml")
function _:getObjectTypes() {
   let $db := db:open("simplePLM_test1")//objectType

   return {$db}
};

any idea?




*Cordialement / Best Regards,*

*Yoann Maingon*
Minerva France

*+33 6 64 32 49 66*

Download Aras Innovator - Téléchargez Aras
Innovator




2014-05-14 20:59 GMT+02:00 Yoann Maingon :

> Thx for the blog post !
>
> I was close to make it work but now I've got an issue with Basex itself.
> It says can't communicate with server when I'm trying to launch the
> basexhttp
> I know it happened to me once on another computer never knew how I either
> fixed it or if I had my computer stolen since then.
>
> Is there any log I should check, any cleaning advice?
>
>
> *Cordialement / Best Regards,*
>
> *Yoann Maingon*
> Minerva France
>
> *+33 6 64 32 49 66 <%2B33%206%C2%A064%2032%2049%2066>*
>
> Download Aras Innovator - Téléchargez Aras 
> Innovator
>
>
>
>
> 2014-05-14 16:25 GMT+02:00 Andy Bunce :
>
> Hi Yoann,
>>
>> I do it like this:
>> http://quodatum.wordpress.com/2014/05/14/using-angular-with-basex
>>
>> /Andy
>>
>>
>>
>> On 14 May 2014 10:53, Yoann Maingon  wrote:
>>
>>> Hi,
>>>
>>> I've got two questions about using Basex with Angular, because I still
>>> have an issue accessing the XQuery module file.
>>>
>>> Quick feasibility question for development: If I just install basex and
>>> store my angularjs app in the webapp folder will this is be ok to interact
>>> with the database?
>>> The github repo shows a typical folder structure :
>>> https://github.com/BaseXdb/basex-contrib/tree/master/basex-web-ng
>>> What would it be if directly integrated in the basex folder?
>>> Might be a noob question, but I'm a bit struggling here. I'm looking for
>>> an easy to way to setup a dev environnement. I'm not too much about
>>> perf/dbsize for now.
>>>
>>> Thx for your help.
>>>
>>>
>>>
>>>
>>>
>>> *Cordialement / Best Regards,*
>>>
>>> *Yoann Maingon*
>>> Minerva France
>>>
>>> *+33 6 64 32 49 66 <%2B33%206%C2%A064%2032%2049%2066>*
>>>
>>> Download Aras Innovator - Téléchargez Aras 
>>> Innovator
>>>
>>>
>>>
>>>
>>> 2014-05-07 15:21 GMT+02:00 Alexander Holupirek :
>>>
>>> On 07.05.2014, at 09:34, Maximilian Gärber  wrote:
 > @basex: maybe it is time for a basex contrib page?

 Nice idea!

 We have just created

 https://github.com/BaseXdb/basex-contrib

 A github repository for

 BaseX User Community Contributions


 On 07.05.2014, at 01:38, Yoann Maingon 
 wrote:
 > Does anyone as some example using either angularjs or jquery ?

 We just added a first project

 BaseX-Web-NG
 A BaseX-RestXQ-AngularJS-Bootstrap-WebApp example

 motivated by your initial question (screenshot [1]):


 Looking forward to your examples and contributions!
 Micheee and Holu

 [1]
 https://raw.githubusercontent.com/BaseXdb/basex-contrib/master/basex-web-ng/public/static/gfx/Hello_Stranger.png


>>>
>>
>


Re: [basex-talk] Rest Access from javascript using AngularJs

2014-05-14 Thread Yoann Maingon
Thx for the blog post !

I was close to make it work but now I've got an issue with Basex itself.
It says can't communicate with server when I'm trying to launch the
basexhttp
I know it happened to me once on another computer never knew how I either
fixed it or if I had my computer stolen since then.

Is there any log I should check, any cleaning advice?


*Cordialement / Best Regards,*

*Yoann Maingon*
Minerva France

*+33 6 64 32 49 66*

Download Aras Innovator - Téléchargez Aras
Innovator




2014-05-14 16:25 GMT+02:00 Andy Bunce :

> Hi Yoann,
>
> I do it like this:
> http://quodatum.wordpress.com/2014/05/14/using-angular-with-basex
>
> /Andy
>
>
>
> On 14 May 2014 10:53, Yoann Maingon  wrote:
>
>> Hi,
>>
>> I've got two questions about using Basex with Angular, because I still
>> have an issue accessing the XQuery module file.
>>
>> Quick feasibility question for development: If I just install basex and
>> store my angularjs app in the webapp folder will this is be ok to interact
>> with the database?
>> The github repo shows a typical folder structure :
>> https://github.com/BaseXdb/basex-contrib/tree/master/basex-web-ng
>> What would it be if directly integrated in the basex folder?
>> Might be a noob question, but I'm a bit struggling here. I'm looking for
>> an easy to way to setup a dev environnement. I'm not too much about
>> perf/dbsize for now.
>>
>> Thx for your help.
>>
>>
>>
>>
>>
>> *Cordialement / Best Regards,*
>>
>> *Yoann Maingon*
>> Minerva France
>>
>> *+33 6 64 32 49 66 <%2B33%206%C2%A064%2032%2049%2066>*
>>
>> Download Aras Innovator - Téléchargez Aras 
>> Innovator
>>
>>
>>
>>
>> 2014-05-07 15:21 GMT+02:00 Alexander Holupirek :
>>
>> On 07.05.2014, at 09:34, Maximilian Gärber  wrote:
>>> > @basex: maybe it is time for a basex contrib page?
>>>
>>> Nice idea!
>>>
>>> We have just created
>>>
>>> https://github.com/BaseXdb/basex-contrib
>>>
>>> A github repository for
>>>
>>> BaseX User Community Contributions
>>>
>>>
>>> On 07.05.2014, at 01:38, Yoann Maingon 
>>> wrote:
>>> > Does anyone as some example using either angularjs or jquery ?
>>>
>>> We just added a first project
>>>
>>> BaseX-Web-NG
>>> A BaseX-RestXQ-AngularJS-Bootstrap-WebApp example
>>>
>>> motivated by your initial question (screenshot [1]):
>>>
>>>
>>> Looking forward to your examples and contributions!
>>> Micheee and Holu
>>>
>>> [1]
>>> https://raw.githubusercontent.com/BaseXdb/basex-contrib/master/basex-web-ng/public/static/gfx/Hello_Stranger.png
>>>
>>>
>>
>


Re: [basex-talk] Rest Access from javascript using AngularJs

2014-05-14 Thread Andy Bunce
Hi Yoann,

I do it like this:
http://quodatum.wordpress.com/2014/05/14/using-angular-with-basex

/Andy



On 14 May 2014 10:53, Yoann Maingon  wrote:

> Hi,
>
> I've got two questions about using Basex with Angular, because I still
> have an issue accessing the XQuery module file.
>
> Quick feasibility question for development: If I just install basex and
> store my angularjs app in the webapp folder will this is be ok to interact
> with the database?
> The github repo shows a typical folder structure :
> https://github.com/BaseXdb/basex-contrib/tree/master/basex-web-ng
> What would it be if directly integrated in the basex folder?
> Might be a noob question, but I'm a bit struggling here. I'm looking for
> an easy to way to setup a dev environnement. I'm not too much about
> perf/dbsize for now.
>
> Thx for your help.
>
>
>
>
>
> *Cordialement / Best Regards,*
>
> *Yoann Maingon*
> Minerva France
>
> *+33 6 64 32 49 66 <%2B33%206%C2%A064%2032%2049%2066>*
>
> Download Aras Innovator - Téléchargez Aras 
> Innovator
>
>
>
>
> 2014-05-07 15:21 GMT+02:00 Alexander Holupirek :
>
> On 07.05.2014, at 09:34, Maximilian Gärber  wrote:
>> > @basex: maybe it is time for a basex contrib page?
>>
>> Nice idea!
>>
>> We have just created
>>
>> https://github.com/BaseXdb/basex-contrib
>>
>> A github repository for
>>
>> BaseX User Community Contributions
>>
>>
>> On 07.05.2014, at 01:38, Yoann Maingon 
>> wrote:
>> > Does anyone as some example using either angularjs or jquery ?
>>
>> We just added a first project
>>
>> BaseX-Web-NG
>> A BaseX-RestXQ-AngularJS-Bootstrap-WebApp example
>>
>> motivated by your initial question (screenshot [1]):
>>
>>
>> Looking forward to your examples and contributions!
>> Micheee and Holu
>>
>> [1]
>> https://raw.githubusercontent.com/BaseXdb/basex-contrib/master/basex-web-ng/public/static/gfx/Hello_Stranger.png
>>
>>
>


Re: [basex-talk] Rest Access from javascript using AngularJs

2014-05-14 Thread Yoann Maingon
Hi,

I've got two questions about using Basex with Angular, because I still have
an issue accessing the XQuery module file.

Quick feasibility question for development: If I just install basex and
store my angularjs app in the webapp folder will this is be ok to interact
with the database?
The github repo shows a typical folder structure :
https://github.com/BaseXdb/basex-contrib/tree/master/basex-web-ng
What would it be if directly integrated in the basex folder?
Might be a noob question, but I'm a bit struggling here. I'm looking for an
easy to way to setup a dev environnement. I'm not too much about
perf/dbsize for now.

Thx for your help.





*Cordialement / Best Regards,*

*Yoann Maingon*
Minerva France

*+33 6 64 32 49 66*

Download Aras Innovator - Téléchargez Aras
Innovator




2014-05-07 15:21 GMT+02:00 Alexander Holupirek :

> On 07.05.2014, at 09:34, Maximilian Gärber  wrote:
> > @basex: maybe it is time for a basex contrib page?
>
> Nice idea!
>
> We have just created
>
> https://github.com/BaseXdb/basex-contrib
>
> A github repository for
>
> BaseX User Community Contributions
>
>
> On 07.05.2014, at 01:38, Yoann Maingon 
> wrote:
> > Does anyone as some example using either angularjs or jquery ?
>
> We just added a first project
>
> BaseX-Web-NG
> A BaseX-RestXQ-AngularJS-Bootstrap-WebApp example
>
> motivated by your initial question (screenshot [1]):
>
>
> Looking forward to your examples and contributions!
> Micheee and Holu
>
> [1]
> https://raw.githubusercontent.com/BaseXdb/basex-contrib/master/basex-web-ng/public/static/gfx/Hello_Stranger.png
>
>


Re: [basex-talk] Rest Access from javascript using AngularJs

2014-05-07 Thread Alexander Holupirek
On 07.05.2014, at 09:34, Maximilian Gärber  wrote:
> @basex: maybe it is time for a basex contrib page?

Nice idea!

We have just created

https://github.com/BaseXdb/basex-contrib

A github repository for

BaseX User Community Contributions


On 07.05.2014, at 01:38, Yoann Maingon  wrote:
> Does anyone as some example using either angularjs or jquery ?

We just added a first project

BaseX-Web-NG
A BaseX-RestXQ-AngularJS-Bootstrap-WebApp example

motivated by your initial question (screenshot [1]):


Looking forward to your examples and contributions!
Micheee and Holu

[1] 
https://raw.githubusercontent.com/BaseXdb/basex-contrib/master/basex-web-ng/public/static/gfx/Hello_Stranger.png



signature.asc
Description: Message signed with OpenPGP using GPGMail


Re: [basex-talk] Rest Access from javascript using AngularJs

2014-05-07 Thread Andy Bunce
>although I was surprised about the reported execution times at that time

Yes my test was a bit harsh :-)
ab -n 100 -c 10  http://localhost:8984/bsp/simple
Is 100 requests as fast as possible with 10 concurrent. I also had nearly
2Mb of parser code in XQuery generated by REX [1] just in one app.

Thanks for the tips.
/Andy

[1] http://www.bottlecaps.de/rex/


On 7 May 2014 11:24, Christian Grün  wrote:

> > However one thing to be aware of with the current implementation is that
> > response times depend on the quantity of XQuery code defined, making
> large
> > applications problematic. This was mentioned in Christian's recent
> "Upcoming
> > features" email, so I am sure it will be addressed soon.
>
> I agree with Andy (although I was surprised about the reported
> execution times at that time). In one of our projects, we now have
> around 500 KB of XQuery code, and the constant overhead for evaluating
> a single REST request is about 40 ms - which may be too slow if you
> have lots of requests per seconds.
>
> However, if you encounter bottlenecks, there are already various ways
> to improve performance (all of them undocumented, I guess - once
> again, Wiki edits are welcome..):
>
> * Move all XQuery modules without RESTXQ annotations into your
> repository ("repo" directory) [1]. This can be done manually (there is
> no need to use the REPO commands), and you can edit XQuery modules
> directly in your repo directory.
>
> * Only keep those XQuery modules in your restxq directory which are
> required in your project.
>
> The reason is that the restxq directory is scanned for changes every
> time a new request takes place. We think about introducing a RELEASE
> mode in a future version, in which various checks will be skipped that
> are required during the development stage.
>
> Hope this helps,
> Christian
>
> [1] http://docs.basex.org/wiki/Repository
>
>
>
>
> >> Hello Yoann,
> >>
> >> You do not "need to do so", but I remember your project quite well and I
> >> was one of the people who said you don't actually need PHP. From what I
> >> saw and remember, I think RestXQ is simply a much better fit.
> >>
> >> RestXQ enables you to do complete server-side processing (just like PHP
> >> does) using XQuery. You can define all sorts of options for your
> >> functions using annotations and how it should be served to your users.
> >>
> >> Theoretically, this would also be possible using Rest. However, the Rest
> >> interface is more intended for short queries and querying on a data set.
> >> You will always have to submit your query and of course this is very
> >> impractical and slow if you develop a whole web app.
> >> But it might be a good idea to add something to the documentation to
> >> make the distinction between rest and RestXQ clearer. So much we could
> >> add to the docs, actually... :)
> >>
> >> Cheers,
> >> Dirk
> >>
> >> On 07/05/14 10:44, Yoann Maingon wrote:
> >> > Thx
> >> >
> >> > I look into the provided example. At first I was more going into Rest
> >> > and
> >> > not RestXq, but if I need to do so then I guess I need to spend some
> >> > time
> >> > on it.
> >> > Open sourcing our projects is a good question.
> >> > I still have some colleagues affraid to somehow loose what they've
> >> > developped and I don't have a clear opinion about it. But I'd be happy
> >> > to
> >> > share code (you may regret it! I'm a bad developper !)
> >> >
> >> >
> >> > *Cordialement / Best Regards,*
> >> >
> >> > *Yoann Maingon*
> >> > Minerva France
> >> >
> >> > *+33 6 64 32 49 66*
> >> >
> >> > Download Aras Innovator - Téléchargez Aras
> >> > Innovator<
> http://www.aras.com/support/downloads/downloadInnovator.aspx>
> >> >
> >> >
> >> >
> >> >
> >> > 2014-05-07 10:18 GMT+02:00 Dirk Kirsten :
> >> >
> >> >> Hi,
> >> >>
> >> >> I agree with Max that it would be a good idea to have a list of
> >> >> projects
> >> >> and examples, which are build on top of BaseX. A problem might be
> that
> >> >> many applications which are build on top of BaseX are not open
> source.
> >> >>
> >> >> @Yoann: Please be aware that there is a Rest and RestXQ
> implementation
> >> >> within BaseX, which are quite different. What you most likely want to
> >> >> use is RestXQ. Some documentation is available at
> >> >> https://docs.basex.org/wiki/RESTXQ
> >> >> Using RestXQ itself, there is an example for a blog at
> >> >> https://github.com/siserle/blog-example
> >> >>
> >> >> As Max already suggested, the main difference when you use it with
> >> >> angular or some other framework is that you most likely want to
> return
> >> >> JSON, so you have to change the output method.
> >> >>
> >> >> Cheers,
> >> >> Dirk
> >> >>
> >> >> On 07/05/14 09:34, Maximilian Gärber wrote:
> >> >>> Hi Yoann,
> >> >>>
> >> >>> I guess having examples like these would be helpful in general.
> >> >>> Together with basex, we built a larger project for managing
> conference
> >> >>> registrations etc. last year. I could extract some of the modules -

Re: [basex-talk] Rest Access from javascript using AngularJs

2014-05-07 Thread Christian Grün
> However one thing to be aware of with the current implementation is that
> response times depend on the quantity of XQuery code defined, making large
> applications problematic. This was mentioned in Christian's recent "Upcoming
> features" email, so I am sure it will be addressed soon.

I agree with Andy (although I was surprised about the reported
execution times at that time). In one of our projects, we now have
around 500 KB of XQuery code, and the constant overhead for evaluating
a single REST request is about 40 ms - which may be too slow if you
have lots of requests per seconds.

However, if you encounter bottlenecks, there are already various ways
to improve performance (all of them undocumented, I guess - once
again, Wiki edits are welcome..):

* Move all XQuery modules without RESTXQ annotations into your
repository ("repo" directory) [1]. This can be done manually (there is
no need to use the REPO commands), and you can edit XQuery modules
directly in your repo directory.

* Only keep those XQuery modules in your restxq directory which are
required in your project.

The reason is that the restxq directory is scanned for changes every
time a new request takes place. We think about introducing a RELEASE
mode in a future version, in which various checks will be skipped that
are required during the development stage.

Hope this helps,
Christian

[1] http://docs.basex.org/wiki/Repository




>> Hello Yoann,
>>
>> You do not "need to do so", but I remember your project quite well and I
>> was one of the people who said you don't actually need PHP. From what I
>> saw and remember, I think RestXQ is simply a much better fit.
>>
>> RestXQ enables you to do complete server-side processing (just like PHP
>> does) using XQuery. You can define all sorts of options for your
>> functions using annotations and how it should be served to your users.
>>
>> Theoretically, this would also be possible using Rest. However, the Rest
>> interface is more intended for short queries and querying on a data set.
>> You will always have to submit your query and of course this is very
>> impractical and slow if you develop a whole web app.
>> But it might be a good idea to add something to the documentation to
>> make the distinction between rest and RestXQ clearer. So much we could
>> add to the docs, actually... :)
>>
>> Cheers,
>> Dirk
>>
>> On 07/05/14 10:44, Yoann Maingon wrote:
>> > Thx
>> >
>> > I look into the provided example. At first I was more going into Rest
>> > and
>> > not RestXq, but if I need to do so then I guess I need to spend some
>> > time
>> > on it.
>> > Open sourcing our projects is a good question.
>> > I still have some colleagues affraid to somehow loose what they've
>> > developped and I don't have a clear opinion about it. But I'd be happy
>> > to
>> > share code (you may regret it! I'm a bad developper !)
>> >
>> >
>> > *Cordialement / Best Regards,*
>> >
>> > *Yoann Maingon*
>> > Minerva France
>> >
>> > *+33 6 64 32 49 66*
>> >
>> > Download Aras Innovator - Téléchargez Aras
>> > Innovator
>> >
>> >
>> >
>> >
>> > 2014-05-07 10:18 GMT+02:00 Dirk Kirsten :
>> >
>> >> Hi,
>> >>
>> >> I agree with Max that it would be a good idea to have a list of
>> >> projects
>> >> and examples, which are build on top of BaseX. A problem might be that
>> >> many applications which are build on top of BaseX are not open source.
>> >>
>> >> @Yoann: Please be aware that there is a Rest and RestXQ implementation
>> >> within BaseX, which are quite different. What you most likely want to
>> >> use is RestXQ. Some documentation is available at
>> >> https://docs.basex.org/wiki/RESTXQ
>> >> Using RestXQ itself, there is an example for a blog at
>> >> https://github.com/siserle/blog-example
>> >>
>> >> As Max already suggested, the main difference when you use it with
>> >> angular or some other framework is that you most likely want to return
>> >> JSON, so you have to change the output method.
>> >>
>> >> Cheers,
>> >> Dirk
>> >>
>> >> On 07/05/14 09:34, Maximilian Gärber wrote:
>> >>> Hi Yoann,
>> >>>
>> >>> I guess having examples like these would be helpful in general.
>> >>> Together with basex, we built a larger project for managing conference
>> >>> registrations etc. last year. I could extract some of the modules -
>> >>> maybe we could manage to publish them on some github repo or a
>> >>> dedicated site? @basex: maybe it is time for a basex contrib page?
>> >>>
>> >>> What you need, is some json endpoint which leverages the session
>> >>> module, checks the credentials and returns some json back to Angular
>> >>> (or JQuey)
>> >>>
>> >>> Besides that, you need to secure all your restxq endpoints with a
>> >>> authentication check:
>> >>>
>> >>>if(not(session:logged-in())) then web:redirect($C:START-PAGE) else
>> >>> _:do-something-useful()
>> >>>
>> >>>
>> >>> Login example:
>> >>>
>> >>>
>> >>> import module namespace session =
>> >>> "h

Re: [basex-talk] Rest Access from javascript using AngularJs

2014-05-07 Thread Andy Bunce
Hi Yoann,

I completely agree that RESTXQ is the way to go. I have some Angular auth
code for RESTXQ similar to Maximilian's [1]. This is a bit old now (BaseX
7.5 Angular 1.0) so may have rotted a bit.

However one thing to be aware of with the current implementation is that
response times depend on the quantity of XQuery code defined, making large
applications problematic. This was mentioned in Christian's recent
"Upcoming features" email, so I am sure it will be addressed soon.

Regards
/Andy

[1]
https://github.com/apb2006/basex-cellar/blob/master/src/cellar/auth/auth.js


On 7 May 2014 10:06, Dirk Kirsten  wrote:

> Hello Yoann,
>
> You do not "need to do so", but I remember your project quite well and I
> was one of the people who said you don't actually need PHP. From what I
> saw and remember, I think RestXQ is simply a much better fit.
>
> RestXQ enables you to do complete server-side processing (just like PHP
> does) using XQuery. You can define all sorts of options for your
> functions using annotations and how it should be served to your users.
>
> Theoretically, this would also be possible using Rest. However, the Rest
> interface is more intended for short queries and querying on a data set.
> You will always have to submit your query and of course this is very
> impractical and slow if you develop a whole web app.
> But it might be a good idea to add something to the documentation to
> make the distinction between rest and RestXQ clearer. So much we could
> add to the docs, actually... :)
>
> Cheers,
> Dirk
>
> On 07/05/14 10:44, Yoann Maingon wrote:
> > Thx
> >
> > I look into the provided example. At first I was more going into Rest and
> > not RestXq, but if I need to do so then I guess I need to spend some time
> > on it.
> > Open sourcing our projects is a good question.
> > I still have some colleagues affraid to somehow loose what they've
> > developped and I don't have a clear opinion about it. But I'd be happy to
> > share code (you may regret it! I'm a bad developper !)
> >
> >
> > *Cordialement / Best Regards,*
> >
> > *Yoann Maingon*
> > Minerva France
> >
> > *+33 6 64 32 49 66*
> >
> > Download Aras Innovator - Téléchargez Aras
> > Innovator
> >
> >
> >
> >
> > 2014-05-07 10:18 GMT+02:00 Dirk Kirsten :
> >
> >> Hi,
> >>
> >> I agree with Max that it would be a good idea to have a list of projects
> >> and examples, which are build on top of BaseX. A problem might be that
> >> many applications which are build on top of BaseX are not open source.
> >>
> >> @Yoann: Please be aware that there is a Rest and RestXQ implementation
> >> within BaseX, which are quite different. What you most likely want to
> >> use is RestXQ. Some documentation is available at
> >> https://docs.basex.org/wiki/RESTXQ
> >> Using RestXQ itself, there is an example for a blog at
> >> https://github.com/siserle/blog-example
> >>
> >> As Max already suggested, the main difference when you use it with
> >> angular or some other framework is that you most likely want to return
> >> JSON, so you have to change the output method.
> >>
> >> Cheers,
> >> Dirk
> >>
> >> On 07/05/14 09:34, Maximilian Gärber wrote:
> >>> Hi Yoann,
> >>>
> >>> I guess having examples like these would be helpful in general.
> >>> Together with basex, we built a larger project for managing conference
> >>> registrations etc. last year. I could extract some of the modules -
> >>> maybe we could manage to publish them on some github repo or a
> >>> dedicated site? @basex: maybe it is time for a basex contrib page?
> >>>
> >>> What you need, is some json endpoint which leverages the session
> >>> module, checks the credentials and returns some json back to Angular
> >>> (or JQuey)
> >>>
> >>> Besides that, you need to secure all your restxq endpoints with a
> >>> authentication check:
> >>>
> >>>if(not(session:logged-in())) then web:redirect($C:START-PAGE) else
> >>> _:do-something-useful()
> >>>
> >>>
> >>> Login example:
> >>>
> >>>
> >>> import module namespace session = "
> http://basex.org/modules/web/session
> >> ";
> >>>
> >>> declare
> >>>   %restxq:path("/api/login/check")
> >>>   %restxq:POST("{$content}")
> >>>   %output:method("json")
> >>>   %output:json("lax=yes")
> >>>   function _:check(
> >>> $content as item()*
> >>>   )
> >>> {
> >>>   let $user := $content//u/string()
> >>>   let $pass := $content//p/string()
> >>>
> >>>   let $ok := _:check-user($user, $pass)
> >>>
> >>> if ($ok) then
> >>>   let $user-id := session:id()
> >>>   let $role:= session:role()
> >>>   return((),
> >>>   
> >>>   {_:redirect-url-from-role($role)}
> >>> 
> >>>)
> >>>else
> >>>
> >>> Login failed.
> >>>   
> >>> };
> >>>
> >>>
> >>> angular.module('login', [])
> >>>   .config([
> >>>   '$routeProvider',
> >>>   function ($routeProvider) {
> >>> $routeProvider.when('/Logout', {
> >>>   

Re: [basex-talk] Rest Access from javascript using AngularJs

2014-05-07 Thread Dirk Kirsten
Hello Yoann,

You do not "need to do so", but I remember your project quite well and I
was one of the people who said you don't actually need PHP. From what I
saw and remember, I think RestXQ is simply a much better fit.

RestXQ enables you to do complete server-side processing (just like PHP
does) using XQuery. You can define all sorts of options for your
functions using annotations and how it should be served to your users.

Theoretically, this would also be possible using Rest. However, the Rest
interface is more intended for short queries and querying on a data set.
You will always have to submit your query and of course this is very
impractical and slow if you develop a whole web app.
But it might be a good idea to add something to the documentation to
make the distinction between rest and RestXQ clearer. So much we could
add to the docs, actually... :)

Cheers,
Dirk

On 07/05/14 10:44, Yoann Maingon wrote:
> Thx
> 
> I look into the provided example. At first I was more going into Rest and
> not RestXq, but if I need to do so then I guess I need to spend some time
> on it.
> Open sourcing our projects is a good question.
> I still have some colleagues affraid to somehow loose what they've
> developped and I don't have a clear opinion about it. But I'd be happy to
> share code (you may regret it! I'm a bad developper !)
> 
> 
> *Cordialement / Best Regards,*
> 
> *Yoann Maingon*
> Minerva France
> 
> *+33 6 64 32 49 66*
> 
> Download Aras Innovator - Téléchargez Aras
> Innovator
> 
> 
> 
> 
> 2014-05-07 10:18 GMT+02:00 Dirk Kirsten :
> 
>> Hi,
>>
>> I agree with Max that it would be a good idea to have a list of projects
>> and examples, which are build on top of BaseX. A problem might be that
>> many applications which are build on top of BaseX are not open source.
>>
>> @Yoann: Please be aware that there is a Rest and RestXQ implementation
>> within BaseX, which are quite different. What you most likely want to
>> use is RestXQ. Some documentation is available at
>> https://docs.basex.org/wiki/RESTXQ
>> Using RestXQ itself, there is an example for a blog at
>> https://github.com/siserle/blog-example
>>
>> As Max already suggested, the main difference when you use it with
>> angular or some other framework is that you most likely want to return
>> JSON, so you have to change the output method.
>>
>> Cheers,
>> Dirk
>>
>> On 07/05/14 09:34, Maximilian Gärber wrote:
>>> Hi Yoann,
>>>
>>> I guess having examples like these would be helpful in general.
>>> Together with basex, we built a larger project for managing conference
>>> registrations etc. last year. I could extract some of the modules -
>>> maybe we could manage to publish them on some github repo or a
>>> dedicated site? @basex: maybe it is time for a basex contrib page?
>>>
>>> What you need, is some json endpoint which leverages the session
>>> module, checks the credentials and returns some json back to Angular
>>> (or JQuey)
>>>
>>> Besides that, you need to secure all your restxq endpoints with a
>>> authentication check:
>>>
>>>if(not(session:logged-in())) then web:redirect($C:START-PAGE) else
>>> _:do-something-useful()
>>>
>>>
>>> Login example:
>>>
>>>
>>> import module namespace session = "http://basex.org/modules/web/session
>> ";
>>>
>>> declare
>>>   %restxq:path("/api/login/check")
>>>   %restxq:POST("{$content}")
>>>   %output:method("json")
>>>   %output:json("lax=yes")
>>>   function _:check(
>>> $content as item()*
>>>   )
>>> {
>>>   let $user := $content//u/string()
>>>   let $pass := $content//p/string()
>>>
>>>   let $ok := _:check-user($user, $pass)
>>>
>>> if ($ok) then
>>>   let $user-id := session:id()
>>>   let $role:= session:role()
>>>   return((),
>>>   
>>>   {_:redirect-url-from-role($role)}
>>> 
>>>)
>>>else
>>>
>>> Login failed.
>>>   
>>> };
>>>
>>>
>>> angular.module('login', [])
>>>   .config([
>>>   '$routeProvider',
>>>   function ($routeProvider) {
>>> $routeProvider.when('/Logout', {
>>>   redirectTo: '/restxq/logout'
>>> });
>>> }])
>>>
>>>   .controller('LoginCtrl', [
>>> '$scope', '$http', '$location',
>>> function ($scope, $http, $location) {
>>>   $scope.login = function() {
>>> var url = '/restxq/api/login/check';
>>>
>>>//use jquery here, because angular does not detect auto-fill data
>>> var payload = {
>>>   u: $('#u').val(),
>>>   p: $('#p').val()
>>> };
>>>
>>> $http.post(url, payload).
>>> success(function(data) {
>>>   if (data.error) {
>>>   // trigger error status
>>> $scope.loginForm.$error.failed = true;
>>>   } else {
>>>   // redirect
>>> window.location.pathname = data.url;
>>>   }
>>> }).
>>> error(function(data, status, headers, config) {
>>>   a

Re: [basex-talk] Rest Access from javascript using AngularJs

2014-05-07 Thread Yoann Maingon
Thx

I look into the provided example. At first I was more going into Rest and
not RestXq, but if I need to do so then I guess I need to spend some time
on it.
Open sourcing our projects is a good question.
I still have some colleagues affraid to somehow loose what they've
developped and I don't have a clear opinion about it. But I'd be happy to
share code (you may regret it! I'm a bad developper !)


*Cordialement / Best Regards,*

*Yoann Maingon*
Minerva France

*+33 6 64 32 49 66*

Download Aras Innovator - Téléchargez Aras
Innovator




2014-05-07 10:18 GMT+02:00 Dirk Kirsten :

> Hi,
>
> I agree with Max that it would be a good idea to have a list of projects
> and examples, which are build on top of BaseX. A problem might be that
> many applications which are build on top of BaseX are not open source.
>
> @Yoann: Please be aware that there is a Rest and RestXQ implementation
> within BaseX, which are quite different. What you most likely want to
> use is RestXQ. Some documentation is available at
> https://docs.basex.org/wiki/RESTXQ
> Using RestXQ itself, there is an example for a blog at
> https://github.com/siserle/blog-example
>
> As Max already suggested, the main difference when you use it with
> angular or some other framework is that you most likely want to return
> JSON, so you have to change the output method.
>
> Cheers,
> Dirk
>
> On 07/05/14 09:34, Maximilian Gärber wrote:
> > Hi Yoann,
> >
> > I guess having examples like these would be helpful in general.
> > Together with basex, we built a larger project for managing conference
> > registrations etc. last year. I could extract some of the modules -
> > maybe we could manage to publish them on some github repo or a
> > dedicated site? @basex: maybe it is time for a basex contrib page?
> >
> > What you need, is some json endpoint which leverages the session
> > module, checks the credentials and returns some json back to Angular
> > (or JQuey)
> >
> > Besides that, you need to secure all your restxq endpoints with a
> > authentication check:
> >
> >if(not(session:logged-in())) then web:redirect($C:START-PAGE) else
> > _:do-something-useful()
> >
> >
> > Login example:
> >
> >
> > import module namespace session = "http://basex.org/modules/web/session
> ";
> >
> > declare
> >   %restxq:path("/api/login/check")
> >   %restxq:POST("{$content}")
> >   %output:method("json")
> >   %output:json("lax=yes")
> >   function _:check(
> > $content as item()*
> >   )
> > {
> >   let $user := $content//u/string()
> >   let $pass := $content//p/string()
> >
> >   let $ok := _:check-user($user, $pass)
> >
> > if ($ok) then
> >   let $user-id := session:id()
> >   let $role:= session:role()
> >   return((),
> >   
> >   {_:redirect-url-from-role($role)}
> > 
> >)
> >else
> >
> > Login failed.
> >   
> > };
> >
> >
> > angular.module('login', [])
> >   .config([
> >   '$routeProvider',
> >   function ($routeProvider) {
> > $routeProvider.when('/Logout', {
> >   redirectTo: '/restxq/logout'
> > });
> > }])
> >
> >   .controller('LoginCtrl', [
> > '$scope', '$http', '$location',
> > function ($scope, $http, $location) {
> >   $scope.login = function() {
> > var url = '/restxq/api/login/check';
> >
> >//use jquery here, because angular does not detect auto-fill data
> > var payload = {
> >   u: $('#u').val(),
> >   p: $('#p').val()
> > };
> >
> > $http.post(url, payload).
> > success(function(data) {
> >   if (data.error) {
> >   // trigger error status
> > $scope.loginForm.$error.failed = true;
> >   } else {
> >   // redirect
> > window.location.pathname = data.url;
> >   }
> > }).
> > error(function(data, status, headers, config) {
> >   alert("Could not load data from server.")
> > });
> >   };
> >   }]);
> >
> >  
> > 
> > Please Login
> >
> >   
> > 
> >   Incorrect login data. Please try again.
> > 
> >   
> >   
> > 
> >   
> > Username  
> >  > style="width:146px !important;margin:0"/>
> >   
> >   
> > Password   
> >  > style="width:146px !important;margin:0" type="password" />
> >   
> >   
> > 
> >  > style="width:152px !important;margin:0">Login
> > 
> >   
> > 
> >
> >   
> > 
> > 
> >
> >  Regards,
> >
> > Max
> >
> >
> >
> >
> > 2014-05-07 1:38 GMT+02:00 Yoann Maingon :
> >> Hi,
> >>
> >> After xmlprague and my presentation at the BaseX user group I was told
> (and
> >> I agree) that it wasn't really smart to use php for what I was building
> as
> >> it had almost no added value as I could dire

Re: [basex-talk] Rest Access from javascript using AngularJs

2014-05-07 Thread Dirk Kirsten
Hi,

I agree with Max that it would be a good idea to have a list of projects
and examples, which are build on top of BaseX. A problem might be that
many applications which are build on top of BaseX are not open source.

@Yoann: Please be aware that there is a Rest and RestXQ implementation
within BaseX, which are quite different. What you most likely want to
use is RestXQ. Some documentation is available at
https://docs.basex.org/wiki/RESTXQ
Using RestXQ itself, there is an example for a blog at
https://github.com/siserle/blog-example

As Max already suggested, the main difference when you use it with
angular or some other framework is that you most likely want to return
JSON, so you have to change the output method.

Cheers,
Dirk

On 07/05/14 09:34, Maximilian Gärber wrote:
> Hi Yoann,
> 
> I guess having examples like these would be helpful in general.
> Together with basex, we built a larger project for managing conference
> registrations etc. last year. I could extract some of the modules -
> maybe we could manage to publish them on some github repo or a
> dedicated site? @basex: maybe it is time for a basex contrib page?
> 
> What you need, is some json endpoint which leverages the session
> module, checks the credentials and returns some json back to Angular
> (or JQuey)
> 
> Besides that, you need to secure all your restxq endpoints with a
> authentication check:
> 
>if(not(session:logged-in())) then web:redirect($C:START-PAGE) else
> _:do-something-useful()
> 
> 
> Login example:
> 
> 
> import module namespace session = "http://basex.org/modules/web/session";;
> 
> declare
>   %restxq:path("/api/login/check")
>   %restxq:POST("{$content}")
>   %output:method("json")
>   %output:json("lax=yes")
>   function _:check(
> $content as item()*
>   )
> {
>   let $user := $content//u/string()
>   let $pass := $content//p/string()
> 
>   let $ok := _:check-user($user, $pass)
> 
> if ($ok) then
>   let $user-id := session:id()
>   let $role:= session:role()
>   return((),
>   
>   {_:redirect-url-from-role($role)}
> 
>)
>else
>
> Login failed.
>   
> };
> 
> 
> angular.module('login', [])
>   .config([
>   '$routeProvider',
>   function ($routeProvider) {
> $routeProvider.when('/Logout', {
>   redirectTo: '/restxq/logout'
> });
> }])
> 
>   .controller('LoginCtrl', [
> '$scope', '$http', '$location',
> function ($scope, $http, $location) {
>   $scope.login = function() {
> var url = '/restxq/api/login/check';
> 
>//use jquery here, because angular does not detect auto-fill data
> var payload = {
>   u: $('#u').val(),
>   p: $('#p').val()
> };
> 
> $http.post(url, payload).
> success(function(data) {
>   if (data.error) {
>   // trigger error status
> $scope.loginForm.$error.failed = true;
>   } else {
>   // redirect
> window.location.pathname = data.url;
>   }
> }).
> error(function(data, status, headers, config) {
>   alert("Could not load data from server.")
> });
>   };
>   }]);
> 
>  
> 
> Please Login
> 
>   
> 
>   Incorrect login data. Please try again.
> 
>   
>   
> 
>   
> Username  
>  style="width:146px !important;margin:0"/>
>   
>   
> Password   
>  style="width:146px !important;margin:0" type="password" />
>   
>   
> 
>  style="width:152px !important;margin:0">Login
> 
>   
> 
> 
>   
> 
> 
> 
>  Regards,
> 
> Max
> 
> 
> 
> 
> 2014-05-07 1:38 GMT+02:00 Yoann Maingon :
>> Hi,
>>
>> After xmlprague and my presentation at the BaseX user group I was told (and
>> I agree) that it wasn't really smart to use php for what I was building as
>> it had almost no added value as I could directly query basex using the Rest
>> Interface.
>>
>> Does anyone as some example using either angularjs or jquery ? I think I'm
>> struggling with the login. Even just trying with a Rest test tool, I can see
>> that I have error messages in Basex telling me theat access was refused.
>>
>>
>> Yoann Maingon
>> CEO - mydatalinx
>> +33664324966

-- 
Dirk Kirsten, BaseX GmbH, http://basex.org
|-- Firmensitz: Blarerstrasse 56, 78462 Konstanz
|-- Registergericht Freiburg, HRB: 708285, Geschäftsführer:
|   Dr. Christian Grün, Dr. Alexander Holupirek, Michael Seiferle
`-- Phone: 0049 7531 28 28 676, Fax: 0049 7531 20 05 22


Re: [basex-talk] Rest Access from javascript using AngularJs

2014-05-07 Thread Maximilian Gärber
Hi Yoann,

I guess having examples like these would be helpful in general.
Together with basex, we built a larger project for managing conference
registrations etc. last year. I could extract some of the modules -
maybe we could manage to publish them on some github repo or a
dedicated site? @basex: maybe it is time for a basex contrib page?

What you need, is some json endpoint which leverages the session
module, checks the credentials and returns some json back to Angular
(or JQuey)

Besides that, you need to secure all your restxq endpoints with a
authentication check:

   if(not(session:logged-in())) then web:redirect($C:START-PAGE) else
_:do-something-useful()


Login example:


import module namespace session = "http://basex.org/modules/web/session";;

declare
  %restxq:path("/api/login/check")
  %restxq:POST("{$content}")
  %output:method("json")
  %output:json("lax=yes")
  function _:check(
$content as item()*
  )
{
  let $user := $content//u/string()
  let $pass := $content//p/string()

  let $ok := _:check-user($user, $pass)

if ($ok) then
  let $user-id := session:id()
  let $role:= session:role()
  return((),
  
  {_:redirect-url-from-role($role)}

   )
   else
   
Login failed.
  
};


angular.module('login', [])
  .config([
  '$routeProvider',
  function ($routeProvider) {
$routeProvider.when('/Logout', {
  redirectTo: '/restxq/logout'
});
}])

  .controller('LoginCtrl', [
'$scope', '$http', '$location',
function ($scope, $http, $location) {
  $scope.login = function() {
var url = '/restxq/api/login/check';

   //use jquery here, because angular does not detect auto-fill data
var payload = {
  u: $('#u').val(),
  p: $('#p').val()
};

$http.post(url, payload).
success(function(data) {
  if (data.error) {
  // trigger error status
$scope.loginForm.$error.failed = true;
  } else {
  // redirect
window.location.pathname = data.url;
  }
}).
error(function(data, status, headers, config) {
  alert("Could not load data from server.")
});
  };
  }]);

 

Please Login

  

  Incorrect login data. Please try again.

  
  

  
Username  

  
  
Password   

  
  

Login

  


  



 Regards,

Max




2014-05-07 1:38 GMT+02:00 Yoann Maingon :
> Hi,
>
> After xmlprague and my presentation at the BaseX user group I was told (and
> I agree) that it wasn't really smart to use php for what I was building as
> it had almost no added value as I could directly query basex using the Rest
> Interface.
>
> Does anyone as some example using either angularjs or jquery ? I think I'm
> struggling with the login. Even just trying with a Rest test tool, I can see
> that I have error messages in Basex telling me theat access was refused.
>
>
> Yoann Maingon
> CEO - mydatalinx
> +33664324966


Re: [basex-talk] Rest Access from javascript using AngularJs

2014-05-07 Thread Marco Lettere

Hi Yoann,
we had written an example about two years ago when we were using 
Openlaszlo (RIP) as GUI tool so my example is in the framework's code.
I think it is rather understandable and easily portable to JQuery or any 
othe AJAX tk.


Following the method for building and sending the request in our OL AJAX 
class. It sets the src (URI) of the request, the content (with 
corresponding XML mime type header) taken from a OL dataset and the adds 
an Authorzation header to the request. The authorization is Basic and is 
retrieved from a "connectform" widget where the user inserts its 
credentials.



this.setAttribute("src", connectform.getURL())
this.setHeader("Authorization", connectform.getAuth())
if(xmldata != null){
this.setHeader("Content-Type", "application/xml");
this.setAttribute('postbody', xmldata);
}

this.doAJAXRequest()


This is the connectform.getAuth() method that builds the content of the 
Basic Authentication Header.



return "Basic " + b64.encode(this.userfield.getText() + ":" 
+ this.passwordfield.getText())




Hope this helps.
Regards,
Marco.

On 05/07/2014 01:38 AM, Yoann Maingon wrote:

Hi,

After xmlprague and my presentation at the BaseX user group I was told 
(and I agree) that it wasn't really smart to use php for what I was 
building as it had almost no added value as I could directly query 
basex using the Rest Interface.


Does anyone as some example using either angularjs or jquery ? I think 
I'm struggling with the login. Even just trying with a Rest test tool, 
I can see that I have error messages in Basex telling me theat access 
was refused.



Yoann Maingon
CEO - mydatalinx
+33664324966




[basex-talk] Rest Access from javascript using AngularJs

2014-05-06 Thread Yoann Maingon
Hi,

After xmlprague and my presentation at the BaseX user group I was told (and
I agree) that it wasn't really smart to use php for what I was building as
it had almost no added value as I could directly query basex using the Rest
Interface.

Does anyone as some example using either angularjs or jquery ? I think I'm
struggling with the login. Even just trying with a Rest test tool, I can
see that I have error messages in Basex telling me theat access was refused.


Yoann Maingon
CEO - mydatalinx
+33664324966