Kendo grid with declarative editor template - mvvm

Hopefully someone can help me with this - I've been staring at this for 8 hours and can't seem to find a solution. I'm trying to implement a pretty simple Kendo UI MVVM grid. The grid just has a list of roles with an attached category. When you click edit, the grid should allow an inline edit and the category column should turn into a drop down - which is a template that is also bound to a field in the view model.
Here's my jsfiddle: http://jsfiddle.net/Icestorm0141/AT4XT/3/
The markup:
<script type="text/x-kendo-template" id="someTemplate">
<select class="form-control categories" data-auto-bind="false" data-value-field="CategoryId" data-text-field="Description" data-bind="source: categories"></select>
</script>
<div class="manage-roles">
<div data-role="grid"
data-scrollable="true"
data-editable="inline"
data-columns='[
{ "field" : "JobTitle", "width": 120, "title" : "Job Title Code" },
{ "field" : "Description" },
{ "field" : "Category", "template": "${Category}","editor" :kendo.template($("#someTemplate").html()) },
{"command": "edit"}]'
data-bind="source: roles"
style="height: 500px">
</div>
</div>
And the javascript:
var roleViewModel = kendo.observable({
categories: new kendo.data.DataSource({
data: [
{ "CategoryId": 1, "Description": "IT" },
{ "CategoryId": 2, "Description": "Billing" },
{ "CategoryId": 3, "Description": "HR" },
{ "CategoryId": 4, "Description": "Sales" },
{ "CategoryId": 5, "Description": "Field" },
{ "CategoryId": 10, "Description": "Stuff" },
{ "CategoryId": 11, "Description": "Unassigned" }
]
}),
roles: new kendo.data.DataSource({
data: [
{ "RoleId": 1, "JobTitle": "AADM1", "Description": "Administrative Assistant I", "Category": "Stuff", "CategoryId": 10 },
{ "RoleId": 2, "JobTitle": "AADM2", "Description": "Administrative Assistant II", "Category": null, "CategoryId": 0 },
{ "RoleId": 3, "JobTitle": "ACCIN", "Description": "Accounting Intern", "Category": null, "CategoryId": 0 },
{ "RoleId": 4, "JobTitle": "ACCSU", "Description": "Accounting Supervisor", "Category": null, "CategoryId": 0 }, { "RoleId": 5, "JobTitle": "ACCTC", "Description": "Accountant", "Category": null, "CategoryId": 0 }
]
})
});
kendo.bind($(".manage-roles"), roleViewModel);
I havent been able to figure out why the editor template is not binding the drop down. When I use the same markup for template rather than binding to the category name with ${Category}, it works for the template property. (For some reason this doesnt work in fiddle. But the exact same code works locally).
At this point I'll take any suggestions/approaches anything. I really wanted to use MVVM and not the .kendoGrid() syntax but I'll get over myself if it cannot be done. Anyone got any insight into whats going on with the editor template?

You can still build your grid using MVVM, but I think you have to make custom editors with a function call.
So instead of "editor" :kendo.template($("#someTemplate").html()), you just call a function.
edit: rolesViewModel.categoryEditor
See http://demos.kendoui.com/web/grid/editing-custom.html
See sample http://jsbin.com/UQaZaXO/1/edit

Related

Shopify REST API: Unable to add a new product variant with new option type getting error "Option values provided for 1 unknown option(s)"

when creating a product in Shopify via the REST API, adds a default option and variant like below
"options": [
{
"id": 9651869188247,
"product_id": 7644173172887,
"name": "Title",
"position": 1,
"values": [
"Default Title"
]
}
]
Variants:
{
"variants": [
{
"id": 42211487744151,
"product_id": 7644173172887,
"title": "Default Title",
"price": "1.00",
"sku": "",
"position": 1,
"inventory_policy": "deny",
"compare_at_price": null,
"fulfillment_service": "manual",
"inventory_management": "shopify",
"option1": "Default Title",
"option2": null,
"option3": null,
"created_at": "2022-06-17T17:18:24+05:30",
"updated_at": "2022-06-17T17:18:24+05:30",
"taxable": true,
"barcode": null,
"grams": 0,
"image_id": null,
"weight": 0.0,
"weight_unit": "kg",
"inventory_item_id": 44310083534999,
"inventory_quantity": 0,
"old_inventory_quantity": 0,
"requires_shipping": true,
"admin_graphql_api_id": "gid://shopify/ProductVariant/42211487744151"
}
]
}
I want to update the existing Option and Variants of a product to show "Color" & "Size" as options and variants of them. For that I tried the Shopify Rest API but that still is raising the below error
request model:
{
"variant": {
"product_id": 7644173172887,
"option1": "red",
"option2": "small",
"price": "1.0",
"title": "S"
}
}
response :
{
"errors": {
"base": [
"Option values provided for 1 unknown option(s)"
]
}
}
You are not specifing what endpoint you're using but I can see that you're specifing the Product Id and that should not be the case. If you need to add a new variant this is the request you should do
POST https://yourstore.myshopify.com/admin/api/2022-04/products/7644173172887/variants.json
{"variant":{"option1":"Red", "option2" :"Small", "title": "Red", "price":"1.00"}}
You will also need to update the current "Default Title" variant (I suggest, if possible to create the product with a valid variant).
PUT https://yourstore.myshopify.com/admin/api/2022-04/variants/42211487744151.json
{"variant":{"id":42211487744151,"option1":"Red","option2" : "S", "price":"99.00", "title" : "Red"}}

How to get nested "Sequelize" data?

I have created a Sequelize ORM based PostgreSQL database. I have implemented some relation between product and reviews. And, each review has been posted by a user. So, when I am querying for a single product, I want the data with, product, reviews & inside review I want to see who posted as well means user.
{
"id": 1,
"name": "Rounded Neck T-Shirt",
"title": "some title",
"snippet": "some snippet od demin t shirt",
"details": "some details",
"moreInfo": "some moreInfo",
"size": "size will be in a seperate table this will be FK",
"stock": 452,
"askingPrice": 4299,
"offPrice": null,
"offer": null,
"ratings": null,
"images": null,
"pictureUrl": "https://loopinfosol.in/themeforest/ekka-html-v31/ekka-html/assets/images/product-image/6_2.jpg",
"purchaseCost": 4200,
"createdAt": "2022-02-14T10:59:55.999Z",
"updatedAt": "2022-02-14T11:07:12.916Z",
"categoryId": 1,
"userId": 1,
"reviews": [
{
"id": 1,
"rating": 5,
"comment": "Very nice product",
"createdAt": "2022-02-14T17:28:22.680Z",
"updatedAt": "2022-02-14T17:28:22.680Z",
"productId": 1,
"userId": 1
}
]
}
Here, "userId" is the foreign key for the registered user id. I want to see the user data inside "reviews" as well. How can I do that?
I get the above JSON data by querying the following code.
Product.findOne({
include: [Review],
where: { id: req.params.id },
})
If you already have an association definition like Review.belongsTo(User, ... then you simply need to indicate a nested include option with User model:
Product.findOne({
include: [{
model: Review,
include: [{
model: User
}]
}],
where: { id: req.params.id },
})

Updating Mongo DB collection field from object to array of objects

I had to change one of the fields of my collection in mongoDB from an object to array of objects containing a lot of data. New documents get inserted without any problem, but when attempted to get old data, it never maps to the original DTO correctly and runs into errors.
subject is the field that was changed in Students collection.
I was wondering is there any way to update all the records so they all have the same data type, without losing any data.
The old version of Student:
{
"_id": "5fb2ae251373a76ae58945df",
"isActive": true,
"details": {
"picture": "http://placehold.it/32x32",
"age": 17,
"eyeColor": "green",
"name": "Vasquez Sparks",
"gender": "male",
"email": "vasquezsparks#orbalix.com",
"phone": "+1 (962) 512-3196",
"address": "619 Emerald Street, Nutrioso, Georgia, 6576"
},
"subject":
{
"id": 0,
"name": "math",
"module": {
"name": "Advanced",
"semester": "second"
}
}
}
This needs to be updated to the new version like this:
{
"_id": "5fb2ae251373a76ae58945df",
"isActive": true,
"details": {
"picture": "http://placehold.it/32x32",
"age": 17,
"eyeColor": "green",
"name": "Vasquez Sparks",
"gender": "male",
"email": "vasquezsparks#orbalix.com",
"phone": "+1 (962) 512-3196",
"address": "619 Emerald Street, Nutrioso, Georgia, 6576"
},
"subject": [
{
"id": 0,
"name": "math",
"module": {
"name": "Advanced",
"semester": "second"
}
},
{
"id": 1,
"name": "history",
"module": {
"name": "Basic",
"semester": "first"
}
},
{
"id": 2,
"name": "English",
"module": {
"name": "Basic",
"semester": "second"
}
}
]
}
I understand there might be a way to rename old collection, create new and insert data based on old one in to new one. I was wondering for some direct way.
The goal is to turn subject into an array of 1 if it is not already an array, otherwise leave it alone. This will do the trick:
update args are (predicate, actions, options).
db.foo.update(
// Match only those docs where subject is an object (i.e. not turned into array):
{$expr: {$eq:[{$type:"$subject"},"object"]}},
// Actions: set subject to be an array containing $subject. You MUST use the pipeline version
// of the update actions to correctly substitute $subject in the expression!
[ {$set: {subject: ["$subject"] }} ],
// Do this for ALL matches, not just first:
{multi:true});
You can run this converter over and over because it will ignore converted docs.
If the goal is to convert and add some new subjects, preserving the first one, then we can set up the additional subjects and concatenate them into one array as follows:
var mmm = [ {id:8, name:"CORN"}, {id:9, name:"DOG"} ];
rc = db.foo.update({$expr: {$eq:[{$type:"$subject"},"object"]}},
[ {$set: {subject: {$concatArrays: [["$subject"], mmm]} }} ],
{multi:true});

Unable to create a form with multiple FormFields using REST API for Oracle Eloqua Marketing Cloud Service?

I am testing the REST API for Oracle Eloqua Marketing Cloud Service method for creating forms using POSTMAN.
REST API link.
When I give single form field, form is getting created. this is my request:
POST /assets/form
Content-Type: application/json
But when I try to create form with multiple form fields like here:
Request body: {
"type": "Form",
"createdAt": "1510563258",
"createdBy": "9",
"folderId": "7",
"name": "Form with 3 fields_de-DE1254",
"updatedAt": "1510563258",
"elements": [
{
"style": "{\"fieldSize\":\"large\",\"labelPosition\":\"top\"}",
"type": "FormField",
"name": "Æddrèëss 2",
"dataType": "text",
"displayType": "text",
"htmlName": "address2",
"useGlobalSubscriptionStatus": "False",
"validations": []
},
{
"style": "{\"fieldSize\":\"large\",\"labelPosition\":\"top\"}",
"type": "FormField",
"name": "Æddrèëss 3",
"dataType": "text",
"displayType": "text",
"htmlName": "address3",
"useGlobalSubscriptionStatus": "False",
"validations": []
}
]
}
I get error:
Status : 500 InternalServerError
<html>
<head>
<title>Internal Server Error</title>
</head>
<body>
<h1>
Internal Server Error
</h1>
<div>
There was an internal server error.
</div>
<div>
The error has been logged with log identifier
<b>115451307</b>.
</div>
<div>
Please provide this log identifier to technical support.
</div>
</body>
</html>
Please can someone help me with this? Also what is is this log identifier and where can I find it?
I just had this and got the solution from support. You need to put in a unique and negative integer for the field ids. After doing this, you can send in an array of form fields and they will all get processed in one call. The response will contain the newly generated ids, if successful.
Here's the modified snippet:
Request body: {
"type": "Form",
"createdAt": "1510563258",
"createdBy": "9",
"folderId": "7",
"name": "Form with 3 fields_de-DE1254",
"updatedAt": "1510563258",
"elements": [
{
"id": "-1",
"style": "{\"fieldSize\":\"large\",\"labelPosition\":\"top\"}",
"type": "FormField",
"name": "Æddrèëss 2",
"dataType": "text",
"displayType": "text",
"htmlName": "address2",
"useGlobalSubscriptionStatus": "False",
"validations": []
},
{
"id": "-2",
"style": "{\"fieldSize\":\"large\",\"labelPosition\":\"top\"}",
"type": "FormField",
"name": "Æddrèëss 3",
"dataType": "text",
"displayType": "text",
"htmlName": "address3",
"useGlobalSubscriptionStatus": "False",
"validations": []
}
]
}

how to code sap.m.sample.ListGrouping by using js view in openui5

hi i need List grouping control by using js view.but openui5 provides code by using xml view.
https://openui5.hana.ondemand.com/explored.html#/sample/sap.m.sample.ListGrouping/preview
how to convert this code into js view and how to make ListGrouping able to selection for both element level and group level and change this as dropdown box
List.view.xml
<mvc:View
controllerName="sap.m.sample.ListGrouping.List"
xmlns:l="sap.ui.layout"
xmlns:mvc="sap.ui.core.mvc"
xmlns="sap.m">
<List
items="{
path: '/ProductCollection',
sorter: {
path: 'SupplierName',
descending: false,
group: true
},
groupHeaderFactory: '.getGroupHeader'
}"
headerText="Products" >
<StandardListItem
title="{Name}"
description="{ProductId}"
icon="{ProductPicUrl}"
iconDensityAware="false"
iconInset="false" />
</List>
</mvc:View>
List.controller.js
sap.ui.define([
'jquery.sap.global',
'sap/m/GroupHeaderListItem',
'sap/ui/core/mvc/Controller',
'sap/ui/model/json/JSONModel'
], function(jQuery, GroupHeaderListItem, Controller, JSONModel) {
"use strict";
var ListController = Controller.extend("sap.m.sample.ListGrouping.List", {
onInit : function (evt) {
// set explored app's demo model on this sample
var oModel = new JSONModel(jQuery.sap.getModulePath("sap.ui.demo.mock", "/products.json"));
this.getView().setModel(oModel);
},
getGroupHeader: function (oGroup){
return new GroupHeaderListItem( {
title: oGroup.key,
upperCase: false
} );
}
});
return ListController;
});
how to write the same code by using js view
I have tried like as follows, but i am getting Error: Missing template or factory function for aggregation items of Element sap.m.List#__list0 !
List.view.js
sap.ui.jsview("oui5mvc.List", {
getControllerName : function() {
return "oui5mvc.List";
},
createContent : function(oController) {
odbbshiftGlobalId = this.getId();
var oMyFlexbox = new sap.m.FlexBox({
items: [
oList = new sap.m.List({
width: '500px',
group: true,
groupHeaderFactory: '.getGroupHeader',
items: [
]
}),
]
});
oMyFlexbox.placeAt(this.getId()).addStyleClass("tes");
}
});
List.controller.js
sap.ui.controller("oui5mvc.List", {
onInit: function() {
var data = {
"ProductCollection": [
{
"ProductId": "1239102",
"Name": "Power Projector 4713",
"Category": "Projector",
"SupplierName": "Titanium",
"Description": "A very powerful projector with special features for Internet usability, USB",
"WeightMeasure": 1467,
"WeightUnit": "g",
"Price": 856.49,
"CurrencyCode": "EUR",
"Status": "Available",
"Quantity": 3,
"UoM": "PC",
"Width": 51,
"Depth": 42,
"Height": 18,
"DimUnit": "cm",
"ProductPicUrl": "https://openui5.hana.ondemand.com/test-resources/sap/ui/demokit/explored/img/HT-6100.jpg"
},
{
"ProductId": "2212-121-828",
"Name": "Gladiator MX",
"Category": "Graphics Card",
"SupplierName": "Technocom",
"Description": "Gladiator MX: DDR2 RoHS 128MB Supporting 512MB Clock rate: 350 MHz Memory Clock: 533 MHz, Bus Type: PCI-Express, Memory Type: DDR2 Memory Bus: 32-bit Highlighted Features: DVI Out, TV Out , HDTV",
"WeightMeasure": 321,
"WeightUnit": "g",
"Price": 81.7,
"CurrencyCode": "EUR",
"Status": "Discontinued",
"Quantity": 10,
"UoM": "PC",
"Width": 34,
"Depth": 14,
"Height": 2,
"DimUnit": "cm",
"ProductPicUrl": "https://openui5.hana.ondemand.com/test-resources/sap/ui/demokit/explored/img/HT-1071.jpg"
},
{
"ProductId": "K47322.1",
"Name": "Hurricane GX",
"Category": "Graphics Card",
"SupplierName": "Red Point Stores",
"Description": "Hurricane GX: DDR2 RoHS 512MB Supporting 1024MB Clock rate: 550 MHz Memory Clock: 933 MHz, Bus Type: PCI-Express, Memory Type: DDR2 Memory Bus: 64-bit Highlighted Features: DVI Out, TV-In, TV-Out, HDTV",
"WeightMeasure": 588,
"WeightUnit": "g",
"Price": 219,
"CurrencyCode": "EUR",
"Status": "Out of Stock",
"Quantity": 25,
"UoM": "PC",
"Width": 34,
"Depth": 14,
"Height": 2,
"DimUnit": "cm",
"ProductPicUrl": "https://openui5.hana.ondemand.com/test-resources/sap/ui/demokit/explored/img/HT-1072.jpg"
},
],
"ProductCollectionStats": {
"Counts": {
"Total": 14,
"Weight": {
"Ok": 7,
"Heavy": 5,
"Overweight": 2
}
},
"Groups": {
"Category": {
"Projector": 1,
"Graphics Card": 2,
"Accessory": 4,
"Printer": 2,
"Monitor": 3,
"Laptop": 1,
"Keyboard": 1
},
"SupplierName": {
"Titanium": 3,
"Technocom": 3,
"Red Point Stores": 5,
"Very Best Screens": 3
}
},
"Filters": [
{
"type": "Category",
"values": [
{
"text": "Projector",
"data": 1
},
{
"text": "Graphics Card",
"data": 2
},
{
"text": "Accessory",
"data": 4
},
{
"text": "Printer",
"data": 2
},
{
"text": "Monitor",
"data": 3
},
{
"text": "Laptop",
"data": 1
},
{
"text": "Keyboard",
"data": 1
}
]
},
{
"type": "SupplierName",
"values": [
{
"text": "Titanium",
"data": 3
},
{
"text": "Technocom",
"data": 3
},
{
"text": "Red Point Stores",
"data": 5
},
{
"text": "Very Best Screens",
"data": 3
}
]
}
]
}
};
var oTemplate11 = new sap.m.StandardListItem({title : "{Name}"});
oList.setModel(new sap.ui.model.json.JSONModel(data));
oList.bindItems("/ProductCollection");
oList.placeAt('content');
},
getGroupHeader: function (oGroup){
return new sap.m.GroupHeaderListItem( {
title: oGroup.key,
upperCase: false
});
},
});
Your call to bind items to the list is not entirely correct.
The method takes an object with binding information as parameter instead of just the path to the model property. See the documentation for bindItems and bindAggregation in general.
In your case it should look like
oList.bindItems({
path: "/ProductCollection",
template: new sap.m.StandardListItem({
title: "{Name}",
description: "{ProductId}",
icon: "{ProductPicUrl}"
})
});