i created a "todolist" with angular-meteor (meteor add urigo:angular).
This are the files which are involved:
config.js (ui-router file)
.state('app.todolist', {
url: '/todolist',
title: 'Todolist',
controller: 'TodoListController',
controllerAs: 'tc',
templateUrl: helper.basepath('todolist.ng.html'),
authenticate: true
})
todolist.ng.html (static file)
<h3>Todo - List
<small>Example app of a todo list.</small>
</h3>
<ul ng-repeat="task in tc.tasks">
<li>{{task.text}}</li>
</ul>
todolist.js (Controller)
angular.module('angle').controller('TodoListController',
['$scope', '$meteor',
function($scope, $meteor){
var vm = this;
vm.tasks = $meteor.collection(Tasks);
}]
);
the "tasks" collection is loaded in the "lib" folder and has documents inserted
meteor:PRIMARY> db.tasks.find()
{ "_id" : ObjectId("55bf7d98251a0c51417732bf"), "text" : "zweiter eintrag", "createdAt" : ISODate("2015-08-03T14:41:28.534Z") }
{ "_id" : ObjectId("55bf7dab251a0c51417732c0"), "text" : "zweiter eintrag", "createdAt" : ISODate("2015-08-03T14:41:47.045Z") }
{ "_id" : ObjectId("55bf7dac251a0c51417732c1"), "text" : "zweiter eintrag", "createdAt" : ISODate("2015-08-03T14:41:48.685Z") }
{ "_id" : ObjectId("55bf7dad251a0c51417732c2"), "text" : "zweiter eintrag", "createdAt" : ISODate("2015-08-03T14:41:49.003Z") }
{ "_id" : ObjectId("55bf7dad251a0c51417732c3"), "text" : "zweiter eintrag", "createdAt" : ISODate("2015-08-03T14:41:49.261Z") }
lib/js/databases.js
Tasks = new Mongo.Collection('tasks');
But when I run my app and click on the "Todolist" I can't see anything. It doesnt list any task.text... If I use a static array instead of mongodb everything works fine. (for example: vm.tasks = [{ text: "Task1" },{ text: "task2" }]; ).
But with mongodb noting is showing. I checked the database connection, this works. I dont get any errors, when loading the app and accessing the "Todolist".
Any ideas?
Regards,
Simon
Ok problem is solved.
I created the databases.js in the "myapp/client/lib" folder instead of the pure "myapp/lib" folder.
bad mistake... but its solved :) Thanks for help!
Related
I need to do a post request using a JSON file. The JSON is currently looking like this:
{
"compositeRequest" : [{
// Account
"method" : "POST",
"url" : "/services/data/v52.0/sobjects/Account",
"referenceId" : "refAccount",
"body" : {
"Name" : req.body.accName
}
},{
// Contact
"method" : "POST",
"url" : "/services/data/v52.0/sobjects/Contact",
"referenceId" : "refContact",
"body" : {
"LastName" : req.body.conLastName,
"AccountId" : "#{refAccount.id}"
}
},{
// Order
"method" : "POST",
"url" : "/services/data/v52.0/sobjects/Order",
"referenceId" : "refOrder",
"body" : {
"AccountId" : "#{refAccount.id}",
"Pricebook2Id" : PBResult.records[0].Id,
"EffectiveDate" : date,
"Status" : "Draft"
}
},{
// OrderItem
"method" : "POST",
"url" : "/services/data/v52.0/sobjects/OrderItem",
"referenceId" : "refOrderItem",
"body" : {
"Product2Id" : req.params.productId,
"OrderId" : "#{refOrder.id}",
"Quantity" : req.body.itemQuantity,
"PricebookEntryId" : entryResult.records[0].Id,
"UnitPrice" : entryResult.records[0].UnitPrice,
"blng__BillableUnitPrice__c": entryResult.records[0].UnitPrice,
"SBQQ__ChargeType__c": prodResult.records[0].SBQQ__ChargeType__c,
"blng__TaxRule__c": prodResult.records[0].blng__TaxRule__c,
"blng__BillingRule__c": prodResult.records[0].blng__BillingRule__c,
"blng__RevenueRecognitionRule__c": prodResult.records[0].blng__RevenueRecognitionRule__c,
"ServiceDate": date,
"blng__LastChargeToDate__c": date
}
}
]
}
I want to generate more OrderItem objects(indicated in the comment) based on the size of an array, how can I do this? I already have the data that I need to add on the body. Is it possible to create a function to create another OrderItem, and place it after the already existing one (it would even be better if I was going to create the first OrderItem from zero).
Thanks in advance.
If you want to add something to an object, you have to use
Object.assign(myObject, data);
If you want to add something to an array, you have to use:
myArray.push(data);
As I donĀ“t really understand the structure of your data construct, I just try to refer to // OrderItem, which you marked. In this case it would be something like:
let newOrderItem = {
// OrderItem
"method" : "POST",
"url" : "/services/data/v52.0/sobjects/OrderItem",
"referenceId" : "refOrderItem",
"body" : {
"Product2Id" : req.params.productId,
"OrderId" : "#{refOrder.id}",
"Quantity" : req.body.itemQuantity,
"PricebookEntryId" : entryResult.records[0].Id,
"UnitPrice" : entryResult.records[0].UnitPrice,
"blng__BillableUnitPrice__c": entryResult.records[0].UnitPrice,
"SBQQ__ChargeType__c": prodResult.records[0].SBQQ__ChargeType__c,
"blng__TaxRule__c": prodResult.records[0].blng__TaxRule__c,
"blng__BillingRule__c": prodResult.records[0].blng__BillingRule__c,
"blng__RevenueRecognitionRule__c": prodResult.records[0].blng__RevenueRecognitionRule__c,
"ServiceDate": date,
"blng__LastChargeToDate__c": date
}
yourObject.compositeRequest.push(newOrderItem)
I'm developing a chat in angularjs where I have a chat list view and a chat view.
What I'm trying to do is sorting my chat list to show the most recent chat on top using Firebase and JS, I did my research but all of the questions I found they have the date directly as a child but inside my DB my date is inside a 'lastMessage' key. My dates are the following format.
date: 1528417493034
Any help would be highly appreciated
My structure is the following:
"Users": {
"nCsXbTl8CcXvoviuL5Tt7kiV6Bn1" : {
"contacts" : {
"VN9AFnn4uXgDfoir8DWHnw54zrJ3" : {
"email" : "test#test.com",
"lastMessage" : {
"date" : 1528417493034,
"senderId" : "VN9AFnn4uXgDfoir8DWHnw54zrJ3",
"status" : "success",
"text" : "Yes?",
"type" : "text",
"uid" : "1528417493034VN9AFnn4uXgDfoir8DWHnw54zrJ3"
},
"name" : "test"
},
"cHuR26YaSgbO7ahSVLg1XG5HYer2" : {
"email" : "aaa#aaa.com",
"lastMessage" : {
"date" : 1528417068249,
"senderId" : "cHuR26YaSgbO7ahSVLg1XG5HYer2",
"status" : "success",
"text" : "Trigeeeers?",
"type" : "text",
"uid" : "1528417068249cHuR26YaSgbO7ahSVLg1XG5HYer2"
},
"name" : "aaa"
}
}
}
My chat list view is the following:
<div layout="row" class="main-chat-container" layout-wrap>
<div class="list-container" flex="30">
<div class="chat-header">
<p>Lista de Chats</p>
</div>
<div class="chats-list">
<div class="chats-header">
<p>Usuarios</p>
</div>
<div class="chats" ng-repeat="chat in chats">
<div class="email-container" ng-click="setUserData(chat)" ng-class="styleData.email == chat.email ? 'new-background' : ''">
<a>{{chat.email}}</a> <p ng-show="counter > 1">{{testData.number}}</p>
</div>
</div>
</div>
</div>
<div class-"chat-container" flex="70">
<ui-view></ui-view>
</div>
And the controller is the following
app.controller('chatController', function (currentAuth, $scope, $firebaseArray, $firebaseObject) {
$scope.chats = [];
$scope.getContactsList = function(){
var listRef = firebase.database().ref('Users').child(currentAuth.uid).child('contacts');
var test = firebase.database().ref('Users').child(currentAuth.uid).child('contacts');
var listArray = $firebaseArray(listRef);
var testArray = $firebaseArray(test);
$scope.chats = listArray;
console.log("TEST ARRAY IS ");
console.log(testArray);
}
$scope.getContactsList();
});
To so a users contacts on the timestamp of their last message, you'd do something like this:
var userRef = firebase.database().ref('Users').child(currentAuth.uid)
var contactsQuery = userRef.child('contacts').orderByChild("lastMessage/date");
Note that this will give you the contacts in chronological order, so you will have to reverse the result in your client.
Alternatively some folks keep an inverted value in a separate property in their database, e.g.
"VN9AFnn4uXgDfoir8DWHnw54zrJ3" : {
"email" : "test#test.com",
"lastMessage" : {
"date" : 1528417493034,
"invertedDate" : -1528417493034,
"senderId" : "VN9AFnn4uXgDfoir8DWHnw54zrJ3",
Since this invertedDate value is inverted, ordering on that property would give you the contacts in reverse chronological order, so that you don't have to reverse them in the client.
My attempts at retrieving the value of a firebase record are failing. My JSON is as follows:
{
"accounts" : {
"-KRPSyO4B48IpBnHBTYg" : {
"dateCreated" : "",
"email" : "",
"provider" : "",
"userId" : ""
}
},
"products" : {
"-KUKRafaNurpFhGF4jQa" : {
"name" : ""
}
},
"total" : 1
}
I'm trying to return the value of "total". Here's the latest attampt:
var totals = firebase.database().ref('total').once('value', function(products) {});
$scope.totalPosts = totals;
and my HTML:
<div class="card" ng-controller="myController">{{totalPosts}}</div>
All I'm getting is an empty {}. What am I doing wrong?
Thanks in advance!
Firebase queries are asynchronous, try this.
firebase.database().ref('total').once('value', function(products) {
$scope.totalPosts = products.val();
});
Read and write Data
i try to implement the UploadCollection, according to this example. But i can`t make it runnable.
DataMock:
var data = {
"attachments" : [
{
"contributor" : "Susan Baker",
"documentId" : "64469d2f-b3c4-a517-20d6-f91ebf85b9da",
"enableEdit" : true,
"enableDelete" : true,
"fileName" : "Screenshot.jpg",
"fileSize" : 20,
"mimeType" : "image/jpg",
"thumbnailUrl" : "",
"uploadedDate" : "2014-07-30",
"url" : "image/orianda.png"
}, {
"contributor" : "John Smith",
"documentId" : "5082cc4d-da9f-2835-2c0a-8100ed47bcde",
"enableEdit" : true,
"enableDelete" : false,
"fileName" : "Notes.txt",
"fileSize" : 10,
"mimeType" : "text/plain",
"thumbnailUrl" : "",
"uploadedDate" : "2014-08-01",
"url" : "image/orianda.png"
}
]};
Dosen`t work
sap.ui.getCore().setModel(new sap.ui.model.json.JSONModel(), "runtime" )
var oRuntime = sap.ui.getCore().getModel("runtime");
Runtime.setData( data );
and view.xml:
<UploadCollection id="UploadCollection" maximumFilenameLength="55" multiple="true" change="onChange" fileDeleted="onFileDeleted" fileRenamed="onFileRenamed" fileSizeExceed="onFileSizeExceed" typeMissmatch="onTypeMissmatch" uploadComplete="onUploadComplete" items="{runtime>/attachments}">
<items>
<UploadCollectionItem contributor="{contributor}" documentId="{documentId}" fileName="{fileName}" fileSize="{fileSize}" mimeType="{mimeType}" thumbnailUrl="{thumbnailUrl}" uploadedDate="{uploadedDate}" url="{url}" enableEdit="{enableEdit}" enableDelete="{enableDelete}" />
</items>
</UploadCollection>
Works almost:
sap.ui.getCore().setModel(new sap.ui.model.json.JSONModel() )
var oRuntime = sap.ui.getCore().getModel();
Runtime.setData( data );
and view.xml:
<UploadCollection id="UploadCollection" maximumFilenameLength="55" multiple="true" change="onChange" fileDeleted="onFileDeleted" fileRenamed="onFileRenamed" fileSizeExceed="onFileSizeExceed" typeMissmatch="onTypeMissmatch" uploadComplete="onUploadComplete" items="{/attachments}">
<items>
<UploadCollectionItem contributor="{contributor}" documentId="{documentId}" fileName="{fileName}" fileSize="{fileSize}" mimeType="{mimeType}" thumbnailUrl="{thumbnailUrl}" uploadedDate="{uploadedDate}" url="{url}" enableEdit="{enableEdit}" enableDelete="{enableDelete}" />
</items>
</UploadCollection>
The first version loads the two items, but the values for each item is empty.
The second version loads the items correct. The only difference is the named model.
Both versions throw an error, when i try to upload something.
Cannot read property 'addEventListener' of undefined -
What did i wrong?
update: i figured out; its caused by the mock server.The rootURI dosent macht with the upload URI, therefore it should not influents it.
I will open a bug report, if someone can confirm me that this is a bug.
jQuery.sap.require("sap.ui.core.util.MockServer");
var sMockdataBaseUrl = "testdata/data/"
var sMetadataUrl = "testdata/metadata.xml"
sap.ui.core.util.MockServer.config({
autoRespond : true,
autoRespondAfter : 3000
});
var oMockServer = new sap.ui.core.util.MockServer({
rootUri : '/server/'
});
oMockServer.simulate(sMetadataUrl, {
'sMockdataBaseUrl' : sMockdataBaseUrl,
'bGenerateMissingMockData' : true
});
oMockServer.start();
I replicated the scenario and it is perfectly working fine.
Here is example I tried.
https://github.com/Sarathchandrach/openui5examples/tree/master/UploadCollectionDemo.
and Sample code I tried.
Controller:
var oModel = new sap.ui.model.json.JSONModel();
oModel.setData({
modelData: data
});
this.getView().setModel(oModel, "oAppView");
View:
<UploadCollection id="UploadCollection" maximumFilenameLength="55" multiple="true" change="onChange" fileDeleted="onFileDeleted" fileRenamed="onFileRenamed" fileSizeExceed="onFileSizeExceed" typeMissmatch="onTypeMissmatch" uploadComplete="onUploadComplete" items="{oAppView>/modelData/attachments}">
<items>
<UploadCollectionItem contributor="{oAppView>contributor}" documentId="{oAppView>documentId}" fileName="{oAppView>fileName}" fileSize="{oAppView>fileSize}" mimeType="{oAppView>mimeType}" thumbnailUrl="{oAppView>thumbnailUrl}" uploadedDate="{oAppView>uploadedDate}" url="{oAppView>url}" enableEdit="{oAppView>enableEdit}" enableDelete="{oAppView>enableDelete}" />
</items>
</UploadCollection>
I have an angular.js single page app, with initial data gathered from a rest endpoint.
This app gets a list of IDs representing a saved models, as well as a tree of options to populate some cascading dropdowns.
How can I set the default path in the tree based on my IDs from the model?
Some illustrative code:
Models:
DefaultOptions = [
{"Id" : 044},
{"Id" : 142},
{"Id" : 244}
];
OptionsTree = [
{"Text" : "Option1",
"subOptions" : [
{"Text" : "SubOption1", "Id" : 044},
{"Text" : "SubOption2", "Id" : 142}
]},
{"Text" : "Option2",
"subOptions" : [
{"Text" : "SubOptionA", "Id" : 3033},
{"Text" : "SubOptionB", "Id" : 244}
]}
];
HTML:
<div ng-repeat="member in DefaultOptions">
<select ng-model="option"
ng-options="o as o.Text for o in OptionsTree">
</select>
<select ng-model="subOption"
ng-options="s as s.Text for s in option.subOptions"
ng-disabled="!option"
ng-change="member.Id = subOption.Id">
</select>
</div>
This HTML will properly update the DefaultOptions ID if the user selects a new one, but cannot set the default. What am I missing?
Change your selects' ng-model to account for the ng-repeat:
Then put this in your controller:
// Main dropdown
$scope.member.option = OptionsTree[0];
and then:
// Sub dropdown
$scope.member.subOption = OptionsTree[0].subOptions[0].id
Since your question didn't state if you wanted the id or the whole object I assumed the whole object for the main dropdown and just the id for the sub dropdown.