I am currently building an angular.js social media platform and am trying to display facebook posts on my feeds page for facebook. I currently have this:
<div id='fb-root'>
<div ng-repeat="post in facebook">
Test: {{post}}
</div>
</div>
which returns my Test post as:
[{"id":"4681211244366_4681199684077","from":{"id":"4681211244366","name":"Zachy Bear Jones"},"story":"Zachy Bear Jones and Alexander J. Marrs are now friends.","story_tags":{"0":[{"id":"4681211244366","name":"Zachy Bear Jones","offset":0,"length":16,"type":"user"}],"21":[{"id":"10205311345929912","name":"Alexander J. Marrs","offset":21,"length":18,"type":"user"}]},"actions":[{"name":"Comment","link":"https://www.facebook.com/4681211244366/posts/4681199684077"},{"name":"Like","link":"https://www.facebook.com/4681211244366/posts/4681199684077"}],"privacy":{"value":""},"type":"status","status_type":"approved_friend","created_time":"2014-10-11T21:33:29+0000","updated_time":"2014-10-11T21:33:29+0000"},{"id":"4681211244366_4678763463173pmpmymife","from":{"id":"4681211244366","name":"Zachy Bear Jones"},"story":"Zachy Bear Jones commented on a status.","story_tags":{"0":[{"id":"4681211244366","name":"Zachy Bear Jones","offset":0,"length":16,"type":"user"}]},"privacy":{"value":""},"type":"status","application":{"name":"Facebook for iPhone","namespace":"fbiphone","id":"6628568379"},"created_time":"2014-10-11T08:20:12+0000","updated_time":"2014-10-11T08:20:12+0000"},{"id":"4681211244366_4676849935336","from":{"id":"4681211244366","name":"Zachy Bear Jones"},"story":"Zachy Bear Jones likes a photo.","story_tags":{"0":[{"id":"4681211244366","name":"Zachy Bear Jones","offset":0,"length":16,"type":"user"}]},"privacy":{"value":""},"type":"status","created_time":"2014-10-10T18:35:16+0000","updated_time":"2014-10-10T18:35:16+0000"},{"id":"4681211244366_4676161038114","from":{"id":"4681211244366","name":"Zachy Bear Jones"},"story":"Zachy Bear Jones likes The ManKind Project.","story_tags":{"0":[{"id":"4681211244366","name":"Zachy Bear Jones","offset":0,"length":16,"type":"user"}],"23":[{"id":"95845568627","name":"The ManKind Project","offset":23,"length":19,"type":"page"}]},"picture":"https://fbcdn-profile-a.akamaihd.net/hprofile-ak-prn2/v/t1.0-1/c25.37.310.310/s100x100/47037_10151832647868628_1954427594_n.png?
Back as my JSON object. What is the next step to rendering this information as a post? In a prefect world I need profile pic, message, time, location, and the like, share, and comment actions. Any advice on how I can do this? Thank you anyone who can help!
First of all you should format your json object to a readable one to get the certain structure. Based upon your object I did this as an example:
[{
"id":"4681211244366_4681199684077",
"from":{
"id":"4681211244366",
"name":"Zachy Bear Jones"
},
"story":"Zachy Bear Jones and Alexander J. Marrs are now friends.",
"story_tags":{
"0": [{
"id":"4681211244366",
"name":"Zachy Bear Jones",
"offset":0,
"length":16,
"type":"user"
}],
"21":[{
"id":"10205311345929912",
"name":"Alexander J. Marrs",
"offset":21,
"length":18,
"type":"user"
}]
},
"actions":[{
"name":"Comment",
"link":"https://www.facebook.com/4681211244366/posts/4681199684077"
},{
"name":"Like",
"link":"https://www.facebook.com/4681211244366/posts/4681199684077"
}],
"privacy":{
"value":""
},
"type":"status",
"status_type":"approved_friend",
"created_time":"2014-10-11T21:33:29+0000",
"updated_time":"2014-10-11T21:33:29+0000"
},
...
To display data use something like this:
<div id='fb-root'>
<div ng-repeat="post in facebook">
Post from: {{post.from.name}} <br />
Story: {{post.story}} <br />
Tagged: <span ng-repeat="tag in post">{{tag.name}}</span>
</div>
</div>
This should result in something like this:
<div id='fb-root'>
<div>
Post from: Zachy Bear Jones <br />
Story: Zachy Bear Jones and Alexander J. Marrs are now friends. <br />
Tagged: <span>Zachy Bear Jones</span><span>Alexander J. Marrs</span>
</div>
</div>
Related
I am using odoo 15 ; I am trying to customize receipt in point_of_sale module
I have a problem regard access the custom filed in company module as following :
My customized module : custom/models/res_company.py
class rescompany(models.Model):
_name = "res.company"
_inherit = "res.company"
#customized fields
x_industry = fields.Char(string='Compnay Industry', translate=True)
my customized view in xml : custom/static/src/xml/custom_pos.xml
<xpath expr="//t[#t-if='receipt.company.logo']" position="before">
<div>
<span style="font-size: smaller;float: left">
<t t-esc="receipt.company.name" />
</span>
</div>
<div>
<div>
<span style="font-size: smaller;float: left">
<t t-esc="receipt.company.x_industry"/>
</span>
</div>
</div>
</xpath>
</t>
</templates>
manifest.py
...
'assets': {
'web.assets_backend': [
"custom/static/src/js/OrderReceipt.js",
],
'web.assets_qweb': [
'custom/static/src/xml/custom_pos.xml',
],
},
...
Now, I don't know how to access x_industry in OrderReceipt.js ?
I tried to follow this link :
Odoo PoS not showing custom fields in receipts
but it is in odoo 13 and I did not understand the parameters I should add to be modified correctly ;
You cannot access a field in PoS even though it has been added through python code. You need to load the specific field in the javascript files for Point of Sale.
Regarding your question, you need to add a field which is specific for a company. The easiest method is to also add the same field in pos.config model and give a related connection with the new field which you added in res.company.
x_industry = fields.Char(string='Compnay Industry', translate=True, related='company_id.x_industry')
Any field added in the pos.config can be accessed from the PoS and PoS receipt.
<t t-esc="env.pos.config.x_industry"/>
In the ABP framework, the tutorial for version 5.1 says to:
Use Enum:enum-type:enum-value naming convention to localize the enum members.
e.g. "Enum:BookType:1": "Adventure"
However, this does not work when using the abp-select tag helper. I can see from the source code for abp-select that the expected format is actually:
Enum:enum-type.enum-toString
e.g. "Enum:BookType.Adventure": "Adventure"
So the documentation is inaccurate, but not a problem, as soon as I changed the resource file enums to the correct format abp-select localised the display values as expected.
However, the datatables source code for the Book List in the same tutorial then breaks:
columnDefs: [
{
title: l('Type'),
data: "type",
render: function (data) {
return l('Enum:BookType:' + data);
}
}
This code expects the enum format to be Enum:enum-type:enum-value and as data is passed back as an int and not the string representation of the enum, the datatable doesn't show the localised data.
As a work around, I am diverging from the tutorial instructions and binding the datatable to a BookDto where BookType is mapped to a string, not an enum. Feels a bit cludgy though.
Am I missing something here ABP?
Great product but this tutorial needs updating either way.
I ran into the same issue but solved it by updating the localization file en.json to match the enum value stored in the database and then changing the book.component.html file to match the abpLocalization property.
When I followed the official documentation at abp, I got this result:
First run with fallback string in HTML component
Acme.BookStore.Application.Shared/Localization/en.json
{
"culture": "en",
"texts": {
"Menu:Home": "Home",
"Welcome": "Welcome",
"LongWelcomeMessage": "Welcome to the application. This is a startup project based on the ABP framework. For more information, visit abp.io.",
"Menu:BookStore": "Book Store",
"Menu:Books": "Books",
"Actions": "Actions",
"Close": "Close",
"Delete": "Delete",
"Edit": "Edit",
"PublishDate": "Publish date",
"NewBook": "New book",
"Name": "Name",
"Type": "Type",
"Price": "Price",
"CreationTime": "Creation time",
"AreYouSure": "Are you sure?",
"AreYouSureToDelete": "Are you sure you want to delete this item?",
"Enum:BookType.0": "Undefined",
"Enum:BookType.1": "Adventure",
"Enum:BookType.2": "Biography",
"Enum:BookType.3": "Dystopia",
"Enum:BookType.4": "Fantastic",
"Enum:BookType.5": "Horror",
"Enum:BookType.6": "Science",
"Enum:BookType.7": "Science fiction",
"Enum:BookType.8": "Poetry"
}
}
book.component.html in the angular project
<div class="card">
<div class="card-header">
<div class="row">
<div class="col col-md-6">
<h5 class="card-title">
{{ '::Menu:Books' | abpLocalization }}
</h5>
</div>
<div class="text-end col col-md-6"></div>
</div>
</div>
<div class="card-body">
<ngx-datatable [rows]="book.items" [count]="book.totalCount" [list]="list" default>
<ngx-datatable-column [name]="'::Name' | abpLocalization" prop="name"></ngx-datatable-column>
<ngx-datatable-column [name]="'::Type' | abpLocalization" prop="type">
<ng-template let-row="row" ngx-datatable-cell-template>
{{ '::Enum:BookType.' + row.type | abpLocalization }}
</ng-template>
</ngx-datatable-column>
<ngx-datatable-column [name]="'::PublishDate' | abpLocalization" prop="publishDate">
<ng-template let-row="row" ngx-datatable-cell-template>
{{ row.publishDate | date }}
</ng-template>
</ngx-datatable-column>
<ngx-datatable-column [name]="'::Price' | abpLocalization" prop="price">
<ng-template let-row="row" ngx-datatable-cell-template>
{{ row.price | currency }}
</ng-template>
</ngx-datatable-column>
</ngx-datatable>
</div>
</div>
As you can see I have replaced the ":" with a "." as in the localization file.
After change to source-code I get this result:
Enums now translated correctly
I hope this helps you and others struggling with the same issue :)
I just had the same issue. The problem is a mismatch between the declaration of the localization file wrt the usage in the JS code.
In the localization file you can find keys like:
"Enum:BookType.Adventure": "Adventure"
while in the JavaScript it is used:
render: function (data) {
return l('Enum:BookType:' + data);
}
Thus either you change the localization keys as e.g. "Enum:BookType:Adventure": "Adventure" (with ':') or you change the code with this function:
render: function (data) {
return l('Enum:BookType.' + data);
}
where the '.' is concatenated instead of ':'
Sorry for my English.
I need to change input value format, for example: from "1000000" to "1 000 000 $".
In my views of rails app, I have this line of code:
<%= ng_text_field('total_price', 'selected.data.total_price', 'Full price', ng_readonly: '!selected.permissions.update') %>
In helper:
def ng_text_field(name, ng_model, placeholder, options = {})
result = <<-HTML
<div class="form-group" ng-class='{"has-error":errors.#{name}}' #{options[:ng_if] && "ng-if=\"#{options[:ng_if]}\""}>
<label for="#{name}" class="col-sm-3 control-label">#{placeholder}</label>
<div class="col-sm-9">
<input id="#{name}"
type="text"
class="form-control"
name="#{name}"
placeholder="#{placeholder}"
ng-model="#{ng_model}"
#{options[:ng_readonly] && "ng-readonly=\"#{options[:ng_readonly]}\""}>
<p class="help-block small" ng-if="errors.#{name}">{{errors.#{name} | join:',' }}</p>
</div>
</div>
HTML
result.html_safe
end
I am know Angular very little, I have tried some ways and all this ways was incorrect. :(
Could anyone give advice of some help?
Thank you in advance
You're going to need to create a new directive that requires ngModel and applies the appropriate $parser/$formatter to it.
https://docs.angularjs.org/api/ng/type/ngModel.NgModelController#$parsers
A good example of how to do this is (displaying as uppercase but always storing data as lowercase):
ngModel Formatters and Parsers
You should be able to then add the ability to include other directives in your 'options' argument so that they get added correctly to the output.
I am trying to test a Backbone application running on top of a Rails 3.2.8 one using Cucumber, capybara, capybara-webkit, selenium-webdriver, rspec and jasmine. I am using eco as template engine for the backbone template.
My problem is when I run the scenario using the #javascript tag, wether with capybara-webkit or selenium, the page displayed doesn't contain all the model attribute datas.
Here is the scenario :
#javascript
Scenario : first scenario
Given There is Model with "name" as name and "What is it about ?" as associated questions
When I want to fill the questionnaire
Then I should be on the SPA form
And I should see "name"
And I should see "What is it about?"
The scenario fails on the "And I should see 'what is it about?'" step, the page doesn't show the question, but it shows the "name"
I put several debug statement in my backbone code with console.log and I can see that the model is correct with all its attributes. Moreover it is working in live without issue
The template looks like this : 'show.jst.eco'
<p class="text-info"><%= #model.name %></p>
<form id="quidget-form" class="form-vertical">
<% for question in #model.questions: %>
<div class="issue_field">
<label class="string optional control-label"><%= question.question.question_text %></label>
<div class="control-group text">
<textarea class="text answer" name="question-<%= question.question.id %>" id="question_<%= question.question.id %>" data-question="<%= question.question.question_text %>" rows="3">
</textarea>
</div>
</div>
<% end %>
<div class="controls">
<input type="submit" value="Additional Informations" id="quidget-step-one" class="btn btn-success">
The textarea is displayed but not the label above with the question text
Any idea ? I would like to see this pass so i can test more complicated logic with more steps.
Thanks
I've been doing some research into this sort of things as well. Most of it has been focused around Ember.js instead of Backbone but Pamela Fox just wrote a blog post about testing the Backbone.js frontend for Coursera, it could be helpful http://blog.pamelafox.org/2013/06/testing-backbone-frontends.html Also, have you tried testing with capybara in same manner you would a generic rails application with :js => true? Might be worth trying.
Im developing a webapp that is feeded via a server. Its index presents some shops deals, having all of these deals ann id. In the .gsp, i have this code:
<div id="content">
<g:each in='${promos}' var='promo'>
<div id="up_box"></div>
<div class="deal_container">
<div class="images_container"><img src="${createLink(action:'showImage',controller:'image',id:promo.fotoPrincipal.id)}" width="120" height="105" />
</div>
<g:link controller='promotion' action='openPromo' params="[promoid:promo.id]">
<div class="oferta">${promo.name}</div>
</g:link>
<g:link controller='promotion' action='openPromo' params="[promoid:promo.id]">
<div class="flecha">
</div>
</g:link>
</div>
That means, when I click in one of the links, it will open an url like this:
app/promotion/openPromo/3
In case the deal with the id "3" is clicked. I have a "general" deal details page. I want that page to load always, and fulfill its details dinamically, depending the deal the user clicked. How can I do that?
I don't know if I have been clear in my explanation, if i haven't please ask.
Thank you!
Both links will be handled by the openPromo action in the PromotionController and will be passed the id of the promo as promoid.
You can then load the appropriate promo along with any other related offers you want the user to see and give these to the view. Eg:
class PromotionController {
def openPromo() {
Promo promo = Promo.get(params.promoid)
// Load any other relevant data or offers
render (view:'openPromo', model:[promo:promo, <any other model data here>]
}
}
You can then use the model data in your gsp.
You can do it adding that general info to a Template and then render it from the Controller like this
// render a template to the response for the specified model
def theShining = new Book(title: 'The Shining', author: 'Stephen King')
render(template: "book", model: [book: theShining])
You´ve got more info about the render in this link from the Grails documentation.
http://grails.org/doc/latest/ref/Controllers/render.html
It´s easy to do it, you can add a createLink like the first ones whith calls to an action who will render that template.
Hope it helps ;) and good luck!
I did it this way, after asking my workmate:
def openPromo() {
Promotion promo = Promotion.get(params.promoid)
[promo:promo]
}
Almost what you said David, but without rendering, if I name openPromo my gsp.
Thank you!