Serenity: Parameter passing

Created on 16 Mar 2018  路  16Comments  路  Source: serenity-is/Serenity

Can someone please tell me what can be used in ______Grid.ts instead of this.setEquality('someRowField',value) ? I need to pass a value ( say Project Id or Employee Id from the Project Edit Dialog or Employee Edit Dialog to dialog that opens when clicked on one of the tabs present in those Dialogs. I am planning on using this value in my own query I'm trying to write in MyListHandler.

Most helpful comment

Can't speak English, don't understand
Google Translate

All 16 comments

typescript

Object transfer

I use the constructor to pass

Can you be a bit more specific???

Can't speak English, don't understand
Google Translate

hi there. forgive me upfront i've misunderstood your question.
what I think you are asking is, how can I filter the values to be displayed in a Grid that is embedded in a dialog tab, using the values from another tab on the same dialog.

criteria are a more powerful option for filtering your data than simple setequality. you may find you don't even need to write your own query for MyListHandler as it can all be done using criteria in TS.
checkout the gridfilteredbycriteria example on the serenity demo and this should get you started in the right direction.

https://github.com/volkanceylan/Serene/blob/master/Serene/Serene.Web/Modules/BasicSamples/Grids/GridFilteredByCriteria/GridFilteredByCriteria.ts

if your projectId or employeeId are going to change once the dialog is open and you need the grid data to change for new values, then you may need to create a public method on the grid to accept the values and refresh the view.

HTH

Ts is generated according to cs, ts write query cs can generate sql?

instead of this.setEquality you can use request.Criteria

protected onViewSubmit(): boolean {
            if (!super.onViewSubmit()) {
                return false;
            }

            let request = this.view.params as Serenity.ListRequest;

            this.setEquality(fld.TypePayId, 1)

            if (!Authorization.hasPermission("ReadAllItems")) {
                request.Criteria = Serenity.Criteria.and(request.Criteria, Serenity.Criteria.or([[fld.UserId], '=', Authorization.userDefinition.UserId], [[fld.InsertUserId], '=', Authorization.userDefinition.UserId]));
            }

            return true;
        }

@Zahar661, thanks so much for replying on this.
It would really help me a lot if I could understand a little bit more about request.Criteria. Is there an example that I could refer to? I am very new to serenity platform and I am trying to get a hang of it.

I myself searched for examples for a long time, did not find it. Here the principle of SQL queries, Serenity.Criteria.and and Serenity.Criteria.or. But we must not forget about the fact that the above was filtration, etc. and write
request.Criteria = Serenity.Criteria.and(request.Criteria, your conditions );

Thanks @Zahar661. I have one question.
In ______Grid.ts file, we use this.setEquality('somefiled', value) to check whether the calue is equal to the value of 'someField'. Based on this equality condition the requires result is fetched and displayed in the dialog that opens when we click on a tab in the parent dialog.
The thing is I don't want to use the equality condition. that is, I don't want to compare 'value' which is entityId of the EditDialog that is open with 'someField' value of the other table.
I need to use this entityId for joining two or more tables. Do you know how can that be done? Or do you know any other examples I can refer to?
Someone suggested that I use : (this.view.params as ProjectListRequest).EmployeeId = value; instead of setEquality(). Any idea about how that works?

My English is bad. Do you want to merge at the grid level? If so, then LeftJoin in ....Row.cs to help you, or MasterDetal if in the dialog.

Yes, @Zahar661 . Here is a gist of what I need.
1) There is a table called Employees for which I ran Sergen. This created the basic screen where I can perform basic CRUD operations.
2) When I click on one of the rows, EmployeeDialog opens. I have added two tabs in this dialog. One of them is called as 'Projects'
3) What I need is to show all the projects this particular employee has ever worked on. to fetch all the project details, I need to join at least 3 tables. Two tables are joined based on EmployeeId (the Entity Id) of the row that I clicked on to fetch the project Ids of all the projects he has ever worked on. And the next step is to get other details of each of this projectIds (like Project name, client, etc).
4) I have created EmployeeProjectGrid.ts where I have declared a private variable that holds this EntityId value so that I can pass it to ListReposne and in turn to MyListHandler. This is where I have made use of this.SetEquality.
5) All I want is a way to pass this EntityId to ListHandler Service and use it in my own query.
6) I was just following one of the examples. So, I don't know whether I need setEquality() or is there another way in which I can achieve this.
since I am fairly new to this and I have a deadline to meet, I am not able to go through all the examples Volkan or others have put up. Do you have an idea how this can be achieved? If so, would you please help me out?

Look Notrwind->Customers tab Orders

@Zahar661, I have referred the same example. In that, customer and order tables have keys called as Customer ID based on which they are joined. So, they have made use of setEquality() and that works fine for that example. Anyway, thanks so much for replying. Please let me know if there are any other ways.

Serenity.Criteria can be used instead of setEquality()

protected onViewSubmit(): boolean {
            if (!super.onViewSubmit()) {
                return false;
            }
            let request = this.view.params as Serenity.ListRequest;
                request.Criteria = Serenity.Criteria.and(request.Criteria, [[fld.FieldName], '=', FieldValue]));
            return true;
        }

Thanks, @Zahar661 . Will try it out. :)

Closing due to inactivity.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kilroyFR picture kilroyFR  路  3Comments

StefanTheiner picture StefanTheiner  路  3Comments

Pinellus picture Pinellus  路  3Comments

Akarsh03 picture Akarsh03  路  3Comments

GitHubOrim picture GitHubOrim  路  3Comments