Drupal 7 separate field collection in view - drupal-7

I have a field collection "user_card" composed of 2 fields: card_name and card_digits.
Right now the field collection is shown like this
+---------+---------------------------+
| User id | title user_card |
+---------+---------------------------+
| 1 | card_name_1 card_digits_1 |
| 2 | card_name_2 card_digits_2 |
+---------+---------------------------+
I need to show in a view that field collection but in 2 different columns, like this.
+---------+--------------+---------------+
| User id | Card name | Card digits |
+---------+--------------+---------------+
| 1 | card_name_1 | card_digits_1 |
| 2 | card_name_2 | card_digits_2 |
+---------+--------------+---------------+
Is there a way to do it? or at least have a mecanism to break the collection in 2 separate fields.

Use Field Collection Views module.
This module provides a formatter leveraging views for the Field Collection module.
Usage
After install this module,then you could goto host entity's fields
display settings page,such as
admin/structure/profiles/manage/resume/display.
at display settings page, you could choose format for you collection
field,This module provide a new option"Views field-collection items"
then at format summary area, you will see "Embed View:
field_collection_view, default", Yes ,this module using
views_embed_view function,That mean you need config the name and
display id of the view you want to use.
Now if you visit a page of host entity, you could only see three
fields," Field collection Item id", "Edit", "Delete",At the bottom
there is a "Add" link.This is not a bug, that because i do not know
which fields that added to collection field.
Clone views "field_collection_view", at the clone view, you need add
more fields to it, change the sort criteria,Please do not change the
existing fields (except "Exclude from display " for
"Field-collection item: Field-collection item ID"),the Contextual
filters of " Field-collection item: Field-collection item ID"
After that you need config the name /display id of the views you
want to use at display settings page, such as
admin/structure/profiles/manage/resume/display,you click the button
at the right place, then there will be a form inlude 2
elements,"name" and "display id".

Related

How to get an object with it's parent from firebase?

I want to get from firebese an object that have a specific value and this object parent's name. But in some reasons I cant do it.
So first of all I will describe what I have:
Db with the next structure:
db
|
+--clients
|
+--kua
| |
| +--kuaName1
| |
| +--kuaName2
| |
| +--kuaName3
|
+--uo
In every kuaName I have an object with some info, one of the keys is "kuaEdrpou", the value of this key is unique for every kuaName. So I have next logic:
Find an object by kuaEdrpou.
Take this object name (kuaName1, kuaName2, kuaName3) and data to use them in my app.
Also I have function to get data from firebase db:
const stocksRef = firebase.database().ref().child('clients/kua');
stocksRef.orderByChild('kuaEdrpou').equalTo(this.state.kuaEdrpou).once("value",snapshot => {
let snap = snapshot.exportVal();
console.log("snapshot", snap);
}
Console.log shows me an object with three keys
So my questions are how to get from firebase
{kuaName1:{kuaEdrpou: some id}} object and why snapshot.exportVal() returns an object with three nested objects inside?
you are setting the snapshot on ref
firebase.database().ref().child('clients/kua');
so whenever something change/updates you get the whole kua with all of its child.
if you need any specific child under kua add the reference of that children like
firebase.database().ref().child(`clients/kua/${this.state.kuaEdrpou}`);
maybe this way you can get your desired object

Angular - Remove a row after filtering a table

I have a table with filter's like :
ng-repeat="person in filtered = ( data | filter:query | filter : name | filter {m_resource: resourceFilter} | filter : {m_id : idFilter} | limitTo:maxRowSize )"
And inside the table as part of each row, I have a delete button:
<button class ="btn" ng-click="removeRow($data, $index, this)">del</button>
when clicking on the button I want the row to be removed from the UI, without using any filter I just use splice:
$scope.data.splice(index, 1);
But when I am applying filter it wont work beacuse the index(numer of the row in the displayed table) is the UI index not the data index.
Anyone know's how to delete a row after filtering?
Try this,
<button class ="btn" ng-click="removeRow(person)">del</button>
In your removeRow function,
var index = $scope.data.indexOf(person);
$scope.data.splice(index, 1);

AngularJS ng-options/Typeahead expression syntax

I was trying to find the AngularJS select with ng-options or Typeahead expression syntax but I couldn't find the whole thing in one place, so I gather information from here and there and this is what I came up with:
Expression syntax (This is the full syntax, most of it are optional):
(ObjectForModel) as (stringRepresentation for the UI) for (OneObjectFromList) in (ListOfObjects) | (Filter1) | (Filter2) ...
Example: Lets say we have a list of Students:
var StudentList = [{firstName: "Jhon",lastName:"Smith" id:1},{firstName: "Clint",lastName:"Eastwood" id:2} ];
Lets say that we wanna use this list in a typeAhead input but:
1. We want our popup drop down to display: "first name - last name" but when a user select an item we want the whole item from the list to be populate in the ng-model.
2. We want to filter the select to show only 5 elements
3. We want the pop up drop down list to display only what is relevant base on the user input.
So this is how it looks like:
uib-typeahead="student as (student.firstName +' - ' + student.lastName) for student in studentList | filter:$viewValue | limitTo:5"
If you guys have something more to add please do, I know I could have use it...
You can also change the template ( for example displaying a field in a particular way, and on click set the input with another one )
in the html file :
<script type="text/ng-template" id="deterFormACTemplate.html">
<a ng-bind-html="match.model.displayed | unsafe"></a>
</script>
<input typeahead-template-url="deterFormACTemplate.html"
uib-typeahead="item as item.field for item in autocomplete(...)"
typeahead-on-select="mymodel=$model.field;"
typeahead-wait-ms="500" />
in the controller
$scope.autocomplete = function ( ){
return [ {'field':'..', "displayed":"..."},{'field':'..', "displayed":"..."}, .. ];
}

How to filter a certain object property value with angular select box

I would like to filter out a object that has a property value of "None". The object CounterParty has 2 properties, CounterPartyId and CounterPartyName.
The first object in the db has CounterPartyName: "None", I do not want this to show in the select box options.
I setup a plunker but the select-box is not working and there are no errors in the console:
Plunker
<select ng-model="search.CounterParty"
ng-options="c.CounterPartyName as c.CounterPartyName for c in counterPsList | unique: 'CounterPartyName'">
{{c.CounterParty}}
</select>
Json
$scope.counterParties = [
{"$id":"1","CounterPartyId":1,"CounterPartyName":"None","Documents":null},
{"$id":"2","CounterPartyId":2,"CounterPartyName":"CounterParty A","Documents":null},
{"$id":"3","CounterPartyId":3,"CounterPartyName":"Counter Party B","Documents":null},
{"$id":"4","CounterPartyId":4,"CounterPartyName":"Counter Party C","Documents":null},
{"$id":"5","CounterPartyId":5,"CounterPartyName":"Counter Party D","Documents":null}
];
You don't need to use angular-ui's unique filter here - its purpose is something else.
If you just need to filter out based on a certain property, you could specify the filter expression like so (notice the !):
ng-options = '...in counterPsList | filter: { CounterPartyName: "!None" }'
plunker

Taggit gets wrong tags

I have a Work model with Category Foreign Key. I am doing -->
drawingTags = Tag.objects.filter(Q(work__category__slug_en = 'drawing') |
Q(work__category__slug_en = 'illustration') |
Q(work__category__slug_en = 'sketch') |
Q(work__category__slug_en = 'storyboard'))
I get also the tags that do not belong to drawings ? Am i doing smt wrong ?
-- EDIT --
I did a little test. I have two applications named blog and web.
In blog i have 'entry' model and in web i have 'work' model. Both of those models have TaggableManager fields named tags...
When i want to take the tags of works categorized under drawing and do -->
drawingTags = Tag.objects.filter( work__in = drawings ).distinct()
If there is a drawing with id 1 and if entry model has an entry with id 1. Than i get both item's tags. I think there is a problem here but i do not know how to solve the puzzle?
Solution :
from django.contrib.contenttypes.models import ContentType
contentType = ContentType.objects.get_for_model(Work)
drawingTags =Tag.objects.filter(taggit_taggeditem_items__content_type=contentType,
work__in = drawings ).distinct()

Resources