SAPUI5 root view - javascript

I have a problem with rootview. I want create 2 views (login form and home with navigation list).
this is my home view:
I want when I clicked menu in left (root item 1, 2, etc), show content form (just content and still showing menu). I success when root view set to home view but in login view have menu component (navigation list). I want set root view to Home when i load home view, and set root view to other (exclude Home view) when i load login view.
Component.js :
sap.ui.define([
"sap/ui/core/UIComponent"
], function (UIComponent) {
"use strict";
return UIComponent.extend("sap.ui.demo.Component", {
metadata: {
manifest: "json"
},
createContent : function() {
// create root view
var oView = sap.ui.view({
id : "mainContents",
viewName : "sap.ui.demo.template.App",
type : "XML", // <-- change this to JSON
viewData : {
component : this
}
});
// done
return oView;
},
init: function () {
// call the init function of the parent
UIComponent.prototype.init.apply(this, arguments); // calling parent UIComponents
// create the views based on the url/hash
this.getRouter().initialize(); // initializing router
// this.i18nModel(); // set i18n model
},
i18nModel : function(){
var i18nModel = new ResourceModel({
bundleName: "sap.ui.demo.template.i18n.i18n"
});
this.setModel(i18nModel, "i18n");
}
});
});
manifest.json:
{
"_version": "1.1.0",
"sap.app": {
"_version": "1.1.0",
"id": "sap.ui.demo.template",
"type": "application",
"i18n": "i18n/i18n.properties",
"title": "{{appTitle}}",
"description": "{{appDescription}}",
"applicationVersion": {
"version": "1.0.0"
}
},
"sap.ui": {
"_version": "1.1.0",
"technology": "UI5",
"deviceTypes": {
"desktop": true,
"tablet": true,
"phone": true
},
"supportedThemes": [
"sap_hcb",
"sap_bluecrystal",
"sap_belize"
]
},
"sap.ui5": {
"_version": "1.1.0",
"rootView":
{
"viewName": "sap.ui.demo.template.Home",
"type": "XML",
"id": "app"
}
,
"dependencies" : {
"minUI5Version": "1.30",
"libs": {
"sap.ui.core": {},
"sap.m": {},
"sap.tnt": {},
"sap.ui.layout": {}
}
},
"models": {
"i18n": {
"type": "sap.ui.model.resource.ResourceModel",
"settings": {
"bundleName": "sap.ui.demo.template.i18n.i18n"
}
}
},
"routing": {
"config": {
"routerClass": "sap.m.routing.Router",
"controlId": "mainContents",
"viewType": "XML",
"controlAggregation": "pages",
"viewPath": "sap.ui.demo.template",
"async": true
},
"routes": [
{
"pattern": "",
"name": "first",
"target": "first"
},
{
"pattern": "home",
"name": "home",
"target": "second"
},
{
"pattern": "page1",
"name": "page1",
"target": "page1"
},
{
"pattern": "login",
"name": "login",
"target": "login"
},
{
"pattern": "mainContents",
"name": "mainContents",
"target": "mainContents"
}
],
"targets": {
"first": {
"viewName": "Index"
},
"second": {
"viewName": "Home"
},
"page1": {
"viewName": "Page1"
},
"login": {
"viewName": "Index"
},
"mainContents": {
"viewName": "Home"
}
}
}
}
}
I if set root view to Home :
I want to this:
when I set rootview to App, login true but home view false.
App view:
<mvc:View
xmlns="sap.m"
xmlns:mvc="sap.ui.core.mvc"
displayBlock="false">
<App id="mainContents" class="blueBackground">
</App>
</mvc:View>
How to fix this problem about rootview?
Thanks. Bobby.

Set rootview to one view, Handle the rest of the view traversals in controller, with router.navTo() function where you can specify pattern as well.
Just do a cleanup while navigating to another view, destroy the menu created. and create it again on traversal to the concerned view

Related

How to pass an array value to Router.navTo in SAPUI5

I have this call in a SAPUI5 code. Before the soldTo was a simple comboBox, but I changed it for a multiComboBox. So, now this.soldTo is an array.
this._oRouter.navTo("SearchResult", {
soldTo: this.soldTo,
shipTo: this.shipTo,
}, false);
The routing in manifest.json is defined like this:
"routing": {
"config": {
"routerClass": "sap.m.routing.Router",
"viewType": "XML",
"async": true,
"viewPath": "com.openOrder.AM.view",
"controlAggregation": "pages",
"controlId": "app",
"clearControlAggregation": false
},
"routes": [
{
"name": "RouteApp",
"pattern": "",
"target": [
"Search"
]
},
{
"pattern": "{soldTo}/{shipTo}/SearchResult",
"name": "SearchResult",
"target": [
"SearchResult"
]
},
{
"name": "ResultDetails",
"pattern": "{}/ResultDetails",
"target": [
"ResultDetails"
]
}
],
"targets": {
"Search": {
"viewType": "XML",
"transition": "slide",
"clearControlAggregation": false,
"viewName": "Search",
"viewLevel": 1
},
"SearchResult": {
"viewType": "XML",
"transition": "slide",
"clearControlAggregation": false,
"viewName": "SearchResult",
"viewLevel": 2
},
"ResultDetails": {
"viewType": "XML",
"transition": "slide",
"clearControlAggregation": false,
"viewName": "ResultDetails",
"viewLevel": 3
}
}
}
I'm getting this error after change.
"Uncaught TypeError: Cannot read properties of null (reading 'length')"
Does anyone has an exemple how to pass the multiComboBox values to the function Router.navTo, please?
There is no need to send the array with a URL. The URL makes only sense if you want a unique address for a specific record. Therefore you should pass it with the model on your component.
Define your model in the manifest. The definition will enable you to access it using "this.getModel(""). In your views you can access the model with "this.getOwnerComponent().getModel("").

kendo UI file manager navigation issue

HTML code:
<div id="filemanager"></div>
javascript code:
$(document).ready(function () {
$("#filemanager").kendoFileManager({
dataSource: {
transport: {
read: function (options) {
$.ajax({
method: "GET",
datatype: "json",
url: Djangourl,
success: function (result) {
console.log(result);
options.success(result);
},
error: function (result) {
options.error(result);
}
});
},
}
}
});
}
JSON returned by server:
[
{
"name": "abc",
"isDirectory": true,
"hasDirectories": true,
"path": "folder",
"extension": "",
"size": 0,
"created": "2022-07-06T11:28:46.932Z",
"createdUtc": "2022-07-06T11:28:46.932Z",
"items": [
{
"name": "abc_123",
"isDirectory": true,
"hasDirectories": true,
"path": "folder/abc_123",
"extension": "",
"size": 0,
"created": "",
"createdUtc": ""
}
],
"modified": null,
"modifiedUtc": null
}
]
Issue: folder 'abc' is displayed but item inside is not getting displayed, on double click on abc again ,ajax is calling the url. I want to display 'abc_123' directory on double click of 'abc' folder as shown in 'https://dojo.telerik.com/UpUgeZOH' example.

Why GraphQL is not detecting a new field in a JSON object

I'm new in Gatsby Development, in my website I'm using a community theme and modifying it in some things.
My problem started when I modified a JSON file called 'settings.json', where I added a field in the siteConfiguration object, the original file was this:
{"siteConfiguration": {
"logo": { "text": "chrisley"},
"navigation": {
"header": [
{ "label": "About", "url": "/#about" },
{ "label": "Blog", "url": "/blog" },
{ "label": "Features", "url": "/#features" },
{ "label": "Github", "url": "/#github" }
],
"ctaButton": {
"openNewTab": true,
"label": "Resume",
"url": "/resume.pdf"
},
"footer": [
{ "label": "Privacy", "url": "/privacy" },
{ "label": "Imprint", "url": "/imprint" }
]
},
"featureToggles": {
"useDarkModeAsDefault": false,
"useDarkModeBasedOnUsersPreference": true,
"useCookieBar": false
}
}
}
And the one where I added the field 'img' inside "logo" is the following:
{"siteConfiguration": {
"logo": { "text": "chrisley","img":"/content/images/logo-dark.png"},
"navigation": {
"header": [
{ "label": "About", "url": "/#about" },
{ "label": "Blog", "url": "/blog" },
{ "label": "Features", "url": "/#features" },
{ "label": "Github", "url": "/#github" }
],
"ctaButton": {
"openNewTab": true,
"label": "Resume",
"url": "/resume.pdf"
},
"footer": [
{ "label": "Privacy", "url": "/privacy" },
{ "label": "Imprint", "url": "/imprint" }
]
},
"featureToggles": {
"useDarkModeAsDefault": false,
"useDarkModeBasedOnUsersPreference": true,
"useCookieBar": false
}
}
}
And when I trying to get the img field in GraphQL with this Query:
query SiteConfiguration {
allSettingsJson: allContentJson {
settings: nodes {
siteConfiguration {
logo {
text
img
}
}
}
}
}
I get the next error:
{
"errors": [
{
"message": "Cannot query field \"img\" on type \"Logo\".",
"locations": [
{
"line": 7,
"column": 11
}
],
"extensions": {
"stack": [
"GraphQLError: Cannot query field \"img\" on type \"Logo\".",
" at Object.Field (/Users/chrisley/Documents/Development/Gatsby/chrisley_dev_website/node_modules/graphql/validation/rules/FieldsOnCorrectTypeRule.js:48:31)",
" at Object.enter (/Users/chrisley/Documents/Development/Gatsby/chrisley_dev_website/node_modules/graphql/language/visitor.js:323:29)",
" at Object.enter (/Users/chrisley/Documents/Development/Gatsby/chrisley_dev_website/node_modules/graphql/utilities/TypeInfo.js:370:25)",
" at visit (/Users/chrisley/Documents/Development/Gatsby/chrisley_dev_website/node_modules/graphql/language/visitor.js:243:26)",
" at validate (/Users/chrisley/Documents/Development/Gatsby/chrisley_dev_website/node_modules/graphql/validation/validate.js:69:24)",
" at graphqlMiddleware (/Users/chrisley/Documents/Development/Gatsby/chrisley_dev_website/node_modules/express-graphql/index.js:98:38)",
" at processTicksAndRejections (node:internal/process/task_queues:95:5)"
]
}
}
]
}
Hope you can help me guys, as always haha 😅
I'll be answering myself because I found the problem hahaha.
The problem was that I was missing updating the Schema of the theme, in particular of this theme was the file gastby/node/createSchemaCustomization.js
So.. after updating the file with this lines:
module.exports = ({ actions }) => {
actions.createTypes(`
...
type Logo {
text: String
img: String
}
...
`);
};
GraphQL detected my new field 'img' of the 'logo' object.
After some research I'm assuming you are using the following starter: https://github.com/konstantinmuenster/gatsby-theme-portfolio-minimal/tree/main/gatsby-theme-portfolio-minimal
Have you tried stopping your development process and cleaning Gatsby cache by:
gatsby clean
Or manually deleting the .cache folder.

Loopback embedsMany Helper methods don't work

I have these two models:
Student
{
"name": "student",
"plural": "students",
"base": "User",
"idInjection": false,
"options": {
"validateUpsert": true
},
"relations": {
"test": {
"type": "embedsMany",
"model": "test",
"property": "mytest",
"options": {
"validate": true,
"forceId": false
}
}
}
and
Test
{
"name": "test",
"base": "Model",
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {
"text": {
"type": "string",
"required": true
}
}
}
When I try to create a new test I get this error
Error: Invalid reference: undefined
I create the test in this way:
Student.js
studentInstance.test.add({text : "something "})
What am I doing wrong?
Update
Delete in embedsMany
update id in test.
Student.js
Student.show = function(email, cb) {
Student.findById(email,function(err, student) {
...
var tmp = student.mytest;
for (var i = 0; i < tmp.length; i++) {
student.test.destroy(tmp[i].id);
}
})
...
}
I tried with
destroy not work correctly, not always remove the data
and
remove show this error
Error: Invalid reference: undefined
at EmbedsMany.remove
Update
Added a example of db
{
"_id": "value",
"property1": "value",
.
.
"mytest": [
{
"text": "something",
"creation": {
"$date": "2016-08-23T14:31:44.678Z"
},
"id": "d738253472876b17feb4b46b"
}
]
}
You don't have test model.
In test.json you defined its names as notification => "name": "notification",
UPDATE
For building (without persisting) an embedded instance please use studentInstance.test.build({text : "something "})
and for creating (with persisting) that please use studentInstance.test.create({text : "something "})
After 3 years, I've faced with same problem by using remove, destroyById.
And then I use unset method. It works.
Person.findById(body.metadata.person.id, (err, person) => {
person.creditCards.unset(
body.creditCard.id,
(err, res) => {
}
);
}
This works well.

How do I expand nested relationships in REST API using Sails.js

I am a newbie to NodeJS and Sails.js.
I want create a REST API that allows me to expand a resource based on query parameter. For eg
HTTP GET /snippets
{
"count": 1,
"next": null,
"previous": null,
"results": [
{
"url": "http://localhost:8000/snippets/1/",
"highlight": "htep://localhost:8000/snippets/1/highlight/",
"title": "test",
"code": "def test():\r\n pass",
"linenos": false,
"language": "Clipper",
"style": "autumn",
"owner": "http://localhost:8000/users/2/",
"extra": "http://localhost:8000/snippetextras/1/"
}
]}
HTTP GET /snippets?expand=owner
{
"count": 1,
"next": null,
"previous": null,
"results": [
{
"url": "http://localhost:8000/snippets/1/",
"highlight": "http://localhost:8000/snippets/1/highlight/",
"title": "test",
"code": "def test():\r\n pass",
"linenos": false,
"language": "Clipper",
"style": "autumn",
"owner": {
"url": "http://localhost:8000/users/2/",
"username": "test",
"email": "test#test.com"
},
"extra": "http://localhost:8000/snippetextras/1/"
}
]}
Wondering how can I do that in Sails.js or NodeJS?
You should use assocations.
Here is how you would create a one-to-many association between your User model and your Snippet model:
// User.js
module.exports = {
// ...
attributes: {
// ...
snippets: {
collection: 'Snippet',
via: 'owner'
}
}
};
// Snippet.js
module.exports = {
// ...
attributes: {
// ...
owner: {
model: 'User'
}
}
};
Then you can hit /snippets if you want a list of snippets, and hit /snippets?populate=[owner] if you need details about the owners of the snippets.

Categories