Titanium return last three inserted collections - titanium

i just want to know hot to display only last three collections inserted in titanium ?
<View dataCollection="competence" dataFilter="filterFunction" height="Ti.UI.SIZE" layout="vertical" backgroundColor="gray" >
<Label backgroundColor='red' height="Ti.UI.SIZE" text="{date_debut}"/>
<Label backgroundColor='white' height="Ti.UI.SIZE" text="{date_fin}"/>
</View>
This display collections by 'ASC' from id order, my aim is only to show Three last elements.
I tried with dataFilter :
function filterFunction(collection){
// Underscore last method not working
return _.last(collection, 3);
}
Could you help me please ? thank you.

Try this
function filterFunction(collection){
return _.last(collection.models, 3);
}

Related

Cypress: get nested components using id in Next Js

I am going to write tests in cypress. The component which I going to test is below mentioned.
import Layout from "../../components/layout"
import ActionAreaCard from '../../components/card'
import Grid from '#mui/material/Grid';
export default function HomePage() {
return (
<Layout id='layout'>
<Grid container spacing={2}>
<Grid item xs={6}>
<ActionAreaCard
id='action-card-submit'
title='Submit Damage Report'
href="/view/data-submission"
imagePath='/assets/images/car-damage.jpg'
/>
</Grid>
<Grid item xs={6}>
<ActionAreaCard
id='action-card-view'
title='View Damage Reports'
href="/view/view-reports"
imagePath='/assets/images/damage-report.jpg' />
</Grid>
</Grid>
</Layout>
)
}
I need to test navigation after clicking 'ActionAreaCard'. I have done it so far as follows.
it('should navigate to the data submissions page', () => {
// Start from the index page
cy.visit('http://localhost:3000/')
// Find a button with an href attribute containing "/view/data-submission" and click it
cy.get('a[href*="/view/data-submission"]').click()
})
But I need to find the component by 'id'.
Why not use the id.
cy.get('#action-card-submit').click()
You can directly use the text to identify and click the element as well.
cy.contains('Submit Damage Report').click()
cy.contains('View Damage Reports').click()
You have a couple of options when searching by id
use the attribute syntax cy.get('id=["action-card-submit"]')
use shorthand cy.get('#action-card-submit'), but this can fail if special characters are in the id

Didn't display any option in dropdown ( autocomplete component) using cypress

I'm doing a test of an autocomplete component.
The problem is when I want to select an option from the dropdown, it shows me any option. When I did the test manually there are options but with cypress no. It worked and after no. I couldn't see the problem.
Does anyone know how to do it please?
(In cypress it didn't show any error)
Here the code of the autocomplete in js file
<Autocomplete
id={"name-label-" + label.customId}
options={options}
getOptionLabel={option => (option && option.name) ? option.name:''}
noOptionsText="No options"
renderInput={params => (
<TextField {...params} label="Select the name" fullWidth />
)}
data-cy="fichaSelectname"
onChange={(event, value) => handleOptionChange(event, value)}
value={option}
classes={classesAutocomplete}
/>
And here's the cypress code I used
cy.get('[data-cy=fichaSelectname]').click().type('{downarrow}').type('{enter}');
Did you try by selecting one element instead of just using the arrow buttons?
cy.get('[data-cy=fichaSelectname]').type('value{downarrow}{enter}');
Cypress did now show any stacktrace/error/info at all?
Well, first of all your code is wrong:
cy.get should be used like that: cy.get('[data-cy="fichaSelectname"]')
Try this.

How to pre populate the ImageField inside ImageInput in Edit Form, or the right approach to take

I am working with react-admin and in the functionality.. I need to display the original picture in an ImageField but if i choose to drag and drop a new picture then i need to update that ImageField with the new picture. I can't seem to see any examples of what would seem to be a pretty common use case for Image related Edit functionality..
<ImageInput source="src" label="Product Image" accept="image/*" >
<ImageField source="imageUrl"/>
</ImageInput>
Seems to be similar to this
question
but obviously i am new to this and after some frigging with it, i'm no closer to getting it to go... The behaviour i would have expected i guess was that because imageUrl does exist on the form, that the ImageField above would already be populated with the existing pic when the form opened but it's not because it's inside the .. If anyone could point me in the right direction it would be a big help
I have done it like this:
<ImageInput source="src" label="Billede" accept="image/*" mulitple={false}>
<ImageField source="thumbnail" title="title" />
</ImageInput>
<FormDataConsumer>
{({formData, dispatch, ...rest}) => {
if (!formData.src) {
return (
<div>
<Labeled label="Original image">
<ImageField source="thumbnail" {...rest}/>
</Labeled>
</div>
);
}
}}
</FormDataConsumer>
This will display the original image, as long as no new image is selected.
When a new image is selected, this will be displayed, and the original will be hidden.

RML Test of Page Number

Moin Moin,
I'm working on Openerp 7 and there pdf's get created with rml.
Problem is: I need Page Numbers, but just starting of the second Page.
I tried some rml if clause statements, but Page 1 gets printed all the time and the things that get printet are pretty wierd.
<header>
<pageTemplate id="second">
<frame id="second" x1="2.2cm" y1="2.5cm" width="16.9cm" height="22.3cm"/>
<pageGraphics>
<image file="images/isatech_water_header_medium.jpg" x="0.0cm" y="24.4cm" width="19.0cm" height="6.0cm"/>
<image file="images/isatech_water_footer.jpg" x="0.0cm" y="-0.5cm" width="16.9cm" height="2.6cm"/>
</pageGraphics>
</pageTemplate>
<pageTemplate id="first">
<frame id="first" x1="2.2cm" y1="2.5cm" width="16.9cm" height="22.3cm"/>
<pageGraphics>
<image file="images/isatech_water_header.jpg" x="0.0cm" y="24.4cm" width="19.0cm" height="6.0cm"/>
<image file="images/isatech_water_footer.jpg" x="0.0cm" y="-0.5cm" width="16.9cm" height="2.6cm"/>
[[ <pageNumber/> != '1' and <drawCentredString x="10cm" y="0.3cm"><pageNumber/></drawCentredString> ]]
</pageGraphics>
</pageTemplate>
</header>
What gets printed on the pdf is:
]] 1(2,3,...)
The pageTemplate second is for printing different header after page 1. I hope to get that straigt after the page numbers.
I really have no idea why the code behaves like he does. Different solutions are also welcome.
mfg Chris
I found a different way to do it.
It is not a good Idea to check the pageNumber in RML.
If I got it right, then the pageNumber is processed as one of the last steps. (Same goes for PageCount where it makes sense as you can't know the pageCount until the end of building your document)
Even if you call a python function with a pageNumber it gets handled as a String. I can just imagine it is the same reason.
I helped myself with a <setNextTemplate name="pageTemplate id"/>
Uncheck Add RML header in Settings > Actions > Reports > "Your Report"
Change your RML File and define the different pageTemplates
<template title="Sales Order" author="OpenERP S.A.(sales#openerp.com)" allowSplitting="20" showBoundary="0">
<pageTemplate id="first">
<frame id="first" x1="2.2cm" y1="2.5cm" width="16.9cm" height="22.3cm"/>
<pageGraphics>
<image file="images/header_page_1.jpg" x="0.8cm" y="24.7cm" width="16,9cm" height="4cm"/>
<image file="images/footer_page_1.jpg" x="0.4cm" y="-0.4cm" width="16.9cm" height="2.3cm"/>
</pageGraphics>
</pageTemplate>
<pageTemplate id="second">
<frame id="first" x1="2.2cm" y1="2.5cm" width="16.9cm" height="22.3cm"/>
<pageGraphics>
<image file="images/header_page_2.jpg" x="0.8cm" y="24.7cm" width="16,9cm" height="4cm"/>
<image file="images/header_page_2.jpg" x="0.4cm" y="-0.4cm" width="16.9cm" height="2.3cm"/>
</pageGraphics>
</pageTemplate>
Somewhere on page x add <setNextTemplate name="pageTemplate id"/>
or <setNextTemplate name="pageTemplate id"/>
<nextFrame/> to change the pageTemplate of page x+1
<setNextTemplate name="pageTemplate id"/> simply defines the pageTemplate of the next page and
<nextFrame/> additionaly end the current page.
Edit(Multi-Company-Header): I kind of forgot that we have multi Company Headers. Still I use this method. I just copy the .rml for every Company and hardcode the different company logos. Then in the reports setting page for every company(database) I specific the right .rml file.
I's very redundant, but I didn't found a better solution.
VG Chris

Appcelerator Titanium Alloy: How to set the TableViewStyle to GROUPED in xml

I've tried various things along the lines of (also tried just setting style to GROUPED):
<Alloy>
<Window title="Add Remember">
<TableView id="table" style="Ti.UI.iPhone.TableViewStyle.GROUPED">
<!-->
<TableViewSection headerTitle="Title">
<TableViewRow><TextField hintText="Title" id="title"></TextField></TableViewRow>
</TableViewSection>
<TableViewSection headerTitle="Location">
<TableViewRow><TextField hintText="Location" id="location"></TextField></TableViewRow>
</TableViewSection>
<TableViewSection headerTitle="Notes">
<TableViewRow><TextArea hintText="Notes"></TextArea></TableViewRow>
</TableViewSection>
</!-->
</TableView>
</Window>
</Alloy>
But no shebang.
I've also noticed that setting it programmatically in the controller file works, but only if I haven't added any sections or rows to the TableView yet (this is why the sections and rows are commented out above).
How do I set this property in the xml.
I do it this way:
In form.xml:
<TableView class="form">
...
</TableView>
In app.tss:
".form": {
style: Ti.UI.iPhone.TableViewStyle.GROUPED
}
Ok, the solution is to set style="1" in the xml for the TableView; this works with the sections and rows uncommented as well. I figured this out by logging Ti.UI.iPhone.TableViewStyle.GROUPED to the console; evidently the macro doesn't work in the xml.