How to get html from mongodb? - node.js

I have collection
{
"_id" : 1,
"title" : "Title",
"description" : "<p>Text ...</p>",
}
I need to get the description in Angular.
But when I output this data, I get a string <p>Text ...</p> instead of a tag <p>

Try this:
<span [innerHtml]="yourObject.description"></span>

Related

How to create a view based on chosen type of data in Angular?

How to display different json files in the same view?
I have 3 json files:
{"streetAddress": "Kosterijland 20", "postalCode": 3980, "city:" : "Bunnik", "country" : "Netherlands" }
{"firstName": "Anna", "age": 39, "lastName:" : "Kowalski"}
{"test": "value", "test2": "value2"}
I want to have generic method that will display the files like this:
streetAdress: Kosterijland 20
postalCode: 3980
city: Bunnik
country: Netherlands
OR
firstName: Anna
age: 39
lastName: Kowalski
OR
test: value
tet2: value
How can I do that? I want to make it generic, so when I add another json file with different properties I dont have to change the code
myService.ts class for retrieving the data using http client:
private url5 ="./assets/temp-data/location-entity-test.json";
getEntityDetails(){
return this.http.get(this.url5, {responseType: 'text'});
}
component.html class for displaying the json:
<div *ngFor="let item of displayObjectKeys; let i = index">
{{ item }} - {{ displayObjectValues[i] }}
</div>
component.tsclass:
json: any;
displayObjectKeys = [];
displayObjectValues = [];
constructor(private linkedEntityVocabulariesService:
LinkedEntityVocabulariesService) { }
ngOnInit() {
this.linkedEntityVocabulariesService.getEntityDetails()
.subscribe(data=>this.json=data);
}
PS. I know that html page is fine but I dont know how to get the properties and values in ts file and I dont know if the http request is good for this type of operations. Please help me
You could preprocess the objects you want to display into arrays if keys and values and render them seperately.
dogObject = {"name": "woofy", "age": 42, "weight": "a ton"};
carObject = {"color": "red", "power":"1.31GW"};
displayObjectKeys = [];
displayObjectValues = [];
selectObjectToDisplay(selectedItemToDisplay) {
let item = null;
if(selectedItemToDisplay === car) {
item = carObject;
}
if(selectedItemToDisplay === dog) {
item = dogObject;
}
if(!item) {
return;
}
this.displayObjectKeys = Object.keys(item);
this.displayObjectValues = Object.values(item);
}
<button (click)="selectObjectToDisplay("dog")"></button>
<button (click)="selectObjectToDisplay("car")"></button>
now you have the keys and values extracted.
then you could do something like this:
<div *ngFor="let item of displayObjectKeys; let i = index">
{{ item }} - {{ displayObjectValues[i] }}
</div>
this should render the car props as
color - red
power - 1.31GW
And when the user switches the object to display, just call the selectObjectToDisplay() method and pass the new object inside.
BUT
this is very dirty and the properties will be rendered as they are defined.

Translation of a Label containing an url

In my symfony3 project, I have a form field with label "I accept the cgu" with a link on the 'cgu'.
How can I translate the label containing the link, as I must generate the link with {{path('')}} in twig ?
I tried something like that :
{{ form_row(form.valid, {'label' : 'annonces.form.valide_cgu_cgv' | trans ({'cgu_link' : {{ path('page_statique', {'page' : 'cgu'})}}, 'cgv_link' : {{ path('page_statique', {'page' : 'cgv'})}} }) |raw }) }}
but it does not work...
Any idea ?
Thanks all !
When you are under {{ }}, you're writting an expression, so you can't put nested {{ }}.
You can try with:
{{
form_row(form.valid, {
'label' : 'annonces.form.valide_cgu_cgv' | trans({
'cgu_link' : path('page_statique', {'page' : 'cgu'})
'cgv_link': path('page_statique', {'page' : 'cgv'})
})
})
}}

Express JS Display Data By ID

I use mongodb with collection structure as follows:
chatbot collection
{
"_id" : ObjectId("5a2f8edf84b906480af0d121"),
"botname" : "Welcome Chat",
"description" : "Welcome Chat",
"status" : "Inactive"
}
route.js
app.get('/cpanel/chat-bot/:id', function(req, res) {
if (req.session.user == null) {
res.redirect('/cpanel/login');
} else {
CB.getAllRecords().then(results => {
res.render('cpanel/chat-bot/:id', { udata : req.session.user, chatbot: results});
}).catch(err => {
res.sendStatus(500);
});
}
});
index.ejs
<ul class="menu-sidebar">
<% for(var i = 0; i < chatbot.length; i++) { %>
<li>
<span class="fa fa-circle-o"></span><%= chatbot[i].botname %>
</li>
<% } %>
</ul>
how to display data chatbot by id from mongodb? when I click url 1 (/cpanel/chat-bot/1) it will show data id 1 from mongodb, when I click url 2 (/cpanel/chat-bot/2) it will show data id 2 from mongodb? Thank you
When you configure a route like
app.get('/cpanel/chat-bot/:id', ...)
The :id part of the route says that you want to match any value for that part of the path and then Express will put whatever was matched into req.params.id. So, if you want to use that id value as part of your database query, you need to use req.params.id in your database query in order to select only the desired data from your database.
In addition, you do NOT use :id in the render path so remove it from here:
res.render('cpanel/chat-bot/:id', ...);
That should just be a path to your template file (whatever the filename of the template is):
res.render('cpanel/chat-bot', ...);
You don't disclose much about your data in the database so we can't really help with how you would use the req.params.id value to select the desired data from your database. I presume you would use it in a query of some sort.

Uploadifive does not apply on dynamically created INPUT elements

This is my uploadifive setup:
Inside body:
<div id="file_rows_wrapper">
<div class="file_row">
<input class="file_upload" name="file_upload" type="file" multiple="false">
</div>
</div>
Add Another File
While this is the javascript part:
$(function() {
uploadify();
});
function uploadify() {
<?php $timestamp = time();?>
$('.file_upload').uploadifive({
'auto' : true,
'checkScript' : '/files/check_exists',
'formData' : {
'timestamp' : '<?php echo $timestamp;?>',
'token' : '<?php echo md5('hiall' . $timestamp);?>'
},
'queueID' : 'queue',
'uploadScript' : '/files/upload_file',
'multi' : false,
'buttonText' : 'Upload File',
});
};
function add_file()
{
var file = $('.file_row:first').clone();
file.css('margin-top', '20px');
file.fadeIn().appendTo($('#file_rows_wrapper'));
uploadify();
}
All works as expected. The "file_row" div is being cloned but when clicking on the "Add Another File" and choosing the local file, nothing happens. There is no upload. If I maually copy the "file_row" div more times then the upload works fine, even more uploads at once. What am I doing wrong?
I think you need a unique id in your file input to have multiple instances on one page.

adding class to ckeditor

I am trying to add a class to a ul using ckeditor in drupal
In ckeditor.styles.js
this works
{ name : 'my style', element : 'h1', attributes : { 'class' : 'bigblue' } },
this does not
{ name : 'my list style', element : 'ul', attributes : { 'class' : 'highlight' } },
Any help would be appreciated.
I WAS facing the same problem.
Actually, for such styles, you need to create your UL tags with the CkEditor, select it, then it will appear in the style combo, because it is somehow contextual.
Hope this helps.

Resources