Open multiple Kendo Window React wrappers - reactjs

I'm using the Kendo Window React wrapper component in my react app, if you look at the docs, the way to open the window is:
$("[data-role='window']").each(function (index) {
$(this).data('kendoWindow').open()
});
But this will open every window on the page. How can I open a single window when multiple windows controls are used?

You're quite right, it will open every window on the page. When using Kendo React wrappers, a recommended approach for dealing with same type widgets is to place them in different containers to help you locate them:
When the Kendo UI for React wrappers are used we recommend placing same type widgets in different containers in order to easily select them as the ID attribute is not directly passed to the new component
I've modified the basic sample which I assume you were working from to demonstrate this:
class LayoutsContainer extends React.Component {
open() {
$("#win1 [data-role='window']").data('kendoWindow').open();
}
onOpen(){
console.log('Open event was triggered!');
}
onClose(){
console.log('Close event was triggered!');
}
onDragStart(){
console.log('DragStart event was triggered!');
}
onDragEnd(){
console.log('DragEnd event was triggered!');
}
render() {
return (
<div id="win1">
<Window open={this.onOpen} close={this.onClose} dragstart={this.onDragStart} dragend={this.onDragEnd} title={"About Alvar Aalto"} width={"640px"}>
<p>Alvar Aalto is one of the greatest names in modern architecture and design. Glassblowers at the iittala factory still meticulously handcraft the legendary vases that are variations on one theme, fluid organic shapes that let the end user decide the use. Interpretations of the shape in new colors and materials add to the growing Alvar Aalto Collection that remains true to his original design.</p>
<p>Born Hugo Alvar Henrik Aalto (February 3, 1898 - May 11, 1976) in Kuortane, Finland, was noted for his humanistic approach to modernism. He studied architecture at the Helsinki University of Technology from 1916 to 1921. In 1924 he married architect Aino Marsio.</p>
<p>Alvar Aalto was one of the first and most influential architects of the Scandinavian modern movement, and a member of the Congres Internationaux d'Architecture Moderne. Major architectural works include the Finlandia Hall in Helsinki, Finland, and the campus of Helsinki University of Technology.</p>
</Window>
<span id="undo" className="k-button" onClick={this.open}>Click here to open the Window</span>
</div>
);
}
}
ReactDOM.render(
<LayoutsContainer />,
document.querySelector('my-app')
);

Related

Listing files to generate dynamic components with list

I want a scalable solution, using React, to list some pages and automatically using the last one as my main page.
I have my 'legals mention' page, which will be regularly updated with new content.
import { useTranslation } from "react-i18next";
function Legals() {
const { t } = useTranslation('common');
return (
<div>
<h1>Legals</h1>
<span>Version 2.1 - 4th revision</span>
<span>ยท Effective September 30, 2020</span>
<button>Archived versions</button>
{...}<Content>{...}
</div>
)}
export default Legals;
So this is supposed to display the most recent version, and contains a button with a list to older versions.
I was thinking of using i18n and check in a folder for the last version, is it the best way to do it?
How to accomplish it, at least in pseudocode?

Customization of the Height of a Pivot Item Link Line in Fluent UI

I'm trying to increase the height of the line on the selected Pivot item link in Microsoft's Fluent UI using React.
Here's a screenshot for the purposes of clarification:
The orange arrow is pointing to the blue line of which I would like to increase the height.
I have tried setting the styles attribute of the Pivot component but thus far have been unsuccessful. Here's some code
const pivotStyles: Partial<IStyleSet<IPivotStyles>> = {
link: { ? },
linkContent: { ? }
};
<Pivot styles={pivotStyles} linkSize={PivotLinkSize.large}>
<PivotItem headerText="Zane"></PivotItem>
<PivotItem headerText="Kai"></PivotItem>
<PivotItem headerText="Jay"></PivotItem>
</Pivot>
I have experimented with different attributes of both link and linkContent but haven't found a way yet. I believe what I'm trying to do is manipulate the IStyle interface but I can't find details of the attributes of it. The link there is very vague. For example, what are all the available attributes of link, linkContent, etc.?
Any thoughts on this would be most appreciated!
Thank you.
Turns out I was on the right track and just needed the exact fields. Here's what ended up working:
const pivotStyles = {
linkIsSelected: {
selectors: {
':before': {
height: '6px', // was previously defaulted at 2px
}
}
}
};
I scoured about 4.24 million sites to find this answer but here are some of the most helpful in case they are of interest:
the actual source code of Pivot.styles.ts
the Microsoft Fluent UI Pivot Documentation
A deep examination of the classes using Chrome Dev Tools also helped. ;)
Here's a picture of the end result:

Is there a better way to get subcontrol name?

I am trying to get a reference in the "scrollbar-y" of the class qx.ui.list.List
Using the createChildControl event how can I check if the widget is the one named "scrollbar-y"?
So far I found two ways of which none seems elegant but both seem to get the job done
this.__list = new qx.ui.list.List()
this.__list.addListener("createChildControl", this.__onListCreateChildControl, this);
and later
__onListCreateChildControl: function (e){
debugger;
var child = e.getData();
if (child.constructor === qx.ui.core.scroll.ScrollBar && child.getOrientation() === "vertical") {
child.addListener("scroll", this.__onListScroll, this);
}
},
This checks implicitly. Apparently if it is a scrollbar and it is vertical it is our y scrollbar. Yeah it kinda looks like a duck but I have to check for both
if (quacks like one && walks like one)
The other way is
__onListCreateChildControl: function (e){
debugger;
var child = e.getData();
if (child.$$subcontrol === 'scrollbar-y') {
child.addListener("scroll", this.__onListScroll, this);
}
},
which uses the internal variable $$subcontrol. This works fine but it uses qooxdoo internals which seems like a hack.
P.S. I did try getChildControl('scrollbar-y') in various phases but since it is created in "as needed" basis I always get null.
You're right! There is no "straightforward" possibility to retrieve the ID (or name) of a widget created as a child of another widget in terms of child control creation.
Therefore I've submitted a PR to github which does exactly that: namely retrieving the id/name of a child control by exposing the internal $$subcontrol variable via a method getSubcontrolId https://github.com/qooxdoo/qooxdoo/pull/9140
The PR is currently in review state.

In Typescript/Angular 2 how to find an object in an array by a property of the object

I've been doing some searching and there seem to be a few possible solutions.
First one that will probably work: Filtering an array in angular2
but I find using a pipe and a for loop not ideal.
My idea was using an interface.
This would be a typescript solution. Problem here is defining the collection.
public covers = COVERS;
public images = VECTORS; // a BIG image collection
imagesByCoverType: CoverVector = {}; // Array is made if
// I use Vector[]; but I wanted to use interface.
// images are correctly filtered to the relevant ones.
ngOnInit() {
this.imagesByCoverType = this.images.filter(
image => image.type === 'book-cover');
}
// defined outside of the component class of course.
interface CoverVector {
[book_id: number]: Vector;
}
<li *ngFor="let cover of covers")>
<p>{{cover.title}}</p>
<!-- Here I would like to print out a url to an image of an image object -->
<!-- cover has a property book_id, and also a
chapter_id because the book is subdivided -->
<!-- I was thinking something like this: -->
<p>{{imagesByCoverType[cover.id].url}}</p>
</li>
So I want to access an object in an array by using an interface. How do I do this? Considering also that I have a filtered array of vectors that it should go over.
Recap for clarity:
I want:
A big collection of data that has a unique identifier connected to an 'interface' or find method.
This interface should make it possible to input this unique id and access with it the desired object.
Then all properties of this object should be accessible. Or actually only the url in this case. Point being: it should be there, not just the interface property, but any desired object property.
Then all this elegantly wrapped up in a Angular 2 ngIf statement.
I wouldn't have thought this in-array-find-by-object-property thing would be so hard but it's been a struggle.
Solution I am currently using
It's beyond me why I have to resort to a entire for loop just to access one element I already know the identifier of - from a for loop above it - but I used a for loop using a custom pipe.
// Angular 2
import { Pipe, PipeTransform } from '#angular/core';
#Pipe({
name: 'cover'
})
export class CoverVectorPipe{
transform(value: any, cover_id: number) {
return value.filter(
(item: any)=> item.aim_id === cover_id);
}
}
Any help solving this using an interface is still welcome.
Also I am wondering if this isn't computationally expensive.

ASP.NET MVC 4 Mobile Display Modes with Exact View Name

I have set up the Display Mode in Application Start event as
DisplayModeProvider.Instance.Modes.Insert( 0, new DefaultDisplayMode( "iPhone" ){
ContextCondition = ( context =>
context.GetOverriddenUserAgent( ).IndexOf(
"iPhone",
StringComparison.OrdinalIgnoreCase ) >= 0 ) } );
Then in the controller I have return View where I specify the view name:
return View( "~/Views/Common/User/Login.cshtml", viewModel );
And if I visit the page from the iPhone it will go directly to Login View
If I do not specify the view name:
return View( viewModel );
In this case from the iPhone I see the Login.iPhone.cshtml
Question: Is it possible to specify the name of the view but some how the DisplayModeProvider will select general or iPhone version of the cshtml file?
I don't normally like to resurrect old questions but as this one was never answered and this is one I had particular trouble finding an answer to myself, it may be worth having an answer for anyone else who comes across the same problem.
You could add your additional locations to the ViewLocationFormats and PartialViewLocationFormats collections for the ViewEngines you are using. This way you could just specify the view name as tvanfosson suggests and MVC would find the file correctly, which should allow the mobile overriding to work it's magic.
Here is some code I use to override the PartialViewLocationFormats, you could also do the same using ViewLocationFormats. This is added in global.asax as part of application_start
ViewEngines.Engines.Clear();
var razorViewEngine = new RazorViewEngine
{
PartialViewLocationFormats = new[]
{
"~/Views/{1}/{0}.cshtml",
"~/Views/Shared/{0}.cshtml",
"~/Views/{1}/EditorTemplates/{0}.cshtml",
"~/Views/{1}/DisplayTemplates/{0}.cshtml",
"~/Views/Shared/DisplayTemplates/{0}.cshtml"
}
};
Because this method involves clearing the viewengines collection, you will need to add in all locationFormats, even the standard ones, for all the view engines you are using.

Resources