Priority web SDK method getSubform returns parent form - priority-web-sdk

Parent form is the same I only change the company in the request and on some company i get parent form instead of sub form. So for example I have default company make a request get some form. According to user actions I change company in form request( but it is the same form name).
After that I try to get some sub form and on one particular company/form get the parent sub form instead of a child.
I already read topic about the problem that looks the same, but get rows and set active rows doesn't help me.
Do somebody had this problem?
async getDocuments(formName: string, getMappedRows: Function) {
const _currentOrderType = this.priorityService.getCurrentOrderType();
const _groupForm = await this.priorityService.getFormBridge(eSharedForm.GROUP.toString());
await _groupForm.setActiveRow(_currentOrderType.company.key);
const ListForm = await this.priorityService.getSubFormBridge(formName.toString(), _groupForm);
//some more logic
}
private async _getSubForm(name: string, form: any) {
try {
const subform = await form.startSubForm(name, this.onMessage, this.onUpdate);
debugger;
return subform;
} catch (e) {
this.subForms[name] = undefined;
const _e = JSON.stringify(e);
console.log(`[PriorityService::_getSubForm] Error starting subform '${name}': ${_e}`);
throw e;
}
}
and after that i see the same form as before

It is not clear from your code snippet what getSubFormBridge does or what is the value of _currentOrderType.company.key Is it numeric? is this the number of the row you want to retrieve?
When you start the Parent form, try to set autoRetrieveFirstRows to 1, which means, select the first row of the current form. If you know for sure what row you want to retrieve, pass the correct row number.
For example:
const form = await priority.formStart('ORDERS', this.onError, this.onSuccess, '', 1);
If you need to filter first and than select a row, use setActiveRow method and pass it the number of the row you want to retrieve. (Starts from 1)
Once the row is selected, retrieve the subform. For example:
const subform = await form.startSubForm("ORDERITEMS");

Related

Adding new line to top of Grid with data does not display prefilled values in non-editable columns (vaadin7)

Let's say I load data into a Grid. That works perfectly, everything is displayed. I can see it just fine, even after I call editItem(objectId); to edit data for any given line in the Grid.
Then let's say I have a button that adds a new line with mostly empty elements. In other words, the corresponding bean is mostly empty except for some default values. For some reason this behaves weird when I call editItem(objectId);. Here are the situations and their results:
If column is editable (column.setEditable(true);), my default data displays just fine
If column is not editable (column.setEditable(false);), my default data does NOT display. It is definitely in the bean, just not displayed. I see it once I click "Save" or "Cancel" in the edit form.
If I just show the line, do NOT enter the edit form (don't call editItem(objectId);), it display the default data just fine. I mention this just to point out what happens in the "display only" situation.
I even tried making the editField read only, and even that hid the data. So what is happening?
Example of data being displayed (see circled red):
Figure 1: Non-Empty data, but editable column
Example of data NOT being displayed (see circled red):
Figure 2: Empty data inside edit form
Figure 3: Non-Empty data after clicking save.
Note that it does not matter if the column is a ComboBox or just a regular text element, if I make it non-editable, it will not show the value I put in that column on this new line until after I click Save or Cancel.
Here is how I load the list of beans initially, where gridContainer is defined as BeanItemContainer<T> gridContainer:
public void updateList( List<T> dataList, T defaultData ) {
updateList( dataList, defaultData, new GridLoader<T>() {
#Override
public void loadGrid(List<T> dataList) {
gridContainer.removeAllItems();
if( dataList instanceof List && !dataList.isEmpty() )
gridContainer.addAll(dataList);
}
});
}
This works fine for non-editable columns, all data being displayed as expected. My pictures sort of hide it, but it is displaying just fine, and works in edit mode just fine as well.
And here is how I add a new line:
private void addRouting() {
Routing emptyData = Routing.create();
emptyData.setKey(null);
if( facilityId instanceof String && !facilityId.trim().isEmpty() )
emptyData.setFacilityId(facilityId.trim());
if(wmsItem instanceof String && !wmsItem.trim().isEmpty())
{
emptyData.setWmsItem(wmsItem);
// gridComponent.hideColumn("wmsItem", true);
// gridComponent.hideColumn("wmsItemDisplay", false);
}
else
{
// gridComponent.hideColumn("wmsItem", false);
// gridComponent.hideColumn("wmsItemDisplay", true);
}
if(workCenter instanceof String && !workCenter.trim().isEmpty())
{
emptyData.setWorkCenter(workCenter);
// gridComponent.hideColumn("workCenter", true);
// gridComponent.hideColumn("workCenterDisplay", false);
}
else
{
// gridComponent.hideColumn("workCenter", false);
// gridComponent.hideColumn("workCenterDisplay", true);
}
gridComponent.addItemAt(0, emptyData);
gridComponent.select(emptyData);
if(gridComponent.isEditorEnabled())
gridComponent.editItem(emptyData);
}
And in GridComponent, we have addItemAt defined as follows (BTW, GridComponent just wraps a layout with a toolbar at top and a Grid for the data, and so exposes various methods I need from the toolbar and Grid):
public BeanItem<T> addItemAt(int index, T bean) throws IllegalStateException {
BeanItemContainer<T> gridContainer = getGridContainer();
if(gridContainer instanceof BeanItemContainer)
{
/* Clear filter first because adding an item will break this.
* TODO: Maybe restore prior filter with "saveLastFilter();" and then "reapplyLastFilter();" after "add"
*/
saveLastFilter();
clearFilter();
BeanItem<T> newItem = gridContainer.addItemAt(index, bean);
reapplyLastFilter();
return newItem;
}
else
throw new IllegalStateException("Missing bean grid container");
}

How to best access data from QueryRenderer in a parent component in Relay Modern?

As you can see from the picture below, I'm rendering the popover using a react-relay QueryRenderer since the request is slow, and I do not want the rest of the page to wait for events to be fetched.
My problem is that in the navigation I have a button to show/hide the popover. That button should only be rendered when events has loaded, and the button also needs to show a count of how many events there is.
So my question is how to pass events data up from QueryRenderer (popover) to a parent component (toggle button)?
My first idea was to reuse my QueryRenderer for events and pass in dataFrom={'STORE_ONLY'}, to avoid a new HTTP request and use the cache instead, but unfortunately 'STORE_ONLY' is not an option... YET...
From looking at https://github.com/relay-tools/relay-hooks/issues/5 it seems like store-only will be supported by useQuery in the future, so is that the recommended solution to go about it, or how is the recommended way? Surely facebook, and many other applications, must have had this need frequently?
You can achieve redux-like relay store with custom handlers and local schema.
I'll be guessing what your queries, components and fields might be named like so don't forget to change it to correct values
Somewhere in project's src folder create a file ClientState.client.graphql to extend your root query type with new field for client state:
// ClientState.client.graphql
type ClientState {
showToggleButton: Boolean!
eventsCount: Int
}
extend type Query {
clientState: ClientState!
}
this will allow you to wrap Toggle button with fragment like this:
fragment ToggleButton_query on Query {
clientState {
showToggleButton
eventsCount
}
}
and spread this fragment in parent query (probably AppQuery)
Then in your second query, where you'll be fetching events, add #__clientField directive, to define custom handle for that field:
query EventModal {
events #__clientField(handle: "eventsData") {
totalCount
}
}
Create EventsDataHandler for handle eventsData:
// EventsDataHandler.js
// update method will be called every time when field with `#__clientField(handle: "eventsData")` is fetched
const EventsDataHandler = {
update (store, payload) {
const record = store.get(payload.dataID)
if (!record) {
return
}
// get "events" from record
const events = record.getLinkedRecord(payload.fieldKey)
// get events count and set client state values
const eventsCount = events.getValue('totalCount')
const clientState = store.getRoot().getLinkedRecord('clientState')
clientState.setValue(eventsCount, 'eventsCount')
clientState.setValue(true, 'showToggleButton')
// link "events" to record, so the "events" field in EventModal is not undefined
record.setLinkedRecord(events, payload.handleKey)
}
}
export default EventsDataHandler
Last thing to do is to assign custom (and default) handlers to environment and create init store values:
// environment.js
import { commitLocalUpdate, ConnectionHandler, Environment, RecordSource, Store, ViewerHandler } from 'relay-runtime'
import EventsDataHandler from './EventsDataHandler'
// ...
const handlerProvider = handle => {
switch (handle) {
case 'connection':
return ConnectionHandler
case 'viewer':
return ViewerHandler
case 'eventsData':
return EventsDataHandler
default:
throw new Error(`Handler for ${handle} not found.`)
}
}
const environment = new Environment({
network,
store,
handlerProvider
})
// set init client state values
commitLocalUpdate(environment, store => {
const FIELD_KEY = 'clientState'
const TYPENAME = 'ClientState'
const dataID = `client:${FIELD_KEY}`
const record = store.create(dataID, TYPENAME)
record.setValue(false, 'showToggleButton')
// prevent relay from removing client state
environment.retain({
dataID,
variables: {},
node: { selections: [] }
})
store.getRoot().setLinkedRecord(record, FIELD_KEY)
})

Updating list in view Asp.net mvc razor

I have 2 lists in a view. What I want to do is that pick elements from list1 and update list2 with selected elements everytime I pick one. I tried to use PartialView (I don't know if it's correct approach or not) but I failed. I have a function in controller that fills a list by selected items. What needs to be done is updating the view dynamically. Can you suggest me a roadmap for this?
Update
I forgot to say that I have done this with javascript. But I feel like it's the long way when it comes to some validations (checking duplications etc.)
$(document).ready(function (){
$("#allPlayersList a").on("click", function () {
var options = $(this).clone();
$("#thisWeekList").append(options);
});
});
Just create an html list. See if this link helps. https://codepen.io/alexander-holman/pen/QNQrvz. You can also populate the values from database
Then you can get the selected element by javascript like this
var input = document.getElementById('Something').value;
Update after edited question
You can try something like
var listSelection = document.getElementById('Something').value;
Now you can create an api in the backend which accepts this value and returns a list based on it. Call that Api like this
&.ajax({
url: //url of api
data: {exactNameOfApiParameter : listSelection },
success: function(data){
for (i = 0; i < data.length; i++) {
$('<li>', { text: data[i] }).appendTo($('#list2'));
}
}
})
Make sure that id of second list is list2.

MVC 4 #HTML.DropdownlistFor onchange event needs to send SelectedIndex value

I am using MVC 4 and have an #HTML.DropdownlistFor() which loads the rest of the page based on it's selection. On change of the listbox, I want to reload the page so that it load the correct data. As well there are two other parameters that are needed to load the page correctly.
In Create.cshtml view
#Html.DropDownListFor(model => model.SelectedMissionID, Model.MissionsToDisplay, new { onchange = "ReloadPage();" })
function ReloadPage() {
window.location = '#Html.Raw(Url.Action("CreateEdit", "DailyLog", new { ID = 1, ID2 = 0, dailyLogDate = Model.LogDate }))';
}
Where it says ID = 1, I want the selected index of the DropdownlistFor(SelectedMissionID), how do I get this?
I'm not sure if this is the best way to go to the controller, or if I should use a JQUERY .ajax post, is there a better way?
I seems something ideal for an ajax post.
What you have done is OK, inside the ReloadPage() function, just get the selected value in the DropDown, do the Ajax call passing the parameters, and in the success callback put your returned HTML in some container.
The idea is that you replace a part of your view with the return of your Ajax call, not all the page.
To get the selected value, using jQuery:
var selectedValue = $("select[name='SelectedMissionID']").val();
And that can be placed in your ReloadPage() function.
$.post( "your action URL", { ID: selectedValue, OtherParam: "xxxxx" })
.done(function( data ) {
alert( "Data Loaded: " + data );
//here you need to get the HTML, and put in a container
});

How to sort records (with code) in a grouped ListGrid?

This is the scenario: I'm working with a listgrid that needs to be grouped, and also needs to have its records ordered within each group. I've already used the ListGrid.sort() and the ListGrid.sort(String, SortDirection) methods but none of them works properly.
This problem doesn't show up when the grid isn't grouped (it makes the sort perfectly); and when the sort (with the listgrid is grouped) is made by clicking the column header, works fine but I need to sort it by code (without user interaction) because the header sort option needs to be disabled (and context menu too).
I'm using SmartGWT 4.0
Here is the class I'm using:
public class Access extends ListGrid {
public Access() {
super();
setWidth("30%");
setHeight100();
// setShowHeaderContextMenu(false);
setCanResizeFields(false);
// setCanSort(false);
setAutoFitWidthApproach(AutoFitWidthApproach.BOTH);
setWrapCells(true);
setFixedRecordHeights(false);
setShowRecordComponents(true);
setShowRecordComponentsByCell(true);
ListGridField id = new ListGridField("id", "ID");
ListGridField user = new ListGridField("user", "User");
ListGridField access = new ListGridField("access", "Access");
id.setHidden(true);
user.setWidth("60%");
access.setWidth("40%");
access.setType(ListGridFieldType.BOOLEAN);
access.setCanEdit(true);
setFields(id, user, access);
groupBy("access");
access.setGroupTitleRenderer(new GroupTitleRenderer() {
public String getGroupTitle(Object groupValue, GroupNode groupNode, ListGridField field, String fieldName,
ListGrid grid) {
return (String) groupValue + " - " + groupNode.getGroupMembers().length;
}
});
getField("access").setGroupValueFunction(new GroupValueFunction() {
public Object getGroupValue(Object value, ListGridRecord record, ListGridField field, String fieldName,
ListGrid grid) {
Boolean access = (Boolean) value;
if (access)
return "With access";
else
return "Without access";
}
});
ListGridRecord lgr1 = new ListGridRecord();
lgr1.setAttribute("id", 1);
lgr1.setAttribute("user", "ewgzx");
lgr1.setAttribute("access", true);
ListGridRecord lgr2 = new ListGridRecord();
lgr2.setAttribute("id", 2);
lgr2.setAttribute("user", "Bgfths");
lgr2.setAttribute("access", false);
ListGridRecord lgr3 = new ListGridRecord();
lgr3.setAttribute("id", 3);
lgr3.setAttribute("user", "utcvs");
lgr3.setAttribute("access", true);
ListGridRecord lgr4 = new ListGridRecord();
lgr4.setAttribute("id", 4);
lgr4.setAttribute("user", "gfdjxc");
lgr4.setAttribute("access", false);
ListGridRecord lgr5 = new ListGridRecord();
lgr5.setAttribute("id", 5);
lgr5.setAttribute("user", "763");
lgr5.setAttribute("access", true);
ListGridRecord lgr6 = new ListGridRecord();
lgr6.setAttribute("id", 6);
lgr6.setAttribute("user", "2");
lgr6.setAttribute("access", false);
ListGridRecord lgr7 = new ListGridRecord();
lgr7.setAttribute("id", 7);
lgr7.setAttribute("user", "35");
lgr7.setAttribute("access", false);
ListGridRecord lgr8 = new ListGridRecord();
lgr8.setAttribute("id", 8);
lgr8.setAttribute("user", "123");
lgr8.setAttribute("access", true);
ListGridRecord lgr9 = new ListGridRecord();
lgr9.setAttribute("id", 9);
lgr9.setAttribute("user", "2342");
lgr9.setAttribute("access", true);
ListGridRecord lgr10 = new ListGridRecord();
lgr10.setAttribute("id", 10);
lgr10.setAttribute("user", "aqwc");
lgr10.setAttribute("access", false);
setRecords(new ListGridRecord[] { lgr1, lgr2, lgr3, lgr4, lgr5, lgr6, lgr7, lgr8, lgr9, lgr10 });
sort("user", SortDirection.ASCENDING);
}
}
I have been having a similar issue. Disclaimer: if the "grouping data" message is not appearing when you group then the following solution may not help.
In my case the sorting of a grouped column was screwed because of the "grouping data" pop up.
Let me clarify.
The "grouping data" pop up appears when trying to group a ListGrid that is displaying more than 50 records.
It appears because the ListGrid, internally, is doing the grouping operation asynchronously to avoid the "script running slowly" message from the browser.
What I did was to set the grouping async threshold to a higher value. The risk of doing this is getting the "script running slowly" browser message, even though this is likely to happen only with IE8/9.
In the end , in the grid constructor, just add (I used 500 as a threshold):
setInitialSort(new SortSpecifier[] {new SortSpecifier("user", SortDirection.ASCENDING)}));
setGroupByField("access");
setGroupByAsyncThreshold(500);
Also set the initial sort and the grouped column as shown above.
PROGRAMMATICALLY, FIRST SORT, THEN GROUP.
Hope this helps.
This is due to sort() being called before rendering the grid, and setRecords() complicates things further.
Initial rendering of the grid happens along with its parents when rootCanvas.draw() is called (in onModuleLoad or similar).
As setRecords() can be used to change data set in the grid anytime, it tries to redraw the grid regardless of whether its initial stage or not.
If in the real scenario, sort is triggered after UI initialization, it should work as given in following code sample.
Remove the sort() call at the end of the constructor.
final Access access = new Access();
Button button = new Button("Sort");
button.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
// toggle sort direction, using two different ways to do it
SortSpecifier sortSpecifier = access.getSortSpecifier("user");
if (sortSpecifier == null || SortDirection.DESCENDING.equals(sortSpecifier.getSortDirection())) {
access.sort("user", SortDirection.ASCENDING);
} else {
access.setSort(new SortSpecifier[]{
new SortSpecifier("user", SortDirection.DESCENDING)
});
}
}
});
Check http://www.smartclient.com/smartgwt/showcase/#grid_multilevel_sort to see how to use listGrid.setInitialSort().
Having setRecords() in the constructor could lead to other initialization issues as well.
Update
To have the grid grouped by and sorted on load, set an initial sort and a group by field as indicated below.
// along with other configuration methods, can not use after grid is drawn
SortSpecifier sortSpecifier = new SortSpecifier("user", SortDirection.ASCENDING);
setInitialSort(new SortSpecifier[]{sortSpecifier});
// use following instead of groupBy(), which is used to group the grid programmatically
// groupBy() causes a redraw
setGroupByField("access");
An overloaded ListGrid.setGroupByField(String... field) method is available to group by multiple fields.

Resources