Thursday, July 27, 2017

About Those Frames Part III

No-frames Xpress Client.

In the previous two posts of this series I talked about why I wanted to examine changing the current Frames based interface for enCore, and the non-frames version of the Xpress Login screen that resulted. In this post I'll describe a non-frames version of the Xpress Client itself.

The Xpress client is a fundamental part of the Xpress interface because it is what the user interacts with the most frequently as Guest, Programmer, or Wizard. Since it is so fundamental to the operation of the whole enCore system any changes made should not interfere with the usability.


The client is a typical web page layout with a menu in a header bar and two columns below. The columns hold the text input and output from the MOO on the left and the WEB display generated by the MOO on the right.  In the existing frames based layout this is really very easy to generate with a frameset document whose contents are the output of the verbs on the xpress_client object.


I figured the same kind of changes I made for the Login screen should work, that is replacing the frameset document with an HTML layout that used iframes and CSS. If possible I wanted to avoid having to change anything other than verbs on the client object itself.

A key thing I wanted was to keep the layout the same at any screen size from fullscreen on a desktop monitor to a screen on a smartphone or tablet. I also wanted the columns to resize cleanly as the client window size changes and without adding extraneous scrollbars.  This is handled by the flexbox system like I used for the login.

Keeping the menu bar in place relative to the columns below was tricky and that is handled by a CSS directive called box-sizing. You can read the gory details of what it does here.

So thanks to Google 😀 and lots of experimenting I applied these tools to the same DIV / iframe setup I used for the login screen.

Surprisingly this worked pretty well, once the inevitable tweaks to make it look the same and behave well at multiple screen sizes were made of course. 

Here is the resulting CSS:

<style>
/*I love me some border-box*/
       * {
        box-sizing: border-box;
       }

       /*Just removing default browser padding/margin*/
        html,
        body {
            padding: 0;
            margin: 0;
            color: #ebebeb;
  }
        /*Flexbox gives us the flexiness we need.
        The top just stays put as there is no scrolling on the body due to the page
        never exceeding viewport height*/
       .menu-frame {
            display: flex;
            align-items: center;
            justify-content: center;
            background-color: darkgreen;
            font-size: 3rem;
            position: relative;
            z-index: 10;
            height: 65px;
        }
        /*This is our main wrapping element, it's made 100vh high to ensure
        it is always the correct size and then moved into place and padded 
        with negative margin and padding*/
        .Container {
            display: flex;
            overflow: hidden;
            height: 100vh;
            margin-top: -65px;
            padding-top: 65px;
            position: relative;
            width: 100%;
            backface-visibility: hidden;
            will-change: overflow;
        }

        .java-frame,
        .web-frame {
            overflow: hidden;
            height: auto;
            padding-bottom: 0.5rem;
        }

        .java-frame {
            width: 50%;
            background-color: white;
        }

        .web-frame {
            flex:1;
            background-color: white;
        }
</style>



I modified the Xpress_Client object to get this code from a .CSS property for easy editing.

The only verb I needed to modify was :vertical_layout horizontal_layout and here is the modified verb that resulted:

"===========================================================";
"Copyright (C) 1999-2004, Jan Rune Holmevik";
"Generates the main enCore Xpress client user screen using three frames";
"Modified to use iframes and DIVs instead of frames";
"KRJ June 2017";
"Vertical layout only!";
"===========================================================";
if (caller != $httpd)
  return E_PERM;
endif
user = args[1];
html = {};
base_url = tostr("http://", $network.site, ":", $network.webport, "/Xpress_client/");
menu = tostr(base_url, "menu.html");
java = tostr(base_url, "java.html");
web = tostr(base_url, "web.html");
html = $list_utils:append(html, this.CSS);
html = {@html, "  <div class=\"menu-frame\">"};
html = {@html, tostr("               <iframe src=\"", menu, "\" name=\"", this.menu_frame, "\" width=\"100%\"  height=\"100%\" noresize=\"noresize\" scrolling=\"no\" marginwidth=\"0\" marginheight=\"0\" frameborder=\"", this.frameborder, "\"></iframe>")};
html = {@html, "  </div>"};
html = {@html, "  <div class=\"Container\">"};
html = {@html, "      <div class=\"java-frame\">"};
html = {@html, tostr("                    <iframe src=\"", java, "\" name=\"", this.java_frame, "\"height=\"100%\" width=\"100%\" scrolling=\"no\" marginwidth=\"0\" marginheight=\"0\" frameborder=\"", this.frameborder, "\"> </iframe>")};
html = {@html, "      </div>"};
html = {@html, "      <div class=\"web-frame\">"};
html = {@html, tostr("                    <iframe src=\"", web, "\" name=\"", this.web_frame, "\" height=\"100%\" width=\"100%\" scrolling=\"auto\" marginwidth=\"", this.frame_marginwidth, "\" marginheight=\"", this.frame_marginheight, "\" frameborder=\"", this.frameborder, "\"> </iframe>")};
html = {@html, "      </div> "};
html = {@html, "  </div>"};
result = this:build(user, html, tostr($httpd.server_name, $core_version), "", "", "", "", this.doctype_frameset);
return result;
"Last modified Sat Jun 17 10:54:40 2017 MDT by Wizard (#2).";



Now the existing Xpress_Client has lots of options for changing the display. Things like whether the client is aligned vertically or horizontally and how big the text display is relative to the web display.  To keep things simple the no-frames client only handles the vertical display, which I think most people use anyways.  Allowing those settings to be changed I will leave as an exercise for the reader 😀

Again to test this safely I did an "@dump with create $Xpress_Client", created a new enCore_CGI_Application object called Xpress_Client_Noframes, pasted the @dump into it making an exact copy of the original which I could modify, and then replaced the object number in #0 for the Xpress_Client with the new object. If it didn't work, more times than not frankly, I would just change the object number in #0 back to the original using the text client and still be able to login with the old client. 

This same system should be able to be used for any of the utilities in enCore too. Some of them like the Program Editor, Help Browser, and Mail Client would be tricky given the number of frames they use but I don't see any reason they couldn't be converted in a similar way.

I hope this client will be useful.

Let me know if you try it and how it works, and as always suggestions and critiques are welcome.

Thanks for reading.
KJ 




Saturday, July 1, 2017

About those frames... Part II

Happy Canada Day!

Previously I wrote about why I wanted to examine changing the current Frames based interface for enCore.

After much experimentation, reading up on "current" web development tools, plus a dash of hair pulling, some heavy coffee consumption, and staring at the ceiling going "Why me..." for longer than my wife thought healthy 😆, I have a no-frames version of both the login page and the Xpress Client.


I'll start with the Login page first. Mainly because it is just a two column layout with one fixed page, the welcome page, and the login page. The welcome page is a static html file and the login screen is built by a verb on the Xpress_login object and is also basically an html file.

I experimented with a pure html/CSS/javascript design but I couldn't make it robust. That is it was difficult to make it work without changing more of the MOO code associated with the login object itself. So following my "If it isn't broke don't fix it "plan, I looked for ways to use the existing functionality as much as possible.

The best option turned out to be the last remaining "frame" allowed in current web development, the lowly iframe!

I replaced the frameset with a page using divs that held two iframes whose source is the output of the two verbs on the Xpress_login object.  The problem was then to arrange the display of the page in such a way that extraneous scrollbars from the iframes were removed  and the page would resize without getting too badly messed up.  This took a while to do and much of what I tried looked OK at full screen but scrambled badly when the browser screen was shrunk to what a mobile or tablet user would see..

However, since we need to be using HTML5 capable browsers anyways I figured I might as well use some of the newer CSS tools. Flexbox and viewport relative sizes were the key.

The resulting page is mobile friendly, and does not need any javascript at all.  I put the required CSS in a property on the object called login_css, and added it to the html being generated by the verb.
It still uses two vertical columns and the login column is a fixed size but that could be changed using flexbox settings in the CSS if desired.

Here is the revised verb on Xpress_Login:

"===========================================================";
"Copyright (C) 2001-2004, Jan Rune Holmevik";
"Generates the main enCore Xpress Login Screen";
"Revised to us a defined welcome page named on this.welcome_page";
"KRJ Sep 3, 2015";
"Revised to replace Frame set layout with CSS/iframe";
"KRJ June 9, 2017";
"===========================================================";
if (caller != $httpd)
  return E_PERM;
endif
{user, ?message = ""} = args;
html = {};
base_url = tostr($encore_web_utils:baseurl(), "/Xpress_Login/");
login = tostr(base_url, "login");
"Revised Welcome Screen to use locally hosted webpage";
"Set page name in this.welcome_page";
welcome = tostr($xpress_client.external_baseurl, this.welcome_page);
if (message)
  message = tostr("onload=\"", message, "\"");
endif
html = $list_utils:append(html, this.login_css);
html = {@html, "<body>"};
html = {@html, "    <div id=\"wrap\">"};
html = {@html, "        <div id=\"login-frame\">"};
html = {@html, tostr("               <iframe src=\"", login, "\" name=\"login\" width=\"100%\" height=\"100%\" noresize=\"noresize\" marginwidth=\"", this.frame_marginwidth, "\" marginheight=\"", this.frame_marginheight, "\" frameborder=\"", this.frameborder, "\" title=\"Login frame\"></iframe>")};
html = {@html, "        </div>"};
html = {@html, "        <div id=\"welcome-frame\">"};
html = {@html, tostr("               <iframe src=\"", welcome, "\" name=\"welcome\" width=\"100%\" height=\"100%\" marginwidth=\"", this.frame_marginwidth, "\" marginheight=\"", this.frame_marginheight, "\" frameborder=\"", this.frameborder, "\" title=\"Welcome screen\"></iframe>")};
html = {@html, "        </div>"};
html = {@html, "    </div>"};
html = {@html, "</body>"};
html = this:build(user, html, "Login", message, "", "", "", this.doctype_frameset);
return html;
"Last modified Fri Jun  9 21:17:55 2017 MDT by Wizard (#2).";

"===========================================================";

And here is the CSS data:

<style>
        body,
 html {
     margin:0;
     padding:0;
     color:#000;
     background:grey;
 }
 #wrap {
     display: flex;
     height:100%;
 }
 #welcome-frame {
     flex: 1;  /* grow */
     background:white;
 }
 #login-frame {
     height:450px;/* fall back for old browsers */
     height:100vh;
            flex: 0 0 200px; /* do not grow, do not shrink, start at 200px */
 }
</style>

Note that this must be stored in .login_css as a list of strings. I used the object editor to store the CSS as a description and then copied that over using the program editor.

The magic here is the way the CSS "display:flex" allows the columns to dynamically resize as the browser window does. Because the CSS is held in a separate property it can be edited and adjusted without messing with the verb so lots of customization is possible.

To test this safely I did an "@dump with create $Xpress_Login", created a new enCore_CGI_Application object called Xpress_Login_Noframes, pasted the @dump into it making an exact copy of the original, then replaced the object number in #0 for the Xpress_Login with the new object. That way, as I messed things up (which happend A LOT) I could change the object number back to the default value when logged in through the text only client, and still be able to use Xpress. 

Next time I'll discuss the more complicated layout for the Xpress_Client.

Thanks for reading
KJ

Friday, June 16, 2017

About those frames... Part I

I have been playing around with trying to update the enCore Xpress user interface.
"Trying" is the key word here.😑

First a little background on why this is something to even worry about.

The user interface and many of the more useful utilities included in the Xpress system are "frames based" layouts. Frames are a way to split a webpage up into independent pieces each with their own URL and context. This is a 1990's technology, a solution for the problem of how to include other web resources inside a webpage, that retained all the formatting, and allowed easy update of a piece without disturbing the rest of the page etc. The frame was basically a window in which to display content from somewhere else.

Practically its main use in the days before CSS and JavaScript was to keep a menu of links available even as the main content frame changed. Since loading a new page always caused the page to reload completely keeping state information was tricky and necessitated a bunch of cookies and other fragile data structures.  Now as far as Xpress is concerned frames were the perfect vehicle to enable the simple web server running inside the MOO to display easily. Each frame was a way to display the output of  a MOO verb. Because frames could reference each other easily it was possible to maintain state through logged in session and update the display as required.

Now frames have always been controversial because they break some of the fundamental attributes of the Web. Things like search engine indexing, bookmarking, and even the "back" button on the browser.

Want to get treated like a pariah in web development circles?
Ask about how to setup something using frames!

AJAX, which used JavaScript and XML data, was a way to do part of what we need.  I experimented with it in my AJAX auto updating room back in 2011. It allowed the web page for a room or object to automatically update the list of objects contained as it changed without having to do a "look" to refresh the web display.  But AJAX causes a lot of traffic to the MOO web server, it essentially polls the object looking for changes. Since unlike the formal web server running alongside the actual MOO executable, the in-moo web server can impact the lag that a user experiences. When it is creating and updating the display NOTHING ELSE CAN RUN.  I considered this a reasonable trade off since it only happens when a room is actually being displayed. However to use it for the Xpress interface itself would entail constant polling from every connection, from every frame of the interface, all the time! Maybe OK for one or two users but would kill a system like Literary Worlds which quite happily handles 100 or more users at once with the current frames based interface.

Definitely not an optimal solution to get rid of the frames.


So...
For our purposes using enCore, FRAMES ARE PERFECT!  Now that we no longer need the JAVA applet to connect we have a pure web based application I.E. a Web App!  Web apps are a different critter entirely from a typical webpage. For one thing Google doesn't ever get to index the inside chunks of a web app display, nobody bookmarks parts of a web app, and the browser's back button doesn't work in a web app like it does on a typical webpage anyway.

Notice that these are the main complaints that the web development community had about frames!
If you look at how typical web apps are coded you'll see a tremendous amount of complexity, and therefore fragility, needed just to do what Xpress does with a simple frameset document.

I'm a big fan of 'if it isn't broken don't fix it' so I wouldn't mess with Xpress except for one thing...

Frames are no longer included in HTML5, not just "deprecated" but actually gone! While most browsers still know how to display them that may not continue. Already support for frames is beginning to disappear in mobile browsers.  This means that if we want to continue to keep enCore and its Xpress interface working we should, reluctantly, see about changing the interface away from frames.

So far my initial messing around has been very discouraging.  In the next parts of this series I will try to explain what I've tried and what worked and what didn't.

Thanks for reading.

Part II is here.

Monday, February 27, 2017

How Time Flies When You Are Having Fun!

Wow!

There is an old saying that states:
Life is what happens when you have other plans.
Definitely holds true for me.

Since I lasted posted to this blog lots of things have happened with the enCore Learning Environment.
Some good some bad.

The Bad is that the enCore Consortium folded. Partly as a result of the unfortunate passing of one of the key movers and shakers, Barbara McManus, and difficulty in getting access to the old domain to maintain the mail list.

The Good is that we now have a JAVA free client for enCore V4 MOOs that is a drop in replacement for the JAVA based Mootcan applet. Jack Lewis at Western Michigan University created and supports the client at Literary Worlds and they have kindly made the client available to all enCore systems.

So where to from here?

I know there is still a lot of interest in enCore, more so now that we no longer have to fight with JAVA restriction policies at many educational institutions.

I know that those of us who have used these systems over the years have collected a fair amount of information tricks and tools and new users and builders could benefit mightily from access to that.

Community support via the old encore mail list was excellent and really helped those of us struggling with making enCore perform all the tricks our imaginations wanted it to.

Thus I have created a new Google Group to become the hub for support of this system.
You can access the Group here: https://groups.google.com/d/forum/encore-learning-environment

This group is not currently open to the public but feel free to request membership and I'll add you.

The Barn is hosted still at Literary Worlds here: http://brn227.brown.wmich.edu/Barn/news.htm

Watch the group and this blog for more interesting MOO news over the coming months.

Thanks for reading.
KJ


 

Friday, October 26, 2012

SOLID design principles


My apologies for the lack of posts.
I've been playing in the Steampunk World lately.
Found this article at TechRepublic and it occurs to me that it applies to MOO code pretty well.
Enjoy
KJ

SOLID design principles improve object-oriented development 
By Justin James October 19, 2012, 1:45 PM PDT

 SRP is the idea that objects should do one thing and one thing only. It is tempting to think this means that a class should represent an entire piece of business logic or data, but that is not quite correct. The idea is not to group all of the functionality that is related together, but all of the functionality that achieves the same goal together.
For example, if you have a class representing printer, putting all of the printer operations (getting toner levels, printing a page, getting an error message) in the printer class may make sense, but it is not really the right approach. Instead, you would put all of the functions related to printing in the same class, and all of the functions for reporting status in a class, and so on. You break the work down into small, digestible chunks. The payoff here is that you can make changes to a select piece of functionality without possibly affecting a ton of other items.

O - Open/closed principle (OCP)

This very simple idea is that classes can allow themselves to be extended but not modified. The source code for the original class should only be modified if a bug is found. The reason behind this is that changing the code will mean that everything depending upon it will need to be retested as well.

L - Liskov substitution principle (LSP)

LSP states that the subclass of an object can be used in place of the superclass without changing things like what the program does, whether it compiles, etc. For example, if class “elephant” is a subtype of class “animal,” then you should be able to use “elephant” where you use “animal,” and the “walk” method will still “walk” (even though the implementation may be different), the “numberOfLegs” property will still return the number of legs (though again, it may be a different number from the base class), the “eat” method will not throw any exceptions that it would not throw in the “animal” class, and so on. It is much easier to make changes and test when you follow LSP.

I - Interface segregation principle (ISP)

ISP dictates that interfaces need to have as little functionality in them as possible. This allows the consumer to only deal with the functionality they are concerned with, which reduces testing needs and the impact of changes to the system.

D - Dependency inversion principle (DIP)

With DIP, high-level objects are abstracted away from low-level objects. It is normal to think of the low-level objects as just being smaller pieces of a bigger one. For example, let’s say that you want to query a database and fill a data set. The temptation is to pass in the database connection information to the data set and let it make the connection. Instead, you pass in a connection that is already configured, and in this way, the database can change without needing to retest the entire data set object.
J.Ja

Monday, February 20, 2012

Inventing on Principle

Thanks to Paul Rayner at Muddle for pointing me to this fantastic presentation.
Enjoy
KJ



Bret Victor - Inventing on Principle from CUSEC on Vimeo.

Tuesday, January 24, 2012

The Machine

Found this comment in a thread on the PiLuD: free talks on Programming Language Design Google group.

https://groups.google.com/group/pilud/about?hl=en

"OOP is best used to model the program like a big machine - gears, stacks, queues, sensors and actuators, signals and data. If you do this, then a lot of problems are cleanly avoided."
David Barbour  

Very apropos to MOO code programming.