#1 Re: mORMot 1 » Mustache - accessing an element in an array by index » 2020-02-05 21:29:57

Thanks ab.

I am not using the latest version of Mormot, so I will update and try again.

Cheers.

Vernon.

#2 mORMot 1 » Mustache - accessing an element in an array by index » 2020-02-05 03:51:48

Joker
Replies: 2

Hi all,
Is it possible to access a particular element in an array by specifying it's index?

Take the array below ... I want to be able to access element 2 (i.e. the 2018 year in a zero based array).

Some general Mustache pages suggest to use syntax line this {{Report.2}}, but that doesn't seem to work.

Any ideas or suggestions would be greatly appreciated?

            "Report":
            [
                {
                    "ClassName": "TSQLBreederPerformanceLine",
                    "ID": 0,
                    "Year": 2020,
                    "Branded": 0,
                    "Breeders": 26672,
                    "BrandingRate": 0
                },
                {
                    "ClassName": "TSQLBreederPerformanceLine",
                    "ID": 0,
                    "Year": 2019,
                    "Branded": 10492,
                    "Breeders": 22577,
                    "BrandingRate": "46.4720733489835"
                },
                {
                    "ClassName": "TSQLBreederPerformanceLine",
                    "ID": 0,
                    "Year": 2018,
                    "Branded": 11273,
                    "Breeders": 22103,
                    "BrandingRate": "51.0021264081799"
                },
                {
                    "ClassName": "TSQLBreederPerformanceLine",
                    "ID": 0,
                    "Year": 2017,
                    "Branded": 10935,
                    "Breeders": 18961,
                    "BrandingRate": "57.671008913032"
                }
            ]


Cheers.

Vernon.

#3 Re: mORMot 1 » Mustache expression helper - accessing object properties » 2017-12-22 21:06:10

According to the documentation using a section should work - https://synopse.info/files/html/Synopse … #TITLE_509

I think the issue is that although the object is returned by the expression helper it does not become part of the data context, so can't be referenced.

It would be nice if it could, but it's not the end of the world.


... and can I just say that I think the Mormot framework is absolutely fantastic and I really love using it.

#4 Re: mORMot 1 » Mustache expression helper - accessing object properties » 2017-12-21 23:54:26

No the "product" JSON does not appear in the data context when I append /json ... however I would not expect it to either, as the the helper function gets called after the context has been generated.

#5 Re: mORMot 1 » Mustache expression helper - accessing object properties » 2017-12-21 22:11:40

So I tried something along the lines of what you suggested using the SynCrossPlatformREST TSQLRecord.ToVariant method eg Product.ToVariant.

So the GetProduct helper returns {"ID":2,"Name":"Product2","BarCode":"1234","ProductSize":5,"PurchUnits":2,"UseUnits":1}

And I have this {{#GetProduct ProductID}} {{Name}} {{/GetProduct}} in my web page, but it does not render the name.

#6 Re: mORMot 1 » Mustache expression helper - accessing object properties » 2017-12-21 21:28:36

Thanks for the response AB, but I don't think this will work for me.
I should probably expand a little on what I am doing as it will make more sense why I am actually doing this even though it is a little against Mustache "rules".

This is the layout of the "system":

SQLite DB --- App Server (interface based REST server) --- FMX App (uses MormotClient.pas)
                             |
                              ---- Web Server (MVC server also using MormotClient.pas to communicate with the App Server)


So as you can see the web server does not have direct access the the TSQLUserProduct, it uses the type defined in MormotClient.pas.
To expand a little further, the TSQLUserProduct is actually a property of another object TSQLPurchProduct, and I am actually passing the TSQLPurchProduct to the context, however I also need access to the TSQLUserProduct property.

Here is the code from the App Server

  TSQLPurchProduct = class(TSQLRecord)
  private
    fProductID : TSQLUserProduct;
    fOnHand  : double;
    fPurchDate : TDateTime;
    fPurchasedFrom : RawUTF8;
    fCost : double;
...
  published
    property ProductID : TSQLUserProduct read fProductID write fProductID;
    property PurchDate : TDateTime read fPurchDate write fPurchDate;
    property PurchasedFrom : RawUTF8 read fPurchasedFrom write fPurchasedFrom;
    property Cost : double read fCost write fCost;
  end;

Now here is the code on the web server, where I am having the difficulty. As you can see the ProductID is defined as a TID rather than a TSQLUserProduct.

  TSQLPurchProduct = class(TSQLRecord)
  protected
    fProductID: TID; 
    fOnHand: Double; 
    fPurchDate: TDateTime; 
    fPurchasedFrom: String; 
    fCost: Double; 
  published
    // defined as ProductID: TSQLUserProduct on the server
    property ProductID: TID read fProductID write fProductID;
    property OnHand: Double read fOnHand write fOnHand;
    property PurchDate: TDateTime read fPurchDate write fPurchDate;
    property PurchasedFrom: String read fPurchasedFrom write fPurchasedFrom;
    property Cost: Double read fCost write fCost;
  end;

#7 mORMot 1 » Mustache expression helper - accessing object properties » 2017-12-21 04:46:15

Joker
Replies: 7

Hi all,
I want to return an object via an expression helper and access properties of that object on the web page (rendered via Mustache). I don't know if it's supposed to work, but I certainly can't get it to work.

Below is an example of what I am trying to do.

Here is the object

  TSQLUserProduct = class(TSQLRecord)
  protected
    fName: String; 
    fBarCode: String; 
    fProductSize: Double; 
    fPurchUnits: TUseUnits; 
    fUseUnits: TUseUnits; 
  published
    property Name: String index 40 read fName write fName;
    property BarCode: String index 40 read fBarCode write fBarCode;
    property ProductSize: Double read fProductSize write fProductSize;
    property PurchUnits: TUseUnits read fPurchUnits write fPurchUnits;
    property UseUnits: TUseUnits read fUseUnits write fUseUnits;
  end;

The expression helper ...

procedure GetProduct (const Value: variant; out result: variant);
  var Product : TSQLUserProduct;
begin
  SetVariantNull(result);

  try
    .... get product based on ID ...
  
     _ObjAddProps (['Product', Product], Result);

   finally
    Product.Free;
  end;
end;

The web page ...

....

            <td>{{#GetProduct ProductID}}  {{Product.ProductSize}} {{Product.PurchUnits}} {{/GetProduct}}</td>

....

#8 Re: mORMot 1 » Multiple Controllers in an MVC Server » 2017-12-15 11:09:52

Excellent. Thanks guys.
It was easier than I thought.

#9 mORMot 1 » Multiple Controllers in an MVC Server » 2017-12-14 22:30:41

Joker
Replies: 7

Hi all,
Maybe I'm missing something simple here, but this is what I am trying to do ...

I have a rather complex MVC application and I want to have a different controller (TMVCApplication) for each different area of the application i.e. I don't want ALL the code in a single unit/TMVCApplication object, as it is getting a little cumbersome.

Is there an easy way to have a single server application but have multiple controllers and/or source files split along logical lines?

Thanks in advance.

Joker.

#10 mORMot 1 » Multiple Mormot based servers accessing the same SQLite database » 2017-09-29 00:24:24

Joker
Replies: 2

Hi all,
I'm after some advice here.

I have multiple servers, one a rest server and the other a MVC web server, developed using Mormot, that I want to access the same SQLite database i.e. these servers are currently running two separate processes/executables.

1. Is it safe to just allow them both to access the same SQL database?
2. Should I combine the servers into a single process/executable?
3. Should I use some other method to access the database, or use some other database engine?

Thanks in advance.

#11 Re: mORMot 1 » Turn MVC View Caching in DEBUG mode off » 2017-05-24 04:42:42

Thanks itSDS for that solution ... I was looking for a way to do that.

#12 Re: mORMot 1 » Is this possible with an MVC server? » 2017-05-16 04:48:55

Actually I found a better way to do this using the "/json" tag at the end of the URL. This means I can call the function without creating a new server and still use the authentication/cookie data as I would for normal page calls. Here is a quick example of the js function I call :

function resetpassword(client_id, user_name){
        $.post("/admin/resetpassword/json",
        {
          ClientID: client_id,
          UserName: user_name
        },
        function(data,status){
          if (data.ResetPasswordResult.Success)
            {
              document.getElementById("dialog_title").innerHTML = "Reset Password";
              document.getElementById("dialog_content").innerHTML = "Password reset successful";
              $("#ModalDialog").modal();
            }
          else
            {
              document.getElementById("dialog_title").innerHTML = "Reset Password FAILED!";
              document.getElementById("dialog_content").innerHTML = data.ResetPasswordResult.ErrMsg;
              $("#ModalDialog").modal();
            }
        })
        .fail(function() {
          document.getElementById("dialog_title").innerHTML = "Reset Password FAILED!";
          document.getElementById("dialog_content").innerHTML = "Unable to access server";
          $("#ModalDialog").modal();
        })
        ;
}

#13 Re: mORMot 1 » Is this possible with an MVC server? » 2017-05-16 01:31:47

Thanks ab. I might try option 2 and see how I go.

#14 mORMot 1 » Is this possible with an MVC server? » 2017-05-12 06:30:58

Joker
Replies: 6

Hi All,
I have an MVC server currently working well, however I want to be able to call services that don't return a page.

For example I have a page where an admin can reset a users password just by clicking a button. The page doesn't need to change (and I don't want it to change), however I may want to display a "dialog" to say that the password reset has been successful.

So my questions are:
1. Can I do this within the MVC framework?
2. If so, how?
3. If not, what are my other options?

Thanks in advance.

Joker.

#15 mORMot 1 » Cross Platform and TSQLRecordMany doesn't work » 2015-07-06 02:08:30

Joker
Replies: 0

Hi,
I'm trying to use the cross platform wrappers to generate wrappers to use with Smart Mobile Studio.
My project contains an class of type TSQLRecordMany (i.e. pivot table) and when I try and generate the wrappers I get an exception "Not enough RTTI for TMyClass".

Is there a way around this issue?

Thanks in advance.


Joker.

Board footer

Powered by FluxBB