Meteor Easy-Search including two field names into autosuggest box - meteor

So I have an easy-search template as such:
{{> EasySearch.Autosuggest index=PlayersIndex labelField="Player" valueField="Team"}}
My index is defined as:
export const PlayersIndex = new Index({
collection: Stocks,
fields: ['Player', 'Team'],
engine: new MinimongoEngine(),
});
And I want the autosuggest box to display both the Player and the Team. Right now it just shows the Player. How can I achieve this?

You should first visit the autosuggest's documentation which is pretty short. From there it's pretty clear that only the first member of the fields array (in your case "Player") is chosen as the value to present when searching. To change this behavior you can pass a different template through the renderSuggestion parameter that EasySearch.Autosuggest seems to accept. By default it's using the
EasySearch_Autosuggest_DefaultRenderSuggestion template which you can find here. You can just create your own template in one of your files
<template name="playerTeamAuto">
<div>
<span class="autosuggest-title">
<span class="name">{{label}}</span>
<span class="teamName">{{doc.Team}}</span>
</span>
</div>
</template>
This will work only for your set of results where the returned documents would have a guranteed field of Team that's why we can access it through the doc variable. This comes from the object that the template is rendered with here on this specific line. As you can see it has all the data fields returned through the form of item, as even the label is gotten from there. I've added a between the player and team name, but you can format them any way you want.

Related

How can I translate input use ngx-translate?

<input type="text" name="title" [(ngModel)]="dataAdd.titleEN">
<input type="text" name="title" [(ngModel)]="dataAdd.titleFR">
I need to show two title but different language
If I click of button en show text in English or fr show text in French
and save in variable string
Note: I need unique variable for unique data insert in Firestore
dataAdd = {
titleEN: '',
titleFR: '',
}
this.translateList = this.afs.collection('translates');
this.translateList.doc('en').set({
TITLE_FOR_RENT: this.dataAdd.titleEN,
});
this.translateList = this.afs.collection('translates');
this.translateList.doc('fr').set({
TITLE_FOR_RENT: this.dataAdd.titleFR,
});
In my opinion you have assumed wrongly the usage of ngx-translate, this package is used in order to support multiple pre defined languages , for example if you want to support en and fr , beforehand you must have a .json file for each desired language, with the following KvP structure => where the key is a universal key (some string that is the same in each json file), which is used to map values to the translations from the .json files. You can check out the official StackBlitz Demo for detailed example of the usage.
In order to achieve the result that you described, I would suggest to use something like Cloud Translation API provided by Google, which is able to translate live user inputs (or whatever you pass to the API), after that depending on your strategy you might display the response from the API directly to the client, or load it first in the ngx-translate and then display it to the client.
Note:
I would go for the first option, because I assume in your case filling the browser memory is unnecessary (because when loading the translation trough in ngx-translate you are just feeling one big js object behind the scenes)

Adding fields dynamically to Share form

I want to add a text field for each file that is added to the attached package items in alfresco to write notes regarding each file, is it possible to do?
I have implemented something that could be reused for your use case.
You can define a property with multiple values that will contain the list of notes associated with each attachment.
There is a simple trick to post a property with multiple values: add "[]" to the name of the property. For example:
<input id="template_x002e_edit-metadata_x002e_edit-metadata_x0023_default_prop_someco_notes_0"
name="prop_someco_notes[]"
tabindex="0"
type="text"
value="Meeting minutes"
title="Notes"
noderef="workflow://...."
>
<input id="template_x002e_edit-metadata_x002e_edit-metadata_x0023_default_prop_someco_notes_1"
name="prop_someco_notes[]"
tabindex="1"
type="text"
value="Meeting minutes"
title="Notes"
noderef="workflow://...."
>
As you can see, the name of the input ends with []. Both input textfields have the same name.
The Alfresco Form Engine will consider these two inputs as the value for the property with multiple values: "someco:notes".
The bigger problem is that you need to generate this html with some smart javascript and free marker template.
You can write a custom free marker template to render the initial html: if a user opens a task on which documents have been already attached, you will need to generate the list of inputs using a custom control (you can of course start from textfield.ftl).
It won't be easy to generate the initial list because unfortunately Alfresco returns the list of values as a single comma separated value.
You can customise the webscript that injects the model in the free marker template "org.alfresco.web.scripts.forms.FormUIGet" to pass an array instead of a csv.
A quicker and dirtier solution is to split the csv value. In share-config-custom.xml, you can specify what textfield.ftl show use as a separator instead of the comma.
When a user adds/remove elements from the package, you can intercept the update and add/remove the correspondent note. Notice that I have added the filed "noderef" to each input so it is possible to know the relation between the notes and the nodes in the package.
UPDATE:
For the associations (used for example to define the package in a workflow task), Share uses a javascript library called "object finder" (or "object picker"). This library fires an event called "formValueChanged" that you can intercept:
YAHOO.Bubbling.fire("formValueChanged",
{
eventGroup: this,
addedItems: addedItems,
removedItems: removedItems,
selectedItems: selectedItems,
selectedItemsMetaData: Alfresco.util.deepCopy(this.selectedItems)
});

Meteor dynamic form generation

I have a survey form I would like an admin to be able to add more questions to on the fly. The way I'm thinking of doing this is to have the admin add questions to a Questions collection with several properties e.g:
{
"description" : "desc",
"fieldType" : "textField",
"sortOrder" : 1,
"dataType" : "text",
"_id" : "eFopP8XFgY8Br93fA"
}
and then on the client side, loop through these using an #each block and a dynamic template like so:
{{#each questions}}
{{>Template.dynamic template=fieldType}}
{{/each}}
Now the "fieldType" field would correspond to the name of a stored template e.g
<template name="textField">
<div>
<input id="{{_id}}" type="{{dataType}}" class="validate">
<label for="{{_id}}">{{description}}</label>
</div>
</template>
and inside these templates would have different input fields depending on the type.
I have two issues:
Is this a good way to go about this problem?
If it is, how would you be able to get the values of these input fields when saving the answers (as we don't know what fields could be there at compile time)
Regarding your first question, I agree with #Kyll regarding autoform and I think you can pass the schema as a json object dynamically.
Regarding your 2nd question, please check SO question Dynamically add form fields in meteorjs where you will find answer to your second question. You can easily grab value of all fields in your dynamically created form using .serializeArray() JQuery serializeArray

Sonata Admin Action Button to Pre Filtered List

I am rather new to Symfony (2 weeks) so forgive my ignorance.
I am trying to add a custom action button that will link to a pre filtered list of a RELATED entity. I have done a lot of research but can't quite seem to find what I need.
Currently I have two entities Books and Authors with a manyToOne relation ship.
I have these set up in Sonata Admin in the usual way and all works well. I even have an author filter on the book list page which I am hoping can be leveraged to accomplish my goal.
In the Author list view, I would like to add an action button on each row next to View and Edit, called "View Books By Author". I can get the button but fail to correctly build the URL.
I have 3 issues with the routing:
1) I am trying to use admin.generateObjectUrl() or similar in my button template to cleanly build an admin URL but can't get a path to an alternate entity. In my case, since I am currently viewing authors, the links always point to the author entity not books as I would like.
2) I am uncertain how to get the id of the current author in order to pass it to the filters
3) I am uncertain how to cleanly build the filter query string parameters. I could do it by hand if necessary: bookEntityListPath + "?filter[author][value][]=" + $authorID
But obviously this is not that clean and I would prefer a better method if possible.
Thanks in advance!!!
I had the same issue and started trying out some code when I could not find an answer. Using the path() twig method (route to path conversion) it is quite easy to create a link like that.
See this documentation: http://symfony.com/doc/current/book/routing.html#generating-urls-from-a-template
Your link would look something like this:
<a href="{{ path('admin_application_book_list', {
'filter[author][value]': object.id
}) }}" class="btn btn-small">
With 'admin_application_book_list' being the path to the list of books (bookEntityListPath?) and object.id being the id of your author (would have the name object in a detail or edit template of that entity)

Displaying Localized Vocabulary on Skin-based Folder Listing

I understand it's better to write browser view in a product, but want to know if there's any quick solution to the following task.
I have a custom Dexterity type with a cities field:
cities = schema.List(
title=_(u"Cities"),
value_type=schema.Choice(
vocabulary='cities',
required=False,
),
)
Values in the vocabularies.py look like:
SimpleTerm(value="NewYorkCity", title=_(u"New York City")),
Now I want utilize Skin-based template folder_listing.pt and add the following to display the cities values.
<tal:cities condition="item_obj/cities"
tal:repeat="city item_obj/cities">
<span tal:replace="city">Value</span>
<span class="separator" tal:condition="not:repeat/city/end">,</span>
</tal:cities>
It displays the results as NewYorkCity, but I really want is its translated title in Chinese, like 紐約市. If feasible, how can I meet this needs with template customization?
I think that you just need to use i18n:domain and i18n:translate :
<span i18n:domain="yourdomain" i18n:translate="" tal:replace="city">Value</span>
(see http://wiki.zope.org/zope3/ZPTInternationalizationSupport)

Resources