sap.m.UploadCollection, doesn't work - javascript

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>

Related

Getting json fields from json file

I am facing a problem. I have this json log
{
"log": "Log Info : { \"datetime\" : \"datetime\", \"field1\" : \"value1\", \"field2\" : \"value2\", \"field3\" : \"value3\", \"field4\" : \"value4\", \"field5\" : \"value5\", \"field6\" : \"value6\", \"field7\" : \"value7\", \"field8\" : \"value8\", \"field9\" : \"value9\", \"field10\" : \"value10\", \"field11\" : \"value11\"}\n",
"stream": "stdout",
"kubernetes": {
"pod_name": "pod_name",
"namespace_name": "namespace_name",
"pod_id": "pod_id",
"host": "host",
"container_name": "container_name",
"docker_id": "docker_id",
"container_hash": "container_hash",
"container_image": "container_image"
}
}
I need to get all field inside "log" key. These fields will be increased, so I need to get all fields inside log dynamically. I am using this code to parse json, but the output is this. Maybe someone can help me? Thanks.
const readFile = require("fs").readFile;
readFile("log.json", (err, data) => {
if (err) throw err;
const log = JSON.parse(data);
console.log(log);
});
Output:
{
log: 'Log Info : { "datetime" : "datetime", "field1" : "value1", "
field2" : "value2", "field3" : "value3", "field4" : "value4", "field5" :
"value5", "field6" : "value6", "field7" : "value7", "field8" : "value8"
, "field9" : "value9", "field10" : "value10", "field11" : "value11"}\n',
stream: 'stdout',
kubernetes: {
pod_name: 'pod_name',
namespace_name: 'namespace_name',
pod_id: 'pod_id',
host: 'host',
container_name: 'container_name',
docker_id: 'docker_id',
container_hash: 'container_hash',
container_image: 'container_image'
}
}
You need to JSON.parse also the "inner" json (after you clean it from the prefix)
var obj = {
"log": "Log Info : { \"datetime\" : \"datetime\", \"field1\" : \"value1\", \"field2\" : \"value2\", \"field3\" : \"value3\", \"field4\" : \"value4\", \"field5\" : \"value5\", \"field6\" : \"value6\", \"field7\" : \"value7\", \"field8\" : \"value8\", \"field9\" : \"value9\", \"field10\" : \"value10\", \"field11\" : \"value11\"}\n",
"stream": "stdout",
"kubernetes": {
"pod_name": "pod_name",
"namespace_name": "namespace_name",
"pod_id": "pod_id",
"host": "host",
"container_name": "container_name",
"docker_id": "docker_id",
"container_hash": "container_hash",
"container_image": "container_image"
}
}
var str = (obj.log).substring(obj.log.indexOf(':') + 1);
//console.log(str)
var result = JSON.parse(str);
console.log(result)

Generate a json file dynamically

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)

How to use forEach in Firebase Cloud Functions while querying?

So, I have a https function, which when triggered, needs to read the current server time and get the list of items that have a target_date which is lesser than the current time. Once it gets those list of items, those respective items need to be updated by setting its 'status' value to 'completed'. I have written the function but it is throwing an error. Can you please help me fix it?
exports.checkCampaignDate = functions.https.onRequest((request, response) => {
const current_time = Date.now();
console.log("current time", current_time);
var targetRef = admin.database().ref('/Fund');
console.log("target ref", targetRef);
targetRef.orderByChild("time_left").endAt(current_time).once("value", function(snapshot) {
const artcall_list = snapshot.val();
const artcall_id = snapshot.key;
snapshot.forEach((artcallSnap) => {
console.log("Artcall Snap", artcallSnap.val());
artcallSnap.child("status").set("completed");
});
console.log("This is the list of artcalls that have this same date", artcall_list);
console.log("This is the artcall id:", artcall_id);
// do some stuff once
});
return null;
});
My database:
"Fund" : {
"-LEEy7uxXEeI4AJuePoB" : {
"amount_funded" : 5200,
"artist_name" : "Sean Roldan and Friends",
"genre" : "Indian Blues and Jazz",
"image_url" : "https://firebasestorage.googleapis.com/v0/b/artcall-f8f1a.appspot.com/o/profile_images%2Fthumbs%2Fseanroldan.jpg?alt=media&token=6414d8d6-e8a8-487e-baf3-0d36d017a205",
"percent_funded" : 0.29714285714285715,
"perf_location" : "Chennai",
"reward_amt" : 6000,
"target_amount" : 1750000,
"target_date" : 1566568176731,
"time_left" : 1566568176731,
"total_backers" : 1
"status" : "incomplete"
},
"-asdffdsa123" : {
"amount_funded" : 0,
"artist_name" : "Agam",
"genre" : "Rock",
"image_url" : "default",
"percent_funded" : 0,
"perf_location" : "Chennai",
"target_amount" : 1300000,
"target_amt" : 1300000,
"target_date" : 1566568176731,
"time_left" : 1566568176731,
"total_backers" : 0
"status" : "incomplete"
}
},
Error:
TypeError: artcallSnap.child(...).set is not a function
at snapshot.forEach (/user_code/index.js:311:36)
at /user_code/node_modules/firebase-admin/node_modules/#firebase/database/dist/index.node.cjs.js:4255:20
at /user_code/node_modules/firebase-admin/node_modules/#firebase/database/dist/index.node.cjs.js:3669:24
at LLRBNode.inorderTraversal (/user_code/node_modules/firebase-admin/node_modules/#firebase/database/dist/index.node.cjs.js:2606:13)
at SortedMap.inorderTraversal (/user_code/node_modules/firebase-admin/node_modules/#firebase/database/dist/index.node.cjs.js:3052:27)
at ChildrenNode.forEachChild (/user_code/node_modules/firebase-admin/node_modules/#firebase/database/dist/index.node.cjs.js:3668:24)
at DataSnapshot.forEach (/user_code/node_modules/firebase-admin/node_modules/#firebase/database/dist/index.node.cjs.js:4254:31)
at /user_code/index.js:309:12
at onceCallback (/user_code/node_modules/firebase-admin/node_modules/#firebase/database/dist/index.node.cjs.js:4843:51)
at /user_code/node_modules/firebase-admin/node_modules/#firebase/database/dist/index.node.cjs.js:4465:22
at exceptionGuard (/user_code/node_modules/firebase-admin/node_modules/#firebase/database/dist/index.node.cjs.js:691:9)
at EventList.raise (/user_code/node_modules/firebase-admin/node_modules/#firebase/database/dist/index.node.cjs.js:9727:17)
at EventQueue.raiseQueuedEventsMatchingPredicate_ (/user_code/node_modules/firebase-admin/node_modules/#firebase/database/dist/index.node.cjs.js:9681:41)
at EventQueue.raiseEventsForChangedPath (/user_code/node_modules/firebase-admin/node_modules/#firebase/database/dist/index.node.cjs.js:9665:14)
at Repo.onDataUpdate_ (/user_code/node_modules/firebase-admin/node_modules/#firebase/database/dist/index.node.cjs.js:12770:26)
at PersistentConnection.onDataPush_ (/user_code/node_modules/firebase-admin/node_modules/#firebase/database/dist/index.node.cjs.js:12070:18)
at PersistentConnection.onDataMessage_ (/user_code/node_modules/firebase-admin/node_modules/#firebase/database/dist/index.node.cjs.js:12064:18)
at Connection.onDataMessage_ (/user_code/node_modules/firebase-admin/node_modules/#firebase/database/dist/index.node.cjs.js:11341:14)
at Connection.onPrimaryMessageReceived_ (/user_code/node_modules/firebase-admin/node_modules/#firebase/database/dist/index.node.cjs.js:11335:18)
at WebSocketConnection.onMessage (/user_code/node_modules/firebase-admin/node_modules/#firebase/database/dist/index.node.cjs.js:11236:27)
at WebSocketConnection.appendFrame_ (/user_code/node_modules/firebase-admin/node_modules/#firebase/database/dist/index.node.cjs.js:10841:18)
at WebSocketConnection.handleIncomingFrame (/user_code/node_modules/firebase-admin/node_modules/#firebase/database/dist/index.node.cjs.js:10891:22)
artcallSnap is a DataSnapshot, which doesn't have a set() method. To get the Reference from a snapshot, use its ref property. So:
artcallSnap.ref.child("status").set("completed")

jQuery Datatables TypeError: aData is undefined

I have a jQuery datatable that uses an Ajax data source. The table is defined as follows:
$("#tblNotes").DataTable({
"ajax" : {
"url": "/projects/ajaxGetProjectNotes/",
"type" : "post",
"dataType" : "json",
"data" : {"idProject" : "b92792db-9ea6-49bf-b4dc-1cdf3f441148"}
},
"columns" :
[
{"data" : "dComment", "width" : "130px", "orderable" : true},
{"data" : "cComment", "width" : "270px", "orderable" : false}
]
});
The ajax response from the php script is:
[{"dComment":"","cComment":""}]
I am getting an error:
TypeError: aData is undefined
for ( i=0 ; i<aData.length ; i++ ) {
-------------^
The error is coming from datatables.js (line 15748, col 18).
Here's the source of the ajax source (and the accompanying model function that retrieves the data). Note that this is codeigniter based code (but I don't think that will make much of a difference):
function ajaxGetProjectNotes(){
$id = $_POST["idProject"];
$notes = $this->projects_model->getNotes($id);
if(!isset($notes[0]["cComment"])){
$notes[0]["dComment"]="";
$notes[0]["cComment"]="";
}
echo json_encode($notes);
}
The model code:
function getNotes($idProject){
$this->db->select("*")
->from("projectnotes")
->where("idProject", $idProject);
$query = $this->db->get();
$aResult = $query->result_array();
return $aResult;
}
The error is occuring when the page loads.
Any assistance would be appreciated...

no database content is showing (Meteor, AngularJS, mongodb)

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!

Categories