Search in sources :

Example 1 with Page

use of net.n2oapp.framework.api.metadata.meta.page.Page in project n2o-framework by i-novus-llc.

the class OpenPageCompileTest method dynamicPage.

@Test
public void dynamicPage() {
    SimplePage page = (SimplePage) compile("net/n2oapp/framework/config/metadata/compile/action/testOpenPageDynamicPage.page.xml").get(new PageContext("testOpenPageDynamicPage", "/page"));
    PageContext context = (PageContext) route("/page/testOpenPageSimplePageAction1/id1", Page.class);
    DataSet data = new DataSet();
    data.put("page_test_id", "testOpenPageSimplePageAction1");
    SimplePage openPage = (SimplePage) read().compile().bind().get(context, data);
    assertThat(openPage.getBreadcrumb().size(), is(2));
    assertThat(openPage.getBreadcrumb().get(0).getLabel(), is("first"));
    assertThat(openPage.getBreadcrumb().get(1).getLabel(), is("second"));
    assertThat(openPage.getWidget().getId(), is("page_testOpenPageSimplePageAction1_id1_main"));
    assertThat(openPage.getRoutes().getList().get(0).getPath(), is("/page/testOpenPageSimplePageAction1/id1"));
    assertThat(openPage.getWidget(), instanceOf(Form.class));
    context = (PageContext) route("/page/testOpenPageSimplePageAction2/id1", Page.class);
    data = new DataSet();
    data.put("page_test_id", "testOpenPageSimplePageAction2");
    openPage = (SimplePage) read().compile().bind().get(context, data);
    assertThat(openPage.getBreadcrumb().size(), is(2));
    assertThat(openPage.getBreadcrumb().get(0).getLabel(), is("first"));
    assertThat(openPage.getBreadcrumb().get(1).getLabel(), is("second2"));
    assertThat(openPage.getWidget().getId(), is("page_testOpenPageSimplePageAction2_id1_main"));
    assertThat(openPage.getRoutes().getList().get(0).getPath(), is("/page/testOpenPageSimplePageAction2/id1"));
    assertThat(openPage.getWidget(), instanceOf(Form.class));
}
Also used : DataSet(net.n2oapp.criteria.dataset.DataSet) Form(net.n2oapp.framework.api.metadata.meta.widget.form.Form) SimplePage(net.n2oapp.framework.api.metadata.meta.page.SimplePage) PageContext(net.n2oapp.framework.config.metadata.compile.context.PageContext) Page(net.n2oapp.framework.api.metadata.meta.page.Page) SimplePage(net.n2oapp.framework.api.metadata.meta.page.SimplePage) StandardPage(net.n2oapp.framework.api.metadata.meta.page.StandardPage) Test(org.junit.Test)

Example 2 with Page

use of net.n2oapp.framework.api.metadata.meta.page.Page in project n2o-framework by i-novus-llc.

the class OpenPageCompileTest method breadcrumb.

@Test
public void breadcrumb() {
    // проверка breadcrumb при открытии open-page из таблицы
    DataSet data = new DataSet().add("parent_id", 123);
    PageContext context = new PageContext("testOpenPageSimplePage", "/page/:parent_id/view");
    context.setBreadcrumbs(Collections.singletonList(new Breadcrumb("parent", "/page/:parent_id")));
    Page page = compile("net/n2oapp/framework/config/metadata/compile/action/testOpenPageSimplePage.page.xml").bind().get(context, data);
    assertThat(page.getRoutes().findRouteByUrl("/page/123/view"), notNullValue());
    Page createPage = routeAndGet("/page/123/view/action1", Page.class);
    assertThat(createPage.getRoutes().findRouteByUrl("/page/123/view/action1"), notNullValue());
    assertThat(createPage.getBreadcrumb().size(), is(3));
    assertThat(createPage.getBreadcrumb().get(0).getLabel(), is("parent"));
    assertThat(createPage.getBreadcrumb().get(0).getPath(), is("/page/123"));
    assertThat(createPage.getBreadcrumb().get(1).getLabel(), is("first"));
    assertThat(createPage.getBreadcrumb().get(1).getPath(), is("/page/123/view"));
    assertThat(createPage.getBreadcrumb().get(2).getLabel(), is("second"));
    assertThat(createPage.getBreadcrumb().get(2).getPath(), nullValue());
    Page updatePage = routeAndGet("/page/123/view/456/action2", Page.class);
    assertThat(updatePage.getRoutes().findRouteByUrl("/page/123/view/456/action2"), notNullValue());
    assertThat(updatePage.getBreadcrumb().size(), is(3));
    assertThat(updatePage.getBreadcrumb().get(0).getLabel(), is("parent"));
    assertThat(updatePage.getBreadcrumb().get(0).getPath(), is("/page/123"));
    assertThat(updatePage.getBreadcrumb().get(1).getLabel(), is("first"));
    assertThat(updatePage.getBreadcrumb().get(1).getPath(), is("/page/123/view"));
    assertThat(updatePage.getBreadcrumb().get(2).getLabel(), is("second"));
    assertThat(updatePage.getBreadcrumb().get(2).getPath(), nullValue());
    HashMap<String, String[]> params = new HashMap<>();
    data.put("name", "ivan");
    data.put("secondName", "ivanov");
    Page masterDetailPage = routeAndGet("/page/123/view/456/masterDetail", Page.class, params);
    assertThat(masterDetailPage.getRoutes().findRouteByUrl("/page/123/view/456/masterDetail"), notNullValue());
    assertThat(masterDetailPage.getBreadcrumb().size(), is(3));
    assertThat(masterDetailPage.getBreadcrumb().get(0).getLabel(), is("parent"));
    assertThat(masterDetailPage.getBreadcrumb().get(0).getPath(), is("/page/123"));
    assertThat(masterDetailPage.getBreadcrumb().get(1).getLabel(), is("first"));
    assertThat(masterDetailPage.getBreadcrumb().get(1).getPath(), is("/page/123/view"));
    assertThat(masterDetailPage.getBreadcrumb().get(2).getLabel(), is("second"));
    assertThat(masterDetailPage.getBreadcrumb().get(2).getPath(), nullValue());
    Page level3Page = routeAndGet("/page/123/view/456/masterDetail/level3", Page.class, params);
    assertThat(level3Page.getBreadcrumb().size(), is(4));
    assertThat(level3Page.getBreadcrumb().get(0).getLabel(), is("parent"));
    assertThat(level3Page.getBreadcrumb().get(0).getPath(), is("/page/123"));
    assertThat(level3Page.getBreadcrumb().get(1).getLabel(), is("first"));
    assertThat(level3Page.getBreadcrumb().get(1).getPath(), is("/page/123/view"));
    assertThat(level3Page.getBreadcrumb().get(2).getLabel(), is("second"));
    assertThat(level3Page.getBreadcrumb().get(2).getPath(), is("/page/123/view/456/masterDetail?name=:name&surname=:surname&secondName=test"));
    // проверка breadcrumb при открытии open-page не из таблицы, а другого виджета
    // при этом в parentId не должны сохраняться id выбранных записей
    context = new PageContext("testOpenPageSimplePage2", "/page/:parent_id/view2");
    context.setBreadcrumbs(Collections.singletonList(new Breadcrumb("parent", "/page/:parent_id")));
    Page page2 = compile("net/n2oapp/framework/config/metadata/compile/action/testOpenPageSimplePage2.page.xml").bind().get(context, data);
    assertThat(page2.getRoutes().findRouteByUrl("/page/123/view2"), notNullValue());
    updatePage = routeAndGet("/page/123/view2/456/action2", Page.class);
    assertThat(updatePage.getRoutes().findRouteByUrl("/page/123/view2/456/action2"), notNullValue());
    assertThat(updatePage.getBreadcrumb().size(), is(3));
    assertThat(updatePage.getBreadcrumb().get(0).getLabel(), is("parent"));
    assertThat(updatePage.getBreadcrumb().get(0).getPath(), is("/page/123"));
    assertThat(updatePage.getBreadcrumb().get(1).getLabel(), is("first"));
    // не содержит :page_test_id
    assertThat(updatePage.getBreadcrumb().get(1).getPath(), is("/page/123/view2"));
    assertThat(updatePage.getBreadcrumb().get(2).getLabel(), is("second"));
    assertThat(updatePage.getBreadcrumb().get(2).getPath(), nullValue());
}
Also used : DataSet(net.n2oapp.criteria.dataset.DataSet) HashMap(java.util.HashMap) PageContext(net.n2oapp.framework.config.metadata.compile.context.PageContext) Breadcrumb(net.n2oapp.framework.api.metadata.meta.Breadcrumb) Page(net.n2oapp.framework.api.metadata.meta.page.Page) SimplePage(net.n2oapp.framework.api.metadata.meta.page.SimplePage) StandardPage(net.n2oapp.framework.api.metadata.meta.page.StandardPage) Test(org.junit.Test)

Example 3 with Page

use of net.n2oapp.framework.api.metadata.meta.page.Page in project n2o-framework by i-novus-llc.

the class ShowModalCompileTest method updateWithPreFilters.

@Test
public void updateWithPreFilters() {
    PageContext pageContext = new PageContext("testShowModalRootPage", "/p");
    Page rootPage = compile("net/n2oapp/framework/config/metadata/compile/action/testShowModalRootPage.page.xml").get(pageContext);
    PageContext modalContext = (PageContext) route("/p/123/updateWithPrefilters", Page.class);
    assertThat(modalContext.getSourceId(null), is("testShowModalPage"));
    assertThat(modalContext.getDatasources().size(), is(1));
    assertThat(modalContext.getDatasources().get(0).getDefaultValuesMode(), is(DefaultValuesMode.query));
    N2oPreFilter[] filters = modalContext.getDatasources().get(0).getFilters();
    assertThat(filters.length, is(1));
    assertThat(filters[0].getDatasource(), is("main"));
    assertThat(filters[0].getRefPageId(), is("p"));
    assertThat(filters[0].getFieldId(), is(N2oQuery.Field.PK));
    assertThat(filters[0].getType(), is(FilterType.eq));
    assertThat(filters[0].getModel(), is(ReduxModel.resolve));
    assertThat(filters[0].getValue(), is("{id}"));
    SimplePage modalPage = (SimplePage) read().compile().get(modalContext);
    assertThat(modalPage.getId(), is("p_updateWithPrefilters"));
    assertThat(modalPage.getBreadcrumb(), nullValue());
    Widget modalWidget = modalPage.getWidget();
    Datasource ds = modalPage.getDatasources().get(modalWidget.getDatasource());
    assertThat(ds.getProvider().getPathMapping().get("id").getBindLink(), is("models.resolve['p_main']"));
    assertThat(ds.getProvider().getPathMapping().get("id").getValue(), is("`id`"));
    assertThat(ds.getProvider().getQueryMapping().get("name").getBindLink(), is("models.filter['p_second']"));
    assertThat(ds.getProvider().getQueryMapping().get("name").getValue(), is("`name`"));
    assertThat(ds.getDefaultValuesMode(), is(DefaultValuesMode.query));
    List<AbstractButton> buttons = modalPage.getToolbar().get("bottomRight").get(0).getButtons();
    assertThat(buttons.size(), is(2));
    assertThat(buttons.get(0).getId(), is("submit"));
    assertThat(buttons.get(0).getAction(), notNullValue());
    assertThat(buttons.get(1).getId(), is("close"));
    assertThat(buttons.get(1).getAction(), notNullValue());
    InvokeAction submit = (InvokeAction) modalPage.getToolbar().getButton("submit").getAction();
    assertThat(submit.getMeta().getSuccess().getRefresh().getDatasources(), hasItem("p_main"));
    assertThat(submit.getMeta().getSuccess().getModalsToClose(), is(1));
    assertThat(submit.getPayload().getDataProvider().getUrl(), is("n2o/data/p/:id/updateWithPrefilters/submit"));
    ActionContext submitContext = (ActionContext) route("/p/:id/updateWithPrefilters/submit", CompiledObject.class);
    assertThat(submitContext.getSourceId(null), is("testShowModal"));
    assertThat(submitContext.getOperationId(), is("update"));
    assertThat(submitContext.getOperationId(), is("update"));
    DataSet data = new DataSet();
    data.put("id", 222);
    modalPage = (SimplePage) read().compile().bind().get(modalContext, data);
    assertThat(modalPage.getDatasources().get(modalPage.getWidget().getDatasource()).getProvider().getUrl(), is("n2o/data/p/222/updateWithPrefilters/modal"));
    submit = (InvokeAction) modalPage.getToolbar().getButton("submit").getAction();
    assertThat(submit.getPayload().getDataProvider().getPathMapping(), not(hasKey("p_main_id")));
}
Also used : Datasource(net.n2oapp.framework.api.metadata.datasource.Datasource) AbstractButton(net.n2oapp.framework.api.metadata.meta.widget.toolbar.AbstractButton) DataSet(net.n2oapp.criteria.dataset.DataSet) CompiledObject(net.n2oapp.framework.api.metadata.local.CompiledObject) Widget(net.n2oapp.framework.api.metadata.meta.widget.Widget) Page(net.n2oapp.framework.api.metadata.meta.page.Page) StandardPage(net.n2oapp.framework.api.metadata.meta.page.StandardPage) SimplePage(net.n2oapp.framework.api.metadata.meta.page.SimplePage) ActionContext(net.n2oapp.framework.config.metadata.compile.context.ActionContext) InvokeAction(net.n2oapp.framework.api.metadata.meta.action.invoke.InvokeAction) PageContext(net.n2oapp.framework.config.metadata.compile.context.PageContext) SimplePage(net.n2oapp.framework.api.metadata.meta.page.SimplePage) N2oPreFilter(net.n2oapp.framework.api.metadata.global.dao.N2oPreFilter) Test(org.junit.Test)

Example 4 with Page

use of net.n2oapp.framework.api.metadata.meta.page.Page in project n2o-framework by i-novus-llc.

the class ShowModalCompileTest method copyActionWithTwoWidgetWithoutCopyAttributes.

@Test
public void copyActionWithTwoWidgetWithoutCopyAttributes() {
    Page rootPage = compile("net/n2oapp/framework/config/metadata/compile/action/testShowModalCopyActionWithTwoWidgetDefault.page.xml").get(new PageContext("testShowModalCopyActionWithTwoWidgetDefault"));
    PageContext modalContext = (PageContext) route("/testShowModalCopyActionWithTwoWidgetDefault/123/update", Page.class);
    StandardPage modalPage = (StandardPage) read().compile().get(modalContext);
    CopyAction submit = (CopyAction) modalPage.getToolbar().getButton("submit").getAction();
    assertThat(submit.getType(), is("n2o/models/COPY"));
    assertThat(submit.getPayload().getSource().getPrefix(), is(ReduxModel.resolve.getId()));
    assertThat(submit.getPayload().getSource().getKey(), is("testShowModalCopyActionWithTwoWidgetDefault_update_master"));
    assertThat(submit.getPayload().getSource().getField(), nullValue());
    assertThat(submit.getPayload().getTarget().getPrefix(), is(ReduxModel.edit.getId()));
    assertThat(submit.getPayload().getTarget().getKey(), is("testShowModalCopyActionWithTwoWidgetDefault_ignore_table"));
    assertThat(submit.getPayload().getTarget().getField(), is("dictionary.id"));
    assertThat(submit.getPayload().getMode(), is(CopyMode.replace));
    assertThat(submit.getMeta().getModalsToClose(), is(1));
    List<AbstractButton> buttons = modalPage.getToolbar().get("bottomRight").get(0).getButtons();
    assertThat(buttons.get(0).getId(), is("submit"));
    assertThat(buttons.get(0).getAction(), is(submit));
    assertThat(buttons.get(0).getLabel(), is("Выбрать"));
}
Also used : AbstractButton(net.n2oapp.framework.api.metadata.meta.widget.toolbar.AbstractButton) CopyAction(net.n2oapp.framework.api.metadata.meta.action.copy.CopyAction) Page(net.n2oapp.framework.api.metadata.meta.page.Page) StandardPage(net.n2oapp.framework.api.metadata.meta.page.StandardPage) SimplePage(net.n2oapp.framework.api.metadata.meta.page.SimplePage) PageContext(net.n2oapp.framework.config.metadata.compile.context.PageContext) StandardPage(net.n2oapp.framework.api.metadata.meta.page.StandardPage) Test(org.junit.Test)

Example 5 with Page

use of net.n2oapp.framework.api.metadata.meta.page.Page in project n2o-framework by i-novus-llc.

the class ShowModalCompileTest method testShowModalPreFilters.

/**
 * Проверяет, что show-modal pre-filters пробрасываются на модальную страницу
 */
@Test
public void testShowModalPreFilters() {
    PageContext pageContext = new PageContext("testShowModalPreFilters", "/p");
    compile("net/n2oapp/framework/config/metadata/compile/action/testShowModalPreFilters.page.xml").get(pageContext);
    SimplePage page = (SimplePage) routeAndGet("/p/create", Page.class);
    ClientDataProvider provider = page.getDatasources().get("p_create_modal").getProvider();
    assertThat(provider, notNullValue());
    assertThat(provider.getQueryMapping().get("modal_id").normalizeLink(), is("models.resolve['p_form'].id"));
    assertThat(provider.getQueryMapping().get("modal_name").getValue(), is(123));
}
Also used : ClientDataProvider(net.n2oapp.framework.api.metadata.meta.ClientDataProvider) PageContext(net.n2oapp.framework.config.metadata.compile.context.PageContext) SimplePage(net.n2oapp.framework.api.metadata.meta.page.SimplePage) Page(net.n2oapp.framework.api.metadata.meta.page.Page) StandardPage(net.n2oapp.framework.api.metadata.meta.page.StandardPage) SimplePage(net.n2oapp.framework.api.metadata.meta.page.SimplePage) Test(org.junit.Test)

Aggregations

Page (net.n2oapp.framework.api.metadata.meta.page.Page)64 Test (org.junit.Test)60 PageContext (net.n2oapp.framework.config.metadata.compile.context.PageContext)47 SimplePage (net.n2oapp.framework.api.metadata.meta.page.SimplePage)39 StandardPage (net.n2oapp.framework.api.metadata.meta.page.StandardPage)27 DataSet (net.n2oapp.criteria.dataset.DataSet)22 N2oEnvironment (net.n2oapp.framework.config.compile.pipeline.N2oEnvironment)10 ModelLink (net.n2oapp.framework.api.metadata.meta.ModelLink)9 AbstractButton (net.n2oapp.framework.api.metadata.meta.widget.toolbar.AbstractButton)8 CollectionPage (net.n2oapp.criteria.api.CollectionPage)7 InvokeAction (net.n2oapp.framework.api.metadata.meta.action.invoke.InvokeAction)7 N2oPage (net.n2oapp.framework.api.metadata.global.view.page.N2oPage)6 CompiledQuery (net.n2oapp.framework.api.metadata.local.CompiledQuery)6 LinkActionImpl (net.n2oapp.framework.api.metadata.meta.action.link.LinkActionImpl)6 DefaultValues (net.n2oapp.framework.api.metadata.meta.control.DefaultValues)6 CompiledObject (net.n2oapp.framework.api.metadata.local.CompiledObject)5 PageRoutes (net.n2oapp.framework.api.metadata.meta.page.PageRoutes)5 HashMap (java.util.HashMap)4 Datasource (net.n2oapp.framework.api.metadata.datasource.Datasource)4 N2oSimplePage (net.n2oapp.framework.api.metadata.global.view.page.N2oSimplePage)4