Aurelia - bind only once showing the title in repeater - aurelia

I have a list of users, every users have some roles. In aurelia html file I want to categorize the users. The incoming data has all the users chronologically by roles.
So basically, if the user has a role1, show section title ROLE1 and list those users, then show ROLE2 and list those users.
I tried to use this:
<p if.bind="user.role1">ROLE1</p>
<p if.bind="user.role2">ROLE2</p>
and here is my full code:
<template repeat.for="user of users">
<p if.bind="user.role1">ROLE1</p>
<p if.bind="user.role2">ROLE2</p>
<checkbox-input label="${user.name}" checked-value.two-way="user['selected']"></checkbox-input>
</template>
The problem is, that the titles ROLE1 or ROLE2 are showing above each user as this in a repeater, but I need to show them only once. I tried to use also if.bind.one-time but that works not.

Finally, I solved it different way - I used the same repeaters 2 times. The titles I put above the repeater and inside the checkboxes I used if.bind="user.role1" or role2 for the second one. This way it works, however I wanted to solve it easier, but finally this works.
<p>ROLE1</p>
<template repeat.for="user of users">
<checkbox-input if.bind="user.role1" label="${user.name}" checked-value.two-way="user['selected']"></checkbox-input>
</template>
<p>ROLE2</p>
<template repeat.for="user of users">
<checkbox-input if.bind="user.role2" label="${user.name}" checked-value.two-way="user['selected']"></checkbox-input>
</template>

Related

Display one object property value, and show another one on hover

the question I have might be hard to understand, so please help me re-organize the question if you can see the better way to put it in.
So, I am building a registration platform.
(1) First, I receive an array of objects of cases the user can sign time to.
(2) Each object consists of 2 properties, "name", "description".
(3) I store the array in the data, end use it in the element provided by a picker called "vue-multiselect", which basically accepts the array and loops over the objects and displays them.
(4) As you can see, it displays both properties and values, which I am trying to avoid. My question is, is it possible to pass only the "name" value into the picker, and display the description value when hovering the first value?
You can find this use case documentation here: https://vue-multiselect.js.org/#sub-custom-option-template
<multiselect v-model="value"
deselect-label=""
select-label=""
placeholder=""
selected-label=""
:show-pointer="true"
:options="projectCases">
<template slot="option" slot-scope="{ option }">
<strong :title="option.description">{{ option.name }}</strong>
</template>
</multiselect>
ps: I use title attribute to implement display-on-hover functionality. you can use any other tooltip library as well.

bootstrap-vue toggle expand table row

This seems to remain unanswered so here is another attempt at a solution.
Currently in bootstrap-vue, I am rendering a b-table. I would like to improve this by having the ability to select a row and collapse/expand an extra div/row/etc to show further information.
In the below snippet you will see what I am trying. The problem is that I can't seem to get the expanded data to span the number of columns in the table. I have tried adding <tr><td colspan="6"></td></tr> but it doesn't seem to span like I would expect. Any workarounds for this? Thanks.
<b-table
:items="case.cases"
:fields="tableFields"
head-variant="dark">
<template
slot="meta.status"
slot-scope="data">
<b-badge
v-b-toggle.collapse1
:variant="foobar"
tag="h6">
{{ data.value }}
</b-badge>
</template>
<template
slot="#id"
slot-scope="data">
<span
v-b-toggle.collapse1>
{{ data.value }}
</span>
<b-collapse id="collapse1">
Collapse contents Here
</b-collapse>
</template>
</b-table>`
Sounds like you could use the Row Details slot:
If you would optionally like to display additional record information (such as columns not specified in the fields definition array), you can use the scoped slot row-details
<b-table :items="case.cases" :fields="tableFields" head-variant="dark">
<template slot="meta.status" slot-scope="data">
<b-button #click="data.toggleDetails">
{{ data.value }}
</b-button>
</template>
<template slot="row-details" slot-scope="data">
<b-button #click="data.toggleDetails">
{{ data.detailsShowing ? 'Hide' : 'Show'}} Details }}
</b-button>
<div>
Details for row go here.
data.item contains the row's (item) record data
{{ data.item }}
</div>
</template>
</b-table>
There is a good example in the docs at https://bootstrap-vue.js.org/docs/components/table#row-details-support
I (think) I had the same issue, and I came up with a solution which leverages the filtering functionality of the bootstrap-vue <b-table> to achieve the effect of expanding and collapsing rows.
There's a minimal example in a JSFiddle here:
https://jsfiddle.net/adlaws/mk4128dg/
Basically you provide a tree structure for the table like this:
[
{
columnA: 'John', columnB:'Smith', columnC:'75',
children:
[
{ columnA: 'Mary', columnB:'Symes', columnC:'46' },
{ columnA: 'Stan', columnB:'Jones', columnC:'42' },
{ columnA: 'Pat', columnB:'Black', columnC:'38' },
]
}
]
The tree is then "flattened" out to rows which can be displayed in a table by the _flattenTreeStructure() method. During this process, the rows are also annotated with some extra properties to uniquely identify the row, store the depth of the row (used for indentation), the parent row of the row (if any) and whether or not the row is currently expanded.
Once this is done, the flattened structure can be handed to the <b-table> as it is just an array of rows - this is done via the computed property flattenedTree.
The main work now is done by the _filterFunction() method which provides custom filtering on the table. It works off the state of the expandedRowIndices property of the filterObj data item.
As the expand/collapse buttons are clicked, the row index (as populated during the flattening process) is inserted as a key into expandedRowIndices with a true or false indicating its current expanded state.
The _filterFunction() uses this to "filter out" rows which are not expanded, which results in the effect of expanding/collapsing a tree in the table.
OK, so it works (yay!), but...
it's not as flexible as the base <b-table>; if you want to show different columns of data, you'll need to do some work and to re-do the <template slot="???"> sections for the columns as required.
if you want to actually use filtering to filter the content (with a text search, for example) you'll need to extend the custom filter function to take this into account as well
sorting the data is not something I had to do for my use case, and I'm not sure how it would work in the context of a tree structure anyway - maintaining the tree's parent/child relationships while changing the order of the rows around would be... fun, and I suspect this would be a nice challenge to implement for someone who is not as time poor as me. ;)
Anyway, I hope this is of use to someone. I'm reasonably new to Vue.js, so there may be a better way to approach this, but it's done the job I needed to get done.

How to add limit on records of table in angular 2

This is the html where table structure is made with the help of helper components. As in BookingRow selector rowData is used as attribute and in
Booking I am getting the listing of booking. So it is showing 10 records.
I want to display only 5 record so how to do this in angular 2.
<div>
<div>
<h3>Today's Bookings</h3>
<div>
<table width="100%">
<thead BookingHeadings type="provider"></thead>
<tbody BookingRow pageType="provider dashboard" [rowData]="Bookings" pricingColumnStatus=false></tbody>
</table>
<div><a [routerLink]="['/provider/bookings/todays']">
<button type="button" value="View all">View All</button></a>
</div>
</div>
I guess your [rowData]=“Bookings“ is an Array. And I also guessing you get the Bookings from some kind of http service. So you can in the Success callback slice the Array.
var onlyFiveBookings=Bookings.slice(0,5); // for the first five.
I think a better way is to change it server side so that the response would only contain 5 bookings.

Selenium access a form field with bad id

Looking for the best approach to enter / read a value from a form field that lacks human readable ids / references.
The basic outline looks like
<div id="form-2143">
<div id="numberfield-1234">
<label id="numberfield-1234-label">
<span class="x-form-label">Field Name 1</span>
</label>
<div id="numberfield-1234-body">
<div id="numberfield-1234-wrap">
<input id="numberfield-1234-input" class="form-field" componentid="numberfield-1234">
</div>
</div>
</div>
...
</div>
There are more class defs and attributes involved, but above is the "basics" I have to work with.
This form has a number of entries, and there are more forms like it, so I am looking for a way to search for the label name, and access the input field within the same container.
I lack control of the site and cannot edit the HTML structure of the site; meaning I cannot give sensible names to the ids, but want to avoid hard referencing the poor names. Any suggestions on how to get Robot Framework & selenium to reference these elements?
Highlighting Andersson's answer in the comments
Using the XPath
//label[span[text()="Field Name 1"]]/following-sibling::div//input
Works for the above example.
The key part that answers the question of how to reference nearby elements is
/following-sibling

Breadcrumb microdata help

I'm trying to help Google generate appropriate breadcrumb details for my website. I am currently using this as the breadcrumb:
<div id="breadcrumb">
<span class="crust" itemscope="itemscope" itemtype="http://data-vocabulary.org/Breadcrumb">
<a href="http://www.radonsystems.net" class="crumb" rel="up" itemprop="url">
<span itemprop="title">Home</span>
</a>
<span class="arrow">
<span>»</span>
</span>
</span>
<span class="crust" itemscope="itemscope" itemtype="http://data-vocabulary.org/Breadcrumb">
<a href="http://www.radonsystems.net/business/profile.2" class="crumb" rel="up" itemprop="url">
<span itemprop="title">Business Profile</span>
</a>
</span>
</div>
However, this isn't helping Google at all, even the testing tool does not generate the breadrumb link, though it does see the microdata and correctly identifies it as breadcrumb microdata.
Any ideas?
Instead of using the microdata schemas at data-vocabulary.org, I would use the newer ones at http://schema.org which is the joint project by Google, Yahoo and Microsoft. It has a wider range of schemas to be more expressive with your data modeling.
In particular, the webpage schema is what you want for defined breadcrumb microdata.
http://www.schema.org/WebPage
What I did was to add a new column, in which numbers could be entered as format: 1,3,4. Then, I retrieved it from the database, exploded it into an array, and for each number, I'd retrieve information about that link id: url, text, then output it.
If you want to list your pages, you need to create a version that contains enough substance that should be sought.