I need to know about to access Collection object data in html as shown below :
var fieldData = [
{fieldName: "Hcare1",
fieldOptions: [ "Bike","Car","TV","Radio","etc"]
},
{fieldName: "Hcare2",
fieldOptions: [ "Bike1","Car1","TV1","Radio1","etc"]
},
{fieldName: "Hcare3",
fieldOptions: [ "Bike2","Car2","TV2","Radio2","etc"]
}
];
In the above code how to access fieldOptions data in html.The fieldData is inserted into a collection i.e Collection name is Fields.I'm new to meteor.So can you please suggest me what to do?
In mongo console:
db.foo.findOne().fieldOptions;
[ "Bike", "Car", "TV", "Radio", "etc" ]
Or on client:
collectionName.findOne().fieldOptions;
In JS:
Template.your_layout.helpers({
fieldOptions: function() {
Fields.findOne().fieldOptions;
}
});
In HTML:
{{#each fieldOptions}}
{{this}}
{{/each}}
Smth like this...
Related
I am working with DataTables, trying to load my json data. The HTML renders fine but I can't get any data to display. The live data wasn't working so I created a string to simulate the return. I'm not making an Ajax call to get the data, I'm calling the endpoint in c# and passing the resulting json string to JS. I'm getting no errors in the console. If you are curious why I'm not using Ajax, I'll say I don't know. :-)
We just downloaded DataTables so it is the latest version and the project is .Net Framework 4.6.1
Here is my Json:
var fakeJson =
{
"data":
{
"Triggers": {
"TriggerTypeId": 2,
"TriggeredKeyId1": 499,
"TriggerHelpText": "Blah blah blah",
"TriggerActionDefinitionID": 2,
"ComparisonOperatorID": 1
},
"Action": {
"TaDescription":"this is an action description"
},
"Protocols": {
"protocolDescription": "this is a protocol description"
},
"Operators": {
"CODisplayText": "="
}
}
};
and here is my JS:
var dataSource = <%= DataTableJson %>;
dataString = JSON.stringify(dataSource);
dataSource = JSON.parse(dataString);
console.log(fakeJson.data.Triggers.TriggerHelpText);
var editor = new $.fn.dataTable.Editor({
table: '#ProtocolTriggerTable',
"data": fakeJson
},
fields: [{
label: "Comparison",
name: "data.Operators.CODisplayText",
//type: "select"
}, {
label: "Action",
name: "data.Action.TaDescription",
//type: "select"
}, {
label: "Item",
name: "data.Protocols.protocolDescription",
//type: "select"
}, {
label: "Pop-up Text",
name: "data.Triggers.TriggerHelpText",
//type: "select"
}]
});
$('#ProtocolTriggerTable').DataTable({
dom: "rt",
data: fakeJson,
columns: [
{ data: "data.Operators.CODisplayText" },
{ data: "data.Action.TaDescription" },
{ data: "data.Protocols.protocolDescription" },
{ data: "data.Triggers.TriggerHelpText" }
],
});
and the HTML
<table border="1" id="ProtocolTriggerTable" class="display" style="background-color: #e0e0e0; width:100%;">
<thead>
<tr>
<th style="width:20px !important"></th>
<th>Comparison</th>
<th>Action</th>
<th>Item</th>
<th>Pop-up Text</th>
</tr>
</thead>
</table>
Follow-up: Based on two or three good comments below, here is the Json structure that finally worked. No I just have to apply this to my live data.
var fakeJson =
[{
"Triggers": {
"TriggerTypeId": 2,
"TriggeredKeyId1": 499,
"TriggerHelpText": "Blah blah blah",
"TriggerActionDefinitionID": 2,
"ComparisonOperatorID": 1
},
"Action": {
"TaDescription": "this is an action description"
},
"Protocols": {
"protocolDescription": "this is a protocol description"
},
"Operators": {
"CODisplayText": "="
}
}];
The format of the DataTableJson is not usable try something like this:
[
['Comparison0', 'Action0', 'Item0', 'Popup0'],
['Comparison1', 'Action1', 'Item1', 'Popup1'],
]
First of all, I tried to write how to save users input data to google sheet after developing the simple codes. It's able to work. Thank Mr.Master for providing this tutorial(Below the link).
Reference Mr.Master: https://www.youtube.com/watch?v=huwUpJZsTok
Next, I bumped into the problem below the code. I didn't know how to write it in Fulfillment. Could someone realize it to teach me?
Tool: Dialogflow, Google sheet, Firebase.
Theme: Order process
I tried to write Forhere() there. However, it didn't work.(First code)
function Forhere(agent){
const{
forhere, howmanypeople, whattime, namelist
} = agent.parameters;
const data1 = [{
Forhere: forhere,
HowManyPeople: howmanypeople,
Time: whattime,
Name: namelist
}];
axios.post('......', data1);
}
{/*....This code is a result of test(second one)
"responseId": "d0f44937-e58a-4b71-b6dc-ec2d6c39337b-f308a5c4",
"queryResult": {
"queryText": "黃大哥",
"parameters": {
"forhere": [
"內用"
],
"howmanypeople": [
2
],
"whattime": [
**{
"date_time": "2019-09-19T14:00:00+08:00"
}**
],
"namelist": [
"黃大哥"
]
},
"allRequiredParamsPresent": true,
"outputContexts": [
{
"name": "projects/test-tyrpxs/agent/sessions/5dd26d5c-bd99-072c-3693-41f95a3a348d/contexts/forhere",
"lifespanCount": 4,
"parameters": {
"howmanypeople": [
2
],
"namelist.original": [
"黃大哥"
],
"howmanypeople.original": [
"2"
],
"forhere": [
"內用"
],
"whattime.original": [
"明天下午2點"
],
"welcome": "嗨",
"whattime": [
{
"date_time": "2019-09-19T14:00:00+08:00"
}
],
"namelist": [
"黃大哥"
],
"welcome.original": "hi",
"forhere.original": [
"內用"
]
}
}
],
"intent": {
"name": "projects/test-tyrpxs/agent/intents/ec0f55c4-e9c9-401f-bce7-d2478c40fb85",
"displayName": "ForHere"
},
"intentDetectionConfidence": 1,
"diagnosticInfo": {
"webhook_latency_ms": 4992
},
"languageCode": "zh-tw"
},
"webhookStatus": {
"code": 4,
"message": "Webhook call failed. Error: Request timeout."
}
}
You can use below code
let forhere= agent.parameters.forhere;
let howmanypeople= agent.parameters.howmanypeople;
let whattime= agent.parameters.whattime;
let namelist= agent.parameters.namelist;
then use this variables in your api call.
To T.Ali:
Dialogflowfirebasefulfillment&Error message:
Although I think this error didn't show where these mistakes are.
Dialogflow Request body: {"responseId":"ab277bc6-3bcc-4c4b-9a94-192b9ecfb8af-f308a5c4","queryResult":{"queryText":"黃大哥","parameters":{"forhere":"內用","whattime":{"date_time":"2019-09-20T12:00:00+08:00"},"howmanypeople":3,"namelist":"黃大哥"},"allRequiredParamsPresent":true,"outputContexts":[{"name":"projects/test-tyrpxs/agent/sessions/5dd26d5c-bd99-072c-3693-41f95a3a348d/contexts/forhere","lifespanCount":4,"parameters":{"welcome":"嗨","welcome.original":"hi","forhere":"內用","forhere.original":"內用","whattime":{"date_time":"2019-09-20T12:00:00+08:00"},"whattime.original":"明天中午","howmanypeople":3,"howmanypeople.original":"3","namelist":"黃大哥","namelist.original":"黃大哥"}}],"intent":{"name":"projects/test-tyrpxs/agent/intents/ec0f55c4-e9c9-401f-bce7-d2478c40fb85","displayName":"ForHere"},"intentDetectionConfidence":1,"languageCode":"zh-tw"},"originalDetectIntentRequest":{"payload":{}},"session":"projects/test-tyrpxs/agent/sessions/5dd26d5c-bd99-072c-3693-41f95a3a348d"}
Error: No handler for requested intent
at WebhookClient.handleRequest (/srv/node_modules/dialogflow-fulfillment/src/dialogflow-fulfillment.js:317:29)
at exports.dialogflowFirebaseFulfillment.functions.https.onRequest (/srv/index.js:105:9)
at cloudFunction (/srv/node_modules/firebase-functions/lib/providers/https.js:57:9)
at /worker/worker.js:783:7
at /worker/worker.js:766:11
at _combinedTickCallback (internal/process/next_tick.js:132:7)
at process._tickDomainCallback (internal/process/next_tick.js:219:9)
Furthermore, I've write below the code worked formally(input users data to google sheet).
enter image description here
We can now retrieve documents from a collection group which is great. To do so, I need to create an index through an error message on the Firebase console. How can I add this new index to the firestore.indexes.json file?
Example of the documentation:
let museums = db.collectionGroup('landmarks').where('type', '==', 'museum');
museums.get().then(function(querySnapshot) {
querySnapshot.forEach(function(doc) {
console.log(doc.id, ' => ', doc.data());
});
});
At the top level of your index file, add a new element called fieldOverrides and populate it like this:
{
"fieldOverrides": [
{
"collectionGroup": "landmarks",
"fieldPath": "type",
"indexes": [
{
"order": "ASCENDING",
"queryScope": "COLLECTION"
},
{
"order": "DESCENDING",
"queryScope": "COLLECTION"
},
{
"arrayConfig": "CONTAINS",
"queryScope": "COLLECTION"
},
{
"order": "ASCENDING",
"queryScope": "COLLECTION_GROUP"
}
]
}
]
}
This preserves the all the default automatic indexing for the type field in landmarks at the COLLECTION scope, and allows for type also to be used at the COLLECTION_GROUP scope.
I am trying to interact with an iframe located in a chrome-extension popup. I know content.js can be injected in all frame using the manifest.json but it's working with frame inside a webpage and not inside the extension's popup.
Is it doable ? I tried many things but I didn't find a solution yet.
my manifest :
{
"name" :"test",
"version": "1.0",
"manifest_version": 2,
"description" :"Scraping Facebook",
"permissions": [
"cookies",
"background",
"tabs",
"http://*/*",
"https://*/*",
"storage",
"unlimitedStorage"
],
"icons": { "128": "images/pint.png" },
"content_scripts": [
{
"matches": [
"http://*/*",
"https://*/*"
],
"js": ["jquery-3.1.0.min.js","content.js"],
"run_at":"document_end"
}
],
"web_accessible_resources": [
"http://*/*",
"https://*/*",
"styles/*",
"fonts/*"
],
"background": {
"scripts": ["background.js"]
},
"browser_action" :
{
"default_popup": "popup.html",
"default_title": "test"
}
}
Use "all_frames": true in your content script declaration to inject it into an iframe:
"content_scripts": [{
"matches": [ "http://example.com/*" ],
"js": [ "content.js" ],
"all_frames": true
}],
To differentiate this iframe from normal tabs you can add a dummy parameter to the URL when you create the iframe e.g. http://example.com/?foo so you can match it in manifest.json like "http://example.com/*foo*" for example.
Then you can use messaging: the content script initiates it, and the extension script registers a listener.
Trivial one-time sendMessage:
content.js:
chrome.runtime.sendMessage('test', response => {
console.log(response);
});
popup.js (or background.js and so on):
chrome.runtime.onMessage.addListener((msg, sender, sendResponse) => {
console.log('popup got', msg, 'from', sender);
sendResponse('response');
});
Long-lived port:
content.js:
let port = chrome.runtime.connect({name: 'test'});
port.onMessage.addListener((msg, port) => {
console.log(msg);
});
port.postMessage('from-iframe');
popup.js (or background.js and so on):
let iframePort; // in case you want to alter its behavior later in another function
chrome.runtime.onConnect.addListener(port => {
iframePort = port;
port.onMessage.addListener((msg, port) => {
console.log(msg);
});
port.postMessage('from-popup');
});
An example of popup.html is really straightforward:
<html>
<body>
<iframe width="500" height="500" src="http://example.com"></iframe>
<script src="popup.js"></script>
</body>
</html>
Of course you can also add the iframe(s) programmatically using DOM manipulation.
I have a meteor app using livestamp. However, I wish to represent a collection within a reactive-table. However, when I try the code below, it doesn't work (I see nothing in the updated column):
Template.sensor_table.helpers
settings: () ->
return {
collection: Sensors
rowsPerPage: 100
showFilter: true
fields: [
{ key: '_id', label: 'id' },
{ key: '_id', label: 'rack', fn: (v,o) -> (getSensor v).rack },
{ key: 'temp', label: 'temperature (degC)' },
{ key: 'ts', label: 'updated', fn: (v,o) -> livestamp v }
]
}
but when I use it within a template, it works fine. How can I get the functionality of livestamp within my reactive table?
You can do that with https://atmospherejs.com/aldeed/tabular it's also datatables but it's different package (in my opinion better)
if you choose to use it here is an example, tabular has the option to render fields as a template and livestamp should work just as on the template itself.
TabularTables.Books = new Tabular.Table({
name: "Books",
collection: Books,
columns: [
{data: "_id", title: "id"},
{data: "_id", title: "Rack"},
{ data: 'ts', title: 'updated',
tmpl: Meteor.isClient && Template.liveStamp
}
]
});
// template
<template name="liveStamp">
<p>{{livestamp this.ts}}</p>
</template>
so i guess it helps to actually read the manual....
Template.sensor_table.helpers
settings: () ->
return {
collection: Sensors
rowsPerPage: 100
showFilter: true
fields: [
{ key: '_id', label: 'id' },
{ key: '_id', label: 'rack', fn: (v,o) -> (getSensor v).rack },
{ key: 'temp', label: 'temperature (°C)' },
{ key: 'ts', label: 'updated', tmpl: Template.sensor_updated }
]
}
and then a template somewhere...
<template name="sensor_updated">
{{ livestamp ts }}
</template>