Triply-Dev / YASGUI.YASQE-deprecated

Deprecated, see https://github.com/TriplyDB/Yasgui for the Yasgui monorepo
MIT License
73 stars 36 forks source link

How can we do for keep action on button execute #132

Closed art-tom closed 6 years ago

art-tom commented 6 years ago

Hello,

My subject : I use YASQE and I configure a auto-completion pluging with Gosparqled. And use Symfony 2.8 for my project

My question : The plug-in Yasqe is configure with the button execute and I have no control on this, the query is execute directly on sparql endpoint. But I want to keep the button and I retrieve the query when I click on. My purpose is generate method Ajax for example call controler symfony with the final query. I know how to get query but the action I don't know where she is.

I want a query for execute directly (with method PHP) on controler Symfony and send the result at yars.

Thank in advance,

wouterbeek commented 6 years ago

@art-tom Can you rephrase the title and description a bit? It is currently not so clear what your question is about. E.g., what is a controller in this context? And what do you mean with another endpoint; do you mean federation using a service clause?

art-tom commented 6 years ago

Hello @wouterbeek ,

Thank for the answer. I have explain my problem. It is more clear ?

Thank

art-tom commented 6 years ago

Hello,

Has you have an idea ?

Thank

LaurensRietveld commented 6 years ago

Hi @art-tom,

If I understand you correctly, you don't want to query a sparql endpoint via YASQE, but send a different (non-sparql) request to another API when a user is clicking the query button. To do so, you can overwrite the 'executeQuery' function of YASQE:

YASQE.executeQuery = function(yasqe, config) {
  console.log('Just pressed the query button. The current value is: ', yasqe.getValue());
  //YASQE.updateQueryButton(yasqe, "busy"); //Set the query button to loading status
  //YASQE.updateQueryButton(yasqe, "valid"); // Set the query button to non-loading and valid-query status
  //YASQE.updateQueryButton(yasqe, "error"); //set the query button to error status
  //YASQE.updateQueryButton(yasqe); //Automatically detect (based on the current query), whether the status is valid or invalid
}

Added, in comments, some functions you can use in the callback to your API to change the query button state according to the response you receive

art-tom commented 6 years ago

Hello,

Many thanks for answer.

I modified the method, but I have a last problem for fetch the result into yasr. My on yars is a tableau and it's not possible to change.

My function is : `YASQE.executeQuery = function(yasqe, config) {

            $.ajax({
                    url:       path,
                    type:       'post',
                    dataType:   'json',
                    async:      true,
                    data : {"request" : yasqe.getValue()},
                    success: function(data, status, response) {
                        yasr.setResponse({response: data});
                    },
                    error : function(xhr, textStatus, errorThrown) {
                    alert('Ajax request failed.');
                    }
            });
            }`

When I log the return I have a table on console {0: {…}, 1: {…}, 2: {…}, 3: {…}, 4: {…}, 5: {…}, 6: {…}, 7: {…}, 8: {…}, 9: {…}} 0 : {sub: {…}, pred: {…}, obj: {…}} 1 : {sub: {…}, pred: {…}, obj: {…}} 2 : {sub: {…}, pred: {…}, obj: {…}} 3 : {sub: {…}, pred: {…}, obj: {…}} 4 : {sub: {…}, pred: {…}, obj: {…}} 5 : {sub: {…}, pred: {…}, obj: {…}} 6 : {sub: {…}, pred: {…}, obj: {…}} 7 : {sub: {…}, pred: {…}, obj: {…}} 8 : {sub: {…}, pred: {…}, obj: {…}} 9 : {sub: {…}, pred: {…}, obj: {…}} __proto__ : Object

What is the type of return used with Yasqe ? Can you help me ?

Thanks in adavance

art-tom commented 6 years ago

And in my controller the code is :

if ($request->isXmlHttpRequest()) {
            $req = $request-> get('request');
            switch($req){
                case stripos($req, 'select') !== false:
                    $req = $this->deleteSelect($req);
                    $qb->select($req);
                    $result = $qb->getQuery()->execute();
                    return new JsonResponse(json_encode($result));
                break;

                case stripos($req, 'construct') !== false:
                    $req = $this->deleteConstruct($req);
                    $qb->construct($req);
                    $result = $qb->getQuery()->execute();
                    return new JsonResponse(json_encode($result));
                break;

                default :
                    return new Response(json_encode("Query is not authorize"));
                break;
            }
art-tom commented 6 years ago

@LaurensRietveld Ok I have change my code. On my controller use EasyRdf. But the probleme it's the same. I test to convert my result on string etc... I doesn't work. What is the format is return when we click on standard button execute ?

 if ($request->isXmlHttpRequest()) {
            $req = $request-> get('request');
            if( stripos($req, 'select') !== false || stripos($req, 'construct') !== false){
                $result = $sparql->query($req);
                return new Response(json_encode($result));
            }else{
                return new Response(json_encode("Query is not authorize"));
            }           
        } else {
            return new Response(json_encode("Erreur : Ce n'est pas une requette Ajax"),400);
        }
art-tom commented 6 years ago

Hello,

Sorry for my insisted. I have a question, it's possible to execute a normal function query with Yasqe bundle in my callback function Jquery.

I explain, when I retrieve my query in my control and check a differents think, I return the Query and in callback on success I call the method developped in Yasqe for execute query normaly and pass the result at yasr.

Like this :

yasqe.options.sparql.handlers.success =  function(data, status, response) {
    yasr.setResponse({response: data, contentType: response.getResponseHeader("Content-Type")});
};

And my function for example :

YASQE.executeQuery = function(yasqe, config) {    
    $.ajax({
            url: path, // initialize in index
            type: 'post',
            dataType: "json",
            data : {"request" : yasqe.getValue()},
            success: function(data, status, response) {
               **/// CALL NORMAL EXECUTION QUERY** 
            },
            error : function(xhr, textStatus, errorThrown) {
                yasr.setResponse({exception: textStatus, contentType: response.getResponseHeader("Content-Type")});
            },
            beforeSend: function(){
                YASQE.updateQueryButton(yasqe, "busy");
            },
            complete: function(){
                YASQE.updateQueryButton(yasqe);
            }

        });
}
art-tom commented 6 years ago

I find the solution. I save the original function and I call when I have need


` var _old = YASQE.executeQuery;
    YASQE.executeQuery = function(yasqe, config) {    
        $.ajax({
                url: path, // initialize in index
                type: 'post',
                dataType: "json",
                data : {"request" : yasqe.getValue()},
                success: function(data, status, response) {
    //               yasr.setResponse({response: data});
                   console.log(data);
                  // prototype.yasqe.query();
                  console.log(_old);
                   _old(yasqe,config);
                    //YASQE.executeQuery(yasqe.getValue());
                },
                error : function(xhr, textStatus, errorThrown) {
                    yasr.setResponse({exception: textStatus, contentType: response.getResponseHeader("Content-Type")});
                },
                beforeSend: function(){
                    YASQE.updateQueryButton(yasqe, "busy");
                },
                complete: function(){
                    YASQE.updateQueryButton(yasqe);
                }

            });
    }`